Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20080620123752

Diff

Diff from 1.103 to:

Annotations

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

Annotated File View

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