Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:plunky:20110723082837

Diff

Diff from 1.192 to:

Annotations

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

Annotated File View

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