Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20080622103541

Diff

Diff from 1.105 to:

Annotations

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

Annotated File View

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