Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20101117071530

Diff

Diff from 1.163 to:

Annotations

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

Annotated File View

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