Quick Search:

View

Revision:
Expand:  
Changeset: r-1-0-1:ragge:20110404145023

Diff

Diff from 1.170.2.1.2.1 to:

Annotations

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

Annotated File View

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