Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20080728144500

Diff

Diff from 1.115 to:

Annotations

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

Annotated File View

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