Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:plunky:20110813082145

Diff

Diff from 1.196 to:

Annotations

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

Annotated File View

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