Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:plunky:20110831104049

Diff

Diff from 1.208 to:

Annotations

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

Annotated File View

plunky
1.208
1 /*      $Id: cc.c,v 1.208 2011/08/31 10:40:49 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
73 #ifdef WIN32
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);
149 #ifdef WIN32
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;
169 int     pflag;
170 int     sflag;
171 int     cflag;
172 int     eflag;
173 int     gflag;
gmcgarry
1.145
174 int     rflag;
ragge
1.128
175 int     vflag;
176 int     tflag;
177 int     Eflag;
178 int     Oflag;
179 int     kflag;  /* generate PIC/pic code */
180 #define F_PIC   1
181 #define F_pic   2
182 int     Mflag;  /* dependencies only */
183 int     pgflag;
184 int     exfail;
185 int     Xflag;
186 int     Wallflag;
187 int     Wflag;
188 int     nostartfilesBstaticshared;
189 int     nostdincnostdlib;
190 int     onlyas;
191 int     pthreads;
ragge
1.198
192 int     xcflagxgnu89xgnu99;
ragge
1.128
193 int     ascpp;
plunky
1.196
194 #ifdef CHAR_UNSIGNED
195 int     funsigned_char = 1;
196 #else
197 int     funsigned_char = 0;
198 #endif
ragge
1.198
199 int     cxxflag;
ragge
1.128
200
201 char    *passp = LIBEXECDIR PREPROCESSOR;
202 char    *pass0 = LIBEXECDIR COMPILER;
ragge
1.198
203 char    *passxx0 = LIBEXECDIR "c++com";
ragge
1.128
204 char    *as = ASSEMBLER;
205 char    *ld = LINKER;
ragge
1.175
206 char    *sysroot;
ragge
1.128
207 char *cppadd[] = CPPADD;
208 #ifdef DYNLINKER
209 char *dynlinker[] = DYNLINKER;
210 #endif
211 #ifdef CRT0FILE
212 char *crt0file = CRT0FILE;
213 #endif
214 #ifdef CRT0FILE_PROFILE
215 char *crt0file_profile = CRT0FILE_PROFILE;
216 #endif
217 #ifdef STARTFILES
218 char *startfiles[] = STARTFILES;
219 char *endfiles[] = ENDFILES;
220 #endif
221 #ifdef STARTFILES_T
222 char *startfiles_T[] = STARTFILES_T;
223 char *endfiles_T[] = ENDFILES_T;
224 #endif
225 #ifdef STARTFILES_S
226 char *startfiles_S[] = STARTFILES_S;
227 char *endfiles_S[] = ENDFILES_S;
228 #endif
229 #ifdef MULTITARGET
230 char *mach = DEFMACH;
231 struct cppmd {
232         char *mach;
233         char *cppmdadd[MAXCPPMDARGS];
234 };
235
236 struct cppmd cppmds[] = CPPMDADDS;
237 #else
238 char *cppmdadd[] = CPPMDADD;
239 #endif
240 #ifdef LIBCLIBS
241 char *libclibs[] = LIBCLIBS;
242 #else
243 char *libclibs[] = { "-lc"NULL };
244 #endif
245 #ifdef LIBCLIBS_PROFILE
246 char *libclibs_profile[] = LIBCLIBS_PROFILE;
247 #else
248 char *libclibs_profile[] = { "-lc_p"NULL };
249 #endif
250 #ifndef STARTLABEL
251 #define STARTLABEL "__start"
252 #endif
253 char *incdir = STDINC;
gmcgarry
1.153
254 char *altincdir = INCLUDEDIR "pcc/";
gmcgarry
1.136
255 char *libdir = LIBDIR;
plunky
1.200
256 #ifdef PCCINCDIR
ragge
1.128
257 char *pccincdir = PCCINCDIR;
ragge
1.198
258 char *pxxincdir = PCCINCDIR "/c++";
plunky
1.200
259 #endif
260 #ifdef PCCLIBDIR
ragge
1.128
261 char *pcclibdir = PCCLIBDIR;
plunky
1.200
262 #endif
ragge
1.164
263 #ifdef mach_amd64
264 int amd64_i386;
265 #endif
ragge
1.128
266
267 /* handle gcc warning emulations */
268 struct Wflags {
269         char *name;
270         int flags;
271 #define INWALL          1
272 #define NEGATIVE        2
273 Wflags[] = {
gmcgarry
1.154
274         { "-Wtruncate"0 },
275         { "-Wno-truncate"NEGATIVE },
plunky
1.194
276         { "-Wstrict-prototypes"0 },
277         { "-Wno-strict-prototypes"NEGATIVE },
278         { "-Wmissing-prototypes"0 },
279         { "-Wno-missing-prototypes"NEGATIVE },
280         { "-Wimplicit-int"0 },
281         { "-Wno-implicit-int"NEGATIVE },
282         { "-Wimplicit-function-declaration"0 },
283         { "-Wno-implicit-function-declaration"NEGATIVE },
ragge
1.128
284         { "-Wshadow"0 },
285         { "-Wno-shadow"NEGATIVE },
286         { "-Wpointer-sign"INWALL },
287         { "-Wno-pointer-sign"NEGATIVE },
288         { "-Wsign-compare"0 },
289         { "-Wno-sign-compare"NEGATIVE },
290         { "-Wunknown-pragmas"INWALL },
291         { "-Wno-unknown-pragmas"NEGATIVE },
292         { "-Wunreachable-code"0 },
293         { "-Wno-unreachable-code"NEGATIVE },
294         { 00 },
295 };
296
297 #define SZWFL   (sizeof(Wflags)/sizeof(Wflags[0]))
298
ragge
1.158
299 #ifndef USHORT
300 /* copied from mip/manifest.h */
301 #define USHORT          5
302 #define INT             6
303 #define UNSIGNED        7
304 #endif
305
ragge
1.157
306 /*
307  * Wide char defines.
308  */
309 #if WCHAR_TYPE == USHORT
310 #define WCT "short unsigned int"
311 #define WCM "65535U"
ragge
1.158
312 #if WCHAR_SIZE != 2
313 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
314 #endif
ragge
1.157
315 #elif WCHAR_TYPE == INT
316 #define WCT "int"
317 #define WCM "2147483647"
ragge
1.158
318 #if WCHAR_SIZE != 4
319 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
320 #endif
ragge
1.157
321 #elif WCHAR_TYPE == UNSIGNED
322 #define WCT "unsigned int"
ragge
1.158
323 #define WCM "4294967295U"
324 #if WCHAR_SIZE != 4
325 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
326 #endif
327 #else
328 #error WCHAR_TYPE not defined or invalid
ragge
1.157
329 #endif
330
ragge
1.160
331 #ifdef GCC_COMPAT
332 #ifndef REGISTER_PREFIX
333 #define REGISTER_PREFIX ""
334 #endif
335 #ifndef USER_LABEL_PREFIX
336 #define USER_LABEL_PREFIX ""
337 #endif
338 #endif
339
plunky
1.192
340 #ifndef PCC_WINT_TYPE
341 #define PCC_WINT_TYPE "unsigned int"
342 #endif
343
344 #ifndef PCC_SIZE_TYPE
345 #define PCC_SIZE_TYPE "unsigned long"
346 #endif
347
ragge
1.161
348 #ifndef PCC_PTRDIFF_TYPE
349 #define PCC_PTRDIFF_TYPE "long int"
350 #endif
351
ragge
1.128
352 int
353 main(int argcchar *argv[])
354 {
355         struct Wflags *Wf;
356         char *t, *u;
357         char *assource;
358         char **pv, *ptemp[MAXOPT], **pvt;
gmcgarry
1.163
359         int ncnlnasncppijcnxona;
ragge
1.128
360 #ifdef MULTITARGET
361         int k;
362 #endif
363
ragge
1.198
364         if (strcmp(argv[0], "p++") == 0) {
365                 cxxflag = 1;
366                 pass0 = passxx0;
367         }
368
ragge
1.128
369 #ifdef WIN32
370         /* have to prefix path early.  -B may override */
371         incdir = win32pathsubst(incdir);
gmcgarry
1.153
372         altincdir = win32pathsubst(altincdir);
gmcgarry
1.136
373         libdir = win32pathsubst(libdir);
plunky
1.200
374 #ifdef PCCINCDIR
ragge
1.128
375         pccincdir = win32pathsubst(pccincdir);
plunky
1.199
376         pxxincdir = win32pathsubst(pxxincdir);
plunky
1.200
377 #endif
378 #ifdef PCCLIBDIR
ragge
1.128
379         pcclibdir = win32pathsubst(pcclibdir);
plunky
1.200
380 #endif
ragge
1.128
381         passp = win32pathsubst(passp);
382         pass0 = win32pathsubst(pass0);
gmcgarry
1.180
383 #ifdef STARTFILES
384         for (i = 0startfiles[i] != NULLi++)
385                 startfiles[i] = win32pathsubst(startfiles[i]);
386         for (i = 0endfiles[i] != NULLi++)
387                 endfiles[i] = win32pathsubst(endfiles[i]);
388 #endif
389 #ifdef STARTFILES_T
390         for (i = 0startfiles_T[i] != NULLi++)
391                 startfiles_T[i] = win32pathsubst(startfiles_T[i]);
392         for (i = 0endfiles_T[i] != NULLi++)
393                 endfiles_T[i] = win32pathsubst(endfiles_T[i]);
394 #endif
395 #ifdef STARTFILES_S
396         for (i = 0startfiles_S[i] != NULLi++)
397                 startfiles_S[i] = win32pathsubst(startfiles_S[i]);
398         for (i = 0endfiles_S[i] != NULLi++)
399                 endfiles_S[i] = win32pathsubst(endfiles_S[i]);
400 #endif
ragge
1.128
401 #endif
402
gmcgarry
1.163
403         i = nc = nl = nas = ncpp = nxo = 0;
ragge
1.128
404         pv = ptemp;
405         while(++i < argc) {
406                 if (argv[i][0] == '-') {
407                         switch (argv[i][1]) {
408                         default:
409                                 goto passa;
410 #ifdef notyet
411         /* must add library options first (-L/-l/...) */
412                                 error("unrecognized option `-%c'"argv[i][1]);
413                                 break;
414 #endif
415
416                         case '-'/* double -'s */
ragge
1.130
417                                 if (strcmp(argv[i], "--version") == 0) {
ragge
1.128
418                                         printf("%s\n"VERSSTR);
ragge
1.130
419                                         return 0;
ragge
1.175
420                                 } else if (strncmp(argv[i], "--sysroot="10) == 0) {
421                                         sysroot = argv[i] + 10;
ragge
1.169
422                                 } else if (strcmp(argv[i], "--param") == 0) {
ragge
1.128
423                                         /* NOTHING YET */;
ragge
1.169
424                                         i++; /* ignore arg */
425                                 } else
gmcgarry
1.148
426                                         goto passa;
ragge
1.128
427                                 break;
428
429                         case 'B'/* other search paths for binaries */
ragge
1.175
430                                 add_prefix(argv[i] + 2);
ragge
1.128
431                                 break;
432
433 #ifdef MULTITARGET
434                         case 'b':
435                                 t = &argv[i][2];
436                                 if (*t == '\0' && i + 1 < argc) {
437                                         t = argv[i+1];
438                                         i++;
439                                 }
440                                 if (strncmp(t"?"1) == 0) {
441                                         /* show machine targets */
442                                         printf("Available machine targets:");
443                                         for (j=0cppmds[j].machj++)
444                                                 printf(" %s",cppmds[j].mach);
445                                         printf("\n");
446                                         exit(0);
447                                 }
448                                 for (j=0cppmds[j].machj++)
449                                         if (strcmp(tcppmds[j].mach) == 0) {
450                                                 mach = cppmds[j].mach;
451                                                 break;
452                                         }
453                                 if (cppmds[j].mach == NULL)
454                                         errorx(1"unknown target arch %s"t);
455                                 break;
456 #endif
457
458                         case 'X':
459                                 Xflag++;
460                                 break;
461                         case 'W'/* Ignore (most of) W-flags */
462                                 if (strncmp(argv[i], "-Wl,"4) == 0) {
463                                         /* options to the linker */
464                                         t = &argv[i][4];
465                                         while ((u = strchr(t','))) {
466                                                 *u++ = 0;
467                                                 llist[nl++] = t;
468                                                 t = u;
469                                         }
470                                         llist[nl++] = t;
471                                 } else if (strncmp(argv[i], "-Wa,"4) == 0) {
472                                         /* options to the assembler */
473                                         t = &argv[i][4];
474                                         while ((u = strchr(t','))) {
475                                                 *u++ = 0;
476                                                 aslist[nas++] = t;
477                                                 t = u;
478                                         }
479                                         aslist[nas++] = t;
ragge
1.137
480                                 } else if (strncmp(argv[i], "-Wc,"4) == 0) {
481                                         /* options to ccom */
482                                         t = &argv[i][4];
483                                         while ((u = strchr(t','))) {
484                                                 *u++ = 0;
485                                                 wlist[nw++] = t;
486                                                 t = u;
487                                         }
488                                         wlist[nw++] = t;
ragge
1.128
489                                 } else if (strncmp(argv[i], "-Wp,"4) == 0) {
490                                         /* preprocessor */
gmcgarry
1.163
491                                         t = &argv[i][4];
492                                         while ((u = strchr(t','))) {
493                                                 *u++ = 0;
494                                                 cpplist[ncpp++] = t;
495                                                 t = u;
496                                         }
497                                         cpplist[ncpp++] = t;
plunky
1.193
498                                 } else if (strcmp(argv[i], "-Werror") == 0) {
499                                         wlist[nw++] = argv[i];
ragge
1.128
500                                 } else if (strcmp(argv[i], "-Wall") == 0) {
501                                         Wallflag = 1;
502                                 } else if (strcmp(argv[i], "-WW") == 0) {
503                                         Wflag = 1;
504                                 } else {
505                                         /* check and set if available */
506                                         for (Wf = WflagsWf->nameWf++) {
507                                                 if (strcmp(argv[i], Wf->name))
508                                                         continue;
509                                                 wlist[nw++] = Wf->name;
510                                         }
511                                 }
512                                 break;
513
514                         case 'f'/* GCC compatibility flags */
515                                 if (strcmp(argv[i], "-fPIC") == 0)
516                                         kflag = F_PIC;
517                                 else if (strcmp(argv[i], "-fpic") == 0)
518                                         kflag = F_pic;
ragge
1.195
519                                 else if (strcmp(argv[i], "-ffreestanding") == 0)
520                                         flist[nf++] = argv[i];
ragge
1.128
521                                 else if (strcmp(argv[i],
plunky
1.196
522                                     "-fsigned-char") == 0) {
ragge
1.128
523                                         flist[nf++] = argv[i];
plunky
1.196
524                                         funsigned_char = 0;
525                                 } else if (strcmp(argv[i],
526                                     "-fno-signed-char") == 0) {
ragge
1.128
527                                         flist[nf++] = argv[i];
plunky
1.204
528                                         funsigned_char = 1;
plunky
1.196
529                                 } else if (strcmp(argv[i],
530                                     "-funsigned-char") == 0) {
ragge
1.128
531                                         flist[nf++] = argv[i];
plunky
1.196
532                                         funsigned_char = 1;
533                                 } else if (strcmp(argv[i],
534                                     "-fno-unsigned-char") == 0) {
ragge
1.128
535                                         flist[nf++] = argv[i];
plunky
1.204
536                                         funsigned_char = 0;
plunky
1.196
537                                 } else if (strcmp(argv[i],
ragge
1.128
538                                     "-fstack-protector") == 0) {
539                                         flist[nf++] = argv[i];
540                                         sspflag++;
541                                 } else if (strcmp(argv[i],
542                                     "-fstack-protector-all") == 0) {
543                                         flist[nf++] = argv[i];
544                                         sspflag++;
545                                 } else if (strcmp(argv[i],
546                                     "-fno-stack-protector") == 0) {
547                                         flist[nf++] = argv[i];
548                                         sspflag = 0;
549                                 } else if (strcmp(argv[i],
550                                     "-fno-stack-protector-all") == 0) {
551                                         flist[nf++] = argv[i];
552                                         sspflag = 0;
553                                 }
554                                 /* silently ignore the rest */
555                                 break;
556
557                         case 'g'/* create debug output */
ragge
1.177
558                                 if (argv[i][2] == '0')
559                                         gflag = 0;
560                                 else
561                                         gflag++;
ragge
1.128
562                                 break;
563
564                         case 'i':
565                                 if (strcmp(argv[i], "-isystem") == 0) {
566                                         *pv++ = "-S";
567                                         *pv++ = argv[++i];
568                                 } else if (strcmp(argv[i], "-include") == 0) {
569                                         *pv++ = "-i";
570                                         *pv++ = argv[++i];
571                                 } else if (strcmp(argv[i], "-idirafter") == 0) {
572                                         idirafter = argv[++i];
gmcgarry
1.172
573 #ifdef os_darwin
574                                 } else if (strcmp(argv[i], "-install_name") == 0) {
575                                         llist[nl++] = argv[i];
576                                         llist[nl++] = argv[++i];
577 #endif
ragge
1.128
578                                 } else
579                                         goto passa;
580                                 break;
581
582                         case 'k'/* generate PIC code */
583                                 kflag = F_pic;
584                                 break;
585
586                         case 'm'/* target-dependent options */
ragge
1.164
587 #ifdef mach_amd64
588                                 /* need to call i386 ccom for this */
589                                 if (strcmp(argv[i], "-m32") == 0) {
590                                         pass0 = LIBEXECDIR "/ccom_i386";
591                                         amd64_i386 = 1;
592                                         break;
593                                 }
594 #endif
ragge
1.128
595                                 mlist[nm++] = argv[i];
ragge
1.169
596                                 if (argv[i][2] == 0) {
597                                         /* separate second arg */
598                                         /* give also to linker */
599                                         llist[nl++] = argv[i++];
600                                         mlist[nm++] = argv[i];
601                                         llist[nl++] = argv[i];
602                                 }
ragge
1.128
603                                 break;
604
605                         case 'n'/* handle -n flags */
606                                 if (strcmp(argv[i], "-nostdinc") == 0)
607                                         nostdinc++;
608                                 else if (strcmp(argv[i], "-nostdlib") == 0) {
609                                         nostdlib++;
610                                         nostartfiles++;
611                                 } else if (strcmp(argv[i], "-nostartfiles") == 0)
612                                         nostartfiles = 1;
plunky
1.202
613                                 else if (strcmp(argv[i], "-nodefaultlibs") == 0)
614                                         nostdlib++;
ragge
1.128
615                                 else
616                                         goto passa;
617                                 break;
618
619                         case 'p':
620                                 if (strcmp(argv[i], "-pg") == 0 ||
621                                     strcmp(argv[i], "-p") == 0)
622                                         pgflag++;
623                                 else if (strcmp(argv[i], "-pthread") == 0)
624                                         pthreads++;
625                                 else if (strcmp(argv[i], "-pipe") == 0)
626                                         /* NOTHING YET */;
gmcgarry
1.144
627                                 else if (strcmp(argv[i], "-pedantic") == 0)
628                                         /* NOTHING YET */;
ragge
1.162
629                                 else if (strcmp(argv[i],
630                                     "-print-prog-name=ld") == 0) {
631                                         printf("%s\n"LINKER);
632                                         return 0;
ragge
1.174
633                                 } else if (strcmp(argv[i],
634                                     "-print-multi-os-directory") == 0) {
635                                         printf("%s\n"MULTIOSDIR);
636                                         return 0;
ragge
1.162
637                                 } else
ragge
1.128
638                                         errorx(1"unknown option %s"argv[i]);
639                                 break;
640
gmcgarry
1.145
641                         case 'r':
642                                 rflag = 1;
643                                 break;
644
ragge
1.128
645                         case 'x':
646                                 t = &argv[i][2];
647                                 if (*t == 0)
648                                         t = argv[++i];
649                                 if (strcmp(t"c") == 0)
650                                         xcflag = 1/* default */
651                                 else if (strcmp(t"assembler-with-cpp") == 0)
652                                         ascpp = 1;
653                                 else if (strcmp(t"c++") == 0)
654                                         cxxflag++;
655                                 else
656                                         xlist[xnum++] = argv[i];
657                                 break;
658                         case 't':
659                                 tflag++;
660                                 break;
661                         case 'S':
662                                 sflag++;
663                                 cflag++;
664                                 break;
665                         case 'o':
666                                 if (outfile)
667                                         errorx(8"too many -o");
668                                 outfile = argv[++i];
669                                 break;
670                         case 'O':
plunky
1.203
671                                 if (argv[i][2] == '\0')
672                                         Oflag++;
673                                 else if (argv[i][3] == '\0' && isdigit((unsigned char)argv[i][2]))
674                                         Oflag = argv[i][2] - '0';
ragge
1.128
675                                 else
plunky
1.203
676                                         error("unknown option %s"argv[i]);
ragge
1.128
677                                 break;
678                         case 'E':
679                                 Eflag++;
680                                 break;
681                         case 'P':
682                                 pflag++;
683                                 *pv++ = argv[i];
684                         case 'c':
gmcgarry
1.172
685 #ifdef os_darwin
686                                 if (strcmp(argv[i], "-compatibility_version") == 0) {
687                                         llist[nl++] = argv[i];
688                                         llist[nl++] = argv[++i];
689                                 } else if (strcmp(argv[i], "-current_version") == 0) {
690                                         llist[nl++] = argv[i];
691                                         llist[nl++] = argv[++i];
692                                 } else
693 #endif
694                                         cflag++;
ragge
1.128
695                                 break;
696 #if 0
697                         case '2':
698                                 if(argv[i][2] == '\0')
699                                         pref = "/lib/crt2.o";
700                                 else {
701                                         pref = "/lib/crt20.o";
702                                 }
703                                 break;
704 #endif
705                         case 'C':
gmcgarry
1.163
706                                 cpplist[ncpp++] = argv[i];
ragge
1.128
707                                 break;
708                         case 'D':
709                         case 'I':
710                         case 'U':
711                                 *pv++ = argv[i];
plunky
1.207
712                                 if (argv[i][2] == '\0')
ragge
1.128
713                                         *pv++ = argv[++i];
714                                 if (pv >= ptemp+MAXOPT) {
715                                         error("Too many DIU options");
716                                         --pv;
717                                 }
718                                 break;
719
720                         case 'M':
721                                 Mflag++;
722                                 break;
723
724                         case 'd':
gmcgarry
1.144
725 #ifdef os_darwin
726                                 if (strcmp(argv[i], "-dynamiclib") == 0) {
727                                         shared = 1;
728                                 } else
729 #endif
ragge
1.128
730                                 break;
731                         case 'v':
732                                 printf("%s\n"VERSSTR);
733                                 vflag++;
734                                 break;
735
736                         case 's':
gmcgarry
1.144
737 #ifndef os_darwin
738                                 if (strcmp(argv[i], "-shared") == 0) {
ragge
1.128
739                                         shared = 1;
gmcgarry
1.144
740                                 } else
741 #endif
742                                 if (strcmp(argv[i], "-static") == 0) {
743                                         Bstatic = 1;
plunky
1.189
744                                 } else if (strcmp(argv[i], "-symbolic") == 0) {
745                                         llist[nl++] = "-Bsymbolic";
ragge
1.128
746                                 } else if (strncmp(argv[i], "-std"4) == 0) {
ragge
1.190
747                                         if (strcmp(&argv[i][5], "gnu99") == 0 ||
ragge
1.198
748                                             strcmp(&argv[i][5], "gnu9x") == 0)
749                                                 xgnu99 = 1;
750                                         if (strcmp(&argv[i][5], "gnu89") == 0)
751                                                 xgnu89 = 1;
ragge
1.128
752                                 } else
753                                         goto passa;
754                                 break;
755                         }
756                 } else {
757                 passa:
758                         t = argv[i];
759                         if (*argv[i] == '-' && argv[i][1] == 'L')
760                                 ;
ragge
1.198
761                         else if ((cxxsuf(getsufp(t)) && cxxflag) ||
762                             (c=getsuf(t))=='c' || c=='S' || c=='i' ||
ragge
1.128
763                             c=='s'|| Eflag || xcflag) {
764                                 clist[nc++] = t;
765                                 if (nc>=MAXFIL) {
766                                         error("Too many source files");
767                                         exit(1);
768                                 }
769                         }
770
771                         /* Check for duplicate .o files. */
772                         for (j = getsuf(t) == 'o' ? 0 : nlj < nlj++) {
773                                 if (strcmp(llist[j], t) == 0)
774                                         break;
775                         }
gmcgarry
1.150
776                         if ((c=getsuf(t))!='c' && c!='S' &&
777                             c!='s' && c!='i' && j==nl) {
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.196
856                 if (funsigned_char)
857                         av[na++] = "-D__CHAR_UNSIGNED__";
ragge
1.128
858                 if (ascpp)
859                         av[na++] = "-D__ASSEMBLER__";
860                 if (sspflag)
plunky
1.208
861                         av[na++] = "-D__SSP__";
ragge
1.128
862                 if (pthreads)
863                         av[na++] = "-D_PTHREADS";
864                 if (Mflag)
865                         av[na++] = "-M";
ragge
1.160
866                 if (Oflag)
867                         av[na++] = "-D__OPTIMIZE__";
868 #ifdef GCC_COMPAT
869                 av[na++] = "-D__REGISTER_PREFIX__=" REGISTER_PREFIX;
870                 av[na++] = "-D__USER_LABEL_PREFIX__=" USER_LABEL_PREFIX;
871 #endif
ragge
1.128
872                 for (j = 0cppadd[j]; j++)
873                         av[na++] = cppadd[j];
gmcgarry
1.163
874                 for (j = 0j < ncppj++)
875                         av[na++] = cpplist[j];
gmcgarry
1.149
876                 av[na++] = "-D__STDC_ISO_10646__=200009L";
ragge
1.157
877                 av[na++] = "-D__WCHAR_TYPE__=" WCT;
878                 av[na++] = "-D__SIZEOF_WCHAR_T__=" MKS(WCHAR_SIZE);
879                 av[na++] = "-D__WCHAR_MAX__=" WCM;
plunky
1.192
880                 av[na++] = "-D__WINT_TYPE__=" PCC_WINT_TYPE;
881                 av[na++] = "-D__SIZE_TYPE__=" PCC_SIZE_TYPE;
ragge
1.161
882                 av[na++] = "-D__PTRDIFF_TYPE__=" PCC_PTRDIFF_TYPE;
gmcgarry
1.142
883                 av[na++] = "-D__SIZEOF_WINT_T__=4";
plunky
1.201
884 #if defined(os_darwin) || defined(os_netbsd)
885                 av[na++] = "-D__FLT_RADIX__=2";
886                 av[na++] = "-D__FLT_DIG__=6";
887                 av[na++] = "-D__FLT_EPSILON__=1.19209290e-07F";
888                 av[na++] = "-D__FLT_MANT_DIG__=24";
889                 av[na++] = "-D__FLT_MAX_10_EXP__=38";
890                 av[na++] = "-D__FLT_MAX_EXP__=128";
891                 av[na++] = "-D__FLT_MAX__=3.40282347e+38F";
892                 av[na++] = "-D__FLT_MIN_10_EXP__=(-37)";
893                 av[na++] = "-D__FLT_MIN_EXP__=(-125)";
gmcgarry
1.171
894                 av[na++] = "-D__FLT_MIN__=1.17549435e-38F";
plunky
1.201
895                 av[na++] = "-D__DBL_DIG__=15";
896                 av[na++] = "-D__DBL_EPSILON__=2.2204460492503131e-16";
897                 av[na++] = "-D__DBL_MANT_DIG__=53";
898                 av[na++] = "-D__DBL_MAX_10_EXP__=308";
899                 av[na++] = "-D__DBL_MAX_EXP__=1024";
900                 av[na++] = "-D__DBL_MAX__=1.7976931348623157e+308";
901                 av[na++] = "-D__DBL_MIN_10_EXP__=(-307)";
902                 av[na++] = "-D__DBL_MIN_EXP__=(-1021)";
gmcgarry
1.171
903                 av[na++] = "-D__DBL_MIN__=2.2250738585072014e-308";
plunky
1.201
904 #if defined(mach_i386) || defined(mach_amd64)
905                 av[na++] = "-D__LDBL_DIG__=18";
906                 av[na++] = "-D__LDBL_EPSILON__=1.08420217248550443401e-19L";
907                 av[na++] = "-D__LDBL_MANT_DIG__=64";
908                 av[na++] = "-D__LDBL_MAX_10_EXP__=4932";
909                 av[na++] = "-D__LDBL_MAX_EXP__=16384";
910                 av[na++] = "-D__LDBL_MAX__=1.18973149535723176502e+4932L";
911                 av[na++] = "-D__LDBL_MIN_10_EXP__=(-4931)";
912                 av[na++] = "-D__LDBL_MIN_EXP__=(-16381)";
gmcgarry
1.171
913                 av[na++] = "-D__LDBL_MIN__=3.36210314311209350626e-4932L";
plunky
1.201
914 #else
915                 av[na++] = "-D__LDBL_DIG__=15";
916                 av[na++] = "-D__LDBL_EPSILON__=2.2204460492503131e-16";
917                 av[na++] = "-D__LDBL_MANT_DIG__=53";
918                 av[na++] = "-D__LDBL_MAX_10_EXP__=308";
919                 av[na++] = "-D__LDBL_MAX_EXP__=1024";
920                 av[na++] = "-D__LDBL_MAX__=1.7976931348623157e+308";
921                 av[na++] = "-D__LDBL_MIN_10_EXP__=(-307)";
922                 av[na++] = "-D__LDBL_MIN_EXP__=(-1021)";
923                 av[na++] = "-D__LDBL_MIN__=2.2250738585072014e-308";
924 #endif
gmcgarry
1.171
925 #endif
ragge
1.128
926 #ifdef MULTITARGET
927                 for (k = 0cppmds[k].machk++) {
928                         if (strcmp(cppmds[k].machmach) != 0)
929                                 continue;
930                         for (j = 0cppmds[k].cppmdadd[j]; j++)
931                                 av[na++] = cppmds[k].cppmdadd[j];
932                         break;
933                 }
934 #else
935                 for (j = 0cppmdadd[j]; j++)
936                         av[na++] = cppmdadd[j];
937 #endif
938                 if (tflag)
939                         av[na++] = "-t";
940                 for(pv=ptemppv <pvtpv++)
941                         av[na++] = *pv;
gmcgarry
1.153
942                 if (!nostdinc) {
plunky
1.185
943                         av[na++] = "-S"av[na++] = cat(sysrootaltincdir);
944                         av[na++] = "-S"av[na++] = cat(sysrootincdir);
plunky
1.200
945 #ifdef PCCINCDIR
ragge
1.198
946                         if (cxxflag)
947                                 av[na++] = "-S"av[na++] = pxxincdir;
plunky
1.187
948                         av[na++] = "-S"av[na++] = pccincdir;
plunky
1.200
949 #endif
gmcgarry
1.153
950                 }
ragge
1.128
951                 if (idirafter) {
952                         av[na++] = "-I";
953                         av[na++] = idirafter;
954                 }
955                 av[na++] = clist[i];
956                 if (!Eflag && !Mflag)
957                         av[na++] = tmp4;
ragge
1.141
958                 if ((Eflag || Mflag) && outfile)
ragge
1.128
959                          ermfile = av[na++] = outfile;
960                 av[na++]=0;
gmcgarry
1.140
961                 if (callsys(passpav)) {
962                         exfail++;
963                         eflag++;
964                 }
ragge
1.128
965                 if (Eflag || Mflag)
966                         continue;
967                 if (onlyas) {
968                         assource = tmp4;
969                         goto assemble;
970                 }
971
972                 /*
973                  * C compiler
974                  */
975         com:
976                 na = 0;
ragge
1.198