Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20120802142439

Diff

Diff from 1.221 to:

Annotations

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

Annotated File View

ragge
1.221
1 /*      $Id: cc.c,v 1.221 2012/08/02 14:24:39 ragge Exp $       */
ragge
1.128
2 /*
3  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * Redistributions of source code and documentation must retain the above
10  * copyright notice, this list of conditions and the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditionsand the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * All advertising materials mentioning features or use of this software
15  * must display the following acknowledgement:
16  *      This product includes software developed or owned by Caldera
17  *      International, Inc.
18  * Neither the name of Caldera International, Inc. nor the names of other
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23  * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
27  * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35
36 /*
37  * Front-end to the C compiler.
38  *
39  * Brief description of its syntax:
40  * - Files that end with .c are passed via cpp->ccom->as->ld
41  * - Files that end with .i are passed via ccom->as->ld
plunky
1.206
42  * - Files that end with .S are passed via cpp->as->ld
43  * - Files that end with .s are passed via as->ld
ragge
1.128
44  * - Files that end with .o are passed directly to ld
45  * - Multiple files may be given on the command line.
46  * - Unrecognized options are all sent directly to ld.
47  * -c or -S cannot be combined with -o if multiple files are given.
48  *
49  * This file should be rewritten readable.
50  */
51 #include "config.h"
52
53 #include <sys/types.h>
54 #ifdef HAVE_SYS_WAIT_H
55 #include <sys/wait.h>
56 #endif
57
58 #include <ctype.h>
59 #include <errno.h>
60 #include <fcntl.h>
61 #ifdef HAVE_LIBGEN_H
62 #include <libgen.h>
63 #endif
64 #include <signal.h>
65 #include <stdarg.h>
66 #include <stdio.h>
67 #include <stdlib.h>
68 #include <string.h>
69 #ifdef HAVE_UNISTD_H
70 #include <unistd.h>
71 #endif
72
plunky
1.213
73 #ifdef os_win32
ragge
1.128
74 #include <windows.h>
75 #include <process.h>
76 #include <io.h>
gmcgarry
1.179
77 #define F_OK    0x00
78 #define R_OK    0x04
79 #define W_OK    0x02
80 #define X_OK    R_OK
ragge
1.128
81 #endif
82
83 #include "compat.h"
84
85 #include "ccconfig.h"
ragge
1.167
86 #include "macdefs.h"
ragge
1.218
87
88 #include "xalloc.h"
89 #include "strlist.h"
ragge
1.128
90 /* C command */
91
92 #define MKS(x) _MKS(x)
93 #define _MKS(x) #x
94
95 /*
96  * Many specific definitions, should be declared elsewhere.
97  */
98
99 #ifndef STDINC
100 #define STDINC          "/usr/include/"
101 #endif
102
103 #ifndef LIBDIR
104 #define LIBDIR          "/usr/lib/"
105 #endif
106
107 #ifndef PREPROCESSOR
108 #define PREPROCESSOR    "cpp"
109 #endif
110
111 #ifndef COMPILER
gmcgarry
1.138
112 #define COMPILER        "ccom"
ragge
1.128
113 #endif
114
115 #ifndef ASSEMBLER
116 #define ASSEMBLER       "as"
117 #endif
118
119 #ifndef LINKER
120 #define LINKER          "ld"
121 #endif
122
ragge
1.174
123 #ifndef MULTIOSDIR
124 #define MULTIOSDIR      "."
125 #endif
126
127
ragge
1.128
128 #define MAXFIL 10000
129 #define MAXLIB 10000
130 #define MAXAV  10000
ragge
1.173
131 #define MAXOPT 200
ragge
1.128
132 char    *tmp3;
133 char    *tmp4;
134 char    *outfile, *ermfile;
ragge
1.220
135 static char **lav;
136 static int lac;
ragge
1.175
137 static void add_prefix(const char *);
138 static char *find_file(const char *, int);
plunky
1.183
139 char *copy(const char *, int);
plunky
1.185
140 char *cat(const char *, const char *);
gmcgarry
1.150
141 char *setsuf(char *, char);
ragge
1.198
142 int cxxsuf(char *);
ragge
1.128
143 int getsuf(char *);
ragge
1.198
144 char *getsufp(char *s);
ragge
1.128
145 int main(intchar *[]);
146 void error(char *, ...);
147 void errorx(intchar *, ...);
148 int callsys(char [], char *[]);
149 int cunlink(char *);
150 void dexit(int);
151 void idexit(int);
152 char *gettmp(void);
153 void *ccmalloc(int size);
ragge
1.218
154 void aerror(char *);
ragge
1.219
155 void oerror(char *);
ragge
1.218
156 char *argnxt(char *, char *);
ragge
1.220
157 char *nxtopt(char *o);
plunky
1.213
158 #ifdef os_win32
ragge
1.128
159 char *win32pathsubst(char *);
gmcgarry
1.149
160 char *win32commandline(char *, char *[]);
ragge
1.128
161 #endif
162 char    *av[MAXAV];
163 char    *clist[MAXFIL];
gmcgarry
1.150
164 char    *olist[MAXFIL];
ragge
1.128
165 char    *llist[MAXLIB];
166 char    *aslist[MAXAV];
167 char    *xlist[100];
168 int     xnum;
169 char    *mlist[100];
170 char    *flist[100];
171 char    *wlist[100];
172 char    *idirafter;
173 int     nm;
174 int     nf;
175 int     nw;
176 int     sspflag;
plunky
1.214
177 int     freestanding;
ragge
1.128
178 int     pflag;
179 int     sflag;
180 int     cflag;
181 int     eflag;
182 int     gflag;
gmcgarry
1.145
183 int     rflag;
ragge
1.128
184 int     vflag;
185 int     tflag;
186 int     Eflag;
187 int     Oflag;
188 int     kflag;  /* generate PIC/pic code */
189 #define F_PIC   1
190 #define F_pic   2
ragge
1.216
191 int     MflagMPflagnMfiles/* dependencies only */
192 char    *Mfiles[10];
ragge
1.128
193 int     pgflag;
194 int     exfail;
195 int     Xflag;
196 int     Wallflag;
197 int     Wflag;
198 int     nostartfilesBstaticshared;
199 int     nostdincnostdlib;
200 int     onlyas;
201 int     pthreads;
plunky
1.217
202 int     xasmxcflagxgnu89xgnu99;
ragge
1.128
203 int     ascpp;
plunky
1.196
204 #ifdef CHAR_UNSIGNED
plunky
1.209
205 int     xuchar = 1;
plunky
1.196
206 #else
plunky
1.209
207 int     xuchar = 0;
plunky
1.196
208 #endif
ragge
1.198
209 int     cxxflag;
ragge
1.216
210 int     cppflag;
ragge
1.128
211
212 char    *passp = LIBEXECDIR PREPROCESSOR;
213 char    *pass0 = LIBEXECDIR COMPILER;
ragge
1.212
214 char    *passxx0 = LIBEXECDIR "cxxcom";
ragge
1.128
215 char    *as = ASSEMBLER;
216 char    *ld = LINKER;
ragge
1.175
217 char    *sysroot;
ragge
1.128
218 char *cppadd[] = CPPADD;
219 #ifdef DYNLINKER
220 char *dynlinker[] = DYNLINKER;
221 #endif
222 #ifdef CRT0FILE
223 char *crt0file = CRT0FILE;
224 #endif
225 #ifdef CRT0FILE_PROFILE
226 char *crt0file_profile = CRT0FILE_PROFILE;
227 #endif
228 #ifdef STARTFILES
229 char *startfiles[] = STARTFILES;
230 char *endfiles[] = ENDFILES;
231 #endif
232 #ifdef STARTFILES_T
233 char *startfiles_T[] = STARTFILES_T;
234 char *endfiles_T[] = ENDFILES_T;
235 #endif
236 #ifdef STARTFILES_S
237 char *startfiles_S[] = STARTFILES_S;
238 char *endfiles_S[] = ENDFILES_S;
239 #endif
240 #ifdef MULTITARGET
241 char *mach = DEFMACH;
242 struct cppmd {
243         char *mach;
244         char *cppmdadd[MAXCPPMDARGS];
245 };
246
247 struct cppmd cppmds[] = CPPMDADDS;
248 #else
249 char *cppmdadd[] = CPPMDADD;
250 #endif
251 #ifdef LIBCLIBS
252 char *libclibs[] = LIBCLIBS;
253 #else
254 char *libclibs[] = { "-lc"NULL };
255 #endif
256 #ifdef LIBCLIBS_PROFILE
257 char *libclibs_profile[] = LIBCLIBS_PROFILE;
258 #else
259 char *libclibs_profile[] = { "-lc_p"NULL };
260 #endif
261 #ifndef STARTLABEL
262 #define STARTLABEL "__start"
263 #endif
264 char *incdir = STDINC;
gmcgarry
1.153
265 char *altincdir = INCLUDEDIR "pcc/";
gmcgarry
1.136
266 char *libdir = LIBDIR;
plunky
1.200
267 #ifdef PCCINCDIR
ragge
1.128
268 char *pccincdir = PCCINCDIR;
ragge
1.198
269 char *pxxincdir = PCCINCDIR "/c++";
plunky
1.200
270 #endif
271 #ifdef PCCLIBDIR
ragge
1.128
272 char *pcclibdir = PCCLIBDIR;
plunky
1.200
273 #endif
ragge
1.164
274 #ifdef mach_amd64
275 int amd64_i386;
276 #endif
ragge
1.128
277
ragge
1.218
278 #define match(a,b)      (strcmp(a,b) == 0)
279
ragge
1.128
280 /* handle gcc warning emulations */
281 struct Wflags {
282         char *name;
283         int flags;
284 #define INWALL          1
285 Wflags[] = {
plunky
1.215
286         { "truncate"0 },
287         { "strict-prototypes"0 },
288         { "missing-prototypes"0 },
289         { "implicit-int"INWALL },
290         { "implicit-function-declaration"INWALL },
291         { "shadow"0 },
292         { "pointer-sign"INWALL },
293         { "sign-compare"0 },
294         { "unknown-pragmas"INWALL },
295         { "unreachable-code"0 },
296         { NULL0 },
ragge
1.128
297 };
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.216
352 #ifndef CPPROGNAME
353 #define CPPROGNAME      "cpp"
354 #endif
355
ragge
1.218
356 struct strlist preprocessor_flags;
ragge
1.219
357 struct strlist incdirs;
ragge
1.221
358 struct strlist user_sysincdirs;
359 struct strlist includes;
ragge
1.218
360
ragge
1.128
361 int
362 main(int argcchar *argv[])
363 {
ragge
1.218
364         struct string *s;
ragge
1.128
365         struct Wflags *Wf;
ragge
1.218
366         char *t, *u, *argp;
ragge
1.128
367         char *assource;
gmcgarry
1.163
368         int ncnlnasncppijcnxona;
ragge
1.128
369 #ifdef MULTITARGET
370         int k;
371 #endif
ragge
1.220
372         lav = argv;
373         lac = argc;
ragge
1.128
374
ragge
1.218
375         strlist_init(&preprocessor_flags);
ragge
1.219
376         strlist_init(&incdirs);
ragge
1.221
377         strlist_init(&user_sysincdirs);
378         strlist_init(&includes);
ragge
1.218
379
ragge
1.216
380         if ((t = strrchr(argv[0], '/')))
381                 t = copy(t+10);
382         else
383                 t = argv[0];
384         if (strcmp(t"p++") == 0) {
ragge
1.198
385                 cxxflag = 1;
386                 pass0 = passxx0;
ragge
1.216
387         } else if (strcmp(t"cpp") == 0 || strcmp(tCPPROGNAME) == 0) {
388                 cppflag = 1;
389                 Eflag = 1;
ragge
1.198
390         }
391
plunky
1.213
392 #ifdef os_win32
ragge
1.128
393         /* have to prefix path early.  -B may override */
394         incdir = win32pathsubst(incdir);
gmcgarry
1.153
395         altincdir = win32pathsubst(altincdir);
gmcgarry
1.136
396         libdir = win32pathsubst(libdir);
plunky
1.200
397 #ifdef PCCINCDIR
ragge
1.128
398         pccincdir = win32pathsubst(pccincdir);
plunky
1.199
399         pxxincdir = win32pathsubst(pxxincdir);
plunky
1.200
400 #endif
401 #ifdef PCCLIBDIR
ragge
1.128
402         pcclibdir = win32pathsubst(pcclibdir);
plunky
1.200
403 #endif
ragge
1.128
404         passp = win32pathsubst(passp);
405         pass0 = win32pathsubst(pass0);
gmcgarry
1.180
406 #ifdef STARTFILES
407         for (i = 0startfiles[i] != NULLi++)
408                 startfiles[i] = win32pathsubst(startfiles[i]);
409         for (i = 0endfiles[i] != NULLi++)
410                 endfiles[i] = win32pathsubst(endfiles[i]);
411 #endif
412 #ifdef STARTFILES_T
413         for (i = 0startfiles_T[i] != NULLi++)
414                 startfiles_T[i] = win32pathsubst(startfiles_T[i]);
415         for (i = 0endfiles_T[i] != NULLi++)
416                 endfiles_T[i] = win32pathsubst(endfiles_T[i]);
417 #endif
418 #ifdef STARTFILES_S
419         for (i = 0startfiles_S[i] != NULLi++)
420                 startfiles_S[i] = win32pathsubst(startfiles_S[i]);
421         for (i = 0endfiles_S[i] != NULLi++)
422                 endfiles_S[i] = win32pathsubst(endfiles_S[i]);
423 #endif
ragge
1.128
424 #endif
425
ragge
1.220
426         nc = nl = nas = ncpp = nxo = 0;
427         while (--lac) {
428                 ++lav;
429                 argp = *lav;
430
431                 if (*argp != '-' || match(argp"-"))
432                         goto passa;
433
434                 switch (argp[1]) {
435                 default:
436                         goto passa;
ragge
1.128
437 #ifdef notyet
438         /* must add library options first (-L/-l/...) */
ragge
1.220
439                         oerror(argp);
440                         break;
ragge
1.128
441 #endif
442
ragge
1.220
443                 case '-'/* double -'s */
444                         if (match(argp"--version")) {
445                                 printf("%s\n"VERSSTR);
446                                 return 0;
447                         } else if (strncmp(argp"--sysroot="10) == 0) {
448                                 sysroot = argp + 10;
449                         } else if (strcmp(argp"--param") == 0) {
450                                 /* NOTHING YET */;
451                                 (void)nxtopt(0); /* ignore arg */
452                         } else
453                                 goto passa;
454                         break;
ragge
1.128
455
ragge
1.220
456                 case 'B'/* other search paths for binaries */
457                         add_prefix(argp + 2);
458                         break;
ragge
1.128
459
460 #ifdef MULTITARGET
ragge
1.220
461                 case 'b':
462                         t = &argp[2];
463                         if (*t == '\0' && i + 1 < argc) {
464                                 t = nxtopt(0);
465                         }
466                         if (strncmp(t"?"1) == 0) {
467                                 /* show machine targets */
468                                 printf("Available machine targets:");
469                                 for (j=0cppmds[j].machj++)
470                                         printf(" %s",cppmds[j].mach);
471                                 printf("\n");
472                                 exit(0);
473                         }
474                         for (j=0cppmds[j].machj++)
475                                 if (strcmp(tcppmds[j].mach) == 0) {
476                                         mach = cppmds[j].mach;
477                                         break;
ragge
1.128
478                                 }
ragge
1.220
479                         if (cppmds[j].mach == NULL)
480                                 errorx(1"unknown target arch %s"t);
481                         break;
ragge
1.128
482 #endif
483
ragge
1.220
484                 case 'C':
485                         if (match(argp"-C") || match(argp"-CC"))
486                                 strlist_append(&preprocessor_flagsargp);
487                         else
488                                 oerror(argp);
489                         break;
ragge
1.218
490
ragge
1.220
491                 case 'X':
492                         Xflag++;
493                         break;
494                 case 'W'/* Ignore (most of) W-flags */
495                         if (strncmp(argp"-Wl,"4) == 0) {
496                                 /* options to the linker */
497                                 t = &argp[4];
498                                 while ((u = strchr(t','))) {
499                                         *u++ = 0;
ragge
1.128
500                                         llist[nl++] = t;
ragge
1.220
501                                         t = u;
502                                 }
503                                 llist[nl++] = t;
504                         } else if (strncmp(argp"-Wa,"4) == 0) {
505                                 /* options to the assembler */
506                                 t = &argp[4];
507                                 while ((u = strchr(t','))) {
508                                         *u++ = 0;
ragge
1.128
509                                         aslist[nas++] = t;
ragge
1.220
510                                         t = u;
511                                 }
512                                 aslist[nas++] = t;
513                         } else if (strncmp(argp"-Wc,"4) == 0) {
514                                 /* options to ccom */
515                                 t = &argp[4];
516                                 while ((u = strchr(t','))) {
517                                         *u++ = 0;
ragge
1.137
518                                         wlist[nw++] = t;
ragge
1.220
519                                         t = u;
520                                 }
521                                 wlist[nw++] = t;
522                         } else if ((t = argnxt(argp"-Wp,"))) {
523                                 u = strtok(t",");
524                                 do {
525                                         strlist_append(&preprocessor_flagsu);
526                                 } while ((u = strtok(NULL",")) != NULL);
527                         } else if (strcmp(argp"-Werror") == 0) {
528                                 wlist[nw++] = argp;
529                         } else if (strcmp(argp"-Wall") == 0) {
530                                 Wallflag = 1;
531                         } else if (strcmp(argp"-WW") == 0) {
532                                 Wflag = 1;
533                         } else {
534                                 /* pass through, if supported */
535                                 t = &argp[2];
536                                 if (strncmp(t"no-"3) == 0)
537                                         t += 3;
538                                 if (strncmp(t"error="6) == 0)
539                                         t += 6;
540                                 for (Wf = WflagsWf->nameWf++) {
541                                         if (strcmp(tWf->name) == 0)
542                                                 wlist[nw++] = argp;
ragge
1.128
543                                 }
ragge
1.220
544                         }
545                         break;
ragge
1.128
546
ragge
1.220
547                 case 'f'/* GCC compatibility flags */
548                         if (strcmp(argp"-fPIC") == 0)
549                                 kflag = F_PIC;
550                         else if (strcmp(argp"-fpic") == 0)
551                                 kflag = F_pic;
552                         else if (strcmp(argp"-ffreestanding") == 0)
553                                 freestanding = 1;
ragge
1.221
554                         else if (match(argp"-fsigned-char") ||
555                             match(argp"-fno-unsigned-char"))
ragge
1.220
556                                 xuchar = 0;
ragge
1.221
557                         else if (match(argp"-fno-signed-char") ||
558                             match(argp"-funsigned-char"))
ragge
1.220
559                                 xuchar = 1;
ragge
1.221
560                         else if (strcmp(argp"-fstack-protector") == 0) {
ragge
1.220
561                                 flist[nf++] = argp;
562                                 sspflag++;
ragge
1.221
563                         } else if (strcmp(argp"-fstack-protector-all") == 0) {
ragge
1.220
564                                 flist[nf++] = argp;
565                                 sspflag++;
ragge
1.221
566                         } else if (strcmp(argp"-fno-stack-protector") == 0) {
ragge
1.220
567                                 flist[nf++] = argp;
568                                 sspflag = 0;
ragge
1.221
569                         } else if (strcmp(argp"-fno-stack-protector-all") == 0) {
ragge
1.220
570                                 flist[nf++] = argp;
571                                 sspflag = 0;
572                         }
573                         /* silently ignore the rest */
574                         break;
ragge
1.128
575
ragge
1.220
576                 case 'g'/* create debug output */
577                         if (argp[2] == '0')
578                                 gflag = 0;
579                         else
580                                 gflag++;
581                         break;
ragge
1.128
582
ragge
1.220
583                 case 'D':
584                 case 'U':
ragge
1.221
585                         strlist_append(&preprocessor_flagsargp);
ragge
1.220
586                         if (argp[2] != 0)
ragge
1.219
587                                 break;
ragge
1.221
588                         strlist_append(&preprocessor_flagsnxtopt(argp));
589                         break;
590
591                 case 'I'/* Add include dirs */
592                         strlist_append(&incdirsnxtopt("-I"));
ragge
1.220
593                         break;
ragge
1.219
594
ragge
1.220
595                 case 'i':
ragge
1.221
596                         if (match(argp"-isystem")) {
597                                 strlist_append(&user_sysincdirsnxtopt(0));
598                         } else if (match(argp"-include")) {
599                                 strlist_append(&includesnxtopt(0));
ragge
1.220
600                         } else if (strcmp(argp"-idirafter") == 0) {
601                                 idirafter = nxtopt("-idirafter");
gmcgarry
1.172
602 #ifdef os_darwin
ragge
1.220
603                         } else if (strcmp(argp"-install_name") == 0) {
604                                 llist[nl++] = argp;
605                                 llist[nl++] = nxtopt("-install_name");
gmcgarry
1.172
606 #endif
ragge
1.220
607                         } else
608                                 goto passa;
609                         break;
ragge
1.128
610
ragge
1.220
611                 case 'k'/* generate PIC code */
612                         kflag = F_pic;
613                         break;
ragge
1.128
614
ragge
1.220
615                 case 'm'/* target-dependent options */
ragge
1.164
616 #ifdef mach_amd64
ragge
1.220
617                         /* need to call i386 ccom for this */
618                         if (strcmp(argp"-m32") == 0) {
619                                 pass0 = LIBEXECDIR "/ccom_i386";
620                                 amd64_i386 = 1;
621                                 break;
622                         }
ragge
1.164
623 #endif
ragge
1.220
624                         mlist[nm++] = argp;
625                         if (argp[2] == 0) {
626                                 /* separate second arg */
627                                 /* give also to linker */
628                                 llist[nl++] = argp;
629                                 lav++, lac--;
630                                 mlist[nm++] = lav[0];
631                                 llist[nl++] = lav[0];
632                         }
633                         break;
ragge
1.128
634
ragge
1.220
635                 case 'n'/* handle -n flags */
636                         if (strcmp(argp"-nostdinc") == 0)
637                                 nostdinc++;
638                         else if (strcmp(argp"-nostdlib") == 0) {
639                                 nostdlib++;
640                                 nostartfiles++;
641                         } else if (strcmp(argp"-nostartfiles") == 0)
642                                 nostartfiles = 1;
643                         else if (strcmp(argp"-nodefaultlibs") == 0)
644                                 nostdlib++;
645                         else
646                                 goto passa;
647                         break;
ragge
1.128
648
ragge
1.220
649                 case 'p':
650                         if (strcmp(argp"-pg") == 0 ||
651                             strcmp(argp"-p") == 0)
652                                 pgflag++;
653                         else if (strcmp(argp"-pthread") == 0)
654                                 pthreads++;
655                         else if (strcmp(argp"-pipe") == 0)
656                                 /* NOTHING YET */;
657                         else if (strcmp(argp"-pedantic") == 0)
658                                 /* NOTHING YET */;
659                         else if (strcmp(argp,
660                             "-print-prog-name=ld") == 0) {
661                                 printf("%s\n"LINKER);
662                                 return 0;
663                         } else if (strcmp(argp,
664                             "-print-multi-os-directory") == 0) {
665                                 printf("%s\n"MULTIOSDIR);
666                                 return 0;
667                         } else
668                                 oerror(argp);
669                         break;
ragge
1.128
670
ragge
1.220
671                 case 'r':
672                         rflag = 1;
673                         break;
gmcgarry
1.145
674
ragge
1.220
675                 case 'x':
676                         t = nxtopt("-x");
677                         if (match(t"c"))
678                                 xcflag = 1/* default */
679                         else if (match(t"assembler"))
680                                 xasm = 1;
681                         else if (match(t"assembler-with-cpp"))
682                                 ascpp = 1;
683                         else if (match(t"c++"))
684                                 cxxflag++;
685                         else if (argp[2])
686                                 xlist[xnum++] = argp;
687                         else
688                                 xlist[xnum++] = "-x"xlist[xnum++] = t;
689                         break;
690                 case 't':
691                         tflag++;
692                         break;
693                 case 'S':
694                         sflag++;
695                         cflag++;
696                         break;
697                 case 'o':
698                         if (outfile)
699                                 errorx(8"too many -o");
700                         outfile = nxtopt("-o");
701                         break;
702                 case 'O':
703                         if (argp[2] == '\0')
704                                 Oflag++;
705                         else if (argp[3] == '\0' && isdigit((unsigned char)argp[2]))
706                                 Oflag = argp[2] - '0';
707                         else if (argp[3] == '\0' && argp[2] == 's')
708                                 Oflag = 1;      /* optimize for space only */
709                         else
710                                 oerror(argp);
711                         break;
712                 case 'E':
713                         Eflag++;
714                         break;
715                 case 'P':
716                         pflag++;
ragge
1.221
717                         strlist_append(&preprocessor_flagsargp);
718                         break;
719
ragge
1.220
720                 case 'c':
gmcgarry
1.172
721 #ifdef os_darwin
ragge
1.220
722                         if (strcmp(argp"-compatibility_version") == 0) {
723                                 llist[nl++] = argp;
724                                 llist[nl++] = nxtopt(0);
725                         } else if (strcmp(argp"-current_version") == 0) {
726                                 llist[nl++] = argp;
727                                 llist[nl++] = nxtopt(0);
728                         } else
gmcgarry
1.172
729 #endif
ragge
1.220
730                                 cflag++;
731                         break;
ragge
1.128
732 #if 0
ragge
1.220
733                 case '2':
734                         if(argp[2] == '\0')
735                                 pref = "/lib/crt2.o";
736                         else {
737                                 pref = "/lib/crt20.o";
738                         }
739                         break;
ragge
1.128
740 #endif
ragge
1.220
741                 case 'M':
742                         switch (argp[2]) {
743                         case '\0'Mflag++; break;
744                         case 'P'MPflag++; break;
745                         case 'F'outfile = nxtopt(0); break;
746                         case 'T':
747                         case 'Q':
748                                 j = strlen(u = nxtopt(0));
749                                 t = copy("-xM.,"j);
750                                 strlcat(tuj+6);
751                                 t[3] = argp[2];
752                                 Mfiles[nMfiles++] = t;
ragge
1.128
753                                 break;
ragge
1.220
754                         default:
755                                 oerror(argp);
756                         }
757                         break;
ragge
1.128
758
ragge
1.220
759                 case 'd':
gmcgarry
1.144
760 #ifdef os_darwin
ragge
1.220
761                         if (strcmp(argp"-dynamiclib") == 0) {
762                                 shared = 1;
763                         } else
gmcgarry
1.144
764 #endif
ragge
1.220
765                         break;
766                 case 'v':
767                         printf("%s\n"VERSSTR);
768                         vflag++;
769                         break;
ragge
1.128
770
ragge
1.220
771                 case 's':
gmcgarry
1.144
772 #ifndef os_darwin
ragge
1.220
773                         if (strcmp(argp"-shared") == 0) {
774                                 shared = 1;
775                         } else
776 #endif
777                         if (strcmp(argp"-static") == 0) {
778                                 Bstatic = 1;
779                         } else if (strcmp(argp"-symbolic") == 0) {
780                                 llist[nl++] = "-Bsymbolic";
781                         } else if (strncmp(argp"-std"4) == 0) {
782                                 if (strcmp(&argp[5], "gnu99") == 0 ||
783                                     strcmp(&argp[5], "gnu9x") == 0)
784                                         xgnu99 = 1;
785                                 if (strcmp(&argp[5], "gnu89") == 0)
786                                         xgnu89 = 1;
787                         } else
788                                 goto passa;
789                         break;
790                 }
791                 continue;
792
793         passa:
794                 t = argp;
795                 if (*argp == '-' && argp[1] == 'L')
796                         ;
797                 else if ((cxxsuf(getsufp(t)) && cxxflag) ||
798                     (c=getsuf(t))=='c' || c=='S' || c=='i' ||
799                     c=='s'|| Eflag || xcflag || xasm) {
800                         clist[nc++] = t;
801                         if (nc>=MAXFIL) {
802                                 error("Too many source files");
803                                 exit(1);
ragge
1.128
804                         }
ragge
1.220
805                 }
ragge
1.128
806
ragge
1.220
807                 /* Check for duplicate .o files. */
808                 for (j = getsuf(t) == 'o' ? 0 : nlj < nlj++) {
809                         if (strcmp(llist[j], t) == 0)
810                                 break;
811                 }
812                 if ((c=getsuf(t))!='c' && c!='S' &&
813                     c!='s' && c!='i' && j==nl &&
814                     !(cxxsuf(getsufp(t)) && cxxflag) && !xasm) {
815                         llist[nl++] = t;
816                         if (nl >= MAXLIB) {
817                                 error("Too many object/library files");
818                                 exit(1);
ragge
1.128
819                         }
ragge
1.220
820                         if (getsuf(t)=='o')
821                                 nxo++;
ragge
1.128
822                 }
823         }
824         /* Sanity checking */
ragge
1.216
825         if (cppflag) {
826                 if (nc == 0)
827                         clist[nc++] = "-";
828                 else if (nc > 2 || (nc == 2 && outfile))
829                         errorx(8"too many files");
830                 else if (nc == 2)
831                         outfile = clist[--nc];
832         }
ragge
1.128
833         if (nc == 0 && nl == 0)
834                 errorx(8"no input files");
835         if (outfile && (cflag || sflag || Eflag) && nc > 1)
836                 errorx(8"-o given with -c || -E || -S and more than one file");
837         if (outfile && clist[0] && strcmp(outfileclist[0]) == 0)
838                 errorx(8"output file will be clobbered");
gmcgarry
1.150
839         if (nc==0)
ragge
1.128
840                 goto nocom;
841         if (pflag==0) {
842                 if (!sflag)
843                         tmp3 = gettmp();
844                 tmp4 = gettmp();
845         }
846         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
847                 signal(SIGINTidexit);
848         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
849                 signal(SIGTERMidexit);
850 #ifdef MULTITARGET
plunky
1.186
851         pass0 = cat(LIBEXECDIR "/ccom_"mach);
ragge
1.128
852 #endif
853         for (i=0i<nci++) {
854                 /*
855                  * C preprocessor
856                  */
857                 if (nc>1 && !Eflag)
858                         printf("%s:\n"clist[i]);
859                 onlyas = 0;
860                 assource = tmp3;
861                 if (getsuf(clist[i])=='S')
862                         ascpp = 1;
863                 if (getsuf(clist[i])=='i') {
864                         if(Eflag)
865                                 continue;
866                         goto com;
867                 } else if (ascpp) {
868                         onlyas = 1;
plunky
1.217
869                 } else if (xasm || getsuf(clist[i])=='s') {
ragge
1.128
870                         assource = clist[i];
871                         goto assemble;
872                 }
873                 if (pflag)
874                         tmp4 = setsuf(clist[i], 'i');
875                 na = 0;
876                 av[na++] = "cpp";
877                 if (vflag)
878                         av[na++] = "-v";
879                 av[na++] = "-D__PCC__=" MKS(PCC_MAJOR);
880                 av[na++] = "-D__PCC_MINOR__=" MKS(PCC_MINOR);
881                 av[na++] = "-D__PCC_MINORMINOR__=" MKS(PCC_MINORMINOR);
gmcgarry
1.156
882 #ifndef os_win32
ragge
1.155
883 #ifdef GCC_COMPAT
884                 av[na++] = "-D__GNUC__=4";
885                 av[na++] = "-D__GNUC_MINOR__=3";
886                 av[na++] = "-D__GNUC_PATCHLEVEL__=1";
ragge
1.198
887                 if (xgnu89)
plunky
1.208
888                         av[na++] = "-D__GNUC_GNU_INLINE__";
ragge
1.191
889                 else
plunky
1.208
890                         av[na++] = "-D__GNUC_STDC_INLINE__";
ragge
1.170
891 #endif
892 #endif
ragge
1.166
893                 av[na++] = "-D__VERSION__=" MKS(VERSSTR);
ragge
1.167
894                 av[na++] = "-D__SCHAR_MAX__=" MKS(MAX_CHAR);
895                 av[na++] = "-D__SHRT_MAX__=" MKS(MAX_SHORT);
896                 av[na++] = "-D__INT_MAX__=" MKS(MAX_INT);
897                 av[na++] = "-D__LONG_MAX__=" MKS(MAX_LONG);
898                 av[na++] = "-D__LONG_LONG_MAX__=" MKS(MAX_LONGLONG);
plunky
1.214
899                 if (freestanding)
900                         av[na++] = "-D__STDC_HOSTED__=0";
901                 else
902                         av[na++] = "-D__STDC_HOSTED__=1";
ragge
1.212
903                 if (cxxflag)
904                         av[na++] = "-D__cplusplus";
plunky
1.209
905                 if (xuchar)
plunky
1.196
906                         av[na++] = "-D__CHAR_UNSIGNED__";
ragge
1.128
907                 if (ascpp)
908                         av[na++] = "-D__ASSEMBLER__";
909                 if (sspflag)
plunky
1.208
910                         av[na++] = "-D__SSP__";
ragge
1.128
911                 if (pthreads)
912                         av[na++] = "-D_PTHREADS";
913                 if (Mflag)
914                         av[na++] = "-M";
ragge
1.216
915                 if (MPflag)
916                         av[na++] = "-xMP";
917                 for (j = 0j < nMfilesj++)
918                         av[na++] = Mfiles[j];
ragge
1.160
919                 if (Oflag)
920                         av[na++] = "-D__OPTIMIZE__";
921 #ifdef GCC_COMPAT
922                 av[na++] = "-D__REGISTER_PREFIX__=" REGISTER_PREFIX;
923                 av[na++] = "-D__USER_LABEL_PREFIX__=" USER_LABEL_PREFIX;
924 #endif
ragge
1.128
925                 for (j = 0cppadd[j]; j++)
926                         av[na++] = cppadd[j];
ragge
1.218
927                 STRLIST_FOREACH(s, &preprocessor_flags) {
928                         av[na++] = s->value;
929                 }
ragge
1.221
930                 STRLIST_FOREACH(s, &includes) {
931                         av[na++] = "-i";
932                         av[na++] = s->value;
933                 }
ragge
1.219
934                 STRLIST_FOREACH(s, &incdirs) {
ragge
1.221
935                         av[na++] = "-I";
936                         av[na++] = s->value;
937                 }
938                 STRLIST_FOREACH(s, &user_sysincdirs) {
939                         av[na++] = "-S";
ragge
1.219
940                         av[na++] = s->value;
941                 }
gmcgarry
1.149
942                 av[na++] = "-D__STDC_ISO_10646__=200009L";
ragge
1.157
943                 av[na++] = "-D__WCHAR_TYPE__=" WCT;
944                 av[na++] = "-D__SIZEOF_WCHAR_T__=" MKS(WCHAR_SIZE);
945                 av[na++] = "-D__WCHAR_MAX__=" WCM;
plunky
1.192
946                 av[na++] = "-D__WINT_TYPE__=" PCC_WINT_TYPE;
947                 av[na++] = "-D__SIZE_TYPE__=" PCC_SIZE_TYPE;
ragge
1.161
948                 av[na++] = "-D__PTRDIFF_TYPE__=" PCC_PTRDIFF_TYPE;
gmcgarry
1.142
949                 av[na++] = "-D__SIZEOF_WINT_T__=4";
plunky
1.201
950 #if defined(os_darwin) || defined(os_netbsd)
951                 av[na++] = "-D__FLT_RADIX__=2";
952                 av[na++] = "-D__FLT_DIG__=6";
953                 av[na++] = "-D__FLT_EPSILON__=1.19209290e-07F";
954                 av[na++] = "-D__FLT_MANT_DIG__=24";
955                 av[na++] = "-D__FLT_MAX_10_EXP__=38";
956                 av[na++] = "-D__FLT_MAX_EXP__=128";
957                 av[na++] = "-D__FLT_MAX__=3.40282347e+38F";
958                 av[na++] = "-D__FLT_MIN_10_EXP__=(-37)";
959                 av[na++] = "-D__FLT_MIN_EXP__=(-125)";
gmcgarry
1.171
960                 av[na++] = "-D__FLT_MIN__=1.17549435e-38F";
plunky
1.201
961                 av[na++] = "-D__DBL_DIG__=15";
962                 av[na++] = "-D__DBL_EPSILON__=2.2204460492503131e-16";
963                 av[na++] = "-D__DBL_MANT_DIG__=53";
964                 av[na++] = "-D__DBL_MAX_10_EXP__=308";
965                 av[na++] = "-D__DBL_MAX_EXP__=1024";
966                 av[na++] = "-D__DBL_MAX__=1.797693