Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20160223111408

Diff

Diff from 1.305 to:

Annotations

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

Annotated File View

ragge
1.305
1 /*      $Id: cc.c,v 1.305 2016/02/23 11:14:08 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
333 Wflags[] = {
plunky
1.215
334         { "truncate"0 },
335         { "strict-prototypes"0 },
336         { "missing-prototypes"0 },
337         { "implicit-int"INWALL },
338         { "implicit-function-declaration"INWALL },
339         { "shadow"0 },
340         { "pointer-sign"INWALL },
341         { "sign-compare"0 },
342         { "unknown-pragmas"INWALL },
343         { "unreachable-code"0 },
plunky
1.275
344         { "deprecated-declarations"0 },
plunky
1.276
345         { "attributes"0 },
plunky
1.215
346         { NULL0 },
ragge
1.128
347 };
348
ragge
1.158
349 #ifndef USHORT
350 /* copied from mip/manifest.h */
351 #define USHORT          5
352 #define INT             6
353 #define UNSIGNED        7
354 #endif
355
ragge
1.157
356 /*
357  * Wide char defines.
358  */
359 #if WCHAR_TYPE == USHORT
360 #define WCT "short unsigned int"
361 #define WCM "65535U"
ragge
1.158
362 #if WCHAR_SIZE != 2
363 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
364 #endif
ragge
1.157
365 #elif WCHAR_TYPE == INT
366 #define WCT "int"
367 #define WCM "2147483647"
ragge
1.158
368 #if WCHAR_SIZE != 4
369 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
370 #endif
ragge
1.157
371 #elif WCHAR_TYPE == UNSIGNED
372 #define WCT "unsigned int"
ragge
1.158
373 #define WCM "4294967295U"
374 #if WCHAR_SIZE != 4
375 #error WCHAR_TYPE vs. WCHAR_SIZE mismatch
376 #endif
377 #else
378 #error WCHAR_TYPE not defined or invalid
ragge
1.157
379 #endif
380
ragge
1.160
381 #ifdef GCC_COMPAT
382 #ifndef REGISTER_PREFIX
383 #define REGISTER_PREFIX ""
384 #endif
385 #ifndef USER_LABEL_PREFIX
386 #define USER_LABEL_PREFIX ""
387 #endif
388 #endif
389
plunky
1.192
390 #ifndef PCC_WINT_TYPE
391 #define PCC_WINT_TYPE "unsigned int"
392 #endif
393
394 #ifndef PCC_SIZE_TYPE
395 #define PCC_SIZE_TYPE "unsigned long"
396 #endif
397
ragge
1.161
398 #ifndef PCC_PTRDIFF_TYPE
399 #define PCC_PTRDIFF_TYPE "long int"
400 #endif
401
ragge
1.216
402
ragge
1.218
403 struct strlist preprocessor_flags;
ragge
1.223
404 struct strlist depflags;
ragge
1.219
405 struct strlist incdirs;
ragge
1.221
406 struct strlist user_sysincdirs;
407 struct strlist includes;
ragge
1.222
408 struct strlist sysincdirs;
ragge
1.223
409 struct strlist dirafterdirs;
ragge
1.222
410 struct strlist crtdirs;
411 struct strlist libdirs;
412 struct strlist progdirs;
ragge
1.224
413 struct strlist early_linker_flags;
414 struct strlist middle_linker_flags;
415 struct strlist late_linker_flags;
416 struct strlist inputs;
ragge
1.225
417 struct strlist assembler_flags;
418 struct strlist temp_outputs;
ragge
1.226
419 struct strlist compiler_flags;
ragge
1.218
420
ragge
1.128
421 int
422 main(int argcchar *argv[])
423 {
424         struct Wflags *Wf;
ragge
1.226
425         struct string *s;
ragge
1.218
426         char *t, *u, *argp;
ragge
1.239
427         char *msuffix;
ragge
1.226
428         int ninputj;
ragge
1.222
429
ragge
1.220
430         lav = argv;
431         lac = argc;
plunky
1.242
432         ninput = 0;
ragge
1.128
433
ragge
1.222
434         strlist_init(&crtdirs);
435         strlist_init(&libdirs);
436         strlist_init(&progdirs);
ragge
1.218
437         strlist_init(&preprocessor_flags);
ragge
1.219
438         strlist_init(&incdirs);
ragge
1.221
439         strlist_init(&user_sysincdirs);
440         strlist_init(&includes);
ragge
1.222
441         strlist_init(&sysincdirs);
ragge
1.223
442         strlist_init(&dirafterdirs);
443         strlist_init(&depflags);
ragge
1.224
444         strlist_init(&early_linker_flags);
445         strlist_init(&middle_linker_flags);
446         strlist_init(&late_linker_flags);
447         strlist_init(&inputs);
ragge
1.225
448         strlist_init(&assembler_flags);
449         strlist_init(&temp_outputs);
ragge
1.226
450         strlist_init(&compiler_flags);
ragge
1.218
451
ragge
1.216
452         if ((t = strrchr(argv[0], '/')))
ragge
1.226
453                 t++;
ragge
1.229
454         else
455                 t = argv[0];
ragge
1.226
456
plunky
1.303
457         if (match(tCXXPROGNAME)) {
ragge
1.198
458                 cxxflag = 1;
plunky
1.303
459         } else if (match(tCPPROGNAME)) {
ragge
1.226
460                 Eflag = cppflag = 1;
ragge
1.198
461         }
462
plunky
1.260
463 #ifdef PCC_EARLY_SETUP
464         PCC_EARLY_SETUP
ragge
1.246
465 #endif
466
plunky
1.293
467 #ifdef _WIN32
ragge
1.128
468         /* have to prefix path early.  -B may override */
469         incdir = win32pathsubst(incdir);
gmcgarry
1.153
470         altincdir = win32pathsubst(altincdir);
gmcgarry
1.136
471         libdir = win32pathsubst(libdir);
plunky
1.200
472 #ifdef PCCINCDIR
ragge
1.128
473         pccincdir = win32pathsubst(pccincdir);
plunky
1.199
474         pxxincdir = win32pathsubst(pxxincdir);
plunky
1.200
475 #endif
476 #ifdef PCCLIBDIR
ragge
1.128
477         pcclibdir = win32pathsubst(pcclibdir);
plunky
1.200
478 #endif
ragge
1.128
479         passp = win32pathsubst(passp);
480         pass0 = win32pathsubst(pass0);
gmcgarry
1.180
481 #ifdef STARTFILES
482         for (i = 0startfiles[i] != NULLi++)
483                 startfiles[i] = win32pathsubst(startfiles[i]);
484         for (i = 0endfiles[i] != NULLi++)
485                 endfiles[i] = win32pathsubst(endfiles[i]);
486 #endif
487 #ifdef STARTFILES_T
488         for (i = 0startfiles_T[i] != NULLi++)
489                 startfiles_T[i] = win32pathsubst(startfiles_T[i]);
490         for (i = 0endfiles_T[i] != NULLi++)
491                 endfiles_T[i] = win32pathsubst(endfiles_T[i]);
492 #endif
493 #ifdef STARTFILES_S
494         for (i = 0startfiles_S[i] != NULLi++)
495                 startfiles_S[i] = win32pathsubst(startfiles_S[i]);
496         for (i = 0endfiles_S[i] != NULLi++)
497                 endfiles_S[i] = win32pathsubst(endfiles_S[i]);
498 #endif
ragge
1.128
499 #endif
500
ragge
1.220
501         while (--lac) {
502                 ++lav;
503                 argp = *lav;
504
plunky
1.260
505 #ifdef PCC_EARLY_ARG_CHECK
506                 PCC_EARLY_ARG_CHECK
ragge
1.227
507 #endif
508
ragge
1.225
509                 if (*argp != '-' || match(argp"-")) {
510                         /* Check for duplicate .o files. */
511                         if (getsuf(argp) == 'o') {
512                                 j = 0;
513                                 STRLIST_FOREACH(s, &inputs)
514                                         if (match(argps->value))
515                                                 j++;
516                                 if (j)
517                                         continue/* skip it */
518                         }
519                         strlist_append(&inputsargp);
plunky
1.242
520                         ninput++;
ragge
1.225
521                         continue;
522                 }
ragge
1.220
523
524                 switch (argp[1]) {
525                 default:
plunky
1.257
526                         oerror(argp);
ragge
1.220
527                         break;
ragge
1.128
528
plunky
1.296
529                 case '#':
530                         if (match(argp"-###")) {
531                                 printf("%s\n"VERSSTR);
532                                 vflag++;
533                                 noexec++;
534                         } else
535                                 oerror(argp);
536                         break;
537
ragge
1.220
538                 case '-'/* double -'s */
539                         if (match(argp"--version")) {
540                                 printf("%s\n"VERSSTR);
541                                 return 0;
542                         } else if (strncmp(argp"--sysroot="10) == 0) {
543                                 sysroot = argp + 10;
gmcgarry
1.298
544                         } else if (strncmp(argp"--sysroot"9) == 0) {
545                                 sysroot = nxtopt(argp);
ragge
1.220
546                         } else if (strcmp(argp"--param") == 0) {
547                                 /* NOTHING YET */;
548                                 (void)nxtopt(0); /* ignore arg */
549                         } else
plunky
1.257
550                                 oerror(argp);
ragge
1.220
551                         break;
ragge
1.128
552
ragge
1.220
553                 case 'B'/* other search paths for binaries */
ragge
1.224
554                         t = nxtopt("-B");
555                         strlist_append(&crtdirst);
556                         strlist_append(&libdirst);
557                         strlist_append(&progdirst);
ragge
1.220
558                         break;
ragge
1.128
559
ragge
1.220
560                 case 'C':
561                         if (match(argp"-C") || match(argp"-CC"))
562                                 strlist_append(&preprocessor_flagsargp);
563                         else
564                                 oerror(argp);
565                         break;
ragge
1.218
566
ragge
1.255
567                 case 'c':
568                         cflag++;
569                         break;
570
plunky
1.277
571                 case 'd'/* debug options */
572                         for (t = &argp[2]; *tt++) {
573                                 if (*t == 'M')
574                                         strlist_append(&preprocessor_flags"-dM");
575
576                                 /* ignore others */
577                         }
ragge
1.220
578                         break;
ragge
1.255
579
580                 case 'E':
581                         Eflag++;
ragge
1.220
582                         break;
ragge
1.128
583
ragge
1.220
584                 case 'f'/* GCC compatibility flags */
ragge
1.246
585                         u = &argp[2];
586                         j = 0;
587                         if (strncmp(u"no-"3) == 0)
588                                 j = 1u += 3;
589                         if (match(u"PIC") || match(u"pic")) {
590                                 kflag = j ? 0 : *u == 'P' ? F_PIC : F_pic;
591                         } else if (match(u"freestanding")) {
592                                 freestanding = j ? 0 : 1;
593                         } else if (match(u"signed-char")) {
594                                 xuchar = j ? 1 : 0;
595                         } else if (match(u"unsigned-char")) {
596                                 xuchar = j ? 0 : 1;
plunky
1.248
597                         } else if (match(u"stack-protector") ||
598                             match(u"stack-protector-all")) {
ragge
1.246
599                                 sspflag = j ? 0 : 1;
ragge
1.220
600                         }
601                         /* silently ignore the rest */
602                         break;
ragge
1.128
603
ragge
1.220
604                 case 'g'/* create debug output */
605                         if (argp[2] == '0')
606                                 gflag = 0;
607                         else
608                                 gflag++;
609                         break;
ragge
1.128
610
ragge
1.255
611
612                 case 'X':
613                         Xflag++;
614                         break;
615
ragge
1.220
616                 case 'D':
617                 case 'U':
ragge
1.221
618                         strlist_append(&preprocessor_flagsargp);
ragge
1.220
619                         if (argp[2] != 0)
ragge
1.219
620                                 break;
ragge
1.221
621                         strlist_append(&preprocessor_flagsnxtopt(argp));
622                         break;
623
624                 case 'I'/* Add include dirs */
625                         strlist_append(&incdirsnxtopt("-I"));
ragge
1.220
626                         break;
ragge
1.219
627
ragge
1.220
628                 case 'i':
ragge
1.221
629                         if (match(argp"-isystem")) {
630                                 strlist_append(&user_sysincdirsnxtopt(0));
631                         } else if (match(argp"-include")) {
632                                 strlist_append(&includesnxtopt(0));
ragge
1.222
633                         } else if (match(argp"-isysroot")) {
634                                 isysroot = nxtopt(0);
ragge
1.220
635                         } else if (strcmp(argp"-idirafter") == 0) {
ragge
1.223
636                                 strlist_append(&dirafterdirsnxtopt(0));
ragge
1.220
637                         } else
plunky
1.257
638                                 oerror(argp);
ragge
1.220
639                         break;
ragge
1.128
640
ragge
1.220
641                 case 'k'/* generate PIC code */
ragge
1.247
642                         kflag = argp[2] ? argp[2] - '0' : F_pic;
ragge
1.220
643                         break;
ragge
1.128
644
ragge
1.224
645                 case 'l':
646                 case 'L':
ragge
1.226
647                         if (argp[2] == 0)
ragge
1.245
648                                 argp = cat(argpnxtopt(0));
649                         strlist_append(&inputsargp);
ragge
1.224
650                         break;
651
ragge
1.220
652                 case 'm'/* target-dependent options */
ragge
1.285
653                         if (strncmp(argp"-march="6) == 0) {
654                                 strlist_append(&compiler_flagsargp);
655                                 break;
656                         }
ragge
1.164
657 #ifdef mach_amd64
ragge
1.220
658                         /* need to call i386 ccom for this */
ragge
1.262
659                         if (strcmp(argp"-melf_i386") == 0) {
ragge
1.220
660                                 pass0 = LIBEXECDIR "/ccom_i386";
661                                 amd64_i386 = 1;
662                                 break;
663                         }
ragge
1.164
664 #endif
plunky
1.295
665 #if defined(mach_arm) || defined(mach_mips)
666                         if (match(argp"-mbig-endian")) {
667                                 bigendian = 1;
668                                 strlist_append(&compiler_flagsargp);
669                                 break;
670                         }
671                         if (match(argp"-mlittle-endian")) {
672                                 bigendian = 0;
673                                 strlist_append(&compiler_flagsargp);
674                                 break;
675                         }
676                         if (match(argp"-msoft-float")) {
677                                 softfloat = 1;
678                                 strlist_append(&compiler_flagsargp);
679                                 break;
680                         }
681 #endif
682 #if defined(mach_mips)
683                         if (match(argp"-mhard-float")) {
684                                 softfloat = 0;
685                                 strlist_append(&compiler_flagsargp);
686                                 break;
687                         }
688 #endif
ragge
1.225
689                         strlist_append(&middle_linker_flagsargp);
ragge
1.220
690                         if (argp[2] == 0) {
ragge
1.225
691                                 t = nxtopt(0);
692                                 strlist_append(&middle_linker_flagst);
ragge
1.220
693                         }
694                         break;
ragge
1.128
695
ragge
1.220
696                 case 'n'/* handle -n flags */
697                         if (strcmp(argp"-nostdinc") == 0)
698                                 nostdinc++;
699                         else if (strcmp(argp"-nostdlib") == 0) {
700                                 nostdlib++;
701                                 nostartfiles++;
702                         } else if (strcmp(argp"-nostartfiles") == 0)
703                                 nostartfiles = 1;
704                         else if (strcmp(argp"-nodefaultlibs") == 0)
705                                 nostdlib++;
706                         else
plunky
1.257
707                                 oerror(argp);
ragge
1.220
708                         break;
ragge
1.128
709
ragge
1.220
710                 case 'p':
711                         if (strcmp(argp"-pg") == 0 ||
712                             strcmp(argp"-p") == 0)
713                                 pgflag++;
714                         else if (strcmp(argp"-pthread") == 0)
715                                 pthreads++;
716                         else if (strcmp(argp"-pipe") == 0)
717                                 /* NOTHING YET */;
718                         else if (strcmp(argp"-pedantic") == 0)
719                                 /* NOTHING YET */;
ragge
1.254
720                         else if ((t = argnxt(argp"-print-prog-name="))) {
721                                 fname = t;
722                                 printprogname = 1;
723                         } else if ((t = argnxt(argp"-print-file-name="))) {
724                                 fname = t;
725                                 printfilename = 1;
726                         } else if (match(argp"-print-libgcc-file-name")) {
727                                 fname = "libpcc.a";
728                                 printfilename = 1;
ragge
1.220
729                         } else
730                                 oerror(argp);
731                         break;
ragge
1.128
732
ragge
1.299
733                 case 'R':
734                         if (argp[2] == 0)
735                                 argp = cat(argpnxtopt(0));
736                         strlist_append(&middle_linker_flagsargp);
737                         break;
738
ragge
1.220
739                 case 'r':
740                         rflag = 1;
741                         break;
gmcgarry
1.145
742
ragge
1.240
743                 case 'T':
744                         strlist_append(&inputsargp);
mickey
1.241
745                         if (argp[2] == 0 ||
746                             strcmp(argp"-Ttext") == 0 ||
747                             strcmp(argp"-Tdata") == 0 ||
748                             strcmp(argp"-Tbss") == 0)
749                                 strlist_append(&inputsnxtopt(0));
ragge
1.240
750                         break;
ragge
1.255
751
752                 case 's':
753                         if (match(argp"-shared")) {
754                                 shared = 1;
755                         } else if (match(argp"-static")) {
756                                 Bstatic = 1;
757                         } else if (match(argp"-symbolic")) {
758                                 strlist_append(&middle_linker_flags,
759                                     "-Bsymbolic");
760                         } else if (strncmp(argp"-std"4) == 0) {
761                                 if (strcmp(&argp[5], "gnu99") == 0 ||
762                                     strcmp(&argp[5], "gnu9x") == 0)
ragge
1.302
763                                         cstd = SGNU99;
764                                 if (strcmp(&argp[5], "c89") == 0)
765                                         cstd = SC89;
ragge
1.255
766                                 if (strcmp(&argp[5], "gnu89") == 0)
ragge
1.302
767                                         cstd = SGNU89;
768                                 if (strcmp(&argp[5], "c99") == 0)
769                                         cstd = SC99;
ragge
1.255
770                         } else
plunky
1.257
771                                 oerror(argp);
ragge
1.220
772                         break;
ragge
1.255
773
ragge
1.220
774                 case 'S':
ragge
1.226
775                         Sflag++;
ragge
1.220
776                         cflag++;
777                         break;
ragge
1.255
778
779                 case 't':
780                         tflag++;
ragge
1.302
781                         cstd = STRAD;
ragge
1.255
782                         break;
783
ragge
1.220
784                 case 'o':
785                         if (outfile)
786                                 errorx(8"too many -o");
787                         outfile = nxtopt("-o");
788                         break;
ragge
1.255
789
ragge
1.220
790                 case 'O':
791                         if (argp[2] == '\0')
792                                 Oflag++;
ragge
1.226
793                         else if (argp[3] == '\0' &&
794                             isdigit((unsigned char)argp[2]))
ragge
1.220
795                                 Oflag = argp[2] - '0';
796                         else if (argp[3] == '\0' && argp[2] == 's')
797                                 Oflag = 1;      /* optimize for space only */
798                         else
799                                 oerror(argp);
800                         break;
ragge
1.255
801
ragge
1.220
802                 case 'P':
ragge
1.221
803                         strlist_append(&preprocessor_flagsargp);
804                         break;
805
ragge
1.220
806                 case 'M':
ragge
1.233
807                         needM = 1;
808                         if (match(argp"-M")) {
ragge
1.223
809                                 Mflag++;
810                                 strlist_append(&depflagsargp);
ragge
1.233
811                         } else if (match(argp"-MP")) {
ragge
1.223
812                                 strlist_append(&depflags"-xMP");
ragge
1.233
813                         } else if (match(argp"-MF")) {
814                                 MFfile = nxtopt("-MF");
815                         } else if (match(argp"-MT") || match(argp"-MQ")) {
ragge
1.226
816                                 t = cat("-xMT,"nxtopt("-MT"));
ragge
1.220
817                                 t[3] = argp[2];
ragge
1.223
818                                 strlist_append(&depflagst);
ragge
1.233
819                         } else if (match(argp"-MD")) {
820                                 MDflag++;
821                                 needM = 0;
822                                 strlist_append(&depflags"-M");
ragge
1.279
823                         } else if (match(argp"-MMD")) {
824                                 MMDflag++;
825                                 needM = 0;
826                                 strlist_append(&depflags"-M");
827                                 strlist_append(&depflags"-xMMD");
ragge
1.233
828                         } else
ragge
1.220
829                                 oerror(argp);
830                         break;
ragge
1.128
831
ragge
1.220
832                 case 'v':
833                         printf("%s\n"VERSSTR);
834                         vflag++;
835                         break;
ragge
1.128
836
ragge
1.283
837                 case 'w'/* no warnings at all emitted */
838                         strlist_append(&compiler_flags"-w");
839                         break;
ragge
1.282
840
ragge
1.255
841                 case 'W'/* Ignore (most of) W-flags */
842                         if ((t = argnxt(argp"-Wl,"))) {
843                                 u = strtok(t",");
844                                 do {
845                                         strlist_append(&inputsu);
846                                 } while ((u = strtok(NULL",")) != NULL);
847                         } else if ((t = argnxt(argp"-Wa,"))) {
848                                 u = strtok(t",");
849                                 do {
850                                         strlist_append(&assembler_flagsu);
851                                 } while ((u = strtok(NULL",")) != NULL);
852                         } else if ((t = argnxt(argp"-Wc,"))) {
853                                 u = strtok(t",");
854                                 do {
855                                         strlist_append(&compiler_flagsu);
856                                 } while ((u = strtok(NULL",")) != NULL);
857                         } else if ((t = argnxt(argp"-Wp,"))) {
858                                 u = strtok(t",");
859                                 do {
860                                         strlist_append(&preprocessor_flagsu);
861                                 } while ((u = strtok(NULL",")) != NULL);
862                         } else if (strcmp(argp"-Werror") == 0) {
863                                 strlist_append(&compiler_flags"-Werror");
plunky
1.261
864                                 strlist_append(&preprocessor_flags"-E");
ragge
1.255
865                         } else if (strcmp(argp"-Wall") == 0) {
866                                 for (Wf = WflagsWf->nameWf++)
867                                         if (Wf->flags & INWALL)
868                                                 strlist_append(&compiler_flags,
869                                                     cat("-W"Wf->name));
870                         } else if (strcmp(argp"-WW") == 0) {
871                                 for (Wf = WflagsWf->nameWf++)
872                                         strlist_append(&compiler_flags,
873                                             cat("-W"Wf->name));
874                         } else {
875                                 /* pass through, if supported */
876                                 t = &argp[2];
877                                 if (strncmp(t"no-"3) == 0)
878                                         t += 3;
879                                 if (strncmp(t"error="6) == 0)
880                                         t += 6;
881                                 for (Wf = WflagsWf->nameWf++) {
882                                         if (strcmp(tWf->name) == 0)
883                                                 strlist_append(&compiler_flags,
884                                                     argp);
885                                 }
886                         }
887                         break;
888
889                 case 'x':
890                         t = nxtopt("-x");
plunky
1.267
891                         if (match(t"none"))
892                                 strlist_append(&inputs")");
893                         else if (match(t"c"))
ragge
1.255
894                                 strlist_append(&inputs")c");
895                         else if (match(t"assembler"))
896                                 strlist_append(&inputs")s");
897                         else if (match(t"assembler-with-cpp"))
898                                 strlist_append(&inputs")S");
899                         else if (match(t"c++"))
900                                 strlist_append(&inputs")c++");
901                         else {
902                                 strlist_append(&compiler_flags"-x");
903                                 strlist_append(&compiler_flagst);
904                         }
ragge
1.220
905                         break;
ragge
1.255
906
ragge
1.220
907                 }
908                 continue;
909
ragge
1.128
910         }
ragge
1.222
911
ragge
1.128
912         /* Sanity checking */
ragge
1.216
913         if (cppflag) {
ragge
1.224
914                 if (ninput == 0) {
915                         strlist_append(&inputs"-");
ragge
1.232
916                         ninput++;
ragge
1.224
917                 } else if (ninput > 2 || (ninput == 2 && outfile)) {
ragge
1.216
918                         errorx(8"too many files");
ragge
1.232
919                 } else if (ninput == 2) {
920                         outfile = STRLIST_NEXT(STRLIST_FIRST(&inputs))->value;
921                         STRLIST_FIRST(&inputs)->next = NULL;
922                         ninput--;
ragge
1.224
923                 }
ragge
1.216
924         }
ragge
1.302
925         if (tflag && Eflag == 0)