Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20080802091138

Diff

Diff from 1.118 to:

Annotations

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

Annotated File View

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