Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:plunky:20111114115213

Diff

Diff from 1.215 to:

Annotations

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

Annotated File View

plunky
1.215
1 /*      $Id: cc.c,v 1.215 2011/11/14 11:52:13 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 Wflags[] = {
plunky
1.215
274         { "truncate"0 },
275         { "strict-prototypes"0 },
276         { "missing-prototypes"0 },
277         { "implicit-int"INWALL },
278         { "implicit-function-declaration"INWALL },
279         { "shadow"0 },
280         { "pointer-sign"INWALL },
281         { "sign-compare"0 },
282         { "unknown-pragmas"INWALL },
283         { "unreachable-code"0 },
284         { NULL0 },
ragge
1.128
285 };
286
ragge
1.158
287 #ifndef USHORT
288 /* copied from mip/manifest.h */
289 #define USHORT          5
290 #define INT             6
291 #define UNSIGNED        7
292 #endif
293
ragge
1.157
294 /*
295  * Wide char defines.
296  */
297 #if WCHAR_TYPE == USHORT
298 #define WCT "short unsigned int"
299 #define WCM "65535U"
ragge
1.158
300 #if WCHAR_SIZE != 2
301 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
302 #endif
ragge
1.157
303 #elif WCHAR_TYPE == INT
304 #define WCT "int"
305 #define WCM "2147483647"
ragge
1.158
306 #if WCHAR_SIZE != 4
307 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
308 #endif
ragge
1.157
309 #elif WCHAR_TYPE == UNSIGNED
310 #define WCT "unsigned int"
ragge
1.158
311 #define WCM "4294967295U"
312 #if WCHAR_SIZE != 4
313 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
314 #endif
315 #else
316 #error WCHAR_TYPE not defined or invalid
ragge
1.157
317 #endif
318
ragge
1.160
319 #ifdef GCC_COMPAT
320 #ifndef REGISTER_PREFIX
321 #define REGISTER_PREFIX ""
322 #endif
323 #ifndef USER_LABEL_PREFIX
324 #define USER_LABEL_PREFIX ""
325 #endif
326 #endif
327
plunky
1.192
328 #ifndef PCC_WINT_TYPE
329 #define PCC_WINT_TYPE "unsigned int"
330 #endif
331
332 #ifndef PCC_SIZE_TYPE
333 #define PCC_SIZE_TYPE "unsigned long"
334 #endif
335
ragge
1.161
336 #ifndef PCC_PTRDIFF_TYPE
337 #define PCC_PTRDIFF_TYPE "long int"
338 #endif
339
ragge
1.128
340 int
341 main(int argcchar *argv[])
342 {
343         struct Wflags *Wf;
344         char *t, *u;
345         char *assource;
346         char **pv, *ptemp[MAXOPT], **pvt;
gmcgarry
1.163
347         int ncnlnasncppijcnxona;
ragge
1.128
348 #ifdef MULTITARGET
349         int k;
350 #endif
351
ragge
1.198
352         if (strcmp(argv[0], "p++") == 0) {
353                 cxxflag = 1;
354                 pass0 = passxx0;
355         }
356
plunky
1.213
357 #ifdef os_win32
ragge
1.128
358         /* have to prefix path early.  -B may override */
359         incdir = win32pathsubst(incdir);
gmcgarry
1.153
360         altincdir = win32pathsubst(altincdir);
gmcgarry
1.136
361         libdir = win32pathsubst(libdir);
plunky
1.200
362 #ifdef PCCINCDIR
ragge
1.128
363         pccincdir = win32pathsubst(pccincdir);
plunky
1.199
364         pxxincdir = win32pathsubst(pxxincdir);
plunky
1.200
365 #endif
366 #ifdef PCCLIBDIR
ragge
1.128
367         pcclibdir = win32pathsubst(pcclibdir);
plunky
1.200
368 #endif
ragge
1.128
369         passp = win32pathsubst(passp);
370         pass0 = win32pathsubst(pass0);
gmcgarry
1.180
371 #ifdef STARTFILES
372         for (i = 0startfiles[i] != NULLi++)
373                 startfiles[i] = win32pathsubst(startfiles[i]);
374         for (i = 0endfiles[i] != NULLi++)
375                 endfiles[i] = win32pathsubst(endfiles[i]);
376 #endif
377 #ifdef STARTFILES_T
378         for (i = 0startfiles_T[i] != NULLi++)
379                 startfiles_T[i] = win32pathsubst(startfiles_T[i]);
380         for (i = 0endfiles_T[i] != NULLi++)
381                 endfiles_T[i] = win32pathsubst(endfiles_T[i]);
382 #endif
383 #ifdef STARTFILES_S
384         for (i = 0startfiles_S[i] != NULLi++)
385                 startfiles_S[i] = win32pathsubst(startfiles_S[i]);
386         for (i = 0endfiles_S[i] != NULLi++)
387                 endfiles_S[i] = win32pathsubst(endfiles_S[i]);
388 #endif
ragge
1.128
389 #endif
390
gmcgarry
1.163
391         i = nc = nl = nas = ncpp = nxo = 0;
ragge
1.128
392         pv = ptemp;
393         while(++i < argc) {
394                 if (argv[i][0] == '-') {
395                         switch (argv[i][1]) {
396                         default:
397                                 goto passa;
398 #ifdef notyet
399         /* must add library options first (-L/-l/...) */
400                                 error("unrecognized option `-%c'"argv[i][1]);
401                                 break;
402 #endif
403
404                         case '-'/* double -'s */
ragge
1.130
405                                 if (strcmp(argv[i], "--version") == 0) {
ragge
1.128
406                                         printf("%s\n"VERSSTR);
ragge
1.130
407                                         return 0;
ragge
1.175
408                                 } else if (strncmp(argv[i], "--sysroot="10) == 0) {
409                                         sysroot = argv[i] + 10;
ragge
1.169
410                                 } else if (strcmp(argv[i], "--param") == 0) {
ragge
1.128
411                                         /* NOTHING YET */;
ragge
1.169
412                                         i++; /* ignore arg */
413                                 } else
gmcgarry
1.148
414                                         goto passa;
ragge
1.128
415                                 break;
416
417                         case 'B'/* other search paths for binaries */
ragge
1.175
418                                 add_prefix(argv[i] + 2);
ragge
1.128
419                                 break;
420
421 #ifdef MULTITARGET
422                         case 'b':
423                                 t = &argv[i][2];
424                                 if (*t == '\0' && i + 1 < argc) {
425                                         t = argv[i+1];
426                                         i++;
427                                 }
428                                 if (strncmp(t"?"1) == 0) {
429                                         /* show machine targets */
430                                         printf("Available machine targets:");
431                                         for (j=0cppmds[j].machj++)
432                                                 printf(" %s",cppmds[j].mach);
433                                         printf("\n");
434                                         exit(0);
435                                 }
436                                 for (j=0cppmds[j].machj++)
437                                         if (strcmp(tcppmds[j].mach) == 0) {
438                                                 mach = cppmds[j].mach;
439                                                 break;
440                                         }
441                                 if (cppmds[j].mach == NULL)
442                                         errorx(1"unknown target arch %s"t);
443                                 break;
444 #endif
445
446                         case 'X':
447                                 Xflag++;
448                                 break;
449                         case 'W'/* Ignore (most of) W-flags */
450                                 if (strncmp(argv[i], "-Wl,"4) == 0) {
451                                         /* options to the linker */
452                                         t = &argv[i][4];
453                                         while ((u = strchr(t','))) {
454                                                 *u++ = 0;
455                                                 llist[nl++] = t;
456                                                 t = u;
457                                         }
458                                         llist[nl++] = t;
459                                 } else if (strncmp(argv[i], "-Wa,"4) == 0) {
460                                         /* options to the assembler */
461                                         t = &argv[i][4];
462                                         while ((u = strchr(t','))) {
463                                                 *u++ = 0;
464                                                 aslist[nas++] = t;
465                                                 t = u;
466                                         }
467                                         aslist[nas++] = t;
ragge
1.137
468                                 } else if (strncmp(argv[i], "-Wc,"4) == 0) {
469                                         /* options to ccom */
470                                         t = &argv[i][4];
471                                         while ((u = strchr(t','))) {
472                                                 *u++ = 0;
473                                                 wlist[nw++] = t;
474                                                 t = u;
475                                         }
476                                         wlist[nw++] = t;
ragge
1.128
477                                 } else if (strncmp(argv[i], "-Wp,"4) == 0) {
478                                         /* preprocessor */
gmcgarry
1.163
479                                         t = &argv[i][4];
480                                         while ((u = strchr(t','))) {
481                                                 *u++ = 0;
482                                                 cpplist[ncpp++] = t;
483                                                 t = u;
484                                         }
485                                         cpplist[ncpp++] = t;
plunky
1.193
486                                 } else if (strcmp(argv[i], "-Werror") == 0) {
487                                         wlist[nw++] = argv[i];
ragge
1.128
488                                 } else if (strcmp(argv[i], "-Wall") == 0) {
489                                         Wallflag = 1;
490                                 } else if (strcmp(argv[i], "-WW") == 0) {
491                                         Wflag = 1;
492                                 } else {
plunky
1.215
493                                         /* pass through, if supported */
494                                         t = &argv[i][2];
495                                         if (strncmp(t"no-"3) == 0)
496                                                 t += 3;
497                                         if (strncmp(t"error="6) == 0)
498                                                 t += 6;
ragge
1.128
499                                         for (Wf = WflagsWf->nameWf++) {
plunky
1.215
500                                                 if (strcmp(tWf->name) == 0)
501                                                         wlist[nw++] = argv[i];
ragge
1.128
502                                         }
503                                 }
504                                 break;
505
506                         case 'f'/* GCC compatibility flags */
507                                 if (strcmp(argv[i], "-fPIC") == 0)
508                                         kflag = F_PIC;
509                                 else if (strcmp(argv[i], "-fpic") == 0)
510                                         kflag = F_pic;
ragge
1.195
511                                 else if (strcmp(argv[i], "-ffreestanding") == 0)
plunky
1.214
512                                         freestanding = 1;
ragge
1.128
513                                 else if (strcmp(argv[i],
plunky
1.209
514                                     "-fsigned-char") == 0)
515                                         xuchar = 0;
516                                 else if (strcmp(argv[i],
517                                     "-fno-signed-char") == 0)
518                                         xuchar = 1;
519                                 else if (strcmp(argv[i],
520                                     "-funsigned-char") == 0)
521                                         xuchar = 1;
522                                 else if (strcmp(argv[i],
523                                     "-fno-unsigned-char") == 0)
524                                         xuchar = 0;
525                                 else if (strcmp(argv[i],
ragge
1.128
526                                     "-fstack-protector") == 0) {
527                                         flist[nf++] = argv[i];
528                                         sspflag++;
529                                 } else if (strcmp(argv[i],
530                                     "-fstack-protector-all") == 0) {
531                                         flist[nf++] = argv[i];
532                                         sspflag++;
533                                 } else if (strcmp(argv[i],
534                                     "-fno-stack-protector") == 0) {
535                                         flist[nf++] = argv[i];
536                                         sspflag = 0;
537                                 } else if (strcmp(argv[i],
538                                     "-fno-stack-protector-all") == 0) {
539                                         flist[nf++] = argv[i];
540                                         sspflag = 0;
541                                 }
542                                 /* silently ignore the rest */
543                                 break;
544
545                         case 'g'/* create debug output */
ragge
1.177
546                                 if (argv[i][2] == '0')
547                                         gflag = 0;
548                                 else
549                                         gflag++;
ragge
1.128
550                                 break;
551
552                         case 'i':
553                                 if (strcmp(argv[i], "-isystem") == 0) {
554                                         *pv++ = "-S";
555                                         *pv++ = argv[++i];
556                                 } else if (strcmp(argv[i], "-include") == 0) {
557                                         *pv++ = "-i";
558                                         *pv++ = argv[++i];
559                                 } else if (strcmp(argv[i], "-idirafter") == 0) {
560                                         idirafter = argv[++i];
gmcgarry
1.172
561 #ifdef os_darwin
562                                 } else if (strcmp(argv[i], "-install_name") == 0) {
563                                         llist[nl++] = argv[i];
564                                         llist[nl++] = argv[++i];
565 #endif
ragge
1.128
566                                 } else
567                                         goto passa;
568                                 break;
569
570                         case 'k'/* generate PIC code */
571                                 kflag = F_pic;
572                                 break;
573
574                         case 'm'/* target-dependent options */
ragge
1.164
575 #ifdef mach_amd64
576                                 /* need to call i386 ccom for this */
577                                 if (strcmp(argv[i], "-m32") == 0) {
578                                         pass0 = LIBEXECDIR "/ccom_i386";
579                                         amd64_i386 = 1;
580                                         break;
581                                 }
582 #endif
ragge
1.128
583                                 mlist[nm++] = argv[i];
ragge
1.169
584                                 if (argv[i][2] == 0) {
585                                         /* separate second arg */
586                                         /* give also to linker */
587                                         llist[nl++] = argv[i++];
588                                         mlist[nm++] = argv[i];
589                                         llist[nl++] = argv[i];
590                                 }
ragge
1.128
591                                 break;
592
593                         case 'n'/* handle -n flags */
594                                 if (strcmp(argv[i], "-nostdinc") == 0)
595                                         nostdinc++;
596                                 else if (strcmp(argv[i], "-nostdlib") == 0) {
597                                         nostdlib++;
598                                         nostartfiles++;
599                                 } else if (strcmp(argv[i], "-nostartfiles") == 0)
600                                         nostartfiles = 1;
plunky
1.202
601                                 else if (strcmp(argv[i], "-nodefaultlibs") == 0)
602                                         nostdlib++;
ragge
1.128
603                                 else
604                                         goto passa;
605                                 break;
606
607                         case 'p':
608                                 if (strcmp(argv[i], "-pg") == 0 ||
609                                     strcmp(argv[i], "-p") == 0)
610                                         pgflag++;
611                                 else if (strcmp(argv[i], "-pthread") == 0)
612                                         pthreads++;
613                                 else if (strcmp(argv[i], "-pipe") == 0)
614                                         /* NOTHING YET */;
gmcgarry
1.144
615                                 else if (strcmp(argv[i], "-pedantic") == 0)
616                                         /* NOTHING YET */;
ragge
1.162
617                                 else if (strcmp(argv[i],
618                                     "-print-prog-name=ld") == 0) {
619                                         printf("%s\n"LINKER);
620                                         return 0;
ragge
1.174
621                                 } else if (strcmp(argv[i],
622                                     "-print-multi-os-directory") == 0) {
623                                         printf("%s\n"MULTIOSDIR);
624                                         return 0;
ragge
1.162
625                                 } else
ragge
1.128
626                                         errorx(1"unknown option %s"argv[i]);
627                                 break;
628
gmcgarry
1.145
629                         case 'r':
630                                 rflag = 1;
631                                 break;
632
ragge
1.128
633                         case 'x':
634                                 t = &argv[i][2];
635                                 if (*t == 0)
636                                         t = argv[++i];
637                                 if (strcmp(t"c") == 0)
638                                         xcflag = 1/* default */
639                                 else if (strcmp(t"assembler-with-cpp") == 0)
640                                         ascpp = 1;
641                                 else if (strcmp(t"c++") == 0)
642                                         cxxflag++;
643                                 else
644                                         xlist[xnum++] = argv[i];
645                                 break;
646                         case 't':
647                                 tflag++;
648                                 break;
649                         case 'S':
650                                 sflag++;
651                                 cflag++;
652                                 break;
653                         case 'o':
654                                 if (outfile)
655                                         errorx(8"too many -o");
656                                 outfile = argv[++i];
657                                 break;
658                         case 'O':
plunky
1.203
659                                 if (argv[i][2] == '\0')
660                                         Oflag++;
661                                 else if (argv[i][3] == '\0' && isdigit((unsigned char)argv[i][2]))
662                                         Oflag = argv[i][2] - '0';
plunky
1.211
663                                 else if (argv[i][3] == '\0' && argv[i][2] == 's')
664                                         Oflag = 1;      /* optimize for space only */
ragge
1.128
665                                 else
plunky
1.203
666                                         error("unknown option %s"argv[i]);
ragge
1.128
667                                 break;
668                         case 'E':
669                                 Eflag++;
670                                 break;
671                         case 'P':
672                                 pflag++;
673                                 *pv++ = argv[i];
674                         case 'c':
gmcgarry
1.172
675 #ifdef os_darwin
676                                 if (strcmp(argv[i], "-compatibility_version") == 0) {
677                                         llist[nl++] = argv[i];
678                                         llist[nl++] = argv[++i];
679                                 } else if (strcmp(argv[i], "-current_version") == 0) {
680                                         llist[nl++] = argv[i];
681                                         llist[nl++] = argv[++i];
682                                 } else
683 #endif
684                                         cflag++;
ragge
1.128
685                                 break;
686 #if 0
687                         case '2':
688                                 if(argv[i][2] == '\0')
689                                         pref = "/lib/crt2.o";
690                                 else {
691                                         pref = "/lib/crt20.o";
692                                 }
693                                 break;
694 #endif
695                         case 'C':
gmcgarry
1.163
696                                 cpplist[ncpp++] = argv[i];
ragge
1.128
697                                 break;
698                         case 'D':
699                         case 'I':
700                         case 'U':
701                                 *pv++ = argv[i];
plunky
1.207
702                                 if (argv[i][2] == '\0')
ragge
1.128
703                                         *pv++ = argv[++i];
704                                 if (pv >= ptemp+MAXOPT) {
705                                         error("Too many DIU options");
706                                         --pv;
707                                 }
708                                 break;
709
710                         case 'M':
711                                 Mflag++;
712                                 break;
713
714                         case 'd':
gmcgarry
1.144
715 #ifdef os_darwin
716                                 if (strcmp(argv[i], "-dynamiclib") == 0) {
717                                         shared = 1;
718                                 } else
719 #endif
ragge
1.128
720                                 break;
721                         case 'v':
722                                 printf("%s\n"VERSSTR);
723                                 vflag++;
724                                 break;
725
726                         case 's':
gmcgarry
1.144
727 #ifndef os_darwin
728                                 if (strcmp(argv[i], "-shared") == 0) {
ragge
1.128
729                                         shared = 1;
gmcgarry
1.144
730                                 } else
731 #endif
732                                 if (strcmp(argv[i], "-static") == 0) {
733                                         Bstatic = 1;
plunky
1.189
734                                 } else if (strcmp(argv[i], "-symbolic") == 0) {
735                                         llist[nl++] = "-Bsymbolic";
ragge
1.128
736                                 } else if (strncmp(argv[i], "-std"4) == 0) {
ragge
1.190
737                                         if (strcmp(&argv[i][5], "gnu99") == 0 ||
ragge
1.198
738                                             strcmp(&argv[i][5], "gnu9x") == 0)
739                                                 xgnu99 = 1;
740                                         if (strcmp(&argv[i][5], "gnu89") == 0)
741                                                 xgnu89 = 1;
ragge
1.128
742                                 } else
743                                         goto passa;
744                                 break;
745                         }
746                 } else {
747                 passa:
748                         t = argv[i];
749                         if (*argv[i] == '-' && argv[i][1] == 'L')
750                                 ;
ragge
1.198
751                         else if ((cxxsuf(getsufp(t)) && cxxflag) ||
752                             (c=getsuf(t))=='c' || c=='S' || c=='i' ||
ragge
1.128
753                             c=='s'|| Eflag || xcflag) {
754                                 clist[nc++] = t;
755                                 if (nc>=MAXFIL) {
756                                         error("Too many source files");
757                                         exit(1);
758                                 }
759                         }
760
761                         /* Check for duplicate .o files. */
762                         for (j = getsuf(t) == 'o' ? 0 : nlj < nlj++) {
763                                 if (strcmp(llist[j], t) == 0)
764                                         break;
765                         }
gmcgarry
1.150
766                         if ((c=getsuf(t))!='c' && c!='S' &&
ragge
1.212
767                             c!='s' && c!='i' && j==nl &&
768                             !(cxxsuf(getsufp(t)) && cxxflag)) {
ragge
1.128
769                                 llist[nl++] = t;
770                                 if (nl >= MAXLIB) {
771                                         error("Too many object/library files");
772                                         exit(1);
773                                 }
774                                 if (getsuf(t)=='o')
775                                         nxo++;
776                         }
777                 }
778         }
779         /* Sanity checking */
780         if (nc == 0 && nl == 0)
781                 errorx(8"no input files");
782         if (outfile && (cflag || sflag || Eflag) && nc > 1)
783                 errorx(8"-o given with -c || -E || -S and more than one file");
784         if (outfile && clist[0] && strcmp(outfileclist[0]) == 0)
785                 errorx(8"output file will be clobbered");
gmcgarry
1.150
786         if (nc==0)
ragge
1.128
787                 goto nocom;
788         if (pflag==0) {
789                 if (!sflag)
790                         tmp3 = gettmp();
791                 tmp4 = gettmp();
792         }
793         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
794                 signal(SIGINTidexit);
795         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
796                 signal(SIGTERMidexit);
797 #ifdef MULTITARGET
plunky
1.186
798         pass0 = cat(LIBEXECDIR "/ccom_"mach);
ragge
1.128
799 #endif
800         pvt = pv;
801         for (i=0i<nci++) {
802                 /*
803                  * C preprocessor
804                  */
805                 if (nc>1 && !Eflag)
806                         printf("%s:\n"clist[i]);
807                 onlyas = 0;
808                 assource = tmp3;
809                 if (getsuf(clist[i])=='S')
810                         ascpp = 1;
811                 if (getsuf(clist[i])=='i') {
812                         if(Eflag)
813                                 continue;
814                         goto com;
815                 } else if (ascpp) {
816                         onlyas = 1;
817                 } else if (getsuf(clist[i])=='s') {
818                         assource = clist[i];
819                         goto assemble;
820                 }
821                 if (pflag)
822                         tmp4 = setsuf(clist[i], 'i');
823                 na = 0;
824                 av[na++] = "cpp";
825                 if (vflag)
826                         av[na++] = "-v";
827                 av[na++] = "-D__PCC__=" MKS(PCC_MAJOR);
828                 av[na++] = "-D__PCC_MINOR__=" MKS(PCC_MINOR);
829                 av[na++] = "-D__PCC_MINORMINOR__=" MKS(PCC_MINORMINOR);
gmcgarry
1.156
830 #ifndef os_win32
ragge
1.155
831 #ifdef GCC_COMPAT
832                 av[na++] = "-D__GNUC__=4";
833                 av[na++] = "-D__GNUC_MINOR__=3";
834                 av[na++] = "-D__GNUC_PATCHLEVEL__=1";
ragge
1.198
835                 if (xgnu89)
plunky
1.208
836                         av[na++] = "-D__GNUC_GNU_INLINE__";
ragge
1.191
837                 else
plunky
1.208
838                         av[na++] = "-D__GNUC_STDC_INLINE__";
ragge
1.170
839 #endif
840 #endif
ragge
1.166
841                 av[na++] = "-D__VERSION__=" MKS(VERSSTR);
ragge
1.167
842                 av[na++] = "-D__SCHAR_MAX__=" MKS(MAX_CHAR);
843                 av[na++] = "-D__SHRT_MAX__=" MKS(MAX_SHORT);
844                 av[na++] = "-D__INT_MAX__=" MKS(MAX_INT);
845                 av[na++] = "-D__LONG_MAX__=" MKS(MAX_LONG);
846                 av[na++] = "-D__LONG_LONG_MAX__=" MKS(MAX_LONGLONG);
plunky
1.214
847                 if (freestanding)
848                         av[na++] = "-D__STDC_HOSTED__=0";
849                 else
850                         av[na++] = "-D__STDC_HOSTED__=1";
ragge
1.212
851                 if (cxxflag)
852                         av[na++] = "-D__cplusplus";
plunky
1.209
853                 if (xuchar)
plunky
1.196
854                         av[na++] = "-D__CHAR_UNSIGNED__";
ragge
1.128
855                 if (ascpp)
856                         av[na++] = "-D__ASSEMBLER__";
857                 if (sspflag)
plunky
1.208
858                         av[na++] = "-D__SSP__";
ragge
1.128
859                 if (pthreads)
860                         av[na++] = "-D_PTHREADS";
861                 if (Mflag)
862                         av[na++] = "-M";
ragge
1.160
863                 if (Oflag)
864                         av[na++] = "-D__OPTIMIZE__";
865 #ifdef GCC_COMPAT
866                 av[na++] = "-D__REGISTER_PREFIX__=" REGISTER_PREFIX;
867                 av[na++] = "-D__USER_LABEL_PREFIX__=" USER_LABEL_PREFIX;
868 #endif
ragge
1.128
869                 for (j = 0cppadd[j]; j++)
870                         av[na++] = cppadd[j];
gmcgarry
1.163
871                 for (j = 0j < ncppj++)
872                         av[na++] = cpplist[j];
gmcgarry
1.149
873                 av[na++] = "-D__STDC_ISO_10646__=200009L";
ragge
1.157
874                 av[na++] = "-D__WCHAR_TYPE__=" WCT;
875                 av[na++] = "-D__SIZEOF_WCHAR_T__=" MKS(WCHAR_SIZE);
876                 av[na++] = "-D__WCHAR_MAX__=" WCM;
plunky
1.192
877                 av[na++] = "-D__WINT_TYPE__=" PCC_WINT_TYPE;
878                 av[na++] = "-D__SIZE_TYPE__=" PCC_SIZE_TYPE;
ragge
1.161
879                 av[na++] = "-D__PTRDIFF_TYPE__=" PCC_PTRDIFF_TYPE;
gmcgarry
1.142
880                 av[na++] = "-D__SIZEOF_WINT_T__=4";
plunky
1.201
881 #if defined(os_darwin) || defined(os_netbsd)
882                 av[na++] = "-D__FLT_RADIX__=2";
883                 av[na++] = "-D__FLT_DIG__=6";
884                 av[na++] = "-D__FLT_EPSILON__=1.19209290e-07F";
885                 av[na++] = "-D__FLT_MANT_DIG__=24";
886                 av[na++] = "-D__FLT_MAX_10_EXP__=38";
887                 av[na++] = "-D__FLT_MAX_EXP__=128";
888                 av[na++] = "-D__FLT_MAX__=3.40282347e+38F";
889                 av[na++] = "-D__FLT_MIN_10_EXP__=(-37)";
890                 av[na++] = "-D__FLT_MIN_EXP__=(-125)";
gmcgarry
1.171
891                 av[na++] = "-D__FLT_MIN__=1.17549435e-38F";
plunky
1.201
892                 av[na++] = "-D__DBL_DIG__=15";
893                 av[na++] = "-D__DBL_EPSILON__=2.2204460492503131e-16";
894                 av[na++] = "-D__DBL_MANT_DIG__=53";
895                 av[na++] = "-D__DBL_MAX_10_EXP__=308";
896                 av[na++] = "-D__DBL_MAX_EXP__=1024";
897                 av[na++] = "-D__DBL_MAX__=1.7976931348623157e+308";
898                 av[na++] = "-D__DBL_MIN_10_EXP__=(-307)";
899                 av[na++] = "-D__DBL_MIN_EXP__=(-1021)";
gmcgarry
1.171
900                 av[na++] = "-D__DBL_MIN__=2.2250738585072014e-308";
plunky
1.201
901 #if defined(mach_i386) || defined(mach_amd64)
902                 av[na++] = "-D__LDBL_DIG__=18";
903                 av[na++] = "-D__LDBL_EPSILON__=1.08420217248550443401e-19L";
904                 av[na++] = "-D__LDBL_MANT_DIG__=64";
905                 av[na++] = "-D__LDBL_MAX_10_EXP__=4932";
906                 av[na++] = "-D__LDBL_MAX_EXP__=16384";
907                 av[na++] = "-D__LDBL_MAX__=1.18973149535723176502e+4932L";
908                 av[na++] = "-D__LDBL_MIN_10_EXP__=(-4931)";
909                 av[na++] = "-D__LDBL_MIN_EXP__=(-16381)";
gmcgarry
1.171
910                 av[na++] = "-D__LDBL_MIN__=3.36210314311209350626e-4932L";
plunky
1.201
911 #else
912                 av[na++] = "-D__LDBL_DIG__=15";
913                 av[na++] = "-D__LDBL_EPSILON__=2.2204460492503131e-16";
914                 av[na++] = "-D__LDBL_MANT_DIG__=53";
915                 av[na++] = "-D__LDBL_MAX_10_EXP__=308";
916                 av[na++] = "-D__LDBL_MAX_EXP__=1024";
917                 av[na++] = "-D__LDBL_MAX__=1.7976931348623157e+308";
918                 av[na++] = "-D__LDBL_MIN_10_EXP__=(-307)";
919                 av[na++] = "-D__LDBL_MIN_EXP__=(-1021)";
920                 av[na++] = "-D__LDBL_MIN__=2.2250738585072014e-308";
921 #endif
gmcgarry
1.171
922 #endif
ragge
1.128
923 #ifdef MULTITARGET
924                 for (k = 0cppmds[k].machk++) {
925                         if (strcmp(cppmds[k].machmach) != 0)
926                                 continue;
927                         for (j = 0cppmds[k].cppmdadd[j]; j++)
928                                 av[na++] = cppmds[k].cppmdadd[j];
929                         break;
930                 }
931 #else
932                 for (j = 0cppmdadd[j]; j++)
933                         av[na++] = cppmdadd[j];
934 #endif
935                 if (tflag)
936                         av[na++] = "-t";
937                 for(pv=ptemppv <pvtpv++)
938                         av[na++] = *pv;
gmcgarry
1.153
939                 if (!nostdinc) {
plunky
1.185
940                         av[na++] = "-S"av[na++] = cat(sysrootaltincdir);
941                         av[na++] = "-S"av[na++] = cat(sysrootincdir);
plunky
1.200
942 #ifdef PCCINCDIR
ragge
1.198
943                         if (cxxflag)
944                                 av[na++] = "-S"av[na++] = pxxincdir;
plunky
1.187
945                         av[na++] = "-S"av[na++] = pccincdir;
plunky
1.200
946 #endif
gmcgarry
1.153
947                 }
ragge
1.128
948                 if (idirafter) {
949                         av[na++] = "-I";
950                         av[na++] = idirafter;
951                 }
952                 av[na++] = clist[i];
953                 if (!Eflag && !Mflag)
954                         av[na++] = tmp4;
ragge
1.141
955                 if ((Eflag || Mflag) && outfile)
ragge
1.128
956                          ermfile = av[na++] = outfile;
957                 av[na++]=0;
gmcgarry
1.140
958                 if (callsys(passpav)) {
959                         exfail++;
960                         eflag++;
961                 }
ragge
1.128
962                 if (Eflag || Mflag)
963                         continue;
964                 if (onlyas) {
965                         assource = tmp4;
966