Changeset 832

Show
Ignore:
Timestamp:
11/14/07 15:17:42 (1 year ago)
Author:
Jim Panic
Message:

closes #162
Also fixed the "indentation"

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/rebuild/mars.c

    r830 r832  
    5656Global::Global() 
    5757{ 
    58     mars_ext = "d"; 
    59     sym_ext  = "d"; 
    60     hdr_ext  = "di"; 
    61     doc_ext  = "html"; 
    62     ddoc_ext = "ddoc"; 
    63  
    64     obj_ext  = "o"; 
    65  
    66     copyright = "Copyright (c) 1999-2007 by Digital Mars and Gregor Richards,"; 
    67     written = "written by Walter Bright and Gregor Richards"; 
    68     version = "version 0.73 (based on DMD 2.003)"; 
    69     global.structalign = 8; 
    70     cmodules = NULL; 
    71  
    72     memset(&params, 0, sizeof(Param)); 
     58   mars_ext = "d"; 
     59   sym_ext  = "d"; 
     60   hdr_ext  = "di"; 
     61   doc_ext  = "html"; 
     62   ddoc_ext = "ddoc"; 
     63 
     64   obj_ext  = "o"; 
     65 
     66   copyright = "Copyright (c) 1999-2007 by Digital Mars and Gregor Richards,"; 
     67   written = "written by Walter Bright and Gregor Richards"; 
     68   version = "version 0.73 (based on DMD 2.003)"; 
     69   global.structalign = 8; 
     70   cmodules = NULL; 
     71 
     72   memset(&params, 0, sizeof(Param)); 
    7373} 
    7474 
    7575char *Loc::toChars() 
    7676{ 
    77     OutBuffer buf; 
    78     char *p; 
    79  
    80     if (filename) 
    81    
    82     buf.printf("%s", filename); 
    83    
    84  
    85     if (linnum) 
    86     buf.printf("(%d)", linnum); 
    87     buf.writeByte(0); 
    88     return (char *)buf.extractData(); 
     77   OutBuffer buf; 
     78   char *p; 
     79 
     80   if (filename) 
     81   
     82       buf.printf("%s", filename); 
     83   
     84 
     85   if (linnum) 
     86       buf.printf("(%d)", linnum); 
     87   buf.writeByte(0); 
     88   return (char *)buf.extractData(); 
    8989} 
    9090 
    9191Loc::Loc(Module *mod, unsigned linnum) 
    9292{ 
    93     this->linnum = linnum; 
    94     this->filename = mod ? mod->srcfile->toChars() : NULL; 
     93   this->linnum = linnum; 
     94   this->filename = mod ? mod->srcfile->toChars() : NULL; 
    9595} 
    9696 
     
    101101void error(Loc loc, const char *format, ...) 
    102102{ 
    103     va_list ap; 
    104     va_start(ap, format); 
    105     verror(loc, format, ap); 
    106     va_end( ap ); 
     103   va_list ap; 
     104   va_start(ap, format); 
     105   verror(loc, format, ap); 
     106   va_end( ap ); 
    107107} 
    108108 
    109109void verror(Loc loc, const char *format, va_list ap) 
    110110{ 
    111     if (!global.gag) 
    112    
    113     char *p = loc.toChars(); 
    114  
    115     if (*p) 
    116         fprintf(stdmsg, "%s: ", p); 
    117     mem.free(p); 
    118  
    119     fprintf(stdmsg, "Error: "); 
    120     vfprintf(stdmsg, format, ap); 
    121     fprintf(stdmsg, "\n"); 
    122     fflush(stdmsg); 
    123 //halt(); 
    124    
    125     global.errors++; 
     111   if (!global.gag) 
     112   
     113       char *p = loc.toChars(); 
     114 
     115       if (*p) 
     116           fprintf(stdmsg, "%s: ", p); 
     117       mem.free(p); 
     118 
     119       fprintf(stdmsg, "Error: "); 
     120       vfprintf(stdmsg, format, ap); 
     121       fprintf(stdmsg, "\n"); 
     122       fflush(stdmsg); 
     123       //halt(); 
     124   
     125   global.errors++; 
    126126} 
    127127 
     
    134134{ 
    135135#if 0 
    136     halt(); 
     136   halt(); 
    137137#endif 
    138     exit(EXIT_FAILURE); 
     138   exit(EXIT_FAILURE); 
    139139} 
    140140 
     
    146146{ 
    147147#ifdef DEBUG 
    148     *(char*)0=0; 
     148   *(char*)0=0; 
    149149#endif 
    150150} 
    151151 
    152152/*extern void backend_init(); 
    153 extern void backend_term();*/ 
     153  extern void backend_term();*/ 
    154154 
    155155void usage() 
    156156{ 
    157     printf("ReBuild %s\n%s %s\n", 
    158     global.version, global.copyright, global.written); 
    159     printf("\ 
    160 Documentation: http://www.digitalmars.com/d/index.html\n\ 
    161 Usage:\n\ 
    162   rebuild files.d ... { -switch }\n\ 
    163 \n\ 
    164   files.d        D source files\n\ 
    165   -rf<filename>  Use specified response file\n\ 
    166   -dc=<compiler> use the specified compiler configuration\n\ 
    167   -p             do not compile (or link)\n\ 
    168   -c             do not link\n\ 
    169   -D             generate documentation\n\ 
    170   -Dddocdir      write documentation files to docdir directory\n\ 
    171   -Dffilename    write documentation file to filename\n\ 
    172   -Dqdocdir      write documentation files to docdir directory with\n\ 
    173                  fully-qualified file names\n\ 
    174   -lib           link a static library\n\ 
    175   -libs-safe     exit failure or success for whether libraries can be safely\n\ 
    176                  be used with any D code\n\ 
    177   -shlib         link a shared library\n\ 
    178   -shlib-support exit failure or success for whether shared libraries are\n\ 
    179                  supported\n\ 
    180   -dylib         link a dynamic library (a library intended to be loaded at\n\ 
    181                  runtime)\n\ 
    182   -dylib-support exit failure or success for whether dynamic libraries are\n\ 
    183                  supported\n\ 
    184   -g             add symbolic debug info\n\ 
    185   -gc            add symbolic debug info, pretend to be C\n\ 
    186   -files         list files which would be compiled (but don't compile)\n\ 
    187   -notfound      list files which are imported, but do not exist (and don't\n\ 
    188                  compile)\n\ 
    189   -objfiles      list object files generated\n\ 
    190   -keeprfiles    Keep response files (if they are used)\n\ 
    191   -full          compile all source files, regardless of their age\n\ 
    192   -explicit      only compile files explicitly named, not dependencies\n\ 
    193   --help         print help\n\ 
    194   -Ipath         where to look for imports\n\ 
    195   -Ccompileflag  pass compileflag to compilation\n\ 
    196   -Llinkerflag   pass linkerflag to the linker at link time\n\ 
    197   -Klinkerflag   pass linkerflag to the compiler at link time\n\ 
    198   -ll<lib>       link in the specified library\n\ 
    199                  Windows: Link to <lib>.lib\n\ 
    200                  Posix: Link to lib<lib>.{a,so}\n\ 
    201   -Spath         search path for libraries\n\ 
    202   -O             optimize\n\ 
    203   -oqobjdir      write object files to directory objdir with fully-qualified\n\ 
    204                  module names\n\ 
    205   -odobjdir      write object files to directory objdir\n\ 
    206   -offilename  name output file to filename\n\ 
    207   -quiet         suppress unnecessary messages\n\ 
    208   -release     compile release version\n\ 
    209   -exec          run resulting program\n\ 
    210   -v             verbose\n\ 
    211   -n             just list the commands to be run, don't run them\n\ 
    212   -version=level compile in version code >= level\n\ 
    213   -version=ident compile in version code identified by ident\n\ 
    214   -debug         compile in debug code\n\ 
    215   -debug=level   compile in debug code <= level\n\ 
    216   -debug=ident   compile in debug code identified by ident\n\ 
    217   -clean         remove object files after done building\n\ 
    218   -no-export-dynamic do not export dynamic symbols. Dynamic symbols are\n\ 
    219                  exported by default on POSIX to support .so files\n\ 
    220   -circular      allow circular dependencies to work on some compilers (namely\n\ 
    221                 GDC) \n\ 
    222   -testversion=<version>\n\ 
    223                  exit failure or success for whether the specified version is\n\ 
    224                  defined\n\ 
    225   -reflect       use drefgen to make rodin-compatible reflections of all\n\ 
    226                  included modules\n\ 
    227   -candydoc      generate the modules.ddoc file for candydoc (must specify -Dq)\n\ 
    228   All other flags are passed to the compiler.\n\ 
    229 "); 
     157   printf("ReBuild %s\n%s %s\n", 
     158          global.version, global.copyright, global.written); 
     159   printf("\ 
     160          Documentation: http://www.digitalmars.com/d/index.html\n\ 
     161          Usage:\n\ 
     162          rebuild files.d ... { -switch }\n\ 
     163          \n\ 
     164          files.d        D source files\n\ 
     165          -rf<filename>  Use specified response file\n\ 
     166          -dc=<compiler> use the specified compiler configuration\n\ 
     167          -p             do not compile (or link)\n\ 
     168          -c             do not link\n\ 
     169          -D             generate documentation\n\ 
     170          -Dddocdir      write documentation files to docdir directory\n\ 
     171          -Dffilename    write documentation file to filename\n\ 
     172          -Dqdocdir      write documentation files to docdir directory with\n\ 
     173          fully-qualified file names\n\ 
     174          -lib           link a static library\n\ 
     175          -libs-safe     exit failure or success for whether libraries can be safely\n\ 
     176          be used with any D code\n\ 
     177          -shlib         link a shared library\n\ 
     178          -shlib-support exit failure or success for whether shared libraries are\n\ 
     179          supported\n\ 
     180          -dylib         link a dynamic library (a library intended to be loaded at\n\ 
     181                                                 runtime)\n\ 
     182          -dylib-support exit failure or success for whether dynamic libraries are\n\ 
     183          supported\n\ 
     184          -g             add symbolic debug info\n\ 
     185          -gc            add symbolic debug info, pretend to be C\n\ 
     186          -files         list files which would be compiled (but don't compile)\n\ 
     187          -notfound      list files which are imported, but do not exist (and don't\n\ 
     188                                                                          compile)\n\ 
     189          -objfiles      list object files generated\n\ 
     190          -keeprfiles    Keep response files (if they are used)\n\ 
     191          -full          compile all source files, regardless of their age\n\ 
     192          -explicit      only compile files explicitly named, not dependencies\n\ 
     193          --help         print help\n\ 
     194          -Ipath         where to look for imports\n\ 
     195          -Ccompileflag  pass compileflag to compilation\n\ 
     196          -Llinkerflag   pass linkerflag to the linker at link time\n\ 
     197          -Klinkerflag   pass linkerflag to the compiler at link time\n\ 
     198          -ll<lib>       link in the specified library\n\ 
     199          Windows: Link to <lib>.lib\n\ 
     200          Posix: Link to lib<lib>.{a,so}\n\ 
     201          -Spath         search path for libraries\n\ 
     202          -O             optimize\n\ 
     203          -oqobjdir      write object files to directory objdir with fully-qualified\n\ 
     204          module names\n\ 
     205          -odobjdir      write object files to directory objdir\n\ 
     206          -offilename  name output file to filename\n\ 
     207          -quiet         suppress unnecessary messages\n\ 
     208          -release     compile release version\n\ 
     209          -exec          run resulting program\n\ 
     210          -v             verbose\n\ 
     211          -n             just list the commands to be run, don't run them\n\ 
     212          -version=level compile in version code >= level\n\ 
     213          -version=ident compile in version code identified by ident\n\ 
     214          -debug         compile in debug code\n\ 
     215          -debug=level   compile in debug code <= level\n\ 
     216          -debug=ident   compile in debug code identified by ident\n\ 
     217          -clean         remove object files after done building\n\ 
     218          -no-export-dynamic do not export dynamic symbols. Dynamic symbols are\n\ 
     219          exported by default on POSIX to support .so files\n\ 
     220          -circular      allow circular dependencies to work on some compilers (namely\n\ 
     221                                                                                GDC) \n\ 
     222          -testversion=<version>\n\ 
     223          exit failure or success for whether the specified version is\n\ 
     224          defined\n\ 
     225          -reflect       use drefgen to make rodin-compatible reflections of all\n\ 
     226          included modules\n\ 
     227          -candydoc      generate the modules.ddoc file for candydoc (must specify -Dq)\n\ 
     228          All other flags are passed to the compiler.\n\ 
     229          "); 
    230230} 
    231231 
    232232bool stringInArray(Array *arr, char *str) 
    233233{ 
    234     for (unsigned int i = 0; i < arr->dim; i++) { 
    235         if (!stricmp((char *) arr->data[i], str)) return true; 
    236    
    237     return false; 
     234   for (unsigned int i = 0; i < arr->dim; i++) { 
     235       if (!stricmp((char *) arr->data[i], str)) return true; 
     236   
     237   return false; 
    238238} 
    239239 
    240240int main(int argc, char *argv[]) 
    241241{ 
    242     int i; 
    243     Array files; 
    244     char *p; 
    245     Module *m; 
    246     int status = EXIT_SUCCESS; 
    247     int argcstart = argc; 
    248  
    249     // Check for malformed input 
    250     if (argc < 1 || !argv) 
    251    
    252       Largs: 
    253     error("missing or null command line arguments"); 
    254     fatal(); 
    255    
    256     for (i = 0; i < argc; i++) 
    257    
    258     if (!argv[i]) 
    259         goto Largs; 
    260    
    261  
    262     files.reserve(argc - 1); 
    263  
    264     // Set default values 
    265     global.params.argv0 = argv[0]; 
    266     global.params.link = 1; 
    267     global.params.lib = 0; 
    268     global.params.shlib = 0; 
    269     global.params.dylib = 0; 
    270     global.params.fullbuild = 0; 
    271     global.params.expbuild = 0; 
    272     global.params.listfiles = 0; 
    273     global.params.listnffiles = 0; 
    274     global.params.listobjfiles = 0; 
    275     global.params.keeprfiles = 0; 
    276     global.params.fullqobjs = 1; 
    277     global.params.fullqdocs = 0; 
    278     global.params.clean = 0; 
    279     global.params.oneatatime = 0; 
    280     global.params.reflect = 0; 
    281     global.params.candydoc = 0; 
    282     global.params.objdir = "."; 
    283     global.params.useAssert = 1; 
    284     global.params.useInvariants = 1; 
    285     global.params.useIn = 1; 
    286     global.params.useOut = 1; 
    287     global.params.useArrayBounds = 1; 
    288     global.params.useSwitchError = 1; 
    289     global.params.useInline = 0; 
    290     global.params.obj = 1; 
    291     global.params.exportDynamic = 1; 
    292     global.params.Dversion = 2; 
    293     global.params.listonly = 0; 
    294     global.params.run = 0; 
    295      
    296     // set true if we're running as rerun 
    297     bool rerun = false; 
    298  
    299     global.params.linkswitches = new Array(); 
    300     global.params.libfiles = new Array(); 
    301     global.params.objfiles = new Array(); 
    302     global.params.genobjfiles = new Array(); 
    303     global.params.ddocfiles = new Array(); 
    304      
    305     // Check for being run as rdmd, rgdmd or rerun 
    306     char *binname = FileName::name(argv[0]); 
    307     if (strncmp(binname, "rerun", 5) == 0 || 
    308         strncmp(binname, "rdmd",  4) == 0 || 
    309         strncmp(binname, "rgdmd", 5) == 0) { 
    310         // first argument is the source, then args for the program 
    311         if (argc < 2) { 
    312             error("No D source file provided."); 
    313             exit(1); 
    314        
    315          
    316         global.params.run = 1; 
    317         global.params.runargs = &argv[2]; 
    318         global.params.runargs_length = argc - 2; 
    319         rerun = true; 
    320    
    321  
    322     // Predefine version identifiers 
    323     VersionCondition::addPredefinedGlobalIdent("build"); 
    324     VersionCondition::addPredefinedGlobalIdent("rebuild"); 
    325     VersionCondition::addPredefinedGlobalIdent("all"); 
    326      
    327     // BEFORE reading configuration, check for a specified profile 
    328     char *chooseProfile = "default"; 
    329      
    330     // first in the environment 
    331     char *envProfile = getenv("REBUILDPROFILE"); 
    332     if (envProfile) chooseProfile = envProfile; 
    333      
    334     // then in args 
    335     for (i = 1; !global.params.run && i < argc; i++) 
    336    
    337         p = argv[i]; 
    338         if (!strncmp(p, "-dc=", 4)) { 
    339             chooseProfile = p + 4; 
    340             break; 
    341        
    342         else if (strncmp(p, "-rf", 3) == 0) 
    343        
    344             // figure out the rf name 
    345             char *rf = p + 3; 
    346             if (!rf[0]) { 
    347                 i++; 
    348                 if (i >= argc) { 
    349                     i--; 
    350                     goto Lnoarg; 
    351                
    352                 rf = argv[i]; 
    353            
    354              
    355             parseResponseFile(&argc, &argv, rf, i); 
    356        
    357    
    358      
    359     readConfig(argv[0], chooseProfile, (chooseProfile == "default")); 
    360      
    361     // if the configuration includes path=, add that path 
    362     if (masterConfig.find("") != masterConfig.end() && 
    363         masterConfig[""].find("path") != masterConfig[""].end()) { 
    364         std::string newPath = masterConfig[""]["path"]; 
    365          
     242   int i; 
     243   Array files; 
     244   char *p; 
     245   Module *m; 
     246   int status = EXIT_SUCCESS; 
     247   int argcstart = argc; 
     248 
     249   // Check for malformed input 
     250   if (argc < 1 || !argv) 
     251   
     252Largs: 
     253       error("missing or null command line arguments"); 
     254       fatal(); 
     255   
     256   for (i = 0; i < argc; i++) 
     257   
     258       if (!argv[i]) 
     259           goto Largs; 
     260   
     261 
     262   files.reserve(argc - 1); 
     263 
     264   // Set default values 
     265   global.params.argv0 = argv[0]; 
     266   global.params.link = 1; 
     267   global.params.lib = 0; 
     268   global.params.shlib = 0; 
     269   global.params.dylib = 0; 
     270   global.params.fullbuild = 0; 
     271   global.params.expbuild = 0; 
     272   global.params.listfiles = 0; 
     273   global.params.listnffiles = 0; 
     274   global.params.listobjfiles = 0; 
     275   global.params.keeprfiles = 0; 
     276   global.params.fullqobjs = 1; 
     277   global.params.fullqdocs = 0; 
     278   global.params.clean = 0; 
     279   global.params.oneatatime = 0; 
     280   global.params.reflect = 0; 
     281   global.params.candydoc = 0; 
     282   global.params.objdir = "."; 
     283   global.params.useAssert = 1; 
     284   global.params.useInvariants = 1; 
     285   global.params.useIn = 1; 
     286   global.params.useOut = 1; 
     287   global.params.useArrayBounds = 1; 
     288   global.params.useSwitchError = 1; 
     289   global.params.useInline = 0; 
     290   global.params.obj = 1; 
     291   global.params.exportDynamic = 1; 
     292   global.params.Dversion = 2; 
     293   global.params.listonly = 0; 
     294   global.params.run = 0; 
     295 
     296   // set true if we're running as rerun 
     297   bool rerun = false; 
     298 
     299   global.params.linkswitches = new Array(); 
     300   global.params.libfiles = new Array(); 
     301   global.params.objfiles = new Array(); 
     302   global.params.genobjfiles = new Array(); 
     303   global.params.ddocfiles = new Array(); 
     304 
     305   // Check for being run as rdmd, rgdmd or rerun 
     306   char *binname = FileName::name(argv[0]); 
     307   if (strncmp(binname, "rerun", 5) == 0 || 
     308       strncmp(binname, "rdmd",  4) == 0 || 
     309       strncmp(binname, "rgdmd", 5) == 0) { 
     310       // first argument is the source, then args for the program 
     311       if (argc < 2) { 
     312           error("No D source file provided."); 
     313           exit(1); 
     314       
     315 
     316       global.params.run = 1; 
     317       global.params.runargs = &argv[2]; 
     318       global.params.runargs_length = argc - 2; 
     319       rerun = true; 
     320   
     321 
     322   // Predefine version identifiers 
     323   VersionCondition::addPredefinedGlobalIdent("build"); 
     324   VersionCondition::addPredefinedGlobalIdent("rebuild"); 
     325   VersionCondition::addPredefinedGlobalIdent("all"); 
     326 
     327   // BEFORE reading configuration, check for a specified profile 
     328   char *chooseProfile = "default"; 
     329 
     330   // first in the environment 
     331   char *envProfile = getenv("REBUILDPROFILE"); 
     332   if (envProfile) chooseProfile = envProfile; 
     333 
     334   // then in args 
     335   for (i = 1; !global.params.run && i < argc; i++) 
     336   
     337       p = argv[i]; 
     338       if (!strncmp(p, "-dc=", 4)) { 
     339           chooseProfile = p + 4; 
     340           break; 
     341       
     342       else if (strncmp(p, "-rf", 3) == 0) 
     343       
     344           // figure out the rf name 
     345           char *rf = p + 3; 
     346           if (!rf[0]) { 
     347               i++; 
     348               if (i >= argc) { 
     349                   i--; 
     350                   goto Lnoarg; 
     351               
     352               rf = argv[i]; 
     353           
     354 
     355           parseResponseFile(&argc, &argv, rf, i); 
     356       
     357   
     358 
     359   readConfig(argv[0], chooseProfile, (chooseProfile == "default")); 
     360 
     361   // if the configuration includes path=, add that path 
     362   if (masterConfig.find("") != masterConfig.end() && 
     363       masterConfig[""].find("path") != masterConfig[""].end()) { 
     364       std::string newPath = masterConfig[""]["path"]; 
     365 
    366366#ifdef __WIN32 
    367         newPath += ";"; 
     367       newPath += ";"; 
    368368#else 
    369         newPath += ":"; 
     369       newPath += ":"; 
    370370#endif 
    371          
    372         newPath += getenv("PATH"); 
    373         char *snewPath = mem.strdup(newPath.c_str()); 
     371 
     372       newPath += getenv("PATH"); 
     373       char *snewPath = mem.strdup(newPath.c_str()); 
    374374#ifdef __WIN32 
    375         SetEnvironmentVariable("PATH", snewPath); 
     375       SetEnvironmentVariable("PATH", snewPath); 
    376376#else 
    377         setenv("PATH", snewPath, 1); 
     377       setenv("PATH", snewPath, 1); 
    378378#endif 
    379    
    380      
    381     /* include <prefix>/include/d always, so that DSSS-installed things are 
    382     * usable with pure rebuild */ 
    383     char *argdir, *argfil; 
    384     if (whereAmI(argv[0], &argdir, &argfil)) { 
    385         char *fulldir = FileName::combine( 
    386             argdir, ".." DIRSEP "include" DIRSEP "d"); 
    387          
    388         if (!global.params.imppath) 
    389             global.params.imppath = new Array(); 
    390         global.params.imppath->push(fulldir); 
    391         addFlag(compileFlags, "compile", "incdir", "-I$i", fulldir); 
    392    
    393      
    394     // get include paths 
    395     if (masterConfig.find("") != masterConfig.end() && 
    396         masterConfig[""].find("compiler") != masterConfig[""].end()) { 
    397         std::string compiler = masterConfig[""]["compiler"]; 
    398          
    399         if (compiler.substr(compiler.length() - 3) == "gdc") { 
    400             // a bit more complicated 
     379   
     380 
     381   /* include <prefix>/include/d always, so that DSSS-installed things are 
     382    * usable with pure rebuild */ 
     383   char *argdir, *argfil; 
     384   if (whereAmI(argv[0], &argdir, &argfil)) { 
     385       char *fulldir = FileName::combine( 
     386                                         argdir, ".." DIRSEP "include" DIRSEP "d"); 
     387 
     388       if (!global.params.imppath) 
     389           global.params.imppath = new Array(); 
     390       global.params.imppath->push(fulldir); 
     391       addFlag(compileFlags, "compile", "incdir", "-I$i", fulldir); 
     392   
     393 
     394   // get include paths 
     395   if (masterConfig.find("") != masterConfig.end() && 
     396       masterConfig[""].find("compiler") != masterConfig[""].end()) { 
     397       std::string compiler = masterConfig[""]["compiler"]; 
     398 
     399       if (compiler.substr(compiler.length() - 3) == "gdc") { 
     400           // a bit more complicated 
    401401#define READBUFSIZ 1024 
    402             char readBuf[READBUFSIZ + 1]; 
    403             readBuf[READBUFSIZ] = '\0'; 
    404             int nloc; 
    405              
    406             // 1) read version 
    407             if (readCommand(compiler + " -dumpversion", readBuf, READBUFSIZ) < 1) { 
    408                 error("Failed to detect GDC version"); 
    409            
    410             std::string cversion = readBuf; 
    411             nloc = cversion.find('\n', 0); 
    412             if (nloc != std::string::npos) cversion = cversion.substr(0, nloc); 
    413              
    414             // 2) read machine 
    415             if (readCommand(compiler + " -dumpmachine", readBuf, READBUFSIZ) < 1) { 
    416                 error("Failed to detect GDC target"); 
    417            
    418             std::string cmachine = readBuf; 
    419             nloc = cmachine.find('\n', 0); 
    420             if (nloc != std::string::npos) cmachine = cmachine.substr(0, nloc); 
    421              
    422             // 3) get the prefix 
    423             char *gdcdir, *gdcfil; 
    424             if (!whereAmI(compiler.c_str(), &gdcdir, &gdcfil)) { 
    425                 error("%s is not in $PATH", compiler.c_str()); 
    426                 exit(1); 
    427            
    428              
    429             // 4) make include paths 
    430             if (!global.params.imppath) 
    431                 global.params.imppath = new Array(); 
    432             global.params.imppath->push(strdup( 
    433                 (std::string(gdcdir) + "/../include/d/" + cversion + "/").c_str())); 
    434             global.params.imppath->push(strdup( 
    435                 (std::string(gdcdir) + "/../include/d/" + cversion + "/" + cmachine + "/").c_str())); 
    436             global.params.imppath->push(strdup( 
    437                 (std::string(gdcdir) + "/../" + cmachine + "/include/d/" + cversion + "/").c_str())); 
    438             global.params.imppath->push(strdup( 
    439                 (std::string(gdcdir) + "/../" + cmachine + "/include/d/" + cversion + "/" + cmachine + "/").c_str())); 
    440        
    441         // assume dmd based compiler if inifile is set 
    442         else if (masterConfig[""].find("inifile") != masterConfig[""].end()) { 
    443             std::string inif = masterConfig[""]["inifile"]; 
    444  
    445             // trick whereami into giving us a path 
    446             char *dir, *fil; 
    447             if (!whereAmI(compiler.c_str(), &dir, &fil)) { 
    448                 error("%s is not in $PATH", compiler.c_str()); 
    449                 exit(1); 
    450            
    451             std::string full = dir; 
     402           char readBuf[READBUFSIZ + 1]; 
     403           readBuf[READBUFSIZ] = '\0'; 
     404           int nloc; 
     405 
     406           // 1) read version 
     407           if (readCommand(compiler + " -dumpversion", readBuf, READBUFSIZ) < 1) { 
     408               error("Failed to detect GDC version"); 
     409           
     410           std::string cversion = readBuf; 
     411           nloc = cversion.find('\n', 0); 
     412           if (nloc != std::string::npos) cversion = cversion.substr(0, nloc); 
     413 
     414           // 2) read machine 
     415           if (readCommand(compiler + " -dumpmachine", readBuf, READBUFSIZ) < 1) { 
     416               error("Failed to detect GDC target"); 
     417           
     418           std::string cmachine = readBuf; 
     419           nloc = cmachine.find('\n', 0); 
     420           if (nloc != std::string::npos) cmachine = cmachine.substr(0, nloc); 
     421 
     422           // 3) get the prefix 
     423           char *gdcdir, *gdcfil; 
     424           if (!whereAmI(compiler.c_str(), &gdcdir, &gdcfil)) { 
     425               error("%s is not in $PATH", compiler.c_str()); 
     426               exit(1); 
     427           
     428 
     429           // 4) make include paths 
     430           if (!global.params.imppath) 
     431               global.params.imppath = new Array(); 
     432           global.params.imppath->push(strdup( 
     433                                              (std::string(gdcdir) + "/../include/d/" + cversion + "/").c_str())); 
     434           global.params.imppath->push(strdup( 
     435                                              (std::string(gdcdir) + "/../include/d/" + cversion + "/" + cmachine + "/").c_str())); 
     436           global.params.imppath->push(strdup( 
     437                                              (std::string(gdcdir) + "/../" + cmachine + "/include/d/" + cversion + "/").c_str())); 
     438           global.params.imppath->push(strdup( 
     439                                              (std::string(gdcdir) + "/../" + cmachine + "/include/d/" + cversion + "/" + cmachine + "/").c_str())); 
     440       
     441       // assume dmd based compiler if inifile is set 
     442       else if (masterConfig[""].find("inifile") != masterConfig[""].end()) { 
     443           std::string inif = masterConfig[""]["inifile"]; 
     444 
     445           // trick whereami into giving us a path 
     446           char *dir, *fil; 
     447           if (!whereAmI(compiler.c_str(), &dir, &fil)) { 
     448               error("%s is not in $PATH", compiler.c_str()); 
     449               exit(1); 
     450           
     451           std::string full = dir; 
    452452#if __WIN32 
    453             full.append("\\"); 
     453           full.append("\\"); 
    454454#else 
    455             full.append("/"); 
     455           full.append("/"); 
    456456#endif 
    457             full.append(compiler); 
    458  
    459             inifile((char*)full.c_str(), (char*)inif.c_str()); 
    460        
    461    
    462      
    463     // special configuration options needed here 
    464     if (masterConfig.find("") != masterConfig.end() && 
    465         masterConfig[""].find("objext") != masterConfig[""].end()) { 
    466         global.obj_ext = strdup(masterConfig[""]["objext"].c_str()); 
    467    
    468      
    469     // get any arguments from $REBUILD_FLAGS... 
    470     getenv_setargv("REBUILD_FLAGS", &argc, &argv); 
    471      
    472     // and from $BUILD_FLAGS 
    473     getenv_setargv("BUILD_FLAGS", &argc, &argv); 
    474      
    475     // and finally, DFLAGS 
    476     getenv_setargv("DFLAGS", &argc, &argv); 
    477      
    478     // and from the configuration file 
    479     if (masterConfig.find("") != masterConfig.end() && 
    480         masterConfig[""].find("flags") != masterConfig[""].end()) { 
    481         string_setargv(masterConfig[""]["flags"].c_str(), &argc, &argv); 
    482    
     457           full.append(compiler); 
     458 
     459           inifile((char*)full.c_str(), (char*)inif.c_str()); 
     460       
     461   
     462 
     463   // special configuration options needed here 
     464   if (masterConfig.find("") != masterConfig.end() && 
     465       masterConfig[""].find("objext") != masterConfig[""].end()) { 
     466       global.obj_ext = strdup(masterConfig[""]["objext"].c_str()); 
     467   
     468 
     469   // get any arguments from $REBUILD_FLAGS... 
     470   getenv_setargv("REBUILD_FLAGS", &argc, &argv); 
     471 
     472   // and from $BUILD_FLAGS 
     473   getenv_setargv("BUILD_FLAGS", &argc, &argv); 
     474 
     475   // and finally, DFLAGS 
     476   getenv_setargv("DFLAGS", &argc, &argv); 
     477 
     478   // and from the configuration file 
     479   if (masterConfig.find("") != masterConfig.end() && 
     480       masterConfig[""].find("flags") != masterConfig[""].end()) { 
     481       string_setargv(masterConfig[""]["flags"].c_str(), &argc, &argv); 
     482   
    483483 
    484484#if 0 
    485     for (i = 0; i < argc; i++) 
    486    
    487     printf("argv[%d] = '%s'\n", i, argv[i]); 
    488    
     485   for (i = 0; i < argc; i++) 
     486   
     487       printf("argv[%d] = '%s'\n", i, argv[i]); 
     488   
    489489#endif 
    490490 
    491     dupArgs(&argc, &argv); 
    492      
    493     for (i = 1; (rerun && i < 2) || (!rerun && i < argc); i++) 
    494     { 
    495     p = argv[i]; 
    496     if (*p == '-') 
     491    dupArgs(&argc, &argv); 
     492 
     493    for (i = 1; (rerun && i < 2) || (!rerun && i < argc); i++) 
    497494    { 
    498             if (strcmp(p + 1, "p") == 0) 
    499             { 
    500                 global.params.obj = 0; 
    501                 global.params.link = 0; 
    502                 addFlag(compileFlags, "compile", "o-", "-o-"); 
    503             } 
    504         else if (strcmp(p + 1, "c") == 0 || 
    505                      strcmp(p + 1, "obj") == 0 /* compat with build */) 
     495        p = argv[i]; 
     496        if (*p == '-') 
     497        { 
     498            if (strcmp(p + 1, "p") == 0) 
     499            { 
     500                global.params.obj = 0; 
     501                global.params.link = 0; 
     502                addFlag(compileFlags, "compile", "o-", "-o-"); 
     503            } 
     504            else if (strcmp(p + 1, "c") == 0 || 
     505                     strcmp(p + 1, "obj") == 0 /* compat with build */) 
     506                global.params.link = 0; 
     507            else if (strcmp(p + 1, "g") == 0) 
     508            { 
     509                addFlag(compileFlags, "compile", "debug", "-g"); 
     510                addFlag(linkFlags, "link", "debug", "-g"); 
     511                addFlag(liblinkFlags, "liblink", "debug", ""); 
     512                addFlag(shliblinkFlags, "shliblink", "debug", "-g"); 
     513            } 
     514            else if (strcmp(p + 1, "gc") == 0) 
     515            { 
     516                addFlag(compileFlags, "compile", "debugc", "-gc"); 
     517                addFlag(linkFlags, "link", "debugc", "-gc"); 
     518                addFlag(liblinkFlags, "liblink", "debugc", ""); 
     519                addFlag(shliblinkFlags, "shliblink", "debugc", "-gc"); 
     520            } 
     521            else if (strcmp(p + 1, "lib") == 0) 
     522            { 
     523                global.params.lib = 1; 
     524            } 
     525            else if (strcmp(p + 1, "shlib") == 0) 
     526            { 
     527                global.params.shlib = 1; 
     528            } 
     529            else if (strcmp(p + 1, "dylib") == 0) 
     530            { 
     531                global.params.dylib = 1; 
     532            } 
     533            else if (strcmp(p + 1, "link") == 0) /* compat with build */ 
     534            { 
     535                global.params.link = 1; 
     536                global.params.lib = 0; 
     537                global.params.shlib = 0; 
     538                global.params.dylib = 0; 
     539            } 
     540            else if (strcmp(p + 1, "nolib") == 0) /* compat with build */ 
     541            { 
     542                global.params.lib = 0; 
     543                global.params.shlib = 0; 
     544                global.params.dylib = 0; 
     545            } 
     546            else if (strcmp(p + 1, "nolink") == 0) /* compat with build */ 
     547                global.params.link = 0; 
     548            else if (strcmp(p + 1, "libs-safe") == 0) 
     549            { 
     550                if (masterConfig.find("liblink") == masterConfig.end() || 
     551                    masterConfig["liblink"].find("safe") == masterConfig["liblink"].end() || 
     552                    masterConfig["liblink"]["safe"] != "yes") { 
     553                    exit(1); 
     554                } else { 
     555                    exit(0); 
     556                } 
     557            } 
     558            else if (strcmp(p + 1, "shlib-support") == 0) 
     559            { 
     560                // just test for support 
     561                if (masterConfig.find("shliblink") == masterConfig.end() || 
     562                    masterConfig["shliblink"].find("shlibs") == masterConfig["shliblink"].end() || 
     563                    masterConfig["shliblink"]["shlibs"] != "yes") { 
     564                    exit(1); 
     565                } else { 
     566                    exit(0); 
     567                } 
     568            } 
     569            else if (strcmp(p + 1, "dylib-support") == 0) 
     570            { 
     571                // just test for support 
     572                if (masterConfig.find("dyliblink") == masterConfig.end() || 
     573                    masterConfig["dyliblink"].find("dylibs") == masterConfig["dyliblink"].end() || 
     574                    masterConfig["dyliblink"]["dylibs"] != "yes") { 
     575                    exit(1); 
     576                } else { 
     577                    exit(0); 
     578                } 
     579            } 
     580            else if (strcmp(p + 1, "files") == 0) 
     581            { 
     582                global.params.listfiles = 1; 
     583                global.params.obj = 0; 
     584                global.params.link = 0; 
     585            } 
     586            else if (strcmp(p + 1, "notfound") == 0) 
     587            { 
     588                global.params.listnffiles = 1; 
     589                global.params.obj = 0; 
     590                global.params.link = 0; 
     591            } 
     592            else if (strcmp(p + 1, "objfiles") == 0) 
     593            { 
     594                global.params.listobjfiles = 1; 
     595            } 
     596            else if (strcmp(p + 1, "keeprfiles") == 0) 
     597            { 
     598                global.params.keeprfiles = 1; 
     599            } 
     600            else if (strcmp(p + 1, "full") == 0) 
     601                global.params.fullbuild = 1; 
     602            else if (strcmp(p + 1, "explicit") == 0) 
     603                global.params.expbuild = 1; 
     604            else if (strcmp(p + 1, "v") == 0 || 
     605                     strcmp(p + 1, "V") == 0 || /* compat with build */ 
     606                     strcmp(p + 1, "names") == 0 /* also build */) 
     607            { 
     608                global.params.verbose = 1; 
     609                //addFlag(compileFlags, "compile", "verbose", "-v"); 
     610            } 
     611            else if (strcmp(p + 1, "n") == 0) { 
     612                global.params.listonly = 1; 
     613                global.params.fullbuild = 1; 
     614            } 
     615            else if (strcmp(p + 1, "w") == 0) 
     616                global.params.warnings = 1; 
     617            else if (strcmp(p + 1, "O") == 0) 
     618            { 
     619                global.params.optimize = 1; 
     620                addFlag(compileFlags, "compile", "optimize", "-O"); 
     621            } 
     622            else if (p[1] == 'o') 
     623            { 
     624                switch (p[2]) 
     625                { 
     626                case 'q': 
     627                    if (!p[3]) 
     628                        global.params.objdir = "."; 
     629                    else 
     630                        global.params.objdir = p + 3; 
     631                    global.params.fullqobjs = 1; 
     632                    break; 
     633 
     634                case 'd': 
     635                    if (!p[3]) 
     636                        goto Lnoarg; 
     637                    global.params.objdir = p + 3; 
     638                    global.params.fullqobjs = 0; 
     639                    break; 
     640 
     641                case 'f': 
     642                    if (!p[3]) 
     643                        goto Lnoarg; 
     644                    global.params.objname = p + 3; 
     645                    break; 
     646 
     647                case 'p': 
     648                    error("Rebuild does not support -op. Use -oq instead."); 
     649                    exit(1); 
     650                    /*if (p[3]) 
     651                      goto Lerror; 
     652                      global.params.preservePaths = 1; 
     653                      addFlag(compileFlags, "compile", "op", "-op"); */ 
     654                    break; 
     655 
     656                case '-': 
     657            &