Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20080705150905

Diff

Diff from 1.107 to:

Annotations

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

Annotated File View

ragge
1.107
1 /*      $Id: cc.c,v 1.107 2008/07/05 15:09:05 ragge Exp $       */
ragge
1.3
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  */
ragge
1.2
35
ragge
1.1
36 /*
ragge
1.3
37  * Front-end to the C compiler.
ragge
1.18
38  *
39  * Brief description of its syntax:
40  * - Files that end with .c are passed via cpp->ccom->as->ld
ragge
1.59
41  * - Files that end with .i are passed via ccom->as->ld
ragge
1.18
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.
ragge
1.1
49  */
ragge
1.80
50 #include "config.h"
51
ragge
1.9
52 #include <sys/types.h>
gmcgarry
1.86
53 #ifdef HAVE_SYS_WAIT_H
ragge
1.36
54 #include <sys/wait.h>
gmcgarry
1.86
55 #endif
ragge
1.2
56
ragge
1.1
57 #include <ctype.h>
stefan
1.72
58 #include <errno.h>
59 #include <fcntl.h>
gmcgarry
1.86
60 #ifdef HAVE_LIBGEN_H
stefan
1.72
61 #include <libgen.h>
gmcgarry
1.86
62 #endif
ragge
1.1
63 #include <signal.h>
stefan
1.72
64 #include <stdarg.h>
65 #include <stdio.h>
66 #include <stdlib.h>
ragge
1.4
67 #include <string.h>
gmcgarry
1.86
68 #ifdef HAVE_UNISTD_H
ragge
1.4
69 #include <unistd.h>
gmcgarry
1.86
70 #endif
71
gmcgarry
1.87
72 #ifdef WIN32
gmcgarry
1.86
73 #include <windows.h>
74 #include <process.h>
75 #include <io.h>
76 #endif
77
78 #include "compat.h"
ragge
1.24
79
80 #include "ccconfig.h"
ragge
1.3
81 /* C command */
ragge
1.1
82
ragge
1.20
83 #define MKS(x) _MKS(x)
84 #define _MKS(x) #x
85
86 /*
87  * Many specific definitions, should be declared elsewhere.
88  */
gmcgarry
1.79
89
90 #ifndef STDINC
91 #define STDINC          "/usr/include/"
92 #endif
93
gmcgarry
1.97
94 #ifndef LIBDIR
95 #define LIBDIR          "/usr/lib/"
96 #endif
97
gmcgarry
1.79
98 #ifndef PREPROCESSOR
99 #define PREPROCESSOR    "cpp"
100 #endif
101
102 #ifndef COMPILER
103 #define COMPILER        "ccom";
104 #endif
105
106 #ifndef ASSEMBLER
107 #define ASSEMBLER       "as"
108 #endif
109
110 #ifndef LINKER
111 #define LINKER          "ld"
112 #endif
ragge
1.20
113
gmcgarry
1.97
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
ragge
1.62
123 #define MAXFIL 10000
ragge
1.12
124 #define MAXLIB 10000
ragge
1.14
125 #define MAXAV  10000
ragge
1.3
126 #define MAXOPT 100
127 char    *tmp3;
128 char    *tmp4;
ragge
1.1
129 char    *outfile;
ragge
1.91
130 char *copy(char *, int),*setsuf(char *, char);
stefan
1.72
131 int getsuf(char *);
ragge
1.4
132 int main(intchar *[]);
ragge
1.36
133 void error(char *, ...);
stefan
1.72
134 void errorx(intchar *, ...);
ragge
1.4
135 int callsys(char [], char *[]);
136 int cunlink(char *);
stefan
1.72
137 void dexit(int);
ragge
1.4
138 void idexit(int);
gmcgarry
1.99
139 char *gettmp(void);
ragge
1.91
140 void *ccmalloc(int size);
ragge
1.14
141 char    *av[MAXAV];
ragge
1.3
142 char    *clist[MAXFIL];
143 char    *llist[MAXLIB];
ragge
1.4
144 char    alist[20];
ragge
1.43
145 char    *xlist[100];
146 int     xnum;
gmcgarry
1.78
147 char    *mlist[100];
gmcgarry
1.101
148 char    *flist[100];
149 char    *wlist[100];
ragge
1.83
150 char    *idirafter;
gmcgarry
1.78
151 int     nm;
gmcgarry
1.101
152 int     nf;
153 int     nw;
154 int     sspflag;
ragge
1.63
155 int     Cflag;
ragge
1.43
156 int     dflag;
ragge
1.3
157 int     pflag;
158 int     sflag;
159 int     cflag;
160 int     eflag;
161 int     gflag;
ragge
1.5
162 int     vflag;
ragge
1.7
163 int     tflag;
ragge
1.8
164 int     Eflag;
ragge
1.4
165 int     Oflag;
ragge
1.58
166 int     kflag;  /* generate PIC/pic code */
167 #define F_PIC   1
168 #define F_pic   2
ragge
1.51
169 int     Mflag;  /* dependencies only */
ragge
1.52
170 int     pgflag;
ragge
1.1
171 int     exfail;
ragge
1.10
172 int     Xflag;
ragge
1.84
173 int     nostartfilesBstaticshared;
ragge
1.52
174 int     nostdincnostdlib;
ragge
1.43
175 int     onlyas;
ragge
1.52
176 int     pthreads;
ragge
1.91
177 int     xcflag;
ragge
1.107
178 int     ascpp;
ragge
1.14
179
gmcgarry
1.79
180 char    *passp = LIBEXECDIR "/" PREPROCESSOR;
181 char    *pass0 = LIBEXECDIR "/" COMPILER;
182 char    *as = ASSEMBLER;
183 char    *ld = LINKER;
ragge
1.47
184 char    *Bflag;
ragge
1.25
185 char *cppadd[] = CPPADD;
gmcgarry
1.94
186 #ifdef DYNLINKER
ragge
1.25
187 char *dynlinker[] = DYNLINKER;
gmcgarry
1.94
188 #endif
189 #ifdef CRT0FILE
ragge
1.25
190 char *crt0file = CRT0FILE;
gmcgarry
1.94
191 #endif
192 #ifdef CRT0FILE_PROFILE
gmcgarry
1.81
193 char *crt0file_profile = CRT0FILE_PROFILE;
gmcgarry
1.94
194 #endif
195 #ifdef STARTFILES
ragge
1.25
196 char *startfiles[] = STARTFILES;
197 char *endfiles[] = ENDFILES;
gmcgarry
1.94
198 #endif
ragge
1.84
199 #ifdef STARTFILES_S
200 char *startfiles_S[] = STARTFILES_S;
201 char *endfiles_S[] = ENDFILES_S;
202 #endif
ragge
1.25
203 char *cppmdadd[] = CPPMDADD;
ragge
1.50
204 #ifdef LIBCLIBS
205 char *libclibs[] = LIBCLIBS;
206 #else
207 char *libclibs[] = { "-lc"NULL };
208 #endif
gmcgarry
1.81
209 #ifdef LIBCLIBS_PROFILE
210 char *libclibs_profile[] = LIBCLIBS_PROFILE;
211 #else
212 char *libclibs_profile[] = { "-lc_p"NULL };
213 #endif
ragge
1.48
214 #ifndef STARTLABEL
215 #define STARTLABEL "__start"
216 #endif
ragge
1.1
217
ragge
1.105
218 /* handle gcc warning emulations */
219 struct Wflags {
220         char *name;
221         int flags;
222 #define INWALL          1
223 #define NEGATIVE        2
224 Wflags[] = {
225         { "-Werror"0 },
226         { "-Wshadow"0 },
227         { "-Wno-shadow"NEGATIVE },
228         { "-Wno-pointer-sign"NEGATIVE },
229         { "-Wsign-compare"0 },
230         { "-Wno-sign-compare"NEGATIVE },
231         { "-Wunknown-pragmas"INWALL },
232         { "-Wno-unknown-pragmas"NEGATIVE },
233         { "-Wunreachable-code"0 },
234         { "-Wno-unreachable-code"NEGATIVE },
235         { 00 },
236 };
237
238 #define SZWFL   (sizeof(Wflags)/sizeof(Wflags[0]))
239
ragge
1.4
240 int
pj
1.26
241 main(int argcchar *argv[])
242 {
ragge
1.105
243         struct Wflags *Wf;
ragge
1.15
244         char *t, *u;
ragge
1.1
245         char *assource;
ragge
1.3
246         char **pv, *ptemp[MAXOPT], **pvt;
ragge
1.36
247         int ncnlijcnxona;
ragge
1.3
248
ragge
1.36
249         i = nc = nl = nxo = 0;
ragge
1.3
250         pv = ptemp;
251         while(++i < argc) {
ragge
1.66
252                 if (argv[i][0] == '-') {
253                         switch (argv[i][1]) {
254                         default:
255                                 goto passa;
256 #ifdef notyet
257         /* must add library options first (-L/-l/...) */
258                                 error("unrecognized option `-%c'"argv[i][1]);
259                                 break;
260 #endif
ragge
1.22
261
ragge
1.66
262                         case 'B'/* other search paths for binaries */
263                                 Bflag = &argv[i][2];
264                                 break;
ragge
1.22
265
ragge
1.66
266                         case 'X':
267                                 Xflag++;
268                                 break;
269                         case 'W'/* Ignore (most of) W-flags */
gmcgarry
1.101
270                                 if (strncmp(argv[i], "-Wl,"4) == 0) {
ragge
1.66
271                                         /* options to the linker */
272                                         t = &argv[i][4];
273                                         while ((u = strchr(t','))) {
274                                                 *u++ = 0;
275                                                 llist[nl++] = t;
276                                                 t = u;
277                                         }
ragge
1.15
278                                         llist[nl++] = t;
ragge
1.83
279                                 } else if (strncmp(argv[i], "-Wp,"4) == 0) {
280                                         /* preprocessor */
281                                         if (!strncmp(argv[i], "-Wp,-C"6))
282                                                 Cflag++;
gmcgarry
1.101
283                                 } else if (strcmp(argv[i], "-Wall") == 0) {
ragge
1.105
284                                         /* Set only the same flags as gcc */
285                                         for (Wf = WflagsWf->nameWf++) {
286                                                 if (Wf->flags != INWALL)
287                                                         continue;
288                                                 wlist[nw++] = Wf->name;
289                                         }
290                                 } else if (strcmp(argv[i], "-WW") == 0) {
291                                         /* set all positive flags */
292                                         for (Wf = WflagsWf->nameWf++) {
293                                                 if (Wf->flags == NEGATIVE)
294                                                         continue;
295                                                 wlist[nw++] = Wf->name;
296                                         }
297                                 } else {
298                                         /* check and set if available */
299                                         for (Wf = WflagsWf->nameWf++) {
300                                                 if (strcmp(argv[i], Wf->name))
301                                                         continue;
302                                                 wlist[nw++] = Wf->name;
303                                         }
ragge
1.15
304                                 }
ragge
1.66
305                                 break;
ragge
1.15
306
ragge
1.66
307                         case 'f'/* GCC compatibility flags */
308                                 if (strcmp(argv[i], "-fPIC") == 0)
309                                         kflag = F_PIC;
gmcgarry
1.101
310                                 else if (strcmp(argv[i], "-fpic") == 0)
ragge
1.66
311                                         kflag = F_pic;
gmcgarry
1.101
312                                 else if (strcmp(argv[i],
313                                     "-fsigned-char") == 0)
314                                         flist[nf++] = argv[i];
315                                 else if (strcmp(argv[i],
316                                     "-fno-signed-char") == 0)
317                                         flist[nf++] = argv[i];
318                                 else if (strcmp(argv[i],
319                                     "-funsigned-char") == 0)
320                                         flist[nf++] = argv[i];
321                                 else if (strcmp(argv[i],
322                                     "-fno-unsigned-char") == 0)
323                                         flist[nf++] = argv[i];
324                                 else if (strcmp(argv[i],
325                                     "-fstack-protector") == 0) {
326                                         flist[nf++] = argv[i];
327                                         sspflag++;
328                                 } else if (strcmp(argv[i],
329                                     "-fno-stack-protector") == 0) {
330                                         flist[nf++] = argv[i];
331                                         sspflag = 0;
332                                 }
ragge
1.66
333                                 /* silently ignore the rest */
334                                 break;
ragge
1.14
335
ragge
1.66
336                         case 'g'/* create debug output */
337                                 gflag++;
338                                 break;
ragge
1.25
339
ragge
1.66
340                         case 'i':
341                                 if (strcmp(argv[i], "-isystem") == 0) {
342                                         *pv++ = "-S";
343                                         *pv++ = argv[++i];
344                                 } else if (strcmp(argv[i], "-include") == 0) {
345                                         *pv++ = "-i";
346                                         *pv++ = argv[++i];
ragge
1.83
347                                 } else if (strcmp(argv[i], "-idirafter") == 0) {
348                                         idirafter = argv[++i];
ragge
1.66
349                                 } else
350                                         goto passa;
351                                 break;
ragge
1.20
352
ragge
1.66
353                         case 'k'/* generate PIC code */
354                                 kflag = F_pic;
355                                 break;
ragge
1.49
356
gmcgarry
1.78
357                         case 'm'/* target-dependent options */
358                                 mlist[nm++] = argv[i];
359                                 break;
360
ragge
1.66
361                         case 'n'/* handle -n flags */
362                                 if (strcmp(argv[i], "-nostdinc") == 0)
363                                         nostdinc++;
364                                 else if (strcmp(argv[i], "-nostdlib") == 0) {
365                                         nostdlib++;
366                                         nostartfiles++;
367                                 } else if (strcmp(argv[i], "-nostartfiles") == 0)
368                                         nostartfiles = 1;
369                                 else
370                                         goto passa;
371                                 break;
ragge
1.14
372
ragge
1.66
373                         case 'p':
ragge
1.88
374                                 if (strcmp(argv[i], "-pg") == 0 ||
375                                     strcmp(argv[i], "-p") == 0)
ragge
1.66
376                                         pgflag++;
377                                 else if (strcmp(argv[i], "-pthread") == 0)
378                                         pthreads++;
gmcgarry
1.81
379                                 else if (strcmp(argv[i], "-pipe") == 0) {
380                                 } else
ragge
1.66
381                                         errorx(1"unknown option %s"argv[i]);
382                                 break;
ragge
1.52
383
ragge
1.66
384                         case 'x':
ragge
1.83
385                                 t = &argv[i][2];
386                                 if (*t == 0)
387                                         t = argv[++i];
388                                 if (strcmp(t"c") == 0)
ragge
1.91
389                                         xcflag = 1/* default */
ragge
1.107
390                                 else if (strcmp(t"assembler-with-cpp") == 0)
391                                         ascpp = 1;
ragge
1.83
392 #ifdef notyet
393                                 else if (strcmp(t"c++")
394                                         cxxflag++;
395 #endif
396                                 else
397                                         xlist[xnum++] = argv[i];
ragge
1.66
398                                 break;
399                         case 't':
400                                 tflag++;
401                                 break;
402                         case 'S':
403                                 sflag++;
404                                 cflag++;
405                                 break;
406                         case 'o':
407                                 if (outfile)
408                                         errorx(8"too many -o");
409                                 outfile = argv[++i];
410                                 break;
411                         case 'O':
gmcgarry
1.96
412                                 if (argv[i][2] == '0')
413                                         Oflag = 0;
414                                 else
ragge
1.85
415                                         Oflag++;
ragge
1.66
416                                 break;
417                         case 'E':
418                                 Eflag++;
419                                 break;
420                         case 'P':
421                                 pflag++;
422                                 *pv++ = argv[i];
423                         case 'c':
424                                 cflag++;
425                                 break;
ragge
1.3
426
ragge
1.24
427 #if 0
ragge
1.66
428                         case '2':
429                                 if(argv[i][2] == '\0')
430                                         pref = "/lib/crt2.o";
431                                 else {
432                                         pref = "/lib/crt20.o";
433                                 }
434                                 break;
ragge
1.24
435 #endif
ragge
1.66
436                         case 'C':
437                                 Cflag = 1;
438                                 break;
439                         case 'D':
440                         case 'I':
441                         case 'U':
442                                 *pv++ = argv[i];
443                                 if (argv[i][2] == 0)
444                                         *pv++ = argv[++i];
445                                 if (pv >= ptemp+MAXOPT) {
446                                         error("Too many DIU options");
447                                         --pv;
ragge
1.3
448                                 }
ragge
1.66
449                                 break;
ragge
1.3
450
ragge
1.66
451                         case 'M':
452                                 Mflag++;
453                                 break;
ragge
1.51
454
ragge
1.66
455                         case 'd':
456                                 dflag++;
ragge
1.67
457                                 strlcpy(alistargv[i], sizeof (alist));
ragge
1.66
458                                 break;
459                         case 'v':
460                                 printf("%s\n"VERSSTR);
461                                 vflag++;
462                                 break;
ragge
1.14
463
ragge
1.66
464                         case 's':
465                                 if (strcmp(argv[i], "-static") == 0)
466                                         Bstatic = 1;
ragge
1.84
467                                 else if (strcmp(argv[i], "-shared") == 0) {
468                                         shared = 1;
469                                         nostdlib = 1;
470                                 } else
ragge
1.66
471                                         goto passa;
472                                 break;
473                         }
ragge
1.3
474                 } else {
475                 passa:
476                         t = argv[i];
ragge
1.11
477                         if (*argv[i] == '-' && argv[i][1] == 'L')
478                                 ;
ragge
1.59
479                         else if((c=getsuf(t))=='c' || c=='S' || c=='i' ||
ragge
1.91
480                             c=='s'|| Eflag || xcflag) {
ragge
1.3
481                                 clist[nc++] = t;
ragge
1.66
482                                 if (nc>=MAXFIL) {
ragge
1.36
483                                         error("Too many source files");
ragge
1.3
484                                         exit(1);
ragge
1.66
485                                 }
ragge
1.3
486                                 t = setsuf(t'o');
487                         }
stefan
1.76
488
489                         /* Check for duplicate .o files. */
490                         for (j = getsuf(t) == 'o' ? 0 : nlj < nlj++) {
491                                 if (strcmp(llist[j], t) == 0)
492                                         break;
493                         }
494                         if (j == nl) {
ragge
1.3
495                                 llist[nl++] = t;
ragge
1.66
496                                 if (nl >= MAXLIB) {
ragge
1.36
497                                         error("Too many object/library files");
ragge
1.3
498                                         exit(1);
ragge
1.66
499                                 }
ragge
1.3
500                                 if (getsuf(t)=='o')
501                                         nxo++;
ragge
1.1
502                         }
503                 }
504         }
ragge
1.18
505         /* Sanity checking */
506         if (nc == 0 && nl == 0)
ragge
1.36
507                 errorx(8"no input files");
ragge
1.61
508         if (outfile && (cflag || sflag || Eflag) && nc > 1)
509                 errorx(8"-o given with -c || -E || -S and more than one file");
ragge
1.19
510         if (outfile && clist[0] && strcmp(outfileclist[0]) == 0)
ragge
1.36
511                 errorx(8"output file will be clobbered");
ragge
1.4
512         if (gflagOflag = 0;
ragge
1.24
513 #if 0
514         if (proflag)
ragge
1.3
515                 pref = "/lib/mcrt0.o";
ragge
1.24
516 #endif
ragge
1.3
517         if(nc==0)
518                 goto nocom;
519         if (pflag==0) {
stefan
1.74
520                 if (!sflag)
521                         tmp3 = gettmp();
pj
1.30
522                 tmp4 = gettmp();
ragge
1.1
523         }
ragge
1.3
524         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
ragge
1.1
525                 signal(SIGINTidexit);
ragge
1.3
526         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
ragge
1.1
527                 signal(SIGTERMidexit);
ragge
1.3
528         pvt = pv;
ragge
1.1
529         for (i=0i<nci++) {
ragge
1.18
530                 /*
531                  * C preprocessor
532                  */
ragge
1.37
533                 if (nc>1 && !Eflag)
ragge
1.1
534                         printf("%s:\n"clist[i]);
ragge
1.43
535                 onlyas = 0;
pj
1.32
536                 assource = tmp3;
ragge
1.107
537                 if (getsuf(clist[i])=='S')
538                         ascpp = 1;
ragge
1.59
539                 if (getsuf(clist[i])=='i') {
540                         if(Eflag)
541                                 continue;
542                         goto com;
ragge
1.107
543                 } else if (ascpp) {
544                         onlyas = 1;
ragge
1.59
545                 } else if (getsuf(clist[i])=='s') {
ragge
1.1
546                         assource = clist[i];
ragge
1.43
547                         goto assemble;
ragge
1.107
548                 }
ragge
1.1
549                 if (pflag)
550                         tmp4 = setsuf(clist[i], 'i');
ragge
1.5
551                 na = 0;
552                 av[na++] = "cpp";
ragge
1.60
553                 if (vflag)
554                         av[na++] = "-v";
ragge
1.20
555                 av[na++] = "-D__PCC__=" MKS(PCC_MAJOR);
ragge
1.40
556                 av[na++] = "-D__PCC_MINOR__=" MKS(PCC_MINOR);
557                 av[na++] = "-D__PCC_MINORMINOR__=" MKS(PCC_MINORMINOR);
ragge
1.107
558                 if (ascpp)
ragge
1.52
559                         av[na++] = "-D__ASSEMBLER__";
gmcgarry
1.101
560                 if (sspflag)
561                         av[na++] = "-D__SSP__=1";
ragge
1.52
562                 if (pthreads)
563                         av[na++] = "-D_PTHREADS";
ragge
1.63
564                 if (Cflag)
565                         av[na++] = "-C";
ragge
1.51
566                 if (Mflag)
567                         av[na++] = "-M";
ragge
1.57
568                 if (dflag)
569                         av[na++] = alist;
ragge
1.5
570                 for (j = 0cppadd[j]; j++)
571                         av[na++] = cppadd[j];
ragge
1.24
572                 for (j = 0cppmdadd[j]; j++)
573                         av[na++] = cppmdadd[j];
ragge
1.7
574                 if (tflag)
ragge
1.20
575                         av[na++] = "-t";
ragge
1.7
576                 for(pv=ptemppv <pvtpv++)
577                         av[na++] = *pv;
gmcgarry
1.98
578                 if (!nostdinc) {
ragge
1.52
579                         av[na++] = "-S"av[na++] = STDINC;
gmcgarry
1.98
580                         av[na++] = "-I" PCCINCDIR;
581                 }
ragge
1.83
582                 if (idirafter) {
583                         av[na++] = "-I";
584                         av[na++] = idirafter;
585                 }
ragge
1.5
586                 av[na++] = clist[i];
ragge
1.51
587                 if (!Eflag && !Mflag)
ragge
1.20
588                         av[na++] = tmp4;
ragge
1.61
589                 if (Eflag && outfile)
590                          av[na++] = outfile;
ragge
1.3
591                 av[na++]=0;
592                 if (callsys(passpav))
593                         {exfail++; eflag++;}
ragge
1.51
594                 if (Eflag || Mflag)
ragge
1.37
595                         continue;
stefan
1.73
596                 if (onlyas) {
597                         assource = tmp4;
ragge
1.7
598                         goto assemble;
stefan
1.73
599                 }
ragge
1.18
600
601                 /*
602                  * C compiler
603                  */
ragge
1.59
604         com:
ragge
1.25
605                 na = 0;
606                 av[na++]= "ccom";
gmcgarry
1.101
607                 for (j = 0j < nwj++)
608                         av[na++] = wlist[j];
609                 for (j = 0j < nfj++)
610                         av[na++] = flist[j];
ragge
1.60
611                 if (vflag)
612                         av[na++] = "-v";
gmcgarry
1.81
613                 if (pgflag)
614                         av[na++] = "-p";
ragge
1.25
615                 if (gflag)
616                         av[na++] = "-g";
gmcgarry
1.94
617 #ifdef os_darwin
gmcgarry
1.82
618                 /* darwin always wants PIC compilation */
619                 av[na++] = "-k";
620 #else
ragge
1.49
621                 if (kflag)
622                         av[na++] = "-k";
gmcgarry
1.82
623 #endif
ragge
1.44
624                 if (Oflag) {
625                         av[na++] = "-xtemps";
ragge
1.64
626                         av[na++] = "-xdeljumps";
ragge
1.44
627                 }
ragge
1.45
628                 for (j = 0j < xnumj++)
629                         av[na++] = xlist[j];
gmcgarry
1.78
630                 for (j = 0j < nmj++)
631                         av[na++] = mlist[j];
ragge
1.68
632                 if (getsuf(clist[i])=='i')
633                         av[na++] = clist[i];
634                 else
635                         av[na++] = tmp4/* created by cpp */
ragge
1.3
636                 if (pflag || exfail)
637                         {
ragge
1.1
638                         cflag++;
639                         continue;
ragge
1.3
640                         }
ragge
1.16
641                 if(sflag) {
642                         if (outfile)
stefan
1.77
643                                 tmp3 = outfile;
ragge
1.16
644                         else
stefan
1.77
645                                 tmp3 = setsuf(clist[i], 's');
ragge
1.16
646                 }
ragge
1.25
647                 av[na++] = tmp3;
648 #if 0
ragge
1.3
649                 if (proflag) {
650                         av[3] = "-XP";
651                         av[4] = 0;
652                 } else
653                         av[3] = 0;
ragge
1.25
654 #endif
655                 av[na++] = NULL;
ragge
1.3
656                 if (callsys(pass0av)) {
ragge
1.1
657                         cflag++;
658                         eflag++;
659                         continue;
660                 }
661                 if (sflag)
662                         continue;
ragge
1.18
663
664                 /*
665                  * Assembler
666                  */
ragge
1.1
667         assemble:
ragge
1.49
668                 na = 0;
gmcgarry
1.79
669                 av[na++] = as;
gmcgarry
1.98
670 #if defined(os_sunos) && defined(mach_sparc64)
671                 av[na++] = "-m64";
672 #endif
ragge
1.60
673                 if (vflag)
674                         av[na++] = "-v";
ragge
1.49
675                 if (kflag)
676                         av[na++] = "-k";
677                 av[na++] = "-o";
ragge
1.18
678                 if (outfile && cflag)
ragge
1.49
679                         av[na++] = outfile;
ragge
1.18
680                 else
ragge
1.49
681                         av[na++] = setsuf(clist[i], 'o');
stefan
1.73
682                 av[na++] = assource;
ragge
1.49
683                 if (dflag)
684                         av[na++] = alist;
685                 av[na++] = 0;
gmcgarry
1.79
686                 if (callsys(asav)) {
ragge
1.1
687                         cflag++;
688                         eflag++;
ragge
1.7
689                         cunlink(tmp4);
ragge
1.1
690                         continue;
691                 }
ragge
1.7
692                 cunlink(tmp4);
ragge
1.1
693         }
ragge
1.18
694
ragge
1.51
695         if (Eflag || Mflag)
ragge
1.37
696                 dexit(eflag);
697
ragge
1.18
698         /*
699          * Linker
700          */
ragge
1.1
701 nocom:
702         if (cflag==0 && nl!=0) {
ragge
1.6
703                 j = 0;
gmcgarry
1.79
704                 av[j++] = ld;
gmcgarry
1.95
705 #ifndef os_win32
ragge
1.60
706                 if (vflag)
707                         av[j++] = "-v";
gmcgarry
1.98
708 #ifndef os_sunos
ragge
1.6
709                 av[j++] = "-X";
gmcgarry
1.98
710 #endif
ragge
1.84
711                 if (shared) {
712                         av[j++] = "-shared";
gmcgarry
1.98
713 #ifndef os_sunos
ragge
1.84
714                 } else {
gmcgarry
1.106
715 #ifndef os_darwin
ragge
1.84
716                         av[j++] = "-d";
gmcgarry
1.106
717 #endif
ragge
1.84
718                         av[j++] = "-e";
719                         av[j++] = STARTLABEL;
gmcgarry
1.98
720 #endif
ragge
1.84
721                         if (Bstatic == 0) { /* Dynamic linkage */
gmcgarry
1.94
722 #ifdef DYNLINKER
ragge
1.84
723                                 for (i = 0dynlinker[i]; i++)
724                                         av[j++] = dynlinker[i];
gmcgarry
1.94
725 #endif
ragge
1.84
726                         } else
727                                 av[j++] = "-Bstatic";
728                 }
gmcgarry
1.95
729 #endif
ragge
1.1
730                 if (outfile) {
ragge
1.3
731                         av[j++] = "-o";
732                         av[j++] = outfile;
733                 }
ragge
1.84
734                 if (shared) {
735 #ifdef STARTFILES_S
736                         for (i = 0startfiles_S[i]; i++)
737                                 av[j++] = startfiles_S[i];
738 #endif
739                 } else {
740                         if (!nostartfiles) {
gmcgarry
1.94
741 #ifdef CRT0FILE_PROFILE
742                                 if (pgflag)
743                                 {
744                                         av[j++] = crt0file_profile;
745                                 }
746                                 else
747 #endif
748                                 {
749 #ifdef CRT0FILE
750                                         av[j++] = crt0file;
751 #endif
752                                 }
753 #ifdef STARTFILES
ragge
1.84
754                                 for (i = 0startfiles[i]; i++)
755                                         av[j++] = startfiles[i];
gmcgarry
1.94
756 #endif
ragge
1.84
757                         }
ragge
1.14
758                 }
ragge
1.24
759                 i = 0;
ragge
1.14
760                 while(i<nl) {
ragge
1.3
761                         av[j++] = llist[i++];
ragge
1.14
762                         if (j >= MAXAV)
ragge
1.36
763                                 error("Too many ld options");
ragge
1.14
764                 }
gmcgarry
1.82
765 #ifndef MACHOABI
766                 /* darwin assembler doesn't want -g */
ragge
1.65
767                 if (gflag)
768                         av[j++] = "-g";
gmcgarry
1.82
769 #endif
ragge
1.11
770 #if 0
ragge
1.3
771                 if (gflag)
772                         av[j++] = "-lg";
ragge
1.11
773 #endif
ragge
1.52
774                 if (pthreads)
775                         av[j++] = "-lpthread";
gmcgarry
1.81
776                 if (!nostdlib) {
gmcgarry
1.97
777                         av[j++] = "-L" PCCLIBDIR;
gmcgarry
1.81
778                         if (pgflag) {
779                                 for (i = 0libclibs_profile[i]; i++)
780                                         av[j++] = libclibs_profile[i];
781                         } else {
782                                 for (i = 0libclibs[i]; i++)
783                                         av[j++] = libclibs[i];
784                         }
785                 }
ragge
1.84
786                 if (shared) {
787 #ifdef STARTFILES_S
788                         for (i = 0endfiles_S[i]; i++)
789                                 av[j++] = endfiles_S[i];
790 #endif
791                 } else {
gmcgarry
1.95
792 #ifdef STARTFILES
ragge
1.84
793                         if (!nostartfiles) {
794                                 for (i = 0endfiles[i]; i++)
795                                         av[j++] = endfiles[i];
796                         }
gmcgarry
1.95
797 #endif
ragge
1.14
798                 }
ragge
1.3
799                 av[j++] = 0;
gmcgarry
1.79
800                 eflag |= callsys(ldav);
ragge
1.1
801                 if (nc==1 && nxo==1 && eflag==0)
ragge
1.3
802                         cunlink(setsuf(clist[0], 'o'));
ragge
1.46
803                 else if (nc > 0 && eflag == 0) {
804                         /* remove .o files XXX ugly */
805                         for (i = 0i < nci++)
806                                 cunlink(setsuf(clist[i], 'o'));
807                 }
ragge
1.1
808         }
ragge
1.36
809         dexit(eflag);
ragge
1.4
810         return 0;
ragge
1.1
811 }
812
ragge
1.36
813 /*
814  * exit and cleanup after interrupt.
815  */
ragge
1.4
816 void
817 idexit(int arg)
ragge
1.1
818 {
ragge
1.36
819         dexit(100);
ragge
1.1
820 }
821
ragge
1.36
822 /*
823  * exit and cleanup.
824  */
ragge
1.4
825 void
ragge
1.36
826 dexit(int eval)
ragge
1.1
827 {
ragge
1.10
828         if (!pflag && !Xflag) {
ragge
1.1
829                 if (sflag==0)
830                         cunlink(tmp3);
831                 cunlink(tmp4);
832         }
ragge
1.70
833         if (eval == 100)
834                 _exit(eval);
ragge
1.36
835         exit(eval);
ragge
1.1
836 }
837
ragge
1.36
838 static void
839 ccerror(char *sva_list ap)
ragge
1.1
840 {
ragge
1.36
841         vfprintf(Eflag ? stderr : stdoutsap);
ragge
1.8
842         putc('\n'Eflagstderr : stdout);
ragge
1.1
843         exfail++;
844         cflag++;
845         eflag++;
846 }
847
ragge
1.36
848 /*
849  * complain a bit.
850  */
851 void
852 error(char *s, ...)
853 {
854         va_list ap;
855