Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20080619114358

Diff

Diff from 1.102 to:

Annotations

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

Annotated File View

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