Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20110315192152

Diff

Diff from 1.173 to:

Annotations

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

Annotated File View

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