Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20080810135140

Diff

Diff from 1.122 to:

Annotations

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

Annotated File View

gmcgarry
1.122
1 /*      $Id: cc.c,v 1.122 2008/08/10 13:51:40 gmcgarry Exp $    */
ragge
1.3
2 /*
3  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * Redistributions of source code and documentation must retain the above
10  * copyright notice, this list of conditions and the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditionsand the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * All advertising materials mentioning features or use of this software
15  * must display the following acknowledgement:
16  *      This product includes software developed or owned by Caldera
17  *      International, Inc.
18  * Neither the name of Caldera International, Inc. nor the names of other
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23  * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
27  * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
ragge
1.2
35
ragge
1.1
36 /*
ragge
1.3
37  * Front-end to the C compiler.
ragge
1.18
38  *
39  * Brief description of its syntax:
40  * - Files that end with .c are passed via cpp->ccom->as->ld
ragge
1.59
41  * - Files that end with .i are passed via ccom->as->ld
ragge
1.18
42  * - Files that end with .s are passed as->ld
43  * - Files that end with .o are passed directly to ld
44  * - Multiple files may be given on the command line.
45  * - Unrecognized options are all sent directly to ld.
46  * -c or -S cannot be combined with -o if multiple files are given.
47  *
48  * This file should be rewritten readable.
ragge
1.1
49  */
ragge
1.80
50 #include "config.h"
51
ragge
1.9
52 #include <sys/types.h>
gmcgarry
1.86
53 #ifdef HAVE_SYS_WAIT_H
ragge
1.36
54 #include <sys/wait.h>
gmcgarry
1.86
55 #endif
ragge
1.2
56
ragge
1.1
57 #include <ctype.h>
stefan
1.72
58 #include <errno.h>
59 #include <fcntl.h>
gmcgarry
1.86
60 #ifdef HAVE_LIBGEN_H
stefan
1.72
61 #include <libgen.h>
gmcgarry
1.86
62 #endif
ragge
1.1
63 #include <signal.h>
stefan
1.72
64 #include <stdarg.h>
65 #include <stdio.h>
66 #include <stdlib.h>
ragge
1.4
67 #include <string.h>
gmcgarry
1.86
68 #ifdef HAVE_UNISTD_H
ragge
1.4
69 #include <unistd.h>
gmcgarry
1.86
70 #endif
71
gmcgarry
1.87
72 #ifdef WIN32
gmcgarry
1.86
73 #include <windows.h>
74 #include <process.h>
75 #include <io.h>
76 #endif
77
78 #include "compat.h"
ragge
1.24
79
80 #include "ccconfig.h"
ragge
1.3
81 /* C command */
ragge
1.1
82
ragge
1.20
83 #define MKS(x) _MKS(x)
84 #define _MKS(x) #x
85
86 /*
87  * Many specific definitions, should be declared elsewhere.
88  */
gmcgarry
1.79
89
90 #ifndef STDINC
91 #define STDINC          "/usr/include/"
92 #endif
93
gmcgarry
1.97
94 #ifndef LIBDIR
95 #define LIBDIR          "/usr/lib/"
96 #endif
97
gmcgarry
1.79
98 #ifndef PREPROCESSOR
99 #define PREPROCESSOR    "cpp"
100 #endif
101
102 #ifndef COMPILER
103 #define COMPILER        "ccom";
104 #endif
105
106 #ifndef ASSEMBLER
107 #define ASSEMBLER       "as"
108 #endif
109
110 #ifndef LINKER
111 #define LINKER          "ld"
112 #endif
ragge
1.20
113
gmcgarry
1.97
114 #define OS MKS(TARGOS)
115 #define MACH MKS(TARGMACH)
116 #ifndef PCCINCDIR
117 #define PCCINCDIR       LIBDIR "pcc/" MACH "-" OS "/" PACKAGE_VERSION "/include"
118 #endif
119 #ifndef PCCLIBDIR
120 #define PCCLIBDIR       LIBDIR "pcc/" MACH "-" OS "/" PACKAGE_VERSION "/lib"
121 #endif
122
ragge
1.62
123 #define MAXFIL 10000
ragge
1.12
124 #define MAXLIB 10000
ragge
1.14
125 #define MAXAV  10000
ragge
1.3
126 #define MAXOPT 100
127 char    *tmp3;
128 char    *tmp4;
ragge
1.1
129 char    *outfile;
gmcgarry
1.115
130 char *Bprefix(char *);
ragge
1.91
131 char *copy(char *, int),*setsuf(char *, char);
stefan
1.72
132 int getsuf(char *);
ragge
1.4
133 int main(intchar *[]);
ragge
1.36
134 void error(char *, ...);
stefan
1.72
135 void errorx(intchar *, ...);
ragge
1.4
136 int callsys(char [], char *[]);
137 int cunlink(char *);
stefan
1.72
138 void dexit(int);
ragge
1.4
139 void idexit(int);
gmcgarry
1.99
140 char *gettmp(void);
ragge
1.91
141 void *ccmalloc(int size);
ragge
1.14
142 char    *av[MAXAV];
ragge
1.3
143 char    *clist[MAXFIL];
144 char    *llist[MAXLIB];
gmcgarry
1.118
145 char    *aslist[MAXAV];
ragge
1.4
146 char    alist[20];
ragge
1.43
147 char    *xlist[100];
148 int     xnum;
gmcgarry
1.78
149 char    *mlist[100];
gmcgarry
1.101
150 char    *flist[100];
151 char    *wlist[100];
ragge
1.83
152 char    *idirafter;
gmcgarry
1.78
153 int     nm;
gmcgarry
1.101
154 int     nf;
155 int     nw;
156 int     sspflag;
ragge
1.63
157 int     Cflag;
ragge
1.43
158 int     dflag;
ragge
1.3
159 int     pflag;
160 int     sflag;
161 int     cflag;
162 int     eflag;
163 int     gflag;
ragge
1.5
164 int     vflag;
ragge
1.7
165 int     tflag;
ragge
1.8
166 int     Eflag;
ragge
1.4
167 int     Oflag;
ragge
1.58
168 int     kflag;  /* generate PIC/pic code */
169 #define F_PIC   1
170 #define F_pic   2
ragge
1.51
171 int     Mflag;  /* dependencies only */
ragge
1.52
172 int     pgflag;
ragge
1.1
173 int     exfail;
ragge
1.10
174 int     Xflag;
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.66
273                         case 'B'/* other search paths for binaries */
274                                 Bflag = &argv[i][2];
275                                 break;
ragge
1.22
276
ragge
1.66
277                         case 'X':
278                                 Xflag++;
279                                 break;
280                         case 'W'/* Ignore (most of) W-flags */
gmcgarry
1.101
281                                 if (strncmp(argv[i], "-Wl,"4) == 0) {
ragge
1.66
282                                         /* options to the linker */
283                                         t = &argv[i][4];
284                                         while ((u = strchr(t','))) {
285                                                 *u++ = 0;
286                                                 llist[nl++] = t;
287                                                 t = u;
288                                         }
ragge
1.15
289                                         llist[nl++] = t;
gmcgarry
1.118
290                                 } else if (strncmp(argv[i], "-Wa,"4) == 0) {
291                                         /* options to the assembler */
292                                         t = &argv[i][4];
293                                         while ((u = strchr(t','))) {
294                                                 *u++ = 0;
295                                                 aslist[nas++] = t;
296                                                 t = u;
297                                         }
298                                         aslist[nas++] = t;
ragge
1.83
299                                 } else if (strncmp(argv[i], "-Wp,"4) == 0) {
300                                         /* preprocessor */
301                                         if (!strncmp(argv[i], "-Wp,-C"6))
302                                                 Cflag++;
gmcgarry
1.101
303                                 } else if (strcmp(argv[i], "-Wall") == 0) {
gmcgarry
1.119
304                                         Wallflag = 1;
ragge
1.105
305                                 } else if (strcmp(argv[i], "-WW") == 0) {
gmcgarry
1.119
306                                         Wflag = 1;
ragge
1.105
307                                 } else {
308                                         /* check and set if available */
309                                         for (Wf = WflagsWf->nameWf++) {
310                                                 if (strcmp(argv[i], Wf->name))
311                                                         continue;
312                                                 wlist[nw++] = Wf->name;
313                                         }
ragge
1.15
314                                 }
ragge
1.66
315                                 break;
ragge
1.15
316
ragge
1.66
317                         case 'f'/* GCC compatibility flags */
318                                 if (strcmp(argv[i], "-fPIC") == 0)
319                                         kflag = F_PIC;
gmcgarry
1.101
320                                 else if (strcmp(argv[i], "-fpic") == 0)
ragge
1.66
321                                         kflag = F_pic;
gmcgarry
1.101
322                                 else if (strcmp(argv[i],
323                                     "-fsigned-char") == 0)
324                                         flist[nf++] = argv[i];
325                                 else if (strcmp(argv[i],
326                                     "-fno-signed-char") == 0)
327                                         flist[nf++] = argv[i];
328                                 else if (strcmp(argv[i],
329                                     "-funsigned-char") == 0)
330                                         flist[nf++] = argv[i];
331                                 else if (strcmp(argv[i],
332                                     "-fno-unsigned-char") == 0)
333                                         flist[nf++] = argv[i];
334                                 else if (strcmp(argv[i],
335                                     "-fstack-protector") == 0) {
336                                         flist[nf++] = argv[i];
337                                         sspflag++;
338                                 } else if (strcmp(argv[i],
gmcgarry
1.109
339                                     "-fstack-protector-all") == 0) {
340                                         flist[nf++] = argv[i];
341                                         sspflag++;
342                                 } else if (strcmp(argv[i],
gmcgarry
1.101
343                                     "-fno-stack-protector") == 0) {
344                                         flist[nf++] = argv[i];
345                                         sspflag = 0;
gmcgarry
1.109
346                                 } else if (strcmp(argv[i],
347                                     "-fno-stack-protector-all") == 0) {
348                                         flist[nf++] = argv[i];
349                                         sspflag = 0;
gmcgarry
1.101
350                                 }
ragge
1.66
351                                 /* silently ignore the rest */
352                                 break;
ragge
1.14
353
ragge
1.66
354                         case 'g'/* create debug output */
355                                 gflag++;
356                                 break;
ragge
1.25
357
ragge
1.66
358                         case 'i':
359                                 if (strcmp(argv[i], "-isystem") == 0) {
360                                         *pv++ = "-S";
361                                         *pv++ = argv[++i];
362                                 } else if (strcmp(argv[i], "-include") == 0) {
363                                         *pv++ = "-i";
364                                         *pv++ = argv[++i];
ragge
1.83
365                                 } else if (strcmp(argv[i], "-idirafter") == 0) {
366                                         idirafter = argv[++i];
ragge
1.66
367                                 } else
368                                         goto passa;
369                                 break;
ragge
1.20
370
ragge
1.66
371                         case 'k'/* generate PIC code */
372                                 kflag = F_pic;
373                                 break;
ragge
1.49
374
gmcgarry
1.78
375                         case 'm'/* target-dependent options */
376                                 mlist[nm++] = argv[i];
377                                 break;
378
ragge
1.66
379                         case 'n'/* handle -n flags */
380                                 if (strcmp(argv[i], "-nostdinc") == 0)
381                                         nostdinc++;
382                                 else if (strcmp(argv[i], "-nostdlib") == 0) {
383                                         nostdlib++;
384                                         nostartfiles++;
385                                 } else if (strcmp(argv[i], "-nostartfiles") == 0)
386                                         nostartfiles = 1;
387                                 else
388                                         goto passa;
389                                 break;
ragge
1.14
390
ragge
1.66
391                         case 'p':
ragge
1.88
392                                 if (strcmp(argv[i], "-pg") == 0 ||
393                                     strcmp(argv[i], "-p") == 0)
ragge
1.66
394                                         pgflag++;
395                                 else if (strcmp(argv[i], "-pthread") == 0)
396                                         pthreads++;
gmcgarry
1.81
397                                 else if (strcmp(argv[i], "-pipe") == 0) {
398                                 } else
ragge
1.66
399                                         errorx(1"unknown option %s"argv[i]);
400                                 break;
ragge
1.52
401
ragge
1.66
402                         case 'x':
ragge
1.83
403                                 t = &argv[i][2];
404                                 if (*t == 0)
405                                         t = argv[++i];
406                                 if (strcmp(t"c") == 0)
ragge
1.91
407                                         xcflag = 1/* default */
ragge
1.107
408                                 else if (strcmp(t"assembler-with-cpp") == 0)
409                                         ascpp = 1;
ragge
1.83
410 #ifdef notyet
411                                 else if (strcmp(t"c++")
412                                         cxxflag++;
413 #endif
414                                 else
415                                         xlist[xnum++] = argv[i];
ragge
1.66
416                                 break;
417                         case 't':
418                                 tflag++;
419                                 break;
420                         case 'S':
421                                 sflag++;
422                                 cflag++;
423                                 break;
424                         case 'o':
425                                 if (outfile)
426                                         errorx(8"too many -o");
427                                 outfile = argv[++i];
428                                 break;
429                         case 'O':
gmcgarry
1.96
430                                 if (argv[i][2] == '0')
431                                         Oflag = 0;
432                                 else
ragge
1.85
433                                         Oflag++;
ragge
1.66
434                                 break;
435                         case 'E':
436                                 Eflag++;
437                                 break;
438                         case 'P':
439                                 pflag++;
440                                 *pv++ = argv[i];
441                         case 'c':
442                                 cflag++;
443                                 break;
ragge
1.3
444
ragge
1.24
445 #if 0
ragge
1.66
446                         case '2':
447                                 if(argv[i][2] == '\0')
448                                         pref = "/lib/crt2.o";
449                                 else {
450                                         pref = "/lib/crt20.o";
451                                 }
452                                 break;
ragge
1.24
453 #endif
ragge
1.66
454                         case 'C':
455                                 Cflag = 1;
456                                 break;
457                         case 'D':
458                         case 'I':
459                         case 'U':
460                                 *pv++ = argv[i];
461                                 if (argv[i][2] == 0)
462                                         *pv++ = argv[++i];
463                                 if (pv >= ptemp+MAXOPT) {
464                                         error("Too many DIU options");
465                                         --pv;
ragge
1.3
466                                 }
ragge
1.66
467                                 break;
ragge
1.3
468
ragge
1.66
469                         case 'M':
470                                 Mflag++;
471                                 break;
ragge
1.51
472
ragge
1.66
473                         case 'd':
474                                 dflag++;
ragge
1.67
475                                 strlcpy(alistargv[i], sizeof (alist));
ragge
1.66
476                                 break;
477                         case 'v':
478                                 printf("%s\n"VERSSTR);
479                                 vflag++;
480                                 break;
ragge
1.14
481
ragge
1.66
482                         case 's':
483                                 if (strcmp(argv[i], "-static") == 0)
484                                         Bstatic = 1;
ragge
1.84
485                                 else if (strcmp(argv[i], "-shared") == 0) {
486                                         shared = 1;
gmcgarry
1.114
487 #ifndef os_win32
ragge
1.84
488                                         nostdlib = 1;
gmcgarry
1.114
489 #endif
ragge
1.116
490                                 } else if (strncmp(argv[i], "-std"4) == 0) {
491                                         /* ignore gcc -std= */;
ragge
1.84
492                                 } else
ragge
1.66
493                                         goto passa;
494                                 break;
495                         }
ragge
1.3
496                 } else {
497                 passa:
498                         t = argv[i];
ragge
1.11
499                         if (*argv[i] == '-' && argv[i][1] == 'L')
500                                 ;
ragge
1.59
501                         else if((c=getsuf(t))=='c' || c=='S' || c=='i' ||
ragge
1.91
502                             c=='s'|| Eflag || xcflag) {
ragge
1.3
503                                 clist[nc++] = t;
ragge
1.66
504                                 if (nc>=MAXFIL) {
ragge
1.36
505                                         error("Too many source files");
ragge
1.3
506                                         exit(1);
ragge
1.66
507                                 }
ragge
1.3
508                                 t = setsuf(t'o');
509                         }
stefan
1.76
510
511                         /* Check for duplicate .o files. */
512                         for (j = getsuf(t) == 'o' ? 0 : nlj < nlj++) {
513                                 if (strcmp(llist[j], t) == 0)
514                                         break;
515                         }
516                         if (j == nl) {
ragge
1.3
517                                 llist[nl++] = t;
ragge
1.66
518                                 if (nl >= MAXLIB) {
ragge
1.36
519                                         error("Too many object/library files");
ragge
1.3
520                                         exit(1);
ragge
1.66
521                                 }
ragge
1.3
522                                 if (getsuf(t)=='o')
523                                         nxo++;
ragge
1.1
524                         }
525                 }
526         }
ragge
1.18
527         /* Sanity checking */
528         if (nc == 0 && nl == 0)
ragge
1.36
529                 errorx(8"no input files");
ragge
1.61
530         if (outfile && (cflag || sflag || Eflag) && nc > 1)
531                 errorx(8"-o given with -c || -E || -S and more than one file");
ragge
1.19
532         if (outfile && clist[0] && strcmp(outfileclist[0]) == 0)
ragge
1.36
533                 errorx(8"output file will be clobbered");
ragge
1.4
534         if (gflagOflag = 0;
ragge
1.24
535 #if 0
536         if (proflag)
ragge
1.3
537                 pref = "/lib/mcrt0.o";
ragge
1.24
538 #endif
ragge
1.3
539         if(nc==0)
540                 goto nocom;
541         if (pflag==0) {
stefan
1.74
542                 if (!sflag)
543                         tmp3 = gettmp();
pj
1.30
544                 tmp4 = gettmp();
ragge
1.1
545         }
gmcgarry
1.115
546         if (Bflag) {
547                 incdir = Bflag;
548                 libdir = Bflag;
549         }
ragge
1.3
550         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
ragge
1.1
551                 signal(SIGINTidexit);
ragge
1.3
552         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
ragge
1.1
553                 signal(SIGTERMidexit);
ragge
1.3
554         pvt = pv;
ragge
1.1
555         for (i=0i<nci++) {
ragge
1.18
556                 /*
557                  * C preprocessor
558                  */
ragge
1.37
559                 if (nc>1 && !Eflag)
ragge
1.1
560                         printf("%s:\n"clist[i]);
ragge
1.43
561                 onlyas = 0;
pj
1.32
562                 assource = tmp3;
ragge
1.107
563                 if (getsuf(clist[i])=='S')
564                         ascpp = 1;
ragge
1.59
565                 if (getsuf(clist[i])=='i') {
566                         if(Eflag)
567                                 continue;
568                         goto com;
ragge
1.107
569                 } else if (ascpp) {
570                         onlyas = 1;
ragge
1.59
571                 } else if (getsuf(clist[i])=='s') {
ragge
1.1
572                         assource = clist[i];
ragge
1.43
573                         goto assemble;
ragge
1.107
574                 }
ragge
1.1
575                 if (pflag)
576                         tmp4 = setsuf(clist[i], 'i');
ragge
1.5
577                 na = 0;
578                 av[na++] = "cpp";
ragge
1.60
579                 if (vflag)
580                         av[na++] = "-v";
ragge
1.20
581                 av[na++] = "-D__PCC__=" MKS(PCC_MAJOR);
ragge
1.40
582                 av[na++] = "-D__PCC_MINOR__=" MKS(PCC_MINOR);
583                 av[na++] = "-D__PCC_MINORMINOR__=" MKS(PCC_MINORMINOR);
ragge
1.107
584                 if (ascpp)
ragge
1.52
585                         av[na++] = "-D__ASSEMBLER__";
gmcgarry
1.101
586                 if (sspflag)
587                         av[na++] = "-D__SSP__=1";
ragge
1.52
588                 if (pthreads)
589                         av[na++] = "-D_PTHREADS";
ragge
1.63
590                 if (Cflag)
591                         av[na++] = "-C";
ragge
1.51
592                 if (Mflag)
593                         av[na++] = "-M";
ragge
1.57
594                 if (dflag)
595                         av[na++] = alist;
ragge
1.5
596                 for (j = 0cppadd[j]; j++)
597                         av[na++] = cppadd[j];
ragge
1.24
598                 for (j = 0cppmdadd[j]; j++)
599                         av[na++] = cppmdadd[j];
ragge
1.7
600                 if (tflag)
ragge
1.20
601                         av[na++] = "-t";
ragge
1.7
602                 for(pv=ptemppv <pvtpv++)
603                         av[na++] = *pv;
gmcgarry
1.108
604                 if (!nostdinc)
gmcgarry
1.115
605                         av[na++] = "-S"av[na++] = incdir;
606                 av[na++] = "-I"av[na++] = PCCINCDIR;
ragge
1.83
607                 if (idirafter) {
608                         av[na++] = "-I";
609                         av[na++] = idirafter;
610                 }
ragge
1.5
611                 av[na++] = clist[i];
ragge
1.51
612                 if (!Eflag && !Mflag)
ragge
1.20
613                         av[na++] = tmp4;
ragge
1.61
614                 if (Eflag && outfile)
615                          av[na++] = outfile;
ragge
1.3
616                 av[na++]=0;
617                 if (callsys(passpav))
618                         {exfail++; eflag++;}
ragge
1.51
619                 if (Eflag || Mflag)
ragge
1.37
620                         continue;
stefan
1.73
621                 if (onlyas) {
622                         assource = tmp4;
ragge
1.7
623                         goto assemble;
stefan
1.73
624                 }
ragge
1.18
625
626                 /*
627                  * C compiler
628                  */
ragge
1.59
629         com:
ragge
1.25
630                 na = 0;
631                 av[na++]= "ccom";
gmcgarry
1.119
632                 if (Wallflag) {
633                         /* Set only the same flags as gcc */
634                         for (Wf = WflagsWf->nameWf++) {
635                                 if (Wf->flags != INWALL)
636                                         continue;
637                                 av[na++] = Wf->name;
638                         }
639                 }
640                 if (Wflag) {
641                         /* set all positive flags */
642                         for (Wf = WflagsWf->nameWf++) {
643                                 if (Wf->flags == NEGATIVE)
644                                         continue;
645                                 av[na++] = Wf->name;
646                         }
647                 }
gmcgarry
1.101
648                 for (j = 0j < nwj++)
649                         av[na++] = wlist[j];
650                 for (j = 0j < nfj++)
651                         av[na++] = flist[j];
ragge
1.60
652                 if (vflag)
653                         av[na++] = "-v";
gmcgarry
1.81
654                 if (pgflag)
655                         av[na++] = "-p";
ragge
1.25
656                 if (gflag)
657                         av[na++] = "-g";
gmcgarry
1.94
658 #ifdef os_darwin
gmcgarry
1.82
659                 /* darwin always wants PIC compilation */
gmcgarry
1.112
660                 if (!Bstatic)
661                         av[na++] = "-k";
gmcgarry
1.82
662 #else
ragge
1.49
663                 if (kflag)
664                         av[na++] = "-k";
gmcgarry
1.82
665 #endif
ragge
1.44
666                 if (Oflag) {
667                         av[na++] = "-xtemps";
ragge
1.64
668                         av[na++] = "-xdeljumps";
ragge
1.44
669                 }
ragge
1.45
670                 for (j = 0j < xnumj++)
671                         av[na++] = xlist[j];
gmcgarry
1.78
672                 for (j = 0j < nmj++)
673                         av[na++] = mlist[j];
ragge
1.68
674                 if (getsuf(clist[i])=='i')
675                         av[na++] = clist[i];
676                 else
677                         av[na++] = tmp4/* created by cpp */
ragge
1.3
678                 if (pflag || exfail)
679                         {
ragge
1.1
680                         cflag++;
681                         continue;
ragge
1.3
682                         }
ragge
1.16
683                 if(sflag) {
684                         if (outfile)
stefan
1.77
685                                 tmp3 = outfile;
ragge
1.16
686                         else
stefan
1.77
687                                 tmp3 = setsuf(clist[i], 's');
ragge
1.16
688                 }
ragge
1.25
689                 av[na++] = tmp3;
690 #if 0
ragge
1.3
691                 if (proflag) {
692                         av[3] = "-XP";
693                         av[4] = 0;
694                 } else
695                         av[3] = 0;
ragge
1.25
696 #endif
697                 av[na++] = NULL;
ragge
1.3
698                 if (callsys(pass0av)) {
ragge
1.1
699                         cflag++;
700                         eflag++;
701                         continue;
702                 }
703                 if (sflag)
704                         continue;
ragge
1.18
705
706                 /*
707                  * Assembler
708                  */
ragge
1.1
709         assemble:
ragge
1.49
710                 na = 0;
gmcgarry
1.79
711                 av[na++] = as;
gmcgarry
1.118
712                 for (j = 0j < nasj++)
713                         av[na++] = aslist[j];
gmcgarry
1.98
714 #if defined(os_sunos) && defined(mach_sparc64)
715                 av[na++] = "-m64";
716 #endif
gmcgarry
1.113
717 #if defined(os_darwin)
718                 if (Bstatic)
719                         av[na++] = "-static";
720 #endif
ragge
1.60
721                 if (vflag)
722                         av[na++] = "-v";
ragge
1.49
723                 if (kflag)
724                         av[na++] = "-k";
725                 av[na++] = "-o";
ragge
1.18
726                 if (outfile && cflag)
ragge
1.49
727                         av[na++] = outfile;
ragge
1.18
728                 else
ragge
1.49
729                         av[na++] = setsuf(clist[i], 'o');
stefan
1.73
730                 av[na++] = assource;
ragge
1.49
731                 if (dflag)
732                         av[na++] = alist;
733                 av[na++] = 0;
gmcgarry
1.79
734                 if (callsys(asav)) {
ragge
1.1
735                         cflag++;
736                         eflag++;
ragge
1.7
737                         cunlink(tmp4);
ragge
1.1
738                         continue;
739                 }
ragge
1.7
740                 cunlink(tmp4);
ragge
1.1
741         }
ragge
1.18
742
ragge
1.51
743         if (Eflag || Mflag)
ragge
1.37
744                 dexit(eflag);
745
ragge
1.18
746         /*
747          * Linker
748          */
ragge
1.1
749 nocom:
750         if (cflag==0 && nl!=0) {
ragge
1.6
751                 j = 0;
gmcgarry
1.79
752                 av[j++] = ld;
gmcgarry
1.122
753 #ifndef MSLINKER
ragge
1.60
754                 if (vflag)
755                         av[j++] = "-v";
gmcgarry
1.114
756 #endif
757 #if !defined(os_sunos) && !defined(os_win32)
ragge
1.6
758                 av[j++] = "-X";
gmcgarry
1.98
759 #endif
ragge
1.84
760                 if (shared) {
761                         av[j++] = "-shared";
gmcgarry
1.114
762 #ifdef os_win32
763                         av[j++] = "-Bdynamic";
764 #endif
gmcgarry
1.98
765 #ifndef os_sunos
ragge
1.84
766                 } else {
gmcgarry
1.114
767 #ifndef os_win32
gmcgarry
1.106
768 #ifndef os_darwin
ragge
1.84
769                         av[j++] = "-d";
gmcgarry
1.106
770 #endif
ragge
1.84
771                         av[j++] = "-e";
772                         av[j++] = STARTLABEL;
gmcgarry
1.98
773 #endif
gmcgarry
1.114
774 #endif
ragge
1.84
775                         if (Bstatic == 0) { /* Dynamic linkage */
gmcgarry
1.94
776 #ifdef DYNLINKER
ragge
1.84
777                                 for (i = 0dynlinker[i]; i++)
778                                         av[j++] = dynlinker[i];
gmcgarry
1.94
779 #endif
gmcgarry
1.112
780                         } else {
781 #ifdef os_darwin
782                                 av[j++] = "-static";
783 #else
ragge
1.84
784                                 av[j++] = "-Bstatic";
gmcgarry
1.112
785 #endif
786                         }
ragge
1.84
787                 }
ragge
1.1
788                 if (outfile) {
gmcgarry
1.122
789 #ifdef MSLINKER
790                         char *s = copy("/OUT:"strlen(outfile));
791                         strcat(soutfile);
792                         av[j++] = s;
793 #else
ragge
1.3
794                         av[j++] = "-o";
795                         av[j++] = outfile;
gmcgarry
1.122
796 #endif
ragge
1.3
797                 }
gmcgarry
1.110
798 #ifdef STARTFILES_S
ragge
1.84
799                 if (shared) {
gmcgarry
1.114
800                         if (!nostartfiles) {
801                                 for (i = 0startfiles_S[i]; i++)
gmcgarry
1.115
802                                         av[j++] = Bprefix(startfiles_S[i]);
gmcgarry
1.114
803                         }
gmcgarry
1.110
804                 } else
ragge
1.84
805 #endif
gmcgarry
1.110
806                 {
ragge
1.84
807                         if (!nostartfiles) {
gmcgarry
1.94
808 #ifdef CRT0FILE_PROFILE
809                                 if (pgflag)
810                                 {
gmcgarry
1.115
811                                         av[j++] = Bprefix(crt0file_profile);
gmcgarry
1.94
812                                 }
813                                 else
814 #endif
815                                 {
816 #ifdef CRT0FILE
gmcgarry
1.115
817                                         av[j++] = Bprefix(crt0file);
gmcgarry
1.94
818 #endif
819                                 }
gmcgarry
1.111
820 #ifdef STARTFILES_T
821                                 if (Bstatic) {
822                                         for (i = 0startfiles_T[i]; i++)
gmcgarry
1.115
823                                                 av[j++] = Bprefix(listartfiles_T[i]);
gmcgarry
1.111
824                                 } else
825 #endif
826                                 {
gmcgarry
1.94
827 #ifdef STARTFILES
gmcgarry
1.111
828                                         for (i = 0startfiles[i]; i++)
gmcgarry
1.115
829                                                 av[j++] = Bprefix(startfiles[i]);
gmcgarry
1.94
830 #endif
gmcgarry
1.111
831                                 }
ragge
1.84
832                         }
ragge
1.14
833                 }
ragge
1.24
834                 i = 0;
ragge
1.14
835                 while(i<nl) {
ragge
1.3
836                         av[j++] = llist[i++];
ragge
1.14
837                         if (j >= MAXAV)
ragge
1.36
838                                 error("Too many ld options");
ragge
1.14
839                 }
gmcgarry
1.82
840 #ifndef MACHOABI
841                 /* darwin assembler doesn't want -g */
ragge
1.65
842                 if (gflag)
843                         av[j++] = "-g";