Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:plunky:20110606133056

Diff

Diff from 1.184 to:

Annotations

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

Annotated File View

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