Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20100606083545

Diff

Diff from 1.158 to:

Annotations

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

Annotated File View

ragge
1.158
1 /*      $Id: cc.c,v 1.158 2010/06/06 08:35:45 ragge Exp $       */
ragge
1.128
2 /*
3  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * Redistributions of source code and documentation must retain the above
10  * copyright notice, this list of conditions and the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditionsand the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * All advertising materials mentioning features or use of this software
15  * must display the following acknowledgement:
16  *      This product includes software developed or owned by Caldera
17  *      International, Inc.
18  * Neither the name of Caldera International, Inc. nor the names of other
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23  * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
27  * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35
36 /*
37  * Front-end to the C compiler.
38  *
39  * Brief description of its syntax:
40  * - Files that end with .c are passed via cpp->ccom->as->ld
41  * - Files that end with .i are passed via ccom->as->ld
42  * - Files that end with .s are passed as->ld
43  * - Files that end with .o are passed directly to ld
44  * - Multiple files may be given on the command line.
45  * - Unrecognized options are all sent directly to ld.
46  * -c or -S cannot be combined with -o if multiple files are given.
47  *
48  * This file should be rewritten readable.
49  */
50 #include "config.h"
51
52 #include <sys/types.h>
53 #ifdef HAVE_SYS_WAIT_H
54 #include <sys/wait.h>
55 #endif
56
57 #include <ctype.h>
58 #include <errno.h>
59 #include <fcntl.h>
60 #ifdef HAVE_LIBGEN_H
61 #include <libgen.h>
62 #endif
63 #include <signal.h>
64 #include <stdarg.h>
65 #include <stdio.h>
66 #include <stdlib.h>
67 #include <string.h>
68 #ifdef HAVE_UNISTD_H
69 #include <unistd.h>
70 #endif
71
72 #ifdef WIN32
73 #include <windows.h>
74 #include <process.h>
75 #include <io.h>
76 #endif
77
78 #include "compat.h"
79
80 #include "ccconfig.h"
81 /* C command */
82
83 #define MKS(x) _MKS(x)
84 #define _MKS(x) #x
85
86 /*
87  * Many specific definitions, should be declared elsewhere.
88  */
89
90 #ifndef STDINC
91 #define STDINC          "/usr/include/"
92 #endif
93
94 #ifndef LIBDIR
95 #define LIBDIR          "/usr/lib/"
96 #endif
97
98 #ifndef PREPROCESSOR
99 #define PREPROCESSOR    "cpp"
100 #endif
101
102 #ifndef COMPILER
gmcgarry
1.138
103 #define COMPILER        "ccom"
ragge
1.128
104 #endif
105
106 #ifndef ASSEMBLER
107 #define ASSEMBLER       "as"
108 #endif
109
110 #ifndef LINKER
111 #define LINKER          "ld"
112 #endif
113
114 #define OS MKS(TARGOS)
115 #define MACH MKS(TARGMACH)
116 #ifndef PCCINCDIR
117 #define PCCINCDIR       LIBDIR "pcc/" MACH "-" OS "/" PACKAGE_VERSION "/include"
118 #endif
119 #ifndef PCCLIBDIR
120 #define PCCLIBDIR       LIBDIR "pcc/" MACH "-" OS "/" PACKAGE_VERSION "/lib"
121 #endif
122
123 #define MAXFIL 10000
124 #define MAXLIB 10000
125 #define MAXAV  10000
126 #define MAXOPT 100
127 char    *tmp3;
128 char    *tmp4;
129 char    *outfile, *ermfile;
130 char *Bprefix(char *);
gmcgarry
1.150
131 char *copy(char *, int);
132 char *setsuf(char *, char);
ragge
1.128
133 int getsuf(char *);
134 int main(intchar *[]);
135 void error(char *, ...);
136 void errorx(intchar *, ...);
137 int callsys(char [], char *[]);
138 int cunlink(char *);
139 void dexit(int);
140 void idexit(int);
141 char *gettmp(void);
142 void *ccmalloc(int size);
143 #ifdef WIN32
144 char *win32pathsubst(char *);
gmcgarry
1.149
145 char *win32commandline(char *, char *[]);
ragge
1.128
146 #endif
147 char    *av[MAXAV];
148 char    *clist[MAXFIL];
gmcgarry
1.150
149 char    *olist[MAXFIL];
ragge
1.128
150 char    *llist[MAXLIB];
151 char    *aslist[MAXAV];
152 char    alist[20];
153 char    *xlist[100];
154 int     xnum;
155 char    *mlist[100];
156 char    *flist[100];
157 char    *wlist[100];
158 char    *idirafter;
159 int     nm;
160 int     nf;
161 int     nw;
162 int     sspflag;
163 int     Cflag;
gmcgarry
1.147
164 int     Pflag;
gmcgarry
1.134
165 int     Vflag;
ragge
1.128
166 int     dflag;
167 int     pflag;
168 int     sflag;
169 int     cflag;
170 int     eflag;
171 int     gflag;
gmcgarry
1.145
172 int     rflag;
ragge
1.128
173 int     vflag;
174 int     tflag;
175 int     Eflag;
176 int     Oflag;
177 int     kflag;  /* generate PIC/pic code */
178 #define F_PIC   1
179 #define F_pic   2
180 int     Mflag;  /* dependencies only */
181 int     pgflag;
182 int     exfail;
183 int     Xflag;
184 int     Wallflag;
185 int     Wflag;
186 int     nostartfilesBstaticshared;
187 int     nostdincnostdlib;
188 int     onlyas;
189 int     pthreads;
190 int     xcflag;
191 int     ascpp;
192
193 char    *passp = LIBEXECDIR PREPROCESSOR;
194 char    *pass0 = LIBEXECDIR COMPILER;
195 char    *as = ASSEMBLER;
196 char    *ld = LINKER;
197 char    *Bflag;
198 char *cppadd[] = CPPADD;
199 #ifdef DYNLINKER
200 char *dynlinker[] = DYNLINKER;
201 #endif
202 #ifdef CRT0FILE
203 char *crt0file = CRT0FILE;
204 #endif
205 #ifdef CRT0FILE_PROFILE
206 char *crt0file_profile = CRT0FILE_PROFILE;
207 #endif
208 #ifdef STARTFILES
209 char *startfiles[] = STARTFILES;
210 char *endfiles[] = ENDFILES;
211 #endif
212 #ifdef STARTFILES_T
213 char *startfiles_T[] = STARTFILES_T;
214 char *endfiles_T[] = ENDFILES_T;
215 #endif
216 #ifdef STARTFILES_S
217 char *startfiles_S[] = STARTFILES_S;
218 char *endfiles_S[] = ENDFILES_S;
219 #endif
220 #ifdef MULTITARGET
221 char *mach = DEFMACH;
222 struct cppmd {
223         char *mach;
224         char *cppmdadd[MAXCPPMDARGS];
225 };
226
227 struct cppmd cppmds[] = CPPMDADDS;
228 #else
229 char *cppmdadd[] = CPPMDADD;
230 #endif
231 #ifdef LIBCLIBS
232 char *libclibs[] = LIBCLIBS;
233 #else
234 char *libclibs[] = { "-lc"NULL };
235 #endif
236 #ifdef LIBCLIBS_PROFILE
237 char *libclibs_profile[] = LIBCLIBS_PROFILE;
238 #else
239 char *libclibs_profile[] = { "-lc_p"NULL };
240 #endif
241 #ifndef STARTLABEL
242 #define STARTLABEL "__start"
243 #endif
244 char *incdir = STDINC;
gmcgarry
1.153
245 char *altincdir = INCLUDEDIR "pcc/";
gmcgarry
1.136
246 char *libdir = LIBDIR;
ragge
1.128
247 char *pccincdir = PCCINCDIR;
248 char *pcclibdir = PCCLIBDIR;
249
250 /* handle gcc warning emulations */
251 struct Wflags {
252         char *name;
253         int flags;
254 #define INWALL          1
255 #define NEGATIVE        2
256 Wflags[] = {
gmcgarry
1.154
257         { "-Wtruncate"0 },
258         { "-Wno-truncate"NEGATIVE },
ragge
1.128
259         { "-Werror"0 },
260         { "-Wshadow"0 },
261         { "-Wno-shadow"NEGATIVE },
262         { "-Wpointer-sign"INWALL },
263         { "-Wno-pointer-sign"NEGATIVE },
264         { "-Wsign-compare"0 },
265         { "-Wno-sign-compare"NEGATIVE },
266         { "-Wunknown-pragmas"INWALL },
267         { "-Wno-unknown-pragmas"NEGATIVE },
268         { "-Wunreachable-code"0 },
269         { "-Wno-unreachable-code"NEGATIVE },
270         { 00 },
271 };
272
273 #define SZWFL   (sizeof(Wflags)/sizeof(Wflags[0]))
274
ragge
1.158
275 #ifndef USHORT
276 /* copied from mip/manifest.h */
277 #define USHORT          5
278 #define INT             6
279 #define UNSIGNED        7
280 #endif
281
ragge
1.157
282 /*
283  * Wide char defines.
284  */
285 #if WCHAR_TYPE == USHORT
286 #define WCT "short unsigned int"
287 #define WCM "65535U"
ragge
1.158
288 #if WCHAR_SIZE != 2
289 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
290 #endif
ragge
1.157
291 #elif WCHAR_TYPE == INT
292 #define WCT "int"
293 #define WCM "2147483647"
ragge
1.158
294 #if WCHAR_SIZE != 4
295 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
296 #endif
ragge
1.157
297 #elif WCHAR_TYPE == UNSIGNED
298 #define WCT "unsigned int"
ragge
1.158
299 #define WCM "4294967295U"
300 #if WCHAR_SIZE != 4
301 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
302 #endif
303 #else
304 #error WCHAR_TYPE not defined or invalid
ragge
1.157
305 #endif
306
ragge
1.128
307 int
308 main(int argcchar *argv[])
309 {
310         struct Wflags *Wf;
311         char *t, *u;
312         char *assource;
313         char **pv, *ptemp[MAXOPT], **pvt;
314         int ncnlnasijcnxona;
315 #ifdef MULTITARGET
316         int k;
317 #endif
318
319 #ifdef WIN32
320         /* have to prefix path early.  -B may override */
321         incdir = win32pathsubst(incdir);
gmcgarry
1.153
322         altincdir = win32pathsubst(altincdir);
gmcgarry
1.136
323         libdir = win32pathsubst(libdir);
ragge
1.128
324         pccincdir = win32pathsubst(pccincdir);
325         pcclibdir = win32pathsubst(pcclibdir);
326         passp = win32pathsubst(passp);
327         pass0 = win32pathsubst(pass0);
328 #endif
329
330         i = nc = nl = nas = nxo = 0;
331         pv = ptemp;
332         while(++i < argc) {
333                 if (argv[i][0] == '-') {
334                         switch (argv[i][1]) {
335                         default:
336                                 goto passa;
337 #ifdef notyet
338         /* must add library options first (-L/-l/...) */
339                                 error("unrecognized option `-%c'"argv[i][1]);
340                                 break;
341 #endif
342
343                         case '-'/* double -'s */
ragge
1.130
344                                 if (strcmp(argv[i], "--version") == 0) {
ragge
1.128
345                                         printf("%s\n"VERSSTR);
ragge
1.130
346                                         return 0;
347                                 } else if (strcmp(argv[i], "--param") == 0)
ragge
1.128
348                                         /* NOTHING YET */;
349                                 else
gmcgarry
1.148
350                                         goto passa;
ragge
1.128
351                                 break;
352
353                         case 'B'/* other search paths for binaries */
354                                 Bflag = &argv[i][2];
355                                 break;
356
357 #ifdef MULTITARGET
358                         case 'b':
359                                 t = &argv[i][2];
360                                 if (*t == '\0' && i + 1 < argc) {
361                                         t = argv[i+1];
362                                         i++;
363                                 }
364                                 if (strncmp(t"?"1) == 0) {
365                                         /* show machine targets */
366                                         printf("Available machine targets:");
367                                         for (j=0cppmds[j].machj++)
368                                                 printf(" %s",cppmds[j].mach);
369                                         printf("\n");
370                                         exit(0);
371                                 }
372                                 for (j=0cppmds[j].machj++)
373                                         if (strcmp(tcppmds[j].mach) == 0) {
374                                                 mach = cppmds[j].mach;
375                                                 break;
376                                         }
377                                 if (cppmds[j].mach == NULL)
378                                         errorx(1"unknown target arch %s"t);
379                                 break;
380 #endif
381
382                         case 'X':
383                                 Xflag++;
384                                 break;
385                         case 'W'/* Ignore (most of) W-flags */
386                                 if (strncmp(argv[i], "-Wl,"4) == 0) {
387                                         /* options to the linker */
388                                         t = &argv[i][4];
389                                         while ((u = strchr(t','))) {
390                                                 *u++ = 0;
391                                                 llist[nl++] = t;
392                                                 t = u;
393                                         }
394                                         llist[nl++] = t;
395                                 } else if (strncmp(argv[i], "-Wa,"4) == 0) {
396                                         /* options to the assembler */
397                                         t = &argv[i][4];
398                                         while ((u = strchr(t','))) {
399                                                 *u++ = 0;
400                                                 aslist[nas++] = t;
401                                                 t = u;
402                                         }
403                                         aslist[nas++] = t;
ragge
1.137
404                                 } else if (strncmp(argv[i], "-Wc,"4) == 0) {
405                                         /* options to ccom */
406                                         t = &argv[i][4];
407                                         while ((u = strchr(t','))) {
408                                                 *u++ = 0;
409                                                 wlist[nw++] = t;
410                                                 t = u;
411                                         }
412                                         wlist[nw++] = t;
ragge
1.128
413                                 } else if (strncmp(argv[i], "-Wp,"4) == 0) {
414                                         /* preprocessor */
415                                         if (!strncmp(argv[i], "-Wp,-C"6))
416                                                 Cflag++;
gmcgarry
1.134
417                                         else if (!strncmp(argv[i], "-Wp,-V"6))
418                                                 Vflag++;
gmcgarry
1.147
419                                         else if (!strncmp(argv[i], "-Wp,-P"6))
420                                                 Pflag++;
ragge
1.128
421                                 } else if (strcmp(argv[i], "-Wall") == 0) {
422                                         Wallflag = 1;
423                                 } else if (strcmp(argv[i], "-WW") == 0) {
424                                         Wflag = 1;
425                                 } else {
426                                         /* check and set if available */
427                                         for (Wf = WflagsWf->nameWf++) {
428                                                 if (strcmp(argv[i], Wf->name))
429                                                         continue;
430                                                 wlist[nw++] = Wf->name;
431                                         }
432                                 }
433                                 break;
434
435                         case 'f'/* GCC compatibility flags */
436                                 if (strcmp(argv[i], "-fPIC") == 0)
437                                         kflag = F_PIC;
438                                 else if (strcmp(argv[i], "-fpic") == 0)
439                                         kflag = F_pic;
440                                 else if (strcmp(argv[i],
441                                     "-fsigned-char") == 0)
442                                         flist[nf++] = argv[i];
443                                 else if (strcmp(argv[i],
444                                     "-fno-signed-char") == 0)
445                                         flist[nf++] = argv[i];
446                                 else if (strcmp(argv[i],
447                                     "-funsigned-char") == 0)
448                                         flist[nf++] = argv[i];
449                                 else if (strcmp(argv[i],
450                                     "-fno-unsigned-char") == 0)
451                                         flist[nf++] = argv[i];
452                                 else if (strcmp(argv[i],
453                                     "-fstack-protector") == 0) {
454                                         flist[nf++] = argv[i];
455                                         sspflag++;
456                                 } else if (strcmp(argv[i],
457                                     "-fstack-protector-all") == 0) {
458                                         flist[nf++] = argv[i];
459                                         sspflag++;
460                                 } else if (strcmp(argv[i],
461                                     "-fno-stack-protector") == 0) {
462                                         flist[nf++] = argv[i];
463                                         sspflag = 0;
464                                 } else if (strcmp(argv[i],
465                                     "-fno-stack-protector-all") == 0) {
466                                         flist[nf++] = argv[i];
467                                         sspflag = 0;
468                                 }
469                                 /* silently ignore the rest */
470                                 break;
471
472                         case 'g'/* create debug output */
473                                 gflag++;
474                                 break;
475
476                         case 'i':
477                                 if (strcmp(argv[i], "-isystem") == 0) {
478                                         *pv++ = "-S";
479                                         *pv++ = argv[++i];
480                                 } else if (strcmp(argv[i], "-include") == 0) {
481                                         *pv++ = "-i";
482                                         *pv++ = argv[++i];
483                                 } else if (strcmp(argv[i], "-idirafter") == 0) {
484                                         idirafter = argv[++i];
485                                 } else
486                                         goto passa;
487                                 break;
488
489                         case 'k'/* generate PIC code */
490                                 kflag = F_pic;
491                                 break;
492
493                         case 'm'/* target-dependent options */
494                                 mlist[nm++] = argv[i];
495                                 break;
496
497                         case 'n'/* handle -n flags */
498                                 if (strcmp(argv[i], "-nostdinc") == 0)
499                                         nostdinc++;
500                                 else if (strcmp(argv[i], "-nostdlib") == 0) {
501                                         nostdlib++;
502                                         nostartfiles++;
503                                 } else if (strcmp(argv[i], "-nostartfiles") == 0)
504                                         nostartfiles = 1;
505                                 else
506                                         goto passa;
507                                 break;
508
509                         case 'p':
510                                 if (strcmp(argv[i], "-pg") == 0 ||
511                                     strcmp(argv[i], "-p") == 0)
512                                         pgflag++;
513                                 else if (strcmp(argv[i], "-pthread") == 0)
514                                         pthreads++;
515                                 else if (strcmp(argv[i], "-pipe") == 0)
516                                         /* NOTHING YET */;
gmcgarry
1.144
517                                 else if (strcmp(argv[i], "-pedantic") == 0)
518                                         /* NOTHING YET */;
ragge
1.128
519                                 else
520                                         errorx(1"unknown option %s"argv[i]);
521                                 break;
522
gmcgarry
1.145
523                         case 'r':
524                                 rflag = 1;
525                                 break;
526
ragge
1.128
527                         case 'x':
528                                 t = &argv[i][2];
529                                 if (*t == 0)
530                                         t = argv[++i];
531                                 if (strcmp(t"c") == 0)
532                                         xcflag = 1/* default */
533                                 else if (strcmp(t"assembler-with-cpp") == 0)
534                                         ascpp = 1;
535 #ifdef notyet
536                                 else if (strcmp(t"c++") == 0)
537                                         cxxflag++;
538 #endif
539                                 else
540                                         xlist[xnum++] = argv[i];
541                                 break;
542                         case 't':
543                                 tflag++;
544                                 break;
545                         case 'S':
546                                 sflag++;
547                                 cflag++;
548                                 break;
549                         case 'o':
550                                 if (outfile)
551                                         errorx(8"too many -o");
552                                 outfile = argv[++i];
553                                 break;
554                         case 'O':
555                                 if (argv[i][2] == '0')
556                                         Oflag = 0;
557                                 else
558                                         Oflag++;
559                                 break;
560                         case 'E':
561                                 Eflag++;
562                                 break;
563                         case 'P':
564                                 pflag++;
565                                 *pv++ = argv[i];
566                         case 'c':
567                                 cflag++;
568                                 break;
569
570 #if 0
571                         case '2':
572                                 if(argv[i][2] == '\0')
573                                         pref = "/lib/crt2.o";
574                                 else {
575                                         pref = "/lib/crt20.o";
576                                 }
577                                 break;
578 #endif
579                         case 'C':
580                                 Cflag = 1;
581                                 break;
582                         case 'D':
583                         case 'I':
584                         case 'U':
585                                 *pv++ = argv[i];
586                                 if (argv[i][2] == 0)
587                                         *pv++ = argv[++i];
588                                 if (pv >= ptemp+MAXOPT) {
589                                         error("Too many DIU options");
590                                         --pv;
591                                 }
592                                 break;
593
594                         case 'M':
595                                 Mflag++;
596                                 break;
597
598                         case 'd':
gmcgarry
1.144
599 #ifdef os_darwin
600                                 if (strcmp(argv[i], "-dynamiclib") == 0) {
601                                         shared = 1;
602                                 } else
603 #endif
604                                 if (strcmp(argv[i], "-d") == 0) {
605                                         dflag++;
606                                         strlcpy(alistargv[i], sizeof (alist));
607                                 }
ragge
1.128
608                                 break;
609                         case 'v':
610                                 printf("%s\n"VERSSTR);
611                                 vflag++;
612                                 break;
613
614                         case 's':
gmcgarry
1.144
615 #ifndef os_darwin
616                                 if (strcmp(argv[i], "-shared") == 0) {
ragge
1.128
617                                         shared = 1;
618 #ifndef os_win32
619                                         nostdlib = 1;
620 #endif
gmcgarry
1.144
621                                 } else
622 #endif
623                                 if (strcmp(argv[i], "-static") == 0) {
624                                         Bstatic = 1;
ragge
1.128
625                                 } else if (strncmp(argv[i], "-std"4) == 0) {
626                                         /* ignore gcc -std= */;
627                                 } else
628                                         goto passa;
629                                 break;
630                         }
631                 } else {
632                 passa:
633                         t = argv[i];
634                         if (*argv[i] == '-' && argv[i][1] == 'L')
635                                 ;
636                         else if((c=getsuf(t))=='c' || c=='S' || c=='i' ||
637                             c=='s'|| Eflag || xcflag) {
638                                 clist[nc++] = t;
639                                 if (nc>=MAXFIL) {
640                                         error("Too many source files");
641                                         exit(1);
642                                 }
643                         }
644
645                         /* Check for duplicate .o files. */
646                         for (j = getsuf(t) == 'o' ? 0 : nlj < nlj++) {
647                                 if (strcmp(llist[j], t) == 0)
648                                         break;
649                         }
gmcgarry
1.150
650                         if ((c=getsuf(t))!='c' && c!='S' &&
651                             c!='s' && c!='i' && j==nl) {
ragge
1.128
652                                 llist[nl++] = t;
653                                 if (nl >= MAXLIB) {
654                                         error("Too many object/library files");
655                                         exit(1);
656                                 }
657                                 if (getsuf(t)=='o')
658                                         nxo++;
659                         }
660                 }
661         }
662         /* Sanity checking */
663         if (nc == 0 && nl == 0)
664                 errorx(8"no input files");
665         if (outfile && (cflag || sflag || Eflag) && nc > 1)
666                 errorx(8"-o given with -c || -E || -S and more than one file");
667         if (outfile && clist[0] && strcmp(outfileclist[0]) == 0)
668                 errorx(8"output file will be clobbered");
gmcgarry
1.150
669         if (nc==0)
ragge
1.128
670                 goto nocom;
671         if (pflag==0) {
672                 if (!sflag)
673                         tmp3 = gettmp();
674                 tmp4 = gettmp();
675         }
676         if (Bflag) {
gmcgarry
1.153
677                 altincdir = Bflag;
ragge
1.128
678                 pccincdir = Bflag;
679                 pcclibdir = Bflag;
680         }
681         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
682                 signal(SIGINTidexit);
683         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
684                 signal(SIGTERMidexit);
685 #ifdef MULTITARGET
ragge
1.133
686         pass0 = copy(LIBEXECDIR "/ccom_"k = strlen(mach));
687         strlcat(pass0machsizeof(LIBEXECDIR "/ccom_") + k);
ragge
1.128
688 #endif
689         pvt = pv;
690         for (i=0i<nci++) {
691                 /*
692                  * C preprocessor
693                  */
694                 if (nc>1 && !Eflag)
695                         printf("%s:\n"clist[i]);
696                 onlyas = 0;
697                 assource = tmp3;
698                 if (getsuf(clist[i])=='S')
699                         ascpp = 1;
700                 if (getsuf(clist[i])=='i') {
701                         if(Eflag)
702                                 continue;
703                         goto com;
704                 } else if (ascpp) {
705                         onlyas = 1;
706                 } else if (getsuf(clist[i])=='s') {
707                         assource = clist[i];
708                         goto assemble;
709                 }
710                 if (pflag)
711                         tmp4 = setsuf(clist[i], 'i');
712                 na = 0;
713                 av[na++] = "cpp";
714                 if (vflag)
715                         av[na++] = "-v";
716                 av[na++] = "-D__PCC__=" MKS(PCC_MAJOR);
717                 av[na++] = "-D__PCC_MINOR__=" MKS(PCC_MINOR);
718                 av[na++] = "-D__PCC_MINORMINOR__=" MKS(PCC_MINORMINOR);
gmcgarry
1.156
719 #ifndef os_win32
ragge
1.155
720 #ifdef GCC_COMPAT
721                 av[na++] = "-D__GNUC__=4";
722                 av[na++] = "-D__GNUC_MINOR__=3";
723                 av[na++] = "-D__GNUC_PATCHLEVEL__=1";
724                 av[na++] = "-D__GNUC_STDC_INLINE__=1";
725 #endif
gmcgarry
1.156
726 #endif
ragge
1.128
727                 if (ascpp)
728                         av[na++] = "-D__ASSEMBLER__";
729                 if (sspflag)
730                         av[na++] = "-D__SSP__=1";
731                 if (pthreads)
732                         av[na++] = "-D_PTHREADS";
733                 if (Cflag)
734                         av[na++] = "-C";
735                 if (Mflag)
736                         av[na++] = "-M";
gmcgarry
1.134
737                 if (Vflag)
738                         av[na++] = "-V";
gmcgarry
1.147
739                 if (Pflag)
740                         av[na++] = "-P";
ragge
1.128
741                 if (dflag)
742                         av[na++] = alist;
743                 for (j = 0cppadd[j]; j++)
744                         av[na++] = cppadd[j];
gmcgarry
1.149
745                 av[na++] = "-D__STDC_ISO_10646__=200009L";
ragge
1.157
746                 av[na++] = "-D__WCHAR_TYPE__=" WCT;
747                 av[na++] = "-D__SIZEOF_WCHAR_T__=" MKS(WCHAR_SIZE);
748                 av[na++] = "-D__WCHAR_MAX__=" WCM;
gmcgarry
1.142
749                 av[na++] = "-D__WINT_TYPE__=unsigned int";
gmcgarry
1.149
750                 av[na++] = "-D__SIZE_TYPE__=unsigned long";
751                 av[na++] = "-D__PTRDIFF_TYPE__=int";
gmcgarry
1.142
752                 av[na++] = "-D__SIZEOF_WINT_T__=4";
ragge
1.128
753 #ifdef MULTITARGET
754                 for (k = 0cppmds[k].machk++) {
755                         if (strcmp(cppmds[k].machmach) != 0)
756                                 continue;
757                         for (j = 0cppmds[k].cppmdadd[j]; j++)
758                                 av[na++] = cppmds[k].cppmdadd[j];
759                         break;
760                 }
761 #else
762                 for (j = 0cppmdadd[j]; j++)
763                         av[na++] = cppmdadd[j];
764 #endif
765                 if (tflag)
766                         av[na++] = "-t";
767                 for(pv=ptemppv <pvtpv++)
768                         av[na++] = *pv;
gmcgarry
1.153
769                 if (!nostdinc) {
770                         av[na++] = "-S"av[na++] = altincdir;
ragge
1.128
771                         av[na++] = "-S"av[na++] = incdir;
gmcgarry
1.153
772                         av[na++] = "-S"av[na++] = pccincdir;
773                 }
ragge
1.128
774                 if (idirafter) {
775                         av[na++] = "-I";
776                         av[na++] = idirafter;
777                 }
778                 av[na++] = clist[i];
779                 if (!Eflag && !Mflag)
780                         av[na++] = tmp4;
ragge
1.141
781                 if ((Eflag || Mflag) && outfile)
ragge
1.128
782                          ermfile = av[na++] = outfile;
783                 av[na++]=0;
gmcgarry
1.140
784                 if (callsys(passpav)) {
785                         exfail++;
786                         eflag++;
787                 }
ragge
1.128
788                 if (Eflag || Mflag)
789                         continue;
790                 if (onlyas) {
791                         assource = tmp4;
792                         goto assemble;
793                 }
794
795                 /*
796                  * C compiler
797                  */
798         com:
799                 na = 0;
800                 av[na++]= "ccom";
801                 if (Wallflag) {
802                         /* Set only the same flags as gcc */
803                         for (Wf = WflagsWf->nameWf++) {
804                                 if (Wf->flags != INWALL)
805                                         continue;
806                                 av[na++] = Wf->name;
807                         }
808                 }
809                 if (Wflag) {
810                         /* set all positive flags */
811                         for (Wf = WflagsWf->nameWf++) {
812                                 if (Wf->flags == NEGATIVE)
813                                         continue;
814                                 av[na++] = Wf->name;
815                         }
816                 }
817                 for (j = 0j < nwj++)
818                         av[na++] = wlist[j];
819                 for (j = 0j < nfj++)
820                         av[na++] = flist[j];
821                 if (vflag)
822                         av[na++] = "-v";
823                 if (pgflag)
824                         av[na++] = "-p";
825                 if (gflag)
826                         av[na++] = "-g";
827 #ifdef os_darwin
828                 /* darwin always wants PIC compilation */
829                 if (!Bstatic)
830                         av[na++] = "-k";
831 #else
832                 if (kflag)
833                         av[na++] = "-k";
834 #endif
835                 if (Oflag) {
836                         av[na++] = "-xtemps";
837                         av[na++] = "-xdeljumps";
ragge
1.133
838                         av[na++] = "-xinline";
ragge
1.128
839                 }
840                 for (j = 0j < xnumj++)
841                         av[na++] = xlist[j];
842                 for (j = 0j < nmj++)
843                         av[na++] = mlist[j];
844                 if (getsuf(clist[i])=='i')
845                         av[na++] = clist[i];
846                 else
847                         av[na++] = tmp4/* created by cpp */
848                 if (pflag || exfail)
849                         {
850                         cflag++;
851                         continue;
852                         }
853                 if(sflag) {
854                         if (outfile)
855                                 tmp3 = outfile;
856                         else
857                                 tmp3 = setsuf(clist[i], 's');
858                 }
859                 ermfile = av[na++] = tmp3;
860 #if 0
861                 if (proflag) {
862                         av[3] = "-XP";
863                         av[4] = 0;
864                 } else
865                         av[3] = 0;
866 #endif
867                 av[na++] = NULL;
868                 if (callsys(pass0av)) {
869                         cflag++;
870                         eflag++;
871                         continue;
872                 }
873                 if (sflag)
874                         continue;
875
876                 /*
877                  * Assembler
878                  */
879         assemble:
880                 na = 0;
881                 av[na++] = as;
882                 for (j = 0j < nasj++)
883                         av[na++] = aslist[j];
gmcgarry
1.149
884 #if defined(os_win32) && defined(USE_YASM)
885                 av[na++] = "-p";
886                 av[na++] = "gnu";
887                 av[na++] = "-f";
888                 av[na++] = "win32";
889 #endif
ragge
1.128
890 #if defined(os_sunos) && defined(mach_sparc64)
891                 av[na++] = "-m64";
892 #endif
893 #if defined(os_darwin)
894                 if (Bstatic)
895                         av[na++] = "-static";
896 #endif
897                 if (vflag)
898                         av[na++] = "-v";
899                 if (kflag)
900                         av[na++] = "-k";
901                 av[na++] = "-o";
902                 if (outfile && cflag)
903                         ermfile = av[na++] = outfile;
gmcgarry
1.150
904                 else if (cflag)
905                         ermfile = av[na++] = olist[i] = setsuf(clist[i], 'o');
ragge
1.128
906                 else
gmcgarry
1.150
907                         ermfile = av[na++] = olist[i] = gettmp();
ragge
1.128
908                 av[na++] = assource;
909                 if (dflag)
910                         av[na++] = alist;
911                 av[na++] = 0;
912                 if (callsys(asav)) {
913                         cflag++;
914                         eflag++;
915                         cunlink(tmp4);
916                         continue;
917                 }
918                 cunlink(tmp4);
919         }
920
921         if (Eflag || Mflag)
922                 dexit(eflag);
923
924         /*
925          * Linker
926          */
927 nocom:
gmcgarry
1.150
928         if (cflag==0 && nc+nl != 0) {
ragge
1.128
929                 j = 0;
930                 av[j++] = ld;
931 #ifndef MSLINKER
932                 if (vflag)
933                         av[j++] = "-v";
934 #endif
gmcgarry
1.131
935 #if !defined(os_sunos) && !defined(os_win32) && !defined(os_darwin)
ragge
1.128
936                 av[j++] = "-X";
937 #endif
938                 if (shared) {
gmcgarry
1.144
939 #ifdef os_darwin
940                         av[j++] = "-dylib";
941 #else
ragge
1.128
942                         av[j++] = "-shared";
gmcgarry
1.144
943 #endif
ragge
1.128
944 #ifdef os_win32
945                         av[j++] = "-Bdynamic";
946 #endif
947 #ifndef os_sunos
948                 } else {
949 #ifndef os_win32
950 #ifndef os_darwin
951                         av[j++] = "-d";
952 #endif
gmcgarry
1.145
953                         if (rflag) {
954                                 av[j++] = "-r";
955                         } else {
956                                 av[j++] = "-e";
957                                 av[j++] = STARTLABEL;
958                         }
ragge
1.128
959 #endif
960 #endif
961                         if (Bstatic == 0) { /* Dynamic linkage */
962 #ifdef DYNLINKER
963                                 for (i = 0dynlinker[i]; i++)
964                                         av[j++] = dynlinker[i];
965 #endif
966                         } else {
967 #ifdef os_darwin
968                                 av[j++] = "-static";
969 #else
970                                 av[j++] = "-Bstatic";
971 #endif
972                         }
973                 }
974                 if (outfile) {
975 #ifdef MSLINKER
gmcgarry
1.135
976 #define OUTSTR  "/OUT:"
977                         char *s = copy(OUTSTRi = strlen(outfile));
978                         strlcat(soutfilesizeof(OUTSTR) + i);
ragge
1.128
979                         av[j++] = s;
980 #else
981                         av[j++] = "-o";
982                         av[j++] = outfile;
983 #endif
984                 }
985 #ifdef STARTFILES_S
986                 if (shared) {
987                         if (!nostartfiles) {
988                                 for (i = 0startfiles_S[i]; i++)
989                                         av[j++] = Bprefix(startfiles_S[i]);
990                         }
991                 } else
992 #endif
993                 {
994                         if (!nostartfiles) {
995 #ifdef CRT0FILE_PROFILE
996                                 if (pgflag) {
997                                         av[j++] = Bprefix(crt0file_profile);
998                                 } else
999 #endif
1000                                 {
1001 #ifdef CRT0FILE
1002                                         av[j++] = Bprefix(crt0file);
1003 #endif
1004                                 }
1005 #ifdef STARTFILES_T
1006                                 if (Bstatic) {
1007                                         for (i = 0startfiles_T[i]; i++)
ragge
1.129
1008                                                 av[j++] = Bprefix(startfiles_T[i]);
ragge
1.128
1009                                 } else
1010 #endif
1011                                 {
1012 #ifdef STARTFILES
1013                                         for (i = 0startfiles[i]; i++)
1014                                                 av[j++] = Bprefix(startfiles[i]);
1015 #endif
1016                                 }
1017                         }
1018                 }
1019                 i = 0;
gmcgarry
1.150
1020                 while (i<nc) {
1021                         av[j++] = olist[i++];
1022                         if (j >= MAXAV)
1023                                 error("Too many ld options");
1024                 }
1025                 i = 0;
ragge
1.128
1026                 while(i<nl) {
1027                         av[j++] = llist[i++];
1028                         if (j >= MAXAV)
1029                                 error("Too many ld options");
1030                 }
gmcgarry
1.151
1031 #if !defined(os_darwin) && !defined(os_sunos)
ragge
1.128
1032                 /* darwin assembler doesn't want -g */
1033                 if (gflag)
1034                         av[j++] = "-g";
1035 #endif
1036 #if 0
1037                 if (gflag)
1038                         av[j++] = "-lg";
1039 #endif
1040                 if (pthreads)
1041                         av[j++] = "-lpthread";
1042                 if (!nostdlib) {
1043 #ifdef MSLINKER
ragge
1.133
1044 #define DL      "/LIBPATH:"
ragge
1.128
1045 #else
ragge
1.133
1046 #define DL      "-L"
ragge
1.128
1047 #endif
ragge
1.133
1048                         char *s = copy(DLi = strlen(