Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20090516074734

Diff

Diff from 1.152 to:

Annotations

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

Annotated File View

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