Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20110326062519

Diff

Diff from 1.176 to:

Annotations

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

Annotated File View

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