Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:plunky:20110727150602

Diff

Diff from 1.193 to:

Annotations

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

Annotated File View

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