Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20120730112806

Diff

Diff from 1.216 to:

Annotations

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

Annotated File View

ragge
1.216
1 /*      $Id: cc.c,v 1.216 2012/07/30 11:28:06 ragge Exp $       */
ragge
1.128
2 /*
3  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * Redistributions of source code and documentation must retain the above
10  * copyright notice, this list of conditions and the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditionsand the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * All advertising materials mentioning features or use of this software
15  * must display the following acknowledgement:
16  *      This product includes software developed or owned by Caldera
17  *      International, Inc.
18  * Neither the name of Caldera International, Inc. nor the names of other
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23  * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
27  * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35
36 /*
37  * Front-end to the C compiler.
38  *
39  * Brief description of its syntax:
40  * - Files that end with .c are passed via cpp->ccom->as->ld
41  * - Files that end with .i are passed via ccom->as->ld
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
ragge
1.216
183 int     MflagMPflagnMfiles/* dependencies only */
184 char    *Mfiles[10];
ragge
1.128
185 int     pgflag;
186 int     exfail;
187 int     Xflag;
188 int     Wallflag;
189 int     Wflag;
190 int     nostartfilesBstaticshared;
191 int     nostdincnostdlib;
192 int     onlyas;
193 int     pthreads;
ragge
1.198
194 int     xcflagxgnu89xgnu99;
ragge
1.128
195 int     ascpp;
plunky
1.196
196 #ifdef CHAR_UNSIGNED
plunky
1.209
197 int     xuchar = 1;
plunky
1.196
198 #else
plunky
1.209
199 int     xuchar = 0;
plunky
1.196
200 #endif
ragge
1.198
201 int     cxxflag;
ragge
1.216
202 int     cppflag;
ragge
1.128
203
204 char    *passp = LIBEXECDIR PREPROCESSOR;
205 char    *pass0 = LIBEXECDIR COMPILER;
ragge
1.212
206 char    *passxx0 = LIBEXECDIR "cxxcom";
ragge
1.128
207 char    *as = ASSEMBLER;
208 char    *ld = LINKER;
ragge
1.175
209 char    *sysroot;
ragge
1.128
210 char *cppadd[] = CPPADD;
211 #ifdef DYNLINKER
212 char *dynlinker[] = DYNLINKER;
213 #endif
214 #ifdef CRT0FILE
215 char *crt0file = CRT0FILE;
216 #endif
217 #ifdef CRT0FILE_PROFILE
218 char *crt0file_profile = CRT0FILE_PROFILE;
219 #endif
220 #ifdef STARTFILES
221 char *startfiles[] = STARTFILES;
222 char *endfiles[] = ENDFILES;
223 #endif
224 #ifdef STARTFILES_T
225 char *startfiles_T[] = STARTFILES_T;
226 char *endfiles_T[] = ENDFILES_T;
227 #endif
228 #ifdef STARTFILES_S
229 char *startfiles_S[] = STARTFILES_S;
230 char *endfiles_S[] = ENDFILES_S;
231 #endif
232 #ifdef MULTITARGET
233 char *mach = DEFMACH;
234 struct cppmd {
235         char *mach;
236         char *cppmdadd[MAXCPPMDARGS];
237 };
238
239 struct cppmd cppmds[] = CPPMDADDS;
240 #else
241 char *cppmdadd[] = CPPMDADD;
242 #endif
243 #ifdef LIBCLIBS
244 char *libclibs[] = LIBCLIBS;
245 #else
246 char *libclibs[] = { "-lc"NULL };
247 #endif
248 #ifdef LIBCLIBS_PROFILE
249 char *libclibs_profile[] = LIBCLIBS_PROFILE;
250 #else
251 char *libclibs_profile[] = { "-lc_p"NULL };
252 #endif
253 #ifndef STARTLABEL
254 #define STARTLABEL "__start"
255 #endif
256 char *incdir = STDINC;
gmcgarry
1.153
257 char *altincdir = INCLUDEDIR "pcc/";
gmcgarry
1.136
258 char *libdir = LIBDIR;
plunky
1.200
259 #ifdef PCCINCDIR
ragge
1.128
260 char *pccincdir = PCCINCDIR;
ragge
1.198
261 char *pxxincdir = PCCINCDIR "/c++";
plunky
1.200
262 #endif
263 #ifdef PCCLIBDIR
ragge
1.128
264 char *pcclibdir = PCCLIBDIR;
plunky
1.200
265 #endif
ragge
1.164
266 #ifdef mach_amd64
267 int amd64_i386;
268 #endif
ragge
1.128
269
270 /* handle gcc warning emulations */
271 struct Wflags {
272         char *name;
273         int flags;
274 #define INWALL          1
275 Wflags[] = {
plunky
1.215
276         { "truncate"0 },
277         { "strict-prototypes"0 },
278         { "missing-prototypes"0 },
279         { "implicit-int"INWALL },
280         { "implicit-function-declaration"INWALL },
281         { "shadow"0 },
282         { "pointer-sign"INWALL },
283         { "sign-compare"0 },
284         { "unknown-pragmas"INWALL },
285         { "unreachable-code"0 },
286         { NULL0 },
ragge
1.128
287 };
288
ragge
1.158
289 #ifndef USHORT
290 /* copied from mip/manifest.h */
291 #define USHORT          5
292 #define INT             6
293 #define UNSIGNED        7
294 #endif
295
ragge
1.157
296 /*
297  * Wide char defines.
298  */
299 #if WCHAR_TYPE == USHORT
300 #define WCT "short unsigned int"
301 #define WCM "65535U"
ragge
1.158
302 #if WCHAR_SIZE != 2
303 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
304 #endif
ragge
1.157
305 #elif WCHAR_TYPE == INT
306 #define WCT "int"
307 #define WCM "2147483647"
ragge
1.158
308 #if WCHAR_SIZE != 4
309 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
310 #endif
ragge
1.157
311 #elif WCHAR_TYPE == UNSIGNED
312 #define WCT "unsigned int"
ragge
1.158
313 #define WCM "4294967295U"
314 #if WCHAR_SIZE != 4
315 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
316 #endif
317 #else
318 #error WCHAR_TYPE not defined or invalid
ragge
1.157
319 #endif
320
ragge
1.160
321 #ifdef GCC_COMPAT
322 #ifndef REGISTER_PREFIX
323 #define REGISTER_PREFIX ""
324 #endif
325 #ifndef USER_LABEL_PREFIX
326 #define USER_LABEL_PREFIX ""
327 #endif
328 #endif
329
plunky
1.192
330 #ifndef PCC_WINT_TYPE
331 #define PCC_WINT_TYPE "unsigned int"
332 #endif
333
334 #ifndef PCC_SIZE_TYPE
335 #define PCC_SIZE_TYPE "unsigned long"
336 #endif
337
ragge
1.161
338 #ifndef PCC_PTRDIFF_TYPE
339 #define PCC_PTRDIFF_TYPE "long int"
340 #endif
341
ragge
1.216
342 #ifndef CPPROGNAME
343 #define CPPROGNAME      "cpp"
344 #endif
345
ragge
1.128
346 int
347 main(int argcchar *argv[])
348 {
349         struct Wflags *Wf;
350         char *t, *u;
351         char *assource;
352         char **pv, *ptemp[MAXOPT], **pvt;
gmcgarry
1.163
353         int ncnlnasncppijcnxona;
ragge
1.128
354 #ifdef MULTITARGET
355         int k;
356 #endif
357
ragge
1.216
358         if ((t = strrchr(argv[0], '/')))
359                 t = copy(t+10);
360         else
361                 t = argv[0];
362         if (strcmp(t"p++") == 0) {
ragge
1.198
363                 cxxflag = 1;
364                 pass0 = passxx0;
ragge
1.216
365         } else if (strcmp(t"cpp") == 0 || strcmp(tCPPROGNAME) == 0) {
366                 cppflag = 1;
367                 Eflag = 1;
ragge
1.198
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 {
plunky
1.215
506                                         /* pass through, if supported */
507                                         t = &argv[i][2];
508                                         if (strncmp(t"no-"3) == 0)
509                                                 t += 3;
510                                         if (strncmp(t"error="6) == 0)
511                                                 t += 6;
ragge
1.128
512                                         for (Wf = WflagsWf->nameWf++) {
plunky
1.215
513                                                 if (strcmp(tWf->name) == 0)
514                                                         wlist[nw++] = argv[i];
ragge
1.128
515                                         }
516                                 }
517                                 break;
518
519                         case 'f'/* GCC compatibility flags */
520                                 if (strcmp(argv[i], "-fPIC") == 0)
521                                         kflag = F_PIC;
522                                 else if (strcmp(argv[i], "-fpic") == 0)
523                                         kflag = F_pic;
ragge
1.195
524                                 else if (strcmp(argv[i], "-ffreestanding") == 0)
plunky
1.214
525                                         freestanding = 1;
ragge
1.128
526                                 else if (strcmp(argv[i],
plunky
1.209
527                                     "-fsigned-char") == 0)
528                                         xuchar = 0;
529                                 else if (strcmp(argv[i],
530                                     "-fno-signed-char") == 0)
531                                         xuchar = 1;
532                                 else if (strcmp(argv[i],
533                                     "-funsigned-char") == 0)
534                                         xuchar = 1;
535                                 else if (strcmp(argv[i],
536                                     "-fno-unsigned-char") == 0)
537                                         xuchar = 0;
538                                 else if (strcmp(argv[i],
ragge
1.128
539                                     "-fstack-protector") == 0) {
540                                         flist[nf++] = argv[i];
541                                         sspflag++;
542                                 } else if (strcmp(argv[i],
543                                     "-fstack-protector-all") == 0) {
544                                         flist[nf++] = argv[i];
545                                         sspflag++;
546                                 } else if (strcmp(argv[i],
547                                     "-fno-stack-protector") == 0) {
548                                         flist[nf++] = argv[i];
549                                         sspflag = 0;
550                                 } else if (strcmp(argv[i],
551                                     "-fno-stack-protector-all") == 0) {
552                                         flist[nf++] = argv[i];
553                                         sspflag = 0;
554                                 }
555                                 /* silently ignore the rest */
556                                 break;
557
558                         case 'g'/* create debug output */
ragge
1.177
559                                 if (argv[i][2] == '0')
560                                         gflag = 0;
561                                 else
562                                         gflag++;
ragge
1.128
563                                 break;
564
565                         case 'i':
566                                 if (strcmp(argv[i], "-isystem") == 0) {
567                                         *pv++ = "-S";
568                                         *pv++ = argv[++i];
569                                 } else if (strcmp(argv[i], "-include") == 0) {
570                                         *pv++ = "-i";
571                                         *pv++ = argv[++i];
572                                 } else if (strcmp(argv[i], "-idirafter") == 0) {
573                                         idirafter = argv[++i];
gmcgarry
1.172
574 #ifdef os_darwin
575                                 } else if (strcmp(argv[i], "-install_name") == 0) {
576                                         llist[nl++] = argv[i];
577                                         llist[nl++] = argv[++i];
578 #endif
ragge
1.128
579                                 } else
580                                         goto passa;
581                                 break;
582
583                         case 'k'/* generate PIC code */
584                                 kflag = F_pic;
585                                 break;
586
587                         case 'm'/* target-dependent options */
ragge
1.164
588 #ifdef mach_amd64
589                                 /* need to call i386 ccom for this */
590                                 if (strcmp(argv[i], "-m32") == 0) {
591                                         pass0 = LIBEXECDIR "/ccom_i386";
592                                         amd64_i386 = 1;
593                                         break;
594                                 }
595 #endif
ragge
1.128
596                                 mlist[nm++] = argv[i];
ragge
1.169
597                                 if (argv[i][2] == 0) {
598                                         /* separate second arg */
599                                         /* give also to linker */
600                                         llist[nl++] = argv[i++];
601                                         mlist[nm++] = argv[i];
602                                         llist[nl++] = argv[i];
603                                 }
ragge
1.128
604                                 break;
605
606                         case 'n'/* handle -n flags */
607                                 if (strcmp(argv[i], "-nostdinc") == 0)
608                                         nostdinc++;
609                                 else if (strcmp(argv[i], "-nostdlib") == 0) {
610                                         nostdlib++;
611                                         nostartfiles++;
612                                 } else if (strcmp(argv[i], "-nostartfiles") == 0)
613                                         nostartfiles = 1;
plunky
1.202
614                                 else if (strcmp(argv[i], "-nodefaultlibs") == 0)
615                                         nostdlib++;
ragge
1.128
616                                 else
617                                         goto passa;
618                                 break;
619
620                         case 'p':
621                                 if (strcmp(argv[i], "-pg") == 0 ||
622                                     strcmp(argv[i], "-p") == 0)
623                                         pgflag++;
624                                 else if (strcmp(argv[i], "-pthread") == 0)
625                                         pthreads++;
626                                 else if (strcmp(argv[i], "-pipe") == 0)
627                                         /* NOTHING YET */;
gmcgarry
1.144
628                                 else if (strcmp(argv[i], "-pedantic") == 0)
629                                         /* NOTHING YET */;
ragge
1.162
630                                 else if (strcmp(argv[i],
631                                     "-print-prog-name=ld") == 0) {
632                                         printf("%s\n"LINKER);
633                                         return 0;
ragge
1.174
634                                 } else if (strcmp(argv[i],
635                                     "-print-multi-os-directory") == 0) {
636                                         printf("%s\n"MULTIOSDIR);
637                                         return 0;
ragge
1.162
638                                 } else
ragge
1.128
639                                         errorx(1"unknown option %s"argv[i]);
640                                 break;
641
gmcgarry
1.145
642                         case 'r':
643                                 rflag = 1;
644                                 break;
645
ragge
1.128
646                         case 'x':
647                                 t = &argv[i][2];
648                                 if (*t == 0)
649                                         t = argv[++i];
650                                 if (strcmp(t"c") == 0)
651                                         xcflag = 1/* default */
652                                 else if (strcmp(t"assembler-with-cpp") == 0)
653                                         ascpp = 1;
654                                 else if (strcmp(t"c++") == 0)
655                                         cxxflag++;
656                                 else
657                                         xlist[xnum++] = argv[i];
658                                 break;
659                         case 't':
660                                 tflag++;
661                                 break;
662                         case 'S':
663                                 sflag++;
664                                 cflag++;
665                                 break;
666                         case 'o':
667                                 if (outfile)
668                                         errorx(8"too many -o");
669                                 outfile = argv[++i];
670                                 break;
671                         case 'O':
plunky
1.203
672                                 if (argv[i][2] == '\0')
673                                         Oflag++;
674                                 else if (argv[i][3] == '\0' && isdigit((unsigned char)argv[i][2]))
675                                         Oflag = argv[i][2] - '0';
plunky
1.211
676                                 else if (argv[i][3] == '\0' && argv[i][2] == 's')
677                                         Oflag = 1;      /* optimize for space only */
ragge
1.128
678                                 else
plunky
1.203
679                                         error("unknown option %s"argv[i]);
ragge
1.128
680                                 break;
681                         case 'E':
682                                 Eflag++;
683                                 break;
684                         case 'P':
685                                 pflag++;
686                                 *pv++ = argv[i];
687                         case 'c':
gmcgarry
1.172
688 #ifdef os_darwin
689                                 if (strcmp(argv[i], "-compatibility_version") == 0) {
690                                         llist[nl++] = argv[i];
691                                         llist[nl++] = argv[++i];
692                                 } else if (strcmp(argv[i], "-current_version") == 0) {
693                                         llist[nl++] = argv[i];
694                                         llist[nl++] = argv[++i];
695                                 } else
696 #endif
697                                         cflag++;
ragge
1.128
698                                 break;
699 #if 0
700                         case '2':
701                                 if(argv[i][2] == '\0')
702                                         pref = "/lib/crt2.o";
703                                 else {
704                                         pref = "/lib/crt20.o";
705                                 }
706                                 break;
707 #endif
708                         case 'C':
gmcgarry
1.163
709                                 cpplist[ncpp++] = argv[i];
ragge
1.128
710                                 break;
711                         case 'D':
712                         case 'I':
713                         case 'U':
714                                 *pv++ = argv[i];
plunky
1.207
715                                 if (argv[i][2] == '\0')
ragge
1.128
716                                         *pv++ = argv[++i];
717                                 if (pv >= ptemp+MAXOPT) {
718                                         error("Too many DIU options");
719                                         --pv;
720                                 }
721                                 break;
722
723                         case 'M':
ragge
1.216
724                                 switch (argv[i][2]) {
725                                 case '\0'Mflag++; break;
726                                 case 'P'MPflag++; break;
727                                 case 'F'outfile = argv[++i]; break;
728                                 case 'T':
729                                 case 'Q':
730                                         j = strlen(argv[++i]);
731                                         t = copy("-xM.,"j);
732                                         strlcat(targv[i], j+6);
733                                         t[3] = argv[i-1][2];
734                                         Mfiles[nMfiles++] = t;
735                                         break;
736                                 default:
737                                         error("unknown option '%s'"argv[i]);
738                                 }
ragge
1.128
739                                 break;
740
741                         case 'd':
gmcgarry
1.144
742 #ifdef os_darwin
743                                 if (strcmp(argv[i], "-dynamiclib") == 0) {
744                                         shared = 1;
745                                 } else
746 #endif
ragge
1.128
747                                 break;
748                         case 'v':
749                                 printf("%s\n"VERSSTR);
750                                 vflag++;
751                                 break;
752
753                         case 's':
gmcgarry
1.144
754 #ifndef os_darwin
755                                 if (strcmp(argv[i], "-shared") == 0) {
ragge
1.128
756                                         shared = 1;
gmcgarry
1.144
757                                 } else
758 #endif
759                                 if (strcmp(argv[i], "-static") == 0) {
760                                         Bstatic = 1;
plunky
1.189
761                                 } else if (strcmp(argv[i], "-symbolic") == 0) {
762                                         llist[nl++] = "-Bsymbolic";
ragge
1.128
763                                 } else if (strncmp(argv[i], "-std"4) == 0) {
ragge
1.190
764                                         if (strcmp(&argv[i][5], "gnu99") == 0 ||
ragge
1.198
765                                             strcmp(&argv[i][5], "gnu9x") == 0)
766                                                 xgnu99 = 1;
767                                         if (strcmp(&argv[i][5], "gnu89") == 0)
768                                                 xgnu89 = 1;
ragge
1.128
769                                 } else
770                                         goto passa;
771                                 break;
772                         }
773                 } else {
774                 passa:
775                         t = argv[i];
776                         if (*argv[i] == '-' && argv[i][1] == 'L')
777                                 ;
ragge
1.198
778                         else if ((cxxsuf(getsufp(t)) && cxxflag) ||
779                             (c=getsuf(t))=='c' || c=='S' || c=='i' ||
ragge
1.128
780                             c=='s'|| Eflag || xcflag) {
781                                 clist[nc++] = t;
782                                 if (nc>=MAXFIL) {
783                                         error("Too many source files");
784                                         exit(1);
785                                 }
786                         }
787
788                         /* Check for duplicate .o files. */
789                         for (j = getsuf(t) == 'o' ? 0 : nlj < nlj++) {
790                                 if (strcmp(llist[j], t) == 0)
791                                         break;
792                         }
gmcgarry
1.150
793                         if ((c=getsuf(t))!='c' && c!='S' &&
ragge
1.212
794                             c!='s' && c!='i' && j==nl &&
795                             !(cxxsuf(getsufp(t)) && cxxflag)) {
ragge
1.128
796                                 llist[nl++] = t;
797                                 if (nl >= MAXLIB) {
798                                         error("Too many object/library files");
799                                         exit(1);
800                                 }
801                                 if (getsuf(t)=='o')
802                                         nxo++;
803                         }
804                 }
805         }
806         /* Sanity checking */
ragge
1.216
807         if (cppflag) {
808                 if (nc == 0)
809                         clist[nc++] = "-";
810                 else if (nc > 2 || (nc == 2 && outfile))
811                         errorx(8"too many files");
812                 else if (nc == 2)
813                         outfile = clist[--nc];
814         }
ragge
1.128
815         if (nc == 0 && nl == 0)
816                 errorx(8"no input files");
817         if (outfile && (cflag || sflag || Eflag) && nc > 1)
818                 errorx(8"-o given with -c || -E || -S and more than one file");
819         if (outfile && clist[0] && strcmp(outfileclist[0]) == 0)
820                 errorx(8"output file will be clobbered");
gmcgarry
1.150
821         if (nc==0)
ragge
1.128
822                 goto nocom;
823         if (pflag==0) {
824                 if (!sflag)
825                         tmp3 = gettmp();
826                 tmp4 = gettmp();
827         }
828         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
829                 signal(SIGINTidexit);
830         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
831                 signal(SIGTERMidexit);
832 #ifdef MULTITARGET
plunky
1.186
833         pass0 = cat(LIBEXECDIR "/ccom_"mach);
ragge
1.128
834 #endif
835         pvt = pv;
836         for (i=0i<nci++) {
837                 /*
838                  * C preprocessor
839                  */
840                 if (nc>1 && !Eflag)
841                         printf("%s:\n"clist[i]);
842                 onlyas = 0;
843                 assource = tmp3;
844                 if (getsuf(clist[i])=='S')
845                         ascpp = 1;
846                 if (getsuf(clist[i])=='i') {
847                         if(Eflag)
848                                 continue;
849                         goto com;
850                 } else if (ascpp) {
851                         onlyas = 1;
852                 } else if (getsuf(clist[i])=='s') {
853                         assource = clist[i];
854                         goto assemble;
855                 }
856                 if (pflag)
857                         tmp4 = setsuf(clist[i], 'i');
858                 na = 0;
859                 av[na++] = "cpp";
860                 if (vflag)
861                         av[na++] = "-v";
862                 av[na++] = "-D__PCC__=" MKS(PCC_MAJOR);
863                 av[na++] = "-D__PCC_MINOR__=" MKS(PCC_MINOR);
864                 av[na++] = "-D__PCC_MINORMINOR__=" MKS(PCC_MINORMINOR);
gmcgarry
1.156
865 #ifndef os_win32
ragge
1.155
866 #ifdef GCC_COMPAT
867                 av[na++] = "-D__GNUC__=4";
868                 av[na++] = "-D__GNUC_MINOR__=3";
869                 av[na++] = "-D__GNUC_PATCHLEVEL__=1";
ragge
1.198
870                 if (xgnu89)
plunky
1.208
871                         av[na++] = "-D__GNUC_GNU_INLINE__";
ragge
1.191
872                 else
plunky
1.208
873                         av[na++] = "-D__GNUC_STDC_INLINE__";
ragge
1.170
874 #endif
875 #endif
ragge
1.166
876                 av[na++] = "-D__VERSION__=" MKS(VERSSTR);
ragge
1.167
877                 av[na++] = "-D__SCHAR_MAX__=" MKS(MAX_CHAR);
878                 av[na++] = "-D__SHRT_MAX__=" MKS(MAX_SHORT);
879                 av[na++] = "-D__INT_MAX__=" MKS(MAX_INT);
880                 av[na++] = "-D__LONG_MAX__=" MKS(MAX_LONG);
881                 av[na++] = "-D__LONG_LONG_MAX__=" MKS(MAX_LONGLONG);
plunky
1.214
882                 if (freestanding)
883                         av[na++] = "-D__STDC_HOSTED__=0";
884                 else
885                         av[na++] = "-D__STDC_HOSTED__=1";
ragge
1.212
886                 if (cxxflag)
887                         av[na++] = "-D__cplusplus";
plunky
1.209
888                 if (xuchar)
plunky
1.196
889                         av[na++] = "-D__CHAR_UNSIGNED__";
ragge
1.128
890                 if (ascpp)
891                         av[na++] = "-D__ASSEMBLER__";
892                 if (sspflag)
plunky
1.208
893                         av[na++] = "-D__SSP__";
ragge
1.128
894                 if (pthreads)
895                         av[na++] = "-D_PTHREADS";
896                 if (Mflag)
897                         av[na++] = "-M";
ragge
1.216
898                 if (MPflag)
899                         av[na++] = "-xMP";
900                 for (j = 0j < nMfilesj++)
901                         av[na++] = Mfiles[j];
ragge
1.160
902                 if (Oflag)
903                         av[na++] = "-D__OPTIMIZE__";
904 #ifdef GCC_COMPAT
905                 av[na++] = "-D__REGISTER_PREFIX__=" REGISTER_PREFIX;
906                 av[na++] = "-D__USER_LABEL_PREFIX__=" USER_LABEL_PREFIX;
907 #endif
ragge
1.128
908                 for (j = 0cppadd[j]; j++)
909                         av[na++] = cppadd[j];
gmcgarry
1.163
910                 for (j = 0j < ncppj++)
911                         av[na++] = cpplist[j];
gmcgarry
1.149
912                 av[na++] = "-D__STDC_ISO_10646__=200009L";
ragge
1.157
913                 av[na++] = "-D__WCHAR_TYPE__=" WCT;
914                 av[na++] = "-D__SIZEOF_WCHAR_T__=" MKS(WCHAR_SIZE);
915                 av[na++] = "-D__WCHAR_MAX__=" WCM;
plunky
1.192
916                 av[na++] = "-D__WINT_TYPE__=" PCC_WINT_TYPE;
917                 av[na++] = "-D__SIZE_TYPE__=" PCC_SIZE_TYPE;
ragge
1.161
918                 av[na++] = "-D__PTRDIFF_TYPE__=" PCC_PTRDIFF_TYPE;
gmcgarry
1.142
919                 av[na++] = "-D__SIZEOF_WINT_T__=4";
plunky
1.201
920 #if defined(os_darwin) || defined(os_netbsd)
921                 av[na++] = "-D__FLT_RADIX__=2";
922                 av[na++] = "-D__FLT_DIG__=6";
923                 av[na++] = "-D__FLT_EPSILON__=1.19209290e-07F";
924                 av[na++] = "-D__FLT_MANT_DIG__=24";
925                 av[na++] = "-D__FLT_MAX_10_EXP__=38";
926                 av[na++] = "-D__FLT_MAX_EXP__=128";
927                 av[na++] = "-D__FLT_MAX__=3.40282347e+38F";
928                 av[na++] = "-D__FLT_MIN_10_EXP__=(-37)";
929                 av[na++] = "-D__FLT_MIN_EXP__=(-125)";
gmcgarry
1.171
930                 av[na++] = "-D__FLT_MIN__=1.17549435e-38F";
plunky
1.201
931                 av[na++] = "-D__DBL_DIG__=15";
932                 av[na++] = "-D__DBL_EPSILON__=2.2204460492503131e-16";
933                 av[na++] = "-D__DBL_MANT_DIG__=53";
934                 av[na++] = "-D__DBL_MAX_10_EXP__=308";
935                 av[na++] = "-D__DBL_MAX_EXP__=1024";
936                 av[na++] = "-D__DBL_MAX__=1.7976931348623157e+308";
937                 av[na++] = "-D__DBL_MIN_10_EXP__=(-307)";
938                 av[na++] = "-D__DBL_MIN_EXP__=(-1021)";
gmcgarry
1.171
939                 av[na++] = "-D__DBL_MIN__=2.2250738585072014e-308";
plunky
1.201
940 #if defined(mach_i386) || defined(mach_amd64)
941                 av[na++] = "-D__LDBL_DIG__=18";
942                 av[na++] = "-D__LDBL_EPSILON__=1.08420217248550443401e-19L";
943                 av[na++] = "-D__LDBL_MANT_DIG__=64";
944                 av[na++] = "-D__LDBL_MAX_10_EXP__=4932";
945                 av[na++] = "-D__LDBL_MAX_EXP__=16384";
946                 av[na++] = "-D__LDBL_MAX__=1.18973149535723176502e+4932L";
947                 av[na++] = "-D__LDBL_MIN_10_EXP__=(-4931)";
948                 av[na++] = "-D__LDBL_MIN_EXP__=(-16381)";
gmcgarry
1.171
949                 av[na++] = "-D__LDBL_MIN__=3.36210314311209350626e-4932L";
plunky
1.201
950 #else
951                 av[na++] = "-D__LDBL_DIG__=15";
952                 av[na++] = "-D__LDBL_EPSILON__=2.2204460492503131e-16";
953                 av[na++] = "-D__LDBL_MANT_DIG__=53";
954                 av[na++] = "-D__LDBL_MAX_10_EXP__=308";
955                 av[na++] = "-D__LDBL_MAX_EXP__=1024";
956                 av[na++] = "-D__LDBL_MAX__=1.7976931348623157e+308";
957                 av[na++] = "-D__LDBL_MIN_10_EXP__=(-307)";
958                 av[na++] = "-D__LDBL_MIN_EXP__=(-1021)";
959                 av[na++] = "-D__LDBL_MIN__=2.2250738585072014e-308";
960 #endif
gmcgarry
1.171
961 #endif
ragge
1.128
962 #ifdef MULTITARGET
963                 for (k = 0cppmds[k].machk++) {
964                         if (strcmp(cppmds[k].machmach) != 0)
965                                 continue;
966                         for (j = 0cppmds[k].cppmdadd[j]; j++)
967                                 av[na++] = cppmds[k].cppmdadd[j];
968                         break;
969                 }
970 #else
971                 for (j = 0cppmdadd[j]; j++)
972                         av[na++] = cppmdadd[j];
973 #endif
974                 if (tflag)
975                         av[na++] = "-t";