Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20100421085419

Diff

Diff from 1.157 to:

Annotations

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

Annotated File View

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