Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:plunky:20110826204707

Diff

Diff from 1.205 to:

Annotations

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

Annotated File View

plunky
1.205
1 /*      $Id: cc.c,v 1.205 2011/08/26 20:47:07 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
ragge
1.174
119 #ifndef MULTIOSDIR
120 #define MULTIOSDIR      "."
121 #endif
122
123
ragge
1.128
124 #define MAXFIL 10000
125 #define MAXLIB 10000
126 #define MAXAV  10000
ragge
1.173
127 #define MAXOPT 200
ragge
1.128
128 char    *tmp3;
129 char    *tmp4;
130 char    *outfile, *ermfile;
ragge
1.175
131 static void add_prefix(const char *);
132 static char *find_file(const char *, int);
plunky
1.183
133 char *copy(const char *, int);
plunky
1.185
134 char *cat(const char *, const char *);
gmcgarry
1.150
135 char *setsuf(char *, char);
ragge
1.198
136 int cxxsuf(char *);
ragge
1.128
137 int getsuf(char *);
ragge
1.198
138 char *getsufp(char *s);
ragge
1.128
139 int main(intchar *[]);
140 void error(char *, ...);
141 void errorx(intchar *, ...);
142 int callsys(char [], char *[]);
143 int cunlink(char *);
144 void dexit(int);
145 void idexit(int);
146 char *gettmp(void);
147 void *ccmalloc(int size);
148 #ifdef WIN32
149 char *win32pathsubst(char *);
gmcgarry
1.149
150 char *win32commandline(char *, char *[]);
ragge
1.128
151 #endif
152 char    *av[MAXAV];
153 char    *clist[MAXFIL];
gmcgarry
1.150
154 char    *olist[MAXFIL];
ragge
1.128
155 char    *llist[MAXLIB];
156 char    *aslist[MAXAV];
gmcgarry
1.163
157 char    *cpplist[MAXAV];
ragge
1.128
158 char    *xlist[100];
159 int     xnum;
160 char    *mlist[100];
161 char    *flist[100];
162 char    *wlist[100];
163 char    *idirafter;
164 int     nm;
165 int     nf;
166 int     nw;
167 int     sspflag;
168 int     pflag;
169 int     sflag;
170 int     cflag;
171 int     eflag;
172 int     gflag;
gmcgarry
1.145
173 int     rflag;
ragge
1.128
174 int     vflag;
175 int     tflag;
176 int     Eflag;
177 int     Oflag;
178 int     kflag;  /* generate PIC/pic code */
179 #define F_PIC   1
180 #define F_pic   2
181 int     Mflag;  /* dependencies only */
182 int     pgflag;
183 int     exfail;
184 int     Xflag;
185 int     Wallflag;
186 int     Wflag;
187 int     nostartfilesBstaticshared;
188 int     nostdincnostdlib;
189 int     onlyas;
190 int     pthreads;
ragge
1.198
191 int     xcflagxgnu89xgnu99;
ragge
1.128
192 int     ascpp;
plunky
1.196
193 #ifdef CHAR_UNSIGNED
194 int     funsigned_char = 1;
195 #else
196 int     funsigned_char = 0;
197 #endif
ragge
1.198
198 int     cxxflag;
ragge
1.128
199
200 char    *passp = LIBEXECDIR PREPROCESSOR;
201 char    *pass0 = LIBEXECDIR COMPILER;
ragge
1.198
202 char    *passxx0 = LIBEXECDIR "c++com";
ragge
1.128
203 char    *as = ASSEMBLER;
204 char    *ld = LINKER;
ragge
1.175
205 char    *sysroot;
ragge
1.128
206 char *cppadd[] = CPPADD;
207 #ifdef DYNLINKER
208 char *dynlinker[] = DYNLINKER;
209 #endif
210 #ifdef CRT0FILE
211 char *crt0file = CRT0FILE;
212 #endif
213 #ifdef CRT0FILE_PROFILE
214 char *crt0file_profile = CRT0FILE_PROFILE;
215 #endif
216 #ifdef STARTFILES
217 char *startfiles[] = STARTFILES;
218 char *endfiles[] = ENDFILES;
219 #endif
220 #ifdef STARTFILES_T
221 char *startfiles_T[] = STARTFILES_T;
222 char *endfiles_T[] = ENDFILES_T;
223 #endif
224 #ifdef STARTFILES_S
225 char *startfiles_S[] = STARTFILES_S;
226 char *endfiles_S[] = ENDFILES_S;
227 #endif
228 #ifdef MULTITARGET
229 char *mach = DEFMACH;
230 struct cppmd {
231         char *mach;
232         char *cppmdadd[MAXCPPMDARGS];
233 };
234
235 struct cppmd cppmds[] = CPPMDADDS;
236 #else
237 char *cppmdadd[] = CPPMDADD;
238 #endif
239 #ifdef LIBCLIBS
240 char *libclibs[] = LIBCLIBS;
241 #else
242 char *libclibs[] = { "-lc"NULL };
243 #endif
244 #ifdef LIBCLIBS_PROFILE
245 char *libclibs_profile[] = LIBCLIBS_PROFILE;
246 #else
247 char *libclibs_profile[] = { "-lc_p"NULL };
248 #endif
249 #ifndef STARTLABEL
250 #define STARTLABEL "__start"
251 #endif
252 char *incdir = STDINC;
gmcgarry
1.153
253 char *altincdir = INCLUDEDIR "pcc/";
gmcgarry
1.136
254 char *libdir = LIBDIR;
plunky
1.200
255 #ifdef PCCINCDIR
ragge
1.128
256 char *pccincdir = PCCINCDIR;
ragge
1.198
257 char *pxxincdir = PCCINCDIR "/c++";
plunky
1.200
258 #endif
259 #ifdef PCCLIBDIR
ragge
1.128
260 char *pcclibdir = PCCLIBDIR;
plunky
1.200
261 #endif
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
ragge
1.198
363         if (strcmp(argv[0], "p++") == 0) {
364                 cxxflag = 1;
365                 pass0 = passxx0;
366         }
367
ragge
1.128
368 #ifdef WIN32
369         /* have to prefix path early.  -B may override */
370         incdir = win32pathsubst(incdir);
gmcgarry
1.153
371         altincdir = win32pathsubst(altincdir);
gmcgarry
1.136
372         libdir = win32pathsubst(libdir);
plunky
1.200
373 #ifdef PCCINCDIR
ragge
1.128
374         pccincdir = win32pathsubst(pccincdir);
plunky
1.199
375         pxxincdir = win32pathsubst(pxxincdir);
plunky
1.200
376 #endif
377 #ifdef PCCLIBDIR
ragge
1.128
378         pcclibdir = win32pathsubst(pcclibdir);
plunky
1.200
379 #endif
ragge
1.128
380         passp = win32pathsubst(passp);
381         pass0 = win32pathsubst(pass0);
gmcgarry
1.180
382 #ifdef STARTFILES
383         for (i = 0startfiles[i] != NULLi++)
384                 startfiles[i] = win32pathsubst(startfiles[i]);
385         for (i = 0endfiles[i] != NULLi++)
386                 endfiles[i] = win32pathsubst(endfiles[i]);
387 #endif
388 #ifdef STARTFILES_T
389         for (i = 0startfiles_T[i] != NULLi++)
390                 startfiles_T[i] = win32pathsubst(startfiles_T[i]);
391         for (i = 0endfiles_T[i] != NULLi++)
392                 endfiles_T[i] = win32pathsubst(endfiles_T[i]);
393 #endif
394 #ifdef STARTFILES_S
395         for (i = 0startfiles_S[i] != NULLi++)
396                 startfiles_S[i] = win32pathsubst(startfiles_S[i]);
397         for (i = 0endfiles_S[i] != NULLi++)
398                 endfiles_S[i] = win32pathsubst(endfiles_S[i]);
399 #endif
ragge
1.128
400 #endif
401
gmcgarry
1.163
402         i = nc = nl = nas = ncpp = nxo = 0;
ragge
1.128
403         pv = ptemp;
404         while(++i < argc) {
405                 if (argv[i][0] == '-') {
406                         switch (argv[i][1]) {
407                         default:
408                                 goto passa;
409 #ifdef notyet
410         /* must add library options first (-L/-l/...) */
411                                 error("unrecognized option `-%c'"argv[i][1]);
412                                 break;
413 #endif
414
415                         case '-'/* double -'s */
ragge
1.130
416                                 if (strcmp(argv[i], "--version") == 0) {
ragge
1.128
417                                         printf("%s\n"VERSSTR);
ragge
1.130
418                                         return 0;
ragge
1.175
419                                 } else if (strncmp(argv[i], "--sysroot="10) == 0) {
420                                         sysroot = argv[i] + 10;
ragge
1.169
421                                 } else if (strcmp(argv[i], "--param") == 0) {
ragge
1.128
422                                         /* NOTHING YET */;
ragge
1.169
423                                         i++; /* ignore arg */
424                                 } else
gmcgarry
1.148
425                                         goto passa;
ragge
1.128
426                                 break;
427
428                         case 'B'/* other search paths for binaries */
ragge
1.175
429                                 add_prefix(argv[i] + 2);
ragge
1.128
430                                 break;
431
432 #ifdef MULTITARGET
433                         case 'b':
434                                 t = &argv[i][2];
435                                 if (*t == '\0' && i + 1 < argc) {
436                                         t = argv[i+1];
437                                         i++;
438                                 }
439                                 if (strncmp(t"?"1) == 0) {
440                                         /* show machine targets */
441                                         printf("Available machine targets:");
442                                         for (j=0cppmds[j].machj++)
443                                                 printf(" %s",cppmds[j].mach);
444                                         printf("\n");
445                                         exit(0);
446                                 }
447                                 for (j=0cppmds[j].machj++)
448                                         if (strcmp(tcppmds[j].mach) == 0) {
449                                                 mach = cppmds[j].mach;
450                                                 break;
451                                         }
452                                 if (cppmds[j].mach == NULL)
453                                         errorx(1"unknown target arch %s"t);
454                                 break;
455 #endif
456
457                         case 'X':
458                                 Xflag++;
459                                 break;
460                         case 'W'/* Ignore (most of) W-flags */
461                                 if (strncmp(argv[i], "-Wl,"4) == 0) {
462                                         /* options to the linker */
463                                         t = &argv[i][4];
464                                         while ((u = strchr(t','))) {
465                                                 *u++ = 0;
466                                                 llist[nl++] = t;
467                                                 t = u;
468                                         }
469                                         llist[nl++] = t;
470                                 } else if (strncmp(argv[i], "-Wa,"4) == 0) {
471                                         /* options to the assembler */
472                                         t = &argv[i][4];
473                                         while ((u = strchr(t','))) {
474                                                 *u++ = 0;
475                                                 aslist[nas++] = t;
476                                                 t = u;
477                                         }
478                                         aslist[nas++] = t;
ragge
1.137
479                                 } else if (strncmp(argv[i], "-Wc,"4) == 0) {
480                                         /* options to ccom */
481                                         t = &argv[i][4];
482                                         while ((u = strchr(t','))) {
483                                                 *u++ = 0;
484                                                 wlist[nw++] = t;
485                                                 t = u;
486                                         }
487                                         wlist[nw++] = t;
ragge
1.128
488                                 } else if (strncmp(argv[i], "-Wp,"4) == 0) {
489                                         /* preprocessor */
gmcgarry
1.163
490                                         t = &argv[i][4];
491                                         while ((u = strchr(t','))) {
492                                                 *u++ = 0;
493                                                 cpplist[ncpp++] = t;
494                                                 t = u;
495                                         }
496                                         cpplist[ncpp++] = t;
plunky
1.193
497                                 } else if (strcmp(argv[i], "-Werror") == 0) {
498                                         wlist[nw++] = argv[i];
ragge
1.128
499                                 } else if (strcmp(argv[i], "-Wall") == 0) {
500                                         Wallflag = 1;
501                                 } else if (strcmp(argv[i], "-WW") == 0) {
502                                         Wflag = 1;
503                                 } else {
504                                         /* check and set if available */
505                                         for (Wf = WflagsWf->nameWf++) {
506                                                 if (strcmp(argv[i], Wf->name))
507                                                         continue;
508                                                 wlist[nw++] = Wf->name;
509                                         }
510                                 }
511                                 break;
512
513                         case 'f'/* GCC compatibility flags */
514                                 if (strcmp(argv[i], "-fPIC") == 0)
515                                         kflag = F_PIC;
516                                 else if (strcmp(argv[i], "-fpic") == 0)
517                                         kflag = F_pic;
ragge
1.195
518                                 else if (strcmp(argv[i], "-ffreestanding") == 0)
519                                         flist[nf++] = argv[i];
ragge
1.128
520                                 else if (strcmp(argv[i],
plunky
1.196
521                                     "-fsigned-char") == 0) {
ragge
1.128
522                                         flist[nf++] = argv[i];
plunky
1.196
523                                         funsigned_char = 0;
524                                 } else if (strcmp(argv[i],
525                                     "-fno-signed-char") == 0) {
ragge
1.128
526                                         flist[nf++] = argv[i];
plunky
1.204
527                                         funsigned_char = 1;
plunky
1.196
528                                 } else if (strcmp(argv[i],
529                                     "-funsigned-char") == 0) {
ragge
1.128
530                                         flist[nf++] = argv[i];
plunky
1.196
531                                         funsigned_char = 1;
532                                 } else if (strcmp(argv[i],
533                                     "-fno-unsigned-char") == 0) {
ragge
1.128
534                                         flist[nf++] = argv[i];
plunky
1.204
535                                         funsigned_char = 0;
plunky
1.196
536                                 } else if (strcmp(argv[i],
ragge
1.128
537                                     "-fstack-protector") == 0) {
538                                         flist[nf++] = argv[i];
539                                         sspflag++;
540                                 } else if (strcmp(argv[i],
541                                     "-fstack-protector-all") == 0) {
542                                         flist[nf++] = argv[i];
543                                         sspflag++;
544                                 } else if (strcmp(argv[i],
545                                     "-fno-stack-protector") == 0) {
546                                         flist[nf++] = argv[i];
547                                         sspflag = 0;
548                                 } else if (strcmp(argv[i],
549                                     "-fno-stack-protector-all") == 0) {
550                                         flist[nf++] = argv[i];
551                                         sspflag = 0;
552                                 }
553                                 /* silently ignore the rest */
554                                 break;
555
556                         case 'g'/* create debug output */
ragge
1.177
557                                 if (argv[i][2] == '0')
558                                         gflag = 0;
559                                 else
560                                         gflag++;
ragge
1.128
561                                 break;
562
563                         case 'i':
564                                 if (strcmp(argv[i], "-isystem") == 0) {
565                                         *pv++ = "-S";
566                                         *pv++ = argv[++i];
567                                 } else if (strcmp(argv[i], "-include") == 0) {
568                                         *pv++ = "-i";
569                                         *pv++ = argv[++i];
570                                 } else if (strcmp(argv[i], "-idirafter") == 0) {
571                                         idirafter = argv[++i];
gmcgarry
1.172
572 #ifdef os_darwin
573                                 } else if (strcmp(argv[i], "-install_name") == 0) {
574                                         llist[nl++] = argv[i];
575                                         llist[nl++] = argv[++i];
576 #endif
ragge
1.128
577                                 } else
578                                         goto passa;
579                                 break;
580
581                         case 'k'/* generate PIC code */
582                                 kflag = F_pic;
583                                 break;
584
585                         case 'm'/* target-dependent options */
ragge
1.164
586 #ifdef mach_amd64
587                                 /* need to call i386 ccom for this */
588                                 if (strcmp(argv[i], "-m32") == 0) {
589                                         pass0 = LIBEXECDIR "/ccom_i386";
590                                         amd64_i386 = 1;
591                                         break;
592                                 }
593 #endif
ragge
1.128
594                                 mlist[nm++] = argv[i];
ragge
1.169
595                                 if (argv[i][2] == 0) {
596                                         /* separate second arg */
597                                         /* give also to linker */
598                                         llist[nl++] = argv[i++];
599                                         mlist[nm++] = argv[i];
600                                         llist[nl++] = argv[i];
601                                 }
ragge
1.128
602                                 break;
603
604                         case 'n'/* handle -n flags */
605                                 if (strcmp(argv[i], "-nostdinc") == 0)
606                                         nostdinc++;
607                                 else if (strcmp(argv[i], "-nostdlib") == 0) {
608                                         nostdlib++;
609                                         nostartfiles++;
610                                 } else if (strcmp(argv[i], "-nostartfiles") == 0)
611                                         nostartfiles = 1;
plunky
1.202
612                                 else if (strcmp(argv[i], "-nodefaultlibs") == 0)
613                                         nostdlib++;
ragge
1.128
614                                 else
615                                         goto passa;
616                                 break;
617
618                         case 'p':
619                                 if (strcmp(argv[i], "-pg") == 0 ||
620                                     strcmp(argv[i], "-p") == 0)
621                                         pgflag++;
622                                 else if (strcmp(argv[i], "-pthread") == 0)
623                                         pthreads++;
624                                 else if (strcmp(argv[i], "-pipe") == 0)
625                                         /* NOTHING YET */;
gmcgarry
1.144
626                                 else if (strcmp(argv[i], "-pedantic") == 0)
627                                         /* NOTHING YET */;
ragge
1.162
628                                 else if (strcmp(argv[i],
629                                     "-print-prog-name=ld") == 0) {
630                                         printf("%s\n"LINKER);
631                                         return 0;
ragge
1.174
632                                 } else if (strcmp(argv[i],
633                                     "-print-multi-os-directory") == 0) {
634                                         printf("%s\n"MULTIOSDIR);
635                                         return 0;
ragge
1.162
636                                 } else
ragge
1.128
637                                         errorx(1"unknown option %s"argv[i]);
638                                 break;
639
gmcgarry
1.145
640                         case 'r':
641                                 rflag = 1;
642                                 break;
643
ragge
1.128
644                         case 'x':
645                                 t = &argv[i][2];
646                                 if (*t == 0)
647                                         t = argv[++i];
648                                 if (strcmp(t"c") == 0)
649                                         xcflag = 1/* default */
650                                 else if (strcmp(t"assembler-with-cpp") == 0)
651                                         ascpp = 1;
652                                 else if (strcmp(t"c++") == 0)
653                                         cxxflag++;
654                                 else
655                                         xlist[xnum++] = argv[i];
656                                 break;
657                         case 't':
658                                 tflag++;
659                                 break;
660                         case 'S':
661                                 sflag++;
662                                 cflag++;
663                                 break;
664                         case 'o':
665                                 if (outfile)
666                                         errorx(8"too many -o");
667                                 outfile = argv[++i];
668                                 break;
669                         case 'O':
plunky
1.203
670                                 if (argv[i][2] == '\0')
671                                         Oflag++;
672                                 else if (argv[i][3] == '\0' && isdigit((unsigned char)argv[i][2]))
673                                         Oflag = argv[i][2] - '0';
ragge
1.128
674                                 else
plunky
1.203
675                                         error("unknown option %s"argv[i]);
ragge
1.128
676                                 break;
677                         case 'E':
678                                 Eflag++;
679                                 break;
680                         case 'P':
681                                 pflag++;
682                                 *pv++ = argv[i];
683                         case 'c':
gmcgarry
1.172
684 #ifdef os_darwin
685                                 if (strcmp(argv[i], "-compatibility_version") == 0) {
686                                         llist[nl++] = argv[i];
687                                         llist[nl++] = argv[++i];
688                                 } else if (strcmp(argv[i], "-current_version") == 0) {
689                                         llist[nl++] = argv[i];
690                                         llist[nl++] = argv[++i];
691                                 } else
692 #endif
693                                         cflag++;
ragge
1.128
694                                 break;
695 #if 0
696                         case '2':
697                                 if(argv[i][2] == '\0')
698                                         pref = "/lib/crt2.o";
699                                 else {
700                                         pref = "/lib/crt20.o";
701                                 }
702                                 break;
703 #endif
704                         case 'C':
gmcgarry
1.163
705                                 cpplist[ncpp++] = argv[i];
ragge
1.128
706                                 break;
707                         case 'D':
708                         case 'I':
709                         case 'U':
710                                 *pv++ = argv[i];
711                                 if (argv[i][2] == 0)
712                                         *pv++ = argv[++i];
713                                 if (pv >= ptemp+MAXOPT) {
714                                         error("Too many DIU options");
715                                         --pv;
716                                 }
717                                 break;
718
719                         case 'M':
720                                 Mflag++;
721                                 break;
722
723                         case 'd':
gmcgarry
1.144
724 #ifdef os_darwin
725                                 if (strcmp(argv[i], "-dynamiclib") == 0) {
726                                         shared = 1;
727                                 } else
728 #endif
ragge
1.128
729                                 break;
730                         case 'v':
731                                 printf("%s\n"VERSSTR);
732                                 vflag++;
733                                 break;
734
735                         case 's':
gmcgarry
1.144
736 #ifndef os_darwin
737                                 if (strcmp(argv[i], "-shared") == 0) {
ragge
1.128
738                                         shared = 1;
gmcgarry
1.144
739                                 } else
740 #endif
741                                 if (strcmp(argv[i], "-static") == 0) {
742                                         Bstatic = 1;
plunky
1.189
743                                 } else if (strcmp(argv[i], "-symbolic") == 0) {
744                                         llist[nl++] = "-Bsymbolic";
ragge
1.128
745                                 } else if (strncmp(argv[i], "-std"4) == 0) {
ragge
1.190
746                                         if (strcmp(&argv[i][5], "gnu99") == 0 ||
ragge
1.198
747                                             strcmp(&argv[i][5], "gnu9x") == 0)
748                                                 xgnu99 = 1;
749                                         if (strcmp(&argv[i][5], "gnu89") == 0)
750                                                 xgnu89 = 1;
ragge
1.128
751                                 } else
752                                         goto passa;
753                                 break;
754                         }
755                 } else {
756                 passa:
757                         t = argv[i];
758                         if (*argv[i] == '-' && argv[i][1] == 'L')
759                                 ;
ragge
1.198
760                         else if ((cxxsuf(getsufp(t)) && cxxflag) ||
761                             (c=getsuf(t))=='c' || c=='S' || c=='i' ||
ragge
1.128
762                             c=='s'|| Eflag || xcflag) {
763                                 clist[nc++] = t;
764                                 if (nc>=MAXFIL) {
765                                         error("Too many source files");
766                                         exit(1);
767                                 }
768                         }
769
770                         /* Check for duplicate .o files. */
771                         for (j = getsuf(t) == 'o' ? 0 : nlj < nlj++) {
772                                 if (strcmp(llist[j], t) == 0)
773                                         break;
774                         }
gmcgarry
1.150
775                         if ((c=getsuf(t))!='c' && c!='S' &&
776                             c!='s' && c!='i' && j==nl) {
ragge
1.128
777                                 llist[nl++] = t;
778                                 if (nl >= MAXLIB) {
779                                         error("Too many object/library files");
780                                         exit(1);
781                                 }
782                                 if (getsuf(t)=='o')
783                                         nxo++;
784                         }
785                 }
786         }
787         /* Sanity checking */
788         if (nc == 0 && nl == 0)
789                 errorx(8"no input files");
790         if (outfile && (cflag || sflag || Eflag) && nc > 1)
791                 errorx(8"-o given with -c || -E || -S and more than one file");
792         if (outfile && clist[0] && strcmp(outfileclist[0]) == 0)
793                 errorx(8"output file will be clobbered");
gmcgarry
1.150
794         if (nc==0)
ragge
1.128
795                 goto nocom;
796         if (pflag==0) {
797                 if (!sflag)
798                         tmp3 = gettmp();
799                 tmp4 = gettmp();
800         }
801         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
802                 signal(SIGINTidexit);
803         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
804                 signal(SIGTERMidexit);
805 #ifdef MULTITARGET
plunky
1.186
806         pass0 = cat(LIBEXECDIR "/ccom_"mach);
ragge
1.128
807 #endif
808         pvt = pv;
809         for (i=0i<nci++) {
810                 /*
811                  * C preprocessor
812                  */
813                 if (nc>1 && !Eflag)
814                         printf("%s:\n"clist[i]);
815                 onlyas = 0;
816                 assource = tmp3;
817                 if (getsuf(clist[i])=='S')
818                         ascpp = 1;
819                 if (getsuf(clist[i])=='i') {
820                         if(Eflag)
821                                 continue;
822                         goto com;
823                 } else if (ascpp) {
824                         onlyas = 1;
825                 } else if (getsuf(clist[i])=='s') {
826                         assource = clist[i];
827                         goto assemble;
828                 }
829                 if (pflag)
830                         tmp4 = setsuf(clist[i], 'i');
831                 na = 0;
832                 av[na++] = "cpp";
833                 if (vflag)
834                         av[na++] = "-v";
835                 av[na++] = "-D__PCC__=" MKS(PCC_MAJOR);
836                 av[na++] = "-D__PCC_MINOR__=" MKS(PCC_MINOR);
837                 av[na++] = "-D__PCC_MINORMINOR__=" MKS(PCC_MINORMINOR);
gmcgarry
1.156
838 #ifndef os_win32
ragge
1.155
839 #ifdef GCC_COMPAT
840                 av[na++] = "-D__GNUC__=4";
841                 av[na++] = "-D__GNUC_MINOR__=3";
842                 av[na++] = "-D__GNUC_PATCHLEVEL__=1";
ragge
1.198
843                 if (xgnu89)
ragge
1.191
844                         av[na++] = "-D__GNUC_GNU_INLINE__=1";
845                 else
846                         av[na++] = "-D__GNUC_STDC_INLINE__=1";
ragge
1.170
847 #endif
848 #endif
ragge
1.166
849                 av[na++] = "-D__VERSION__=" MKS(VERSSTR);
ragge
1.167
850                 av[na++] = "-D__SCHAR_MAX__=" MKS(MAX_CHAR);
851                 av[na++] = "-D__SHRT_MAX__=" MKS(MAX_SHORT);
852                 av[na++] = "-D__INT_MAX__=" MKS(MAX_INT);
853                 av[na++] = "-D__LONG_MAX__=" MKS(MAX_LONG);
854                 av[na++] = "-D__LONG_LONG_MAX__=" MKS(MAX_LONGLONG);
plunky
1.196
855                 if (funsigned_char)
856                         av[na++] = "-D__CHAR_UNSIGNED__";
ragge
1.128
857                 if (ascpp)
858                         av[na++] = "-D__ASSEMBLER__";
859                 if (sspflag)
860                         av[na++] = "-D__SSP__=1";
861                 if (pthreads)
862                         av[na++] = "-D_PTHREADS";
863                 if (Mflag)
864                         av[na++] = "-M";
ragge
1.160
865                 if (Oflag)
866                         av[na++] = "-D__OPTIMIZE__";
867 #ifdef GCC_COMPAT
868                 av[na++] = "-D__REGISTER_PREFIX__=" REGISTER_PREFIX;
869                 av[na++] = "-D__USER_LABEL_PREFIX__=" USER_LABEL_PREFIX;
870 #endif
ragge
1.128
871                 for (j = 0cppadd[j]; j++)
872                         av[na++] = cppadd[j];
gmcgarry
1.163
873                 for (j = 0j < ncppj++)
874                         av[na++] = cpplist[j];
gmcgarry
1.149
875                 av[na++] = "-D__STDC_ISO_10646__=200009L";
ragge
1.157
876                 av[na++] = "-D__WCHAR_TYPE__=" WCT;
877                 av[na++] = "-D__SIZEOF_WCHAR_T__=" MKS(WCHAR_SIZE);
878                 av[na++] = "-D__WCHAR_MAX__=" WCM;
plunky
1.192
879                 av[na++] = "-D__WINT_TYPE__=" PCC_WINT_TYPE;
880                 av[na++] = "-D__SIZE_TYPE__=" PCC_SIZE_TYPE;
ragge
1.161
881                 av[na++] = "-D__PTRDIFF_TYPE__=" PCC_PTRDIFF_TYPE;
gmcgarry
1.142
882                 av[na++] = "-D__SIZEOF_WINT_T__=4";
plunky
1.201
883 #if defined(os_darwin) || defined(os_netbsd)
884                 av[na++] = "-D__FLT_RADIX__=2";
885                 av[na++] = "-D__FLT_DIG__=6";
886                 av[na++] = "-D__FLT_EPSILON__=1.19209290e-07F";
887                 av[na++] = "-D__FLT_MANT_DIG__=24";
888                 av[na++] = "-D__FLT_MAX_10_EXP__=38";
889                 av[na++] = "-D__FLT_MAX_EXP__=128";
890                 av[na++] = "-D__FLT_MAX__=3.40282347e+38F";
891                 av[na++] = "-D__FLT_MIN_10_EXP__=(-37)";
892                 av[na++] = "-D__FLT_MIN_EXP__=(-125)";
gmcgarry
1.171
893                 av[na++] = "-D__FLT_MIN__=1.17549435e-38F";
plunky
1.201
894                 av[na++] = "-D__DBL_DIG__=15";
895                 av[na++] = "-D__DBL_EPSILON__=2.2204460492503131e-16";
896                 av[na++] = "-D__DBL_MANT_DIG__=53";
897                 av[na++] = "-D__DBL_MAX_10_EXP__=308";
898                 av[na++] = "-D__DBL_MAX_EXP__=1024";
899                 av[na++] = "-D__DBL_MAX__=1.7976931348623157e+308";
900                 av[na++] = "-D__DBL_MIN_10_EXP__=(-307)";
901                 av[na++] = "-D__DBL_MIN_EXP__=(-1021)";
gmcgarry
1.171
902                 av[na++] = "-D__DBL_MIN__=2.2250738585072014e-308";
plunky
1.201
903 #if defined(mach_i386) || defined(mach_amd64)
904                 av[na++] = "-D__LDBL_DIG__=18";
905                 av[na++] = "-D__LDBL_EPSILON__=1.08420217248550443401e-19L";
906                 av[na++] = "-D__LDBL_MANT_DIG__=64";
907                 av[na++] = "-D__LDBL_MAX_10_EXP__=4932";
908                 av[na++] = "-D__LDBL_MAX_EXP__=16384";
909                 av[na++] = "-D__LDBL_MAX__=1.18973149535723176502e+4932L";
910                 av[na++] = "-D__LDBL_MIN_10_EXP__=(-4931)";
911                 av[na++] = "-D__LDBL_MIN_EXP__=(-16381)";
gmcgarry
1.171
912                 av[na++] = "-D__LDBL_MIN__=3.36210314311209350626e-4932L";
plunky
1.201
913 #else
914                 av[na++] = "-D__LDBL_DIG__=15";
915                 av[na++] = "-D__LDBL_EPSILON__=2.2204460492503131e-16";
916                 av[na++] = "-D__LDBL_MANT_DIG__=53";
917                 av[na++] = "-D__LDBL_MAX_10_EXP__=308";
918                 av[na++] = "-D__LDBL_MAX_EXP__=1024";
919                 av[na++] = "-D__LDBL_MAX__=1.7976931348623157e+308";
920                 av[na++] = "-D__LDBL_MIN_10_EXP__=(-307)";
921                 av[na++] = "-D__LDBL_MIN_EXP__=(-1021)";
922                 av[na++] = "-D__LDBL_MIN__=2.2250738585072014e-308";
923 #endif
gmcgarry
1.171
924 #endif
ragge
1.128
925 #ifdef MULTITARGET
926                 for (k = 0cppmds[k].machk++) {
927                         if (strcmp(cppmds[k].machmach) != 0)
928                                 continue;
929                         for (j = 0cppmds[k].cppmdadd[j]; j++)
930                                 av[na++] = cppmds[k].cppmdadd[j];
931                         break;
932                 }
933 #else
934                 for (j = 0cppmdadd[j]; j++)
935                         av[na++] = cppmdadd[j];
936 #endif
937                 if (tflag)
938                         av[na++] = "-t";
939                 for(pv=ptemppv <pvtpv++)
940                         av[na++] = *pv;
gmcgarry
1.153
941                 if (!nostdinc) {
plunky
1.185
942                         av[na++] = "-S"av[na++] = cat(sysrootaltincdir);
943                         av[na++] = "-S"av[na++] = cat(sysrootincdir);
plunky
1.200
944 #ifdef PCCINCDIR
ragge
1.198
945                         if (cxxflag)
946                                 av[na++] = "-S"av[na++] = pxxincdir;
plunky
1.187
947                         av[na++] = "-S"av[na++] = pccincdir;
plunky
1.200
948 #endif
gmcgarry
1.153
949                 }
ragge
1.128
950                 if (idirafter) {
951                         av[na++] = "-I";
952                         av[na++] = idirafter;
953                 }
954                 av[na++] = clist[i];
955                 if (!Eflag && !Mflag)
956                         av[na++] = tmp4;
ragge
1.141
957                 if ((Eflag || Mflag) && outfile)
ragge
1.128
958                          ermfile = av[na++] = outfile;
959                 av[na++]=0;
gmcgarry
1.140
960                 if (callsys(passpav)) {
961                         exfail++;
962                         eflag++;
963                 }
ragge
1.128
964                 if (Eflag || Mflag)
965                         continue;
966                 if (onlyas) {
967                         assource = tmp4;
968                         goto assemble;
969                 }
970
971                 /*
972                  * C compiler
973                  */
974         com:
975                 na = 0;
ragge
1.198
976                 av[na++]= cxxflag ? "c++com" : "ccom";
ragge
1.128
977                 if (Wallflag) {
978                         /* Set only the same flags as gcc */
979                         for (Wf = WflagsWf->nameWf++) {
980                                 if (Wf->flags != INWALL)
981                                         continue;
982                                 av[na++] = Wf->name;
983                         }
984                 }
985                 if (Wflag) {
986                         /* set all positive flags */
987                         for (Wf = WflagsWf->nameWf++) {
988                                 if (Wf->flags == NEGATIVE)
989                                         continue;
990                                 av[na++] = Wf->name;
991                         }
992