Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20080414161455

Diff

Diff from 1.85 to:

Annotations

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

Annotated File View

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