Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20110412081742

Diff

Diff from 1.178 to:

Annotations

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

Annotated File View

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