Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20110315211414

Diff

Diff from 1.174 to:

Annotations

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

Annotated File View

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