Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20090519051535

Diff

Diff from 1.153 to:

Annotations

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

Annotated File View

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