Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20091114162610

Diff

Diff from 1.155 to:

Annotations

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

Annotated File View

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