Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20080708072728

Diff

Diff from 1.108 to:

Annotations

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

Annotated File View

gmcgarry
1.108
1 /*      $Id: cc.c,v 1.108 2008/07/08 07:27:28 gmcgarry 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 },
gmcgarry
1.108
228         { "-Wpointer-sign"INWALL },
ragge
1.105
229         { "-Wno-pointer-sign"NEGATIVE },
230         { "-Wsign-compare"0 },
231         { "-Wno-sign-compare"NEGATIVE },
232         { "-Wunknown-pragmas"INWALL },
233         { "-Wno-unknown-pragmas"NEGATIVE },
234         { "-Wunreachable-code"0 },
235         { "-Wno-unreachable-code"NEGATIVE },
236         { 00 },
237 };
238
239 #define SZWFL   (sizeof(Wflags)/sizeof(Wflags[0]))
240
ragge
1.4
241 int
pj
1.26
242 main(int argcchar *argv[])
243 {
ragge
1.105
244         struct Wflags *Wf;
ragge
1.15
245         char *t, *u;
ragge
1.1
246         char *assource;
ragge
1.3
247         char **pv, *ptemp[MAXOPT], **pvt;
ragge
1.36
248         int ncnlijcnxona;
ragge
1.3
249
ragge
1.36
250         i = nc = nl = nxo = 0;
ragge
1.3
251         pv = ptemp;
252         while(++i < argc) {
ragge
1.66
253                 if (argv[i][0] == '-') {
254                         switch (argv[i][1]) {
255                         default:
256                                 goto passa;
257 #ifdef notyet
258         /* must add library options first (-L/-l/...) */
259                                 error("unrecognized option `-%c'"argv[i][1]);
260                                 break;
261 #endif
ragge
1.22
262
ragge
1.66
263                         case 'B'/* other search paths for binaries */
264                                 Bflag = &argv[i][2];
265                                 break;
ragge
1.22
266
ragge
1.66
267                         case 'X':
268                                 Xflag++;
269                                 break;
270                         case 'W'/* Ignore (most of) W-flags */
gmcgarry
1.101
271                                 if (strncmp(argv[i], "-Wl,"4) == 0) {
ragge
1.66
272                                         /* options to the linker */
273                                         t = &argv[i][4];
274                                         while ((u = strchr(t','))) {
275                                                 *u++ = 0;
276                                                 llist[nl++] = t;
277                                                 t = u;
278                                         }
ragge
1.15
279                                         llist[nl++] = t;
ragge
1.83
280                                 } else if (strncmp(argv[i], "-Wp,"4) == 0) {
281                                         /* preprocessor */
282                                         if (!strncmp(argv[i], "-Wp,-C"6))
283                                                 Cflag++;
gmcgarry
1.101
284                                 } else if (strcmp(argv[i], "-Wall") == 0) {
ragge
1.105
285                                         /* Set only the same flags as gcc */
286                                         for (Wf = WflagsWf->nameWf++) {
287                                                 if (Wf->flags != INWALL)
288                                                         continue;
289                                                 wlist[nw++] = Wf->name;
290                                         }
291                                 } else if (strcmp(argv[i], "-WW") == 0) {
292                                         /* set all positive flags */
293                                         for (Wf = WflagsWf->nameWf++) {
294                                                 if (Wf->flags == NEGATIVE)
295                                                         continue;
296                                                 wlist[nw++] = Wf->name;
297                                         }
298                                 } else {
299                                         /* check and set if available */
300                                         for (Wf = WflagsWf->nameWf++) {
301                                                 if (strcmp(argv[i], Wf->name))
302                                                         continue;
303                                                 wlist[nw++] = Wf->name;
304                                         }
ragge
1.15
305                                 }
ragge
1.66
306                                 break;
ragge
1.15
307
ragge
1.66
308                         case 'f'/* GCC compatibility flags */
309                                 if (strcmp(argv[i], "-fPIC") == 0)
310                                         kflag = F_PIC;
gmcgarry
1.101
311                                 else if (strcmp(argv[i], "-fpic") == 0)
ragge
1.66
312                                         kflag = F_pic;
gmcgarry
1.101
313                                 else if (strcmp(argv[i],
314                                     "-fsigned-char") == 0)
315                                         flist[nf++] = argv[i];
316                                 else if (strcmp(argv[i],
317                                     "-fno-signed-char") == 0)
318                                         flist[nf++] = argv[i];
319                                 else if (strcmp(argv[i],
320                                     "-funsigned-char") == 0)
321                                         flist[nf++] = argv[i];
322                                 else if (strcmp(argv[i],
323                                     "-fno-unsigned-char") == 0)
324                                         flist[nf++] = argv[i];
325                                 else if (strcmp(argv[i],
326                                     "-fstack-protector") == 0) {
327                                         flist[nf++] = argv[i];
328                                         sspflag++;
329                                 } else if (strcmp(argv[i],
330                                     "-fno-stack-protector") == 0) {
331                                         flist[nf++] = argv[i];
332                                         sspflag = 0;
333                                 }
ragge
1.66
334                                 /* silently ignore the rest */
335                                 break;
ragge
1.14
336
ragge
1.66
337                         case 'g'/* create debug output */
338                                 gflag++;
339                                 break;
ragge
1.25
340
ragge
1.66
341                         case 'i':
342                                 if (strcmp(argv[i], "-isystem") == 0) {
343                                         *pv++ = "-S";
344                                         *pv++ = argv[++i];
345                                 } else if (strcmp(argv[i], "-include") == 0) {
346                                         *pv++ = "-i";
347                                         *pv++ = argv[++i];
ragge
1.83
348                                 } else if (strcmp(argv[i], "-idirafter") == 0) {
349                                         idirafter = argv[++i];
ragge
1.66
350                                 } else
351                                         goto passa;
352                                 break;
ragge
1.20
353
ragge
1.66
354                         case 'k'/* generate PIC code */
355                                 kflag = F_pic;
356                                 break;
ragge
1.49
357
gmcgarry
1.78
358                         case 'm'/* target-dependent options */
359                                 mlist[nm++] = argv[i];
360                                 break;
361
ragge
1.66
362                         case 'n'/* handle -n flags */
363                                 if (strcmp(argv[i], "-nostdinc") == 0)
364                                         nostdinc++;
365                                 else if (strcmp(argv[i], "-nostdlib") == 0) {
366                                         nostdlib++;
367                                         nostartfiles++;
368                                 } else if (strcmp(argv[i], "-nostartfiles") == 0)
369                                         nostartfiles = 1;
370                                 else
371                                         goto passa;
372                                 break;
ragge
1.14
373
ragge
1.66
374                         case 'p':
ragge
1.88
375                                 if (strcmp(argv[i], "-pg") == 0 ||
376                                     strcmp(argv[i], "-p") == 0)
ragge
1.66
377                                         pgflag++;
378                                 else if (strcmp(argv[i], "-pthread") == 0)
379                                         pthreads++;
gmcgarry
1.81
380                                 else if (strcmp(argv[i], "-pipe") == 0) {
381                                 } else
ragge
1.66
382                                         errorx(1"unknown option %s"argv[i]);
383                                 break;
ragge
1.52
384
ragge
1.66
385                         case 'x':
ragge
1.83
386                                 t = &argv[i][2];
387                                 if (*t == 0)
388                                         t = argv[++i];
389                                 if (strcmp(t"c") == 0)
ragge
1.91
390                                         xcflag = 1/* default */
ragge
1.107
391                                 else if (strcmp(t"assembler-with-cpp") == 0)
392                                         ascpp = 1;
ragge
1.83
393 #ifdef notyet
394                                 else if (strcmp(t"c++")
395                                         cxxflag++;
396 #endif
397                                 else
398                                         xlist[xnum++] = argv[i];
ragge
1.66
399                                 break;
400                         case 't':
401                                 tflag++;
402                                 break;
403                         case 'S':
404                                 sflag++;
405                                 cflag++;
406                                 break;
407                         case 'o':
408                                 if (outfile)
409                                         errorx(8"too many -o");
410                                 outfile = argv[++i];
411                                 break;
412                         case 'O':
gmcgarry
1.96
413                                 if (argv[i][2] == '0')
414                                         Oflag = 0;
415                                 else
ragge
1.85
416                                         Oflag++;
ragge
1.66
417                                 break;
418                         case 'E':
419                                 Eflag++;
420                                 break;
421                         case 'P':
422                                 pflag++;
423                                 *pv++ = argv[i];
424                         case 'c':
425                                 cflag++;
426                                 break;
ragge
1.3
427
ragge
1.24
428 #if 0
ragge
1.66
429                         case '2':
430                                 if(argv[i][2] == '\0')
431                                         pref = "/lib/crt2.o";
432                                 else {
433                                         pref = "/lib/crt20.o";
434                                 }
435                                 break;
ragge
1.24
436 #endif
ragge
1.66
437                         case 'C':
438                                 Cflag = 1;
439                                 break;
440                         case 'D':
441                         case 'I':
442                         case 'U':
443                                 *pv++ = argv[i];
444                                 if (argv[i][2] == 0)
445                                         *pv++ = argv[++i];
446                                 if (pv >= ptemp+MAXOPT) {
447                                         error("Too many DIU options");
448                                         --pv;
ragge
1.3
449                                 }
ragge
1.66
450                                 break;
ragge
1.3
451
ragge
1.66
452                         case 'M':
453                                 Mflag++;
454                                 break;
ragge
1.51
455
ragge
1.66
456                         case 'd':
457                                 dflag++;
ragge
1.67
458                                 strlcpy(alistargv[i], sizeof (alist));
ragge
1.66
459                                 break;
460                         case 'v':
461                                 printf("%s\n"VERSSTR);
462                                 vflag++;
463                                 break;
ragge
1.14
464
ragge
1.66
465                         case 's':
466                                 if (strcmp(argv[i], "-static") == 0)
467                                         Bstatic = 1;
ragge
1.84
468                                 else if (strcmp(argv[i], "-shared") == 0) {
469                                         shared = 1;
470                                         nostdlib = 1;
471                                 } else
ragge
1.66
472                                         goto passa;
473                                 break;
474                         }
ragge
1.3
475                 } else {
476                 passa:
477                         t = argv[i];
ragge
1.11
478                         if (*argv[i] == '-' && argv[i][1] == 'L')
479                                 ;
ragge
1.59
480                         else if((c=getsuf(t))=='c' || c=='S' || c=='i' ||
ragge
1.91
481                             c=='s'|| Eflag || xcflag) {
ragge
1.3
482                                 clist[nc++] = t;
ragge
1.66
483                                 if (nc>=MAXFIL) {
ragge
1.36
484                                         error("Too many source files");
ragge
1.3
485                                         exit(1);
ragge
1.66
486                                 }
ragge
1.3
487                                 t = setsuf(t'o');
488                         }
stefan
1.76
489
490                         /* Check for duplicate .o files. */
491                         for (j = getsuf(t) == 'o' ? 0 : nlj < nlj++) {
492                                 if (strcmp(llist[j], t) == 0)
493                                         break;
494                         }
495                         if (j == nl) {
ragge
1.3
496                                 llist[nl++] = t;
ragge
1.66
497                                 if (nl >= MAXLIB) {
ragge
1.36
498                                         error("Too many object/library files");
ragge
1.3
499                                         exit(1);
ragge
1.66
500                                 }
ragge
1.3
501                                 if (getsuf(t)=='o')
502                                         nxo++;
ragge
1.1
503                         }
504                 }
505         }
ragge
1.18
506         /* Sanity checking */
507         if (nc == 0 && nl == 0)
ragge
1.36
508                 errorx(8"no input files");
ragge
1.61
509         if (outfile && (cflag || sflag || Eflag) && nc > 1)
510                 errorx(8"-o given with -c || -E || -S and more than one file");
ragge
1.19
511         if (outfile && clist[0] && strcmp(outfileclist[0]) == 0)
ragge
1.36
512                 errorx(8"output file will be clobbered");
ragge
1.4
513         if (gflagOflag = 0;
ragge
1.24
514 #if 0
515         if (proflag)
ragge
1.3
516                 pref = "/lib/mcrt0.o";
ragge
1.24
517 #endif
ragge
1.3
518         if(nc==0)
519                 goto nocom;
520         if (pflag==0) {
stefan
1.74
521                 if (!sflag)
522                         tmp3 = gettmp();
pj
1.30
523                 tmp4 = gettmp();
ragge
1.1
524         }
ragge
1.3
525         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
ragge
1.1
526                 signal(SIGINTidexit);
ragge
1.3
527         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
ragge
1.1
528                 signal(SIGTERMidexit);
ragge
1.3
529         pvt = pv;
ragge
1.1
530         for (i=0i<nci++) {
ragge
1.18
531                 /*
532                  * C preprocessor
533                  */
ragge
1.37
534                 if (nc>1 && !Eflag)
ragge
1.1
535                         printf("%s:\n"clist[i]);
ragge
1.43
536                 onlyas = 0;
pj
1.32
537                 assource = tmp3;
ragge
1.107
538                 if (getsuf(clist[i])=='S')
539                         ascpp = 1;
ragge
1.59
540                 if (getsuf(clist[i])=='i') {
541                         if(Eflag)
542                                 continue;
543                         goto com;
ragge
1.107
544                 } else if (ascpp) {
545                         onlyas = 1;
ragge
1.59
546                 } else if (getsuf(clist[i])=='s') {
ragge
1.1
547                         assource = clist[i];
ragge
1.43
548                         goto assemble;
ragge
1.107
549                 }
ragge
1.1
550                 if (pflag)
551                         tmp4 = setsuf(clist[i], 'i');
ragge
1.5
552                 na = 0;
553                 av[na++] = "cpp";
ragge
1.60
554                 if (vflag)
555                         av[na++] = "-v";
ragge
1.20
556                 av[na++] = "-D__PCC__=" MKS(PCC_MAJOR);
ragge
1.40
557                 av[na++] = "-D__PCC_MINOR__=" MKS(PCC_MINOR);
558                 av[na++] = "-D__PCC_MINORMINOR__=" MKS(PCC_MINORMINOR);
ragge
1.107
559                 if (ascpp)
ragge
1.52
560                         av[na++] = "-D__ASSEMBLER__";
gmcgarry
1.101
561                 if (sspflag)
562                         av[na++] = "-D__SSP__=1";
ragge
1.52
563                 if (pthreads)
564                         av[na++] = "-D_PTHREADS";
ragge
1.63
565                 if (Cflag)
566                         av[na++] = "-C";
ragge
1.51
567                 if (Mflag)
568                         av[na++] = "-M";
ragge
1.57
569                 if (dflag)
570                         av[na++] = alist;
ragge
1.5
571                 for (j = 0cppadd[j]; j++)
572                         av[na++] = cppadd[j];
ragge
1.24
573                 for (j = 0cppmdadd[j]; j++)
574                         av[na++] = cppmdadd[j];
ragge
1.7
575                 if (tflag)
ragge
1.20
576                         av[na++] = "-t";
ragge
1.7
577                 for(pv=ptemppv <pvtpv++)
578                         av[na++] = *pv;
gmcgarry
1.108
579                 if (!nostdinc)
ragge
1.52
580                         av[na++] = "-S"av[na++] = STDINC;
gmcgarry
1.108
581                 av[na++] = "-I" PCCINCDIR;
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
856