Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20080620125033

Diff

Diff from 1.104 to:

Annotations

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

Annotated File View

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