Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20150719142557

Diff

Diff from 1.300 to:

Annotations

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

Annotated File View

ragge
1.300
1 /*      $Id: cc.c,v 1.300 2015/07/19 14:25: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.128
103
plunky
1.293
104 #ifdef  _WIN32
ragge
1.128
105 #include <windows.h>
106 #include <process.h>
107 #include <io.h>
gmcgarry
1.179
108 #define F_OK    0x00
109 #define R_OK    0x04
110 #define W_OK    0x02
111 #define X_OK    R_OK
ragge
1.128
112 #endif
113
114 #include "compat.h"
115
ragge
1.167
116 #include "macdefs.h"
ragge
1.218
117
118 #include "xalloc.h"
119 #include "strlist.h"
ragge
1.226
120
121 #include "ccconfig.h"
ragge
1.128
122 /* C command */
123
124 #define MKS(x) _MKS(x)
125 #define _MKS(x) #x
126
ragge
1.226
127 /* default program names in pcc */
128 /* May be overridden if cross-compiler is generated */
129 #ifndef CPPROGNAME
130 #define CPPROGNAME      "cpp"   /* cc used as cpp */
ragge
1.128
131 #endif
132 #ifndef PREPROCESSOR
ragge
1.226
133 #define PREPROCESSOR    "cpp"   /* "real" preprocessor name */
ragge
1.128
134 #endif
135 #ifndef COMPILER
gmcgarry
1.138
136 #define COMPILER        "ccom"
ragge
1.128
137 #endif
ragge
1.226
138 #ifndef CXXCOMPILER
139 #define CXXCOMPILER     "cxxcom"
140 #endif
ragge
1.128
141 #ifndef ASSEMBLER
142 #define ASSEMBLER       "as"
143 #endif
144 #ifndef LINKER
145 #define LINKER          "ld"
146 #endif
ragge
1.226
147 char    *passp = PREPROCESSOR;
148 char    *pass0 = COMPILER;
149 char    *passxx0 = CXXCOMPILER;
150 char    *as = ASSEMBLER;
151 char    *ld = LINKER;
152 char    *sysroot = "", *isysroot;
153
154
155 /* crt files using pcc default names */
156 #ifndef CRTBEGIN_S
157 #define CRTBEGIN_S      "crtbeginS.o"
158 #endif
159 #ifndef CRTEND_S
160 #define CRTEND_S        "crtendS.o"
161 #endif
162 #ifndef CRTBEGIN_T
163 #define CRTBEGIN_T      "crtbeginT.o"
164 #endif
165 #ifndef CRTEND_T
166 #define CRTEND_T        "crtendT.o"
167 #endif
168 #ifndef CRTBEGIN
169 #define CRTBEGIN        "crtbegin.o"
170 #endif
171 #ifndef CRTEND
172 #define CRTEND          "crtend.o"
173 #endif
174 #ifndef CRTI
175 #define CRTI            "crti.o"
176 #endif
177 #ifndef CRTN
178 #define CRTN            "crtn.o"
179 #endif
180 #ifndef CRT0
181 #define CRT0            "crt0.o"
182 #endif
183 #ifndef GCRT0
184 #define GCRT0           "gcrt0.o"
185 #endif
186
187 /* preprocessor stuff */
188 #ifndef STDINC
189 #define STDINC          "/usr/include/"
190 #endif
ragge
1.286
191 #ifdef MULTIARCH_PATH
192 #define STDINC_MA       STDINC MULTIARCH_PATH "/"
193 #endif
194
ragge
1.226
195
196 char *cppadd[] = CPPADD;
197 char *cppmdadd[] = CPPMDADD;
ragge
1.128
198
ragge
1.226
199 /* Default libraries and search paths */
200 #ifndef PCCLIBDIR       /* set by autoconf */
201 #define PCCLIBDIR       NULL
202 #endif
plunky
1.289
203 #ifndef LIBDIR
204 #define LIBDIR          "/usr/lib/"
205 #endif
ragge
1.226
206 #ifndef DEFLIBDIRS      /* default library search paths */
ragge
1.286
207 #ifdef MULTIARCH_PATH
plunky
1.289
208 #define DEFLIBDIRS      { LIBDIR, LIBDIR MULTIARCH_PATH "/", 0 }
plunky
1.287
209 #else
plunky
1.289
210 #define DEFLIBDIRS      { LIBDIR, 0 }
ragge
1.286
211 #endif
ragge
1.226
212 #endif
213 #ifndef DEFLIBS         /* default libraries included */
214 #define DEFLIBS         { "-lpcc", "-lc", "-lpcc", 0 }
215 #endif
216 #ifndef DEFPROFLIBS     /* default profiling libraries */
217 #define DEFPROFLIBS     { "-lpcc", "-lc_p", "-lpcc", 0 }
218 #endif
219 #ifndef DEFCXXLIBS      /* default c++ libraries */
220 #define DEFCXXLIBS      { "-lp++", "-lpcc", "-lc", "-lpcc", 0 }
221 #endif
222 #ifndef STARTLABEL
223 #define STARTLABEL "__start"
224 #endif
plunky
1.295
225 #ifndef DYNLINKARG
226 #define DYNLINKARG      "-dynamic-linker"
227 #endif
228 #ifndef DYNLINKLIB
229 #define DYNLINKLIB      NULL
230 #endif
ragge
1.174
231
plunky
1.295
232 char *dynlinkarg = DYNLINKARG;
233 char *dynlinklib = DYNLINKLIB;
ragge
1.226
234 char *pcclibdir = PCCLIBDIR;
235 char *deflibdirs[] = DEFLIBDIRS;
236 char *deflibs[] = DEFLIBS;
237 char *defproflibs[] = DEFPROFLIBS;
238 char *defcxxlibs[] = DEFCXXLIBS;
239
ragge
1.254
240 char    *outfile, *MFfile, *fname;
ragge
1.220
241 static char **lav;
242 static int lac;
ragge
1.226
243 static char *find_file(const char *filestruct strlist *pathint mode);
244 static int preprocess_input(char *inputchar *outputint dodep);
245 static int compile_input(char *inputchar *output);
246 static int assemble_input(char *inputchar *output);
247 static int run_linker(void);
248 static int strlist_exec(struct strlist *l);
249
plunky
1.185
250 char *cat(const char *, const char *);
gmcgarry
1.150
251 char *setsuf(char *, char);
ragge
1.198
252 int cxxsuf(char *);
ragge
1.128
253 int getsuf(char *);
ragge
1.198
254 char *getsufp(char *s);
ragge
1.128
255 int main(intchar *[]);
256 void errorx(intchar *, ...);
257 int cunlink(char *);
ragge
1.226
258 void exandrm(char *);
ragge
1.128
259 void dexit(int);
260 void idexit(int);
261 char *gettmp(void);
ragge
1.219
262 void oerror(char *);
ragge
1.218
263 char *argnxt(char *, char *);
ragge
1.220
264 char *nxtopt(char *o);
ragge
1.222
265 void setup_cpp_flags(void);
ragge
1.226
266 void setup_ccom_flags(void);
267 void setup_as_flags(void);
268 void setup_ld_flags(void);
ragge
1.222
269 static void expand_sysroot(void);
plunky
1.293
270 #ifdef  _WIN32
ragge
1.128
271 char *win32pathsubst(char *);
plunky
1.250
272 char *win32commandline(struct strlist *l);
ragge
1.128
273 #endif
274 int     sspflag;
plunky
1.214
275 int     freestanding;
ragge
1.226
276 int     Sflag;
ragge
1.128
277 int     cflag;
278 int     gflag;
gmcgarry
1.145
279 int     rflag;
ragge
1.128
280 int     vflag;
plunky
1.296
281 int     noexec/* -### */
ragge
1.128
282 int     tflag;
283 int     Eflag;
284 int     Oflag;
285 int     kflag;  /* generate PIC/pic code */
286 #define F_PIC   1
287 #define F_pic   2
ragge
1.279
288 int     MflagneedMMDflagMMDflag;  /* dependencies only */
ragge
1.128
289 int     pgflag;
290 int     Xflag;
291 int     nostartfilesBstaticshared;
292 int     nostdincnostdlib;
293 int     pthreads;
ragge
1.239
294 int     xgnu89xgnu99;
ragge
1.128
295 int     ascpp;
plunky
1.196
296 #ifdef CHAR_UNSIGNED
plunky
1.209
297 int     xuchar = 1;
plunky
1.196
298 #else
plunky
1.209
299 int     xuchar = 0;
plunky
1.196
300 #endif
ragge
1.198
301 int     cxxflag;
ragge
1.216
302 int     cppflag;
ragge
1.254
303 int     printprognameprintfilename;
ragge
1.128
304
plunky
1.295
305 #ifdef SOFTFLOAT
306 int     softfloat = 1;
307 #else
308 int     softfloat = 0;
309 #endif
310
311 #ifdef TARGET_BIG_ENDIAN
312 int     bigendian = 1;
313 #else
314 int     bigendian = 0;
315 #endif
316
ragge
1.164
317 #ifdef mach_amd64
318 int amd64_i386;
319 #endif
ragge
1.128
320
ragge
1.218
321 #define match(a,b)      (strcmp(a,b) == 0)
322
ragge
1.128
323 /* handle gcc warning emulations */
324 struct Wflags {
325         char *name;
326         int flags;
327 #define INWALL          1
328 Wflags[] = {
plunky
1.215
329         { "truncate"0 },
330         { "strict-prototypes"0 },
331         { "missing-prototypes"0 },
332         { "implicit-int"INWALL },
333         { "implicit-function-declaration"INWALL },
334         { "shadow"0 },
335         { "pointer-sign"INWALL },
336         { "sign-compare"0 },
337         { "unknown-pragmas"INWALL },
338         { "unreachable-code"0 },
plunky
1.275
339         { "deprecated-declarations"0 },
plunky
1.276
340         { "attributes"0 },
plunky
1.215
341         { NULL0 },
ragge
1.128
342 };
343
ragge
1.158
344 #ifndef USHORT
345 /* copied from mip/manifest.h */
346 #define USHORT          5
347 #define INT             6
348 #define UNSIGNED        7
349 #endif
350
ragge
1.157
351 /*
352  * Wide char defines.
353  */
354 #if WCHAR_TYPE == USHORT
355 #define WCT "short unsigned int"
356 #define WCM "65535U"
ragge
1.158
357 #if WCHAR_SIZE != 2
358 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
359 #endif
ragge
1.157
360 #elif WCHAR_TYPE == INT
361 #define WCT "int"
362 #define WCM "2147483647"
ragge
1.158
363 #if WCHAR_SIZE != 4
364 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
365 #endif
ragge
1.157
366 #elif WCHAR_TYPE == UNSIGNED
367 #define WCT "unsigned int"
ragge
1.158
368 #define WCM "4294967295U"
369 #if WCHAR_SIZE != 4
370 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
371 #endif
372 #else
373 #error WCHAR_TYPE not defined or invalid
ragge
1.157
374 #endif
375
ragge
1.160
376 #ifdef GCC_COMPAT
377 #ifndef REGISTER_PREFIX
378 #define REGISTER_PREFIX ""
379 #endif
380 #ifndef USER_LABEL_PREFIX
381 #define USER_LABEL_PREFIX ""
382 #endif
383 #endif
384
plunky
1.192
385 #ifndef PCC_WINT_TYPE
386 #define PCC_WINT_TYPE "unsigned int"
387 #endif
388
389 #ifndef PCC_SIZE_TYPE
390 #define PCC_SIZE_TYPE "unsigned long"
391 #endif
392
ragge
1.161
393 #ifndef PCC_PTRDIFF_TYPE
394 #define PCC_PTRDIFF_TYPE "long int"
395 #endif
396
ragge
1.216
397
ragge
1.218
398 struct strlist preprocessor_flags;
ragge
1.223
399 struct strlist depflags;
ragge
1.219
400 struct strlist incdirs;
ragge
1.221
401 struct strlist user_sysincdirs;
402 struct strlist includes;
ragge
1.222
403 struct strlist sysincdirs;
ragge
1.223
404 struct strlist dirafterdirs;
ragge
1.222
405 struct strlist crtdirs;
406 struct strlist libdirs;
407 struct strlist progdirs;
ragge
1.224
408 struct strlist early_linker_flags;
409 struct strlist middle_linker_flags;
410 struct strlist late_linker_flags;
411 struct strlist inputs;
ragge
1.225
412 struct strlist assembler_flags;
413 struct strlist temp_outputs;
ragge
1.226
414 struct strlist compiler_flags;
ragge
1.218
415
ragge
1.128
416 int
417 main(int argcchar *argv[])
418 {
419         struct Wflags *Wf;
ragge
1.226
420         struct string *s;
ragge
1.218
421         char *t, *u, *argp;
ragge
1.239
422         char *msuffix;
ragge
1.226
423         int ninputj;
ragge
1.222
424
ragge
1.220
425         lav = argv;
426         lac = argc;
plunky
1.242
427         ninput = 0;
ragge
1.128
428
ragge
1.222
429         strlist_init(&crtdirs);
430         strlist_init(&libdirs);
431         strlist_init(&progdirs);
ragge
1.218
432         strlist_init(&preprocessor_flags);
ragge
1.219
433         strlist_init(&incdirs);
ragge
1.221
434         strlist_init(&user_sysincdirs);
435         strlist_init(&includes);
ragge
1.222
436         strlist_init(&sysincdirs);
ragge
1.223
437         strlist_init(&dirafterdirs);
438         strlist_init(&depflags);
ragge
1.224
439         strlist_init(&early_linker_flags);
440         strlist_init(&middle_linker_flags);
441         strlist_init(&late_linker_flags);
442         strlist_init(&inputs);
ragge
1.225
443         strlist_init(&assembler_flags);
444         strlist_init(&temp_outputs);
ragge
1.226
445         strlist_init(&compiler_flags);
ragge
1.218
446
ragge
1.216
447         if ((t = strrchr(argv[0], '/')))
ragge
1.226
448                 t++;
ragge
1.229
449         else
450                 t = argv[0];
ragge
1.226
451
452         if (match(t"p++")) {
ragge
1.198
453                 cxxflag = 1;
ragge
1.226
454         } else if (match(t"cpp") || match(tCPPROGNAME)) {
455                 Eflag = cppflag = 1;
ragge
1.198
456         }
457
plunky
1.260
458 #ifdef PCC_EARLY_SETUP
459         PCC_EARLY_SETUP
ragge
1.246
460 #endif
461
plunky
1.293
462 #ifdef _WIN32
ragge
1.128
463         /* have to prefix path early.  -B may override */
464         incdir = win32pathsubst(incdir);
gmcgarry
1.153
465         altincdir = win32pathsubst(altincdir);
gmcgarry
1.136
466         libdir = win32pathsubst(libdir);
plunky
1.200
467 #ifdef PCCINCDIR
ragge
1.128
468         pccincdir = win32pathsubst(pccincdir);
plunky
1.199
469         pxxincdir = win32pathsubst(pxxincdir);
plunky
1.200
470 #endif
471 #ifdef PCCLIBDIR
ragge
1.128
472         pcclibdir = win32pathsubst(pcclibdir);
plunky
1.200
473 #endif
ragge
1.128
474         passp = win32pathsubst(passp);
475         pass0 = win32pathsubst(pass0);
gmcgarry
1.180
476 #ifdef STARTFILES
477         for (i = 0startfiles[i] != NULLi++)
478                 startfiles[i] = win32pathsubst(startfiles[i]);
479         for (i = 0endfiles[i] != NULLi++)
480                 endfiles[i] = win32pathsubst(endfiles[i]);
481 #endif
482 #ifdef STARTFILES_T
483         for (i = 0startfiles_T[i] != NULLi++)
484                 startfiles_T[i] = win32pathsubst(startfiles_T[i]);
485         for (i = 0endfiles_T[i] != NULLi++)
486                 endfiles_T[i] = win32pathsubst(endfiles_T[i]);
487 #endif
488 #ifdef STARTFILES_S
489         for (i = 0startfiles_S[i] != NULLi++)
490                 startfiles_S[i] = win32pathsubst(startfiles_S[i]);
491         for (i = 0endfiles_S[i] != NULLi++)
492                 endfiles_S[i] = win32pathsubst(endfiles_S[i]);
493 #endif
ragge
1.128
494 #endif
495
ragge
1.220
496         while (--lac) {
497                 ++lav;
498                 argp = *lav;
499
plunky
1.260
500 #ifdef PCC_EARLY_ARG_CHECK
501                 PCC_EARLY_ARG_CHECK
ragge
1.227
502 #endif
503
ragge
1.225
504                 if (*argp != '-' || match(argp"-")) {
505                         /* Check for duplicate .o files. */
506                         if (getsuf(argp) == 'o') {
507                                 j = 0;
508                                 STRLIST_FOREACH(s, &inputs)
509                                         if (match(argps->value))
510                                                 j++;
511                                 if (j)
512                                         continue/* skip it */
513                         }
514                         strlist_append(&inputsargp);
plunky
1.242
515                         ninput++;
ragge
1.225
516                         continue;
517                 }
ragge
1.220
518
519                 switch (argp[1]) {
520                 default:
plunky
1.257
521                         oerror(argp);
ragge
1.220
522                         break;
ragge
1.128
523
plunky
1.296
524                 case '#':
525                         if (match(argp"-###")) {
526                                 printf("%s\n"VERSSTR);
527                                 vflag++;
528                                 noexec++;
529                         } else
530                                 oerror(argp);
531                         break;
532
ragge
1.220
533                 case '-'/* double -'s */
534                         if (match(argp"--version")) {
535                                 printf("%s\n"VERSSTR);
536                                 return 0;
537                         } else if (strncmp(argp"--sysroot="10) == 0) {
538                                 sysroot = argp + 10;
gmcgarry
1.298
539                         } else if (strncmp(argp"--sysroot"9) == 0) {
540                                 sysroot = nxtopt(argp);
ragge
1.220
541                         } else if (strcmp(argp"--param") == 0) {
542                                 /* NOTHING YET */;
543                                 (void)nxtopt(0); /* ignore arg */
544                         } else
plunky
1.257
545                                 oerror(argp);
ragge
1.220
546                         break;
ragge
1.128
547
ragge
1.220
548                 case 'B'/* other search paths for binaries */
ragge
1.224
549                         t = nxtopt("-B");
550                         strlist_append(&crtdirst);
551                         strlist_append(&libdirst);
552                         strlist_append(&progdirst);
ragge
1.220
553                         break;
ragge
1.128
554
ragge
1.220
555                 case 'C':
556                         if (match(argp"-C") || match(argp"-CC"))
557                                 strlist_append(&preprocessor_flagsargp);
558                         else
559                                 oerror(argp);
560                         break;
ragge
1.218
561
ragge
1.255
562                 case 'c':
563                         cflag++;
564                         break;
565
plunky
1.277
566                 case 'd'/* debug options */
567                         for (t = &argp[2]; *tt++) {
568                                 if (*t == 'M')
569                                         strlist_append(&preprocessor_flags"-dM");
570
571                                 /* ignore others */
572                         }
ragge
1.220
573                         break;
ragge
1.255
574
575                 case 'E':
576                         Eflag++;
ragge
1.220
577                         break;
ragge
1.128
578
ragge
1.220
579                 case 'f'/* GCC compatibility flags */
ragge
1.246
580                         u = &argp[2];
581                         j = 0;
582                         if (strncmp(u"no-"3) == 0)
583                                 j = 1u += 3;
584                         if (match(u"PIC") || match(u"pic")) {
585                                 kflag = j ? 0 : *u == 'P' ? F_PIC : F_pic;
586                         } else if (match(u"freestanding")) {
587                                 freestanding = j ? 0 : 1;
588                         } else if (match(u"signed-char")) {
589                                 xuchar = j ? 1 : 0;
590                         } else if (match(u"unsigned-char")) {
591                                 xuchar = j ? 0 : 1;
plunky
1.248
592                         } else if (match(u"stack-protector") ||
593                             match(u"stack-protector-all")) {
ragge
1.246
594                                 sspflag = j ? 0 : 1;
ragge
1.220
595                         }
596                         /* silently ignore the rest */
597                         break;
ragge
1.128
598
ragge
1.220
599                 case 'g'/* create debug output */
600                         if (argp[2] == '0')
601                                 gflag = 0;
602                         else
603                                 gflag++;
604                         break;
ragge
1.128
605
ragge
1.255
606
607                 case 'X':
608                         Xflag++;
609                         break;
610
ragge
1.220
611                 case 'D':
612                 case 'U':
ragge
1.221
613                         strlist_append(&preprocessor_flagsargp);
ragge
1.220
614                         if (argp[2] != 0)
ragge
1.219
615                                 break;
ragge
1.221
616                         strlist_append(&preprocessor_flagsnxtopt(argp));
617                         break;
618
619                 case 'I'/* Add include dirs */
620                         strlist_append(&incdirsnxtopt("-I"));
ragge
1.220
621                         break;
ragge
1.219
622
ragge
1.220
623                 case 'i':
ragge
1.221
624                         if (match(argp"-isystem")) {
625                                 strlist_append(&user_sysincdirsnxtopt(0));
626                         } else if (match(argp"-include")) {
627                                 strlist_append(&includesnxtopt(0));
ragge
1.222
628                         } else if (match(argp"-isysroot")) {
629                                 isysroot = nxtopt(0);
ragge
1.220
630                         } else if (strcmp(argp"-idirafter") == 0) {
ragge
1.223
631                                 strlist_append(&dirafterdirsnxtopt(0));
ragge
1.220
632                         } else
plunky
1.257
633                                 oerror(argp);
ragge
1.220
634                         break;
ragge
1.128
635
ragge
1.220
636                 case 'k'/* generate PIC code */
ragge
1.247
637                         kflag = argp[2] ? argp[2] - '0' : F_pic;
ragge
1.220
638                         break;
ragge
1.128
639
ragge
1.224
640                 case 'l':
641                 case 'L':
ragge
1.226
642                         if (argp[2] == 0)
ragge
1.245
643                                 argp = cat(argpnxtopt(0));
644                         strlist_append(&inputsargp);
ragge
1.224
645                         break;
646
ragge
1.220
647                 case 'm'/* target-dependent options */
ragge
1.285
648                         if (strncmp(argp"-march="6) == 0) {
649                                 strlist_append(&compiler_flagsargp);
650                                 break;
651                         }
ragge
1.164
652 #ifdef mach_amd64
ragge
1.220
653                         /* need to call i386 ccom for this */
ragge
1.262
654                         if (strcmp(argp"-melf_i386") == 0) {
ragge
1.220
655                                 pass0 = LIBEXECDIR "/ccom_i386";
656                                 amd64_i386 = 1;
657                                 break;
658                         }
ragge
1.164
659 #endif
plunky
1.295
660 #if defined(mach_arm) || defined(mach_mips)
661                         if (match(argp"-mbig-endian")) {
662                                 bigendian = 1;
663                                 strlist_append(&compiler_flagsargp);
664                                 break;
665                         }
666                         if (match(argp"-mlittle-endian")) {
667                                 bigendian = 0;
668                                 strlist_append(&compiler_flagsargp);
669                                 break;
670                         }
671                         if (match(argp"-msoft-float")) {
672                                 softfloat = 1;
673                                 strlist_append(&compiler_flagsargp);
674                                 break;
675                         }
676 #endif
677 #if defined(mach_mips)
678                         if (match(argp"-mhard-float")) {
679                                 softfloat = 0;
680                                 strlist_append(&compiler_flagsargp);
681                                 break;
682                         }
683 #endif
ragge
1.225
684                         strlist_append(&middle_linker_flagsargp);
ragge
1.220
685                         if (argp[2] == 0) {
ragge
1.225
686                                 t = nxtopt(0);
687                                 strlist_append(&middle_linker_flagst);
ragge
1.220
688                         }
689                         break;
ragge
1.128
690
ragge
1.220
691                 case 'n'/* handle -n flags */
692                         if (strcmp(argp"-nostdinc") == 0)
693                                 nostdinc++;
694                         else if (strcmp(argp"-nostdlib") == 0) {
695                                 nostdlib++;
696                                 nostartfiles++;
697                         } else if (strcmp(argp"-nostartfiles") == 0)
698                                 nostartfiles = 1;
699                         else if (strcmp(argp"-nodefaultlibs") == 0)
700                                 nostdlib++;
701                         else
plunky
1.257
702                                 oerror(argp);
ragge
1.220
703                         break;
ragge
1.128
704
ragge
1.220
705                 case 'p':
706                         if (strcmp(argp"-pg") == 0 ||
707                             strcmp(argp"-p") == 0)
708                                 pgflag++;
709                         else if (strcmp(argp"-pthread") == 0)
710                                 pthreads++;
711                         else if (strcmp(argp"-pipe") == 0)
712                                 /* NOTHING YET */;
713                         else if (strcmp(argp"-pedantic") == 0)
714                                 /* NOTHING YET */;
ragge
1.254
715                         else if ((t = argnxt(argp"-print-prog-name="))) {
716                                 fname = t;
717                                 printprogname = 1;
718                         } else if ((t = argnxt(argp"-print-file-name="))) {
719                                 fname = t;
720                                 printfilename = 1;
721                         } else if (match(argp"-print-libgcc-file-name")) {
722                                 fname = "libpcc.a";
723                                 printfilename = 1;
ragge
1.220
724                         } else
725                                 oerror(argp);
726                         break;
ragge
1.128
727
ragge
1.299
728                 case 'R':
729                         if (argp[2] == 0)
730                                 argp = cat(argpnxtopt(0));
731                         strlist_append(&middle_linker_flagsargp);
732                         break;
733
ragge
1.220
734                 case 'r':
735                         rflag = 1;
736                         break;
gmcgarry
1.145
737
ragge
1.240
738                 case 'T':
739                         strlist_append(&inputsargp);
mickey
1.241
740                         if (argp[2] == 0 ||
741                             strcmp(argp"-Ttext") == 0 ||
742                             strcmp(argp"-Tdata") == 0 ||
743                             strcmp(argp"-Tbss") == 0)
744                                 strlist_append(&inputsnxtopt(0));
ragge
1.240
745                         break;
ragge
1.255
746
747                 case 's':
748                         if (match(argp"-shared")) {
749                                 shared = 1;
750                         } else if (match(argp"-static")) {
751                                 Bstatic = 1;
752                         } else if (match(argp"-symbolic")) {
753                                 strlist_append(&middle_linker_flags,
754                                     "-Bsymbolic");
755                         } else if (strncmp(argp"-std"4) == 0) {
756                                 if (strcmp(&argp[5], "gnu99") == 0 ||
757                                     strcmp(&argp[5], "gnu9x") == 0)
758                                         xgnu99 = 1;
759                                 if (strcmp(&argp[5], "gnu89") == 0)
760                                         xgnu89 = 1;
761                         } else
plunky
1.257
762                                 oerror(argp);
ragge
1.220
763                         break;
ragge
1.255
764
ragge
1.220
765                 case 'S':
ragge
1.226
766                         Sflag++;
ragge
1.220
767                         cflag++;
768                         break;
ragge
1.255
769
770                 case 't':
771                         tflag++;
772                         break;
773
ragge
1.220
774                 case 'o':
775                         if (outfile)
776                                 errorx(8"too many -o");
777                         outfile = nxtopt("-o");
778                         break;
ragge
1.255
779
ragge
1.220
780                 case 'O':
781                         if (argp[2] == '\0')
782                                 Oflag++;
ragge
1.226
783                         else if (argp[3] == '\0' &&
784                             isdigit((unsigned char)argp[2]))
ragge
1.220
785                                 Oflag = argp[2] - '0';
786                         else if (argp[3] == '\0' && argp[2] == 's')
787                                 Oflag = 1;      /* optimize for space only */
788                         else
789                                 oerror(argp);
790                         break;
ragge
1.255
791
ragge
1.220
792                 case 'P':
ragge
1.221
793                         strlist_append(&preprocessor_flagsargp);
794                         break;
795
ragge
1.220
796                 case 'M':
ragge
1.233
797                         needM = 1;
798                         if (match(argp"-M")) {
ragge
1.223
799                                 Mflag++;
800                                 strlist_append(&depflagsargp);
ragge
1.233
801                         } else if (match(argp"-MP")) {
ragge
1.223
802                                 strlist_append(&depflags"-xMP");
ragge
1.233
803                         } else if (match(argp"-MF")) {
804                                 MFfile = nxtopt("-MF");
805                         } else if (match(argp"-MT") || match(argp"-MQ")) {
ragge
1.226
806                                 t = cat("-xMT,"nxtopt("-MT"));
ragge
1.220
807                                 t[3] = argp[2];
ragge
1.223
808                                 strlist_append(&depflagst);
ragge
1.233
809                         } else if (match(argp"-MD")) {
810                                 MDflag++;
811                                 needM = 0;
812                                 strlist_append(&depflags"-M");
ragge
1.279
813                         } else if (match(argp"-MMD")) {
814                                 MMDflag++;
815                                 needM = 0;
816                                 strlist_append(&depflags"-M");
817                                 strlist_append(&depflags"-xMMD");
ragge
1.233
818                         } else
ragge
1.220
819                                 oerror(argp);
820                         break;
ragge
1.128
821
ragge
1.220
822                 case 'v':
823                         printf("%s\n"VERSSTR);
824                         vflag++;
825                         break;
ragge
1.128
826
ragge
1.283
827                 case 'w'/* no warnings at all emitted */
828                         strlist_append(&compiler_flags"-w");
829                         break;
ragge
1.282
830
ragge
1.255
831                 case 'W'/* Ignore (most of) W-flags */
832                         if ((t = argnxt(argp"-Wl,"))) {
833                                 u = strtok(t",");
834                                 do {
835                                         strlist_append(&inputsu);
836                                 } while ((u = strtok(NULL",")) != NULL);
837                         } else if ((t = argnxt(argp"-Wa,"))) {
838                                 u = strtok(t",");
839                                 do {
840                                         strlist_append(&assembler_flagsu);
841                                 } while ((u = strtok(NULL",")) != NULL);
842                         } else if ((t = argnxt(argp"-Wc,"))) {
843                                 u = strtok(t",");
844                                 do {
845                                         strlist_append(&compiler_flagsu);
846                                 } while ((u = strtok(NULL",")) != NULL);
847                         } else if ((t = argnxt(argp"-Wp,"))) {
848                                 u = strtok(t",");
849                                 do {
850                                         strlist_append(&preprocessor_flagsu);
851                                 } while ((u = strtok(NULL",")) != NULL);
852                         } else if (strcmp(argp"-Werror") == 0) {
853                                 strlist_append(&compiler_flags"-Werror");
plunky
1.261
854                                 strlist_append(&preprocessor_flags"-E");
ragge
1.255
855                         } else if (strcmp(argp"-Wall") == 0) {
856                                 for (Wf = WflagsWf->nameWf++)
857                                         if (Wf->flags & INWALL)
858                                                 strlist_append(&compiler_flags,
859                                                     cat("-W"Wf->name));
860                         } else if (strcmp(argp"-WW") == 0) {
861                                 for (Wf = WflagsWf->nameWf++)
862                                         strlist_append(&compiler_flags,
863                                             cat("-W"Wf->name));
864                         } else {
865                                 /* pass through, if supported */
866                                 t = &argp[2];
867                                 if (strncmp(t"no-"3) == 0)
868                                         t += 3;
869                                 if (strncmp(t"error="6) == 0)
870                                         t += 6;
871                                 for (Wf = WflagsWf->nameWf++) {
872                                         if (strcmp(tWf->name) == 0)
873                                                 strlist_append(&compiler_flags,
874                                                     argp);
875                                 }
876                         }
877                         break;
878
879                 case 'x':
880                         t = nxtopt("-x");
plunky
1.267
881                         if (match(t"none"))
882                                 strlist_append(&inputs")");
883                         else if (match(t"c"))
ragge
1.255
884                                 strlist_append(&inputs")c");
885                         else if (match(t"assembler"))
886                                 strlist_append(&inputs")s");
887                         else if (match(t"assembler-with-cpp"))
888                                 strlist_append(&inputs")S");
889                         else if (match(t"c++"))
890                                 strlist_append(&inputs")c++");
891                         else {
892                                 strlist_append(&compiler_flags"-x");
893                                 strlist_append(&compiler_flagst);
894                         }
ragge
1.220
895                         break;
ragge
1.255
896
ragge
1.220
897                 }
898                 continue;
899
ragge
1.128
900         }
ragge
1.222
901
ragge
1.128
902         /* Sanity checking */
ragge
1.216
903         if (cppflag) {
ragge
1.224
904                 if (ninput == 0) {
905                         strlist_append(&inputs"-");
ragge
1.232
906                         ninput++;
ragge
1.224
907                 } else if (ninput > 2 || (ninput == 2 && outfile)) {
ragge
1.216
908                         errorx(8"too many files");
ragge
1.232
909                 } else if (ninput == 2) {
910                         outfile = STRLIST_NEXT(STRLIST_FIRST(&inputs))->value;
911                         STRLIST_FIRST(&inputs)->next = NULL;
912                         ninput--;
ragge
1.224
913                 }
ragge
1.216
914         }
ragge
1.254
915         if (ninput == 0 && !(printprogname || printfilename))
ragge
1.128
916                 errorx(8"no input files");
ragge
1.226
917         if (outfile && (cflag || Sflag || Eflag) && ninput > 1)
ragge
1.128
918                 errorx(8"-o given with -c || -E || -S and more than one file");
ragge
1.224
919 #if 0
ragge
1.128
920         if (outfile && clist[0] && strcmp(outfileclist[0]) == 0)
921                 errorx(8"output file will be clobbered");
ragge
1.224
922 #endif
ragge
1.223
923
ragge
1.279
924         if (needM && !Mflag && !MDflag && !MMDflag)
ragge
1.223
925                 errorx(8"to make dependencies needs -M");
926
927
ragge
1.128
928         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
929                 signal(SIGINTidexit);
930         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
931                 signal(SIGTERMidexit);
ragge
1.222
932
ragge
1.226