Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20110814150702

Diff

Diff from 1.198 to:

Annotations

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

Annotated File View

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