Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20080810145054

Diff

Diff from 1.123 to:

Annotations

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

Annotated File View

ragge
1.123
1 /*      $Id: cc.c,v 1.123 2008/08/10 14:50:54 ragge 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;
gmcgarry
1.119
175 int     Wallflag;
176 int     Wflag;
ragge
1.84
177 int     nostartfilesBstaticshared;
ragge
1.52
178 int     nostdincnostdlib;
ragge
1.43
179 int     onlyas;
ragge
1.52
180 int     pthreads;
ragge
1.91
181 int     xcflag;
ragge
1.107
182 int     ascpp;
ragge
1.14
183
gmcgarry
1.122
184 char    *passp = LIBEXECDIR PREPROCESSOR;
185 char    *pass0 = LIBEXECDIR COMPILER;
gmcgarry
1.79
186 char    *as = ASSEMBLER;
187 char    *ld = LINKER;
ragge
1.47
188 char    *Bflag;
ragge
1.25
189 char *cppadd[] = CPPADD;
gmcgarry
1.94
190 #ifdef DYNLINKER
ragge
1.25
191 char *dynlinker[] = DYNLINKER;
gmcgarry
1.94
192 #endif
193 #ifdef CRT0FILE
ragge
1.25
194 char *crt0file = CRT0FILE;
gmcgarry
1.94
195 #endif
196 #ifdef CRT0FILE_PROFILE
gmcgarry
1.81
197 char *crt0file_profile = CRT0FILE_PROFILE;
gmcgarry
1.94
198 #endif
199 #ifdef STARTFILES
ragge
1.25
200 char *startfiles[] = STARTFILES;
201 char *endfiles[] = ENDFILES;
gmcgarry
1.94
202 #endif
gmcgarry
1.111
203 #ifdef STARTFILES_T
204 char *startfiles_T[] = STARTFILES_T;
205 char *endfiles_T[] = ENDFILES_T;
206 #endif
ragge
1.84
207 #ifdef STARTFILES_S
208 char *startfiles_S[] = STARTFILES_S;
209 char *endfiles_S[] = ENDFILES_S;
210 #endif
ragge
1.25
211 char *cppmdadd[] = CPPMDADD;
ragge
1.50
212 #ifdef LIBCLIBS
213 char *libclibs[] = LIBCLIBS;
214 #else
215 char *libclibs[] = { "-lc"NULL };
216 #endif
gmcgarry
1.81
217 #ifdef LIBCLIBS_PROFILE
218 char *libclibs_profile[] = LIBCLIBS_PROFILE;
219 #else
220 char *libclibs_profile[] = { "-lc_p"NULL };
221 #endif
ragge
1.48
222 #ifndef STARTLABEL
223 #define STARTLABEL "__start"
224 #endif
gmcgarry
1.115
225 char *incdir = STDINC;
226 char *libdir = PCCLIBDIR;
ragge
1.1
227
ragge
1.105
228 /* handle gcc warning emulations */
229 struct Wflags {
230         char *name;
231         int flags;
232 #define INWALL          1
233 #define NEGATIVE        2
234 Wflags[] = {
235         { "-Werror"0 },
236         { "-Wshadow"0 },
237         { "-Wno-shadow"NEGATIVE },
gmcgarry
1.108
238         { "-Wpointer-sign"INWALL },
ragge
1.105
239         { "-Wno-pointer-sign"NEGATIVE },
240         { "-Wsign-compare"0 },
241         { "-Wno-sign-compare"NEGATIVE },
242         { "-Wunknown-pragmas"INWALL },
243         { "-Wno-unknown-pragmas"NEGATIVE },
244         { "-Wunreachable-code"0 },
245         { "-Wno-unreachable-code"NEGATIVE },
246         { 00 },
247 };
248
249 #define SZWFL   (sizeof(Wflags)/sizeof(Wflags[0]))
250
ragge
1.4
251 int
pj
1.26
252 main(int argcchar *argv[])
253 {
ragge
1.105
254         struct Wflags *Wf;
ragge
1.15
255         char *t, *u;
ragge
1.1
256         char *assource;
ragge
1.3
257         char **pv, *ptemp[MAXOPT], **pvt;
gmcgarry
1.118
258         int ncnlnasijcnxona;
ragge
1.3
259
gmcgarry
1.118
260         i = nc = nl = nas = nxo = 0;
ragge
1.3
261         pv = ptemp;
262         while(++i < argc) {
ragge
1.66
263                 if (argv[i][0] == '-') {
264                         switch (argv[i][1]) {
265                         default:
266                                 goto passa;
267 #ifdef notyet
268         /* must add library options first (-L/-l/...) */
269                                 error("unrecognized option `-%c'"argv[i][1]);
270                                 break;
271 #endif
ragge
1.22
272
ragge
1.123
273                         case '-'/* double -'s */
274                                 if (strcmp(argv[i], "--version") == 0)
275                                         printf("%s\n"VERSSTR);
276                                 else
277                                         error("unrecognized option %s",
278                                                 argv[i]);
279                                 break;
280
ragge
1.66
281                         case 'B'/* other search paths for binaries */
282                                 Bflag = &argv[i][2];
283                                 break;
ragge
1.22
284
ragge
1.66
285                         case 'X':
286                                 Xflag++;
287                                 break;
288                         case 'W'/* Ignore (most of) W-flags */
gmcgarry
1.101
289                                 if (strncmp(argv[i], "-Wl,"4) == 0) {
ragge
1.66
290                                         /* options to the linker */
291                                         t = &argv[i][4];
292                                         while ((u = strchr(t','))) {
293                                                 *u++ = 0;
294                                                 llist[nl++] = t;
295                                                 t = u;
296                                         }
ragge
1.15
297                                         llist[nl++] = t;
gmcgarry
1.118
298                                 } else if (strncmp(argv[i], "-Wa,"4) == 0) {
299                                         /* options to the assembler */
300                                         t = &argv[i][4];
301                                         while ((u = strchr(t','))) {
302                                                 *u++ = 0;
303                                                 aslist[nas++] = t;
304                                                 t = u;
305                                         }
306                                         aslist[nas++] = t;
ragge
1.83
307                                 } else if (strncmp(argv[i], "-Wp,"4) == 0) {
308                                         /* preprocessor */
309                                         if (!strncmp(argv[i], "-Wp,-C"6))
310                                                 Cflag++;
gmcgarry
1.101
311                                 } else if (strcmp(argv[i], "-Wall") == 0) {
gmcgarry
1.119
312                                         Wallflag = 1;
ragge
1.105
313                                 } else if (strcmp(argv[i], "-WW") == 0) {
gmcgarry
1.119
314                                         Wflag = 1;
ragge
1.105
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.119
640                 if (Wallflag) {
641                         /* Set only the same flags as gcc */
642                         for (Wf = WflagsWf->nameWf++) {
643                                 if (Wf->flags != INWALL)
644                                         continue;
645                                 av[na++] = Wf->name;
646                         }
647                 }
648                 if (Wflag) {
649                         /* set all positive flags */
650                         for (Wf = WflagsWf->nameWf++) {
651                                 if (Wf->flags == NEGATIVE)
652                                         continue;
653                                 av[na++] = Wf->name;
654                         }
655                 }
gmcgarry
1.101
656                 for (j = 0j < nwj++)
657                         av[na++] = wlist[j];
658                 for (j = 0j < nfj++)
659                         av[na++] = flist[j];
ragge
1.60
660                 if (vflag)
661                         av[na++] = "-v";
gmcgarry
1.81
662                 if (pgflag)
663                         av[na++] = "-p";
ragge
1.25
664                 if (gflag)
665                         av[na++] = "-g";
gmcgarry
1.94
666 #ifdef os_darwin
gmcgarry
1.82
667                 /* darwin always wants PIC compilation */
gmcgarry
1.112
668                 if (!Bstatic)
669                         av[na++] = "-k";
gmcgarry
1.82
670 #else
ragge
1.49
671                 if (kflag)
672                         av[na++] = "-k";
gmcgarry
1.82
673 #endif
ragge
1.44
674                 if (Oflag) {
675                         av[na++] = "-xtemps";
ragge
1.64
676                         av[na++] = "-xdeljumps";
ragge
1.44
677                 }
ragge
1.45
678                 for (j = 0j < xnumj++)
679                         av[na++] = xlist[j];
gmcgarry
1.78
680                 for (j = 0j < nmj++)
681                         av[na++] = mlist[j];
ragge
1.68
682                 if (getsuf(clist[i])=='i')
683                         av[na++] = clist[i];
684                 else
685                         av[na++] = tmp4/* created by cpp */
ragge
1.3
686                 if (pflag || exfail)
687                         {
ragge
1.1
688                         cflag++;
689                         continue;
ragge
1.3
690                         }
ragge
1.16
691                 if(sflag) {
692                         if (outfile)
stefan
1.77
693                                 tmp3 = outfile;
ragge
1.16
694                         else
stefan
1.77
695                                 tmp3 = setsuf(clist[i], 's');
ragge
1.16
696                 }
ragge
1.25
697                 av[na++] = tmp3;
698 #if 0
ragge
1.3
699                 if (proflag) {
700                         av[3] = "-XP";
701                         av[4] = 0;
702                 } else
703                         av[3] = 0;
ragge
1.25
704 #endif
705                 av[na++] = NULL;
ragge
1.3
706                 if (callsys(pass0av)) {
ragge
1.1
707                         cflag++;
708                         eflag++;
709                         continue;
710                 }
711                 if (sflag)
712                         continue;
ragge
1.18
713
714                 /*
715                  * Assembler
716                  */
ragge
1.1
717         assemble:
ragge
1.49
718                 na = 0;
gmcgarry
1.79
719                 av[na++] = as;
gmcgarry
1.118
720                 for (j = 0j < nasj++)
721                         av[na++] = aslist[j];
gmcgarry
1.98
722 #if defined(os_sunos) && defined(mach_sparc64)
723                 av[na++] = "-m64";
724 #endif
gmcgarry
1.113
725 #if defined(os_darwin)
726                 if (Bstatic)
727                         av[na++] = "-static";
728 #endif
ragge
1.60
729                 if (vflag)
730                         av[na++] = "-v";
ragge
1.49
731                 if (kflag)
732                         av[na++] = "-k";
733                 av[na++] = "-o";
ragge
1.18
734                 if (outfile && cflag)
ragge
1.49
735                         av[na++] = outfile;
ragge
1.18
736                 else
ragge
1.49
737                         av[na++] = setsuf(clist[i], 'o');
stefan
1.73
738                 av[na++] = assource;
ragge
1.49
739                 if (dflag)
740                         av[na++] = alist;
741                 av[na++] = 0;
gmcgarry
1.79
742                 if (callsys(asav)) {
ragge
1.1
743                         cflag++;
744                         eflag++;
ragge
1.7
745                         cunlink(tmp4);
ragge
1.1
746                         continue;
747                 }
ragge
1.7
748                 cunlink(tmp4);
ragge
1.1
749         }
ragge
1.18
750
ragge
1.51
751         if (Eflag || Mflag)
ragge
1.37
752                 dexit(eflag);
753
ragge
1.18
754         /*
755          * Linker
756          */
ragge
1.1
757 nocom:
758         if (cflag==0 && nl!=0) {
ragge
1.6
759                 j = 0;
gmcgarry
1.79
760                 av[j++] = ld;
gmcgarry
1.122
761 #ifndef MSLINKER
ragge
1.60
762                 if (vflag)
763                         av[j++] = "-v";
gmcgarry
1.114
764 #endif
765 #if !defined(os_sunos) && !defined(os_win32)
ragge
1.6
766                 av[j++] = "-X";
gmcgarry
1.98
767 #endif
ragge
1.84
768                 if (shared) {
769                         av[j++] = "-shared";
gmcgarry
1.114
770 #ifdef os_win32
771                         av[j++] = "-Bdynamic";
772 #endif
gmcgarry
1.98
773 #ifndef os_sunos
ragge
1.84
774                 } else {
gmcgarry
1.114
775 #ifndef os_win32
gmcgarry
1.106
776 #ifndef os_darwin
ragge
1.84
777                         av[j++] = "-d";
gmcgarry
1.106
778 #endif
ragge
1.84
779                         av[j++] = "-e";
780                         av[j++] = STARTLABEL;
gmcgarry
1.98
781 #endif
gmcgarry
1.114
782 #endif
ragge
1.84
783                         if (Bstatic == 0) { /* Dynamic linkage */
gmcgarry
1.94
784 #ifdef DYNLINKER
ragge
1.84
785                                 for (i = 0dynlinker[i]; i++)
786                                         av[j++] = dynlinker[i];
gmcgarry
1.94
787 #endif
gmcgarry
1.112
788                         } else {
789 #ifdef os_darwin
790                                 av[j++] = "-static";
791 #else
ragge
1.84
792                                 av[j++] = "-Bstatic";
gmcgarry
1.112
793 #endif
794                         }
ragge
1.84
795                 }
ragge
1.1
796                 if (outfile) {
gmcgarry
1.122
797 #ifdef MSLINKER
798                         char *s = copy("/OUT:"strlen(outfile));
799                         strcat(soutfile);
800                         av[j++] = s;
801 #else
ragge
1.3
802                         av[j++] = "-o";
803                         av[j++] = outfile;
gmcgarry
1.122
804 #endif
ragge
1.3
805                 }
gmcgarry
1.110
806 #ifdef STARTFILES_S
ragge
1.84
807                 if (shared) {
gmcgarry
1.114
808                         if (!nostartfiles) {
809                                 for (i = 0startfiles_S[i]; i++)
gmcgarry
1.115
810                                         av[j++] = Bprefix(startfiles_S[i]);
gmcgarry
1.114
811                         }
gmcgarry
1.110
812                 } else
ragge
1.84
813 #endif
gmcgarry
1.110
814                 {
ragge
1.84
815                         if (!nostartfiles) {
gmcgarry
1.94
816 #ifdef CRT0FILE_PROFILE
817                                 if (pgflag)
818                                 {
gmcgarry
1.115
819                                         av[j++] = Bprefix(crt0file_profile);
gmcgarry
1.94
820                                 }
821                                 else
822 #endif
823                                 {
824 #ifdef CRT0FILE
gmcgarry
1.115
825                                         av[j++] = Bprefix(crt0file);
gmcgarry
1.94
826 #endif
827                                 }
gmcgarry
1.111
828 #ifdef STARTFILES_T
829                                 if (Bstatic) {
830                                         for (i = 0startfiles_T[i]; i++)
gmcgarry
1.115
831                                                 av[j++] = Bprefix(listartfiles_T[i]);
gmcgarry
1.111
832                                 } else
833 #endif
834                                 {
gmcgarry
1.94
835 #ifdef STARTFILES
gmcgarry
1.111
836                                         for (i = 0startfiles[i]; i++)
gmcgarry
1.115
837                                                 av[j++] = Bprefix(startfiles[i]);
gmcgarry
1.94
838 #endif
gmcgarry
1.111
839                                 }
ragge
1.84
840                         }
ragge
1.14
841                 }
ragge
1.24
842                 i = 0;
ragge
1.14
843                 while(i<nl) {
ragge
1.3
844                         av[j++] = llist[i++];
ragge
1.14
845                         if (j >= MAXAV)
ragge