Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20120802111552

Diff

Diff from 1.219 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/pcc/pcc/cc/cc/cc.c

Annotated File View

ragge
1.219
1 /*      $Id: cc.c,v 1.219 2012/08/02 11:15:52 ragge Exp $       */
ragge
1.128
2 /*
3  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * Redistributions of source code and documentation must retain the above
10  * copyright notice, this list of conditions and the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditionsand the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * All advertising materials mentioning features or use of this software
15  * must display the following acknowledgement:
16  *      This product includes software developed or owned by Caldera
17  *      International, Inc.
18  * Neither the name of Caldera International, Inc. nor the names of other
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23  * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
27  * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35
36 /*
37  * Front-end to the C compiler.
38  *
39  * Brief description of its syntax:
40  * - Files that end with .c are passed via cpp->ccom->as->ld
41  * - Files that end with .i are passed via ccom->as->ld
plunky
1.206
42  * - Files that end with .S are passed via cpp->as->ld
43  * - Files that end with .s are passed via as->ld
ragge
1.128
44  * - Files that end with .o are passed directly to ld
45  * - Multiple files may be given on the command line.
46  * - Unrecognized options are all sent directly to ld.
47  * -c or -S cannot be combined with -o if multiple files are given.
48  *
49  * This file should be rewritten readable.
50  */
51 #include "config.h"
52
53 #include <sys/types.h>
54 #ifdef HAVE_SYS_WAIT_H
55 #include <sys/wait.h>
56 #endif
57
58 #include <ctype.h>
59 #include <errno.h>
60 #include <fcntl.h>
61 #ifdef HAVE_LIBGEN_H
62 #include <libgen.h>
63 #endif
64 #include <signal.h>
65 #include <stdarg.h>
66 #include <stdio.h>
67 #include <stdlib.h>
68 #include <string.h>
69 #ifdef HAVE_UNISTD_H
70 #include <unistd.h>
71 #endif
72
plunky
1.213
73 #ifdef os_win32
ragge
1.128
74 #include <windows.h>
75 #include <process.h>
76 #include <io.h>
gmcgarry
1.179
77 #define F_OK    0x00
78 #define R_OK    0x04
79 #define W_OK    0x02
80 #define X_OK    R_OK
ragge
1.128
81 #endif
82
83 #include "compat.h"
84
85 #include "ccconfig.h"
ragge
1.167
86 #include "macdefs.h"
ragge
1.218
87
88 #include "xalloc.h"
89 #include "strlist.h"
ragge
1.128
90 /* C command */
91
92 #define MKS(x) _MKS(x)
93 #define _MKS(x) #x
94
95 /*
96  * Many specific definitions, should be declared elsewhere.
97  */
98
99 #ifndef STDINC
100 #define STDINC          "/usr/include/"
101 #endif
102
103 #ifndef LIBDIR
104 #define LIBDIR          "/usr/lib/"
105 #endif
106
107 #ifndef PREPROCESSOR
108 #define PREPROCESSOR    "cpp"
109 #endif
110
111 #ifndef COMPILER
gmcgarry
1.138
112 #define COMPILER        "ccom"
ragge
1.128
113 #endif
114
115 #ifndef ASSEMBLER
116 #define ASSEMBLER       "as"
117 #endif
118
119 #ifndef LINKER
120 #define LINKER          "ld"
121 #endif
122
ragge
1.174
123 #ifndef MULTIOSDIR
124 #define MULTIOSDIR      "."
125 #endif
126
127
ragge
1.128
128 #define MAXFIL 10000
129 #define MAXLIB 10000
130 #define MAXAV  10000
ragge
1.173
131 #define MAXOPT 200
ragge
1.128
132 char    *tmp3;
133 char    *tmp4;
134 char    *outfile, *ermfile;
ragge
1.175
135 static void add_prefix(const char *);
136 static char *find_file(const char *, int);
plunky
1.183
137 char *copy(const char *, int);
plunky
1.185
138 char *cat(const char *, const char *);
gmcgarry
1.150
139 char *setsuf(char *, char);
ragge
1.198
140 int cxxsuf(char *);
ragge
1.128
141 int getsuf(char *);
ragge
1.198
142 char *getsufp(char *s);
ragge
1.128
143 int main(intchar *[]);
144 void error(char *, ...);
145 void errorx(intchar *, ...);
146 int callsys(char [], char *[]);
147 int cunlink(char *);
148 void dexit(int);
149 void idexit(int);
150 char *gettmp(void);
151 void *ccmalloc(int size);
ragge
1.218
152 void aerror(char *);
ragge
1.219
153 void oerror(char *);
ragge
1.218
154 char *argnxt(char *, char *);
plunky
1.213
155 #ifdef os_win32
ragge
1.128
156 char *win32pathsubst(char *);
gmcgarry
1.149
157 char *win32commandline(char *, char *[]);
ragge
1.128
158 #endif
159 char    *av[MAXAV];
160 char    *clist[MAXFIL];
gmcgarry
1.150
161 char    *olist[MAXFIL];
ragge
1.128
162 char    *llist[MAXLIB];
163 char    *aslist[MAXAV];
164 char    *xlist[100];
165 int     xnum;
166 char    *mlist[100];
167 char    *flist[100];
168 char    *wlist[100];
169 char    *idirafter;
170 int     nm;
171 int     nf;
172 int     nw;
173 int     sspflag;
plunky
1.214
174 int     freestanding;
ragge
1.128
175 int     pflag;
176 int     sflag;
177 int     cflag;
178 int     eflag;
179 int     gflag;
gmcgarry
1.145
180 int     rflag;
ragge
1.128
181 int     vflag;
182 int     tflag;
183 int     Eflag;
184 int     Oflag;
185 int     kflag;  /* generate PIC/pic code */
186 #define F_PIC   1
187 #define F_pic   2
ragge
1.216
188 int     MflagMPflagnMfiles/* dependencies only */
189 char    *Mfiles[10];
ragge
1.128
190 int     pgflag;
191 int     exfail;
192 int     Xflag;
193 int     Wallflag;
194 int     Wflag;
195 int     nostartfilesBstaticshared;
196 int     nostdincnostdlib;
197 int     onlyas;
198 int     pthreads;
plunky
1.217
199 int     xasmxcflagxgnu89xgnu99;
ragge
1.128
200 int     ascpp;
plunky
1.196
201 #ifdef CHAR_UNSIGNED
plunky
1.209
202 int     xuchar = 1;
plunky
1.196
203 #else
plunky
1.209
204 int     xuchar = 0;
plunky
1.196
205 #endif
ragge
1.198
206 int     cxxflag;
ragge
1.216
207 int     cppflag;
ragge
1.128
208
209 char    *passp = LIBEXECDIR PREPROCESSOR;
210 char    *pass0 = LIBEXECDIR COMPILER;
ragge
1.212
211 char    *passxx0 = LIBEXECDIR "cxxcom";
ragge
1.128
212 char    *as = ASSEMBLER;
213 char    *ld = LINKER;
ragge
1.175
214 char    *sysroot;
ragge
1.128
215 char *cppadd[] = CPPADD;
216 #ifdef DYNLINKER
217 char *dynlinker[] = DYNLINKER;
218 #endif
219 #ifdef CRT0FILE
220 char *crt0file = CRT0FILE;
221 #endif
222 #ifdef CRT0FILE_PROFILE
223 char *crt0file_profile = CRT0FILE_PROFILE;
224 #endif
225 #ifdef STARTFILES
226 char *startfiles[] = STARTFILES;
227 char *endfiles[] = ENDFILES;
228 #endif
229 #ifdef STARTFILES_T
230 char *startfiles_T[] = STARTFILES_T;
231 char *endfiles_T[] = ENDFILES_T;
232 #endif
233 #ifdef STARTFILES_S
234 char *startfiles_S[] = STARTFILES_S;
235 char *endfiles_S[] = ENDFILES_S;
236 #endif
237 #ifdef MULTITARGET
238 char *mach = DEFMACH;
239 struct cppmd {
240         char *mach;
241         char *cppmdadd[MAXCPPMDARGS];
242 };
243
244 struct cppmd cppmds[] = CPPMDADDS;
245 #else
246 char *cppmdadd[] = CPPMDADD;
247 #endif
248 #ifdef LIBCLIBS
249 char *libclibs[] = LIBCLIBS;
250 #else
251 char *libclibs[] = { "-lc"NULL };
252 #endif
253 #ifdef LIBCLIBS_PROFILE
254 char *libclibs_profile[] = LIBCLIBS_PROFILE;
255 #else
256 char *libclibs_profile[] = { "-lc_p"NULL };
257 #endif
258 #ifndef STARTLABEL
259 #define STARTLABEL "__start"
260 #endif
261 char *incdir = STDINC;
gmcgarry
1.153
262 char *altincdir = INCLUDEDIR "pcc/";
gmcgarry
1.136
263 char *libdir = LIBDIR;
plunky
1.200
264 #ifdef PCCINCDIR
ragge
1.128
265 char *pccincdir = PCCINCDIR;
ragge
1.198
266 char *pxxincdir = PCCINCDIR "/c++";
plunky
1.200
267 #endif
268 #ifdef PCCLIBDIR
ragge
1.128
269 char *pcclibdir = PCCLIBDIR;
plunky
1.200
270 #endif
ragge
1.164
271 #ifdef mach_amd64
272 int amd64_i386;
273 #endif
ragge
1.128
274
ragge
1.218
275 #define match(a,b)      (strcmp(a,b) == 0)
276
ragge
1.128
277 /* handle gcc warning emulations */
278 struct Wflags {
279         char *name;
280         int flags;
281 #define INWALL          1
282 Wflags[] = {
plunky
1.215
283         { "truncate"0 },
284         { "strict-prototypes"0 },
285         { "missing-prototypes"0 },
286         { "implicit-int"INWALL },
287         { "implicit-function-declaration"INWALL },
288         { "shadow"0 },
289         { "pointer-sign"INWALL },
290         { "sign-compare"0 },
291         { "unknown-pragmas"INWALL },
292         { "unreachable-code"0 },
293         { NULL0 },
ragge
1.128
294 };
295
ragge
1.158
296 #ifndef USHORT
297 /* copied from mip/manifest.h */
298 #define USHORT          5
299 #define INT             6
300 #define UNSIGNED        7
301 #endif
302
ragge
1.157
303 /*
304  * Wide char defines.
305  */
306 #if WCHAR_TYPE == USHORT
307 #define WCT "short unsigned int"
308 #define WCM "65535U"
ragge
1.158
309 #if WCHAR_SIZE != 2
310 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
311 #endif
ragge
1.157
312 #elif WCHAR_TYPE == INT
313 #define WCT "int"
314 #define WCM "2147483647"
ragge
1.158
315 #if WCHAR_SIZE != 4
316 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
317 #endif
ragge
1.157
318 #elif WCHAR_TYPE == UNSIGNED
319 #define WCT "unsigned int"
ragge
1.158
320 #define WCM "4294967295U"
321 #if WCHAR_SIZE != 4
322 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
323 #endif
324 #else
325 #error WCHAR_TYPE not defined or invalid
ragge
1.157
326 #endif
327
ragge
1.160
328 #ifdef GCC_COMPAT
329 #ifndef REGISTER_PREFIX
330 #define REGISTER_PREFIX ""
331 #endif
332 #ifndef USER_LABEL_PREFIX
333 #define USER_LABEL_PREFIX ""
334 #endif
335 #endif
336
plunky
1.192
337 #ifndef PCC_WINT_TYPE
338 #define PCC_WINT_TYPE "unsigned int"
339 #endif
340
341 #ifndef PCC_SIZE_TYPE
342 #define PCC_SIZE_TYPE "unsigned long"
343 #endif
344
ragge
1.161
345 #ifndef PCC_PTRDIFF_TYPE
346 #define PCC_PTRDIFF_TYPE "long int"
347 #endif
348
ragge
1.216
349 #ifndef CPPROGNAME
350 #define CPPROGNAME      "cpp"
351 #endif
352
ragge
1.218
353 struct strlist preprocessor_flags;
ragge
1.219
354 struct strlist incdirs;
ragge
1.218
355
ragge
1.128
356 int
357 main(int argcchar *argv[])
358 {
ragge
1.218
359         struct string *s;
ragge
1.219
360         struct strlist *sl;
ragge
1.128
361         struct Wflags *Wf;
ragge
1.218
362         char *t, *u, *argp;
ragge
1.128
363         char *assource;
364         char **pv, *ptemp[MAXOPT], **pvt;
gmcgarry
1.163
365         int ncnlnasncppijcnxona;
ragge
1.128
366 #ifdef MULTITARGET
367         int k;
368 #endif
369
ragge
1.218
370         strlist_init(&preprocessor_flags);
ragge
1.219
371         strlist_init(&incdirs);
ragge
1.218
372
ragge
1.216
373         if ((t = strrchr(argv[0], '/')))
374                 t = copy(t+10);
375         else
376                 t = argv[0];
377         if (strcmp(t"p++") == 0) {
ragge
1.198
378                 cxxflag = 1;
379                 pass0 = passxx0;
ragge
1.216
380         } else if (strcmp(t"cpp") == 0 || strcmp(tCPPROGNAME) == 0) {
381                 cppflag = 1;
382                 Eflag = 1;
ragge
1.198
383         }
384
plunky
1.213
385 #ifdef os_win32
ragge
1.128
386         /* have to prefix path early.  -B may override */
387         incdir = win32pathsubst(incdir);
gmcgarry
1.153
388         altincdir = win32pathsubst(altincdir);
gmcgarry
1.136
389         libdir = win32pathsubst(libdir);
plunky
1.200
390 #ifdef PCCINCDIR
ragge
1.128
391         pccincdir = win32pathsubst(pccincdir);
plunky
1.199
392         pxxincdir = win32pathsubst(pxxincdir);
plunky
1.200
393 #endif
394 #ifdef PCCLIBDIR
ragge
1.128
395         pcclibdir = win32pathsubst(pcclibdir);
plunky
1.200
396 #endif
ragge
1.128
397         passp = win32pathsubst(passp);
398         pass0 = win32pathsubst(pass0);
gmcgarry
1.180
399 #ifdef STARTFILES
400         for (i = 0startfiles[i] != NULLi++)
401                 startfiles[i] = win32pathsubst(startfiles[i]);
402         for (i = 0endfiles[i] != NULLi++)
403                 endfiles[i] = win32pathsubst(endfiles[i]);
404 #endif
405 #ifdef STARTFILES_T
406         for (i = 0startfiles_T[i] != NULLi++)
407                 startfiles_T[i] = win32pathsubst(startfiles_T[i]);
408         for (i = 0endfiles_T[i] != NULLi++)
409                 endfiles_T[i] = win32pathsubst(endfiles_T[i]);
410 #endif
411 #ifdef STARTFILES_S
412         for (i = 0startfiles_S[i] != NULLi++)
413                 startfiles_S[i] = win32pathsubst(startfiles_S[i]);
414         for (i = 0endfiles_S[i] != NULLi++)
415                 endfiles_S[i] = win32pathsubst(endfiles_S[i]);
416 #endif
ragge
1.128
417 #endif
418
gmcgarry
1.163
419         i = nc = nl = nas = ncpp = nxo = 0;
ragge
1.128
420         pv = ptemp;
421         while(++i < argc) {
422                 if (argv[i][0] == '-') {
ragge
1.218
423
424                         argp = argv[i];
ragge
1.128
425                         switch (argv[i][1]) {
426                         default:
427                                 goto passa;
428 #ifdef notyet
429         /* must add library options first (-L/-l/...) */
430                                 error("unrecognized option `-%c'"argv[i][1]);
431                                 break;
432 #endif
433
434                         case '-'/* double -'s */
ragge
1.130
435                                 if (strcmp(argv[i], "--version") == 0) {
ragge
1.128
436                                         printf("%s\n"VERSSTR);
ragge
1.130
437                                         return 0;
ragge
1.175
438                                 } else if (strncmp(argv[i], "--sysroot="10) == 0) {
439                                         sysroot = argv[i] + 10;
ragge
1.169
440                                 } else if (strcmp(argv[i], "--param") == 0) {
ragge
1.128
441                                         /* NOTHING YET */;
ragge
1.169
442                                         i++; /* ignore arg */
443                                 } else
gmcgarry
1.148
444                                         goto passa;
ragge
1.128
445                                 break;
446
447                         case 'B'/* other search paths for binaries */
ragge
1.175
448                                 add_prefix(argv[i] + 2);
ragge
1.128
449                                 break;
450
451 #ifdef MULTITARGET
452                         case 'b':
453                                 t = &argv[i][2];
454                                 if (*t == '\0' && i + 1 < argc) {
455                                         t = argv[i+1];
456                                         i++;
457                                 }
458                                 if (strncmp(t"?"1) == 0) {
459                                         /* show machine targets */
460                                         printf("Available machine targets:");
461                                         for (j=0cppmds[j].machj++)
462                                                 printf(" %s",cppmds[j].mach);
463                                         printf("\n");
464                                         exit(0);
465                                 }
466                                 for (j=0cppmds[j].machj++)
467                                         if (strcmp(tcppmds[j].mach) == 0) {
468                                                 mach = cppmds[j].mach;
469                                                 break;
470                                         }
471                                 if (cppmds[j].mach == NULL)
472                                         errorx(1"unknown target arch %s"t);
473                                 break;
474 #endif
475
ragge
1.218
476                         case 'C':
477                                 if (match(argp"-C") || match(argp"-CC"))
478                                         strlist_append(&preprocessor_flagsargp);
479                                 else
ragge
1.219
480                                         oerror(argp);
ragge
1.218
481                                 break;
482
ragge
1.128
483                         case 'X':
484                                 Xflag++;
485                                 break;
486                         case 'W'/* Ignore (most of) W-flags */
487                                 if (strncmp(argv[i], "-Wl,"4) == 0) {
488                                         /* options to the linker */
489                                         t = &argv[i][4];
490                                         while ((u = strchr(t','))) {
491                                                 *u++ = 0;
492                                                 llist[nl++] = t;
493                                                 t = u;
494                                         }
495                                         llist[nl++] = t;
496                                 } else if (strncmp(argv[i], "-Wa,"4) == 0) {
497                                         /* options to the assembler */
498                                         t = &argv[i][4];
499                                         while ((u = strchr(t','))) {
500                                                 *u++ = 0;
501                                                 aslist[nas++] = t;
502                                                 t = u;
503                                         }
504                                         aslist[nas++] = t;
ragge
1.137
505                                 } else if (strncmp(argv[i], "-Wc,"4) == 0) {
506                                         /* options to ccom */
507                                         t = &argv[i][4];
508                                         while ((u = strchr(t','))) {
509                                                 *u++ = 0;
510                                                 wlist[nw++] = t;
511                                                 t = u;
512                                         }
513                                         wlist[nw++] = t;
ragge
1.218
514                                 } else if ((t = argnxt(argp"-Wp,"))) {
515                                         u = strtok(t",");
516                                         do {
517                                                 strlist_append(&preprocessor_flagsu);
518                                         } while ((u = strtok(NULL",")) != NULL);
plunky
1.193
519                                 } else if (strcmp(argv[i], "-Werror") == 0) {
520                                         wlist[nw++] = argv[i];
ragge
1.128
521                                 } else if (strcmp(argv[i], "-Wall") == 0) {
522                                         Wallflag = 1;
523                                 } else if (strcmp(argv[i], "-WW") == 0) {
524                                         Wflag = 1;
525                                 } else {
plunky
1.215
526                                         /* pass through, if supported */
527                                         t = &argv[i][2];
528                                         if (strncmp(t"no-"3) == 0)
529                                                 t += 3;
530                                         if (strncmp(t"error="6) == 0)
531                                                 t += 6;
ragge
1.128
532                                         for (Wf = WflagsWf->nameWf++) {
plunky
1.215
533                                                 if (strcmp(tWf->name) == 0)
534                                                         wlist[nw++] = argv[i];
ragge
1.128
535                                         }
536                                 }
537                                 break;
538
539                         case 'f'/* GCC compatibility flags */
540                                 if (strcmp(argv[i], "-fPIC") == 0)
541                                         kflag = F_PIC;
542                                 else if (strcmp(argv[i], "-fpic") == 0)
543                                         kflag = F_pic;
ragge
1.195
544                                 else if (strcmp(argv[i], "-ffreestanding") == 0)
plunky
1.214
545                                         freestanding = 1;
ragge
1.128
546                                 else if (strcmp(argv[i],
plunky
1.209
547                                     "-fsigned-char") == 0)
548                                         xuchar = 0;
549                                 else if (strcmp(argv[i],
550                                     "-fno-signed-char") == 0)
551                                         xuchar = 1;
552                                 else if (strcmp(argv[i],
553                                     "-funsigned-char") == 0)
554                                         xuchar = 1;
555                                 else if (strcmp(argv[i],
556                                     "-fno-unsigned-char") == 0)
557                                         xuchar = 0;
558                                 else if (strcmp(argv[i],
ragge
1.128
559                                     "-fstack-protector") == 0) {
560                                         flist[nf++] = argv[i];
561                                         sspflag++;
562                                 } else if (strcmp(argv[i],
563                                     "-fstack-protector-all") == 0) {
564                                         flist[nf++] = argv[i];
565                                         sspflag++;
566                                 } else if (strcmp(argv[i],
567                                     "-fno-stack-protector") == 0) {
568                                         flist[nf++] = argv[i];
569                                         sspflag = 0;
570                                 } else if (strcmp(argv[i],
571                                     "-fno-stack-protector-all") == 0) {
572                                         flist[nf++] = argv[i];
573                                         sspflag = 0;
574                                 }
575                                 /* silently ignore the rest */
576                                 break;
577
578                         case 'g'/* create debug output */
ragge
1.177
579                                 if (argv[i][2] == '0')
580                                         gflag = 0;
581                                 else
582                                         gflag++;
ragge
1.128
583                                 break;
584
ragge
1.219
585                         case 'D':
586                         case 'U':
587                         case 'I'/* Add include dirs */
588                                 sl = argp[1] == 'I' ? &incdirs : &preprocessor_flags;
589                                 strlist_append(slargp);
590                                 if (argp[2] != 0)
591                                         break;
592                                 if (argc == i+1)
593                                         aerror(argp);
594                                 strlist_append(slargv[++i]);
595                                 break;
596
ragge
1.128
597                         case 'i':
598                                 if (strcmp(argv[i], "-isystem") == 0) {
599                                         *pv++ = "-S";
600                                         *pv++ = argv[++i];
601                                 } else if (strcmp(argv[i], "-include") == 0) {
602                                         *pv++ = "-i";
603                                         *pv++ = argv[++i];
604                                 } else if (strcmp(argv[i], "-idirafter") == 0) {
605                                         idirafter = argv[++i];
gmcgarry
1.172
606 #ifdef os_darwin
607                                 } else if (strcmp(argv[i], "-install_name") == 0) {
608                                         llist[nl++] = argv[i];
609                                         llist[nl++] = argv[++i];
610 #endif
ragge
1.128
611                                 } else
612                                         goto passa;
613                                 break;
614
615                         case 'k'/* generate PIC code */
616                                 kflag = F_pic;
617                                 break;
618
619                         case 'm'/* target-dependent options */
ragge
1.164
620 #ifdef mach_amd64
621                                 /* need to call i386 ccom for this */
622                                 if (strcmp(argv[i], "-m32") == 0) {
623                                         pass0 = LIBEXECDIR "/ccom_i386";
624                                         amd64_i386 = 1;
625                                         break;
626                                 }
627 #endif
ragge
1.128
628                                 mlist[nm++] = argv[i];
ragge
1.169
629                                 if (argv[i][2] == 0) {
630                                         /* separate second arg */
631                                         /* give also to linker */
632                                         llist[nl++] = argv[i++];
633                                         mlist[nm++] = argv[i];
634                                         llist[nl++] = argv[i];
635                                 }
ragge
1.128
636                                 break;
637
638                         case 'n'/* handle -n flags */
639                                 if (strcmp(argv[i], "-nostdinc") == 0)
640                                         nostdinc++;
641                                 else if (strcmp(argv[i], "-nostdlib") == 0) {
642                                         nostdlib++;
643                                         nostartfiles++;
644                                 } else if (strcmp(argv[i], "-nostartfiles") == 0)
645                                         nostartfiles = 1;
plunky
1.202
646                                 else if (strcmp(argv[i], "-nodefaultlibs") == 0)
647                                         nostdlib++;
ragge
1.128
648                                 else
649                                         goto passa;
650                                 break;
651
652                         case 'p':
653                                 if (strcmp(argv[i], "-pg") == 0 ||
654                                     strcmp(argv[i], "-p") == 0)
655                                         pgflag++;
656                                 else if (strcmp(argv[i], "-pthread") == 0)
657                                         pthreads++;
658                                 else if (strcmp(argv[i], "-pipe") == 0)
659                                         /* NOTHING YET */;
gmcgarry
1.144
660                                 else if (strcmp(argv[i], "-pedantic") == 0)
661                                         /* NOTHING YET */;
ragge
1.162
662                                 else if (strcmp(argv[i],
663                                     "-print-prog-name=ld") == 0) {
664                                         printf("%s\n"LINKER);
665                                         return 0;
ragge
1.174
666                                 } else if (strcmp(argv[i],
667                                     "-print-multi-os-directory") == 0) {
668                                         printf("%s\n"MULTIOSDIR);
669                                         return 0;
ragge
1.162
670                                 } else
ragge
1.128
671                                         errorx(1"unknown option %s"argv[i]);
672                                 break;
673
gmcgarry
1.145
674                         case 'r':
675                                 rflag = 1;
676                                 break;
677
ragge
1.128
678                         case 'x':
679                                 t = &argv[i][2];
680                                 if (*t == 0)
681                                         t = argv[++i];
682                                 if (strcmp(t"c") == 0)
683                                         xcflag = 1/* default */
plunky
1.217
684                                 else if (strcmp(t"assembler") == 0)
685                                         xasm = 1;
ragge
1.128
686                                 else if (strcmp(t"assembler-with-cpp") == 0)
687                                         ascpp = 1;
688                                 else if (strcmp(t"c++") == 0)
689                                         cxxflag++;
690                                 else
691                                         xlist[xnum++] = argv[i];
692                                 break;
693                         case 't':
694                                 tflag++;
695                                 break;
696                         case 'S':
697                                 sflag++;
698                                 cflag++;
699                                 break;
700                         case 'o':
701                                 if (outfile)
702                                         errorx(8"too many -o");
703                                 outfile = argv[++i];
704                                 break;
705                         case 'O':
plunky
1.203
706                                 if (argv[i][2] == '\0')
707                                         Oflag++;
708                                 else if (argv[i][3] == '\0' && isdigit((unsigned char)argv[i][2]))
709                                         Oflag = argv[i][2] - '0';
plunky
1.211
710                                 else if (argv[i][3] == '\0' && argv[i][2] == 's')
711                                         Oflag = 1;      /* optimize for space only */
ragge
1.128
712                                 else
plunky
1.203
713                                         error("unknown option %s"argv[i]);
ragge
1.128
714                                 break;
715                         case 'E':
716                                 Eflag++;
717                                 break;
718                         case 'P':
719                                 pflag++;
720                                 *pv++ = argv[i];
721                         case 'c':
gmcgarry
1.172
722 #ifdef os_darwin
723                                 if (strcmp(argv[i], "-compatibility_version") == 0) {
724                                         llist[nl++] = argv[i];
725                                         llist[nl++] = argv[++i];
726                                 } else if (strcmp(argv[i], "-current_version") == 0) {
727                                         llist[nl++] = argv[i];
728                                         llist[nl++] = argv[++i];
729                                 } else
730 #endif
731                                         cflag++;
ragge
1.128
732                                 break;
733 #if 0
734                         case '2':
735                                 if(argv[i][2] == '\0')
736                                         pref = "/lib/crt2.o";
737                                 else {
738                                         pref = "/lib/crt20.o";
739                                 }
740                                 break;
741 #endif
742                         case 'M':
ragge
1.216
743                                 switch (argv[i][2]) {
744                                 case '\0'Mflag++; break;
745                                 case 'P'MPflag++; break;
746                                 case 'F'outfile = argv[++i]; break;
747                                 case 'T':
748                                 case 'Q':
749                                         j = strlen(argv[++i]);
750                                         t = copy("-xM.,"j);
751                                         strlcat(targv[i], j+6);
752                                         t[3] = argv[i-1][2];
753                                         Mfiles[nMfiles++] = t;
754                                         break;
755                                 default:
756                                         error("unknown option '%s'"argv[i]);
757                                 }
ragge
1.128
758                                 break;
759
760                         case 'd':
gmcgarry
1.144
761 #ifdef os_darwin
762                                 if (strcmp(argv[i], "-dynamiclib") == 0) {
763                                         shared = 1;
764                                 } else
765 #endif
ragge
1.128
766                                 break;
767                         case 'v':
768                                 printf("%s\n"VERSSTR);
769                                 vflag++;
770                                 break;
771
772                         case 's':
gmcgarry
1.144
773 #ifndef os_darwin
774                                 if (strcmp(argv[i], "-shared") == 0) {
ragge
1.128
775                                         shared = 1;
gmcgarry
1.144
776                                 } else
777 #endif
778                                 if (strcmp(argv[i], "-static") == 0) {
779                                         Bstatic = 1;
plunky
1.189
780                                 } else if (strcmp(argv[i], "-symbolic") == 0) {
781                                         llist[nl++] = "-Bsymbolic";
ragge
1.128
782                                 } else if (strncmp(argv[i], "-std"4) == 0) {
ragge
1.190
783                                         if (strcmp(&argv[i][5], "gnu99") == 0 ||
ragge
1.198
784                                             strcmp(&argv[i][5], "gnu9x") == 0)
785                                                 xgnu99 = 1;
786                                         if (strcmp(&argv[i][5], "gnu89") == 0)
787                                                 xgnu89 = 1;
ragge
1.128
788                                 } else
789                                         goto passa;
790                                 break;
791                         }
792                 } else {
793                 passa:
794                         t = argv[i];
795                         if (*argv[i] == '-' && argv[i][1] == 'L')
796                                 ;
ragge
1.198
797                         else if ((cxxsuf(getsufp(t)) && cxxflag) ||
798                             (c=getsuf(t))=='c' || c=='S' || c=='i' ||
plunky
1.217
799                             c=='s'|| Eflag || xcflag || xasm) {
ragge
1.128
800                                 clist[nc++] = t;
801                                 if (nc>=MAXFIL) {
802                                         error("Too many source files");
803                                         exit(1);
804                                 }
805                         }
806
807                         /* Check for duplicate .o files. */
808                         for (j = getsuf(t) == 'o' ? 0 : nlj < nlj++) {
809                                 if (strcmp(llist[j], t) == 0)
810                                         break;
811                         }
gmcgarry
1.150
812                         if ((c=getsuf(t))!='c' && c!='S' &&
ragge
1.212
813                             c!='s' && c!='i' && j==nl &&
plunky
1.217
814                             !(cxxsuf(getsufp(t)) && cxxflag) && !xasm) {
ragge
1.128
815                                 llist[nl++] = t;
816                                 if (nl >= MAXLIB) {
817                                         error("Too many object/library files");
818                                         exit(1);
819                                 }
820                                 if (getsuf(t)=='o')
821                                         nxo++;
822                         }
823                 }
824         }
825         /* Sanity checking */
ragge
1.216
826         if (cppflag) {
827                 if (nc == 0)
828                         clist[nc++] = "-";
829                 else if (nc > 2 || (nc == 2 && outfile))
830                         errorx(8"too many files");
831                 else if (nc == 2)
832                         outfile = clist[--nc];
833         }
ragge
1.128
834         if (nc == 0 && nl == 0)
835                 errorx(8"no input files");
836         if (outfile && (cflag || sflag || Eflag) && nc > 1)
837                 errorx(8"-o given with -c || -E || -S and more than one file");
838         if (outfile && clist[0] && strcmp(outfileclist[0]) == 0)
839                 errorx(8"output file will be clobbered");
gmcgarry
1.150
840         if (nc==0)
ragge
1.128
841                 goto nocom;
842         if (pflag==0) {
843                 if (!sflag)
844                         tmp3 = gettmp();
845                 tmp4 = gettmp();
846         }
847         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
848                 signal(SIGINTidexit);
849         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
850                 signal(SIGTERMidexit);
851 #ifdef MULTITARGET
plunky
1.186
852         pass0 = cat(LIBEXECDIR "/ccom_"mach);
ragge
1.128
853 #endif
854         pvt = pv;
855         for (i=0i<nci++) {
856                 /*
857                  * C preprocessor
858                  */
859                 if (nc>1 && !Eflag)
860                         printf("%s:\n"clist[i]);
861                 onlyas = 0;
862                 assource = tmp3;
863                 if (getsuf(clist[i])=='S')
864                         ascpp = 1;
865                 if (getsuf(clist[i])=='i') {
866                         if(Eflag)
867                                 continue;
868                         goto com;
869                 } else if (ascpp) {
870                         onlyas = 1;
plunky
1.217
871                 } else if (xasm || getsuf(clist[i])=='s') {
ragge
1.128
872                         assource = clist[i];
873                         goto assemble;
874                 }
875                 if (pflag)
876                         tmp4 = setsuf(clist[i], 'i');
877                 na = 0;
878                 av[na++] = "cpp";
879                 if (vflag)
880                         av[na++] = "-v";
881                 av[na++] = "-D__PCC__=" MKS(PCC_MAJOR);
882                 av[na++] = "-D__PCC_MINOR__=" MKS(PCC_MINOR);
883                 av[na++] = "-D__PCC_MINORMINOR__=" MKS(PCC_MINORMINOR);
gmcgarry
1.156
884 #ifndef os_win32
ragge
1.155
885 #ifdef GCC_COMPAT
886                 av[na++] = "-D__GNUC__=4";
887                 av[na++] = "-D__GNUC_MINOR__=3";
888                 av[na++] = "-D__GNUC_PATCHLEVEL__=1";
ragge
1.198
889                 if (xgnu89)
plunky
1.208
890                         av[na++] = "-D__GNUC_GNU_INLINE__";
ragge
1.191
891                 else
plunky
1.208
892                         av[na++] = "-D__GNUC_STDC_INLINE__";
ragge
1.170
893 #endif
894 #endif
ragge
1.166
895                 av[na++] = "-D__VERSION__=" MKS(VERSSTR);
ragge
1.167
896                 av[na++] = "-D__SCHAR_MAX__=" MKS(MAX_CHAR);
897                 av[na++] = "-D__SHRT_MAX__=" MKS(MAX_SHORT);
898                 av[na++] = "-D__INT_MAX__=" MKS(MAX_INT);
899                 av[na++] = "-D__LONG_MAX__=" MKS(MAX_LONG);
900                 av[na++] = "-D__LONG_LONG_MAX__=" MKS(MAX_LONGLONG);
plunky
1.214
901                 if (freestanding)
902                         av[na++] = "-D__STDC_HOSTED__=0";
903                 else
904                         av[na++] = "-D__STDC_HOSTED__=1";
ragge
1.212
905                 if (cxxflag)
906                         av[na++] = "-D__cplusplus";
plunky
1.209
907                 if (xuchar)
plunky
1.196
908                         av[na++] = "-D__CHAR_UNSIGNED__";
ragge
1.128
909                 if (ascpp)
910                         av[na++] = "-D__ASSEMBLER__";
911                 if (sspflag)
plunky
1.208
912                         av[na++] = "-D__SSP__";
ragge
1.128
913                 if (pthreads)
914                         av[na++] = "-D_PTHREADS";
915                 if (Mflag)
916                         av[na++] = "-M";
ragge
1.216
917                 if (MPflag)
918                         av[na++] = "-xMP";
919                 for (j = 0j < nMfilesj++)
920                         av[na++] = Mfiles[j];
ragge
1.160
921                 if (Oflag)
922                         av[na++] = "-D__OPTIMIZE__";
923 #ifdef GCC_COMPAT
924                 av[na++] = "-D__REGISTER_PREFIX__=" REGISTER_PREFIX;
925                 av[na++] = "-D__USER_LABEL_PREFIX__=" USER_LABEL_PREFIX;
926 #endif
ragge
1.128
927                 for (j = 0cppadd[j]; j++)
928                         av[na++] = cppadd[j];
ragge
1.218
929                 STRLIST_FOREACH(s, &preprocessor_flags) {
930                         av[na++] = s->value;
931                 }
ragge
1.219
932                 STRLIST_FOREACH(s, &incdirs) {
933                         av[na++] = s->value;
934                 }
gmcgarry
1.149
935                 av[na++] = "-D__STDC_ISO_10646__=200009L";
ragge
1.157
936                 av[na++] = "-D__WCHAR_TYPE__=" WCT;
937                 av[na++] = "-D__SIZEOF_WCHAR_T__=" MKS(WCHAR_SIZE);
938                 av[na++] = "-D__WCHAR_MAX__=" WCM;
plunky
1.192
939                 av[na++] = "-D__WINT_TYPE__=" PCC_WINT_TYPE;
940                 av[na++] = "-D__SIZE_TYPE__=" PCC_SIZE_TYPE;
ragge
1.161
941                 av[na++] = "-D__PTRDIFF_TYPE__=" PCC_PTRDIFF_TYPE;
gmcgarry
1.142
942                 av[na++] = "-D__SIZEOF_WINT_T__=4";
plunky
1.201
943 #if defined(os_darwin) || defined(os_netbsd)
944                 av[na++] = "-D__FLT_RADIX__=2";
945                 av[na++] = "-D__FLT_DIG__=6";
946                 av[na++] = "-D__FLT_EPSILON__=1.19209290e-07F";
947                 av[na++] = "-D__FLT_MANT_DIG__=24";
948                 av[na++] = "-D__FLT_MAX_10_EXP__=38";
949                 av[na++] = "-D__FLT_MAX_EXP__=128";
950                 av[na++] = "-D__FLT_MAX__=3.40282347e+38F";
951                 av[na++] = "-D__FLT_MIN_10_EXP__=(-37)";
952                 av[na++] = "-D__FLT_MIN_EXP__=(-125)";
gmcgarry
1.171
953                 av[na++] = "-D__FLT_MIN__=1.17549435e-38F";
plunky
1.201
954                 av[na++] = "-D__DBL_DIG__=15";
955                 av[na++] = "-D__DBL_EPSILON__=2.2204460492503131e-16";
956                 av[na++] = "-D__DBL_MANT_DIG__=53";