Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20160826135257

Diff

Diff from 1.310 to:

Annotations

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

Annotated File View

ragge
1.310
1 /*      $Id: cc.c,v 1.310 2016/08/26 13:52:57 ragge Exp $       */
ragge
1.222
2
3 /*-
4  * Copyright (c) 2011 Joerg Sonnenberger <joerg@NetBSD.org>.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31
ragge
1.128
32 /*
33  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
34  *
35  * Redistribution and use in source and binary forms, with or without
36  * modification, are permitted provided that the following conditions
37  * are met:
38  *
39  * Redistributions of source code and documentation must retain the above
40  * copyright notice, this list of conditions and the following disclaimer.
41  * Redistributions in binary form must reproduce the above copyright
42  * notice, this list of conditionsand the following disclaimer in the
43  * documentation and/or other materials provided with the distribution.
44  * All advertising materials mentioning features or use of this software
45  * must display the following acknowledgement:
46  *      This product includes software developed or owned by Caldera
47  *      International, Inc.
48  * Neither the name of Caldera International, Inc. nor the names of other
49  * contributors may be used to endorse or promote products derived from
50  * this software without specific prior written permission.
51  *
52  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
53  * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
54  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
55  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
56  * DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
57  * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60  * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
61  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
62  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
63  * POSSIBILITY OF SUCH DAMAGE.
64  */
65
66 /*
67  * Front-end to the C compiler.
68  *
69  * Brief description of its syntax:
70  * - Files that end with .c are passed via cpp->ccom->as->ld
71  * - Files that end with .i are passed via ccom->as->ld
plunky
1.206
72  * - Files that end with .S are passed via cpp->as->ld
73  * - Files that end with .s are passed via as->ld
ragge
1.128
74  * - Files that end with .o are passed directly to ld
75  * - Multiple files may be given on the command line.
76  * - Unrecognized options are all sent directly to ld.
77  * -c or -S cannot be combined with -o if multiple files are given.
78  *
79  * This file should be rewritten readable.
80  */
81 #include "config.h"
82
83 #include <sys/types.h>
84 #ifdef HAVE_SYS_WAIT_H
85 #include <sys/wait.h>
86 #endif
87
88 #include <ctype.h>
89 #include <errno.h>
90 #include <fcntl.h>
91 #ifdef HAVE_LIBGEN_H
92 #include <libgen.h>
93 #endif
94 #include <signal.h>
95 #include <stdarg.h>
96 #include <stdio.h>
97 #include <stdlib.h>
98 #include <string.h>
99 #ifdef HAVE_UNISTD_H
100 #include <unistd.h>
101 #endif
ragge
1.222
102 #include <assert.h>
ragge
1.304
103 #include <time.h>
ragge
1.128
104
plunky
1.293
105 #ifdef  _WIN32
ragge
1.128
106 #include <windows.h>
107 #include <process.h>
108 #include <io.h>
gmcgarry
1.179
109 #define F_OK    0x00
110 #define R_OK    0x04
111 #define W_OK    0x02
112 #define X_OK    R_OK
ragge
1.128
113 #endif
114
115 #include "compat.h"
116
ragge
1.167
117 #include "macdefs.h"
ragge
1.218
118
119 #include "xalloc.h"
120 #include "strlist.h"
ragge
1.226
121
122 #include "ccconfig.h"
ragge
1.128
123 /* C command */
124
125 #define MKS(x) _MKS(x)
126 #define _MKS(x) #x
127
ragge
1.226
128 /* default program names in pcc */
129 /* May be overridden if cross-compiler is generated */
plunky
1.303
130 #ifndef CXXPROGNAME             /* name as C++ front end */
131 #define CXXPROGNAME     "c++"
132 #endif
ragge
1.226
133 #ifndef CPPROGNAME
plunky
1.303
134 #define CPPROGNAME      "cpp"   /* name as CPP front end */
ragge
1.128
135 #endif
136 #ifndef PREPROCESSOR
ragge
1.226
137 #define PREPROCESSOR    "cpp"   /* "real" preprocessor name */
ragge
1.128
138 #endif
139 #ifndef COMPILER
gmcgarry
1.138
140 #define COMPILER        "ccom"
ragge
1.128
141 #endif
ragge
1.226
142 #ifndef CXXCOMPILER
143 #define CXXCOMPILER     "cxxcom"
144 #endif
ragge
1.128
145 #ifndef ASSEMBLER
146 #define ASSEMBLER       "as"
147 #endif
148 #ifndef LINKER
149 #define LINKER          "ld"
150 #endif
ragge
1.226
151 char    *passp = PREPROCESSOR;
152 char    *pass0 = COMPILER;
153 char    *passxx0 = CXXCOMPILER;
154 char    *as = ASSEMBLER;
155 char    *ld = LINKER;
156 char    *sysroot = "", *isysroot;
157
158
159 /* crt files using pcc default names */
160 #ifndef CRTBEGIN_S
161 #define CRTBEGIN_S      "crtbeginS.o"
162 #endif
163 #ifndef CRTEND_S
164 #define CRTEND_S        "crtendS.o"
165 #endif
166 #ifndef CRTBEGIN_T
167 #define CRTBEGIN_T      "crtbeginT.o"
168 #endif
169 #ifndef CRTEND_T
170 #define CRTEND_T        "crtendT.o"
171 #endif
172 #ifndef CRTBEGIN
173 #define CRTBEGIN        "crtbegin.o"
174 #endif
175 #ifndef CRTEND
176 #define CRTEND          "crtend.o"
177 #endif
178 #ifndef CRTI
179 #define CRTI            "crti.o"
180 #endif
181 #ifndef CRTN
182 #define CRTN            "crtn.o"
183 #endif
184 #ifndef CRT0
185 #define CRT0            "crt0.o"
186 #endif
187 #ifndef GCRT0
188 #define GCRT0           "gcrt0.o"
189 #endif
190
191 /* preprocessor stuff */
192 #ifndef STDINC
193 #define STDINC          "/usr/include/"
194 #endif
ragge
1.286
195 #ifdef MULTIARCH_PATH
196 #define STDINC_MA       STDINC MULTIARCH_PATH "/"
197 #endif
198
ragge
1.226
199
200 char *cppadd[] = CPPADD;
201 char *cppmdadd[] = CPPMDADD;
ragge
1.128
202
ragge
1.226
203 /* Default libraries and search paths */
204 #ifndef PCCLIBDIR       /* set by autoconf */
205 #define PCCLIBDIR       NULL
206 #endif
plunky
1.289
207 #ifndef LIBDIR
208 #define LIBDIR          "/usr/lib/"
209 #endif
ragge
1.226
210 #ifndef DEFLIBDIRS      /* default library search paths */
ragge
1.286
211 #ifdef MULTIARCH_PATH
plunky
1.289
212 #define DEFLIBDIRS      { LIBDIR, LIBDIR MULTIARCH_PATH "/", 0 }
plunky
1.287
213 #else
plunky
1.289
214 #define DEFLIBDIRS      { LIBDIR, 0 }
ragge
1.286
215 #endif
ragge
1.226
216 #endif
217 #ifndef DEFLIBS         /* default libraries included */
218 #define DEFLIBS         { "-lpcc", "-lc", "-lpcc", 0 }
219 #endif
220 #ifndef DEFPROFLIBS     /* default profiling libraries */
221 #define DEFPROFLIBS     { "-lpcc", "-lc_p", "-lpcc", 0 }
222 #endif
223 #ifndef DEFCXXLIBS      /* default c++ libraries */
224 #define DEFCXXLIBS      { "-lp++", "-lpcc", "-lc", "-lpcc", 0 }
225 #endif
226 #ifndef STARTLABEL
227 #define STARTLABEL "__start"
228 #endif
plunky
1.295
229 #ifndef DYNLINKARG
230 #define DYNLINKARG      "-dynamic-linker"
231 #endif
232 #ifndef DYNLINKLIB
233 #define DYNLINKLIB      NULL
234 #endif
ragge
1.174
235
plunky
1.295
236 char *dynlinkarg = DYNLINKARG;
237 char *dynlinklib = DYNLINKLIB;
ragge
1.226
238 char *pcclibdir = PCCLIBDIR;
239 char *deflibdirs[] = DEFLIBDIRS;
240 char *deflibs[] = DEFLIBS;
241 char *defproflibs[] = DEFPROFLIBS;
242 char *defcxxlibs[] = DEFCXXLIBS;
243
ragge
1.254
244 char    *outfile, *MFfile, *fname;
ragge
1.220
245 static char **lav;
246 static int lac;
ragge
1.226
247 static char *find_file(const char *filestruct strlist *pathint mode);
248 static int preprocess_input(char *inputchar *outputint dodep);
249 static int compile_input(char *inputchar *output);
250 static int assemble_input(char *inputchar *output);
251 static int run_linker(void);
252 static int strlist_exec(struct strlist *l);
253
plunky
1.185
254 char *cat(const char *, const char *);
gmcgarry
1.150
255 char *setsuf(char *, char);
ragge
1.198
256 int cxxsuf(char *);
ragge
1.128
257 int getsuf(char *);
ragge
1.198
258 char *getsufp(char *s);
ragge
1.128
259 int main(intchar *[]);
260 void errorx(intchar *, ...);
261 int cunlink(char *);
ragge
1.226
262 void exandrm(char *);
ragge
1.128
263 void dexit(int);
264 void idexit(int);
265 char *gettmp(void);
ragge
1.219
266 void oerror(char *);
ragge
1.218
267 char *argnxt(char *, char *);
ragge
1.220
268 char *nxtopt(char *o);
ragge
1.222
269 void setup_cpp_flags(void);
ragge
1.226
270 void setup_ccom_flags(void);
271 void setup_as_flags(void);
272 void setup_ld_flags(void);
ragge
1.222
273 static void expand_sysroot(void);
plunky
1.293
274 #ifdef  _WIN32
ragge
1.128
275 char *win32pathsubst(char *);
plunky
1.250
276 char *win32commandline(struct strlist *l);
ragge
1.128
277 #endif
278 int     sspflag;
plunky
1.214
279 int     freestanding;
ragge
1.226
280 int     Sflag;
ragge
1.128
281 int     cflag;
282 int     gflag;
gmcgarry
1.145
283 int     rflag;
ragge
1.128
284 int     vflag;
plunky
1.296
285 int     noexec/* -### */
ragge
1.128
286 int     tflag;
287 int     Eflag;
288 int     Oflag;
289 int     kflag;  /* generate PIC/pic code */
290 #define F_PIC   1
291 #define F_pic   2
ragge
1.279
292 int     MflagneedMMDflagMMDflag;  /* dependencies only */
ragge
1.128
293 int     pgflag;
294 int     Xflag;
295 int     nostartfilesBstaticshared;
296 int     nostdincnostdlib;
297 int     pthreads;
ragge
1.302
298 int     xgnu89xgnu99c89defsc99defsc11defs;
ragge
1.128
299 int     ascpp;
plunky
1.196
300 #ifdef CHAR_UNSIGNED
plunky
1.209
301 int     xuchar = 1;
plunky
1.196
302 #else
plunky
1.209
303 int     xuchar = 0;
plunky
1.196
304 #endif
ragge
1.198
305 int     cxxflag;
ragge
1.216
306 int     cppflag;
ragge
1.254
307 int     printprognameprintfilename;
ragge
1.302
308 enum { SC11STRADSC89SGNU89SC99SGNU99 } cstd;
ragge
1.128
309
plunky
1.295
310 #ifdef SOFTFLOAT
311 int     softfloat = 1;
312 #else
313 int     softfloat = 0;
314 #endif
315
316 #ifdef TARGET_BIG_ENDIAN
317 int     bigendian = 1;
318 #else
319 int     bigendian = 0;
320 #endif
321
ragge
1.164
322 #ifdef mach_amd64
323 int amd64_i386;
324 #endif
ragge
1.128
325
ragge
1.218
326 #define match(a,b)      (strcmp(a,b) == 0)
327
ragge
1.128
328 /* handle gcc warning emulations */
329 struct Wflags {
330         char *name;
331         int flags;
332 #define INWALL          1
ragge
1.309
333 #define INWEXTRA        2
ragge
1.128
334 Wflags[] = {
plunky
1.215
335         { "truncate"0 },
336         { "strict-prototypes"0 },
ragge
1.309
337         { "missing-prototypes"INWEXTRA },
plunky
1.215
338         { "implicit-int"INWALL },
339         { "implicit-function-declaration"INWALL },
ragge
1.309
340         { "shadow"INWEXTRA },
plunky
1.215
341         { "pointer-sign"INWALL },
ragge
1.309
342         { "sign-compare"INWEXTRA },
plunky
1.215
343         { "unknown-pragmas"INWALL },
ragge
1.309
344         { "unreachable-code"INWEXTRA },
345         { "deprecated-declarations"INWEXTRA },
plunky
1.276
346         { "attributes"0 },
plunky
1.215
347         { NULL0 },
ragge
1.128
348 };
349
ragge
1.158
350 #ifndef USHORT
351 /* copied from mip/manifest.h */
352 #define USHORT          5
353 #define INT             6
354 #define UNSIGNED        7
355 #endif
356
ragge
1.157
357 /*
358  * Wide char defines.
359  */
360 #if WCHAR_TYPE == USHORT
361 #define WCT "short unsigned int"
362 #define WCM "65535U"
ragge
1.158
363 #if WCHAR_SIZE != 2
364 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
365 #endif
ragge
1.157
366 #elif WCHAR_TYPE == INT
367 #define WCT "int"
368 #define WCM "2147483647"
ragge
1.158
369 #if WCHAR_SIZE != 4
370 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
371 #endif
ragge
1.157
372 #elif WCHAR_TYPE == UNSIGNED
373 #define WCT "unsigned int"
ragge
1.158
374 #define WCM "4294967295U"
375 #if WCHAR_SIZE != 4
376 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
377 #endif
378 #else
379 #error WCHAR_TYPE not defined or invalid
ragge
1.157
380 #endif
381
ragge
1.160
382 #ifdef GCC_COMPAT
383 #ifndef REGISTER_PREFIX
384 #define REGISTER_PREFIX ""
385 #endif
386 #ifndef USER_LABEL_PREFIX
387 #define USER_LABEL_PREFIX ""
388 #endif
389 #endif
390
plunky
1.192
391 #ifndef PCC_WINT_TYPE
392 #define PCC_WINT_TYPE "unsigned int"
393 #endif
394
395 #ifndef PCC_SIZE_TYPE
396 #define PCC_SIZE_TYPE "unsigned long"
397 #endif
398
ragge
1.161
399 #ifndef PCC_PTRDIFF_TYPE
400 #define PCC_PTRDIFF_TYPE "long int"
401 #endif
402
ragge
1.216
403
ragge
1.218
404 struct strlist preprocessor_flags;
ragge
1.223
405 struct strlist depflags;
ragge
1.219
406 struct strlist incdirs;
ragge
1.221
407 struct strlist user_sysincdirs;
408 struct strlist includes;
ragge
1.222
409 struct strlist sysincdirs;
ragge
1.223
410 struct strlist dirafterdirs;
ragge
1.222
411 struct strlist crtdirs;
412 struct strlist libdirs;
413 struct strlist progdirs;
ragge
1.224
414 struct strlist early_linker_flags;
415 struct strlist middle_linker_flags;
416 struct strlist late_linker_flags;
417 struct strlist inputs;
ragge
1.225
418 struct strlist assembler_flags;
419 struct strlist temp_outputs;
ragge
1.226
420 struct strlist compiler_flags;
ragge
1.218
421
ragge
1.128
422 int
423 main(int argcchar *argv[])
424 {
425         struct Wflags *Wf;
ragge
1.226
426         struct string *s;
ragge
1.218
427         char *t, *u, *argp;
ragge
1.239
428         char *msuffix;
ragge
1.226
429         int ninputj;
ragge
1.222
430
ragge
1.220
431         lav = argv;
432         lac = argc;
plunky
1.242
433         ninput = 0;
ragge
1.128
434
ragge
1.222
435         strlist_init(&crtdirs);
436         strlist_init(&libdirs);
437         strlist_init(&progdirs);
ragge
1.218
438         strlist_init(&preprocessor_flags);
ragge
1.219
439         strlist_init(&incdirs);
ragge
1.221
440         strlist_init(&user_sysincdirs);
441         strlist_init(&includes);
ragge
1.222
442         strlist_init(&sysincdirs);
ragge
1.223
443         strlist_init(&dirafterdirs);
444         strlist_init(&depflags);
ragge
1.224
445         strlist_init(&early_linker_flags);
446         strlist_init(&middle_linker_flags);
447         strlist_init(&late_linker_flags);
448         strlist_init(&inputs);
ragge
1.225
449         strlist_init(&assembler_flags);
450         strlist_init(&temp_outputs);
ragge
1.226
451         strlist_init(&compiler_flags);
ragge
1.218
452
ragge
1.216
453         if ((t = strrchr(argv[0], '/')))
ragge
1.226
454                 t++;
ragge
1.229
455         else
456                 t = argv[0];
ragge
1.226
457
plunky
1.303
458         if (match(tCXXPROGNAME)) {
ragge
1.198
459                 cxxflag = 1;
plunky
1.303
460         } else if (match(tCPPROGNAME)) {
ragge
1.226
461                 Eflag = cppflag = 1;
ragge
1.198
462         }
463
plunky
1.260
464 #ifdef PCC_EARLY_SETUP
465         PCC_EARLY_SETUP
ragge
1.246
466 #endif
467
plunky
1.293
468 #ifdef _WIN32
ragge
1.128
469         /* have to prefix path early.  -B may override */
470         incdir = win32pathsubst(incdir);
gmcgarry
1.153
471         altincdir = win32pathsubst(altincdir);
gmcgarry
1.136
472         libdir = win32pathsubst(libdir);
plunky
1.200
473 #ifdef PCCINCDIR
ragge
1.128
474         pccincdir = win32pathsubst(pccincdir);
plunky
1.199
475         pxxincdir = win32pathsubst(pxxincdir);
plunky
1.200
476 #endif
477 #ifdef PCCLIBDIR
ragge
1.128
478         pcclibdir = win32pathsubst(pcclibdir);
plunky
1.200
479 #endif
ragge
1.128
480         passp = win32pathsubst(passp);
481         pass0 = win32pathsubst(pass0);
gmcgarry
1.180
482 #ifdef STARTFILES
483         for (i = 0startfiles[i] != NULLi++)
484                 startfiles[i] = win32pathsubst(startfiles[i]);
485         for (i = 0endfiles[i] != NULLi++)
486                 endfiles[i] = win32pathsubst(endfiles[i]);
487 #endif
488 #ifdef STARTFILES_T
489         for (i = 0startfiles_T[i] != NULLi++)
490                 startfiles_T[i] = win32pathsubst(startfiles_T[i]);
491         for (i = 0endfiles_T[i] != NULLi++)
492                 endfiles_T[i] = win32pathsubst(endfiles_T[i]);
493 #endif
494 #ifdef STARTFILES_S
495         for (i = 0startfiles_S[i] != NULLi++)
496                 startfiles_S[i] = win32pathsubst(startfiles_S[i]);
497         for (i = 0endfiles_S[i] != NULLi++)
498                 endfiles_S[i] = win32pathsubst(endfiles_S[i]);
499 #endif
ragge
1.128
500 #endif
501
ragge
1.220
502         while (--lac) {
503                 ++lav;
504                 argp = *lav;
505
plunky
1.260
506 #ifdef PCC_EARLY_ARG_CHECK
507                 PCC_EARLY_ARG_CHECK
ragge
1.227
508 #endif
509
ragge
1.225
510                 if (*argp != '-' || match(argp"-")) {
511                         /* Check for duplicate .o files. */
512                         if (getsuf(argp) == 'o') {
513                                 j = 0;
514                                 STRLIST_FOREACH(s, &inputs)
515                                         if (match(argps->value))
516                                                 j++;
517                                 if (j)
518                                         continue/* skip it */
519                         }
520                         strlist_append(&inputsargp);
plunky
1.242
521                         ninput++;
ragge
1.225
522                         continue;
523                 }
ragge
1.220
524
525                 switch (argp[1]) {
526                 default:
plunky
1.257
527                         oerror(argp);
ragge
1.220
528                         break;
ragge
1.128
529
plunky
1.296
530                 case '#':
531                         if (match(argp"-###")) {
532                                 printf("%s\n"VERSSTR);
533                                 vflag++;
534                                 noexec++;
535                         } else
536                                 oerror(argp);
537                         break;
538
ragge
1.220
539                 case '-'/* double -'s */
540                         if (match(argp"--version")) {
541                                 printf("%s\n"VERSSTR);
542                                 return 0;
543                         } else if (strncmp(argp"--sysroot="10) == 0) {
544                                 sysroot = argp + 10;
gmcgarry
1.298
545                         } else if (strncmp(argp"--sysroot"9) == 0) {
546                                 sysroot = nxtopt(argp);
ragge
1.220
547                         } else if (strcmp(argp"--param") == 0) {
548                                 /* NOTHING YET */;
549                                 (void)nxtopt(0); /* ignore arg */
550                         } else
plunky
1.257
551                                 oerror(argp);
ragge
1.220
552                         break;
ragge
1.128
553
ragge
1.310
554                 case 'a':       /* only -ansi switch for now */
555                         if (match(argp"-ansi"))
556                                 cstd = SC89;
557                         break;
558
ragge
1.220
559                 case 'B'/* other search paths for binaries */
ragge
1.224
560                         t = nxtopt("-B");
561                         strlist_append(&crtdirst);
562                         strlist_append(&libdirst);
563                         strlist_append(&progdirst);
ragge
1.220
564                         break;
ragge
1.128
565
ragge
1.220
566                 case 'C':
567                         if (match(argp"-C") || match(argp"-CC"))
568                                 strlist_append(&preprocessor_flagsargp);
569                         else
570                                 oerror(argp);
571                         break;
ragge
1.218
572
ragge
1.255
573                 case 'c':
574                         cflag++;
575                         break;
576
plunky
1.277
577                 case 'd'/* debug options */
ragge
1.308
578                         if (match(argp"-dumpmachine")) {
579                                 /* Print target and immediately exit */
580                                 puts(TARGSTR);
581                                 exit(0);
582                         }
583                         if (match(argp"-dumpversion")) {
584                                 /* Print claimed gcc level, immediately exit */
585                                 puts("4.3.1");
586                                 exit(0);
587                         }
plunky
1.277
588                         for (t = &argp[2]; *tt++) {
589                                 if (*t == 'M')
590                                         strlist_append(&preprocessor_flags"-dM");
591
592                                 /* ignore others */
593                         }
ragge
1.220
594                         break;
ragge
1.255
595
596                 case 'E':
597                         Eflag++;
ragge
1.220
598                         break;
ragge
1.128
599
ragge
1.220
600                 case 'f'/* GCC compatibility flags */
ragge
1.246
601                         u = &argp[2];
602                         j = 0;
603                         if (strncmp(u"no-"3) == 0)
604                                 j = 1u += 3;
605                         if (match(u"PIC") || match(u"pic")) {
606                                 kflag = j ? 0 : *u == 'P' ? F_PIC : F_pic;
607                         } else if (match(u"freestanding")) {
608                                 freestanding = j ? 0 : 1;
609                         } else if (match(u"signed-char")) {
610                                 xuchar = j ? 1 : 0;
611                         } else if (match(u"unsigned-char")) {
612                                 xuchar = j ? 0 : 1;
plunky
1.248
613                         } else if (match(u"stack-protector") ||
614                             match(u"stack-protector-all")) {
ragge
1.246
615                                 sspflag = j ? 0 : 1;
ragge
1.220
616                         }
617                         /* silently ignore the rest */
618                         break;
ragge
1.128
619
ragge
1.220
620                 case 'g'/* create debug output */
621                         if (argp[2] == '0')
622                                 gflag = 0;
623                         else
624                                 gflag++;
625                         break;
ragge
1.128
626
ragge
1.255
627
628                 case 'X':
629                         Xflag++;
630                         break;
631
ragge
1.220
632                 case 'D':
633                 case 'U':
ragge
1.221
634                         strlist_append(&preprocessor_flagsargp);
ragge
1.220
635                         if (argp[2] != 0)
ragge
1.219
636                                 break;
ragge
1.221
637                         strlist_append(&preprocessor_flagsnxtopt(argp));
638                         break;
639
640                 case 'I'/* Add include dirs */
641                         strlist_append(&incdirsnxtopt("-I"));
ragge
1.220
642                         break;
ragge
1.219
643
ragge
1.220
644                 case 'i':
ragge
1.221
645                         if (match(argp"-isystem")) {
646                                 strlist_append(&user_sysincdirsnxtopt(0));
647                         } else if (match(argp"-include")) {
648                                 strlist_append(&includesnxtopt(0));
ragge
1.222
649                         } else if (match(argp"-isysroot")) {
650                                 isysroot = nxtopt(0);
ragge
1.220
651                         } else if (strcmp(argp"-idirafter") == 0) {
ragge
1.223
652                                 strlist_append(&dirafterdirsnxtopt(0));
ragge
1.220
653                         } else
plunky
1.257
654                                 oerror(argp);
ragge
1.220
655                         break;
ragge
1.128
656
ragge
1.220
657                 case 'k'/* generate PIC code */
ragge
1.247
658                         kflag = argp[2] ? argp[2] - '0' : F_pic;
ragge
1.220
659                         break;
ragge
1.128
660
ragge
1.224
661                 case 'l':
662                 case 'L':
ragge
1.226
663                         if (argp[2] == 0)
ragge
1.245
664                                 argp = cat(argpnxtopt(0));
665                         strlist_append(&inputsargp);
ragge
1.224
666                         break;
667
ragge
1.220
668                 case 'm'/* target-dependent options */
ragge
1.285
669                         if (strncmp(argp"-march="6) == 0) {
670                                 strlist_append(&compiler_flagsargp);
671                                 break;
672                         }
ragge
1.164
673 #ifdef mach_amd64
ragge
1.220
674                         /* need to call i386 ccom for this */
ragge
1.262
675                         if (strcmp(argp"-melf_i386") == 0) {
ragge
1.220
676                                 pass0 = LIBEXECDIR "/ccom_i386";
677                                 amd64_i386 = 1;
678                                 break;
679                         }
ragge
1.164
680 #endif
ragge
1.306
681 #if defined(mach_arm) || defined(mach_mips) || defined(mach_mips64)
plunky
1.295
682                         if (match(argp"-mbig-endian")) {
683                                 bigendian = 1;
684                                 strlist_append(&compiler_flagsargp);
685                                 break;
686                         }
687                         if (match(argp"-mlittle-endian")) {
688                                 bigendian = 0;
689                                 strlist_append(&compiler_flagsargp);
690                                 break;
691                         }
692                         if (match(argp"-msoft-float")) {
693                                 softfloat = 1;
694                                 strlist_append(&compiler_flagsargp);
695                                 break;
696                         }
697 #endif
ragge
1.306
698 #if defined(mach_mips) || defined(mach_mips64)
plunky
1.295
699                         if (match(argp"-mhard-float")) {
700                                 softfloat = 0;
701                                 strlist_append(&compiler_flagsargp);
702                                 break;
703                         }
704 #endif
ragge
1.225
705                         strlist_append(&middle_linker_flagsargp);
ragge
1.220
706                         if (argp[2] == 0) {
ragge
1.225
707                                 t = nxtopt(0);
708                                 strlist_append(&middle_linker_flagst);
ragge
1.220
709                         }
710                         break;
ragge
1.128
711
ragge
1.220
712                 case 'n'/* handle -n flags */
713                         if (strcmp(argp"-nostdinc") == 0)
714                                 nostdinc++;
715                         else if (strcmp(argp"-nostdlib") == 0) {
716                                 nostdlib++;
717                                 nostartfiles++;
718                         } else if (strcmp(argp"-nostartfiles") == 0)
719                                 nostartfiles = 1;
720                         else if (strcmp(argp"-nodefaultlibs") == 0)
721                                 nostdlib++;
722                         else
plunky
1.257
723                                 oerror(argp);
ragge
1.220
724                         break;
ragge
1.128
725
ragge
1.220
726                 case 'p':
727                         if (strcmp(argp"-pg") == 0 ||
728                             strcmp(argp"-p") == 0)
729                                 pgflag++;
730                         else if (strcmp(argp"-pthread") == 0)
731                                 pthreads++;
732                         else if (strcmp(argp"-pipe") == 0)
733                                 /* NOTHING YET */;
734                         else if (strcmp(argp"-pedantic") == 0)
735                                 /* NOTHING YET */;
ragge
1.254
736                         else if ((t = argnxt(argp"-print-prog-name="))) {
737                                 fname = t;
738                                 printprogname = 1;
739                         } else if ((t = argnxt(argp"-print-file-name="))) {
740                                 fname = t;
741                                 printfilename = 1;
742                         } else if (match(argp"-print-libgcc-file-name")) {
743                                 fname = "libpcc.a";
744                                 printfilename = 1;
ragge
1.220
745                         } else
746                                 oerror(argp);
747                         break;
ragge
1.128
748
ragge
1.299
749                 case 'R':
750                         if (argp[2] == 0)
751                                 argp = cat(argpnxtopt(0));
752                         strlist_append(&middle_linker_flagsargp);
753                         break;
754
ragge
1.220
755                 case 'r':
756                         rflag = 1;
757                         break;
gmcgarry
1.145
758
ragge
1.240
759                 case 'T':
760                         strlist_append(&inputsargp);
mickey
1.241
761                         if (argp[2] == 0 ||
762                             strcmp(argp"-Ttext") == 0 ||
763                             strcmp(argp"-Tdata") == 0 ||
764                             strcmp(argp"-Tbss") == 0)
765                                 strlist_append(&inputsnxtopt(0));
ragge
1.240
766                         break;
ragge
1.255
767
768                 case 's':
769                         if (match(argp"-shared")) {
770                                 shared = 1;
771                         } else if (match(argp"-static")) {
772                                 Bstatic = 1;
773                         } else if (match(argp"-symbolic")) {
774                                 strlist_append(&middle_linker_flags,
775                                     "-Bsymbolic");
ragge
1.307
776                         } else if (strncmp(argp"-std="5) == 0) {
777                                 if (strcmp(&argp[5], "c11") == 0)
778                                         cstd = SC11;
779                                 else if (strcmp(&argp[5], "gnu99") == 0 ||
ragge
1.255
780                                     strcmp(&argp[5], "gnu9x") == 0)
ragge
1.302
781                                         cstd = SGNU99;
ragge
1.307
782                                 else if (strcmp(&argp[5], "c89") == 0)
ragge
1.302
783                                         cstd = SC89;
ragge
1.307
784                                 else if (strcmp(&argp[5], "gnu89") == 0)
ragge
1.302
785                                         cstd = SGNU89;
ragge
1.307
786                                 else if (strcmp(&argp[5], "c99") == 0)
ragge
1.302
787                                         cstd = SC99;
ragge
1.307
788                                 else
789                                         oerror(argp);
790                         } else if (match(argp"-s")) {
791                                 strlist_append(&middle_linker_flagsargp);
792                         } else
plunky
1.257
793                                 oerror(argp);
ragge
1.220
794                         break;
ragge
1.255
795
ragge
1.220
796                 case 'S':
ragge
1.226
797                         Sflag++;
ragge
1.220
798                         cflag++;
799                         break;
ragge
1.255
800
801                 case 't':
802                         tflag++;
ragge
1.302
803                         cstd = STRAD;
ragge
1.255
804                         break;
805
ragge
1.220
806                 case 'o':
807                         if (outfile)
808                                 errorx(8"too many -o");
809                         outfile = nxtopt("-o");
810                         break;
ragge
1.255
811
ragge
1.220
812                 case 'O':
813                         if (argp[2] == '\0')
ragge
1.307
814                                 /* gcc does -O1, clang does -O2 */
815                                 Oflag = 1;      /* do what gcc does */
ragge
1.226
816                         else if (argp[3] == '\0' &&
817                             isdigit((unsigned char)argp[2]))
ragge
1.220
818                                 Oflag = argp[2] - '0';
819                         else if (argp[3] == '\0' && argp[2] == 's')
820                                 Oflag = 1;      /* optimize for space only */
821                         else
822                                 oerror(argp);
823                         break;
ragge
1.255
824
ragge
1.220
825                 case 'P':
ragge
1.221
826                         strlist_append(&preprocessor_flagsargp);
827                         break;
828
ragge
1.220
829                 case 'M':
ragge
1.233
830                         needM = 1;
831                         if (match(argp"-M")) {
ragge
1.223
832                                 Mflag++;
833                                 strlist_append(&depflagsargp);
ragge
1.233
834                         } else if (match(argp"-MP")) {
ragge
1.223
835                                 strlist_append(&depflags"-xMP");
ragge
1.233
836                         } else if (match(argp"-MF")) {
837                                 MFfile = nxtopt("-MF");
838                         } else if (match(argp"-MT") || match(argp"-MQ")) {
ragge
1.226
839                                 t = cat("-xMT,"nxtopt("-MT"));
ragge
1.220
840                                 t[3] = argp[2];
ragge
1.223
841                                 strlist_append(&depflagst);
ragge
1.233
842                         } else if (match(argp"-MD")) {
843                                 MDflag++;
844                                 needM = 0;
845                                 strlist_append(&depflags"-M");
ragge
1.279
846                         } else if (match(argp"-MMD")) {
847                                 MMDflag++;
848                                 needM = 0;
849                                 strlist_append(&depflags"-M");
850                                 strlist_append(&depflags"-xMMD");
ragge
1.233
851                         } else
ragge
1.220
852                                 oerror(argp);
853                         break;
ragge
1.128
854
ragge
1.220
855                 case 'v':
856                         printf("%s\n"VERSSTR);
857                         vflag++;
858                         break;
ragge
1.128
859
ragge
1.283
860                 case 'w'/* no warnings at all emitted */
861                         strlist_append(&compiler_flags"-w");
862                         break;
ragge
1.282
863
ragge
1.255
864                 case 'W'/* Ignore (most of) W-flags */
865                         if ((t = argnxt(argp"-Wl,"))) {
866                                 u = strtok(t",");
867                                 do {
868                                         strlist_append(&inputsu);
869                                 } while ((u = strtok(NULL",")) != NULL);
870                         } else if ((t = argnxt(argp"-Wa,"))) {
871                                 u = strtok(t",");
872                                 do {
873                                         strlist_append(&assembler_flagsu);
874                                 } while ((u = strtok(NULL",")) != NULL);
875                         } else if ((t = argnxt(argp"-Wc,"))) {
876                                 u = strtok(t",");
877                                 do {
878                                         strlist_append(&compiler_flagsu);
879                                 } while ((u = strtok(NULL",")) != NULL);
880                         } else if ((t = argnxt(argp"-Wp,"))) {
881                                 u = strtok(t",");
882                                 do {
883                                         strlist_append(&preprocessor_flagsu);
884                                 } while ((u = strtok(NULL",")) != NULL);
885                         } else if (strcmp(argp"-Werror") == 0) {
886                                 strlist_append(&compiler_flags"-Werror");
plunky
1.261
887                                 strlist_append(&preprocessor_flags"-E");
ragge
1.255
888                         } else if (strcmp(argp"-Wall") == 0) {
889                                 for (Wf = WflagsWf->nameWf++)
890                                         if (Wf->flags & INWALL)
891                                                 strlist_append(&compiler_flags,
892                                                     cat("-W"Wf->name));
ragge
1.309
893                         } else if (strcmp(argp"-Wextra") == 0 ||
894                                    strcmp(argp"-W") == 0) {
895                                 for (Wf = WflagsWf->nameWf++)
896                                         if (Wf->flags & INWEXTRA)
897                                                 strlist_append(&compiler_flags,
898                                                     cat("-W"Wf->name));
ragge
1.255
899                         } else if (strcmp(argp"-WW") == 0) {
900                                 for (Wf = WflagsWf->nameWf++)
901                                         strlist_append(&compiler_flags,
902                                             cat("-W"Wf->name));
903                         } else {
904                                 /* pass through, if supported */
905                                 t = &argp[2];
906                                 if (strncmp(t"no-"3) == 0)
907                                         t += 3;
908                                 if (strncmp(t"error="6) == 0)
909                                         t += 6;
910                                 for (Wf = WflagsWf->nameWf++) {
911                                         if (strcmp(tWf->name) == 0)
912                                                 strlist_append(&compiler_flags,
913                                                     argp);
914                                 }
915                         }
916                         break;
917
918                 case 'x':
919                         t = nxtopt("-x");
plunky
1.267
920                         if (match(t"none"))
921                                 strlist_append(&inputs")");
922                         else if (match(t"c"))
ragge
1.255
923                           &