Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20090219104314

Diff

Diff from 1.146 to:

Annotations

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

Annotated File View

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