Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20080813202200

Diff

Diff from 1.124 to:

Annotations

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

Annotated File View

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