Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20090221214229

Diff

Diff from 1.147 to:

Annotations

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

Annotated File View

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