Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.225
 
1.226
 
MAIN:ragge:20120805102842
 
cc.c
_>113113 
 114114 #include "compat.h"
 115115 
<>116 -#include "ccconfig.h"
117116 #include "macdefs.h"
 118117 
 119118 #include "xalloc.h"
 120119 #include "strlist.h"
<> 120+
  121+#include "ccconfig.h"
121122 /* C command */
 122123 
 123124 #define MKS(x) _MKS(x)
 124125 #define _MKS(x) #x
 125126 
<>126 -/*
 127 - * Many specific definitions, should be declared elsewhere.
 128 - */
 129 -
 130 -#ifndef STDINC
 131 -#define STDINC          "/usr/include/"
  127+/* default program names in pcc */
  128+/* May be overridden if cross-compiler is generated */
  129+#ifndef CPPROGNAME
  130+#define CPPROGNAME      "cpp"   /* cc used as cpp */
132131 #endif
<>133 -
 134 -#ifndef LIBDIR
 135 -#define LIBDIR          "/usr/lib/"
 136 -#endif
 137 -
138132 #ifndef PREPROCESSOR
<>139 -#define PREPROCESSOR    "cpp"
  133+#define PREPROCESSOR    "cpp"   /* "real" preprocessor name */
140134 #endif
<>141 -
142135 #ifndef COMPILER
 143136 #define COMPILER        "ccom"
 144137 #endif
<>145 -
  138+#ifndef CXXCOMPILER
  139+#define CXXCOMPILER     "cxxcom"
  140+#endif
146141 #ifndef ASSEMBLER
 147142 #define ASSEMBLER       "as"
 148143 #endif
<>149 -
150144 #ifndef LINKER
 151145 #define LINKER          "ld"
 152146 #endif
<> 147+char    *passp = PREPROCESSOR;
  148+char    *pass0 = COMPILER;
  149+char    *passxx0 = CXXCOMPILER;
  150+char    *as = ASSEMBLER;
  151+char    *ld = LINKER;
  152+char    *sysroot = "", *isysroot;
153153 
<>154 -#ifndef MULTIOSDIR
 155 -#define MULTIOSDIR      "."
  154+
  155+/* crt files using pcc default names */
  156+#ifndef CRTBEGIN_S
  157+#define CRTBEGIN_S      "crtbeginS.o"
156158 #endif
<> 159+#ifndef CRTEND_S
  160+#define CRTEND_S        "crtendS.o"
  161+#endif
  162+#ifndef CRTBEGIN_T
  163+#define CRTBEGIN_T      "crtbeginT.o"
  164+#endif
  165+#ifndef CRTEND_T
  166+#define CRTEND_T        "crtendT.o"
  167+#endif
  168+#ifndef CRTBEGIN
  169+#define CRTBEGIN        "crtbegin.o"
  170+#endif
  171+#ifndef CRTEND
  172+#define CRTEND          "crtend.o"
  173+#endif
  174+#ifndef CRTI
  175+#define CRTI            "crti.o"
  176+#endif
  177+#ifndef CRTN
  178+#define CRTN            "crtn.o"
  179+#endif
  180+#ifndef CRT0
  181+#define CRT0            "crt0.o"
  182+#endif
  183+#ifndef GCRT0
  184+#define GCRT0           "gcrt0.o"
  185+#endif
157186 
<> 187+/* preprocessor stuff */
  188+#ifndef STDINC
  189+#define STDINC          "/usr/include/"
  190+#endif
158191 
<>159 -#define MAXAV  10000
 160 -char    *tmp3;
 161 -char    *tmp4;
 162 -char    *outfile, *ermfile;
  192+char *cppadd[] = CPPADD;
  193+char *cppmdadd[] = CPPMDADD;
  194+
  195+/* Dynamic linker definitions, per-target */
  196+#ifndef DYNLINKER
  197+#define DYNLINKER { 0 }
  198+#endif
  199+
  200+/* Default libraries and search paths */
  201+#ifndef PCCLIBDIR       /* set by autoconf */
  202+#define PCCLIBDIR       NULL
  203+#endif
  204+#ifndef DEFLIBDIRS      /* default library search paths */
  205+#define DEFLIBDIRS      { "/usr/lib/", 0 }
  206+#endif
  207+#ifndef DEFLIBS         /* default libraries included */
  208+#define DEFLIBS         { "-lpcc", "-lc", "-lpcc", 0 }
  209+#endif
  210+#ifndef DEFPROFLIBS     /* default profiling libraries */
  211+#define DEFPROFLIBS     { "-lpcc", "-lc_p", "-lpcc", 0 }
  212+#endif
  213+#ifndef DEFCXXLIBS      /* default c++ libraries */
  214+#define DEFCXXLIBS      { "-lp++", "-lpcc", "-lc", "-lpcc", 0 }
  215+#endif
  216+#ifndef STARTLABEL
  217+#define STARTLABEL "__start"
  218+#endif
  219+
  220+char *dynlinker[] = DYNLINKER;
  221+char *pcclibdir = PCCLIBDIR;
  222+char *deflibdirs[] = DEFLIBDIRS;
  223+char *deflibs[] = DEFLIBS;
  224+char *defproflibs[] = DEFPROFLIBS;
  225+char *defcxxlibs[] = DEFCXXLIBS;
  226+
  227+char    *outfile;
163228 static char **lav;
 164229 static int lac;
<>165 -static void add_prefix(const char *);
 166 -static char *find_file(const char *, int);
 167 -static char *find_file2(const char *file, struct strlist *path, int mode);
 168 -char *copy(const char *, int);
  230+static char *find_file(const char *file, struct strlist *path, int mode);
  231+static int preprocess_input(char *input, char *output, int dodep);
  232+static int compile_input(char *input, char *output);
  233+static int assemble_input(char *input, char *output);
  234+static int run_linker(void);
  235+static int strlist_exec(struct strlist *l);
  236+
169237 char *cat(const char *, const char *);
 170238 char *setsuf(char *, char);
 171239 int cxxsuf(char *);
     
 !
176244 void errorx(int, char *, ...);
 177245 int callsys(char [], char *[]);
 178246 int cunlink(char *);
<> 247+void exandrm(char *);
179248 void dexit(int);
 180249 void idexit(int);
 181250 char *gettmp(void);
<>182 -void *ccmalloc(int size);
183251 void aerror(char *);
 184252 void oerror(char *);
 185253 void owarning(char *);
 186254 char *argnxt(char *, char *);
 187255 char *nxtopt(char *o);
 188256 void setup_cpp_flags(void);
<> 257+void setup_ccom_flags(void);
  258+void setup_as_flags(void);
  259+void setup_ld_flags(void);
189260 static void expand_sysroot(void);
 190261 #ifdef os_win32
 191262 char *win32pathsubst(char *);
 192263 char *win32commandline(char *, char *[]);
 193264 #endif
<>194 -char    *av[MAXAV];
 195 -char    *xlist[100];
 196 -int     xnum;
 197 -char    *mlist[100];
 198 -char    *flist[100];
 199 -char    *wlist[100];
 200 -int     nm;
 201 -int     nf;
 202 -int     nw;
203265 int     sspflag;
 204266 int     freestanding;
<>205 -int     pflag;
 206 -int     sflag;
  267+int     Sflag;
207268 int     cflag;
<>208 -int     eflag;
209269 int     gflag;
 210270 int     rflag;
 211271 int     vflag;
     
 !
217277 #define F_pic   2
 218278 int     Mflag, needM;   /* dependencies only */
 219279 int     pgflag;
<>220 -int     exfail;
221280 int     Xflag;
 222281 int     Wallflag;
 223282 int     Wflag;
 224283 int     nostartfiles, Bstatic, shared;
 225284 int     nostdinc, nostdlib;
<>226 -int     onlyas;
227285 int     pthreads;
 228286 int     xasm, xcflag, xgnu89, xgnu99;
 229287 int     ascpp;
     
 !
235293 int     cxxflag;
 236294 int     cppflag;
 237295 
<>238 -char    *passp = LIBEXECDIR PREPROCESSOR;
 239 -char    *pass0 = LIBEXECDIR COMPILER;
 240 -char    *passxx0 = LIBEXECDIR "cxxcom";
 241 -char    *as = ASSEMBLER;
 242 -char    *ld = LINKER;
 243 -char    *sysroot = "", *isysroot;
 244 -char *cppadd[] = CPPADD;
 245 -#ifdef DYNLINKER
 246 -char *dynlinker[] = DYNLINKER;
 247 -#endif
 248 -#ifdef CRT0FILE
 249 -char *crt0file = CRT0FILE;
 250 -#endif
 251 -#ifdef CRT0FILE_PROFILE
 252 -char *crt0file_profile = CRT0FILE_PROFILE;
 253 -#endif
 254 -#ifdef STARTFILES
 255 -char *startfiles[] = STARTFILES;
 256 -char *endfiles[] = ENDFILES;
 257 -#endif
 258 -#ifdef STARTFILES_T
 259 -char *startfiles_T[] = STARTFILES_T;
 260 -char *endfiles_T[] = ENDFILES_T;
 261 -#endif
 262 -#ifdef STARTFILES_S
 263 -char *startfiles_S[] = STARTFILES_S;
 264 -char *endfiles_S[] = ENDFILES_S;
 265 -#endif
 266 -char *cppmdadd[] = CPPMDADD;
 267 -#ifdef LIBCLIBS
 268 -char *libclibs[] = LIBCLIBS;
 269 -#else
 270 -char *libclibs[] = { "-lc", NULL };
 271 -#endif
 272 -#ifdef LIBCLIBS_PROFILE
 273 -char *libclibs_profile[] = LIBCLIBS_PROFILE;
 274 -#else
 275 -char *libclibs_profile[] = { "-lc_p", NULL };
 276 -#endif
 277 -#ifndef STARTLABEL
 278 -#define STARTLABEL "__start"
 279 -#endif
 280 -#ifdef PCCLIBDIR
 281 -char *pcclibdir = PCCLIBDIR;
 282 -#endif
283296 #ifdef mach_amd64
 284297 int amd64_i386;
 285298 #endif
     
 !
358371 #define PCC_PTRDIFF_TYPE "long int"
 359372 #endif
 360373 
<>361 -#ifndef CPPROGNAME
 362 -#define CPPROGNAME      "cpp"
 363 -#endif
364374 
 365375 struct strlist preprocessor_flags;
 366376 struct strlist depflags;
     
 !
378388 struct strlist inputs;
 379389 struct strlist assembler_flags;
 380390 struct strlist temp_outputs;
<> 391+struct strlist compiler_flags;
381392 
 382393 int
 383394 main(int argc, char *argv[])
 384395 {
<>385 -        struct string *s, *ss;
386396         struct Wflags *Wf;
<> 397+        struct string *s;
387398         char *t, *u, *argp;
<>388 -        char *assource;
 389 -        int ninput, i, j, nxo, na;
  399+        int ninput, j;
390400 
 391401         lav = argv;
 392402         lac = argc;
     
 !
407417         strlist_init(&inputs);
 408418         strlist_init(&assembler_flags);
 409419         strlist_init(&temp_outputs);
<> 420+        strlist_init(&compiler_flags);
410421 
<> 422+        t = argv[0];
411423         if ((t = strrchr(argv[0], '/')))
<>412 -                t = copy(t+1, 0);
 413 -        else
 414 -                t = argv[0];
 415 -        if (strcmp(t, "p++") == 0) {
  424+                t++;
  425+
  426+        if (match(t, "p++")) {
416427                 cxxflag = 1;
<>417 -                pass0 = passxx0;
 418 -        } else if (strcmp(t, "cpp") == 0 || strcmp(t, CPPROGNAME) == 0) {
 419 -                cppflag = 1;
 420 -                Eflag = 1;
  428+        } else if (match(t, "cpp") || match(t, CPPROGNAME)) {
  429+                Eflag = cppflag = 1;
421430         }
 422431 
 423432 #ifdef os_win32
     
 !
454463 #endif
 455464 #endif
 456465 
<>457 -        nxo = 0;
458466         while (--lac) {
 459467                 ++lav;
 460468                 argp = *lav;
     
 !
496504                         strlist_append(&crtdirs, t);
 497505                         strlist_append(&libdirs, t);
 498506                         strlist_append(&progdirs, t);
<>499 -                        add_prefix(t);
500507                         break;
 501508 
 502509                 case 'C':
     
 !
520527                                 do {
 521528                                         strlist_append(&assembler_flags, u);
 522529                                 } while ((u = strtok(NULL, ",")) != NULL);
<>523 -                        } else if (strncmp(argp, "-Wc,", 4) == 0) {
 524 -                                /* options to ccom */
 525 -                                t = &argp[4];
 526 -                                while ((u = strchr(t, ','))) {
 527 -                                        *u++ = 0;
 528 -                                        wlist[nw++] = t;
 529 -                                        t = u;
 530 -                                }
 531 -                                wlist[nw++] = t;
  530+                        } else if ((t = argnxt(argp, "-Wc,"))) {
  531+                                u = strtok(t, ",");
  532+                                do {
  533+                                        strlist_append(&compiler_flags, u);
  534+                                } while ((u = strtok(NULL, ",")) != NULL);
532535                         } else if ((t = argnxt(argp, "-Wp,"))) {
 533536                                 u = strtok(t, ",");
 534537                                 do {
 535538                                         strlist_append(&preprocessor_flags, u);
 536539                                 } while ((u = strtok(NULL, ",")) != NULL);
 537540                         } else if (strcmp(argp, "-Werror") == 0) {
<>538 -                                wlist[nw++] = argp;
  541+                                strlist_append(&compiler_flags, "-Werror");
539542                         } else if (strcmp(argp, "-Wall") == 0) {
 540543                                 Wallflag = 1;
 541544                         } else if (strcmp(argp, "-WW") == 0) {
     
 !
549552                                         t += 6;
 550553                                 for (Wf = Wflags; Wf->name; Wf++) {
 551554                                         if (strcmp(t, Wf->name) == 0)
<>552 -                                                wlist[nw++] = argp;
  555+                                                strlist_append(&compiler_flags,
  556+                                                    argp);
553557                                 }
 554558                         }
 555559                         break;
     
 !
567571                         else if (match(argp, "-fno-signed-char") ||
 568572                             match(argp, "-funsigned-char"))
 569573                                 xuchar = 1;
<>570 -                        else if (strcmp(argp, "-fstack-protector") == 0) {
 571 -                                flist[nf++] = argp;
  574+                        else if (match(argp, "-fstack-protector") ||
  575+                            match(argp, "-fstack-protector-all")) {
572576                                 sspflag++;
<>573 -                        } else if (strcmp(argp, "-fstack-protector-all") == 0) {
 574 -                                flist[nf++] = argp;
 575 -                                sspflag++;
 576 -                        } else if (strcmp(argp, "-fno-stack-protector") == 0) {
 577 -                                flist[nf++] = argp;
  577+                        } else if (match(argp, "-fno-stack-protector") ||
  578+                            match(argp, "-fno-stack-protector-all")) {
578579                                 sspflag = 0;
<>579 -                        } else if (strcmp(argp, "-fno-stack-protector-all") == 0) {
 580 -                                flist[nf++] = argp;
 581 -                                sspflag = 0;
582580                         }
 583581                         /* silently ignore the rest */
 584582                         break;
     
 !
627625                 case 'l':
 628626                 case 'L':
 629627                         strlist_append(&late_linker_flags, argp);
<> 628+                        if (argp[2] == 0)
  629+                                strlist_append(&late_linker_flags, nxtopt(0));
630630                         break;
 631631 
 632632 
     
 !
639639                                 break;
 640640                         }
 641641 #endif
<>642 -                        mlist[nm++] = argp;
643642                         strlist_append(&middle_linker_flags, argp);
 644643                         if (argp[2] == 0) {
 645644                                 t = nxtopt(0);
 646645                                 strlist_append(&middle_linker_flags, t);
<>647 -                                mlist[nm++] = t;
648646                         }
 649647                         break;
 650648 
     
 !
676674                             "-print-prog-name=ld") == 0) {
 677675                                 printf("%s\n", LINKER);
 678676                                 return 0;
<> 677+#ifdef notdef
  678+                        /* does not exist in gcc??? */
679679                         } else if (strcmp(argp,
 680680                             "-print-multi-os-directory") == 0) {
 681681                                 printf("%s\n", MULTIOSDIR);
 682682                                 return 0;
<> 683+#endif
683684                         } else
 684685                                 oerror(argp);
 685686                         break;
     
 !
698699                                 ascpp = 1;
 699700                         else if (match(t, "c++"))
 700701                                 cxxflag++;
<>701 -                        else if (argp[2])
 702 -                                xlist[xnum++] = argp;
 703 -                        else
 704 -                                xlist[xnum++] = "-x", xlist[xnum++] = t;
  702+                        else {
  703+                                strlist_append(&compiler_flags, "-x");
  704+                                strlist_append(&compiler_flags, t);
  705+                        }
705706                         break;
 706707                 case 't':
 707708                         tflag++;
 708709                         break;
 709710                 case 'S':
<>710 -                        sflag++;
  711+                        Sflag++;
711712                         cflag++;
 712713                         break;
 713714                 case 'o':
     
 !
718719                 case 'O':
 719720                         if (argp[2] == '\0')
 720721                                 Oflag++;
<>721 -                        else if (argp[3] == '\0' && isdigit((unsigned char)argp[2]))
  722+                        else if (argp[3] == '\0' &&
  723+                            isdigit((unsigned char)argp[2]))
722724                                 Oflag = argp[2] - '0';
 723725                         else if (argp[3] == '\0' && argp[2] == 's')
 724726                                 Oflag = 1;      /* optimize for space only */
     
 !
729731                         Eflag++;
 730732                         break;
 731733                 case 'P':
<>732 -                        pflag++;
733734                         strlist_append(&preprocessor_flags, argp);
 734735                         break;
 735736 
     
 !
761762                         case 'T':
 762763                         case 'Q':
 763764                                 needM = 1;
<>764 -                                j = strlen(u = nxtopt("-MT"));
 765 -                                t = copy("-xMT,", j);
 766 -                                strlcat(t, u, j+6);
  765+                                t = cat("-xMT,", nxtopt("-MT"));
767766                                 t[3] = argp[2];
 768767                                 strlist_append(&depflags, t);
 769768                                 break;
     
 !
818817                         strlist_append(&inputs, "-");
 819818                 } else if (ninput > 2 || (ninput == 2 && outfile)) {
 820819                         errorx(8, "too many files");
<>821 -#if 0
 822 -                } else if (ninput == 2) {
 823 -                        outfile = clist[--nc];
 824 -#endif
825820                 }
 826821         }
 827822         if (ninput == 0)
 828823                 errorx(8, "no input files");
<>829 -        if (outfile && (cflag || sflag || Eflag) && ninput > 1)
  824+        if (outfile && (cflag || Sflag || Eflag) && ninput > 1)
830825                 errorx(8, "-o given with -c || -E || -S and more than one file");
 831826 #if 0
 832827         if (outfile && clist[0] && strcmp(outfile, clist[0]) == 0)
     
 !
837832                 errorx(8, "to make dependencies needs -M");
 838833 
 839834 
<>840 -        if (ninput == 0)
 841 -                goto nocom;
 842 -        if (pflag==0) {
 843 -                if (!sflag)
 844 -                        tmp3 = gettmp();
 845 -                tmp4 = gettmp();
 846 -        }
847835         if (signal(SIGINT, SIG_IGN) != SIG_IGN/* interrupt */
 848836                 signal(SIGINT, idexit);
 849837         if (signal(SIGTERM, SIG_IGN) != SIG_IGN)        /* terminate */
 850838                 signal(SIGTERM, idexit);
 851839 
<> 840+        /* after arg parsing */
  841+        strlist_append(&progdirs, LIBEXECDIR);
  842+        if (pcclibdir)
  843+                strlist_append(&crtdirs, pcclibdir);
  844+        for (j = 0; deflibdirs[j]; j++)
  845+                strlist_append(&crtdirs, deflibdirs[j]);
  846+
852847         setup_cpp_flags();
<> 848+        setup_ccom_flags();
  849+        setup_as_flags();
853850 
 854851         if (isysroot == NULL)
 855852                 isysroot = sysroot;
 856853         expand_sysroot();
 857854 
<>858 -        STRLIST_FOREACH(ss, &inputs) {
  855+        STRLIST_FOREACH(s, &inputs) {
  856+                char *suffix;
  857+                char *ifile, *ofile;
  858+
  859+                ifile = s->value;
  860+                if (ninput > 1 && !Eflag)
  861+                        printf("%s:\n", ifile);
  862+
  863+                suffix = getsufp(ifile);
  864+                if (xasm)
  865+                        suffix = "s";
  866+                else if (ascpp)
  867+                        suffix = "S";
  868+                else if (xcflag)
  869+                        suffix = "c";
859870                 /*
 860871                  * C preprocessor
 861872                  */
<>862 -                if (getsuf(ss->value) == 'o' || getsuf(ss->value) == 'a')
 863 -                        continue;
 864 -
 865 -                if (ninput > 1 && !Eflag)
 866 -                        printf("%s:\n", ss->value);
 867 -                onlyas = 0;
 868 -                assource = tmp3;
 869 -                if (getsuf(ss->value)=='S')
 870 -                        ascpp = 1;
 871 -                if (getsuf(ss->value)=='i') {
 872 -                        if(Eflag)
  873+                if (match(suffix, "c") || match(suffix, "S") ||
  874+                    cxxsuf(s->value)) {
  875+                        /* find out next output file */
  876+                        if (Eflag || Mflag) {
  877+                                /* last pass */
  878+                                ofile = outfile;
  879+                        } else {
  880+                                /* to temp file */
  881+                                strlist_append(&temp_outputs, ofile = gettmp());
  882+                        }
  883+                        if (Mflag /* || MDflag */)
  884+                                if (preprocess_input(ifile, ofile, 1))
  885+                                        exandrm(ofile);
  886+                        if (Mflag)
873887                                 continue;
<>874 -                        goto com;
 875 -                } else if (ascpp) {
 876 -                        onlyas = 1;
 877 -                } else if (xasm || getsuf(ss->value)=='s') {
 878 -                        assource = ss->value;
 879 -                        goto assemble;
  888+                        if (preprocess_input(ifile, ofile, 0))
  889+                                exandrm(ofile);
  890+                        if (Eflag)
  891+                                continue;
  892+                        ifile = ofile;
  893+                        suffix = match(suffix, "S") ? "s" : "i";
880894                 }
 881895 
<>882 -
 883 -                if (pflag)
 884 -                        tmp4 = setsuf(s->value, 'i');
 885 -                na = 0;
 886 -                av[na++] = "cpp";
 887 -
 888 -                STRLIST_FOREACH(s, &depflags) {
 889 -                        av[na++] = s->value;
 890 -                }
 891 -                STRLIST_FOREACH(s, &preprocessor_flags) {
 892 -                        av[na++] = s->value;
 893 -                }
 894 -                STRLIST_FOREACH(s, &includes) {
 895 -                        av[na++] = "-i";
 896 -                        av[na++] = s->value;
 897 -                }
 898 -                STRLIST_FOREACH(s, &incdirs) {
 899 -                        av[na++] = "-I";
 900 -                        av[na++] = s->value;
 901 -                }
 902 -                STRLIST_FOREACH(s, &user_sysincdirs) {
 903 -                        av[na++] = "-S";
 904 -                        av[na++] = s->value;
 905 -                }
 906 -                if (!nostdinc) {
 907 -                        STRLIST_FOREACH(s, &sysincdirs) {
 908 -                                av[na++] = "-S";
 909 -                                av[na++] = s->value;
 910 -                        }
 911 -                }
 912 -                STRLIST_FOREACH(s, &dirafterdirs) {
 913 -                        av[na++] = "-S";
 914 -                        av[na++] = s->value;
 915 -                }
 916 -
 917 -                av[na++] = ss->value;
 918 -                if (!Eflag && !Mflag)
 919 -                        av[na++] = tmp4;
 920 -                if ((Eflag || Mflag) && outfile)
 921 -                         ermfile = av[na++] = outfile;
 922 -                av[na++]=0;
 923 -                if (callsys(passp, av)) {
 924 -                        exfail++;
 925 -                        eflag++;
 926 -                }
 927 -                if (Eflag || Mflag)
 928 -                        continue;
 929 -                if (onlyas) {
 930 -                        assource = tmp4;
 931 -                        goto assemble;
 932 -                }
 933 -
934896                 /*
 935897                  * C compiler
 936898                  */
<>937 -        com:
 938 -                na = 0;
 939 -                av[na++]= cxxflag ? "c++com" : "ccom";
 940 -                if (Wflag || Wallflag) {
 941 -                        /* -Wall is same as gcc, -WW is all flags */
 942 -                        for (Wf = Wflags; Wf->name; Wf++) {
 943 -                                if (Wflag || Wf->flags == INWALL)
 944 -                                        av[na++] = cat("-W", Wf->name);
 945 -                        }
  899+                if (match(suffix, "i")) {
  900+                        /* find out next output file */
  901+                        if (Sflag) {
  902+                                ofile = outfile;
  903+                                if (outfile == NULL)
  904+                                        ofile = setsuf(s->value, 's');
  905+                        } else
  906+                                strlist_append(&temp_outputs, ofile = gettmp());
  907+                        if (compile_input(ifile, ofile))
  908+                                exandrm(ofile);
  909+                        if (Sflag)
  910+                                continue;
  911+                        ifile = ofile;
  912+                        suffix = "s";
946913                 }
<>947 -                for (j = 0; j < nw; j++)
 948 -                        av[na++] = wlist[j];
 949 -                for (j = 0; j < nf; j++)
 950 -                        av[na++] = flist[j];
 951 -                if (freestanding)
 952 -                        av[na++] = "-ffreestanding";
 953 -#if !defined(os_sunos) && !defined(mach_i386)
 954 -                if (vflag)
 955 -                        av[na++] = "-v";
 956 -#endif
 957 -                if (pgflag)
 958 -                        av[na++] = "-p";
 959 -                if (gflag)
 960 -                        av[na++] = "-g";
 961 -#ifdef os_darwin
 962 -                /* darwin always wants PIC compilation */
 963 -                if (!Bstatic)
 964 -                        av[na++] = "-k";
 965 -#elif defined(os_sunos) && defined(mach_i386)
 966 -                if (kflag) {
 967 -                        av[na++] = "-K";
 968 -                        av[na++] = "pic";
 969 -                }
 970 -#else
 971 -                if (kflag)
 972 -                        av[na++] = "-k";
 973 -#endif
 974 -                if (Oflag) {
 975 -                        av[na++] = "-xtemps";
 976 -                        av[na++] = "-xdeljumps";
 977 -                        av[na++] = "-xinline";
 978 -                }
 979 -                if (xgnu89)
 980 -                        av[na++] = "-xgnu89";
 981 -                if (xgnu99)
 982 -                        av[na++] = "-xgnu99";
 983 -                if (xuchar)
 984 -                        av[na++] = "-xuchar";
 985 -                for (j = 0; j < xnum; j++)
 986 -                        av[na++] = xlist[j];
 987 -                for (j = 0; j < nm; j++)
 988 -                        av[na++] = mlist[j];
 989 -                if (getsuf(ss->value)=='i')
 990 -                        av[na++] = ss->value;
 991 -                else
 992 -                        av[na++] = tmp4; /* created by cpp */
 993 -                if (pflag || exfail)
 994 -                        {
 995 -                        cflag++;
 996 -                        continue;
 997 -                        }
 998 -                if(sflag) {
 999 -                        if (outfile)
 1000 -                                tmp3 = outfile;
 1001 -                        else
 1002 -                                tmp3 = setsuf(ss->value, 's');
 1003 -                }
 1004 -                ermfile = av[na++] = tmp3;
1005914 
<>1006 -                av[na++] = NULL;
 1007 -                if (callsys(pass0, av)) {
 1008 -                        cflag++;
 1009 -                        eflag++;
 1010 -                        continue;
 1011 -                }
 1012 -                if (sflag)
 1013 -                        continue;
 1014 -
1015915                 /*
 1016916                  * Assembler
 1017917                  */
<>1018 -        assemble:
 1019 -                na = 0;
 1020 -                av[na++] = as;
 1021 -                STRLIST_FOREACH(s, &assembler_flags) {
 1022 -                        av[na++] = s->value;
  918+                if (match(suffix, "s")) {
  919+                        if (cflag) {
  920+                                ofile = outfile;
  921+                                if (ofile == NULL)
  922+                                        ofile = setsuf(s->value, 'o');
  923+                        } else {
  924+                                strlist_append(&temp_outputs, ofile = gettmp());
  925+                                /* strlist_append linker */
  926+                        }
  927+                        if (assemble_input(ifile, ofile))
  928+                                exandrm(ofile);
  929+                        ifile = ofile;
1023930                 }
<>1024 -#if defined(USE_YASM)
 1025 -                av[na++] = "-p";
 1026 -                av[na++] = "gnu";
 1027 -                av[na++] = "-f";
 1028 -#if defined(os_win32)
 1029 -                av[na++] = "win32";
 1030 -#elif defined(os_darwin)
 1031 -                av[na++] = "macho";
 1032 -#else
 1033 -                av[na++] = "elf";
 1034 -#endif
 1035 -#endif
 1036 -#if defined(os_sunos) && defined(mach_sparc64)
 1037 -                av[na++] = "-m64";
 1038 -#endif
 1039 -#if defined(os_darwin)
 1040 -                if (Bstatic)
 1041 -                        av[na++] = "-static";
 1042 -#endif
 1043 -#if !defined(USE_YASM)
 1044 -                if (vflag)
 1045 -                        av[na++] = "-v";
 1046 -#endif
 1047 -                if (kflag)
 1048 -                        av[na++] = "-k";
 1049 -#ifdef os_darwin
 1050 -                av[na++] = "-arch";
 1051 -#if mach_amd64
 1052 -                av[na++] = amd64_i386 ? "i386" : "x86_64";
 1053 -#else
 1054 -                av[na++] = "i386";
 1055 -#endif
 1056 -#else
 1057 -#ifdef mach_amd64
 1058 -                if (amd64_i386)
 1059 -                        av[na++] = "--32";
 1060 -#endif
 1061 -#endif
 1062 -                av[na++] = "-o";
 1063 -                if (outfile && cflag)
 1064 -                        ermfile = outfile;
 1065 -                else if (cflag)
 1066 -                        ermfile = setsuf(ss->value, 'o');
 1067 -                else {
 1068 -                        ermfile = ss->value = gettmp();
 1069 -                        strlist_append(&temp_outputs, ermfile);
 1070 -                }
 1071 -
 1072 -                av[na++] = ermfile;
 1073 -                av[na++] = assource;
 1074 -                av[na++] = 0;
 1075 -                if (callsys(as, av)) {
 1076 -                        cflag++;
 1077 -                        eflag++;
 1078 -                        cunlink(tmp4);
 1079 -                }
 1080 -                cunlink(tmp4);
  931+                strlist_append(&middle_linker_flags, ifile);
1081932         }
 1082933 
<>1083 -        if (Eflag || Mflag)
 1084 -                dexit(eflag);
  934+        if (cflag)
  935+                dexit(0);
1085936 
 1086937         /*
 1087938          * Linker
 1088939          */
<>1089 -nocom:
 1090 -        if (cflag==0 && ninput != 0) {
 1091 -                j = 0;
 1092 -                av[j++] = ld;
 1093 -#ifndef MSLINKER
 1094 -                if (vflag)
 1095 -                        av[j++] = "-v";
 1096 -#endif
 1097 -#if !defined(os_sunos) && !defined(os_win32) && !defined(os_darwin)
 1098 -                av[j++] = "-X";
 1099 -#endif
 1100 -                if (sysroot && *sysroot)
 1101 -                        av[j++] = cat("--sysroot=", sysroot);
 1102 -                if (shared) {
 1103 -#ifdef os_darwin
 1104 -                        av[j++] = "-dylib";
 1105 -#else
 1106 -                        av[j++] = "-shared";
 1107 -#endif
 1108 -#ifdef os_win32
 1109 -                        av[j++] = "-Bdynamic";
 1110 -#endif
 1111 -#ifndef os_sunos
 1112 -                } else {
 1113 -#ifndef os_win32
 1114 -#ifndef os_darwin
 1115 -                        av[j++] = "-d";
 1116 -#endif
 1117 -                        if (rflag) {
 1118 -                                av[j++] = "-r";
 1119 -                        } else {
 1120 -                                av[j++] = "-e";
 1121 -                                av[j++] = STARTLABEL;
 1122 -                        }
 1123 -#endif
 1124 -#endif
 1125 -                        if (Bstatic == 0) { /* Dynamic linkage */
 1126 -#ifdef DYNLINKER
 1127 -                                for (i = 0; dynlinker[i]; i++)
 1128 -                                        av[j++] = dynlinker[i];
 1129 -#endif
 1130 -                        } else {
 1131 -#ifdef os_darwin
 1132 -                                av[j++] = "-static";
 1133 -#else
 1134 -                                av[j++] = "-Bstatic";
 1135 -#endif
 1136 -                        }
 1137 -                }
 1138 -                if (outfile) {
 1139 -#ifdef MSLINKER
 1140 -                        av[j++] = cat("/OUT:", outfile);
 1141 -#else
 1142 -                        av[j++] = "-o";
 1143 -                        av[j++] = outfile;
 1144 -#endif
 1145 -                }
 1146 -#ifdef STARTFILES_S
 1147 -                if (shared) {
 1148 -                        if (!nostartfiles) {
 1149 -                                for (i = 0; startfiles_S[i]; i++)
 1150 -                                        av[j++] = find_file(startfiles_S[i], R_OK);
 1151 -                        }
 1152 -                } else
 1153 -#endif
 1154 -                {
 1155 -                        if (!nostartfiles) {
 1156 -#ifdef CRT0FILE_PROFILE
 1157 -                                if (pgflag) {
 1158 -                                        av[j++] = find_file(crt0file_profile, R_OK);
 1159 -                                } else
 1160 -#endif
 1161 -                                {
 1162 -#ifdef CRT0FILE
 1163 -                                        av[j++] = find_file(crt0file, R_OK);
 1164 -#endif
 1165 -                                }
 1166 -#ifdef STARTFILES_T
 1167 -                                if (Bstatic) {
 1168 -                                        for (i = 0; startfiles_T[i]; i++)
 1169 -                                                av[j++] = find_file(startfiles_T[i], R_OK);
 1170 -                                } else
 1171 -#endif
 1172 -                                {
 1173 -#ifdef STARTFILES
 1174 -                                        for (i = 0; startfiles[i]; i++)
 1175 -                                                av[j++] = find_file(startfiles[i], R_OK);
 1176 -#endif
 1177 -                                }
 1178 -                        }
 1179 -                }
 1180 -                i = 0;
 1181 -                STRLIST_FOREACH(s, &middle_linker_flags)
 1182 -                        av[j++] = s->value;
 1183 -                STRLIST_FOREACH(s, &inputs)
 1184 -                        av[j++] = s->value;
 1185 -                STRLIST_FOREACH(s, &late_linker_flags)
 1186 -                        av[j++] = s->value;
  940+        setup_ld_flags();
  941+        if (run_linker())
  942+                exandrm(0);
1187943 
<>1188 -                i = 0;
 1189 -#if !defined(os_darwin) && !defined(os_sunos)
 1190 -                /* darwin assembler doesn't want -g */
 1191 -                if (gflag)
 1192 -                        av[j++] = "-g";
 1193 -#endif
 1194 -#if 0
 1195 -                if (gflag)
 1196 -                        av[j++] = "-lg";
 1197 -#endif
 1198 -                if (pthreads)
 1199 -                        av[j++] = "-lpthread";
 1200 -                if (!nostdlib) {
 1201 -#ifdef MSLINKER
 1202 -#define LFLAG   "/LIBPATH:"
 1203 -#else
 1204 -#define LFLAG   "-L"
 1205 -#endif
 1206 -#ifdef PCCLIBDIR
 1207 -                        av[j++] = cat(LFLAG, pcclibdir);
 1208 -#endif
 1209 -#ifdef os_win32
 1210 -                        av[j++] = cat(LFLAG, libdir);
 1211 -#endif
 1212 -                        if (pgflag) {
 1213 -                                for (i = 0; libclibs_profile[i]; i++)
 1214 -                                        av[j++] = find_file(libclibs_profile[i], R_OK);
 1215 -                        } else {
 1216 -                                if (cxxflag)
 1217 -                                        av[j++] = "-lp++";
 1218 -                                for (i = 0; libclibs[i]; i++)
 1219 -                                        av[j++] = find_file(libclibs[i], R_OK);
 1220 -                        }
 1221 -                }
 1222 -                if (!nostartfiles) {
 1223 -#ifdef STARTFILES_S
 1224 -                        if (shared) {
 1225 -                                for (i = 0; endfiles_S[i]; i++)
 1226 -                                        av[j++] = find_file(endfiles_S[i], R_OK);
 1227 -                        } else
 1228 -#endif
 1229 -                        {
 1230 -#ifdef STARTFILES_T
 1231 -                                if (Bstatic) {
 1232 -                                        for (i = 0; endfiles_T[i]; i++)
 1233 -                                                av[j++] = find_file(endfiles_T[i], R_OK);
 1234 -                                } else
 1235 -#endif
 1236 -                                {
 1237 -#ifdef STARTFILES
 1238 -                                        for (i = 0; endfiles[i]; i++)
 1239 -                                                av[j++] = find_file(endfiles[i], R_OK);
 1240 -#endif
 1241 -                                }
 1242 -                        }
 1243 -                }
 1244 -                av[j++] = 0;
 1245 -                eflag |= callsys(ld, av);
 1246 -                STRLIST_FOREACH(s, &temp_outputs)
 1247 -                        cunlink(s->value);
 1248 -        }
1249944 #ifdef notdef
 1250945         strlist_free(&crtdirs);
 1251946         strlist_free(&libdirs);
     
 !
1263958         strlist_free(&inputs);
 1264959         strlist_free(&assembler_flags);
 1265960         strlist_free(&temp_outputs);
<> 961+        strlist_free(&compiler_flags);
1266962 #endif
<>1267 -        dexit(eflag);
  963+        dexit(0);
1268964         return 0;
 1269965 }
 1270966 
     
 !
1283979 void
 1284980 dexit(int eval)
 1285981 {
<>1286 -        if (!pflag && !Xflag) {
 1287 -                if (sflag==0)
 1288 -                        cunlink(tmp3);
 1289 -                cunlink(tmp4);
  982+        struct string *s;
  983+
  984+        if (!Xflag) {
  985+                STRLIST_FOREACH(s, &temp_outputs)
  986+                        cunlink(s->value);
1290987         }
<>1291 -        if (exfail || eflag)
 1292 -                cunlink(ermfile);
 1293 -        if (eval == 100)
 1294 -                _exit(eval);
1295988         exit(eval);
 1296989 }
 1297990 
<> 991+/*
  992+ * Called when something failed.
  993+ */
  994+void
  995+exandrm(char *s)
  996+{
  997+        if (s && *s)
  998+                strlist_append(&temp_outputs, s);
  999+        dexit(1);
  1000+}
  1001+
12981002 static void
 12991003 ccerror(char *s, va_list ap)
 13001004 {
 13011005         vfprintf(Eflag ? stderr : stdout, s, ap);
 13021006         putc('\n', Eflag? stderr : stdout);
<>1303 -        exfail++;
 1304 -        cflag++;
 1305 -        eflag++;
13061007 }
 13071008 
 13081009 /*
     
 !
13331034 }
 13341035 
 13351036 static char *
<>1336 -find_file2(const char *file, struct strlist *path, int mode)
  1037+find_file(const char *file, struct strlist *path, int mode)
13371038 {
 13381039         struct string *s;
 13391040         char *f;
     
 !
13561057         return xstrdup(file);
 13571058 }
 13581059 
<> 1060+static int
  1061+compile_input(char *input, char *output)
  1062+{
  1063+        struct strlist args;
  1064+        int retval;
13591065 
<>1360 -static size_t file_prefixes_cnt;
 1361 -static char **file_prefixes;
  1066+        strlist_init(&args);
  1067+        strlist_append_list(&args, &compiler_flags);
  1068+        strlist_append(&args, input);
  1069+        strlist_append(&args, output);
  1070+        strlist_prepend(&args,
  1071+            find_file(cxxflag ? passxx0 : pass0, &progdirs, X_OK));
  1072+        retval = strlist_exec(&args);
  1073+        strlist_free(&args);
  1074+        return retval;
  1075+}
13621076 
<>1363 -static void
 1364 -add_prefix(const char *prefix)
  1077+static int
  1078+assemble_input(char *input, char *output)
13651079 {
<>1366 -        file_prefixes = realloc(file_prefixes,
 1367 -            sizeof(*file_prefixes) * (file_prefixes_cnt + 1));
 1368 -        if (file_prefixes == NULL)
 1369 -                errorx(1, "malloc failed");
 1370 -        file_prefixes[file_prefixes_cnt++] = copy(prefix, 0);
  1080+        struct strlist args;
  1081+        int retval;
  1082+
  1083+        strlist_init(&args);
  1084+        strlist_append_list(&args, &assembler_flags);
  1085+        strlist_append(&args, input);
  1086+        strlist_append(&args, "-o");
  1087+        strlist_append(&args, output);
  1088+        strlist_prepend(&args,
  1089+            find_file(as, &progdirs, X_OK));
  1090+        retval = strlist_exec(&args);
  1091+        strlist_free(&args);
  1092+        return retval;
13711093 }
 13721094 
<>1373 -static char *
 1374 -find_file(const char *base, int mode)
  1095+static int
  1096+preprocess_input(char *input, char *output, int dodep)
13751097 {
<>1376 -        char *path;
 1377 -        size_t baselen = strlen(base);
 1378 -        size_t sysrootlen = sysroot ? strlen(sysroot) : 0;
 1379 -        size_t len, prefix_len, i;
  1098+        struct strlist args;
  1099+        struct string *s;
  1100+        int retval;
13801101 
<>1381 -        for (i = 0; i < file_prefixes_cnt; ++i) {
 1382 -                prefix_len = strlen(file_prefixes[i]);
 1383 -                len = prefix_len + baselen + 2;
 1384 -                if (file_prefixes[i][0] == '=') {
 1385 -                        len += sysrootlen;
 1386 -                        path = ccmalloc(len);
 1387 -                        snprintf(path, len, "%s%s/%s", sysroot,
 1388 -                            file_prefixes[i] + 1, base);
 1389 -                } else {
 1390 -                        path = ccmalloc(len);
 1391 -                        snprintf(path, len, "%s/%s", file_prefixes[i], base);
  1102+        strlist_init(&args);
  1103+        strlist_append_list(&args, &preprocessor_flags);
  1104+        STRLIST_FOREACH(s, &includes) {
  1105+                strlist_append(&args, "-i");
  1106+                strlist_append(&args, s->value);
  1107+        }
  1108+        STRLIST_FOREACH(s, &incdirs) {
  1109+                strlist_append(&args, "-I");
  1110+                strlist_append(&args, s->value);
  1111+        }
  1112+        STRLIST_FOREACH(s, &user_sysincdirs) {
  1113+                strlist_append(&args, "-S");
  1114+                strlist_append(&args, s->value);
  1115+        }
  1116+        if (!nostdinc) {
  1117+                STRLIST_FOREACH(s, &sysincdirs) {
  1118+                        strlist_append(&args, "-S");
  1119+                        strlist_append(&args, s->value);
13921120                 }
<>1393 -                if (access(path, mode) == 0)
 1394 -                        return path;
 1395 -                free(path);
13961121         }
<> 1122+        if (dodep)
  1123+                strlist_append_list(&args, &depflags);
  1124+        strlist_append(&args, input);
  1125+        if (output)
  1126+                strlist_append(&args, output);
13971127 
<>1398 -        return copy(base, 0);
  1128+        strlist_prepend(&args, find_file(passp, &progdirs, X_OK));
  1129+        retval = strlist_exec(&args);
  1130+        strlist_free(&args);
  1131+        return retval;
13991132 }
 14001133 
<> 1134+static int
  1135+run_linker(void)
  1136+{
  1137+        struct strlist linker_flags;
  1138+        int retval;
  1139+
  1140+        if (outfile) {
  1141+                strlist_prepend(&early_linker_flags, outfile);
  1142+                strlist_prepend(&early_linker_flags, "-o");
  1143+        }
  1144+        strlist_init(&linker_flags);
  1145+        strlist_append_list(&linker_flags, &early_linker_flags);
  1146+        strlist_append_list(&linker_flags, &middle_linker_flags);
  1147+        strlist_append_list(&linker_flags, &late_linker_flags);
  1148+        strlist_prepend(&linker_flags, find_file(ld, &progdirs, X_OK));
  1149+
  1150+        retval = strlist_exec(&linker_flags);
  1151+
  1152+        strlist_free(&linker_flags);
  1153+        return retval;
  1154+}
  1155+
14011156 static char *cxxt[] = { "cc", "cp", "cxx", "cpp", "CPP", "c++", "C" };
 14021157 int
 14031158 cxxsuf(char *s)
     
 !
14361191 setsuf(char *s, char ch)
 14371192 {
 14381193         char *p;
<> 1194+        int l;
14391195 
<>1440 -        s = copy(basename(s), 2);
 1441 -        if ((p = strrchr(s, '.')) == NULL) {
 1442 -                p = s + strlen(s);
 1443 -                p[0] = '.';
  1196+        if ((p = strrchr(s, '.'))) {
  1197+                p[1] = ch;
  1198+                p[2] = '\0';
14441199         }
<>1445 -        p[1] = ch;
 1446 -        p[2] = '\0';
  1200+        l = strlen(s)+3;
  1201+        p = xmalloc(l);
  1202+        strlcpy(p, s, l);
  1203+        s = p;
  1204+        p += l-3;
  1205+        *p++ = '.';
  1206+        *p++ = ch;
  1207+        *p++ = 0;
14471208         return(s);
 14481209 }
 14491210 
     
 !
14901251         return (exitCode != 0);
 14911252 }
 14921253 
<>1493 -#else
 1494 -
 1495 -int
 1496 -callsys(char *f, char *v[])
 1497 -{
 1498 -        int t, status = 0;
 1499 -        pid_t p;
 1500 -        char *prog;
 1501 -
 1502 -        if (vflag) {
 1503 -                fprintf(stderr, "%s ", f);
 1504 -                for (t = 1; v[t]; t++)
 1505 -                        fprintf(stderr, "%s ", v[t]);
 1506 -                fprintf(stderr, "\n");
 1507 -        }
 1508 -
 1509 -        prog = find_file(f, X_OK);
 1510 -#ifdef HAVE_VFORK
 1511 -        if ((p = vfork()) == 0) {
 1512 -#else
 1513 -        if ((p = fork()) == 0) {
15141254 #endif
<>1515 -                static const char msg[] = "Can't find ";
 1516 -                execvp(prog, v);
 1517 -                t = write(STDERR_FILENO, msg, sizeof(msg));
 1518 -                t = write(STDERR_FILENO, prog, strlen(prog));
 1519 -                t = write(STDERR_FILENO, "\n", 1);
 1520 -                _exit(100);
 1521 -        }
 1522 -        if (p == -1) {
 1523 -                fprintf(stderr, "fork() failed, try again\n");
 1524 -                return(100);
 1525 -        }
 1526 -        free(prog);
 1527 -        while (waitpid(p, &status, 0) == -1 && errno == EINTR)
 1528 -                ;
 1529 -        if (WIFEXITED(status))
 1530 -                return (WEXITSTATUS(status));
 1531 -        if (WIFSIGNALED(status))
 1532 -                dexit(eflag ? eflag : 1);
 1533 -        errorx(8, "Fatal error in %s", f);
15341255 
<>1535 -        return 0;
 1536 -}
 1537 -#endif
 1538 -
 1539 -#if 0
15401256 static int
 15411257 strlist_exec(struct strlist *l)
 15421258 {
<> 1259+        sig_atomic_t exit_now = 0;
  1260+        sig_atomic_t child;
15431261         char **argv;
 15441262         size_t argc;
 15451263         int result;
 15461264 
 15471265         strlist_make_array(l, &argv, &argc);
<>1548 -        if (verbose_mode) {
  1266+        if (vflag) {
15491267                 printf("Calling ");
 15501268                 strlist_print(l, stdout);
 15511269                 printf("\n");
 15521270         }
 15531271 
<>1554 -        if (exit_now)
 1555 -                return 1;
 1556 -
15571272         switch ((child = fork())) {
 15581273         case 0:
 15591274                 execvp(argv[0], argv);
     
 !
15771292         }
 15781293         return exit_now;
 15791294 }
<>1580 -#endif
15811295 
 15821296 /*
<>1583 - * Make a copy of string as, mallocing extra bytes in the string.
 1584 - */
 1585 -char *
 1586 -copy(const char *s, int extra)
 1587 -{
 1588 -        int len = strlen(s)+1;
 1589 -        char *rv;
 1590 -
 1591 -        rv = ccmalloc(len+extra);
 1592 -        strlcpy(rv, s, len);
 1593 -        return rv;
 1594 -}
 1595 -
 1596 -/*
15971297  * Catenate two (optional) strings together
 15981298  */
 15991299 char *
     
 !
16031303         char *rv;
 16041304 
 16051305         len = (a ? strlen(a) : 0) + (b ? strlen(b) : 0) + 1;
<>1606 -        rv = ccmalloc(len);
  1306+        rv = xmalloc(len);
16071307         snprintf(rv, len, "%s%s", (a ? a : ""), (b ? b : ""));
 16081308         return rv;
 16091309 }
     
 !
16361336                 fprintf(stderr, "%s:\n", pathBuffer);
 16371337                 exit(8);
 16381338         }
<>1639 -        return copy(tempFilename, 0);
  1339+        return xstrdup(tempFilename);
16401340 }
 16411341 
 16421342 #else
 16431343 
 16441344 char *
 16451345 gettmp(void)
 16461346 {
<>1647 -        char *sfn = copy("/tmp/ctm.XXXXXX", 0);
  1347+        char *sfn = xstrdup("/tmp/ctm.XXXXXX");
16481348         int fd = -1;
 16491349 
 16501350         if ((fd = mkstemp(sfn)) == -1) {
     
 !
16561356 }
 16571357 #endif
 16581358 
<>1659 -void *
 1660 -ccmalloc(int size)
 1661 -{
 1662 -        void *rv;
 1663 -
 1664 -        if ((rv = malloc(size)) == NULL)
 1665 -                error("malloc failed");
 1666 -        return rv;
 1667 -}
 1668 -
16691359 static void
 16701360 expand_sysroot(void)
 16711361 {
     
 !
18941584         strlist_append(&sysincdirs, "=" PCCINCDIR);
 18951585 }
 18961586 
<> 1587+struct flgcheck ccomflgcheck[] = {
  1588+        { &Oflag, 1, "-xtemps" },
  1589+        { &Oflag, 1, "-xdeljumps" },
  1590+        { &Oflag, 1, "-xinline" },
  1591+#ifdef notyet
  1592+        { &Oflag, 1, "-xdce" },
  1593+        { &Oflag, 1, "-xssa" },
  1594+#endif
  1595+        { &freestanding, 1, "-ffreestanding" },
  1596+        { &pgflag, 1, "-p" },
  1597+        { &gflag, 1, "-g" },
  1598+        { &xgnu89, 1, "-xgnu89" },
  1599+        { &xgnu99, 1, "-xgnu99" },
  1600+        { &xuchar, 1, "-xuchar" },
  1601+#if !defined(os_sunos) && !defined(mach_i386)
  1602+        { &vflag, 0, "-v" },
  1603+#endif
  1604+#ifdef os_darwin
  1605+        { &Bstatic, 1, "-k" },
  1606+#elif defined(os_sunos) && defined(mach_i386)
  1607+        { &kflag, 1, "-K" },
  1608+        { &kflag, 1, "pic" },
  1609+#else
  1610+        { &kflag, 1, "-k" },
  1611+#endif
  1612+        { &sspflag, 1, "-fstack-protector" },
  1613+        { 0 }
  1614+};
  1615+
  1616+void
  1617+setup_ccom_flags(void)
  1618+{
  1619+        struct Wflags *Wf;
  1620+
  1621+        cksetflags(ccomflgcheck, &compiler_flags);
  1622+        if (Wflag || Wallflag) {
  1623+                /* -Wall is same as gcc, -WW is all flags */
  1624+                for (Wf = Wflags; Wf->name; Wf++) {
  1625+                        if (Wflag || Wf->flags == INWALL)
  1626+                                strlist_append(&compiler_flags,
  1627+                                    cat("-W", Wf->name));
  1628+
  1629+                }
  1630+        }
  1631+}
  1632+
  1633+static int one = 1;
  1634+
  1635+struct flgcheck asflgcheck[] = {
  1636+#if defined(USE_YASM)
  1637+        { &one, 1, "-p" },
  1638+        { &one, 1, "gnu" },
  1639+        { &one, 1, "-f" },
  1640+#if defined(os_win32)
  1641+        { &one, 1, "win32" },
  1642+#elif defined(os_darwin)
  1643+        { &one, 1, "macho" },
  1644+#else
  1645+        { &one, 1, "elf" },
  1646+#endif
  1647+#endif
  1648+#if defined(os_sunos) && defined(mach_sparc64)
  1649+        { &one, 1, "-m64" },
  1650+#endif
  1651+#if defined(os_darwin)
  1652+        { &Bstatic, 1, "-static" },
  1653+#endif
  1654+#if !defined(USE_YASM)
  1655+        { &vflag, 1, "-v" },
  1656+#endif
  1657+        { &kflag, 1, "-k" },
  1658+#ifdef os_darwin
  1659+        { &one, 1, "-arch" },
  1660+#if mach_amd64
  1661+        { &amd64_i386, 1, "i386" },
  1662+        { &amd64_i386, 0, "x86_64" },
  1663+#else
  1664+        { &one, 1, "i386" },
  1665+#endif
  1666+#else
  1667+#ifdef mach_amd64
  1668+        { &amd64_i386, 1, "--32" },
  1669+#endif
  1670+#endif
  1671+        { 0 }
  1672+};
  1673+void
  1674+setup_as_flags(void)
  1675+{
  1676+        one = one;
  1677+        cksetflags(asflgcheck, &assembler_flags);
  1678+}
  1679+
  1680+struct flgcheck ldflgcheck[] = {
  1681+#ifndef MSLINKER
  1682+        { &vflag, 1, "-v" },
  1683+#endif
  1684+#if !defined(os_sunos) && !defined(os_win32) && !defined(os_darwin)
  1685+        { &one, 1, "-X" },
  1686+#endif
  1687+#ifdef os_darwin
  1688+        { &shared, 1, "-dylib" },
  1689+#elif defined(os_win32)
  1690+        { &shared, 1, "-Bdynamic" },
  1691+else
  1692+        { &shared, 1, "-shared" },
  1693+#endif
  1694+#if !defined(os_sunos) && !defined(os_win32)
  1695+#ifndef os_darwin
  1696+        { &shared, 0, "-d" },
  1697+#endif
  1698+        { &rflag, 1, "-r" },
  1699+        { &rflag, 0, "-e" },
  1700+        { &rflag, 0, STARTLABEL },
  1701+#endif
  1702+#ifdef os_darwin
  1703+        { &Bstatic, 1, "-static" },
  1704+#else
  1705+        { &Bstatic, 1, "-Bstatic" },
  1706+#endif
  1707+#if !defined(os_darwin) && !defined(os_sunos)
  1708+        { &gflag, 1, "-g" },
  1709+#endif
  1710+        { &pthreads, 1, "-lpthread" },
  1711+        { 0 },
  1712+};
  1713+
  1714+void
  1715+setup_ld_flags(void)
  1716+{
  1717+        int i;
  1718+
  1719+        cksetflags(ldflgcheck, &early_linker_flags);
  1720+        if (Bstatic == 0)
  1721+                for (i = 0; dynlinker[i]; i++)
  1722+                        strlist_append(&early_linker_flags, dynlinker[i]);
  1723+        if (sysroot && *sysroot)
  1724+                strlist_append(&early_linker_flags, cat("--sysroot=", sysroot));
  1725+        if (!nostdlib) {
  1726+                /* library search paths */
  1727+                if (pcclibdir)
  1728+                        strlist_append(&late_linker_flags,
  1729+                            cat("-L", pcclibdir));
  1730+                for (i = 0; deflibdirs[i]; i++)
  1731+                        strlist_append(&late_linker_flags,
  1732+                            cat("-L", deflibdirs[i]));
  1733+                /* standard libraries */
  1734+                if (pgflag) {
  1735+                        for (i = 0; defproflibs[i]; i++)
  1736+                                strlist_append(&late_linker_flags,
  1737+                                     defproflibs[i]);
  1738+                } else if (cxxflag) {
  1739+                        for (i = 0; defcxxlibs[i]; i++)
  1740+                                strlist_append(&late_linker_flags,
  1741+                                    defcxxlibs[i]);
  1742+                } else {
  1743+                        for (i = 0; deflibs[i]; i++)
  1744+                                strlist_append(&late_linker_flags, deflibs[i]);
  1745+                }
  1746+        }
  1747+        if (!nostartfiles) {
  1748+                if (shared) {
  1749+                        strlist_prepend(&middle_linker_flags,
  1750+                            find_file(CRTBEGIN_S, &crtdirs, R_OK));
  1751+                        strlist_append(&late_linker_flags,
  1752+                            find_file(CRTEND_S, &crtdirs, R_OK));
  1753+                } else {
  1754+                        if (Bstatic) {
  1755+                                strlist_prepend(&middle_linker_flags,
  1756+                                    find_file(CRTBEGIN_T, &crtdirs, R_OK));
  1757+                                strlist_append(&late_linker_flags,
  1758+                                    find_file(CRTEND_T, &crtdirs, R_OK));
  1759+#ifdef notyet
  1760+                        } else if (pieflag) {
  1761+                                strlist_prepend(&middle_linker_flags,
  1762+                                    find_file(CRTBEGIN_S, &crtdirs, R_OK));
  1763+                                strlist_append(&late_linker_flags,
  1764+                                    find_file(CRTEND_S, &crtdirs, R_OK));
  1765+#endif
  1766+                        } else {
  1767+                                strlist_prepend(&middle_linker_flags,
  1768+                                    find_file(CRTBEGIN, &crtdirs, R_OK));
  1769+                                strlist_append(&late_linker_flags,
  1770+                                    find_file(CRTEND, &crtdirs, R_OK));
  1771+                        }
  1772+                        strlist_prepend(&middle_linker_flags,
  1773+                            find_file(CRTI, &crtdirs, R_OK));
  1774+                        strlist_append(&late_linker_flags,
  1775+                            find_file(CRTN, &crtdirs, R_OK));
  1776+                        if (pgflag)
  1777+                                strlist_prepend(&middle_linker_flags,
  1778+                                    find_file(GCRT0, &crtdirs, R_OK));
  1779+#ifdef notyet
  1780+                        else if (pieflag)
  1781+                                strlist_prepend(&middle_linker_flags,
  1782+                                    find_file(SCRT0, &crtdirs, R_OK));
  1783+#endif
  1784+                        else
  1785+                                strlist_prepend(&middle_linker_flags,
  1786+                                    find_file(CRT0, &crtdirs, R_OK));
  1787+                }
  1788+        }
  1789+}
  1790+
18971791 #ifdef os_win32
 18981792 char *
 18991793 win32pathsubst(char *s)
     
 !
19091803         while (env[len-1] == '/' || env[len-1] == '\\' || env[len-1] == '\0')
 19101804                 env[--len] = 0;
 19111805 
<>1912 -        rv = ccmalloc(len+1);
  1806+        rv = xmalloc(len+1);
19131807         strlcpy(rv, env, len+1);
 19141808 
 19151809         return rv;
     
 !
19381832                 len += j + 3;
 19391833         }
 19401834 
<>1941 -        p = cmd = ccmalloc(len);
  1835+        p = cmd = xmalloc(len);
<_19421836         *p++ = '\"';
 19431837         p += strlcpy(p, f, len-1);
 19441838         *p++ = '\"';
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-31 11:44 +0100