Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:plunky:20111111085909

Diff

Diff from 1.214 to:

Annotations

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

Annotated File View

plunky
1.214
1 /*      $Id: cc.c,v 1.214 2011/11/11 08:59:09 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
plunky
1.206
42  * - Files that end with .S are passed via cpp->as->ld
43  * - Files that end with .s are passed via as->ld
ragge
1.128
44  * - Files that end with .o are passed directly to ld
45  * - Multiple files may be given on the command line.
46  * - Unrecognized options are all sent directly to ld.
47  * -c or -S cannot be combined with -o if multiple files are given.
48  *
49  * This file should be rewritten readable.
50  */
51 #include "config.h"
52
53 #include <sys/types.h>
54 #ifdef HAVE_SYS_WAIT_H
55 #include <sys/wait.h>
56 #endif
57
58 #include <ctype.h>
59 #include <errno.h>
60 #include <fcntl.h>
61 #ifdef HAVE_LIBGEN_H
62 #include <libgen.h>
63 #endif
64 #include <signal.h>
65 #include <stdarg.h>
66 #include <stdio.h>
67 #include <stdlib.h>
68 #include <string.h>
69 #ifdef HAVE_UNISTD_H
70 #include <unistd.h>
71 #endif
72
plunky
1.213
73 #ifdef os_win32
ragge
1.128
74 #include <windows.h>
75 #include <process.h>
76 #include <io.h>
gmcgarry
1.179
77 #define F_OK    0x00
78 #define R_OK    0x04
79 #define W_OK    0x02
80 #define X_OK    R_OK
ragge
1.128
81 #endif
82
83 #include "compat.h"
84
85 #include "ccconfig.h"
ragge
1.167
86 #include "macdefs.h"
ragge
1.128
87 /* C command */
88
89 #define MKS(x) _MKS(x)
90 #define _MKS(x) #x
91
92 /*
93  * Many specific definitions, should be declared elsewhere.
94  */
95
96 #ifndef STDINC
97 #define STDINC          "/usr/include/"
98 #endif
99
100 #ifndef LIBDIR
101 #define LIBDIR          "/usr/lib/"
102 #endif
103
104 #ifndef PREPROCESSOR
105 #define PREPROCESSOR    "cpp"
106 #endif
107
108 #ifndef COMPILER
gmcgarry
1.138
109 #define COMPILER        "ccom"
ragge
1.128
110 #endif
111
112 #ifndef ASSEMBLER
113 #define ASSEMBLER       "as"
114 #endif
115
116 #ifndef LINKER
117 #define LINKER          "ld"
118 #endif
119
ragge
1.174
120 #ifndef MULTIOSDIR
121 #define MULTIOSDIR      "."
122 #endif
123
124
ragge
1.128
125 #define MAXFIL 10000
126 #define MAXLIB 10000
127 #define MAXAV  10000
ragge
1.173
128 #define MAXOPT 200
ragge
1.128
129 char    *tmp3;
130 char    *tmp4;
131 char    *outfile, *ermfile;
ragge
1.175
132 static void add_prefix(const char *);
133 static char *find_file(const char *, int);
plunky
1.183
134 char *copy(const char *, int);
plunky
1.185
135 char *cat(const char *, const char *);
gmcgarry
1.150
136 char *setsuf(char *, char);
ragge
1.198
137 int cxxsuf(char *);
ragge
1.128
138 int getsuf(char *);
ragge
1.198
139 char *getsufp(char *s);
ragge
1.128
140 int main(intchar *[]);
141 void error(char *, ...);
142 void errorx(intchar *, ...);
143 int callsys(char [], char *[]);
144 int cunlink(char *);
145 void dexit(int);
146 void idexit(int);
147 char *gettmp(void);
148 void *ccmalloc(int size);
plunky
1.213
149 #ifdef os_win32
ragge
1.128
150 char *win32pathsubst(char *);
gmcgarry
1.149
151 char *win32commandline(char *, char *[]);
ragge
1.128
152 #endif
153 char    *av[MAXAV];
154 char    *clist[MAXFIL];
gmcgarry
1.150
155 char    *olist[MAXFIL];
ragge
1.128
156 char    *llist[MAXLIB];
157 char    *aslist[MAXAV];
gmcgarry
1.163
158 char    *cpplist[MAXAV];
ragge
1.128
159 char    *xlist[100];
160 int     xnum;
161 char    *mlist[100];
162 char    *flist[100];
163 char    *wlist[100];
164 char    *idirafter;
165 int     nm;
166 int     nf;
167 int     nw;
168 int     sspflag;
plunky
1.214
169 int     freestanding;
ragge
1.128
170 int     pflag;
171 int     sflag;
172 int     cflag;
173 int     eflag;
174 int     gflag;
gmcgarry
1.145
175 int     rflag;
ragge
1.128
176 int     vflag;
177 int     tflag;
178 int     Eflag;
179 int     Oflag;
180 int     kflag;  /* generate PIC/pic code */
181 #define F_PIC   1
182 #define F_pic   2
183 int     Mflag;  /* dependencies only */
184 int     pgflag;
185 int     exfail;
186 int     Xflag;
187 int     Wallflag;
188 int     Wflag;
189 int     nostartfilesBstaticshared;
190 int     nostdincnostdlib;
191 int     onlyas;
192 int     pthreads;
ragge
1.198
193 int     xcflagxgnu89xgnu99;
ragge
1.128
194 int     ascpp;
plunky
1.196
195 #ifdef CHAR_UNSIGNED
plunky
1.209
196 int     xuchar = 1;
plunky
1.196
197 #else
plunky
1.209
198 int     xuchar = 0;
plunky
1.196
199 #endif
ragge
1.198
200 int     cxxflag;
ragge
1.128
201
202 char    *passp = LIBEXECDIR PREPROCESSOR;
203 char    *pass0 = LIBEXECDIR COMPILER;
ragge
1.212
204 char    *passxx0 = LIBEXECDIR "cxxcom";
ragge
1.128
205 char    *as = ASSEMBLER;
206 char    *ld = LINKER;
ragge
1.175
207 char    *sysroot;
ragge
1.128
208 char *cppadd[] = CPPADD;
209 #ifdef DYNLINKER
210 char *dynlinker[] = DYNLINKER;
211 #endif
212 #ifdef CRT0FILE
213 char *crt0file = CRT0FILE;
214 #endif
215 #ifdef CRT0FILE_PROFILE
216 char *crt0file_profile = CRT0FILE_PROFILE;
217 #endif
218 #ifdef STARTFILES
219 char *startfiles[] = STARTFILES;
220 char *endfiles[] = ENDFILES;
221 #endif
222 #ifdef STARTFILES_T
223 char *startfiles_T[] = STARTFILES_T;
224 char *endfiles_T[] = ENDFILES_T;
225 #endif
226 #ifdef STARTFILES_S
227 char *startfiles_S[] = STARTFILES_S;
228 char *endfiles_S[] = ENDFILES_S;
229 #endif
230 #ifdef MULTITARGET
231 char *mach = DEFMACH;
232 struct cppmd {
233         char *mach;
234         char *cppmdadd[MAXCPPMDARGS];
235 };
236
237 struct cppmd cppmds[] = CPPMDADDS;
238 #else
239 char *cppmdadd[] = CPPMDADD;
240 #endif
241 #ifdef LIBCLIBS
242 char *libclibs[] = LIBCLIBS;
243 #else
244 char *libclibs[] = { "-lc"NULL };
245 #endif
246 #ifdef LIBCLIBS_PROFILE
247 char *libclibs_profile[] = LIBCLIBS_PROFILE;
248 #else
249 char *libclibs_profile[] = { "-lc_p"NULL };
250 #endif
251 #ifndef STARTLABEL
252 #define STARTLABEL "__start"
253 #endif
254 char *incdir = STDINC;
gmcgarry
1.153
255 char *altincdir = INCLUDEDIR "pcc/";
gmcgarry
1.136
256 char *libdir = LIBDIR;
plunky
1.200
257 #ifdef PCCINCDIR
ragge
1.128
258 char *pccincdir = PCCINCDIR;
ragge
1.198
259 char *pxxincdir = PCCINCDIR "/c++";
plunky
1.200
260 #endif
261 #ifdef PCCLIBDIR
ragge
1.128
262 char *pcclibdir = PCCLIBDIR;
plunky
1.200
263 #endif
ragge
1.164
264 #ifdef mach_amd64
265 int amd64_i386;
266 #endif
ragge
1.128
267
268 /* handle gcc warning emulations */
269 struct Wflags {
270         char *name;
271         int flags;
272 #define INWALL          1
273 #define NEGATIVE        2
274 Wflags[] = {
gmcgarry
1.154
275         { "-Wtruncate"0 },
276         { "-Wno-truncate"NEGATIVE },
plunky
1.194
277         { "-Wstrict-prototypes"0 },
278         { "-Wno-strict-prototypes"NEGATIVE },
279         { "-Wmissing-prototypes"0 },
280         { "-Wno-missing-prototypes"NEGATIVE },
plunky
1.210
281         { "-Wimplicit-int"INWALL },
plunky
1.194
282         { "-Wno-implicit-int"NEGATIVE },
plunky
1.210
283         { "-Wimplicit-function-declaration"INWALL },
plunky
1.194
284         { "-Wno-implicit-function-declaration"NEGATIVE },
ragge
1.128
285         { "-Wshadow"0 },
286         { "-Wno-shadow"NEGATIVE },
287         { "-Wpointer-sign"INWALL },
288         { "-Wno-pointer-sign"NEGATIVE },
289         { "-Wsign-compare"0 },
290         { "-Wno-sign-compare"NEGATIVE },
291         { "-Wunknown-pragmas"INWALL },
292         { "-Wno-unknown-pragmas"NEGATIVE },
293         { "-Wunreachable-code"0 },
294         { "-Wno-unreachable-code"NEGATIVE },
295         { 00 },
296 };
297
298 #define SZWFL   (sizeof(Wflags)/sizeof(Wflags[0]))
299
ragge
1.158
300 #ifndef USHORT
301 /* copied from mip/manifest.h */
302 #define USHORT          5
303 #define INT             6
304 #define UNSIGNED        7
305 #endif
306
ragge
1.157
307 /*
308  * Wide char defines.
309  */
310 #if WCHAR_TYPE == USHORT
311 #define WCT "short unsigned int"
312 #define WCM "65535U"
ragge
1.158
313 #if WCHAR_SIZE != 2
314 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
315 #endif
ragge
1.157
316 #elif WCHAR_TYPE == INT
317 #define WCT "int"
318 #define WCM "2147483647"
ragge
1.158
319 #if WCHAR_SIZE != 4
320 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
321 #endif
ragge
1.157
322 #elif WCHAR_TYPE == UNSIGNED
323 #define WCT "unsigned int"
ragge
1.158
324 #define WCM "4294967295U"
325 #if WCHAR_SIZE != 4
326 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
327 #endif
328 #else
329 #error WCHAR_TYPE not defined or invalid
ragge
1.157
330 #endif
331
ragge
1.160
332 #ifdef GCC_COMPAT
333 #ifndef REGISTER_PREFIX
334 #define REGISTER_PREFIX ""
335 #endif
336 #ifndef USER_LABEL_PREFIX
337 #define USER_LABEL_PREFIX ""
338 #endif
339 #endif
340
plunky
1.192
341 #ifndef PCC_WINT_TYPE
342 #define PCC_WINT_TYPE "unsigned int"
343 #endif
344
345 #ifndef PCC_SIZE_TYPE
346 #define PCC_SIZE_TYPE "unsigned long"
347 #endif
348
ragge
1.161
349 #ifndef PCC_PTRDIFF_TYPE
350 #define PCC_PTRDIFF_TYPE "long int"
351 #endif
352
ragge
1.128
353 int
354 main(int argcchar *argv[])
355 {
356         struct Wflags *Wf;
357         char *t, *u;
358         char *assource;
359         char **pv, *ptemp[MAXOPT], **pvt;
gmcgarry
1.163
360         int ncnlnasncppijcnxona;
ragge
1.128
361 #ifdef MULTITARGET
362         int k;
363 #endif
364
ragge
1.198
365         if (strcmp(argv[0], "p++") == 0) {
366                 cxxflag = 1;
367                 pass0 = passxx0;
368         }
369
plunky
1.213
370 #ifdef os_win32
ragge
1.128
371         /* have to prefix path early.  -B may override */
372         incdir = win32pathsubst(incdir);
gmcgarry
1.153
373         altincdir = win32pathsubst(altincdir);
gmcgarry
1.136
374         libdir = win32pathsubst(libdir);
plunky
1.200
375 #ifdef PCCINCDIR
ragge
1.128
376         pccincdir = win32pathsubst(pccincdir);
plunky
1.199
377         pxxincdir = win32pathsubst(pxxincdir);
plunky
1.200
378 #endif
379 #ifdef PCCLIBDIR
ragge
1.128
380         pcclibdir = win32pathsubst(pcclibdir);
plunky
1.200
381 #endif
ragge
1.128
382         passp = win32pathsubst(passp);
383         pass0 = win32pathsubst(pass0);
gmcgarry
1.180
384 #ifdef STARTFILES
385         for (i = 0startfiles[i] != NULLi++)
386                 startfiles[i] = win32pathsubst(startfiles[i]);
387         for (i = 0endfiles[i] != NULLi++)
388                 endfiles[i] = win32pathsubst(endfiles[i]);
389 #endif
390 #ifdef STARTFILES_T
391         for (i = 0startfiles_T[i] != NULLi++)
392                 startfiles_T[i] = win32pathsubst(startfiles_T[i]);
393         for (i = 0endfiles_T[i] != NULLi++)
394                 endfiles_T[i] = win32pathsubst(endfiles_T[i]);
395 #endif
396 #ifdef STARTFILES_S
397         for (i = 0startfiles_S[i] != NULLi++)
398                 startfiles_S[i] = win32pathsubst(startfiles_S[i]);
399         for (i = 0endfiles_S[i] != NULLi++)
400                 endfiles_S[i] = win32pathsubst(endfiles_S[i]);
401 #endif
ragge
1.128
402 #endif
403
gmcgarry
1.163
404         i = nc = nl = nas = ncpp = nxo = 0;
ragge
1.128
405         pv = ptemp;
406         while(++i < argc) {
407                 if (argv[i][0] == '-') {
408                         switch (argv[i][1]) {
409                         default:
410                                 goto passa;
411 #ifdef notyet
412         /* must add library options first (-L/-l/...) */
413                                 error("unrecognized option `-%c'"argv[i][1]);
414                                 break;
415 #endif
416
417                         case '-'/* double -'s */
ragge
1.130
418                                 if (strcmp(argv[i], "--version") == 0) {
ragge
1.128
419                                         printf("%s\n"VERSSTR);
ragge
1.130
420                                         return 0;
ragge
1.175
421                                 } else if (strncmp(argv[i], "--sysroot="10) == 0) {
422                                         sysroot = argv[i] + 10;
ragge
1.169
423                                 } else if (strcmp(argv[i], "--param") == 0) {
ragge
1.128
424                                         /* NOTHING YET */;
ragge
1.169
425                                         i++; /* ignore arg */
426                                 } else
gmcgarry
1.148
427                                         goto passa;
ragge
1.128
428                                 break;
429
430                         case 'B'/* other search paths for binaries */
ragge
1.175
431                                 add_prefix(argv[i] + 2);
ragge
1.128
432                                 break;
433
434 #ifdef MULTITARGET
435                         case 'b':
436                                 t = &argv[i][2];
437                                 if (*t == '\0' && i + 1 < argc) {
438                                         t = argv[i+1];
439                                         i++;
440                                 }
441                                 if (strncmp(t"?"1) == 0) {
442                                         /* show machine targets */
443                                         printf("Available machine targets:");
444                                         for (j=0cppmds[j].machj++)
445                                                 printf(" %s",cppmds[j].mach);
446                                         printf("\n");
447                                         exit(0);
448                                 }
449                                 for (j=0cppmds[j].machj++)
450                                         if (strcmp(tcppmds[j].mach) == 0) {
451                                                 mach = cppmds[j].mach;
452                                                 break;
453                                         }
454                                 if (cppmds[j].mach == NULL)
455                                         errorx(1"unknown target arch %s"t);
456                                 break;
457 #endif
458
459                         case 'X':
460                                 Xflag++;
461                                 break;
462                         case 'W'/* Ignore (most of) W-flags */
463                                 if (strncmp(argv[i], "-Wl,"4) == 0) {
464                                         /* options to the linker */
465                                         t = &argv[i][4];
466                                         while ((u = strchr(t','))) {
467                                                 *u++ = 0;
468                                                 llist[nl++] = t;
469                                                 t = u;
470                                         }
471                                         llist[nl++] = t;
472                                 } else if (strncmp(argv[i], "-Wa,"4) == 0) {
473                                         /* options to the assembler */
474                                         t = &argv[i][4];
475                                         while ((u = strchr(t','))) {
476                                                 *u++ = 0;
477                                                 aslist[nas++] = t;
478                                                 t = u;
479                                         }
480                                         aslist[nas++] = t;
ragge
1.137
481                                 } else if (strncmp(argv[i], "-Wc,"4) == 0) {
482                                         /* options to ccom */
483                                         t = &argv[i][4];
484                                         while ((u = strchr(t','))) {
485                                                 *u++ = 0;
486                                                 wlist[nw++] = t;
487                                                 t = u;
488                                         }
489                                         wlist[nw++] = t;
ragge
1.128
490                                 } else if (strncmp(argv[i], "-Wp,"4) == 0) {
491                                         /* preprocessor */
gmcgarry
1.163
492                                         t = &argv[i][4];
493                                         while ((u = strchr(t','))) {
494                                                 *u++ = 0;
495                                                 cpplist[ncpp++] = t;
496                                                 t = u;
497                                         }
498                                         cpplist[ncpp++] = t;
plunky
1.193
499                                 } else if (strcmp(argv[i], "-Werror") == 0) {
500                                         wlist[nw++] = argv[i];
ragge
1.128
501                                 } else if (strcmp(argv[i], "-Wall") == 0) {
502                                         Wallflag = 1;
503                                 } else if (strcmp(argv[i], "-WW") == 0) {
504                                         Wflag = 1;
505                                 } else {
506                                         /* check and set if available */
507                                         for (Wf = WflagsWf->nameWf++) {
508                                                 if (strcmp(argv[i], Wf->name))
509                                                         continue;
510                                                 wlist[nw++] = Wf->name;
511                                         }
512                                 }
513                                 break;
514
515                         case 'f'/* GCC compatibility flags */
516                                 if (strcmp(argv[i], "-fPIC") == 0)
517                                         kflag = F_PIC;
518                                 else if (strcmp(argv[i], "-fpic") == 0)
519                                         kflag = F_pic;
ragge
1.195
520                                 else if (strcmp(argv[i], "-ffreestanding") == 0)
plunky
1.214
521                                         freestanding = 1;
ragge
1.128
522                                 else if (strcmp(argv[i],
plunky
1.209
523                                     "-fsigned-char") == 0)
524                                         xuchar = 0;
525                                 else if (strcmp(argv[i],
526                                     "-fno-signed-char") == 0)
527                                         xuchar = 1;
528                                 else if (strcmp(argv[i],
529                                     "-funsigned-char") == 0)
530                                         xuchar = 1;
531                                 else if (strcmp(argv[i],
532                                     "-fno-unsigned-char") == 0)
533                                         xuchar = 0;
534                                 else if (strcmp(argv[i],
ragge
1.128
535                                     "-fstack-protector") == 0) {
536                                         flist[nf++] = argv[i];
537                                         sspflag++;
538                                 } else if (strcmp(argv[i],
539                                     "-fstack-protector-all") == 0) {
540                                         flist[nf++] = argv[i];
541                                         sspflag++;
542                                 } else if (strcmp(argv[i],
543                                     "-fno-stack-protector") == 0) {
544                                         flist[nf++] = argv[i];
545                                         sspflag = 0;
546                                 } else if (strcmp(argv[i],
547                                     "-fno-stack-protector-all") == 0) {
548                                         flist[nf++] = argv[i];
549                                         sspflag = 0;
550                                 }
551                                 /* silently ignore the rest */
552                                 break;
553
554                         case 'g'/* create debug output */
ragge
1.177
555                                 if (argv[i][2] == '0')
556                                         gflag = 0;
557                                 else
558                                         gflag++;
ragge
1.128
559                                 break;
560
561                         case 'i':
562                                 if (strcmp(argv[i], "-isystem") == 0) {
563                                         *pv++ = "-S";
564                                         *pv++ = argv[++i];
565                                 } else if (strcmp(argv[i], "-include") == 0) {
566                                         *pv++ = "-i";
567                                         *pv++ = argv[++i];
568                                 } else if (strcmp(argv[i], "-idirafter") == 0) {
569                                         idirafter = argv[++i];
gmcgarry
1.172
570 #ifdef os_darwin
571                                 } else if (strcmp(argv[i], "-install_name") == 0) {
572                                         llist[nl++] = argv[i];
573                                         llist[nl++] = argv[++i];
574 #endif
ragge
1.128
575                                 } else
576                                         goto passa;
577                                 break;
578
579                         case 'k'/* generate PIC code */
580                                 kflag = F_pic;
581                                 break;
582
583                         case 'm'/* target-dependent options */
ragge
1.164
584 #ifdef mach_amd64
585                                 /* need to call i386 ccom for this */
586                                 if (strcmp(argv[i], "-m32") == 0) {
587                                         pass0 = LIBEXECDIR "/ccom_i386";
588                                         amd64_i386 = 1;
589                                         break;
590                                 }
591 #endif
ragge
1.128
592                                 mlist[nm++] = argv[i];
ragge
1.169
593                                 if (argv[i][2] == 0) {
594                                         /* separate second arg */
595                                         /* give also to linker */
596                                         llist[nl++] = argv[i++];
597                                         mlist[nm++] = argv[i];
598                                         llist[nl++] = argv[i];
599                                 }
ragge
1.128
600                                 break;
601
602                         case 'n'/* handle -n flags */
603                                 if (strcmp(argv[i], "-nostdinc") == 0)
604                                         nostdinc++;
605                                 else if (strcmp(argv[i], "-nostdlib") == 0) {
606                                         nostdlib++;
607                                         nostartfiles++;
608                                 } else if (strcmp(argv[i], "-nostartfiles") == 0)
609                                         nostartfiles = 1;
plunky
1.202
610                                 else if (strcmp(argv[i], "-nodefaultlibs") == 0)
611                                         nostdlib++;
ragge
1.128
612                                 else
613                                         goto passa;
614                                 break;
615
616                         case 'p':
617                                 if (strcmp(argv[i], "-pg") == 0 ||
618                                     strcmp(argv[i], "-p") == 0)
619                                         pgflag++;
620                                 else if (strcmp(argv[i], "-pthread") == 0)
621                                         pthreads++;
622                                 else if (strcmp(argv[i], "-pipe") == 0)
623                                         /* NOTHING YET */;
gmcgarry
1.144
624                                 else if (strcmp(argv[i], "-pedantic") == 0)
625                                         /* NOTHING YET */;
ragge
1.162
626                                 else if (strcmp(argv[i],
627                                     "-print-prog-name=ld") == 0) {
628                                         printf("%s\n"LINKER);
629                                         return 0;
ragge
1.174
630                                 } else if (strcmp(argv[i],
631                                     "-print-multi-os-directory") == 0) {
632                                         printf("%s\n"MULTIOSDIR);
633                                         return 0;
ragge
1.162
634                                 } else
ragge
1.128
635                                         errorx(1"unknown option %s"argv[i]);
636                                 break;
637
gmcgarry
1.145
638                         case 'r':
639                                 rflag = 1;
640                                 break;
641
ragge
1.128
642                         case 'x':
643                                 t = &argv[i][2];
644                                 if (*t == 0)
645                                         t = argv[++i];
646                                 if (strcmp(t"c") == 0)
647                                         xcflag = 1/* default */
648                                 else if (strcmp(t"assembler-with-cpp") == 0)
649                                         ascpp = 1;
650                                 else if (strcmp(t"c++") == 0)
651                                         cxxflag++;
652                                 else
653                                         xlist[xnum++] = argv[i];
654                                 break;
655                         case 't':
656                                 tflag++;
657                                 break;
658                         case 'S':
659                                 sflag++;
660                                 cflag++;
661                                 break;
662                         case 'o':
663                                 if (outfile)
664                                         errorx(8"too many -o");
665                                 outfile = argv[++i];
666                                 break;
667                         case 'O':
plunky
1.203
668                                 if (argv[i][2] == '\0')
669                                         Oflag++;
670                                 else if (argv[i][3] == '\0' && isdigit((unsigned char)argv[i][2]))
671                                         Oflag = argv[i][2] - '0';
plunky
1.211
672                                 else if (argv[i][3] == '\0' && argv[i][2] == 's')
673                                         Oflag = 1;      /* optimize for space only */
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];
plunky
1.207
711                                 if (argv[i][2] == '\0')
ragge
1.128
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' &&
ragge
1.212
776                             c!='s' && c!='i' && j==nl &&
777                             !(cxxsuf(getsufp(t)) && cxxflag)) {
ragge
1.128
778                                 llist[nl++] = t;
779                                 if (nl >= MAXLIB) {
780                                         error("Too many object/library files");
781                                         exit(1);
782                                 }
783                                 if (getsuf(t)=='o')
784                                         nxo++;
785                         }
786                 }
787         }
788         /* Sanity checking */
789         if (nc == 0 && nl == 0)
790                 errorx(8"no input files");
791         if (outfile && (cflag || sflag || Eflag) && nc > 1)
792                 errorx(8"-o given with -c || -E || -S and more than one file");
793         if (outfile && clist[0] && strcmp(outfileclist[0]) == 0)
794                 errorx(8"output file will be clobbered");
gmcgarry
1.150
795         if (nc==0)
ragge
1.128
796                 goto nocom;
797         if (pflag==0) {
798                 if (!sflag)
799                         tmp3 = gettmp();
800                 tmp4 = gettmp();
801         }
802         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
803                 signal(SIGINTidexit);
804         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
805                 signal(SIGTERMidexit);
806 #ifdef MULTITARGET
plunky
1.186
807         pass0 = cat(LIBEXECDIR "/ccom_"mach);
ragge
1.128
808 #endif
809         pvt = pv;
810         for (i=0i<nci++) {
811                 /*
812                  * C preprocessor
813                  */
814                 if (nc>1 && !Eflag)
815                         printf("%s:\n"clist[i]);
816                 onlyas = 0;
817                 assource = tmp3;
818                 if (getsuf(clist[i])=='S')
819                         ascpp = 1;
820                 if (getsuf(clist[i])=='i') {
821                         if(Eflag)
822                                 continue;
823                         goto com;
824                 } else if (ascpp) {
825                         onlyas = 1;
826                 } else if (getsuf(clist[i])=='s') {
827                         assource = clist[i];
828                         goto assemble;
829                 }
830                 if (pflag)
831                         tmp4 = setsuf(clist[i], 'i');
832                 na = 0;
833                 av[na++] = "cpp";
834                 if (vflag)
835                         av[na++] = "-v";
836                 av[na++] = "-D__PCC__=" MKS(PCC_MAJOR);
837                 av[na++] = "-D__PCC_MINOR__=" MKS(PCC_MINOR);
838                 av[na++] = "-D__PCC_MINORMINOR__=" MKS(PCC_MINORMINOR);
gmcgarry
1.156
839 #ifndef os_win32
ragge
1.155
840 #ifdef GCC_COMPAT
841                 av[na++] = "-D__GNUC__=4";
842                 av[na++] = "-D__GNUC_MINOR__=3";
843                 av[na++] = "-D__GNUC_PATCHLEVEL__=1";
ragge
1.198
844                 if (xgnu89)
plunky
1.208
845                         av[na++] = "-D__GNUC_GNU_INLINE__";
ragge
1.191
846                 else
plunky
1.208
847                         av[na++] = "-D__GNUC_STDC_INLINE__";
ragge
1.170
848 #endif
849 #endif
ragge
1.166
850                 av[na++] = "-D__VERSION__=" MKS(VERSSTR);
ragge
1.167
851                 av[na++] = "-D__SCHAR_MAX__=" MKS(MAX_CHAR);
852                 av[na++] = "-D__SHRT_MAX__=" MKS(MAX_SHORT);
853                 av[na++] = "-D__INT_MAX__=" MKS(MAX_INT);
854                 av[na++] = "-D__LONG_MAX__=" MKS(MAX_LONG);
855                 av[na++] = "-D__LONG_LONG_MAX__=" MKS(MAX_LONGLONG);
plunky
1.214
856                 if (freestanding)
857                         av[na++] = "-D__STDC_HOSTED__=0";
858                 else
859                         av[na++] = "-D__STDC_HOSTED__=1";
ragge
1.212
860                 if (cxxflag)
861                         av[na++] = "-D__cplusplus";
plunky
1.209
862                 if (xuchar)
plunky
1.196
863                         av[na++] = "-D__CHAR_UNSIGNED__";
ragge
1.128
864                 if (ascpp)
865                         av[na++] = "-D__ASSEMBLER__";
866                 if (sspflag)
plunky
1.208
867                         av[na++] = "-D__SSP__";
ragge
1.128
868                 if (pthreads)
869                         av[na++] = "-D_PTHREADS";
870                 if (Mflag)
871                         av[na++] = "-M";
ragge
1.160
872                 if (Oflag)
873                         av[na++] = "-D__OPTIMIZE__";
874 #ifdef GCC_COMPAT
875                 av[na++] = "-D__REGISTER_PREFIX__=" REGISTER_PREFIX;
876                 av[na++] = "-D__USER_LABEL_PREFIX__=" USER_LABEL_PREFIX;
877 #endif
ragge
1.128
878                 for (j = 0cppadd[j]; j++)
879                         av[na++] = cppadd[j];
gmcgarry
1.163
880                 for (j = 0j < ncppj++)
881                         av[na++] = cpplist[j];
gmcgarry
1.149
882                 av[na++] = "-D__STDC_ISO_10646__=200009L";
ragge
1.157
883                 av[na++] = "-D__WCHAR_TYPE__=" WCT;
884                 av[na++] = "-D__SIZEOF_WCHAR_T__=" MKS(WCHAR_SIZE);
885                 av[na++] = "-D__WCHAR_MAX__=" WCM;
plunky
1.192
886                 av[na++] = "-D__WINT_TYPE__=" PCC_WINT_TYPE;
887                 av[na++] = "-D__SIZE_TYPE__=" PCC_SIZE_TYPE;
ragge
1.161
888                 av[na++] = "-D__PTRDIFF_TYPE__=" PCC_PTRDIFF_TYPE;
gmcgarry
1.142
889                 av[na++] = "-D__SIZEOF_WINT_T__=4";
plunky
1.201
890 #if defined(os_darwin) || defined(os_netbsd)
891                 av[na++] = "-D__FLT_RADIX__=2";
892                 av[na++] = "-D__FLT_DIG__=6";
893                 av[na++] = "-D__FLT_EPSILON__=1.19209290e-07F";
894                 av[na++] = "-D__FLT_MANT_DIG__=24";
895                 av[na++] = "-D__FLT_MAX_10_EXP__=38";
896                 av[na++] = "-D__FLT_MAX_EXP__=128";
897                 av[na++] = "-D__FLT_MAX__=3.40282347e+38F";
898                 av[na++] = "-D__FLT_MIN_10_EXP__=(-37)";
899                 av[na++] = "-D__FLT_MIN_EXP__=(-125)";
gmcgarry
1.171
900                 av[na++] = "-D__FLT_MIN__=1.17549435e-38F";
plunky
1.201
901                 av[na++] = "-D__DBL_DIG__=15";
902                 av[na++] = "-D__DBL_EPSILON__=2.2204460492503131e-16";
903                 av[na++] = "-D__DBL_MANT_DIG__=53";
904                 av[na++] = "-D__DBL_MAX_10_EXP__=308";
905                 av[na++] = "-D__DBL_MAX_EXP__=1024";
906                 av[na++] = "-D__DBL_MAX__=1.7976931348623157e+308";
907                 av[na++] = "-D__DBL_MIN_10_EXP__=(-307)";
908                 av[na++] = "-D__DBL_MIN_EXP__=(-1021)";
gmcgarry
1.171
909                 av[na++] = "-D__DBL_MIN__=2.2250738585072014e-308";
plunky
1.201
910 #if defined(mach_i386) || defined(mach_amd64)
911                 av[na++] = "-D__LDBL_DIG__=18";
912                 av[na++] = "-D__LDBL_EPSILON__=1.08420217248550443401e-19L";
913                 av[na++] = "-D__LDBL_MANT_DIG__=64";
914                 av[na++] = "-D__LDBL_MAX_10_EXP__=4932";
915                 av[na++] = "-D__LDBL_MAX_EXP__=16384";
916                 av[na++] = "-D__LDBL_MAX__=1.18973149535723176502e+4932L";
917                 av[na++] = "-D__LDBL_MIN_10_EXP__=(-4931)";
918                 av[na++] = "-D__LDBL_MIN_EXP__=(-16381)";
gmcgarry
1.171
919                 av[na++] = "-D__LDBL_MIN__=3.36210314311209350626e-4932L";
plunky
1.201
920 #else
921                 av[na++] = "-D__LDBL_DIG__=15";
922                 av[na++] = "-D__LDBL_EPSILON__=2.2204460492503131e-16";
923                 av[na++] = "-D__LDBL_MANT_DIG__=53";
924                 av[na++] = "-D__LDBL_MAX_10_EXP__=308";
925                 av[na++] = "-D__LDBL_MAX_EXP__=1024";
926                 av[na++] = "-D__LDBL_MAX__=1.7976931348623157e+308";
927                 av[na++] = "-D__LDBL_MIN_10_EXP__=(-307)";
928                 av[na++] = "-D__LDBL_MIN_EXP__=(-1021)";
929                 av[na++] = "-D__LDBL_MIN__=2.2250738585072014e-308";
930 #endif
gmcgarry
1.171
931 #endif
ragge
1.128
932 #ifdef MULTITARGET
933                 for (k = 0cppmds[k].machk++) {
934                         if (strcmp(cppmds[k].machmach) != 0)
935                                 continue;
936                         for (j = 0cppmds[k].cppmdadd[j]; j++)
937                                 av[na++] = cppmds[k].cppmdadd[j];
938                         break;
939                 }
940 #else
941                 for (j = 0cppmdadd[j]; j++)
942                         av[na++] = cppmdadd[j];
943 #endif
944                 if (tflag)
945                         av[na++] = "-t";
946                 for(pv=ptemppv <pvtpv++)
947                         av[na++] = *pv;
gmcgarry
1.153
948                 if (!nostdinc) {
plunky
1.185
949                         av[na++] = "-S"av[na++] = cat(sysrootaltincdir);
950                         av[na++] = "-S"av[na++] = cat(sysrootincdir);
plunky
1.200
951 #ifdef PCCINCDIR
ragge
1.198
952                         if (cxxflag)
953                                 av[na++] = "-S"av[na++] = pxxincdir;
plunky
1.187
954                         av[na++] = "-S"av[na++] = pccincdir;
plunky
1.200
955 #endif
gmcgarry
1.153
956                 }
ragge
1.128
957                 if (idirafter) {
958                         av[na++] = "-I";
959                         av[na++] = idirafter;
960                 }
961                 av[na++] = clist[i];
962                 if (!Eflag && !Mflag)
963                         av[na++] = tmp4;
ragge
1.141
964                 if ((Eflag || Mflag) && outfile)
ragge
1.128
965                          ermfile = av[na++] = outfile;