Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20080520053804

Diff

Diff from 1.97 to:

Annotations

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

Annotated File View

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