Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20080816035859

Diff

Diff from 1.125 to:

Annotations

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

Annotated File View

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