Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20080619081140

Diff

Diff from 1.101 to:

Annotations

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

Annotated File View

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