Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:plunky:20141218213725

Diff

Diff from 1.294 to:

Annotations

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

Annotated File View

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