Changeset 839

Show
Ignore:
Timestamp:
11/17/07 18:40:10 (10 months ago)
Author:
Jim Panic
Message:

Reverted indentation

Files:

Legend:

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

    r833 r839  
    5757Global::Global() 
    5858{ 
    59    mars_ext = "d"; 
    60    sym_ext  = "d"; 
    61    hdr_ext  = "di"; 
    62    doc_ext  = "html"; 
    63    ddoc_ext = "ddoc"; 
    64  
    65    obj_ext  = "o"; 
    66  
    67    copyright = "Copyright (c) 1999-2007 by Digital Mars and Gregor Richards,"; 
    68    written = "written by Walter Bright and Gregor Richards"; 
    69    version = "version 0.73 (based on DMD 2.003)"; 
    70    global.structalign = 8; 
    71    cmodules = NULL; 
    72  
    73    memset(&params, 0, sizeof(Param)); 
     59    mars_ext = "d"; 
     60    sym_ext  = "d"; 
     61    hdr_ext  = "di"; 
     62    doc_ext  = "html"; 
     63    ddoc_ext = "ddoc"; 
     64 
     65    obj_ext  = "o"; 
     66 
     67    copyright = "Copyright (c) 1999-2007 by Digital Mars and Gregor Richards,"; 
     68    written = "written by Walter Bright and Gregor Richards"; 
     69    version = "version 0.73 (based on DMD 2.003)"; 
     70    global.structalign = 8; 
     71    cmodules = NULL; 
     72 
     73    memset(&params, 0, sizeof(Param)); 
    7474} 
    7575 
    7676char *Loc::toChars() 
    7777{ 
    78    OutBuffer buf; 
    79    char *p; 
    80  
    81    if (filename) 
    82    
    83        buf.printf("%s", filename); 
    84    
    85  
    86    if (linnum) 
    87        buf.printf("(%d)", linnum); 
    88    buf.writeByte(0); 
    89    return (char *)buf.extractData(); 
     78    OutBuffer buf; 
     79    char *p; 
     80 
     81    if (filename) 
     82   
     83    buf.printf("%s", filename); 
     84   
     85 
     86    if (linnum) 
     87    buf.printf("(%d)", linnum); 
     88    buf.writeByte(0); 
     89    return (char *)buf.extractData(); 
    9090} 
    9191 
    9292Loc::Loc(Module *mod, unsigned linnum) 
    9393{ 
    94    this->linnum = linnum; 
    95    this->filename = mod ? mod->srcfile->toChars() : NULL; 
     94    this->linnum = linnum; 
     95    this->filename = mod ? mod->srcfile->toChars() : NULL; 
    9696} 
    9797 
     
    102102void error(Loc loc, const char *format, ...) 
    103103{ 
    104    va_list ap; 
    105    va_start(ap, format); 
    106    verror(loc, format, ap); 
    107    va_end( ap ); 
     104    va_list ap; 
     105    va_start(ap, format); 
     106    verror(loc, format, ap); 
     107    va_end( ap ); 
    108108} 
    109109 
    110110void verror(Loc loc, const char *format, va_list ap) 
    111111{ 
    112    if (!global.gag) 
    113    
    114        char *p = loc.toChars(); 
    115  
    116        if (*p) 
    117            fprintf(stdmsg, "%s: ", p); 
    118        mem.free(p); 
    119  
    120        fprintf(stdmsg, "Error: "); 
    121        vfprintf(stdmsg, format, ap); 
    122        fprintf(stdmsg, "\n"); 
    123        fflush(stdmsg); 
    124        //halt(); 
    125    
    126    global.errors++; 
     112    if (!global.gag) 
     113   
     114    char *p = loc.toChars(); 
     115 
     116    if (*p) 
     117        fprintf(stdmsg, "%s: ", p); 
     118    mem.free(p); 
     119 
     120    fprintf(stdmsg, "Error: "); 
     121    vfprintf(stdmsg, format, ap); 
     122    fprintf(stdmsg, "\n"); 
     123    fflush(stdmsg); 
     124//halt(); 
     125   
     126    global.errors++; 
    127127} 
    128128 
     
    135135{ 
    136136#if 0 
    137    halt(); 
     137    halt(); 
    138138#endif 
    139    exit(EXIT_FAILURE); 
     139    exit(EXIT_FAILURE); 
    140140} 
    141141 
     
    147147{ 
    148148#ifdef DEBUG 
    149    *(char*)0=0; 
     149    *(char*)0=0; 
    150150#endif 
    151151} 
    152152 
    153153/*extern void backend_init(); 
    154   extern void backend_term();*/ 
     154extern void backend_term();*/ 
    155155 
    156156void usage() 
    157157{ 
    158    printf("ReBuild %s\n%s %s\n", 
    159           global.version, global.copyright, global.written); 
    160    printf("\ 
    161           Documentation: http://www.digitalmars.com/d/index.html\n\ 
    162           Usage:\n\ 
    163           rebuild files.d ... { -switch }\n\ 
    164           \n\ 
    165           files.d        D source files\n\ 
    166           -rf<filename>  Use specified response file\n\ 
    167           -dc=<compiler> use the specified compiler configuration\n\ 
    168           -p             do not compile (or link)\n\ 
    169           -c             do not link\n\ 
    170           -D             generate documentation\n\ 
    171           -Dddocdir      write documentation files to docdir directory\n\ 
    172           -Dffilename    write documentation file to filename\n\ 
    173           -Dqdocdir      write documentation files to docdir directory with\n\ 
    174           fully-qualified file names\n\ 
    175           -lib           link a static library\n\ 
    176           -libs-safe     exit failure or success for whether libraries can be safely\n\ 
    177           be used with any D code\n\ 
    178           -shlib         link a shared library\n\ 
    179           -shlib-support exit failure or success for whether shared libraries are\n\ 
    180           supported\n\ 
    181           -dylib         link a dynamic library (a library intended to be loaded at\n\ 
    182                                                  runtime)\n\ 
    183           -dylib-support exit failure or success for whether dynamic libraries are\n\ 
    184           supported\n\ 
    185           -g             add symbolic debug info\n\ 
    186           -gc            add symbolic debug info, pretend to be C\n\ 
    187           -files         list files which would be compiled (but don't compile)\n\ 
    188           -notfound      list files which are imported, but do not exist (and don't\n\ 
    189                                                                           compile)\n\ 
    190           -objfiles      list object files generated\n\ 
    191           -keeprfiles    Keep response files (if they are used)\n\ 
    192           -full          compile all source files, regardless of their age\n\ 
    193           -explicit      only compile files explicitly named, not dependencies\n\ 
    194           --help         print help\n\ 
    195           -Ipath         where to look for imports\n\ 
    196           -Ccompileflag  pass compileflag to compilation\n\ 
    197           -Llinkerflag   pass linkerflag to the linker at link time\n\ 
    198           -Klinkerflag   pass linkerflag to the compiler at link time\n\ 
    199           -ll<lib>       link in the specified library\n\ 
    200           Windows: Link to <lib>.lib\n\ 
    201           Posix: Link to lib<lib>.{a,so}\n\ 
    202           -Spath         search path for libraries\n\ 
    203           -O             optimize\n\ 
    204           -oqobjdir      write object files to directory objdir with fully-qualified\n\ 
    205           module names\n\ 
    206           -odobjdir      write object files to directory objdir\n\ 
    207           -offilename  name output file to filename\n\ 
    208           -quiet         suppress unnecessary messages\n\ 
    209           -release     compile release version\n\ 
    210           -exec          run resulting program\n\ 
    211           -v             verbose\n\ 
    212           -n             just list the commands to be run, don't run them\n\ 
    213           -version=level compile in version code >= level\n\ 
    214           -version=ident compile in version code identified by ident\n\ 
    215           -debug         compile in debug code\n\ 
    216           -debug=level   compile in debug code <= level\n\ 
    217           -debug=ident   compile in debug code identified by ident\n\ 
    218           -clean         remove object files after done building\n\ 
    219           -no-export-dynamic do not export dynamic symbols. Dynamic symbols are\n\ 
    220           exported by default on POSIX to support .so files\n\ 
    221           -circular      allow circular dependencies to work on some compilers (namely\n\ 
    222                                                                                 GDC) \n\ 
    223           -testversion=<version>\n\ 
    224           exit failure or success for whether the specified version is\n\ 
    225           defined\n\ 
    226           -reflect       use drefgen to make rodin-compatible reflections of all\n\ 
    227           included modules\n\ 
    228           -candydoc      generate the modules.ddoc file for candydoc (must specify -Dq)\n\ 
    229           All other flags are passed to the compiler.\n\ 
    230           "); 
     158    printf("ReBuild %s\n%s %s\n", 
     159    global.version, global.copyright, global.written); 
     160    printf("\ 
     161Documentation: http://www.digitalmars.com/d/index.html\n\ 
     162Usage:\n\ 
     163  rebuild files.d ... { -switch }\n\ 
     164\n\ 
     165  files.d        D source files\n\ 
     166  -rf<filename>  Use specified response file\n\ 
     167  -dc=<compiler> use the specified compiler configuration\n\ 
     168  -p             do not compile (or link)\n\ 
     169  -c             do not link\n\ 
     170  -D             generate documentation\n\ 
     171  -Dddocdir      write documentation files to docdir directory\n\ 
     172  -Dffilename    write documentation file to filename\n\ 
     173  -Dqdocdir      write documentation files to docdir directory with\n\ 
     174                 fully-qualified file names\n\ 
     175  -lib           link a static library\n\ 
     176  -libs-safe     exit failure or success for whether libraries can be safely\n\ 
     177                 be used with any D code\n\ 
     178  -shlib         link a shared library\n\ 
     179  -shlib-support exit failure or success for whether shared libraries are\n\ 
     180                 supported\n\ 
     181  -dylib         link a dynamic library (a library intended to be loaded at\n\ 
     182                 runtime)\n\ 
     183  -dylib-support exit failure or success for whether dynamic libraries are\n\ 
     184                 supported\n\ 
     185  -g             add symbolic debug info\n\ 
     186  -gc            add symbolic debug info, pretend to be C\n\ 
     187  -files         list files which would be compiled (but don't compile)\n\ 
     188  -notfound      list files which are imported, but do not exist (and don't\n\ 
     189                 compile)\n\ 
     190  -objfiles      list object files generated\n\ 
     191  -keeprfiles    Keep response files (if they are used)\n\ 
     192  -full          compile all source files, regardless of their age\n\ 
     193  -explicit      only compile files explicitly named, not dependencies\n\ 
     194  --help         print help\n\ 
     195  -Ipath         where to look for imports\n\ 
     196  -Ccompileflag  pass compileflag to compilation\n\ 
     197  -Llinkerflag   pass linkerflag to the linker at link time\n\ 
     198  -Klinkerflag   pass linkerflag to the compiler at link time\n\ 
     199  -ll<lib>       link in the specified library\n\ 
     200                 Windows: Link to <lib>.lib\n\ 
     201                 Posix: Link to lib<lib>.{a,so}\n\ 
     202  -Spath         search path for libraries\n\ 
     203  -O             optimize\n\ 
     204  -oqobjdir      write object files to directory objdir with fully-qualified\n\ 
     205                 module names\n\ 
     206  -odobjdir      write object files to directory objdir\n\ 
     207  -offilename  name output file to filename\n\ 
     208  -quiet         suppress unnecessary messages\n\ 
     209  -release     compile release version\n\ 
     210  -exec          run resulting program\n\ 
     211  -v             verbose\n\ 
     212  -n             just list the commands to be run, don't run them\n\ 
     213  -version=level compile in version code >= level\n\ 
     214  -version=ident compile in version code identified by ident\n\ 
     215  -debug         compile in debug code\n\ 
     216  -debug=level   compile in debug code <= level\n\ 
     217  -debug=ident   compile in debug code identified by ident\n\ 
     218  -clean         remove object files after done building\n\ 
     219  -no-export-dynamic do not export dynamic symbols. Dynamic symbols are\n\ 
     220                 exported by default on POSIX to support .so files\n\ 
     221  -circular      allow circular dependencies to work on some compilers (namely\n\ 
     222                GDC) \n\ 
     223  -testversion=<version>\n\ 
     224                 exit failure or success for whether the specified version is\n\ 
     225                 defined\n\ 
     226  -reflect       use drefgen to make rodin-compatible reflections of all\n\ 
     227                 included modules\n\ 
     228  -candydoc      generate the modules.ddoc file for candydoc (must specify -Dq)\n\ 
     229  All other flags are passed to the compiler.\n\ 
     230"); 
    231231} 
    232232 
    233233bool stringInArray(Array *arr, char *str) 
    234234{ 
    235    for (unsigned int i = 0; i < arr->dim; i++) { 
    236        if (!stricmp((char *) arr->data[i], str)) return true; 
    237    
    238    return false; 
     235    for (unsigned int i = 0; i < arr->dim; i++) { 
     236        if (!stricmp((char *) arr->data[i], str)) return true; 
     237   
     238    return false; 
    239239} 
    240240 
    241241int main(int argc, char *argv[]) 
    242242{ 
    243     int i; 
    244     Array files; 
    245     char *p; 
    246     Module *m; 
    247     int status = EXIT_SUCCESS; 
    248     int argcstart = argc; 
    249  
    250     // Check for malformed input 
    251     if (argc < 1 || !argv) 
     243    int i; 
     244    Array files; 
     245    char *p; 
     246    Module *m; 
     247    int status = EXIT_SUCCESS; 
     248    int argcstart = argc; 
     249 
     250    // Check for malformed input 
     251    if (argc < 1 || !argv) 
     252    { 
     253      Largs: 
     254    error("missing or null command line arguments"); 
     255    fatal(); 
     256    } 
     257    for (i = 0; i < argc; i++) 
     258    { 
     259    if (!argv[i]) 
     260        goto Largs; 
     261    } 
     262 
     263    files.reserve(argc - 1); 
     264 
     265    // Set default values 
     266    global.params.argv0 = argv[0]; 
     267    global.params.link = 1; 
     268    global.params.lib = 0; 
     269    global.params.shlib = 0; 
     270    global.params.dylib = 0; 
     271    global.params.fullbuild = 0; 
     272    global.params.expbuild = 0; 
     273    global.params.listfiles = 0; 
     274    global.params.listnffiles = 0; 
     275    global.params.listobjfiles = 0; 
     276    global.params.keeprfiles = 0; 
     277    global.params.fullqobjs = 1; 
     278    global.params.fullqdocs = 0; 
     279    global.params.clean = 0; 
     280    global.params.oneatatime = 0; 
     281    global.params.reflect = 0; 
     282    global.params.candydoc = 0; 
     283    global.params.objdir = "."; 
     284    global.params.useAssert = 1; 
     285    global.params.useInvariants = 1; 
     286    global.params.useIn = 1; 
     287    global.params.useOut = 1; 
     288    global.params.useArrayBounds = 1; 
     289    global.params.useSwitchError = 1; 
     290    global.params.useInline = 0; 
     291    global.params.obj = 1; 
     292    global.params.exportDynamic = 1; 
     293    global.params.Dversion = 2; 
     294    global.params.listonly = 0; 
     295    global.params.run = 0; 
     296     
     297    // set true if we're running as rerun 
     298    bool rerun = false; 
     299 
     300    global.params.linkswitches = new Array(); 
     301    global.params.libfiles = new Array(); 
     302    global.params.objfiles = new Array(); 
     303    global.params.genobjfiles = new Array(); 
     304    global.params.ddocfiles = new Array(); 
     305     
     306    // Check for being run as rdmd, rgdmd or rerun 
     307    char *binname = FileName::name(argv[0]); 
     308    if (strncmp(binname, "rerun", 5) == 0 || 
     309        strncmp(binname, "rdmd",  4) == 0 || 
     310        strncmp(binname, "rgdmd", 5) == 0) { 
     311        // first argument is the source, then args for the program 
     312        if (argc < 2) { 
     313            error("No D source file provided."); 
     314            exit(1); 
     315        } 
     316         
     317        global.params.run = 1; 
     318        global.params.runargs = &argv[2]; 
     319        global.params.runargs_length = argc - 2; 
     320        rerun = true; 
     321    } 
     322 
     323    // Predefine version identifiers 
     324    VersionCondition::addPredefinedGlobalIdent("build"); 
     325    VersionCondition::addPredefinedGlobalIdent("rebuild"); 
     326    VersionCondition::addPredefinedGlobalIdent("all"); 
     327     
     328    // BEFORE reading configuration, check for a specified profile 
     329    char *chooseProfile = "default"; 
     330     
     331    // first in the environment 
     332    char *envProfile = getenv("REBUILDPROFILE"); 
     333    if (envProfile) chooseProfile = envProfile; 
     334     
     335    // then in args 
     336    for (i = 1; !global.params.run && i < argc; i++) 
     337    { 
     338        p = argv[i]; 
     339        if (!strncmp(p, "-dc=", 4)) { 
     340            chooseProfile = p + 4; 
     341            break; 
     342        } 
     343        else if (strncmp(p, "-rf", 3) == 0) 
     344        { 
     345            // figure out the rf name 
     346            char *rf = p + 3; 
     347            if (!rf[0]) { 
     348                i++; 
     349                if (i >= argc) { 
     350                    i--; 
     351                    goto Lnoarg; 
     352                } 
     353                rf = argv[i]; 
     354            } 
     355             
     356            parseResponseFile(&argc, &argv, rf, i); 
     357        } 
     358    } 
     359     
     360    readConfig(argv[0], chooseProfile, (chooseProfile == "default")); 
     361     
     362    // if the configuration includes path=, add that path 
     363    if (masterConfig.find("") != masterConfig.end() && 
     364        masterConfig[""].find("path") != masterConfig[""].end()) { 
     365        std::string newPath = masterConfig[""]["path"]; 
     366         
     367#ifdef __WIN32 
     368        newPath += ";"; 
     369#else 
     370        newPath += ":"; 
     371#endif 
     372         
     373        newPath += getenv("PATH"); 
     374        char *snewPath = mem.strdup(newPath.c_str()); 
     375#ifdef __WIN32 
     376        SetEnvironmentVariable("PATH", snewPath); 
     377#else 
     378        setenv("PATH", snewPath, 1); 
     379#endif 
     380    } 
     381     
     382    /* include <prefix>/include/d always, so that DSSS-installed things are 
     383     * usable with pure rebuild */ 
     384    char *argdir, *argfil; 
     385    if (whereAmI(argv[0], &argdir, &argfil)) { 
     386        char *fulldir = FileName::combine( 
     387            argdir, ".." DIRSEP "include" DIRSEP "d"); 
     388         
     389        if (!global.params.imppath) 
     390            global.params.imppath = new Array(); 
     391        global.params.imppath->push(fulldir); 
     392        addFlag(compileFlags, "compile", "incdir", "-I$i", fulldir); 
     393    } 
     394     
     395    // get include paths 
     396    if (masterConfig.find("") != masterConfig.end() && 
     397        masterConfig[""].find("compiler") != masterConfig[""].end()) { 
     398        std::string compiler = masterConfig[""]["compiler"]; 
     399         
     400        if (compiler.substr(compiler.length() - 3) == "gdc") { 
     401            // a bit more complicated 
     402#define READBUFSIZ 1024 
     403            char readBuf[READBUFSIZ + 1]; 
     404            readBuf[READBUFSIZ] = '\0'; 
     405            int nloc; 
     406             
     407            // 1) read version 
     408            if (readCommand(compiler + " -dumpversion", readBuf, READBUFSIZ) < 1) { 
     409                error("Failed to detect GDC version"); 
     410            } 
     411            std::string cversion = readBuf; 
     412            nloc = cversion.find('\n', 0); 
     413            if (nloc != std::string::npos) cversion = cversion.substr(0, nloc); 
     414             
     415            // 2) read machine 
     416            if (readCommand(compiler + " -dumpmachine", readBuf, READBUFSIZ) < 1) { 
     417                error("Failed to detect GDC target"); 
     418            } 
     419            std::string cmachine = readBuf; 
     420            nloc = cmachine.find('\n', 0); 
     421            if (nloc != std::string::npos) cmachine = cmachine.substr(0, nloc); 
     422             
     423            // 3) get the prefix 
     424            char *gdcdir, *gdcfil; 
     425            if (!whereAmI(compiler.c_str(), &gdcdir, &gdcfil)) { 
     426                error("%s is not in $PATH", compiler.c_str()); 
     427                exit(1); 
     428            } 
     429             
     430            // 4) make include paths 
     431            if (!global.params.imppath) 
     432                global.params.imppath = new Array(); 
     433            global.params.imppath->push(strdup( 
     434                (std::string(gdcdir) + "/../include/d/" + cversion + "/").c_str())); 
     435            global.params.imppath->push(strdup( 
     436                (std::string(gdcdir) + "/../include/d/" + cversion + "/" + cmachine + "/").c_str())); 
     437            global.params.imppath->push(strdup( 
     438                (std::string(gdcdir) + "/../" + cmachine + "/include/d/" + cversion + "/").c_str())); 
     439            global.params.imppath->push(strdup( 
     440                (std::string(gdcdir) + "/../" + cmachine + "/include/d/" + cversion + "/" + cmachine + "/").c_str())); 
     441        } 
     442        // assume dmd based compiler if inifile is set 
     443        else if (masterConfig[""].find("inifile") != masterConfig[""].end()) { 
     444            std::string inif = masterConfig[""]["inifile"]; 
     445 
     446            // trick whereami into giving us a path 
     447            char *dir, *fil; 
     448            if (!whereAmI(compiler.c_str(), &dir, &fil)) { 
     449                error("%s is not in $PATH", compiler.c_str()); 
     450                exit(1); 
     451            } 
     452            std::string full = dir; 
     453#if __WIN32 
     454            full.append("\\"); 
     455#else 
     456            full.append("/"); 
     457#endif 
     458            full.append(compiler); 
     459 
     460            inifile((char*)full.c_str(), (char*)inif.c_str()); 
     461        } 
     462    } 
     463     
     464    // special configuration options needed here 
     465    if (masterConfig.find("") != masterConfig.end() && 
     466        masterConfig[""].find("objext") != masterConfig[""].end()) { 
     467        global.obj_ext = strdup(masterConfig[""]["objext"].c_str()); 
     468    } 
     469     
     470    // get any arguments from $REBUILD_FLAGS... 
     471    getenv_setargv("REBUILD_FLAGS", &argc, &argv); 
     472     
     473    // and from $BUILD_FLAGS 
     474    getenv_setargv("BUILD_FLAGS", &argc, &argv); 
     475     
     476    // and finally, DFLAGS 
     477    getenv_setargv("DFLAGS", &argc, &argv); 
     478     
     479    // and from the configuration file 
     480    if (masterConfig.find("") != masterConfig.end() && 
     481        masterConfig[""].find("flags") != masterConfig[""].end()) { 
     482        string_setargv(masterConfig[""]["flags"].c_str(), &argc, &argv); 
     483    } 
     484 
     485#if 0 
     486    for (i = 0; i < argc; i++) 
     487    { 
     488    printf("argv[%d] = '%s'\n", i, argv[i]); 
     489    } 
     490#endif 
     491 
     492    dupArgs(&argc, &argv); 
     493     
     494    for (i = 1; (rerun && i < 2) || (!rerun && i < argc); i++) 
     495    { 
     496    p = argv[i]; 
     497    if (*p == '-') 
    252498    { 
    253 Largs: 
    254         error("missing or null command line arguments"); 
     499            if (strcmp(p + 1, "p") == 0) 
     500            { 
     501                global.params.obj = 0; 
     502                global.params.link = 0; 
     503                addFlag(compileFlags, "compile", "o-", "-o-"); 
     504            } 
     505        else if (strcmp(p + 1, "c") == 0 || 
     506                     strcmp(p + 1, "obj") == 0 /* compat with build */) 
     507        global.params.link = 0; 
     508            else if (strcmp(p + 1, "g") == 0) 
     509            { 
     510                addFlag(compileFlags, "compile", "debug", "-g"); 
     511                addFlag(linkFlags, "link", "debug", "-g"); 
     512                addFlag(liblinkFlags, "liblink", "debug", ""); 
     513                addFlag(shliblinkFlags, "shliblink", "debug", "-g"); 
     514            } 
     515            else if (strcmp(p + 1, "gc") == 0) 
     516            { 
     517                addFlag(compileFlags, "compile", "debugc", "-gc"); 
     518                addFlag(linkFlags, "link", "debugc", "-gc"); 
     519                addFlag(liblinkFlags, "liblink", "debugc", ""); 
     520                addFlag(shliblinkFlags, "shliblink", "debugc", "-gc"); 
     521            } 
     522            else if (strcmp(p + 1, "lib") == 0) 
     523            { 
     524                global.params.lib = 1; 
     525            } 
     526            else if (strcmp(p + 1, "shlib") == 0) 
     527            { 
     528                global.params.shlib = 1; 
     529            } 
     530            else if (strcmp(p + 1, "dylib") == 0) 
     531            { 
     532                global.params.dylib = 1; 
     533            } 
     534            else if (strcmp(p + 1, "link") == 0) /* compat with build */ 
     535            { 
     536                global.params.link = 1; 
     537                global.params.lib = 0; 
     538                global.params.shlib = 0; 
     539                global.params.dylib = 0; 
     540            } 
     541            else if (strcmp(p + 1, "nolib") == 0) /* compat with build */ 
     542            { 
     543                global.params.lib = 0; 
     544                global.params.shlib = 0; 
     545                global.params.dylib = 0; 
     546            } 
     547            else if (strcmp(p + 1, "nolink") == 0) /* compat with build */ 
     548                global.params.link = 0; 
     549            else if (strcmp(p + 1, "libs-safe") == 0) 
     550            { 
     551                if (masterConfig.find("liblink") == masterConfig.end() || 
     552                    masterConfig["liblink"].find("safe") == masterConfig["liblink"].end() || 
     553                    masterConfig["liblink"]["safe"] != "yes") { 
     554                    exit(1); 
     555                } else { 
     556                    exit(0); 
     557                } 
     558            } 
     559            else if (strcmp(p + 1, "shlib-support") == 0) 
     560            { 
     561                // just test for support 
     562                if (masterConfig.find("shliblink") == masterConfig.end() || 
     563                    masterConfig["shliblink"].find("shlibs") == masterConfig["shliblink"].end() || 
     564                    masterConfig["shliblink"]["shlibs"] != "yes") { 
     565                    exit(1); 
     566                } else { 
     567                    exit(0); 
     568                } 
     569            } 
     570            else if (strcmp(p + 1, "dylib-support") == 0) 
     571            { 
     572                // just test for support 
     573                if (masterConfig.find("dyliblink") == masterConfig.end() || 
     574                    masterConfig["dyliblink"].find("dylibs") == masterConfig["dyliblink"].end() || 
     575                    masterConfig["dyliblink"]["dylibs"] != "yes") { 
     576                    exit(1); 
     577                } else { 
     578                    exit(0); 
     579                } 
     580            } 
     581            else if (strcmp(p + 1, "files") == 0) 
     582            { 
     583                global.params.listfiles = 1; 
     584                global.params.obj = 0; 
     585                global.params.link = 0; 
     586            } 
     587            else if (strcmp(p + 1, "notfound") == 0) 
     588            { 
     589                global.params.listnffiles = 1; 
     590                global.params.obj = 0; 
     591                global.params.link = 0; 
     592            } 
     593            else if (strcmp(p + 1, "objfiles") == 0) 
     594            { 
     595                global.params.listobjfiles = 1; 
     596            } 
     597            else if (strcmp(p + 1, "keeprfiles") == 0) 
     598            { 
     599                global.params.keeprfiles = 1; 
     600            } 
     601            else if (strcmp(p + 1, "full") == 0) 
     602                global.params.fullbuild = 1; 
     603            else if (strcmp(p + 1, "explicit") == 0) 
     604                global.params.expbuild = 1; 
     605        else if (strcmp(p + 1, "v") == 0 || 
     606                     strcmp(p + 1, "V") == 0 || /* compat with build */ 
     607                     strcmp(p + 1, "names") == 0 /* also build */) 
     608            { 
     609        global.params.verbose = 1; 
     610                //addFlag(compileFlags, "compile", "verbose", "-v"); 
     611            } 
     612            else if (strcmp(p + 1, "n") == 0) { 
     613                global.params.listonly = 1; 
     614                global.params.fullbuild = 1; 
     615            } 
     616        else if (strcmp(p + 1, "w") == 0) 
     617        global.params.warnings = 1; 
     618        else if (strcmp(p + 1, "O") == 0) 
     619            { 
     620        global.params.optimize = 1; 
     621                addFlag(compileFlags, "compile", "optimize", "-O"); 
     622            } 
     623        else if (p[1] == 'o') 
     624        { 
     625        switch (p[2]) 
     626        { 
     627                    case 'q': 
     628                        if (!p[3]) 
     629                            global.params.objdir = "."; 
     630                        else 
     631                            global.params.objdir = p + 3; 
     632                        global.params.fullqobjs = 1; 
     633                        break; 
     634                     
     635            case 'd': 
     636            if (!p[3]) 
     637                goto Lnoarg; 
     638            global.params.objdir = p + 3; 
     639                        global.params.fullqobjs = 0; 
     640            break; 
     641 
     642            case 'f': 
     643            if (!p[3]) 
     644                goto Lnoarg; 
     645            global.params.objname = p + 3; 
     646            break; 
     647 
     648            case 'p': 
     649                        error("Rebuild does not support -op. Use -oq instead."); 
     650                        exit(1); 
     651            /*if (p[3]) 
     652                goto Lerror; 
     653            global.params.preservePaths = 1; 
     654                        addFlag(compileFlags, "compile", "op", "-op"); */ 
     655            break; 
     656                         
     657                    case '-': 
     658                        // like -p 
     659                        global.params.obj = 0; 
     660                        global.params.link = 0; 
     661                        addFlag(compileFlags, "compile", "o-", "-o-"); 
     662                        break; 
     663                         
     664            case 0: 
     665            error("-o no longer supported, use -of or -od"); 
     666            break; 
     667 
     668            default: 
     669            goto Lerror; 
     670        } 
     671        } 
     672            else if (p[1] == 'D') 
     673            { 
     674                /* this is passed through, but we keep one piece of information 
     675                 * we may need */ 
     676                 
     677                if (p[2] == 'd') { 
     678                    // yes, it's a documentation directory. Needed for -candydoc 
     679                    global.params.docdir = p + 3; 
     680                    compileFlags += " "; 
     681                    compileFlags += p; 
     682                     
     683                } else if (p[2] == 'q') { 
     684                    // a doc dir, and fullqdocs 
     685                    global.params.docdir = p + 3; 
     686                    global.params.fullqdocs = 1; 
     687                    compileFlags += " "; 
     688                    p[2] = 'd'; 
     689                    compileFlags += p; 
     690                     
     691                } else { 
     692                    compileFlags += " "; 
     693                    compileFlags += p; 
     694                } 
     695            } 
     696        else if (strcmp(p + 1, "quiet") == 0) 
     697            { 
     698        global.params.quiet = 1; 
     699                addFlag(compileFlags, "compile", "quiet", "-quiet"); 
     700            } 
     701        else if (strcmp(p + 1, "release") == 0) 
     702            { 
     703        global.params.release = 1; 
     704                addFlag(compileFlags, "compile", "release", "-release"); 
     705            } 
     706        else if (p[1] == 'I') 
     707        { 
     708        if (!global.params.imppath) 
     709            global.params.imppath = new Array(); 
     710        global.params.imppath->push(p + 2); 
     711                 
     712                addFlag(compileFlags, "compile", "incdir", "-I$i", p + 2); 
     713        } 
     714        else if (p[1] == 'J') 
     715        { 
     716                global.params.fullbuild = 1; 
     717                 
     718                addFlag(compileFlags, "compile", "importdir", "-J$i", p + 2); 
     719        } 
     720        else if (memcmp(p + 1, "version", 5) == 0) 
     721        { 
     722        // Parse: 
     723        //  -version=number 
     724        //  -version=identifier 
     725        if (p[8] == '=') 
     726        { 
     727                    addFlag(compileFlags, "compile", "version", "-version=$i", p + 9); 
     728                     
     729            if (isdigit(p[9])) 
     730            {   long level; 
     731 
     732            errno = 0; 
     733            level = strtol(p + 9, &p, 10); 
     734            if (*p || errno || level > INT_MAX) 
     735                goto Lerror; 
     736            VersionCondition::setGlobalLevel((int)level); 
     737            } 
     738            else if (Lexer::isValidIdentifier(p + 9)) 
     739            VersionCondition::addGlobalIdent(p + 9); 
     740            else 
     741            goto Lerror; 
     742        } 
     743        else 
     744            goto Lerror; 
     745        } 
     746            else if (memcmp(p + 1, "debuglib", 8) == 0) 
     747            { 
     748                if (p[9] == '=') { 
     749                    goto Lpassthrough; 
     750                } else { 
     751                    goto Lerror; 
     752                } 
     753            } 
     754        else if (memcmp(p + 1, "debug", 5) == 0) 
     755        { 
     756        // Parse: 
     757        //  -debug 
     758        //  -debug=number 
     759        //  -debug=identifier 
     760        if (p[6] == '=') 
     761        { 
     762                    addFlag(compileFlags, "compile", "setdebug", "-debug=$i", p + 7); 
     763                     
     764            if (isdigit(p[7])) 
     765            {   long level; 
     766 
     767            errno = 0; 
     768            level = strtol(p + 7, &p, 10); 
     769            if (*p || errno || level > INT_MAX) 
     770                goto Lerror; 
     771            DebugCondition::setGlobalLevel((int)level); 
     772            } 
     773            else if (Lexer::isValidIdentifier(p + 7)) 
     774            DebugCondition::addGlobalIdent(p + 7); 
     775            else 
     776            goto Lerror; 
     777        } 
     778        else if (p[6]) 
     779            goto Lerror; 
     780        else 
     781                { 
     782                    addFlag(compileFlags, "compile", "debug", "-debug"); 
     783                     
     784            global.params.debuglevel = 1; 
     785                } 
     786            } 
     787            else if (strcmp(p + 1, "clean") == 0 || 
     788                     strcmp(p + 1, "cleanup") == 0) 
     789                global.params.clean = 1; 
     790        else if (strcmp(p + 1, "-help") == 0) 
     791        {   usage(); 
     792        exit(EXIT_SUCCESS); 
     793        } 
     794        else if (p[1] == 'L') 
     795        { 
     796                addFlag(linkFlags, "link", "flag", "-L$i", p + 2); 
     797                addFlag(liblinkFlags, "liblink", "flag", "-L$i", p + 2); 
     798                addFlag(shliblinkFlags, "shliblink", "flag", "-L$i", p + 2); 
     799        } 
     800            else if (p[1] == 'K') 
     801            { 
     802                addFlag(linkFlags, "link", "cflag", "$i", p + 2); 
     803                addFlag(liblinkFlags, "link", "cflag", "$i", p + 2); 
     804                addFlag(shliblinkFlags, "link", "cflag", "$i", p + 2); 
     805            } 
     806            else if (strcmp(p + 1, "arch") == 0 || 
     807                     strcmp(p + 1, "isysroot") == 0 || 
     808                     strcmp(p + 1, "framework") == 0) 
     809            { 
     810                // special flags for Mac OS X 
     811                addFlag(compileFlags, "compile", "forceflag", "$i", p); 
     812                addFlag(linkFlags, "link", "forceflag", "$i", p); 
     813                addFlag(shliblinkFlags, "shliblink", "forceflag", "$i", p); 
     814                 
     815                i++; 
     816                if (i >= argc) 
     817                    goto Lnoarg; 
     818                p = argv[i]; 
     819                 
     820                addFlag(compileFlags, "compile", "forceflag", "$i", p); 
     821                addFlag(linkFlags, "link", "forceflag", "$i", p); 
     822                addFlag(shliblinkFlags, "shliblink", "forceflag", "$i", p); 
     823            } 
     824            else if (strcmp(p + 1, "gui") == 0) 
     825            { 
     826                // for Windows, activate GUI mode 
     827                addFlag(linkFlags, "link", "gui", ""); 
     828            } 
     829            else if (strncmp(p + 1, "ll", 2) == 0) 
     830            { 
     831                if (!p[3]) 
     832                    goto Lnoarg; 
     833                linkLibrary(p + 3); 
     834            } 
     835            else if (p[1] == 'C') 
     836            { 
     837                addFlag(compileFlags, "compile", "flag", "$i", p + 2); 
     838            } 
     839            else if (p[1] == 'S') 
     840            { 
     841                // add a flag both to compile and to link 
     842                addFlag(compileFlags, "compile", "libdir", "-L-L$i", p + 2); 
     843 
     844                addFlag(linkFlags, "link", "libdir", "-L-L$i", p + 2); 
     845                addFlag(liblinkFlags, "liblink", "libdir", "-L-L$i", p + 2); 
     846                addFlag(shliblinkFlags, "shliblink", "libdir", "-L-L$i", p + 2); 
     847            } 
     848        else if (strcmp(p + 1, "exec") == 0) 
     849            { 
     850                global.params.run = 1; 
     851        global.params.runargs_length = ((i >= argcstart) ? argc : argcstart) - i - 1; 
     852        if (global.params.runargs_length) 
     853        { 
     854            files.push(argv[i + 1]); 
     855            global.params.runargs = &argv[i + 2]; 
     856            i += global.params.runargs_length; 
     857            global.params.runargs_length--; 
     858        } 
     859        else 
     860        {   global.params.run = 0; 
     861            goto Lnoarg; 
     862        } 
     863        } 
     864            else if (strcmp(p + 1, "circular") == 0) 
     865            { 
     866                addFlag(compileFlags, "compile", "circular", ""); 
     867            } 
     868            else if (strcmp(p + 1, "no-export-dynamic") == 0) 
     869            { 
     870                global.params.exportDynamic = 0; 
     871            } 
     872            else if (strncmp(p + 1, "testversion=", 12) == 0) 
     873            { 
     874                if (!global.params.versionids) exit(1); 
     875                 
     876                if (findCondition(global.params.versionids, 
     877                                  new Identifier(p + 13, 0))) exit(0); 
     878                exit(1); 
     879            } 
     880            else if (strcmp(p + 1, "reflect") == 0) 
     881            { 
     882                global.params.reflect = 1; 
     883            } 
     884            else if (strcmp(p + 1, "candydoc") == 0) 
     885            { 
     886                global.params.candydoc = 1; 
     887            } 
     888            else if (strncmp(p + 1, "dc=", 3) == 0) {} 
     889            else if (strncmp(p + 1, "CFPATH", 6) == 0 || 
     890                     strncmp(p + 1, "BCFPATH", 7) == 0 || 
     891                     strcmp(p + 1, "allobj") == 0 || 
     892                     strncmp(p + 1, "LIBOPT", 6) == 0 || 
     893                     strncmp(p + 1, "SHLIBOPT", 8) == 0 || 
     894                     strncmp(p + 1, "LIBPATH", 7) == 0 || 
     895                     strcmp(p + 1, "test") == 0 || 
     896             strncmp(p + 1, "rf", 2) == 0) {} /* compat with build */ 
     897        else 
     898        { 
     899             Lpassthrough: 
     900                compileFlags += " "; 
     901                compileFlags += p; 
     902                continue; 
     903                 
     904         Lerror: 
     905        error("unrecognized switch '%s'", argv[i]); 
     906        continue; 
     907 
     908         Lnoarg: 
     909        error("argument expected for switch '%s'", argv[i]); 
     910        continue; 
     911        } 
     912    } 
     913    else 
     914        files.push(p); 
     915    } 
     916    if (global.errors) 
     917    {