Changeset 137

Show
Ignore:
Timestamp:
05/02/06 14:03:27 (2 years ago)
Author:
aldacron
Message:

* added support for debug and release builda via command line args to buildme.d and commented the whole module

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/buildme.d

    r136 r137  
    1010} 
    1111 
    12 private static const char[] forBuild = "forbuild.txt"; 
    13 private static const char[] configTxt = "build_debug.txt"; 
    14 private static const char[] commonTxt = "build_common.txt"; 
    15 private static const char[] tempBrf = "temp.brf"; 
    16  
    17 version(Windows) 
    18 
    19     private static const char[] delCmd = "del "; 
    20 
    21 else version(linux) 
    22 
    23     private static const char[] delCmd = "rm -f "; 
    24 
    25 else 
    26 
    27     static assert(0); 
    28 
    29  
     12// build configurations 
    3013enum Mode 
    3114{ 
     
    3417} 
    3518 
     19// name of the text file found in each package directory 
     20private static const char[] forBuild = "forbuild.txt"; 
     21 
     22// possible build configuration file names 
     23private static const char[][] configs =  
     24[ 
     25    "build_debug.txt", 
     26    "build_release.txt" 
     27]; 
     28 
     29// the actual build configuration file to use 
     30private char[] configTxt; 
     31 
     32// name of the text file containing swtiched common to all configurations 
     33private static const char[] commonTxt = "build_common.txt"; 
     34 
     35// buffer to store the contents of commonTxt and configTxt at startup 
     36private static char[] brfBuf = ""; 
     37 
     38// name of the temporary Build Response File generated by this script 
     39private static const char[] tempBrf = "temp.brf"; 
     40 
     41// build configuration. If none is specified on the command line, Mode.Debug is default 
    3642private Mode mode = Mode.Debug; 
     43 
     44version(Windows) 
     45{ 
     46    // Windows delete command 
     47    private static const char[] delCmd = "del "; 
     48} 
     49else version(linux) 
     50{ 
     51    // Linux delete command 
     52    private static const char[] delCmd = "rm -f "; 
     53} 
     54else 
     55{ 
     56    static assert(0); 
     57} 
     58 
     59 
    3760 
    3861void main(char[][] args) 
     
    4568    else 
    4669    { 
     70        // look for a build configuration in the command line 
     71        foreach(char[] c; args) 
     72        { 
     73            if(c.tolower().cmp("release") == 0) 
     74            { 
     75                mode = Mode.Release;                 
     76                break; 
     77            } 
     78            else if(c.tolower().cmp("debug") == 0) 
     79            { 
     80                mode = Mode.Debug;               
     81                break; 
     82            } 
     83        } 
     84         
     85        // set the name of the build configuration text file 
     86        configTxt = configs[mode]; 
     87         
     88        // build a buffer of the commonTxt and configTxt so that it is done 
     89        // one time only and not once for each file 
     90        buildBRFBuffer(); 
     91         
    4792        // parse the command line for individual package names and build each package 
    4893        foreach(char[] c; args) 
     
    65110private char[] libString(char[] packageName) 
    66111{ 
     112    // build a string which will be used as the name of the library file 
    67113    version(Windows) 
    68114    { 
     115        // PackageName.lib 
    69116        return packageName ~ ".lib";         
    70117    } 
    71118    else version(linux) 
    72119    { 
     120        // libPackageName.a 
    73121        return "lib" ~ packageName ~ ".a"; 
    74122    } 
     
    80128} 
    81129 
     130private void buildBRFBuffer() 
     131{ 
     132    // if a common switches file is present... 
     133    if(exists(commonTxt)) 
     134    { 
     135        // read it in and assign it to the brf buffer 
     136        brfBuf = "\n" ~ cast(char[])read(commonTxt); 
     137    } 
     138     
     139    // if a build configuration file is present... 
     140    if(exists(configTxt)) 
     141    { 
     142        // ... read it in and append it to the buffer 
     143        brfBuf ~= cast(char[])read(configTxt); 
     144    } 
     145} 
     146 
    82147private void createBRF(char[] packageName, char[] path) 
    83148{ 
    84149    writefln("Reading build arguments..."); 
    85150     
     151    // read the package forbuild file 
    86152    char[] txt = cast(char[])read(path); 
    87153     
     154    // this will store all of the text to be output to the temp build response file 
    88155    char[] brf = ""; 
    89156     
    90     if(exists(configTxt)) 
    91     { 
    92         brf = cast(char[])read(configTxt); 
    93     } 
    94      
    95     if(exists(commonTxt)) 
    96     { 
    97         brf ~= "\n" ~ cast(char[])read(commonTxt); 
    98     } 
    99      
     157    // append the common brf buffer 
     158    brf ~= brfBuf; 
     159     
     160    // the package directory must be on the import path 
    100161    brf ~= "\n-I" ~ packageName; 
    101162     
     163    // if the current package is not DerelictUtil, then DerelictUtil must be 
     164    // on the import path and excluded from being compiled 
    102165    if(packageName.cmp("DerelictUtil") != 0) 
    103166    { 
     
    105168    } 
    106169     
     170    // append a switch to set the output path of the library 
    107171    brf ~= "\n-Tlib/" ~ libString(packageName) ~ "\n" ~ txt; 
    108172     
     173    // write the temporary build response file to disk 
    109174    writefln("Creating temporary build response file..."); 
    110175    write(tempBrf, cast(void[])brf); 
     
    113178private void buildPackage(char[] packageName) 
    114179{ 
     180    // construct a path to the package's forbuild file 
    115181    char[] path = packageName ~ sep ~ forBuild; 
    116182    if(!exists(path)) 
    117183    { 
     184        // if there is no forbuild file in the subdirectory then this isn't 
     185        // a Derelict package and there is nothing to do 
    118186        return; 
    119187    } 
     188     
     189    // create the temporary build response file 
    120190    writefln("Preparing to build package %s in %s mode...", packageName, modeString);    
    121191    createBRF(packageName, path); 
    122192     
     193    // call out to build with the name of the temporary build response file as an arg 
    123194    writefln("Building package..."); 
    124195    system("build @temp"); 
    125196     
     197    // delete the temporary build response file 
    126198    writefln("Deleting temporary build response file...\n\n"); 
    127199    system(delCmd ~ tempBrf); 
     
    130202private void scan() 
    131203{ 
     204    // delegate to use as the listdir callback 
    132205    bool callback(char[] filename) 
    133206    { 
     207        // if this filename is a directory, pass it to buildpackage for 
     208        // further processing 
    134209        if(isdir(filename)) 
    135210        { 
    136211            buildPackage(filename); 
    137212        } 
     213         
     214        // return true to continue listing directories 
    138215        return true; 
    139216    } 
    140217     
     218    // call listdir to cycle through every Derelict directory 
    141219    writefln("\nScanning for buildable packages...\n\n");    
    142220    listdir(".", &callback);