Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20080802085408

Diff

Diff from 1.117 to:

Annotations

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

Annotated File View

gmcgarry
1.117
1 /*      $Id: cc.c,v 1.117 2008/08/02 08:54:08 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.116
488                                 } else if (strncmp(argv[i], "-std"4) == 0) {
489                                         /* ignore gcc -std= */;
ragge
1.84
490                                 } else
ragge
1.66
491                                         goto passa;
492                                 break;
493                         }
ragge
1.3
494                 } else {
495                 passa:
496                         t = argv[i];
ragge
1.11
497                         if (*argv[i] == '-' && argv[i][1] == 'L')
498                                 ;
ragge
1.59
499                         else if((c=getsuf(t))=='c' || c=='S' || c=='i' ||
ragge
1.91
500                             c=='s'|| Eflag || xcflag) {
ragge
1.3
501                                 clist[nc++] = t;
ragge
1.66
502                                 if (nc>=MAXFIL) {
ragge
1.36
503                                         error("Too many source files");
ragge
1.3
504                                         exit(1);
ragge
1.66
505                                 }
ragge
1.3
506                                 t = setsuf(t'o');
507                         }
stefan
1.76
508
509                         /* Check for duplicate .o files. */
510                         for (j = getsuf(t) == 'o' ? 0 : nlj < nlj++) {
511                                 if (strcmp(llist[j], t) == 0)
512                                         break;
513                         }
514                         if (j == nl) {
ragge
1.3
515                                 llist[nl++] = t;
ragge
1.66
516                                 if (nl >= MAXLIB) {
ragge
1.36
517                                         error("Too many object/library files");
ragge
1.3
518                                         exit(1);
ragge
1.66
519                                 }
ragge
1.3
520                                 if (getsuf(t)=='o')
521                                         nxo++;
ragge
1.1
522                         }
523                 }
524         }
ragge
1.18
525         /* Sanity checking */
526         if (nc == 0 && nl == 0)
ragge
1.36
527                 errorx(8"no input files");
ragge
1.61
528         if (outfile && (cflag || sflag || Eflag) && nc > 1)
529                 errorx(8"-o given with -c || -E || -S and more than one file");
ragge
1.19
530         if (outfile && clist[0] && strcmp(outfileclist[0]) == 0)
ragge
1.36
531                 errorx(8"output file will be clobbered");
ragge
1.4
532         if (gflagOflag = 0;
ragge
1.24
533 #if 0
534         if (proflag)
ragge
1.3
535                 pref = "/lib/mcrt0.o";
ragge
1.24
536 #endif
ragge
1.3
537         if(nc==0)
538                 goto nocom;
539         if (pflag==0) {
stefan
1.74
540                 if (!sflag)
541                         tmp3 = gettmp();
pj
1.30
542                 tmp4 = gettmp();
ragge
1.1
543         }
gmcgarry
1.115
544         if (Bflag) {
545                 incdir = Bflag;
546                 libdir = Bflag;
547         }
ragge
1.3
548         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
ragge
1.1
549                 signal(SIGINTidexit);
ragge
1.3
550         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
ragge
1.1
551                 signal(SIGTERMidexit);
ragge
1.3
552         pvt = pv;
ragge
1.1
553         for (i=0i<nci++) {
ragge
1.18
554                 /*
555                  * C preprocessor
556                  */
ragge
1.37
557                 if (nc>1 && !Eflag)
ragge
1.1
558                         printf("%s:\n"clist[i]);
ragge
1.43
559                 onlyas = 0;
pj
1.32
560                 assource = tmp3;
ragge
1.107
561                 if (getsuf(clist[i])=='S')
562                         ascpp = 1;
ragge
1.59
563                 if (getsuf(clist[i])=='i') {
564                         if(Eflag)
565                                 continue;
566                         goto com;
ragge
1.107
567                 } else if (ascpp) {
568                         onlyas = 1;
ragge
1.59
569                 } else if (getsuf(clist[i])=='s') {
ragge
1.1
570                         assource = clist[i];
ragge
1.43
571                         goto assemble;
ragge
1.107
572                 }
ragge
1.1
573                 if (pflag)
574                         tmp4 = setsuf(clist[i], 'i');
ragge
1.5
575                 na = 0;
576                 av[na++] = "cpp";
ragge
1.60
577                 if (vflag)
578                         av[na++] = "-v";
ragge
1.20
579                 av[na++] = "-D__PCC__=" MKS(PCC_MAJOR);
ragge
1.40
580                 av[na++] = "-D__PCC_MINOR__=" MKS(PCC_MINOR);
581                 av[na++] = "-D__PCC_MINORMINOR__=" MKS(PCC_MINORMINOR);
ragge
1.107
582                 if (ascpp)
ragge
1.52
583                         av[na++] = "-D__ASSEMBLER__";
gmcgarry
1.101
584                 if (sspflag)
585                         av[na++] = "-D__SSP__=1";
ragge
1.52
586                 if (pthreads)
587                         av[na++] = "-D_PTHREADS";
ragge
1.63
588                 if (Cflag)
589                         av[na++] = "-C";
ragge
1.51
590                 if (Mflag)
591                         av[na++] = "-M";
ragge
1.57
592                 if (dflag)
593                         av[na++] = alist;
ragge
1.5
594                 for (j = 0cppadd[j]; j++)
595                         av[na++] = cppadd[j];
ragge
1.24
596                 for (j = 0cppmdadd[j]; j++)
597                         av[na++] = cppmdadd[j];
ragge
1.7
598                 if (tflag)
ragge
1.20
599                         av[na++] = "-t";
ragge
1.7
600                 for(pv=ptemppv <pvtpv++)
601                         av[na++] = *pv;
gmcgarry
1.108
602                 if (!nostdinc)
gmcgarry
1.115
603                         av[na++] = "-S"av[na++] = incdir;
604                 av[na++] = "-I"av[na++] = PCCINCDIR;
ragge
1.83
605                 if (idirafter) {
606                         av[na++] = "-I";
607                         av[na++] = idirafter;
608                 }
ragge
1.5
609                 av[na++] = clist[i];
ragge
1.51
610                 if (!Eflag && !Mflag)
ragge
1.20
611                         av[na++] = tmp4;
ragge
1.61
612                 if (Eflag && outfile)
613                          av[na++] = outfile;
ragge
1.3
614                 av[na++]=0;
615                 if (callsys(passpav))
616                         {exfail++; eflag++;}
ragge
1.51
617                 if (Eflag || Mflag)
ragge
1.37
618                         continue;
stefan
1.73
619                 if (onlyas) {
620                         assource = tmp4;
ragge
1.7
621                         goto assemble;
stefan
1.73
622                 }
ragge
1.18
623
624                 /*
625                  * C compiler
626                  */
ragge
1.59
627         com:
ragge
1.25
628                 na = 0;
629                 av[na++]= "ccom";
gmcgarry
1.101
630                 for (j = 0j < nwj++)
631                         av[na++] = wlist[j];
632                 for (j = 0j < nfj++)
633                         av[na++] = flist[j];
ragge
1.60
634                 if (vflag)
635                         av[na++] = "-v";
gmcgarry
1.81
636                 if (pgflag)
637                         av[na++] = "-p";
ragge
1.25
638                 if (gflag)
639                         av[na++] = "-g";
gmcgarry
1.94
640 #ifdef os_darwin
gmcgarry
1.82
641                 /* darwin always wants PIC compilation */
gmcgarry
1.112
642                 if (!Bstatic)
643                         av[na++] = "-k";
gmcgarry
1.82
644 #else
ragge
1.49
645                 if (kflag)
646                         av[na++] = "-k";
gmcgarry
1.82
647 #endif
ragge
1.44
648                 if (Oflag) {
649                         av[na++] = "-xtemps";
ragge
1.64
650                         av[na++] = "-xdeljumps";
ragge
1.44
651                 }
ragge
1.45
652                 for (j = 0j < xnumj++)
653                         av[na++] = xlist[j];
gmcgarry
1.78
654                 for (j = 0j < nmj++)
655                         av[na++] = mlist[j];
ragge
1.68
656                 if (getsuf(clist[i])=='i')
657                         av[na++] = clist[i];
658                 else
659                         av[na++] = tmp4/* created by cpp */
ragge
1.3
660                 if (pflag || exfail)
661                         {
ragge
1.1
662                         cflag++;
663                         continue;
ragge
1.3
664                         }
ragge
1.16
665                 if(sflag) {
666                         if (outfile)
stefan
1.77
667                                 tmp3 = outfile;
ragge
1.16
668                         else
stefan
1.77
669                                 tmp3 = setsuf(clist[i], 's');
ragge
1.16
670                 }
ragge
1.25
671                 av[na++] = tmp3;
672 #if 0
ragge
1.3
673                 if (proflag) {
674                         av[3] = "-XP";
675                         av[4] = 0;
676                 } else
677                         av[3] = 0;
ragge
1.25
678 #endif
679                 av[na++] = NULL;
ragge
1.3
680                 if (callsys(pass0av)) {
ragge
1.1
681                         cflag++;
682                         eflag++;
683                         continue;
684                 }
685                 if (sflag)
686                         continue;
ragge
1.18
687
688                 /*
689                  * Assembler
690                  */
ragge
1.1
691         assemble:
ragge
1.49
692                 na = 0;
gmcgarry
1.79
693                 av[na++] = as;
gmcgarry
1.98
694 #if defined(os_sunos) && defined(mach_sparc64)
695                 av[na++] = "-m64";
696 #endif
gmcgarry
1.113
697 #if defined(os_darwin)
698                 if (Bstatic)
699                         av[na++] = "-static";
700 #endif
ragge
1.60
701                 if (vflag)
702                         av[na++] = "-v";
ragge
1.49
703                 if (kflag)
704                         av[na++] = "-k";
705                 av[na++] = "-o";
ragge
1.18
706                 if (outfile && cflag)
ragge
1.49
707                         av[na++] = outfile;
ragge
1.18
708                 else
ragge
1.49
709                         av[na++] = setsuf(clist[i], 'o');
stefan
1.73
710                 av[na++] = assource;
ragge
1.49
711                 if (dflag)
712                         av[na++] = alist;
713                 av[na++] = 0;
gmcgarry
1.79
714                 if (callsys(asav)) {
ragge
1.1
715                         cflag++;
716                         eflag++;
ragge
1.7
717                         cunlink(tmp4);
ragge
1.1
718                         continue;
719                 }
ragge
1.7
720                 cunlink(tmp4);
ragge
1.1
721         }
ragge
1.18
722
ragge
1.51
723         if (Eflag || Mflag)
ragge
1.37
724                 dexit(eflag);
725
ragge
1.18
726         /*
727          * Linker
728          */
ragge
1.1
729 nocom:
730         if (cflag==0 && nl!=0) {
ragge
1.6
731                 j = 0;
gmcgarry
1.79
732                 av[j++] = ld;
gmcgarry
1.95
733 #ifndef os_win32
ragge
1.60
734                 if (vflag)
735                         av[j++] = "-v";
gmcgarry
1.114
736 #endif
737 #if !defined(os_sunos) && !defined(os_win32)
ragge
1.6
738                 av[j++] = "-X";
gmcgarry
1.98
739 #endif
ragge
1.84
740                 if (shared) {
741                         av[j++] = "-shared";
gmcgarry
1.114
742 #ifdef os_win32
743                         av[j++] = "-Bdynamic";
744 #endif
gmcgarry
1.98
745 #ifndef os_sunos
ragge
1.84
746                 } else {
gmcgarry
1.114
747 #ifndef os_win32
gmcgarry
1.106
748 #ifndef os_darwin
ragge
1.84
749                         av[j++] = "-d";
gmcgarry
1.106
750 #endif
ragge
1.84
751                         av[j++] = "-e";
752                         av[j++] = STARTLABEL;
gmcgarry
1.98
753 #endif
gmcgarry
1.114
754 #endif
ragge
1.84
755                         if (Bstatic == 0) { /* Dynamic linkage */
gmcgarry
1.94
756 #ifdef DYNLINKER
ragge
1.84
757                                 for (i = 0dynlinker[i]; i++)
758                                         av[j++] = dynlinker[i];
gmcgarry
1.94
759 #endif
gmcgarry
1.112
760                         } else {
761 #ifdef os_darwin
762                                 av[j++] = "-static";
763 #else
ragge
1.84
764                                 av[j++] = "-Bstatic";
gmcgarry
1.112
765 #endif
766                         }
ragge
1.84
767                 }
ragge
1.1
768                 if (outfile) {
ragge
1.3
769                         av[j++] = "-o";
770                         av[j++] = outfile;
771                 }
gmcgarry
1.110
772 #ifdef STARTFILES_S
ragge
1.84
773                 if (shared) {
gmcgarry
1.114
774                         if (!nostartfiles) {
775                                 for (i = 0startfiles_S[i]; i++)
gmcgarry
1.115
776                                         av[j++] = Bprefix(startfiles_S[i]);
gmcgarry
1.114
777                         }
gmcgarry
1.110
778                 } else
ragge
1.84
779 #endif
gmcgarry
1.110
780                 {
ragge
1.84
781                         if (!nostartfiles) {
gmcgarry
1.94
782 #ifdef CRT0FILE_PROFILE
783                                 if (pgflag)
784                                 {
gmcgarry
1.115
785                                         av[j++] = Bprefix(crt0file_profile);
gmcgarry
1.94
786                                 }
787                                 else
788 #endif
789                                 {
790 #ifdef CRT0FILE
gmcgarry
1.115
791                                         av[j++] = Bprefix(crt0file);
gmcgarry
1.94
792 #endif
793                                 }
gmcgarry
1.111
794 #ifdef STARTFILES_T
795                                 if (Bstatic) {
796                                         for (i = 0startfiles_T[i]; i++)
gmcgarry
1.115
797                                                 av[j++] = Bprefix(listartfiles_T[i]);
gmcgarry
1.111
798                                 } else
799 #endif
800                                 {
gmcgarry
1.94
801 #ifdef STARTFILES
gmcgarry
1.111
802                                         for (i = 0startfiles[i]; i++)
gmcgarry
1.115
803                                                 av[j++] = Bprefix(startfiles[i]);
gmcgarry
1.94
804 #endif
gmcgarry
1.111
805                                 }
ragge
1.84
806                         }
ragge
1.14
807                 }
ragge
1.24
808                 i = 0;
ragge
1.14
809                 while(i<nl) {
ragge
1.3
810                         av[j++] = llist[i++];
ragge
1.14
811                         if (j >= MAXAV)
ragge
1.36
812                                 error("Too many ld options");
ragge
1.14
813                 }
gmcgarry
1.82
814 #ifndef MACHOABI
815                 /* darwin assembler doesn't want -g */
ragge
1.65
816                 if (gflag)
817                         av[j++] = "-g";
gmcgarry
1.82
818 #endif
ragge
1.11
819 #if 0
ragge
1.3
820                 if (gflag)
821                         av[j++] = "-lg";
ragge
1.11
822 #endif
ragge
1.52
823                 if (pthreads)
824                         av[j++] = "-lpthread";
gmcgarry
1.81
825                 if (!nostdlib) {
gmcgarry
1.115
826                         char *s = copy("-L"strlen(libdir));
827                         strcat(slibdir);
828                         av[j++] = s;
gmcgarry
1.81
829                         if (pgflag) {
830                                 for (i = 0libclibs_profile[i]; i++)
gmcgarry
1.115
831                                         av[j++] = Bprefix(libclibs_profile[i]);
gmcgarry
1.81
832                         } else {
833                                 for (i = 0libclibs[i]; i++)
gmcgarry
1.115
834                                         av[j++] = Bprefix(libclibs[i]);
gmcgarry
1.81
835                         }
836                 }
gmcgarry
1.117
837                 if (!nostartfiles) {
gmcgarry
1.110
838 #ifdef STARTFILES_S
gmcgarry
1.117
839                         if (shared) {
840                                 for (i = 0endfiles_S[i]; i++)
841                                  &n