Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20090214065927

Diff

Diff from 1.144 to:

Annotations

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

Annotated File View

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