Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:plunky:20110826200050

Diff

Diff from 1.204 to:

Annotations

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

Annotated File View

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