Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20101107141252

Diff

Diff from 1.162 to:

Annotations

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

Annotated File View

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