Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20110517021314

Diff

Diff from 1.180 to:

Annotations

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

Annotated File View

gmcgarry
1.180
1 /*      $Id: cc.c,v 1.180 2011/05/17 02:13:14 gmcgarry 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 #define OS MKS(TARGOS)
120 #define MACH MKS(TARGMACH)
121 #ifndef PCCINCDIR
122 #define PCCINCDIR       LIBDIR "pcc/" MACH "-" OS "/" PACKAGE_VERSION "/include"
123 #endif
124 #ifndef PCCLIBDIR
125 #define PCCLIBDIR       LIBDIR "pcc/" MACH "-" OS "/" PACKAGE_VERSION "/lib"
126 #endif
127
ragge
1.174
128 #ifndef MULTIOSDIR
129 #define MULTIOSDIR      "."
130 #endif
131
132
ragge
1.128
133 #define MAXFIL 10000
134 #define MAXLIB 10000
135 #define MAXAV  10000
ragge
1.173
136 #define MAXOPT 200
ragge
1.128
137 char    *tmp3;
138 char    *tmp4;
139 char    *outfile, *ermfile;
ragge
1.175
140 static void add_prefix(const char *);
141 static char *find_file(const char *, int);
gmcgarry
1.150
142 char *copy(char *, int);
143 char *setsuf(char *, char);
ragge
1.128
144 int getsuf(char *);
145 int main(intchar *[]);
146 void error(char *, ...);
147 void errorx(intchar *, ...);
148 int callsys(char [], char *[]);
149 int cunlink(char *);
150 void dexit(int);
151 void idexit(int);
152 char *gettmp(void);
153 void *ccmalloc(int size);
154 #ifdef WIN32
155 char *win32pathsubst(char *);
gmcgarry
1.149
156 char *win32commandline(char *, char *[]);
ragge
1.128
157 #endif
158 char    *av[MAXAV];
159 char    *clist[MAXFIL];
gmcgarry
1.150
160 char    *olist[MAXFIL];
ragge
1.128
161 char    *llist[MAXLIB];
162 char    *aslist[MAXAV];
gmcgarry
1.163
163 char    *cpplist[MAXAV];
ragge
1.128
164 char    alist[20];
165 char    *xlist[100];
166 int     xnum;
167 char    *mlist[100];
168 char    *flist[100];
169 char    *wlist[100];
170 char    *idirafter;
171 int     nm;
172 int     nf;
173 int     nw;
174 int     sspflag;
175 int     dflag;
176 int     pflag;
177 int     sflag;
178 int     cflag;
179 int     eflag;
180 int     gflag;
gmcgarry
1.145
181 int     rflag;
ragge
1.128
182 int     vflag;
183 int     tflag;
184 int     Eflag;
185 int     Oflag;
186 int     kflag;  /* generate PIC/pic code */
187 #define F_PIC   1
188 #define F_pic   2
189 int     Mflag;  /* dependencies only */
190 int     pgflag;
191 int     exfail;
192 int     Xflag;
193 int     Wallflag;
194 int     Wflag;
195 int     nostartfilesBstaticshared;
196 int     nostdincnostdlib;
197 int     onlyas;
198 int     pthreads;
199 int     xcflag;
200 int     ascpp;
201
202 char    *passp = LIBEXECDIR PREPROCESSOR;
203 char    *pass0 = LIBEXECDIR COMPILER;
204 char    *as = ASSEMBLER;
205 char    *ld = LINKER;
ragge
1.175
206 char    *sysroot;
ragge
1.128
207 char *cppadd[] = CPPADD;
208 #ifdef DYNLINKER
209 char *dynlinker[] = DYNLINKER;
210 #endif
211 #ifdef CRT0FILE
212 char *crt0file = CRT0FILE;
213 #endif
214 #ifdef CRT0FILE_PROFILE
215 char *crt0file_profile = CRT0FILE_PROFILE;
216 #endif
217 #ifdef STARTFILES
218 char *startfiles[] = STARTFILES;
219 char *endfiles[] = ENDFILES;
220 #endif
221 #ifdef STARTFILES_T
222 char *startfiles_T[] = STARTFILES_T;
223 char *endfiles_T[] = ENDFILES_T;
224 #endif
225 #ifdef STARTFILES_S
226 char *startfiles_S[] = STARTFILES_S;
227 char *endfiles_S[] = ENDFILES_S;
228 #endif
229 #ifdef MULTITARGET
230 char *mach = DEFMACH;
231 struct cppmd {
232         char *mach;
233         char *cppmdadd[MAXCPPMDARGS];
234 };
235
236 struct cppmd cppmds[] = CPPMDADDS;
237 #else
238 char *cppmdadd[] = CPPMDADD;
239 #endif
240 #ifdef LIBCLIBS
241 char *libclibs[] = LIBCLIBS;
242 #else
243 char *libclibs[] = { "-lc"NULL };
244 #endif
245 #ifdef LIBCLIBS_PROFILE
246 char *libclibs_profile[] = LIBCLIBS_PROFILE;
247 #else
248 char *libclibs_profile[] = { "-lc_p"NULL };
249 #endif
250 #ifndef STARTLABEL
251 #define STARTLABEL "__start"
252 #endif
253 char *incdir = STDINC;
gmcgarry
1.153
254 char *altincdir = INCLUDEDIR "pcc/";
gmcgarry
1.136
255 char *libdir = LIBDIR;
ragge
1.128
256 char *pccincdir = PCCINCDIR;
257 char *pcclibdir = PCCLIBDIR;
ragge
1.164
258 #ifdef mach_amd64
259 int amd64_i386;
260 #endif
ragge
1.128
261
262 /* handle gcc warning emulations */
263 struct Wflags {
264         char *name;
265         int flags;
266 #define INWALL          1
267 #define NEGATIVE        2
268 Wflags[] = {
gmcgarry
1.154
269         { "-Wtruncate"0 },
270         { "-Wno-truncate"NEGATIVE },
ragge
1.128
271         { "-Werror"0 },
272         { "-Wshadow"0 },
273         { "-Wno-shadow"NEGATIVE },
274         { "-Wpointer-sign"INWALL },
275         { "-Wno-pointer-sign"NEGATIVE },
276         { "-Wsign-compare"0 },
277         { "-Wno-sign-compare"NEGATIVE },
278         { "-Wunknown-pragmas"INWALL },
279         { "-Wno-unknown-pragmas"NEGATIVE },
280         { "-Wunreachable-code"0 },
281         { "-Wno-unreachable-code"NEGATIVE },
282         { 00 },
283 };
284
285 #define SZWFL   (sizeof(Wflags)/sizeof(Wflags[0]))
286
ragge
1.158
287 #ifndef USHORT
288 /* copied from mip/manifest.h */
289 #define USHORT          5
290 #define INT             6
291 #define UNSIGNED        7
292 #endif
293
ragge
1.157
294 /*
295  * Wide char defines.
296  */
297 #if WCHAR_TYPE == USHORT
298 #define WCT "short unsigned int"
299 #define WCM "65535U"
ragge
1.158
300 #if WCHAR_SIZE != 2
301 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
302 #endif
ragge
1.157
303 #elif WCHAR_TYPE == INT
304 #define WCT "int"
305 #define WCM "2147483647"
ragge
1.158
306 #if WCHAR_SIZE != 4
307 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
308 #endif
ragge
1.157
309 #elif WCHAR_TYPE == UNSIGNED
310 #define WCT "unsigned int"
ragge
1.158
311 #define WCM "4294967295U"
312 #if WCHAR_SIZE != 4
313 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
314 #endif
315 #else
316 #error WCHAR_TYPE not defined or invalid
ragge
1.157
317 #endif
318
ragge
1.160
319 #ifdef GCC_COMPAT
320 #ifndef REGISTER_PREFIX
321 #define REGISTER_PREFIX ""
322 #endif
323 #ifndef USER_LABEL_PREFIX
324 #define USER_LABEL_PREFIX ""
325 #endif
326 #endif
327
ragge
1.161
328 #ifndef PCC_PTRDIFF_TYPE
329 #define PCC_PTRDIFF_TYPE "long int"
330 #endif
331
ragge
1.128
332 int
333 main(int argcchar *argv[])
334 {
335         struct Wflags *Wf;
336         char *t, *u;
337         char *assource;
338         char **pv, *ptemp[MAXOPT], **pvt;
gmcgarry
1.163
339         int ncnlnasncppijcnxona;
ragge
1.128
340 #ifdef MULTITARGET
341         int k;
342 #endif
343
344 #ifdef WIN32
345         /* have to prefix path early.  -B may override */
346         incdir = win32pathsubst(incdir);
gmcgarry
1.153
347         altincdir = win32pathsubst(altincdir);
gmcgarry
1.136
348         libdir = win32pathsubst(libdir);
ragge
1.128
349         pccincdir = win32pathsubst(pccincdir);
350         pcclibdir = win32pathsubst(pcclibdir);
351         passp = win32pathsubst(passp);
352         pass0 = win32pathsubst(pass0);
gmcgarry
1.180
353 #ifdef STARTFILES
354         for (i = 0startfiles[i] != NULLi++)
355                 startfiles[i] = win32pathsubst(startfiles[i]);
356         for (i = 0endfiles[i] != NULLi++)
357                 endfiles[i] = win32pathsubst(endfiles[i]);
358 #endif
359 #ifdef STARTFILES_T
360         for (i = 0startfiles_T[i] != NULLi++)
361                 startfiles_T[i] = win32pathsubst(startfiles_T[i]);
362         for (i = 0endfiles_T[i] != NULLi++)
363                 endfiles_T[i] = win32pathsubst(endfiles_T[i]);
364 #endif
365 #ifdef STARTFILES_S
366         for (i = 0startfiles_S[i] != NULLi++)
367                 startfiles_S[i] = win32pathsubst(startfiles_S[i]);
368         for (i = 0endfiles_S[i] != NULLi++)
369                 endfiles_S[i] = win32pathsubst(endfiles_S[i]);
370 #endif
ragge
1.128
371 #endif
372
gmcgarry
1.163
373         i = nc = nl = nas = ncpp = nxo = 0;
ragge
1.128
374         pv = ptemp;
375         while(++i < argc) {
376                 if (argv[i][0] == '-') {
377                         switch (argv[i][1]) {
378                         default:
379                                 goto passa;
380 #ifdef notyet
381         /* must add library options first (-L/-l/...) */
382                                 error("unrecognized option `-%c'"argv[i][1]);
383                                 break;
384 #endif
385
386                         case '-'/* double -'s */
ragge
1.130
387                                 if (strcmp(argv[i], "--version") == 0) {
ragge
1.128
388                                         printf("%s\n"VERSSTR);
ragge
1.130
389                                         return 0;
ragge
1.175
390                                 } else if (strncmp(argv[i], "--sysroot="10) == 0) {
391                                         sysroot = argv[i] + 10;
ragge
1.169
392                                 } else if (strcmp(argv[i], "--param") == 0) {
ragge
1.128
393                                         /* NOTHING YET */;
ragge
1.169
394                                         i++; /* ignore arg */
395                                 } else
gmcgarry
1.148
396                                         goto passa;
ragge
1.128
397                                 break;
398
399                         case 'B'/* other search paths for binaries */
ragge
1.175
400                                 add_prefix(argv[i] + 2);
ragge
1.128
401                                 break;
402
403 #ifdef MULTITARGET
404                         case 'b':
405                                 t = &argv[i][2];
406                                 if (*t == '\0' && i + 1 < argc) {
407                                         t = argv[i+1];
408                                         i++;
409                                 }
410                                 if (strncmp(t"?"1) == 0) {
411                                         /* show machine targets */
412                                         printf("Available machine targets:");
413                                         for (j=0cppmds[j].machj++)
414                                                 printf(" %s",cppmds[j].mach);
415                                         printf("\n");
416                                         exit(0);
417                                 }
418                                 for (j=0cppmds[j].machj++)
419                                         if (strcmp(tcppmds[j].mach) == 0) {
420                                                 mach = cppmds[j].mach;
421                                                 break;
422                                         }
423                                 if (cppmds[j].mach == NULL)
424                                         errorx(1"unknown target arch %s"t);
425                                 break;
426 #endif
427
428                         case 'X':
429                                 Xflag++;
430                                 break;
431                         case 'W'/* Ignore (most of) W-flags */
432                                 if (strncmp(argv[i], "-Wl,"4) == 0) {
433                                         /* options to the linker */
434                                         t = &argv[i][4];
435                                         while ((u = strchr(t','))) {
436                                                 *u++ = 0;
437                                                 llist[nl++] = t;
438                                                 t = u;
439                                         }
440                                         llist[nl++] = t;
441                                 } else if (strncmp(argv[i], "-Wa,"4) == 0) {
442                                         /* options to the assembler */
443                                         t = &argv[i][4];
444                                         while ((u = strchr(t','))) {
445                                                 *u++ = 0;
446                                                 aslist[nas++] = t;
447                                                 t = u;
448                                         }
449                                         aslist[nas++] = t;
ragge
1.137
450                                 } else if (strncmp(argv[i], "-Wc,"4) == 0) {
451                                         /* options to ccom */
452                                         t = &argv[i][4];
453                                         while ((u = strchr(t','))) {
454                                                 *u++ = 0;
455                                                 wlist[nw++] = t;
456                                                 t = u;
457                                         }
458                                         wlist[nw++] = t;
ragge
1.128
459                                 } else if (strncmp(argv[i], "-Wp,"4) == 0) {
460                                         /* preprocessor */
gmcgarry
1.163
461                                         t = &argv[i][4];
462                                         while ((u = strchr(t','))) {
463                                                 *u++ = 0;
464                                                 cpplist[ncpp++] = t;
465                                                 t = u;
466                                         }
467                                         cpplist[ncpp++] = t;
ragge
1.128
468                                 } else if (strcmp(argv[i], "-Wall") == 0) {
469                                         Wallflag = 1;
470                                 } else if (strcmp(argv[i], "-WW") == 0) {
471                                         Wflag = 1;
472                                 } else {
473                                         /* check and set if available */
474                                         for (Wf = WflagsWf->nameWf++) {
475                                                 if (strcmp(argv[i], Wf->name))
476                                                         continue;
477                                                 wlist[nw++] = Wf->name;
478                                         }
479                                 }
480                                 break;
481
482                         case 'f'/* GCC compatibility flags */
483                                 if (strcmp(argv[i], "-fPIC") == 0)
484                                         kflag = F_PIC;
485                                 else if (strcmp(argv[i], "-fpic") == 0)
486                                         kflag = F_pic;
487                                 else if (strcmp(argv[i],
488                                     "-fsigned-char") == 0)
489                                         flist[nf++] = argv[i];
490                                 else if (strcmp(argv[i],
491                                     "-fno-signed-char") == 0)
492                                         flist[nf++] = argv[i];
493                                 else if (strcmp(argv[i],
494                                     "-funsigned-char") == 0)
495                                         flist[nf++] = argv[i];
496                                 else if (strcmp(argv[i],
497                                     "-fno-unsigned-char") == 0)
498                                         flist[nf++] = argv[i];
499                                 else if (strcmp(argv[i],
500                                     "-fstack-protector") == 0) {
501                                         flist[nf++] = argv[i];
502                                         sspflag++;
503                                 } else if (strcmp(argv[i],
504                                     "-fstack-protector-all") == 0) {
505                                         flist[nf++] = argv[i];
506                                         sspflag++;
507                                 } else if (strcmp(argv[i],
508                                     "-fno-stack-protector") == 0) {
509                                         flist[nf++] = argv[i];
510                                         sspflag = 0;
511                                 } else if (strcmp(argv[i],
512                                     "-fno-stack-protector-all") == 0) {
513                                         flist[nf++] = argv[i];
514                                         sspflag = 0;
515                                 }
516                                 /* silently ignore the rest */
517                                 break;
518
519                         case 'g'/* create debug output */
ragge
1.177
520                                 if (argv[i][2] == '0')
521                                         gflag = 0;
522                                 else
523                                         gflag++;
ragge
1.128
524                                 break;
525
526                         case 'i':
527                                 if (strcmp(argv[i], "-isystem") == 0) {
528                                         *pv++ = "-S";
529                                         *pv++ = argv[++i];
530                                 } else if (strcmp(argv[i], "-include") == 0) {
531                                         *pv++ = "-i";
532                                         *pv++ = argv[++i];
533                                 } else if (strcmp(argv[i], "-idirafter") == 0) {
534                                         idirafter = argv[++i];
gmcgarry
1.172
535 #ifdef os_darwin
536                                 } else if (strcmp(argv[i], "-install_name") == 0) {
537                                         llist[nl++] = argv[i];
538                                         llist[nl++] = argv[++i];
539 #endif
ragge
1.128
540                                 } else
541                                         goto passa;
542                                 break;
543
544                         case 'k'/* generate PIC code */
545                                 kflag = F_pic;
546                                 break;
547
548                         case 'm'/* target-dependent options */
ragge
1.164
549 #ifdef mach_amd64
550                                 /* need to call i386 ccom for this */
551                                 if (strcmp(argv[i], "-m32") == 0) {
552                                         pass0 = LIBEXECDIR "/ccom_i386";
553                                         amd64_i386 = 1;
554                                         break;
555                                 }
556 #endif
ragge
1.128
557                                 mlist[nm++] = argv[i];
ragge
1.169
558                                 if (argv[i][2] == 0) {
559                                         /* separate second arg */
560                                         /* give also to linker */
561                                         llist[nl++] = argv[i++];
562                                         mlist[nm++] = argv[i];
563                                         llist[nl++] = argv[i];
564                                 }
ragge
1.128
565                                 break;
566
567                         case 'n'/* handle -n flags */
568                                 if (strcmp(argv[i], "-nostdinc") == 0)
569                                         nostdinc++;
570                                 else if (strcmp(argv[i], "-nostdlib") == 0) {
571                                         nostdlib++;
572                                         nostartfiles++;
573                                 } else if (strcmp(argv[i], "-nostartfiles") == 0)
574                                         nostartfiles = 1;
575                                 else
576                                         goto passa;
577                                 break;
578
579                         case 'p':
580                                 if (strcmp(argv[i], "-pg") == 0 ||
581                                     strcmp(argv[i], "-p") == 0)
582                                         pgflag++;
583                                 else if (strcmp(argv[i], "-pthread") == 0)
584                                         pthreads++;
585                                 else if (strcmp(argv[i], "-pipe") == 0)
586                                         /* NOTHING YET */;
gmcgarry
1.144
587                                 else if (strcmp(argv[i], "-pedantic") == 0)
588                                         /* NOTHING YET */;
ragge
1.162
589                                 else if (strcmp(argv[i],
590                                     "-print-prog-name=ld") == 0) {
591                                         printf("%s\n"LINKER);
592                                         return 0;
ragge
1.174
593                                 } else if (strcmp(argv[i],
594                                     "-print-multi-os-directory") == 0) {
595                                         printf("%s\n"MULTIOSDIR);
596                                         return 0;
ragge
1.162
597                                 } else
ragge
1.128
598                                         errorx(1"unknown option %s"argv[i]);
599                                 break;
600
gmcgarry
1.145
601                         case 'r':
602                                 rflag = 1;
603                                 break;
604
ragge
1.128
605                         case 'x':
606                                 t = &argv[i][2];
607                                 if (*t == 0)
608                                         t = argv[++i];
609                                 if (strcmp(t"c") == 0)
610                                         xcflag = 1/* default */
611                                 else if (strcmp(t"assembler-with-cpp") == 0)
612                                         ascpp = 1;
613 #ifdef notyet
614                                 else if (strcmp(t"c++") == 0)
615                                         cxxflag++;
616 #endif
617                                 else
618                                         xlist[xnum++] = argv[i];
619                                 break;
620                         case 't':
621                                 tflag++;
622                                 break;
623                         case 'S':
624                                 sflag++;
625                                 cflag++;
626                                 break;
627                         case 'o':
628                                 if (outfile)
629                                         errorx(8"too many -o");
630                                 outfile = argv[++i];
631                                 break;
632                         case 'O':
633                                 if (argv[i][2] == '0')
634                                         Oflag = 0;
635                                 else
636                                         Oflag++;
637                                 break;
638                         case 'E':
639                                 Eflag++;
640                                 break;
641                         case 'P':
642                                 pflag++;
643                                 *pv++ = argv[i];
644                         case 'c':
gmcgarry
1.172
645 #ifdef os_darwin
646                                 if (strcmp(argv[i], "-compatibility_version") == 0) {
647                                         llist[nl++] = argv[i];
648                                         llist[nl++] = argv[++i];
649                                 } else if (strcmp(argv[i], "-current_version") == 0) {
650                                         llist[nl++] = argv[i];
651                                         llist[nl++] = argv[++i];
652                                 } else
653 #endif
654                                         cflag++;
ragge
1.128
655                                 break;
656 #if 0
657                         case '2':
658                                 if(argv[i][2] == '\0')
659                                         pref = "/lib/crt2.o";
660                                 else {
661                                         pref = "/lib/crt20.o";
662                                 }
663                                 break;
664 #endif
665                         case 'C':
gmcgarry
1.163
666                                 cpplist[ncpp++] = argv[i];
ragge
1.128
667                                 break;
668                         case 'D':
669                         case 'I':
670                         case 'U':
671                                 *pv++ = argv[i];
672                                 if (argv[i][2] == 0)
673                                         *pv++ = argv[++i];
674                                 if (pv >= ptemp+MAXOPT) {
675                                         error("Too many DIU options");
676                                         --pv;
677                                 }
678                                 break;
679
680                         case 'M':
681                                 Mflag++;
682                                 break;
683
684                         case 'd':
gmcgarry
1.144
685 #ifdef os_darwin
686                                 if (strcmp(argv[i], "-dynamiclib") == 0) {
687                                         shared = 1;
688                                 } else
689 #endif
690                                 if (strcmp(argv[i], "-d") == 0) {
691                                         dflag++;
692                                         strlcpy(alistargv[i], sizeof (alist));
693                                 }
ragge
1.128
694                                 break;
695                         case 'v':
696                                 printf("%s\n"VERSSTR);
697                                 vflag++;
698                                 break;
699
700                         case 's':
gmcgarry
1.144
701 #ifndef os_darwin
702                                 if (strcmp(argv[i], "-shared") == 0) {
ragge
1.128
703                                         shared = 1;
704 #ifndef os_win32
705                                         nostdlib = 1;
706 #endif
gmcgarry
1.144
707                                 } else
708 #endif
709                                 if (strcmp(argv[i], "-static") == 0) {
710                                         Bstatic = 1;
ragge
1.128
711                                 } else if (strncmp(argv[i], "-std"4) == 0) {
712                                         /* ignore gcc -std= */;
713                                 } else
714                                         goto passa;
715                                 break;
716                         }
717                 } else {
718                 passa:
719                         t = argv[i];
720                         if (*argv[i] == '-' && argv[i][1] == 'L')
721                                 ;
722                         else if((c=getsuf(t))=='c' || c=='S' || c=='i' ||
723                             c=='s'|| Eflag || xcflag) {
724                                 clist[nc++] = t;
725                                 if (nc>=MAXFIL) {
726                                         error("Too many source files");
727                                         exit(1);
728                                 }
729                         }
730
731                         /* Check for duplicate .o files. */
732                         for (j = getsuf(t) == 'o' ? 0 : nlj < nlj++) {
733                                 if (strcmp(llist[j], t) == 0)
734                                         break;
735                         }
gmcgarry
1.150
736                         if ((c=getsuf(t))!='c' && c!='S' &&
737                             c!='s' && c!='i' && j==nl) {
ragge
1.128
738                                 llist[nl++] = t;
739                                 if (nl >= MAXLIB) {
740                                         error("Too many object/library files");
741                                         exit(1);
742                                 }
743                                 if (getsuf(t)=='o')
744                                         nxo++;
745                         }
746                 }
747         }
748         /* Sanity checking */
749         if (nc == 0 && nl == 0)
750                 errorx(8"no input files");
751         if (outfile && (cflag || sflag || Eflag) && nc > 1)
752                 errorx(8"-o given with -c || -E || -S and more than one file");
753         if (outfile && clist[0] && strcmp(outfileclist[0]) == 0)
754                 errorx(8"output file will be clobbered");
gmcgarry
1.150
755         if (nc==0)
ragge
1.128
756                 goto nocom;
757         if (pflag==0) {
758                 if (!sflag)
759                         tmp3 = gettmp();
760                 tmp4 = gettmp();
761         }
762         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
763                 signal(SIGINTidexit);
764         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
765                 signal(SIGTERMidexit);
766 #ifdef MULTITARGET
ragge
1.133
767         pass0 = copy(LIBEXECDIR "/ccom_"k = strlen(mach));
768         strlcat(pass0machsizeof(LIBEXECDIR "/ccom_") + k);
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) {
869                         av[na++] = "-S"av[na++] = altincdir;
ragge
1.128
870                         av[na++] = "-S"av[na++] = incdir;
gmcgarry
1.153
871                         av[na++] = "-S"av[na++] = pccincdir;
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                 }
946                 for (j = 0j < xnumj++)
947                         av[na++] = xlist[j];
948                 for (j = 0j < nmj++)
949                         av[na++] = mlist[j];
950                 if (getsuf(clist[i])=='i')
951                         av[na++] = clist[i];
952                 else
953                         av[na++] = tmp4/* created by cpp */
954                 if (pflag || exfail)
955                         {
956                         cflag++;
957                         continue;
958                         }
959                 if(sflag) {
960                         if (outfile)
961                                 tmp3 = outfile;
962                         else
963                                 tmp3 = setsuf(clist[i], 's');
964                 }
965                 ermfile = av[na++] = tmp3;
966 #if 0
967                 if (proflag) {
968                         av[3] = "-XP";
969                         av[4] = 0;
970                 } else
971                         av[3] = 0;
972 #endif
973                 av[na++] = NULL;
974                 if (callsys(pass0av)) {
975                         cflag++;
976                         eflag++;
977                         continue;
978                 }
979                 if (sflag)
980                         continue;
981
982                 /*
983                  * Assembler
984                  */
985         assemble:
986                 na = 0;
987                 av[na++] = as;
988                 for (j = 0j < nasj++)
989                         av[na++] = aslist[j];
gmcgarry
1.178
990 #if defined(USE_YASM)
gmcgarry
1.149
991                 av[na++] = "-p";
992                 av[na++] = "gnu";
993                 av[na++] = "-f";
gmcgarry
1.178
994 #if defined(os_win32)
gmcgarry
1.149
995                 av[na++] = "win32";
gmcgarry
1.178
996 #elif defined(os_darwin)
997                 av[na++] = "macho";
998 #else
999                 av[na++] = "elf";
1000 #endif
gmcgarry
1.149
1001 #endif
ragge
1.128
1002 #if defined(os_sunos) && defined(mach_sparc64)
1003                 av[na++] = "-m64";
1004 #endif
1005 #if defined(os_darwin)
1006                 if (Bstatic)
1007                         av[na++] = "-static";
1008 #endif
gmcgarry
1.178
1009 #if !defined(USE_YASM)
ragge
1.128
1010                 if (vflag)
1011                         av[na++] = "-v";
gmcgarry
1.178
1012 #endif
ragge
1.128
1013                 if (kflag)
1014                         av[na++] = "-k";
ragge
1.164
1015 #ifdef mach_amd64
1016                 if (amd64_i386)
1017                         av[na++] = "--32";
1018 #endif
ragge
1.128
1019                 av[na++] = "-o";
1020                 if (outfile && cflag)
1021                         ermfile = av[na++] = outfile;
gmcgarry
1.150
1022                 else if (cflag)
1023                         ermfile = av[na++] = olist[i] = setsuf(clist[i], 'o');
ragge
1.128
1024                 else
gmcgarry
1.150
1025                         ermfile = av[na++] = olist[i] = gettmp();
ragge
1.128
1026                 av[na++] = assource;
1027                 if (dflag)
1028                         av[na++] = alist;
1029                 av[na++] = 0;
1030                 if (callsys(asav)) {
1031              &nbs