Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20110221232128

Diff

Diff from 1.171 to:

Annotations

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

Annotated File View

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