Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20090310073411

Diff

Diff from 1.149 to:

Annotations

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

Annotated File View

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