Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20080718021709

Diff

Diff from 1.109 to:

Annotations

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

Annotated File View

gmcgarry
1.109
1 /*      $Id: cc.c,v 1.109 2008/07/18 02:17:09 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],
gmcgarry
1.109
330                                     "-fstack-protector-all") == 0) {
331                                         flist[nf++] = argv[i];
332                                         sspflag++;
333                                 } else if (strcmp(argv[i],
gmcgarry
1.101
334                                     "-fno-stack-protector") == 0) {
335                                         flist[nf++] = argv[i];
336                                         sspflag = 0;
gmcgarry
1.109
337                                 } else if (strcmp(argv[i],
338                                     "-fno-stack-protector-all") == 0) {
339                                         flist[nf++] = argv[i];
340                                         sspflag = 0;
gmcgarry
1.101
341                                 }
ragge
1.66
342                                 /* silently ignore the rest */
343                                 break;
ragge
1.14
344
ragge
1.66
345                         case 'g'/* create debug output */
346                                 gflag++;
347                                 break;
ragge
1.25
348
ragge
1.66
349                         case 'i':
350                                 if (strcmp(argv[i], "-isystem") == 0) {
351                                         *pv++ = "-S";
352                                         *pv++ = argv[++i];
353                                 } else if (strcmp(argv[i], "-include") == 0) {
354                                         *pv++ = "-i";
355                                         *pv++ = argv[++i];
ragge
1.83
356                                 } else if (strcmp(argv[i], "-idirafter") == 0) {
357                                         idirafter = argv[++i];
ragge
1.66
358                                 } else
359                                         goto passa;
360                                 break;
ragge
1.20
361
ragge
1.66
362                         case 'k'/* generate PIC code */
363                                 kflag = F_pic;
364                                 break;
ragge
1.49
365
gmcgarry
1.78
366                         case 'm'/* target-dependent options */
367                                 mlist[nm++] = argv[i];
368                                 break;
369
ragge
1.66
370                         case 'n'/* handle -n flags */
371                                 if (strcmp(argv[i], "-nostdinc") == 0)
372                                         nostdinc++;
373                                 else if (strcmp(argv[i], "-nostdlib") == 0) {
374                                         nostdlib++;
375                                         nostartfiles++;
376                                 } else if (strcmp(argv[i], "-nostartfiles") == 0)
377                                         nostartfiles = 1;
378                                 else
379                                         goto passa;
380                                 break;
ragge
1.14
381
ragge
1.66
382                         case 'p':
ragge
1.88
383                                 if (strcmp(argv[i], "-pg") == 0 ||
384                                     strcmp(argv[i], "-p") == 0)
ragge
1.66
385                                         pgflag++;
386                                 else if (strcmp(argv[i], "-pthread") == 0)
387                                         pthreads++;
gmcgarry
1.81
388                                 else if (strcmp(argv[i], "-pipe") == 0) {
389                                 } else
ragge
1.66
390                                         errorx(1"unknown option %s"argv[i]);
391                                 break;
ragge
1.52
392
ragge
1.66
393                         case 'x':
ragge
1.83
394                                 t = &argv[i][2];
395                                 if (*t == 0)
396                                         t = argv[++i];
397                                 if (strcmp(t"c") == 0)
ragge
1.91
398                                         xcflag = 1/* default */
ragge
1.107
399                                 else if (strcmp(t"assembler-with-cpp") == 0)
400                                         ascpp = 1;
ragge
1.83
401 #ifdef notyet
402                                 else if (strcmp(t"c++")
403                                         cxxflag++;
404 #endif
405                                 else
406                                         xlist[xnum++] = argv[i];
ragge
1.66
407                                 break;
408                         case 't':
409                                 tflag++;
410                                 break;
411                         case 'S':
412                                 sflag++;
413                                 cflag++;
414                                 break;
415                         case 'o':
416                                 if (outfile)
417                                         errorx(8"too many -o");
418                                 outfile = argv[++i];
419                                 break;
420                         case 'O':
gmcgarry
1.96
421                                 if (argv[i][2] == '0')
422                                         Oflag = 0;
423                                 else
ragge
1.85
424                                         Oflag++;
ragge
1.66
425                                 break;
426                         case 'E':
427                                 Eflag++;
428                                 break;
429                         case 'P':
430                                 pflag++;
431                                 *pv++ = argv[i];
432                         case 'c':
433                                 cflag++;
434                                 break;
ragge
1.3
435
ragge
1.24
436 #if 0
ragge
1.66
437                         case '2':
438                                 if(argv[i][2] == '\0')
439                                         pref = "/lib/crt2.o";
440                                 else {
441                                         pref = "/lib/crt20.o";
442                                 }
443                                 break;
ragge
1.24
444 #endif
ragge
1.66
445                         case 'C':
446                                 Cflag = 1;
447                                 break;
448                         case 'D':
449                         case 'I':
450                         case 'U':
451                                 *pv++ = argv[i];
452                                 if (argv[i][2] == 0)
453                                         *pv++ = argv[++i];
454                                 if (pv >= ptemp+MAXOPT) {
455                                         error("Too many DIU options");
456                                         --pv;
ragge
1.3
457                                 }
ragge
1.66
458                                 break;
ragge
1.3
459
ragge
1.66
460                         case 'M':
461                                 Mflag++;
462                                 break;
ragge
1.51
463
ragge
1.66
464                         case 'd':
465                                 dflag++;
ragge
1.67
466                                 strlcpy(alistargv[i], sizeof (alist));
ragge
1.66
467                                 break;
468                         case 'v':
469                                 printf("%s\n"VERSSTR);
470                                 vflag++;
471                                 break;
ragge
1.14
472
ragge
1.66
473                         case 's':
474                                 if (strcmp(argv[i], "-static") == 0)
475                                         Bstatic = 1;
ragge
1.84
476                                 else if (strcmp(argv[i], "-shared") == 0) {
477                                         shared = 1;
478                                         nostdlib = 1;
479                                 } else
ragge
1.66
480                                         goto passa;
481                                 break;
482                         }
ragge
1.3
483                 } else {
484                 passa:
485                         t = argv[i];
ragge
1.11
486                         if (*argv[i] == '-' && argv[i][1] == 'L')
487                                 ;
ragge
1.59
488                         else if((c=getsuf(t))=='c' || c=='S' || c=='i' ||
ragge
1.91
489                             c=='s'|| Eflag || xcflag) {
ragge
1.3
490                                 clist[nc++] = t;
ragge
1.66
491                                 if (nc>=MAXFIL) {
ragge
1.36
492                                         error("Too many source files");
ragge
1.3
493                                         exit(1);
ragge
1.66
494                                 }
ragge
1.3
495                                 t = setsuf(t'o');
496                         }
stefan
1.76
497
498                         /* Check for duplicate .o files. */
499                         for (j = getsuf(t) == 'o' ? 0 : nlj < nlj++) {
500                                 if (strcmp(llist[j], t) == 0)
501                                         break;
502                         }
503                         if (j == nl) {
ragge
1.3
504                                 llist[nl++] = t;
ragge
1.66
505                                 if (nl >= MAXLIB) {
ragge
1.36
506                                         error("Too many object/library files");
ragge
1.3
507                                         exit(1);
ragge
1.66
508                                 }
ragge
1.3
509                                 if (getsuf(t)=='o')
510                                         nxo++;
ragge
1.1
511                         }
512                 }
513         }
ragge
1.18
514         /* Sanity checking */
515         if (nc == 0 && nl == 0)
ragge
1.36
516                 errorx(8"no input files");
ragge
1.61
517         if (outfile && (cflag || sflag || Eflag) && nc > 1)
518                 errorx(8"-o given with -c || -E || -S and more than one file");
ragge
1.19
519         if (outfile && clist[0] && strcmp(outfileclist[0]) == 0)
ragge
1.36
520                 errorx(8"output file will be clobbered");
ragge
1.4
521         if (gflagOflag = 0;
ragge
1.24
522 #if 0
523         if (proflag)
ragge
1.3
524                 pref = "/lib/mcrt0.o";
ragge
1.24
525 #endif
ragge
1.3
526         if(nc==0)
527                 goto nocom;
528         if (pflag==0) {
stefan
1.74
529                 if (!sflag)
530                         tmp3 = gettmp();
pj
1.30
531                 tmp4 = gettmp();
ragge
1.1
532         }
ragge
1.3
533         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
ragge
1.1
534                 signal(SIGINTidexit);
ragge
1.3
535         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
ragge
1.1
536                 signal(SIGTERMidexit);
ragge
1.3
537         pvt = pv;
ragge
1.1
538         for (i=0i<nci++) {
ragge
1.18
539                 /*
540                  * C preprocessor
541                  */
ragge
1.37
542                 if (nc>1 && !Eflag)
ragge
1.1
543                         printf("%s:\n"clist[i]);
ragge
1.43
544                 onlyas = 0;
pj
1.32
545                 assource = tmp3;
ragge
1.107
546                 if (getsuf(clist[i])=='S')
547                         ascpp = 1;
ragge
1.59
548                 if (getsuf(clist[i])=='i') {
549                         if(Eflag)
550                                 continue;
551                         goto com;
ragge
1.107
552                 } else if (ascpp) {
553                         onlyas = 1;
ragge
1.59
554                 } else if (getsuf(clist[i])=='s') {
ragge
1.1
555                         assource = clist[i];
ragge
1.43
556                         goto assemble;
ragge
1.107
557                 }
ragge
1.1
558                 if (pflag)
559                         tmp4 = setsuf(clist[i], 'i');
ragge
1.5
560                 na = 0;
561                 av[na++] = "cpp";
ragge
1.60
562                 if (vflag)
563                         av[na++] = "-v";
ragge
1.20
564                 av[na++] = "-D__PCC__=" MKS(PCC_MAJOR);
ragge
1.40
565                 av[na++] = "-D__PCC_MINOR__=" MKS(PCC_MINOR);
566                 av[na++] = "-D__PCC_MINORMINOR__=" MKS(PCC_MINORMINOR);
ragge
1.107
567                 if (ascpp)
ragge
1.52
568                         av[na++] = "-D__ASSEMBLER__";
gmcgarry
1.101
569                 if (sspflag)
570                         av[na++] = "-D__SSP__=1";
ragge
1.52
571                 if (pthreads)
572                         av[na++] = "-D_PTHREADS";
ragge
1.63
573                 if (Cflag)
574                         av[na++] = "-C";
ragge
1.51
575                 if (Mflag)
576                         av[na++] = "-M";
ragge
1.57
577                 if (dflag)
578                         av[na++] = alist;
ragge
1.5
579                 for (j = 0cppadd[j]; j++)
580                         av[na++] = cppadd[j];
ragge
1.24
581                 for (j = 0cppmdadd[j]; j++)
582                         av[na++] = cppmdadd[j];
ragge
1.7
583                 if (tflag)
ragge
1.20
584                         av[na++] = "-t";
ragge
1.7
585                 for(pv=ptemppv <pvtpv++)
586                         av[na++] = *pv;
gmcgarry
1.108
587                 if (!nostdinc)
ragge
1.52
588                         av[na++] = "-S"av[na++] = STDINC;
gmcgarry
1.108
589                 av[na++] = "-I" PCCINCDIR;
ragge
1.83
590                 if (idirafter) {
591                         av[na++] = "-I";
592                         av[na++] = idirafter;
593                 }
ragge
1.5
594                 av[na++] = clist[i];
ragge
1.51
595                 if (!Eflag && !Mflag)
ragge
1.20
596                         av[na++] = tmp4;
ragge
1.61
597                 if (Eflag && outfile)
598                          av[na++] = outfile;
ragge
1.3
599                 av[na++]=0;
600                 if (callsys(passpav))
601                         {exfail++; eflag++;}
ragge
1.51
602                 if (Eflag || Mflag)
ragge
1.37
603                         continue;
stefan
1.73
604                 if (onlyas) {
605                         assource = tmp4;
ragge
1.7
606                         goto assemble;
stefan
1.73
607                 }
ragge
1.18
608
609                 /*
610                  * C compiler
611                  */
ragge
1.59
612         com:
ragge
1.25
613                 na = 0;
614                 av[na++]= "ccom";
gmcgarry
1.101
615                 for (j = 0j < nwj++)
616                         av[na++] = wlist[j];
617                 for (j = 0j < nfj++)
618                         av[na++] = flist[j];
ragge
1.60
619                 if (vflag)
620                         av[na++] = "-v";
gmcgarry
1.81
621                 if (pgflag)
622                         av[na++] = "-p";
ragge
1.25
623                 if (gflag)
624                         av[na++] = "-g";
gmcgarry
1.94
625 #ifdef os_darwin
gmcgarry
1.82
626                 /* darwin always wants PIC compilation */
627                 av[na++] = "-k";
628 #else
ragge
1.49
629                 if (kflag)
630                         av[na++] = "-k";
gmcgarry
1.82
631 #endif
ragge
1.44
632                 if (Oflag) {
633                         av[na++] = "-xtemps";
ragge
1.64
634                         av[na++] = "-xdeljumps";
ragge
1.44
635                 }
ragge
1.45
636                 for (j = 0j < xnumj++)
637                         av[na++] = xlist[j];
gmcgarry
1.78
638                 for (j = 0j < nmj++)
639                         av[na++] = mlist[j];
ragge
1.68
640                 if (getsuf(clist[i])=='i')
641                         av[na++] = clist[i];
642                 else
643                         av[na++] = tmp4/* created by cpp */
ragge
1.3
644                 if (pflag || exfail)
645                         {
ragge
1.1
646                         cflag++;
647                         continue;
ragge
1.3
648                         }
ragge
1.16
649                 if(sflag) {
650                         if (outfile)
stefan
1.77
651                                 tmp3 = outfile;
ragge
1.16
652                         else
stefan
1.77
653                                 tmp3 = setsuf(clist[i], 's');
ragge
1.16
654                 }
ragge
1.25
655                 av[na++] = tmp3;
656 #if 0
ragge
1.3
657                 if (proflag) {
658                         av[3] = "-XP";
659                         av[4] = 0;
660                 } else
661                         av[3] = 0;
ragge
1.25
662 #endif
663                 av[na++] = NULL;
ragge
1.3
664                 if (callsys(pass0av)) {
ragge
1.1
665                         cflag++;
666                         eflag++;
667                         continue;
668                 }
669                 if (sflag)
670                         continue;
ragge
1.18
671
672                 /*
673                  * Assembler
674                  */
ragge
1.1
675         assemble:
ragge
1.49
676                 na = 0;
gmcgarry
1.79
677                 av[na++] = as;
gmcgarry
1.98
678 #if defined(os_sunos) && defined(mach_sparc64)
679                 av[na++] = "-m64";
680 #endif
ragge
1.60
681                 if (vflag)
682                         av[na++] = "-v";
ragge
1.49
683                 if (kflag)
684                         av[na++] = "-k";
685                 av[na++] = "-o";
ragge
1.18
686                 if (outfile && cflag)
ragge
1.49
687                         av[na++] = outfile;
ragge
1.18
688                 else
ragge
1.49
689                         av[na++] = setsuf(clist[i], 'o');
stefan
1.73
690                 av[na++] = assource;
ragge
1.49
691                 if (dflag)
692                         av[na++] = alist;
693                 av[na++] = 0;
gmcgarry
1.79
694                 if (callsys(asav)) {
ragge
1.1
695                         cflag++;
696                         eflag++;
ragge
1.7
697                         cunlink(tmp4);
ragge
1.1
698                         continue;
699                 }
ragge
1.7
700                 cunlink(tmp4);
ragge
1.1
701         }
ragge
1.18
702
ragge
1.51
703         if (Eflag || Mflag)
ragge
1.37
704                 dexit(eflag);
705
ragge
1.18
706         /*
707          * Linker
708          */
ragge
1.1
709 nocom:
710         if (cflag==0 && nl!=0) {
ragge
1.6
711                 j = 0;
gmcgarry
1.79
712                 av[j++] = ld;
gmcgarry
1.95
713 #ifndef os_win32
ragge
1.60
714                 if (vflag)
715                         av[j++] = "-v";
gmcgarry
1.98
716 #ifndef os_sunos
ragge
1.6
717                 av[j++] = "-X";
gmcgarry
1.98
718 #endif
ragge
1.84
719                 if (shared) {
720                         av[j++] = "-shared";
gmcgarry
1.98
721 #ifndef os_sunos
ragge
1.84
722                 } else {
gmcgarry
1.106
723 #ifndef os_darwin
ragge
1.84
724                         av[j++] = "-d";
gmcgarry
1.106
725 #endif
ragge
1.84
726                         av[j++] = "-e";
727                         av[j++] = STARTLABEL;
gmcgarry
1.98
728 #endif
ragge
1.84
729                         if (Bstatic == 0) { /* Dynamic linkage */
gmcgarry
1.94
730 #ifdef DYNLINKER
ragge
1.84
731                                 for (i = 0dynlinker[i]; i++)
732                                         av[j++] = dynlinker[i];
gmcgarry
1.94
733 #endif
ragge
1.84
734                         } else
735                                 av[j++] = "-Bstatic";
736                 }
gmcgarry
1.95
737 #endif
ragge
1.1
738                 if (outfile) {
ragge
1.3
739                         av[j++] = "-o";
740                         av[j++] = outfile;
741                 }
ragge
1.84
742                 if (shared) {
743 #ifdef STARTFILES_S
744                         for (i = 0startfiles_S[i]; i++)
745                                 av[j++] = startfiles_S[i];
746 #endif
747                 } else {
748                         if (!nostartfiles) {
gmcgarry
1.94
749 #ifdef CRT0FILE_PROFILE
750                                 if (pgflag)
751                                 {
752                                         av[j++] = crt0file_profile;
753                                 }
754                                 else
755 #endif
756                                 {
757 #ifdef CRT0FILE
758                                         av[j++] = crt0file;
759 #endif
760                                 }
761 #ifdef STARTFILES
ragge
1.84
762                                 for (i = 0startfiles[i]; i++)
763                                         av[j++] = startfiles[i];
gmcgarry
1.94
764 #endif
ragge
1.84
765                         }
ragge
1.14
766                 }
ragge
1.24
767                 i = 0;
ragge
1.14
768                 while(i<nl) {
ragge
1.3
769                         av[j++] = llist[i++];
ragge
1.14
770                         if (j >= MAXAV)
ragge
1.36
771                                 error("Too many ld options");
ragge
1.14
772                 }
gmcgarry
1.82
773 #ifndef MACHOABI
774                 /* darwin assembler doesn't want -g */
ragge
1.65
775                 if (gflag)
776                         av[j++] = "-g";
gmcgarry
1.82
777 #endif
ragge
1.11
778 #if 0
ragge
1.3
779                 if (gflag)
780                         av[j++] = "-lg";
ragge
1.11
781 #endif
ragge
1.52
782                 if (pthreads)
783                         av[j++] = "-lpthread";
gmcgarry
1.81
784                 if (!nostdlib) {
gmcgarry
1.97
785                         av[j++] = "-L" PCCLIBDIR;
gmcgarry
1.81
786                         if (pgflag) {
787                                 for (i = 0libclibs_profile[i]; i++)
788                                         av[j++] = libclibs_profile[i];
789                         } else {
790                                 for (i = 0libclibs[i]; i++)
791                                         av[j++] = libclibs[i];
792                         }
793                 }
ragge
1.84
794                 if (shared) {
795 #ifdef STARTFILES_S
796                         for (i = 0endfiles_S[i]; i++)
797                                 av[j++] = endfiles_S[i];
798 #endif
799                 } else {
gmcgarry
1.95
800 #ifdef STARTFILES
ragge
1.84
801                         if (!nostartfiles) {
802                                 for (i = 0endfiles[i]; i++)
803                                         av[j++] = endfiles[i];
804                         }
gmcgarry
1.95
805 #endif
ragge
1.14
806                 }
ragge
1.3
807                 av[j++] = 0;
gmcgarry
1.79
808                 eflag |= callsys(ldav);
ragge
1.1
809                 if (nc==1 && nxo==1 && eflag==0)
ragge
1.3
810                         cunlink(setsuf(clist[0], 'o'));
ragge
1.46
811                 else if (nc > 0 && eflag == 0) {
812                         /* remove .o files XXX ugly */
813                         for (i = 0i < nci++)
814                                 cunlink(setsuf(clist[i], 'o'));
815                 }
ragge
1.1
816         }
ragge
1.36
817         dexit(eflag);
ragge
1.4
818         return 0;
ragge
1.1
819 }
820
ragge
1.36
821 /*
822  * exit and cleanup after interrupt.
823  */
ragge
1.4
824 void
825 idexit(int arg)
ragge
1.1
826 {
ragge
1.36
827         dexit(100);
ragge
1.1
828 }
829
ragge
1.36
830 /*
831  * exit and cleanup.
832  */
ragge
1.4
833 void
ragge
1.36
834 dexit(int eval)
ragge
1.1
835 {
ragge
1.10
836         if (!pflag && !Xflag) {
ragge
1.1
837                 if (sflag==0)
838                         cunlink(tmp3);
839                 cunlink(tmp4);
840         }
ragge
1.70
841         if (eval == 100)
842                 _exit(eval);
ragge
1.36
843         exit(eval);
ragge
1.1
844 }
845
ragge
1.36
846 static void
847 ccerror(char *sva_list ap)
ragge