Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20110516232305

Diff

Diff from 1.179 to:

Annotations

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

Annotated File View

gmcgarry
1.179
1 /*      $Id: cc.c,v 1.179 2011/05/16 23:23:05 gmcgarry Exp $    */
ragge
1.128
2 /*
3  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * Redistributions of source code and documentation must retain the above
10  * copyright notice, this list of conditions and the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditionsand the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * All advertising materials mentioning features or use of this software
15  * must display the following acknowledgement:
16  *      This product includes software developed or owned by Caldera
17  *      International, Inc.
18  * Neither the name of Caldera International, Inc. nor the names of other
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23  * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
27  * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35
36 /*
37  * Front-end to the C compiler.
38  *
39  * Brief description of its syntax:
40  * - Files that end with .c are passed via cpp->ccom->as->ld
41  * - Files that end with .i are passed via ccom->as->ld
42  * - Files that end with .s are passed as->ld
43  * - Files that end with .o are passed directly to ld
44  * - Multiple files may be given on the command line.
45  * - Unrecognized options are all sent directly to ld.
46  * -c or -S cannot be combined with -o if multiple files are given.
47  *
48  * This file should be rewritten readable.
49  */
50 #include "config.h"
51
52 #include <sys/types.h>
53 #ifdef HAVE_SYS_WAIT_H
54 #include <sys/wait.h>
55 #endif
56
57 #include <ctype.h>
58 #include <errno.h>
59 #include <fcntl.h>
60 #ifdef HAVE_LIBGEN_H
61 #include <libgen.h>
62 #endif
63 #include <signal.h>
64 #include <stdarg.h>
65 #include <stdio.h>
66 #include <stdlib.h>
67 #include <string.h>
68 #ifdef HAVE_UNISTD_H
69 #include <unistd.h>
70 #endif
71
72 #ifdef WIN32
73 #include <windows.h>
74 #include <process.h>
75 #include <io.h>
gmcgarry
1.179
76 #define F_OK    0x00
77 #define R_OK    0x04
78 #define W_OK    0x02
79 #define X_OK    R_OK
ragge
1.128
80 #endif
81
82 #include "compat.h"
83
84 #include "ccconfig.h"
ragge
1.167
85 #include "macdefs.h"
ragge
1.128
86 /* C command */
87
88 #define MKS(x) _MKS(x)
89 #define _MKS(x) #x
90
91 /*
92  * Many specific definitions, should be declared elsewhere.
93  */
94
95 #ifndef STDINC
96 #define STDINC          "/usr/include/"
97 #endif
98
99 #ifndef LIBDIR
100 #define LIBDIR          "/usr/lib/"
101 #endif
102
103 #ifndef PREPROCESSOR
104 #define PREPROCESSOR    "cpp"
105 #endif
106
107 #ifndef COMPILER
gmcgarry
1.138
108 #define COMPILER        "ccom"
ragge
1.128
109 #endif
110
111 #ifndef ASSEMBLER
112 #define ASSEMBLER       "as"
113 #endif
114
115 #ifndef LINKER
116 #define LINKER          "ld"
117 #endif
118
119 #define OS MKS(TARGOS)
120 #define MACH MKS(TARGMACH)
121 #ifndef PCCINCDIR
122 #define PCCINCDIR       LIBDIR "pcc/" MACH "-" OS "/" PACKAGE_VERSION "/include"
123 #endif
124 #ifndef PCCLIBDIR
125 #define PCCLIBDIR       LIBDIR "pcc/" MACH "-" OS "/" PACKAGE_VERSION "/lib"
126 #endif
127
ragge
1.174
128 #ifndef MULTIOSDIR
129 #define MULTIOSDIR      "."
130 #endif
131
132
ragge
1.128
133 #define MAXFIL 10000
134 #define MAXLIB 10000
135 #define MAXAV  10000
ragge
1.173
136 #define MAXOPT 200
ragge
1.128
137 char    *tmp3;
138 char    *tmp4;
139 char    *outfile, *ermfile;
ragge
1.175
140 static void add_prefix(const char *);
141 static char *find_file(const char *, int);
gmcgarry
1.150
142 char *copy(char *, int);
143 char *setsuf(char *, char);
ragge
1.128
144 int getsuf(char *);
145 int main(intchar *[]);
146 void error(char *, ...);
147 void errorx(intchar *, ...);
148 int callsys(char [], char *[]);
149 int cunlink(char *);
150 void dexit(int);
151 void idexit(int);
152 char *gettmp(void);
153 void *ccmalloc(int size);
154 #ifdef WIN32
155 char *win32pathsubst(char *);
gmcgarry
1.149
156 char *win32commandline(char *, char *[]);
ragge
1.128
157 #endif
158 char    *av[MAXAV];
159 char    *clist[MAXFIL];
gmcgarry
1.150
160 char    *olist[MAXFIL];
ragge
1.128
161 char    *llist[MAXLIB];
162 char    *aslist[MAXAV];
gmcgarry
1.163
163 char    *cpplist[MAXAV];
ragge
1.128
164 char    alist[20];
165 char    *xlist[100];
166 int     xnum;
167 char    *mlist[100];
168 char    *flist[100];
169 char    *wlist[100];
170 char    *idirafter;
171 int     nm;
172 int     nf;
173 int     nw;
174 int     sspflag;
175 int     dflag;
176 int     pflag;
177 int     sflag;
178 int     cflag;
179 int     eflag;
180 int     gflag;
gmcgarry
1.145
181 int     rflag;
ragge
1.128
182 int     vflag;
183 int     tflag;
184 int     Eflag;
185 int     Oflag;
186 int     kflag;  /* generate PIC/pic code */
187 #define F_PIC   1
188 #define F_pic   2
189 int     Mflag;  /* dependencies only */
190 int     pgflag;
191 int     exfail;
192 int     Xflag;
193 int     Wallflag;
194 int     Wflag;
195 int     nostartfilesBstaticshared;
196 int     nostdincnostdlib;
197 int     onlyas;
198 int     pthreads;
199 int     xcflag;
200 int     ascpp;
201
202 char    *passp = LIBEXECDIR PREPROCESSOR;
203 char    *pass0 = LIBEXECDIR COMPILER;
204 char    *as = ASSEMBLER;
205 char    *ld = LINKER;
ragge
1.175
206 char    *sysroot;
ragge
1.128
207 char *cppadd[] = CPPADD;
208 #ifdef DYNLINKER
209 char *dynlinker[] = DYNLINKER;
210 #endif
211 #ifdef CRT0FILE
212 char *crt0file = CRT0FILE;
213 #endif
214 #ifdef CRT0FILE_PROFILE
215 char *crt0file_profile = CRT0FILE_PROFILE;
216 #endif
217 #ifdef STARTFILES
218 char *startfiles[] = STARTFILES;
219 char *endfiles[] = ENDFILES;
220 #endif
221 #ifdef STARTFILES_T
222 char *startfiles_T[] = STARTFILES_T;
223 char *endfiles_T[] = ENDFILES_T;
224 #endif
225 #ifdef STARTFILES_S
226 char *startfiles_S[] = STARTFILES_S;
227 char *endfiles_S[] = ENDFILES_S;
228 #endif
229 #ifdef MULTITARGET
230 char *mach = DEFMACH;
231 struct cppmd {
232         char *mach;
233         char *cppmdadd[MAXCPPMDARGS];
234 };
235
236 struct cppmd cppmds[] = CPPMDADDS;
237 #else
238 char *cppmdadd[] = CPPMDADD;
239 #endif
240 #ifdef LIBCLIBS
241 char *libclibs[] = LIBCLIBS;
242 #else
243 char *libclibs[] = { "-lc"NULL };
244 #endif
245 #ifdef LIBCLIBS_PROFILE
246 char *libclibs_profile[] = LIBCLIBS_PROFILE;
247 #else
248 char *libclibs_profile[] = { "-lc_p"NULL };
249 #endif
250 #ifndef STARTLABEL
251 #define STARTLABEL "__start"
252 #endif
253 char *incdir = STDINC;
gmcgarry
1.153
254 char *altincdir = INCLUDEDIR "pcc/";
gmcgarry
1.136
255 char *libdir = LIBDIR;
ragge
1.128
256 char *pccincdir = PCCINCDIR;
257 char *pcclibdir = PCCLIBDIR;
ragge
1.164
258 #ifdef mach_amd64
259 int amd64_i386;
260 #endif
ragge
1.128
261
262 /* handle gcc warning emulations */
263 struct Wflags {
264         char *name;
265         int flags;
266 #define INWALL          1
267 #define NEGATIVE        2
268 Wflags[] = {
gmcgarry
1.154
269         { "-Wtruncate"0 },
270         { "-Wno-truncate"NEGATIVE },
ragge
1.128
271         { "-Werror"0 },
272         { "-Wshadow"0 },
273         { "-Wno-shadow"NEGATIVE },
274         { "-Wpointer-sign"INWALL },
275         { "-Wno-pointer-sign"NEGATIVE },
276         { "-Wsign-compare"0 },
277         { "-Wno-sign-compare"NEGATIVE },
278         { "-Wunknown-pragmas"INWALL },
279         { "-Wno-unknown-pragmas"NEGATIVE },
280         { "-Wunreachable-code"0 },
281         { "-Wno-unreachable-code"NEGATIVE },
282         { 00 },
283 };
284
285 #define SZWFL   (sizeof(Wflags)/sizeof(Wflags[0]))
286
ragge
1.158
287 #ifndef USHORT
288 /* copied from mip/manifest.h */
289 #define USHORT          5
290 #define INT             6
291 #define UNSIGNED        7
292 #endif
293
ragge
1.157
294 /*
295  * Wide char defines.
296  */
297 #if WCHAR_TYPE == USHORT
298 #define WCT "short unsigned int"
299 #define WCM "65535U"
ragge
1.158
300 #if WCHAR_SIZE != 2
301 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
302 #endif
ragge
1.157
303 #elif WCHAR_TYPE == INT
304 #define WCT "int"
305 #define WCM "2147483647"
ragge
1.158
306 #if WCHAR_SIZE != 4
307 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
308 #endif
ragge
1.157
309 #elif WCHAR_TYPE == UNSIGNED
310 #define WCT "unsigned int"
ragge
1.158
311 #define WCM "4294967295U"
312 #if WCHAR_SIZE != 4
313 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
314 #endif
315 #else
316 #error WCHAR_TYPE not defined or invalid
ragge
1.157
317 #endif
318
ragge
1.160
319 #ifdef GCC_COMPAT
320 #ifndef REGISTER_PREFIX
321 #define REGISTER_PREFIX ""
322 #endif
323 #ifndef USER_LABEL_PREFIX
324 #define USER_LABEL_PREFIX ""
325 #endif
326 #endif
327
ragge
1.161
328 #ifndef PCC_PTRDIFF_TYPE
329 #define PCC_PTRDIFF_TYPE "long int"
330 #endif
331
ragge
1.128
332 int
333 main(int argcchar *argv[])
334 {
335         struct Wflags *Wf;
336         char *t, *u;
337         char *assource;
338         char **pv, *ptemp[MAXOPT], **pvt;
gmcgarry
1.163
339         int ncnlnasncppijcnxona;
ragge
1.128
340 #ifdef MULTITARGET
341         int k;
342 #endif
343
344 #ifdef WIN32
345         /* have to prefix path early.  -B may override */
346         incdir = win32pathsubst(incdir);
gmcgarry
1.153
347         altincdir = win32pathsubst(altincdir);
gmcgarry
1.136
348         libdir = win32pathsubst(libdir);
ragge
1.128
349         pccincdir = win32pathsubst(pccincdir);
350         pcclibdir = win32pathsubst(pcclibdir);
351         passp = win32pathsubst(passp);
352         pass0 = win32pathsubst(pass0);
353 #endif
354
gmcgarry
1.163
355         i = nc = nl = nas = ncpp = nxo = 0;
ragge
1.128
356         pv = ptemp;
357         while(++i < argc) {
358                 if (argv[i][0] == '-') {
359                         switch (argv[i][1]) {
360                         default:
361                                 goto passa;
362 #ifdef notyet
363         /* must add library options first (-L/-l/...) */
364                                 error("unrecognized option `-%c'"argv[i][1]);
365                                 break;
366 #endif
367
368                         case '-'/* double -'s */
ragge
1.130
369                                 if (strcmp(argv[i], "--version") == 0) {
ragge
1.128
370                                         printf("%s\n"VERSSTR);
ragge
1.130
371                                         return 0;
ragge
1.175
372                                 } else if (strncmp(argv[i], "--sysroot="10) == 0) {
373                                         sysroot = argv[i] + 10;
ragge
1.169
374                                 } else if (strcmp(argv[i], "--param") == 0) {
ragge
1.128
375                                         /* NOTHING YET */;
ragge
1.169
376                                         i++; /* ignore arg */
377                                 } else
gmcgarry
1.148
378                                         goto passa;
ragge
1.128
379                                 break;
380
381                         case 'B'/* other search paths for binaries */
ragge
1.175
382                                 add_prefix(argv[i] + 2);
ragge
1.128
383                                 break;
384
385 #ifdef MULTITARGET
386                         case 'b':
387                                 t = &argv[i][2];
388                                 if (*t == '\0' && i + 1 < argc) {
389                                         t = argv[i+1];
390                                         i++;
391                                 }
392                                 if (strncmp(t"?"1) == 0) {
393                                         /* show machine targets */
394                                         printf("Available machine targets:");
395                                         for (j=0cppmds[j].machj++)
396                                                 printf(" %s",cppmds[j].mach);
397                                         printf("\n");
398                                         exit(0);
399                                 }
400                                 for (j=0cppmds[j].machj++)
401                                         if (strcmp(tcppmds[j].mach) == 0) {
402                                                 mach = cppmds[j].mach;
403                                                 break;
404                                         }
405                                 if (cppmds[j].mach == NULL)
406                                         errorx(1"unknown target arch %s"t);
407                                 break;
408 #endif
409
410                         case 'X':
411                                 Xflag++;
412                                 break;
413                         case 'W'/* Ignore (most of) W-flags */
414                                 if (strncmp(argv[i], "-Wl,"4) == 0) {
415                                         /* options to the linker */
416                                         t = &argv[i][4];
417                                         while ((u = strchr(t','))) {
418                                                 *u++ = 0;
419                                                 llist[nl++] = t;
420                                                 t = u;
421                                         }
422                                         llist[nl++] = t;
423                                 } else if (strncmp(argv[i], "-Wa,"4) == 0) {
424                                         /* options to the assembler */
425                                         t = &argv[i][4];
426                                         while ((u = strchr(t','))) {
427                                                 *u++ = 0;
428                                                 aslist[nas++] = t;
429                                                 t = u;
430                                         }
431                                         aslist[nas++] = t;
ragge
1.137
432                                 } else if (strncmp(argv[i], "-Wc,"4) == 0) {
433                                         /* options to ccom */
434                                         t = &argv[i][4];
435                                         while ((u = strchr(t','))) {
436                                                 *u++ = 0;
437                                                 wlist[nw++] = t;
438                                                 t = u;
439                                         }
440                                         wlist[nw++] = t;
ragge
1.128
441                                 } else if (strncmp(argv[i], "-Wp,"4) == 0) {
442                                         /* preprocessor */
gmcgarry
1.163
443                                         t = &argv[i][4];
444                                         while ((u = strchr(t','))) {
445                                                 *u++ = 0;
446                                                 cpplist[ncpp++] = t;
447                                                 t = u;
448                                         }
449                                         cpplist[ncpp++] = t;
ragge
1.128
450                                 } else if (strcmp(argv[i], "-Wall") == 0) {
451                                         Wallflag = 1;
452                                 } else if (strcmp(argv[i], "-WW") == 0) {
453                                         Wflag = 1;
454                                 } else {
455                                         /* check and set if available */
456                                         for (Wf = WflagsWf->nameWf++) {
457                                                 if (strcmp(argv[i], Wf->name))
458                                                         continue;
459                                                 wlist[nw++] = Wf->name;
460                                         }
461                                 }
462                                 break;
463
464                         case 'f'/* GCC compatibility flags */
465                                 if (strcmp(argv[i], "-fPIC") == 0)
466                                         kflag = F_PIC;
467                                 else if (strcmp(argv[i], "-fpic") == 0)
468                                         kflag = F_pic;
469                                 else if (strcmp(argv[i],
470                                     "-fsigned-char") == 0)
471                                         flist[nf++] = argv[i];
472                                 else if (strcmp(argv[i],
473                                     "-fno-signed-char") == 0)
474                                         flist[nf++] = argv[i];
475                                 else if (strcmp(argv[i],
476                                     "-funsigned-char") == 0)
477                                         flist[nf++] = argv[i];
478                                 else if (strcmp(argv[i],
479                                     "-fno-unsigned-char") == 0)
480                                         flist[nf++] = argv[i];
481                                 else if (strcmp(argv[i],
482                                     "-fstack-protector") == 0) {
483                                         flist[nf++] = argv[i];
484                                         sspflag++;
485                                 } else if (strcmp(argv[i],
486                                     "-fstack-protector-all") == 0) {
487                                         flist[nf++] = argv[i];
488                                         sspflag++;
489                                 } else if (strcmp(argv[i],
490                                     "-fno-stack-protector") == 0) {
491                                         flist[nf++] = argv[i];
492                                         sspflag = 0;
493                                 } else if (strcmp(argv[i],
494                                     "-fno-stack-protector-all") == 0) {
495                                         flist[nf++] = argv[i];
496                                         sspflag = 0;
497                                 }
498                                 /* silently ignore the rest */
499                                 break;
500
501                         case 'g'/* create debug output */
ragge
1.177
502                                 if (argv[i][2] == '0')
503                                         gflag = 0;
504                                 else
505                                         gflag++;
ragge
1.128
506                                 break;
507
508                         case 'i':
509                                 if (strcmp(argv[i], "-isystem") == 0) {
510                                         *pv++ = "-S";
511                                         *pv++ = argv[++i];
512                                 } else if (strcmp(argv[i], "-include") == 0) {
513                                         *pv++ = "-i";
514                                         *pv++ = argv[++i];
515                                 } else if (strcmp(argv[i], "-idirafter") == 0) {
516                                         idirafter = argv[++i];
gmcgarry
1.172
517 #ifdef os_darwin
518                                 } else if (strcmp(argv[i], "-install_name") == 0) {
519                                         llist[nl++] = argv[i];
520                                         llist[nl++] = argv[++i];
521 #endif
ragge
1.128
522                                 } else
523                                         goto passa;
524                                 break;
525
526                         case 'k'/* generate PIC code */
527                                 kflag = F_pic;
528                                 break;
529
530                         case 'm'/* target-dependent options */
ragge
1.164
531 #ifdef mach_amd64
532                                 /* need to call i386 ccom for this */
533                                 if (strcmp(argv[i], "-m32") == 0) {
534                                         pass0 = LIBEXECDIR "/ccom_i386";
535                                         amd64_i386 = 1;
536                                         break;
537                                 }
538 #endif
ragge
1.128
539                                 mlist[nm++] = argv[i];
ragge
1.169
540                                 if (argv[i][2] == 0) {
541                                         /* separate second arg */
542                                         /* give also to linker */
543                                         llist[nl++] = argv[i++];
544                                         mlist[nm++] = argv[i];
545                                         llist[nl++] = argv[i];
546                                 }
ragge
1.128
547                                 break;
548
549                         case 'n'/* handle -n flags */
550                                 if (strcmp(argv[i], "-nostdinc") == 0)
551                                         nostdinc++;
552                                 else if (strcmp(argv[i], "-nostdlib") == 0) {
553                                         nostdlib++;
554                                         nostartfiles++;
555                                 } else if (strcmp(argv[i], "-nostartfiles") == 0)
556                                         nostartfiles = 1;
557                                 else
558                                         goto passa;
559                                 break;
560
561                         case 'p':
562                                 if (strcmp(argv[i], "-pg") == 0 ||
563                                     strcmp(argv[i], "-p") == 0)
564                                         pgflag++;
565                                 else if (strcmp(argv[i], "-pthread") == 0)
566                                         pthreads++;
567                                 else if (strcmp(argv[i], "-pipe") == 0)
568                                         /* NOTHING YET */;
gmcgarry
1.144
569                                 else if (strcmp(argv[i], "-pedantic") == 0)
570                                         /* NOTHING YET */;
ragge
1.162
571                                 else if (strcmp(argv[i],
572                                     "-print-prog-name=ld") == 0) {
573                                         printf("%s\n"LINKER);
574                                         return 0;
ragge
1.174
575                                 } else if (strcmp(argv[i],
576                                     "-print-multi-os-directory") == 0) {
577                                         printf("%s\n"MULTIOSDIR);
578                                         return 0;
ragge
1.162
579                                 } else
ragge
1.128
580                                         errorx(1"unknown option %s"argv[i]);
581                                 break;
582
gmcgarry
1.145
583                         case 'r':
584                                 rflag = 1;
585                                 break;
586
ragge
1.128
587                         case 'x':
588                                 t = &argv[i][2];
589                                 if (*t == 0)
590                                         t = argv[++i];
591                                 if (strcmp(t"c") == 0)
592                                         xcflag = 1/* default */
593                                 else if (strcmp(t"assembler-with-cpp") == 0)
594                                         ascpp = 1;
595 #ifdef notyet
596                                 else if (strcmp(t"c++") == 0)
597                                         cxxflag++;
598 #endif
599                                 else
600                                         xlist[xnum++] = argv[i];
601                                 break;
602                         case 't':
603                                 tflag++;
604                                 break;
605                         case 'S':
606                                 sflag++;
607                                 cflag++;
608                                 break;
609                         case 'o':
610                                 if (outfile)
611                                         errorx(8"too many -o");
612                                 outfile = argv[++i];
613                                 break;
614                         case 'O':
615                                 if (argv[i][2] == '0')
616                                         Oflag = 0;
617                                 else
618                                         Oflag++;
619                                 break;
620                         case 'E':
621                                 Eflag++;
622                                 break;
623                         case 'P':
624                                 pflag++;
625                                 *pv++ = argv[i];
626                         case 'c':
gmcgarry
1.172
627 #ifdef os_darwin
628                                 if (strcmp(argv[i], "-compatibility_version") == 0) {
629                                         llist[nl++] = argv[i];
630                                         llist[nl++] = argv[++i];
631                                 } else if (strcmp(argv[i], "-current_version") == 0) {
632                                         llist[nl++] = argv[i];
633                                         llist[nl++] = argv[++i];
634                                 } else
635 #endif
636                                         cflag++;
ragge
1.128
637                                 break;
638 #if 0
639                         case '2':
640                                 if(argv[i][2] == '\0')
641                                         pref = "/lib/crt2.o";
642                                 else {
643                                         pref = "/lib/crt20.o";
644                                 }
645                                 break;
646 #endif
647                         case 'C':
gmcgarry
1.163
648                                 cpplist[ncpp++] = argv[i];
ragge
1.128
649                                 break;
650                         case 'D':
651                         case 'I':
652                         case 'U':
653                                 *pv++ = argv[i];
654                                 if (argv[i][2] == 0)
655                                         *pv++ = argv[++i];
656                                 if (pv >= ptemp+MAXOPT) {
657                                         error("Too many DIU options");
658                                         --pv;
659                                 }
660                                 break;
661
662                         case 'M':
663                                 Mflag++;
664                                 break;
665
666                         case 'd':
gmcgarry
1.144
667 #ifdef os_darwin
668                                 if (strcmp(argv[i], "-dynamiclib") == 0) {
669                                         shared = 1;
670                                 } else
671 #endif
672                                 if (strcmp(argv[i], "-d") == 0) {
673                                         dflag++;
674                                         strlcpy(alistargv[i], sizeof (alist));
675                                 }
ragge
1.128
676                                 break;
677                         case 'v':
678                                 printf("%s\n"VERSSTR);
679                                 vflag++;
680                                 break;
681
682                         case 's':
gmcgarry
1.144
683 #ifndef os_darwin
684                                 if (strcmp(argv[i], "-shared") == 0) {
ragge
1.128
685                                         shared = 1;
686 #ifndef os_win32
687                                         nostdlib = 1;
688 #endif
gmcgarry
1.144
689                                 } else
690 #endif
691                                 if (strcmp(argv[i], "-static") == 0) {
692                                         Bstatic = 1;
ragge
1.128
693                                 } else if (strncmp(argv[i], "-std"4) == 0) {
694                                         /* ignore gcc -std= */;
695                                 } else
696                                         goto passa;
697                                 break;
698                         }
699                 } else {
700                 passa:
701                         t = argv[i];
702                         if (*argv[i] == '-' && argv[i][1] == 'L')
703                                 ;
704                         else if((c=getsuf(t))=='c' || c=='S' || c=='i' ||
705                             c=='s'|| Eflag || xcflag) {
706                                 clist[nc++] = t;
707                                 if (nc>=MAXFIL) {
708                                         error("Too many source files");
709                                         exit(1);
710                                 }
711                         }
712
713                         /* Check for duplicate .o files. */
714                         for (j = getsuf(t) == 'o' ? 0 : nlj < nlj++) {
715                                 if (strcmp(llist[j], t) == 0)
716                                         break;
717                         }
gmcgarry
1.150
718                         if ((c=getsuf(t))!='c' && c!='S' &&
719                             c!='s' && c!='i' && j==nl) {
ragge
1.128
720                                 llist[nl++] = t;
721                                 if (nl >= MAXLIB) {
722                                         error("Too many object/library files");
723                                         exit(1);
724                                 }
725                                 if (getsuf(t)=='o')
726                                         nxo++;
727                         }
728                 }
729         }
730         /* Sanity checking */
731         if (nc == 0 && nl == 0)
732                 errorx(8"no input files");
733         if (outfile && (cflag || sflag || Eflag) && nc > 1)
734                 errorx(8"-o given with -c || -E || -S and more than one file");
735         if (outfile && clist[0] && strcmp(outfileclist[0]) == 0)
736                 errorx(8"output file will be clobbered");
gmcgarry
1.150
737         if (nc==0)
ragge
1.128
738                 goto nocom;
739         if (pflag==0) {
740                 if (!sflag)
741                         tmp3 = gettmp();
742                 tmp4 = gettmp();
743         }
744         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
745                 signal(SIGINTidexit);
746         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
747                 signal(SIGTERMidexit);
748 #ifdef MULTITARGET
ragge
1.133
749         pass0 = copy(LIBEXECDIR "/ccom_"k = strlen(mach));
750         strlcat(pass0machsizeof(LIBEXECDIR "/ccom_") + k);
ragge
1.128
751 #endif
752         pvt = pv;
753         for (i=0i<nci++) {
754                 /*
755                  * C preprocessor
756                  */
757                 if (nc>1 && !Eflag)
758                         printf("%s:\n"clist[i]);
759                 onlyas = 0;
760                 assource = tmp3;
761                 if (getsuf(clist[i])=='S')
762                         ascpp = 1;
763                 if (getsuf(clist[i])=='i') {
764                         if(Eflag)
765                                 continue;
766                         goto com;
767                 } else if (ascpp) {
768                         onlyas = 1;
769                 } else if (getsuf(clist[i])=='s') {
770                         assource = clist[i];
771                         goto assemble;
772                 }
773                 if (pflag)
774                         tmp4 = setsuf(clist[i], 'i');
775                 na = 0;
776                 av[na++] = "cpp";
777                 if (vflag)
778                         av[na++] = "-v";
779                 av[na++] = "-D__PCC__=" MKS(PCC_MAJOR);
780                 av[na++] = "-D__PCC_MINOR__=" MKS(PCC_MINOR);
781                 av[na++] = "-D__PCC_MINORMINOR__=" MKS(PCC_MINORMINOR);
gmcgarry
1.156
782 #ifndef os_win32
ragge
1.155
783 #ifdef GCC_COMPAT
784                 av[na++] = "-D__GNUC__=4";
785                 av[na++] = "-D__GNUC_MINOR__=3";
786                 av[na++] = "-D__GNUC_PATCHLEVEL__=1";
787                 av[na++] = "-D__GNUC_STDC_INLINE__=1";
ragge
1.170
788 #endif
789 #endif
ragge
1.166
790                 av[na++] = "-D__VERSION__=" MKS(VERSSTR);
ragge
1.167
791                 av[na++] = "-D__SCHAR_MAX__=" MKS(MAX_CHAR);
792                 av[na++] = "-D__SHRT_MAX__=" MKS(MAX_SHORT);
793                 av[na++] = "-D__INT_MAX__=" MKS(MAX_INT);
794                 av[na++] = "-D__LONG_MAX__=" MKS(MAX_LONG);
795                 av[na++] = "-D__LONG_LONG_MAX__=" MKS(MAX_LONGLONG);
ragge
1.170
796 #ifdef CHAR_UNSIGNED
797                 av[na++] = "-D__CHAR_UNSIGNED__";
gmcgarry
1.156
798 #endif
ragge
1.128
799                 if (ascpp)
800                         av[na++] = "-D__ASSEMBLER__";
801                 if (sspflag)
802                         av[na++] = "-D__SSP__=1";
803                 if (pthreads)
804                         av[na++] = "-D_PTHREADS";
805                 if (Mflag)
806                         av[na++] = "-M";
ragge
1.160
807                 if (Oflag)
808                         av[na++] = "-D__OPTIMIZE__";
809 #ifdef GCC_COMPAT
810                 av[na++] = "-D__REGISTER_PREFIX__=" REGISTER_PREFIX;
811                 av[na++] = "-D__USER_LABEL_PREFIX__=" USER_LABEL_PREFIX;
812                 if (Oflag)
813                         av[na++] = "-D__OPTIMIZE__";
814 #endif
ragge
1.128
815                 if (dflag)
816                         av[na++] = alist;
817                 for (j = 0cppadd[j]; j++)
818                         av[na++] = cppadd[j];
gmcgarry
1.163
819                 for (j = 0j < ncppj++)
820                         av[na++] = cpplist[j];
gmcgarry
1.149
821                 av[na++] = "-D__STDC_ISO_10646__=200009L";
ragge
1.157
822                 av[na++] = "-D__WCHAR_TYPE__=" WCT;
823                 av[na++] = "-D__SIZEOF_WCHAR_T__=" MKS(WCHAR_SIZE);
824                 av[na++] = "-D__WCHAR_MAX__=" WCM;
gmcgarry
1.142
825                 av[na++] = "-D__WINT_TYPE__=unsigned int";
gmcgarry
1.149
826                 av[na++] = "-D__SIZE_TYPE__=unsigned long";
ragge
1.161
827                 av[na++] = "-D__PTRDIFF_TYPE__=" PCC_PTRDIFF_TYPE;
gmcgarry
1.142
828                 av[na++] = "-D__SIZEOF_WINT_T__=4";
gmcgarry
1.171
829 #ifdef os_darwin
830                 av[na++] = "-D__FLT_MIN__=1.17549435e-38F";
831                 av[na++] = "-D__DBL_MIN__=2.2250738585072014e-308";
832                 av[na++] = "-D__LDBL_MIN__=3.36210314311209350626e-4932L";
833 #endif
ragge
1.128
834 #ifdef MULTITARGET
835                 for (k = 0cppmds[k].machk++) {
836                         if (strcmp(cppmds[k].machmach) != 0)
837                                 continue;
838                         for (j = 0cppmds[k].cppmdadd[j]; j++)
839                                 av[na++] = cppmds[k].cppmdadd[j];
840                         break;
841                 }
842 #else
843                 for (j = 0cppmdadd[j]; j++)
844                         av[na++] = cppmdadd[j];
845 #endif
846                 if (tflag)
847                         av[na++] = "-t";
848                 for(pv=ptemppv <pvtpv++)
849                         av[na++] = *pv;
gmcgarry
1.153
850                 if (!nostdinc) {
851                         av[na++] = "-S"av[na++] = altincdir;
ragge
1.128
852                         av[na++] = "-S"av[na++] = incdir;
gmcgarry
1.153
853                         av[na++] = "-S"av[na++] = pccincdir;
854                 }
ragge
1.128
855                 if (idirafter) {
856                         av[na++] = "-I";
857                         av[na++] = idirafter;
858                 }
859                 av[na++] = clist[i];
860                 if (!Eflag && !Mflag)
861                         av[na++] = tmp4;
ragge
1.141
862                 if ((Eflag || Mflag) && outfile)
ragge
1.128
863                          ermfile = av[na++] = outfile;
864                 av[na++]=0;
gmcgarry
1.140
865                 if (callsys(passpav)) {
866                         exfail++;
867                         eflag++;
868                 }
ragge
1.128
869                 if (Eflag || Mflag)
870                         continue;
871                 if (onlyas) {
872                         assource = tmp4;
873                         goto assemble;
874                 }
875
876                 /*
877                  * C compiler
878                  */
879         com:
880                 na = 0;
881                 av[na++]= "ccom";
882                 if (Wallflag) {
883                         /* Set only the same flags as gcc */
884                         for (Wf = WflagsWf->nameWf++) {
885                                 if (Wf->flags != INWALL)
886                                         continue;
887                                 av[na++] = Wf->name;
888                         }
889                 }
890                 if (Wflag) {
891                         /* set all positive flags */
892                         for (Wf = WflagsWf->nameWf++) {
893                                 if (Wf->flags == NEGATIVE)
894                                         continue;
895                                 av[na++] = Wf->name;
896                         }
897                 }
898                 for (j = 0j < nwj++)
899                         av[na++] = wlist[j];
900                 for (j = 0j < nfj++)
901                         av[na++] = flist[j];
ragge
1.159
902 #if !defined(os_sunos) && !defined(mach_i386)
ragge
1.128
903                 if (vflag)
904                         av[na++] = "-v";
ragge
1.159
905 #endif
ragge
1.128
906                 if (pgflag)
907                         av[na++] = "-p";
908                 if (gflag)
909                         av[na++] = "-g";
910 #ifdef os_darwin
911                 /* darwin always wants PIC compilation */
912                 if (!Bstatic)
913                         av[na++] = "-k";
ragge
1.159
914 #elif defined(os_sunos) && defined(mach_i386)
915                 if (kflag) {
916                         av[na++] = "-K";
917                         av[na++] = "pic";
918                 }
ragge
1.128
919 #else
920                 if (kflag)
921                         av[na++] = "-k";
922 #endif
923                 if (Oflag) {
924                         av[na++] = "-xtemps";
925                         av[na++] = "-xdeljumps";
ragge
1.133
926                         av[na++] = "-xinline";
ragge
1.128
927                 }
928                 for (j = 0j < xnumj++)
929                         av[na++] = xlist[j];
930                 for (j = 0j < nmj++)
931                         av[na++] = mlist[j];
932                 if (getsuf(clist[i])=='i')
933                         av[na++] = clist[i];
934                 else
935                         av[na++] = tmp4/* created by cpp */
936                 if (pflag || exfail)
937                         {
938                         cflag++;
939                         continue;
940                         }
941                 if(sflag) {
942                         if (outfile)
943                                 tmp3 = outfile;
944                         else
945                                 tmp3 = setsuf(clist[i], 's');
946                 }
947                 ermfile = av[na++] = tmp3;
948 #if 0
949                 if (proflag) {
950                         av[3] = "-XP";
951                         av[4] = 0;
952                 } else
953                         av[3] = 0;
954 #endif
955                 av[na++] = NULL;
956                 if (callsys(pass0av)) {
957                         cflag++;
958                         eflag++;
959                         continue;
960                 }
961                 if (sflag)
962                         continue;
963
964                 /*
965                  * Assembler
966                  */
967         assemble:
968                 na = 0;
969                 av[na++] = as;
970                 for (j = 0j < nasj++)
971                         av[na++] = aslist[j];
gmcgarry
1.178
972 #if defined(USE_YASM)
gmcgarry
1.149
973                 av[na++] = "-p";
974                 av[na++] = "gnu";
975                 av[na++] = "-f";
gmcgarry
1.178
976 #if defined(os_win32)
gmcgarry
1.149
977                 av[na++] = "win32";
gmcgarry
1.178
978 #elif defined(os_darwin)
979                 av[na++] = "macho";
980 #else
981                 av[na++] = "elf";
982 #endif
gmcgarry
1.149
983 #endif
ragge
1.128
984 #if defined(os_sunos) && defined(mach_sparc64)
985                 av[na++] = "-m64";
986 #endif
987 #if defined(os_darwin)
988                 if (Bstatic)
989                         av[na++] = "-static";
990 #endif
gmcgarry
1.178
991 #if !defined(USE_YASM)
ragge
1.128
992                 if (vflag)
993                         av[na++] = "-v";
gmcgarry
1.178
994 #endif
ragge
1.128
995                 if (kflag)
996                         av[na++] = "-k";
ragge
1.164
997 #ifdef mach_amd64
998                 if (amd64_i386)
999                         av[na++] = "--32";
1000 #endif
ragge
1.128
1001                 av[na++] = "-o";
1002                 if (outfile && cflag)
1003                         ermfile = av[na++] = outfile;
gmcgarry
1.150
1004                 else if (cflag)
1005                         ermfile = av[na++] = olist[i] = setsuf(clist[i], 'o');
ragge
1.128
1006                 else
gmcgarry
1.150
1007                         ermfile = av[na++] = olist[i] = gettmp();
ragge
1.128
1008                 av[na++] = assource;
1009                 if (dflag)
1010                         av[na++] = alist;
1011                 av[na++] = 0;
1012                 if (callsys(asav)) {
1013                         cflag++;
1014                         eflag++;
1015                         cunlink(tmp4);
1016                         continue;
1017                 }
1018                 cunlink(tmp4);
1019