Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20080719020205

Diff

Diff from 1.112 to:

Annotations

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

Annotated File View

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