Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20110714090650

Diff

Diff from 1.190 to:

Annotations

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

Annotated File View

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