Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20110727190806

Diff

Diff from 1.195 to:

Annotations

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

Annotated File View

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