Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20080605040356

Diff

Diff from 1.99 to:

Annotations

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

Annotated File View

gmcgarry
1.99
1 /*      $Id: cc.c,v 1.99 2008/06/05 04:03:56 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];
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;
gmcgarry
1.98
503                 if (!nostdinc) {
ragge
1.52
504                         av[na++] = "-S"av[na++] = STDINC;
gmcgarry
1.98
505                         av[na++] = "-I" PCCINCDIR;
506                 }
ragge
1.83
507                 if (idirafter) {
508                         av[na++] = "-I";
509                         av[na++] = idirafter;
510                 }
ragge
1.5
511                 av[na++] = clist[i];
ragge
1.51
512                 if (!Eflag && !Mflag)
ragge
1.20
513                         av[na++] = tmp4;
ragge
1.61
514                 if (Eflag && outfile)
515                          av[na++] = outfile;
ragge
1.3
516                 av[na++]=0;
517                 if (callsys(passpav))
518                         {exfail++; eflag++;}
ragge
1.51
519                 if (Eflag || Mflag)
ragge
1.37
520                         continue;
stefan
1.73
521                 if (onlyas) {
522                         assource = tmp4;
ragge
1.7
523                         goto assemble;
stefan
1.73
524                 }
ragge
1.18
525
526                 /*
527                  * C compiler
528                  */
ragge
1.59
529         com:
ragge
1.25
530                 na = 0;
531                 av[na++]= "ccom";
ragge
1.60
532                 if (vflag)
533                         av[na++] = "-v";
gmcgarry
1.81
534                 if (pgflag)
535                         av[na++] = "-p";
ragge
1.25
536                 if (gflag)
537                         av[na++] = "-g";
gmcgarry
1.94
538 #ifdef os_darwin
gmcgarry
1.82
539                 /* darwin always wants PIC compilation */
540                 av[na++] = "-k";
541 #else
ragge
1.49
542                 if (kflag)
543                         av[na++] = "-k";
gmcgarry
1.82
544 #endif
545                 if (Werror)
546                         av[na++] = "-Werror";
ragge
1.44
547                 if (Oflag) {
548                         av[na++] = "-xtemps";
ragge
1.64
549                         av[na++] = "-xdeljumps";
ragge
1.44
550                 }
ragge
1.45
551                 for (j = 0j < xnumj++)
552                         av[na++] = xlist[j];
gmcgarry
1.78
553                 for (j = 0j < nmj++)
554                         av[na++] = mlist[j];
ragge
1.68
555                 if (getsuf(clist[i])=='i')
556                         av[na++] = clist[i];
557                 else
558                         av[na++] = tmp4/* created by cpp */
ragge
1.3
559                 if (pflag || exfail)
560                         {
ragge
1.1
561                         cflag++;
562                         continue;
ragge
1.3
563                         }
ragge
1.16
564                 if(sflag) {
565                         if (outfile)
stefan
1.77
566                                 tmp3 = outfile;
ragge
1.16
567                         else
stefan
1.77
568                                 tmp3 = setsuf(clist[i], 's');
ragge
1.16
569                 }
ragge
1.25
570                 av[na++] = tmp3;
571 #if 0
ragge
1.3
572                 if (proflag) {
573                         av[3] = "-XP";
574                         av[4] = 0;
575                 } else
576                         av[3] = 0;
ragge
1.25
577 #endif
578                 av[na++] = NULL;
ragge
1.3
579                 if (callsys(pass0av)) {
ragge
1.1
580                         cflag++;
581                         eflag++;
582                         continue;
583                 }
584                 if (sflag)
585                         continue;
ragge
1.18
586
587                 /*
588                  * Assembler
589                  */
ragge
1.1
590         assemble:
ragge
1.49
591                 na = 0;
gmcgarry
1.79
592                 av[na++] = as;
gmcgarry
1.98
593 #if defined(os_sunos) && defined(mach_sparc64)
594                 av[na++] = "-m64";
595 #endif
ragge
1.60
596                 if (vflag)
597                         av[na++] = "-v";
ragge
1.49
598                 if (kflag)
599                         av[na++] = "-k";
600                 av[na++] = "-o";
ragge
1.18
601                 if (outfile && cflag)
ragge
1.49
602                         av[na++] = outfile;
ragge
1.18
603                 else
ragge
1.49
604                         av[na++] = setsuf(clist[i], 'o');
stefan
1.73
605                 av[na++] = assource;
ragge
1.49
606                 if (dflag)
607                         av[na++] = alist;
608                 av[na++] = 0;
gmcgarry
1.79
609                 if (callsys(asav)) {
ragge
1.1
610                         cflag++;
611                         eflag++;
ragge
1.7
612                         cunlink(tmp4);
ragge
1.1
613                         continue;
614                 }
ragge
1.7
615                 cunlink(tmp4);
ragge
1.1
616         }
ragge
1.18
617
ragge
1.51
618         if (Eflag || Mflag)
ragge
1.37
619                 dexit(eflag);
620
ragge
1.18
621         /*
622          * Linker
623          */
ragge
1.1
624 nocom:
625         if (cflag==0 && nl!=0) {
ragge
1.6
626                 j = 0;
gmcgarry
1.79
627                 av[j++] = ld;
gmcgarry
1.95
628 #ifndef os_win32
ragge
1.60
629                 if (vflag)
630                         av[j++] = "-v";
gmcgarry
1.98
631 #ifndef os_sunos
ragge
1.6
632                 av[j++] = "-X";
gmcgarry
1.98
633 #endif
ragge
1.84
634                 if (shared) {
635                         av[j++] = "-shared";
gmcgarry
1.98
636 #ifndef os_sunos
ragge
1.84
637                 } else {
638                         av[j++] = "-d";
639                         av[j++] = "-e";
640                         av[j++] = STARTLABEL;
gmcgarry
1.98
641 #endif
ragge
1.84
642                         if (Bstatic == 0) { /* Dynamic linkage */
gmcgarry
1.94
643 #ifdef DYNLINKER
ragge
1.84
644                                 for (i = 0dynlinker[i]; i++)
645                                         av[j++] = dynlinker[i];
gmcgarry
1.94
646 #endif
ragge
1.84
647                         } else
648                                 av[j++] = "-Bstatic";
649                 }
gmcgarry
1.95
650 #endif
ragge
1.1
651                 if (outfile) {
ragge
1.3
652                         av[j++] = "-o";
653                         av[j++] = outfile;
654                 }
ragge
1.84
655                 if (shared) {
656 #ifdef STARTFILES_S
657                         for (i = 0startfiles_S[i]; i++)
658                                 av[j++] = startfiles_S[i];
659 #endif
660                 } else {
661                         if (!nostartfiles) {
gmcgarry
1.94
662 #ifdef CRT0FILE_PROFILE
663                                 if (pgflag)
664                                 {
665                                         av[j++] = crt0file_profile;
666                                 }
667                                 else
668 #endif
669                                 {
670 #ifdef CRT0FILE
671                                         av[j++] = crt0file;
672 #endif
673                                 }
674 #ifdef STARTFILES
ragge
1.84
675                                 for (i = 0startfiles[i]; i++)
676                                         av[j++] = startfiles[i];
gmcgarry
1.94
677 #endif
ragge
1.84
678                         }
ragge
1.14
679                 }
ragge
1.24
680                 i = 0;
ragge
1.14
681                 while(i<nl) {
ragge
1.3
682                         av[j++] = llist[i++];
ragge
1.14
683                         if (j >= MAXAV)
ragge
1.36
684                                 error("Too many ld options");
ragge
1.14
685                 }
gmcgarry
1.82
686 #ifndef MACHOABI
687                 /* darwin assembler doesn't want -g */
ragge
1.65
688                 if (gflag)
689                         av[j++] = "-g";
gmcgarry
1.82
690 #endif
ragge
1.11
691 #if 0
ragge
1.3
692                 if (gflag)
693                         av[j++] = "-lg";
ragge
1.11
694 #endif
ragge
1.52
695                 if (pthreads)
696                         av[j++] = "-lpthread";
gmcgarry
1.81
697                 if (!nostdlib) {
gmcgarry
1.97
698                         av[j++] = "-L" PCCLIBDIR;
gmcgarry
1.81
699                         if (pgflag) {
700                                 for (i = 0libclibs_profile[i]; i++)
701                                         av[j++] = libclibs_profile[i];
702                         } else {
703                                 for (i = 0libclibs[i]; i++)
704                                         av[j++] = libclibs[i];
705                         }
706                 }
ragge
1.84
707                 if (shared) {
708 #ifdef STARTFILES_S
709                         for (i = 0endfiles_S[i]; i++)
710                                 av[j++] = endfiles_S[i];
711 #endif
712                 } else {
gmcgarry
1.95
713 #ifdef STARTFILES
ragge
1.84
714                         if (!nostartfiles) {
715                                 for (i = 0endfiles[i]; i++)
716                                         av[j++] = endfiles[i];
717                         }
gmcgarry
1.95
718 #endif
ragge
1.14
719                 }
ragge
1.3
720                 av[j++] = 0;
gmcgarry
1.79
721                 eflag |= callsys(ldav);
ragge
1.1
722                 if (nc==1 && nxo==1 && eflag==0)
ragge
1.3
723                         cunlink(setsuf(clist[0], 'o'));
ragge
1.46
724                 else if (nc > 0 && eflag == 0) {
725                         /* remove .o files XXX ugly */
726                         for (i = 0i < nci++)
727                                 cunlink(setsuf(clist[i], 'o'));
728                 }
ragge
1.1
729         }
ragge
1.36
730         dexit(eflag);
ragge
1.4
731         return 0;
ragge
1.1
732 }
733
ragge
1.36
734 /*
735  * exit and cleanup after interrupt.
736  */
ragge
1.4
737 void
738 idexit(int arg)
ragge
1.1
739 {
ragge
1.36
740         dexit(100);
ragge
1.1
741 }
742
ragge
1.36
743 /*
744  * exit and cleanup.
745  */
ragge
1.4
746 void
ragge
1.36
747 dexit(int eval)
ragge
1.1
748 {
ragge
1.10
749         if (!pflag && !Xflag) {
ragge
1.1
750                 if (sflag==0)
751                         cunlink(tmp3);
752                 cunlink(tmp4);
753         }
ragge
1.70
754         if (eval == 100)
755                 _exit(eval);
ragge
1.36
756         exit(eval);
ragge
1.1
757 }
758
ragge
1.36
759 static void
760 ccerror(char *sva_list ap)
ragge
1.1
761 {
ragge
1.36
762         vfprintf(Eflag ? stderr : stdoutsap);
ragge
1.8
763         putc('\n'Eflagstderr : stdout);
ragge
1.1
764         exfail++;
765         cflag++;
766         eflag++;
767 }
768
ragge
1.36
769 /*
770  * complain a bit.
771  */
772 void
773 error(char *s, ...)
774 {
775         va_list ap;
776
777         va_start(aps);
778         ccerror(sap);
779         va_end(ap);
780 }
781
782 /*
783  * complain a bit and then exit.
784  */
ragge
1.18
785 void
ragge
1.36
786 errorx(int evalchar *s, ...)
ragge
1.18
787 {
ragge
1.36
788         va_list ap;
789
790         va_start(aps);
791         ccerror(sap);
792         va_end(ap);
793         dexit(eval);
ragge
1.18
794 }
ragge
1.3
795
ragge
1.4
796 int
stefan
1.72
797 getsuf(char *as)
ragge
1.1
798 {
799         register char *s;
800
ragge
1.4
801         if ((s = strrchr(as'.')) && s[1] != '\0' && s[2] == '\0')
802                 return s[1];
ragge
1.3
803         return(0);
ragge
1.1
804 }
805
ragge
1.36
806 /*
807  * Get basename of string s and change its suffix to ch.
808  */
ragge
1.1
809 char *
ragge
1.36
810 setsuf(char *schar ch)
ragge
1.1
811 {
ragge
1.91
812         char *as;
813
814         s = copy(basename(s), 2);
815         if ((as = strrchr(s'.')) == NULL) {
816                 as = s + strlen(s);
817                 as[0] = '.';
818         }
819         as[1] = ch;
820         as[2] = '\0';
ragge
1.36
821         return(s);
ragge
1.1
822 }
823
gmcgarry
1.89
824 #ifdef WIN32
ragge
1.4
825 int
gmcgarry
1.86
826 callsys(char *fchar *v[])
ragge
1.56
827 {
stefan
1.75
828         int tstatus = 0;
gmcgarry
1.89
829         char cmd[MAX_PATH];
gmcgarry
1.93
830         int len;
gmcgarry
1.86
831         STARTUPINFO si;
832         PROCESS_INFORMATION pi;
833         DWORD exitCode;
834         BOOL ok;
835
gmcgarry
1.89
836         len = strlcpy(cmdfMAX_PATH);
837         for (t = 1v[t] && len < MAX_PATHt++) {
838                 len = strlcat(cmd" "MAX_PATH);
839                 len = strlcat(cmdv[t], MAX_PATH);
840         }
841
842         if (vflag)
843                 printf("%s\n"cmd);
844
gmcgarry
1.86
845         ZeroMemory(&sisizeof(STARTUPINFO));
846         si.cb = sizeof(STARTUPINFO);
gmcgarry
1.89
847         ZeroMemory(&pisizeof(PROCESS_INFORMATION));
848
849         ok = CreateProcess(NULL,  // the executable program
850                 cmd,   // the command line arguments
gmcgarry
1.86
851                 NULL,       // ignored
852                 NULL,       // ignored
853                 TRUE,       // inherit handles
gmcgarry
1.89
854                 HIGH_PRIORITY_CLASS,
gmcgarry
1.86
855                 NULL,       // ignored
856                 NULL,       // ignored
857                 &si,
858                 &pi);
859
860         if (!ok) {
861                 printf("Try Again\n");
862                 return</