Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20110124145412

Diff

Diff from 1.167 to:

Annotations

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

Annotated File View

ragge
1.167
1 /*      $Id: cc.c,v 1.167 2011/01/24 14:54:12 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
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;
362                                 } else if (strcmp(argv[i], "--param") == 0)
ragge
1.128
363                                         /* NOTHING YET */;
364                                 else
gmcgarry
1.148
365                                         goto passa;
ragge
1.128
366                                 break;
367
368                         case 'B'/* other search paths for binaries */
369                                 Bflag = &argv[i][2];
370                                 break;
371
372 #ifdef MULTITARGET
373                         case 'b':
374                                 t = &argv[i][2];
375                                 if (*t == '\0' && i + 1 < argc) {
376                                         t = argv[i+1];
377                                         i++;
378                                 }
379                                 if (strncmp(t"?"1) == 0) {
380                                         /* show machine targets */
381                                         printf("Available machine targets:");
382                                         for (j=0cppmds[j].machj++)
383                                                 printf(" %s",cppmds[j].mach);
384                                         printf("\n");
385                                         exit(0);
386                                 }
387                                 for (j=0cppmds[j].machj++)
388                                         if (strcmp(tcppmds[j].mach) == 0) {
389                                                 mach = cppmds[j].mach;
390                                                 break;
391                                         }
392                                 if (cppmds[j].mach == NULL)
393                                         errorx(1"unknown target arch %s"t);
394                                 break;
395 #endif
396
397                         case 'X':
398                                 Xflag++;
399                                 break;
400                         case 'W'/* Ignore (most of) W-flags */
401                                 if (strncmp(argv[i], "-Wl,"4) == 0) {
402                                         /* options to the linker */
403                                         t = &argv[i][4];
404                                         while ((u = strchr(t','))) {
405                                                 *u++ = 0;
406                                                 llist[nl++] = t;
407                                                 t = u;
408                                         }
409                                         llist[nl++] = t;
410                                 } else if (strncmp(argv[i], "-Wa,"4) == 0) {
411                                         /* options to the assembler */
412                                         t = &argv[i][4];
413                                         while ((u = strchr(t','))) {
414                                                 *u++ = 0;
415                                                 aslist[nas++] = t;
416                                                 t = u;
417                                         }
418                                         aslist[nas++] = t;
ragge
1.137
419                                 } else if (strncmp(argv[i], "-Wc,"4) == 0) {
420                                         /* options to ccom */
421                                         t = &argv[i][4];
422                                         while ((u = strchr(t','))) {
423                                                 *u++ = 0;
424                                                 wlist[nw++] = t;
425                                                 t = u;
426                                         }
427                                         wlist[nw++] = t;
ragge
1.128
428                                 } else if (strncmp(argv[i], "-Wp,"4) == 0) {
429                                         /* preprocessor */
gmcgarry
1.163
430                                         t = &argv[i][4];
431                                         while ((u = strchr(t','))) {
432                                                 *u++ = 0;
433                                                 cpplist[ncpp++] = t;
434                                                 t = u;
435                                         }
436                                         cpplist[ncpp++] = t;
ragge
1.128
437                                 } else if (strcmp(argv[i], "-Wall") == 0) {
438                                         Wallflag = 1;
439                                 } else if (strcmp(argv[i], "-WW") == 0) {
440                                         Wflag = 1;
441                                 } else {
442                                         /* check and set if available */
443                                         for (Wf = WflagsWf->nameWf++) {
444                                                 if (strcmp(argv[i], Wf->name))
445                                                         continue;
446                                                 wlist[nw++] = Wf->name;
447                                         }
448                                 }
449                                 break;
450
451                         case 'f'/* GCC compatibility flags */
452                                 if (strcmp(argv[i], "-fPIC") == 0)
453                                         kflag = F_PIC;
454                                 else if (strcmp(argv[i], "-fpic") == 0)
455                                         kflag = F_pic;
456                                 else if (strcmp(argv[i],
457                                     "-fsigned-char") == 0)
458                                         flist[nf++] = argv[i];
459                                 else if (strcmp(argv[i],
460                                     "-fno-signed-char") == 0)
461                                         flist[nf++] = argv[i];
462                                 else if (strcmp(argv[i],
463                                     "-funsigned-char") == 0)
464                                         flist[nf++] = argv[i];
465                                 else if (strcmp(argv[i],
466                                     "-fno-unsigned-char") == 0)
467                                         flist[nf++] = argv[i];
468                                 else if (strcmp(argv[i],
469                                     "-fstack-protector") == 0) {
470                                         flist[nf++] = argv[i];
471                                         sspflag++;
472                                 } else if (strcmp(argv[i],
473                                     "-fstack-protector-all") == 0) {
474                                         flist[nf++] = argv[i];
475                                         sspflag++;
476                                 } else if (strcmp(argv[i],
477                                     "-fno-stack-protector") == 0) {
478                                         flist[nf++] = argv[i];
479                                         sspflag = 0;
480                                 } else if (strcmp(argv[i],
481                                     "-fno-stack-protector-all") == 0) {
482                                         flist[nf++] = argv[i];
483                                         sspflag = 0;
484                                 }
485                                 /* silently ignore the rest */
486                                 break;
487
488                         case 'g'/* create debug output */
489                                 gflag++;
490                                 break;
491
492                         case 'i':
493                                 if (strcmp(argv[i], "-isystem") == 0) {
494                                         *pv++ = "-S";
495                                         *pv++ = argv[++i];
496                                 } else if (strcmp(argv[i], "-include") == 0) {
497                                         *pv++ = "-i";
498                                         *pv++ = argv[++i];
499                                 } else if (strcmp(argv[i], "-idirafter") == 0) {
500                                         idirafter = argv[++i];
501                                 } else
502                                         goto passa;
503                                 break;
504
505                         case 'k'/* generate PIC code */
506                                 kflag = F_pic;
507                                 break;
508
509                         case 'm'/* target-dependent options */
ragge
1.164
510 #ifdef mach_amd64
511                                 /* need to call i386 ccom for this */
512                                 if (strcmp(argv[i], "-m32") == 0) {
513                                         pass0 = LIBEXECDIR "/ccom_i386";
514                                         amd64_i386 = 1;
515                                         break;
516                                 }
517 #endif
ragge
1.128
518                                 mlist[nm++] = argv[i];
519                                 break;
520
521                         case 'n'/* handle -n flags */
522                                 if (strcmp(argv[i], "-nostdinc") == 0)
523                                         nostdinc++;
524                                 else if (strcmp(argv[i], "-nostdlib") == 0) {
525                                         nostdlib++;
526                                         nostartfiles++;
527                                 } else if (strcmp(argv[i], "-nostartfiles") == 0)
528                                         nostartfiles = 1;
529                                 else
530                                         goto passa;
531                                 break;
532
533                         case 'p':
534                                 if (strcmp(argv[i], "-pg") == 0 ||
535                                     strcmp(argv[i], "-p") == 0)
536                                         pgflag++;
537                                 else if (strcmp(argv[i], "-pthread") == 0)
538                                         pthreads++;
539                                 else if (strcmp(argv[i], "-pipe") == 0)
540                                         /* NOTHING YET */;
gmcgarry
1.144
541                                 else if (strcmp(argv[i], "-pedantic") == 0)
542                                         /* NOTHING YET */;
ragge
1.162
543                                 else if (strcmp(argv[i],
544                                     "-print-prog-name=ld") == 0) {
545                                         printf("%s\n"LINKER);
546                                         return 0;
547                                 } else
ragge
1.128
548                                         errorx(1"unknown option %s"argv[i]);
549                                 break;
550
gmcgarry
1.145
551                         case 'r':
552                                 rflag = 1;
553                                 break;
554
ragge
1.128
555                         case 'x':
556                                 t = &argv[i][2];
557                                 if (*t == 0)
558                                         t = argv[++i];
559                                 if (strcmp(t"c") == 0)
560                                         xcflag = 1/* default */
561                                 else if (strcmp(t"assembler-with-cpp") == 0)
562                                         ascpp = 1;
563 #ifdef notyet
564                                 else if (strcmp(t"c++") == 0)
565                                         cxxflag++;
566 #endif
567                                 else
568                                         xlist[xnum++] = argv[i];
569                                 break;
570                         case 't':
571                                 tflag++;
572                                 break;
573                         case 'S':
574                                 sflag++;
575                                 cflag++;
576                                 break;
577                         case 'o':
578                                 if (outfile)
579                                         errorx(8"too many -o");
580                                 outfile = argv[++i];
581                                 break;
582                         case 'O':
583                                 if (argv[i][2] == '0')
584                                         Oflag = 0;
585                                 else
586                                         Oflag++;
587                                 break;
588                         case 'E':
589                                 Eflag++;
590                                 break;
591                         case 'P':
592                                 pflag++;
593                                 *pv++ = argv[i];
594                         case 'c':
595                                 cflag++;
596                                 break;
597
598 #if 0
599                         case '2':
600                                 if(argv[i][2] == '\0')
601                                         pref = "/lib/crt2.o";
602                                 else {
603                                         pref = "/lib/crt20.o";
604                                 }
605                                 break;
606 #endif
607                         case 'C':
gmcgarry
1.163
608                                 cpplist[ncpp++] = argv[i];
ragge
1.128
609                                 break;
610                         case 'D':
611                         case 'I':
612                         case 'U':
613                                 *pv++ = argv[i];
614                                 if (argv[i][2] == 0)
615                                         *pv++ = argv[++i];
616                                 if (pv >= ptemp+MAXOPT) {
617                                         error("Too many DIU options");
618                                         --pv;
619                                 }
620                                 break;
621
622                         case 'M':
623                                 Mflag++;
624                                 break;
625
626                         case 'd':
gmcgarry
1.144
627 #ifdef os_darwin
628                                 if (strcmp(argv[i], "-dynamiclib") == 0) {
629                                         shared = 1;
630                                 } else
631 #endif
632                                 if (strcmp(argv[i], "-d") == 0) {
633                                         dflag++;
634                                         strlcpy(alistargv[i], sizeof (alist));
635                                 }
ragge
1.128
636                                 break;
637                         case 'v':
638                                 printf("%s\n"VERSSTR);
639                                 vflag++;
640                                 break;
641
642                         case 's':
gmcgarry
1.144
643 #ifndef os_darwin
644                                 if (strcmp(argv[i], "-shared") == 0) {
ragge
1.128
645                                         shared = 1;
646 #ifndef os_win32
647                                         nostdlib = 1;
648 #endif
gmcgarry
1.144
649                                 } else
650 #endif
651                                 if (strcmp(argv[i], "-static") == 0) {
652                                         Bstatic = 1;
ragge
1.128
653                                 } else if (strncmp(argv[i], "-std"4) == 0) {
654                                         /* ignore gcc -std= */;
655                                 } else
656                                         goto passa;
657                                 break;
658                         }
659                 } else {
660                 passa:
661                         t = argv[i];
662                         if (*argv[i] == '-' && argv[i][1] == 'L')
663                                 ;
664                         else if((c=getsuf(t))=='c' || c=='S' || c=='i' ||
665                             c=='s'|| Eflag || xcflag) {
666                                 clist[nc++] = t;
667                                 if (nc>=MAXFIL) {
668                                         error("Too many source files");
669                                         exit(1);
670                                 }
671                         }
672
673                         /* Check for duplicate .o files. */
674                         for (j = getsuf(t) == 'o' ? 0 : nlj < nlj++) {
675                                 if (strcmp(llist[j], t) == 0)
676                                         break;
677                         }
gmcgarry
1.150
678                         if ((c=getsuf(t))!='c' && c!='S' &&
679                             c!='s' && c!='i' && j==nl) {
ragge
1.128
680                                 llist[nl++] = t;
681                                 if (nl >= MAXLIB) {
682                                         error("Too many object/library files");
683                                         exit(1);
684                                 }
685                                 if (getsuf(t)=='o')
686                                         nxo++;
687                         }
688                 }
689         }
690         /* Sanity checking */
691         if (nc == 0 && nl == 0)
692                 errorx(8"no input files");
693         if (outfile && (cflag || sflag || Eflag) && nc > 1)
694                 errorx(8"-o given with -c || -E || -S and more than one file");
695         if (outfile && clist[0] && strcmp(outfileclist[0]) == 0)
696                 errorx(8"output file will be clobbered");
gmcgarry
1.150
697         if (nc==0)
ragge
1.128
698                 goto nocom;
699         if (pflag==0) {
700                 if (!sflag)
701                         tmp3 = gettmp();
702                 tmp4 = gettmp();
703         }
704         if (Bflag) {
gmcgarry
1.153
705                 altincdir = Bflag;
ragge
1.128
706                 pccincdir = Bflag;
707                 pcclibdir = Bflag;
708         }
709         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
710                 signal(SIGINTidexit);
711         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
712                 signal(SIGTERMidexit);
713 #ifdef MULTITARGET
ragge
1.133
714         pass0 = copy(LIBEXECDIR "/ccom_"k = strlen(mach));
715         strlcat(pass0machsizeof(LIBEXECDIR "/ccom_") + k);
ragge
1.128
716 #endif
717         pvt = pv;
718         for (i=0i<nci++) {
719                 /*
720                  * C preprocessor
721                  */
722                 if (nc>1 && !Eflag)
723                         printf("%s:\n"clist[i]);
724                 onlyas = 0;
725                 assource = tmp3;
726                 if (getsuf(clist[i])=='S')
727                         ascpp = 1;
728                 if (getsuf(clist[i])=='i') {
729                         if(Eflag)
730                                 continue;
731                         goto com;
732                 } else if (ascpp) {
733                         onlyas = 1;
734                 } else if (getsuf(clist[i])=='s') {
735                         assource = clist[i];
736                         goto assemble;
737                 }
738                 if (pflag)
739                         tmp4 = setsuf(clist[i], 'i');
740                 na = 0;
741                 av[na++] = "cpp";
742                 if (vflag)
743                         av[na++] = "-v";
744                 av[na++] = "-D__PCC__=" MKS(PCC_MAJOR);
745                 av[na++] = "-D__PCC_MINOR__=" MKS(PCC_MINOR);
746                 av[na++] = "-D__PCC_MINORMINOR__=" MKS(PCC_MINORMINOR);
gmcgarry
1.156
747 #ifndef os_win32
ragge
1.155
748 #ifdef GCC_COMPAT
749                 av[na++] = "-D__GNUC__=4";
750                 av[na++] = "-D__GNUC_MINOR__=3";
751                 av[na++] = "-D__GNUC_PATCHLEVEL__=1";
752                 av[na++] = "-D__GNUC_STDC_INLINE__=1";
ragge
1.166
753                 av[na++] = "-D__VERSION__=" MKS(VERSSTR);
ragge
1.167
754                 av[na++] = "-D__SCHAR_MAX__=" MKS(MAX_CHAR);
755                 av[na++] = "-D__SHRT_MAX__=" MKS(MAX_SHORT);
756                 av[na++] = "-D__INT_MAX__=" MKS(MAX_INT);
757                 av[na++] = "-D__LONG_MAX__=" MKS(MAX_LONG);
758                 av[na++] = "-D__LONG_LONG_MAX__=" MKS(MAX_LONGLONG);
ragge
1.155
759 #endif
gmcgarry
1.156
760 #endif
ragge
1.128
761                 if (ascpp)
762                         av[na++] = "-D__ASSEMBLER__";
763                 if (sspflag)
764                         av[na++] = "-D__SSP__=1";
765                 if (pthreads)
766                         av[na++] = "-D_PTHREADS";
767                 if (Mflag)
768                         av[na++] = "-M";
ragge
1.160
769                 if (Oflag)
770                         av[na++] = "-D__OPTIMIZE__";
771 #ifdef GCC_COMPAT
772                 av[na++] = "-D__REGISTER_PREFIX__=" REGISTER_PREFIX;
773                 av[na++] = "-D__USER_LABEL_PREFIX__=" USER_LABEL_PREFIX;
774                 if (Oflag)
775                         av[na++] = "-D__OPTIMIZE__";
776 #endif
ragge
1.128
777                 if (dflag)
778                         av[na++] = alist;
779                 for (j = 0cppadd[j]; j++)
780                         av[na++] = cppadd[j];
gmcgarry
1.163
781                 for (j = 0j < ncppj++)
782                         av[na++] = cpplist[j];
gmcgarry
1.149
783                 av[na++] = "-D__STDC_ISO_10646__=200009L";
ragge
1.157
784                 av[na++] = "-D__WCHAR_TYPE__=" WCT;
785                 av[na++] = "-D__SIZEOF_WCHAR_T__=" MKS(WCHAR_SIZE);
786                 av[na++] = "-D__WCHAR_MAX__=" WCM;
gmcgarry
1.142
787                 av[na++] = "-D__WINT_TYPE__=unsigned int";
gmcgarry
1.149
788                 av[na++] = "-D__SIZE_TYPE__=unsigned long";
ragge
1.161
789                 av[na++] = "-D__PTRDIFF_TYPE__=" PCC_PTRDIFF_TYPE;
gmcgarry
1.142
790                 av[na++] = "-D__SIZEOF_WINT_T__=4";
ragge
1.128
791 #ifdef MULTITARGET
792                 for (k = 0cppmds[k].machk++) {
793                         if (strcmp(cppmds[k].machmach) != 0)
794                                 continue;
795                         for (j = 0cppmds[k].cppmdadd[j]; j++)
796                                 av[na++] = cppmds[k].cppmdadd[j];
797                         break;
798                 }
799 #else
800                 for (j = 0cppmdadd[j]; j++)
801                         av[na++] = cppmdadd[j];
802 #endif
803                 if (tflag)
804                         av[na++] = "-t";
805                 for(pv=ptemppv <pvtpv++)
806                         av[na++] = *pv;
gmcgarry
1.153
807                 if (!nostdinc) {
808                         av[na++] = "-S"av[na++] = altincdir;
ragge
1.128
809                         av[na++] = "-S"av[na++] = incdir;
gmcgarry
1.153
810                         av[na++] = "-S"av[na++] = pccincdir;
811                 }
ragge
1.128
812                 if (idirafter) {
813                         av[na++] = "-I";
814                         av[na++] = idirafter;
815                 }
816                 av[na++] = clist[i];
817                 if (!Eflag && !Mflag)
818                         av[na++] = tmp4;
ragge
1.141
819                 if ((Eflag || Mflag) && outfile)
ragge
1.128
820                          ermfile = av[na++] = outfile;
821                 av[na++]=0;
gmcgarry
1.140
822                 if (callsys(passpav)) {
823                         exfail++;
824                         eflag++;
825                 }
ragge
1.128
826                 if (Eflag || Mflag)
827                         continue;
828                 if (onlyas) {
829                         assource = tmp4;
830                         goto assemble;
831                 }
832
833                 /*
834                  * C compiler
835                  */
836         com:
837                 na = 0;
838                 av[na++]= "ccom";
839                 if (Wallflag) {
840                         /* Set only the same flags as gcc */
841                         for (Wf = WflagsWf->nameWf++) {
842                                 if (Wf->flags != INWALL)
843                                         continue;
844                                 av[na++] = Wf->name;
845                         }
846                 }
847                 if (Wflag) {
848                         /* set all positive flags */
849                         for (Wf = WflagsWf->nameWf++) {
850                                 if (Wf->flags == NEGATIVE)
851                                         continue;
852                                 av[na++] = Wf->name;
853                         }
854                 }
855                 for (j = 0j < nwj++)
856                         av[na++] = wlist[j];
857                 for (j = 0j < nfj++)
858                         av[na++] = flist[j];
ragge
1.159
859 #if !defined(os_sunos) && !defined(mach_i386)
ragge
1.128
860                 if (vflag)
861                         av[na++] = "-v";
ragge
1.159
862 #endif
ragge
1.128
863                 if (pgflag)
864                         av[na++] = "-p";
865                 if (gflag)
866                         av[na++] = "-g";
867 #ifdef os_darwin
868                 /* darwin always wants PIC compilation */
869                 if (!Bstatic)
870                         av[na++] = "-k";
ragge
1.159
871 #elif defined(os_sunos) && defined(mach_i386)
872                 if (kflag) {
873                         av[na++] = "-K";
874                         av[na++] = "pic";
875                 }
ragge
1.128
876 #else
877                 if (kflag)
878                         av[na++] = "-k";
879 #endif
880                 if (Oflag) {
881                         av[na++] = "-xtemps";
882                         av[na++] = "-xdeljumps";
ragge
1.133
883                         av[na++] = "-xinline";
ragge
1.128
884                 }
885                 for (j = 0j < xnumj++)
886                         av[na++] = xlist[j];
887                 for (j = 0j < nmj++)
888                         av[na++] = mlist[j];
889                 if (getsuf(clist[i])=='i')
890                         av[na++] = clist[i];
891                 else
892                         av[na++] = tmp4/* created by cpp */
893                 if (pflag || exfail)
894                         {
895                         cflag++;
896                         continue;
897                         }
898                 if(sflag) {
899                         if (outfile)
900                                 tmp3 = outfile;
901                         else
902                                 tmp3 = setsuf(clist[i], 's');
903                 }
904                 ermfile = av[na++] = tmp3;
905 #if 0
906                 if (proflag) {
907                         av[3] = "-XP";
908                         av[4] = 0;
909                 } else
910                         av[3] = 0;
911 #endif
912                 av[na++] = NULL;
913                 if (callsys(pass0av)) {
914                         cflag++;
915                         eflag++;
916                         continue;
917                 }
918                 if (sflag)
919                         continue;
920
921                 /*
922                  * Assembler
923                  */
924         assemble:
925                 na = 0;
926                 av[na++] = as;
927                 for (j = 0j < nasj++)
928                         av[na++] = aslist[j];
gmcgarry
1.149
929 #if defined(os_win32) && defined(USE_YASM)
930                 av[na++] = "-p";
931                 av[na++] = "gnu";
932                 av[na++] = "-f";
933                 av[na++] = "win32";
934 #endif
ragge
1.128
935 #if defined(os_sunos) && defined(mach_sparc64)
936                 av[na++] = "-m64";
937 #endif
938 #if defined(os_darwin)
939                 if (Bstatic)
940                         av[na++] = "-static";
941 #endif
942                 if (vflag)
943                         av[na++] = "-v";
944                 if (kflag)
945                         av[na++] = "-k";
ragge
1.164
946 #ifdef mach_amd64
947                 if (amd64_i386)
948                         av[na++] = "--32";
949 #endif
ragge
1.128
950                 av[na++] = "-o";
951                 if (outfile && cflag)
952                         ermfile = av[na++] = outfile;
gmcgarry
1.150
953                 else if (cflag)
954                         ermfile = av[na++] = olist[i] = setsuf(clist[i], 'o');
ragge
1.128
955                 else
gmcgarry
1.150
956                         ermfile = av[na++] = olist[i] = gettmp();
ragge
1.128
957                 av[na++] = assource;
958                 if (dflag)
959                         av[na++] = alist;
960                 av[na++] = 0;
961                 if (callsys(asav)) {
962                         cflag++;
963                         eflag++;
964                         cunlink(tmp4);
965                         continue;
966                 }
967                 cunlink(tmp4);
968         }
969
970         if (Eflag || Mflag)
971                 dexit(eflag);
972
973         /*
974          * Linker
975          */
976 nocom:
gmcgarry
1.150
977         if (cflag==0 && nc+nl != 0) {
ragge
1.128
978                 j = 0;
979                 av[j++] = ld;
980 #ifndef MSLINKER
981                 if (vflag)
982                         av[j++] = "-v";
983 #endif
gmcgarry
1.131
984 #if !defined(os_sunos) && !defined(os_win32) && !defined(os_darwin)
ragge
1.128
985                 av[j++] = "-X";
986 #endif
987                 if (shared) {
gmcgarry
1.144
988 #ifdef os_darwin
989                         av[j++] = "-dylib";
990 #else
ragge
1.128
991                         av[j++] = "-shared";
gmcgarry
1.144
992 #endif
ragge
1.128
993 #ifdef os_win32
994                         av[j++] = "-Bdynamic";
995 #endif
996 #ifndef os_sunos
997                 } else {
998 #ifndef os_win32
999 #ifndef os_darwin
1000                         av[j++] = "-d";
1001 #endif
gmcgarry
1.145
1002                         if (rflag) {
1003                                 av[j++] = "-r";
1004                         } else {
1005                                 av[j++] = "-e";
1006                                 av[j++] = STARTLABEL;
1007                         }
ragge
1.128
1008 #endif
1009 #endif
1010                         if (Bstatic == 0) { /* Dynamic linkage */
1011 #ifdef DYNLINKER
1012                                 for (i = 0dynlinker[i]; i++)
1013                                         av[j++] = dynlinker[i];
1014 #endif
1015                         } else {
1016 #ifdef os_darwin
1017                                 av[j++] = "-static";
1018 #else
1019                                 av[j++] = "-Bstatic";
1020 #endif
1021                         }
1022                 }
1023                 if (outfile) {
1024 #ifdef MSLINKER
gmcgarry
1.135
1025 #define OUTSTR  "/OUT:"
1026                         char *s = copy(OUTSTRi = strlen(outfile));
1027                         strlcat(soutfilesizeof(OUTSTR) + i);
ragge
1.128
1028                         av[j++] = s;
1029 #else
1030                         av[j++] = "-o";
1031                         av[j++] = outfile;
1032 #endif
1033                 }
1034 #ifdef STARTFILES_S
1035                 if (shared) {
1036                         if (!nostartfiles) {