Changeset 228

Show
Ignore:
Timestamp:
02/15/07 07:29:50 (1 year ago)
Author:
aldacron
Message:

* yet more tweaking of the build script. Now makes use of Mixin statements and import expressions.

Files:

Legend:

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

    r225 r228  
    4848} 
    4949 
     50// this must be set in a static class constructor in the builder file 
     51private Builder theBuilder = null; 
     52 
    5053//============================================================================== 
    5154// Options 
     
    5962private Mode mode = Mode.Release; 
    6063 
     64// option file types 
     65enum OptsType 
     66{ 
     67    Debug, 
     68    Release, 
     69    Common 
     70} 
     71 
    6172// when true, do not delete the temporary Build Response File for Bud/Build 
    6273private bool doNotDeleteBRF = false; 
    6374 
    6475//============================================================================== 
     76// Utility Functions 
     77//============================================================================== 
     78version(Tango) 
     79{ 
     80    mixin(import("build/tangoUtil.d")); 
     81} 
     82else 
     83{ 
     84    mixin(import("build/phobosUtil.d")); 
     85} 
     86 
     87//============================================================================== 
     88// Builder Configuration 
     89//============================================================================== 
     90mixin(import("build/config.d")); 
     91 
     92//============================================================================== 
    6593// Main 
    6694//============================================================================== 
     
    77105    char[][] packageList; 
    78106     
    79     // instance of the Builder class that will be used to create the libraries 
    80     Builder builder = null; 
    81      
    82107    // parse the command line 
    83108    foreach(c; args) 
     
    86111        switch(lower) 
    87112        { 
    88             case "bud": 
    89             case "build": 
    90                 builder = Builder.getBuilder(lower);             
    91                 break; 
    92113            case "debug": 
    93114                mode = Mode.Debug; 
     
    108129    } 
    109130     
    110     // Hopefully, this is temporary. In the future, I hope to include a default 
    111     // Builder which uses compiler running this script. 
    112     if(builder is null) 
    113     { 
    114         builder = Builder.getBuilder("bud"); 
    115     } 
    116     builder.build(packageList); 
     131    theBuilder.build(packageList); 
    117132} 
    118133 
     
    135150     
    136151private: 
    137     static Builder getBuilder(char[] name) 
    138     { 
    139         switch(name) 
    140         { 
    141             case "bud":              
    142             case "build": 
    143                 return new BudBuilder(name); 
    144             default: 
    145                 return null; 
    146         } 
    147     } 
    148      
    149152    void build(char[][] packageList) 
    150153    { 
     
    201204 
    202205//============================================================================== 
    203 // Bud Builder -- uses Derek Parnell's Bud 
    204 //============================================================================== 
    205 class BudBuilder : Builder 
    206 
    207     //========================================================================== 
    208     // Methods 
    209     //========================================================================== 
    210     override void buildPackage(char[] packageName) 
    211     { 
    212         // construct a path to the package's forbud file 
    213         char[] path = packageName ~ pathSep ~ _forBudName; 
    214          
    215         // verify that the file exists 
    216         bool doesExist = false; 
    217         version(Tango) 
    218         { 
    219         } 
    220         else 
    221         { 
    222             doesExist = exists(path) ? true : false; 
    223         } 
    224          
    225         if(!doesExist) 
    226         { 
    227             printf("Could not find %s\n", toCString(path)); 
    228             return; 
    229         } 
    230          
    231         // create the temporary brf 
    232         printf("Preparing to build package %s in %s mode...\n", toCString(packageName), toCString(modeToString())); 
    233         createBRF(packageName, path); 
    234          
    235         // call out to build with the name of the temp brf as an arg 
    236         if(execute(_name ~ " @" ~ _tempBRFName) != 0) 
    237         { 
    238             throw new Exception("Failed to build package " ~ packageName); 
    239         } 
    240          
    241         if(!doNotDeleteBRF) 
    242         { 
    243             // delete the temporary brf 
    244             printf("Deleting temporary Build Response File...\n\n"); 
    245             execute(delCmd ~ _tempBRFName); 
    246         } 
    247     } 
    248      
    249 private: 
    250     this(char[] name) 
    251     { 
    252         _name = name; 
    253         _commonOptsName     = "bud_common.txt"; 
    254         _configOptsName     = (mode == Mode.Debug) ? "bud_debug.txt" : "bud_release.txt"; 
    255         _tempBRFName        = "temp.brf"; 
    256         _forBudName         = "forbud.txt"; 
    257         _brfBuf             = ""; 
    258          
    259         buildBRFBuffer(); 
    260     } 
    261      
    262     void buildBRFBuffer() 
    263     { 
    264         version(Tango) 
    265         { 
    266         } 
    267         else 
    268         { 
    269             // read in the common options file if it exists 
    270             if(exists(_commonOptsName)) 
     206// Utility functions 
     207//============================================================================== 
     208char[] modeToString() 
     209
     210    return (mode == Mode.Debug) ? "Debug" : "Release"; 
     211
     212 
     213char[] loadOpts(char[] prefix, OptsType type) 
     214
     215    char[] fileName = "buildopts" ~ pathSep ~ prefix ~ optsSuffix(type) ~ ".txt"; 
     216    char[] ret = readFile(fileName); 
     217    if(ret is null) 
     218        return ""; 
     219    return ret; 
     220
     221 
     222char[] optsSuffix(OptsType type) 
     223
     224    switch(type) 
     225    { 
     226        case OptsType.Common: 
     227            return "_common"; 
     228        case OptsType.Release: 
     229            return "_release"; 
     230        case OptsType.Debug: 
     231            return "_debug"; 
     232        default: 
     233            throw new Exception("Unknown OptsType");         
     234    } 
     235
     236 
     237char[] generateFileList(char[] directory) 
     238
     239/* 
     240    char[] files; 
     241     
     242    version(Tango) 
     243    { 
     244    } 
     245    else 
     246    { 
     247        // get a list of all files in the directory 
     248        auto list = listdir(directory); 
     249            foreach(c; list) 
    271250            { 
    272                 _brfBuf = cast(char[])read(_commonOptsName) ~ "\n"; 
     251                // if this filename is a directory, recurse 
     252                if(isdir(c) && c[0] != '.') 
     253                    files ~= (" " ~ generateFileList(directory ~ pathSep ~ c)); 
     254                else if( 
     255                 
    273256            } 
    274              
    275             // read in the options for the build configuration, if the file exists 
    276             if(exists(_configOptsName)) 
    277             { 
    278                 _brfBuf ~= cast(char[])read(_configOptsName); 
    279             } 
    280         } 
    281     } 
    282      
    283     void createBRF(char[] packageName, char[] path) 
    284     { 
    285         printf("Reading build tool arguments...\n"); 
    286          
    287         char[] txt;         // holds the contents of the forbud file 
    288          
    289         // read the forbud.txt in this package       
    290         version(Tango) 
    291         { 
    292         } 
    293         else 
    294         {            
    295             txt = cast(char[])read(path);            
    296         } 
    297          
    298         // this will store all of the text to be output to the temp brf 
    299         char[] brf = ""; 
    300              
    301         // append the common brf buffer 
    302         brf ~= _brfBuf; 
    303          
    304         // the package directory myst be on the import path 
    305         brf ~= "\n-I" ~ packageName; 
    306          
    307         // if the current package is not DerelictUtil, then DerelictUtil must 
    308         // be on the import path and excluded from compilation 
    309         if(cmpStr(packageName, "DerelictUtil") != 0) 
    310         { 
    311             brf ~= "\n-IDerelictUtil\n-XDerelictUtil" ~ pathSep ~ "derelict" ~ pathSep ~ "util"; 
    312         }    
    313          
    314         // append a switch to set the output path of the library and append the config file 
    315         brf ~= "\n-Tlib" ~ pathSep ~ libPre ~ packageName ~ libExt ~ "\n" ~ txt; 
    316          
    317         // write the temporary brf to disk 
    318         printf("Creating temporary Build Response File...\n"); 
    319         version(Tango) 
    320         { 
    321         } 
    322         else 
    323         { 
    324             write(_tempBRFName, cast(void[])brf); 
    325         } 
    326     } 
    327      
    328     //========================================================================== 
    329     // Members 
    330     //========================================================================== 
    331     char[] _name; 
    332     char[] _commonOptsName; 
    333     char[] _configOptsName; 
    334     char[] _tempBRFName; 
    335     char[] _forBudName; 
    336     char[] _brfBuf; 
    337 
    338  
    339 //============================================================================== 
    340 // Utility functions 
    341 //============================================================================== 
    342 char[] modeToString() 
    343 
    344     return (mode == Mode.Debug) ? "Debug" : "Release"; 
    345 
    346  
    347 //============================================================================== 
    348 // Wrappers for compatibility between Phobos and Tango. 
    349 //============================================================================== 
    350 char[] toLowerStr(char[] str) 
    351 
    352     version(Tango) 
    353     { 
    354         return toLower(str); 
    355     } 
    356     else 
    357     { 
    358         return tolower(str); 
    359     } 
    360 
    361  
    362 //============================================================================== 
    363 int cmpStr(char[] a, char[] b) 
    364 
    365     version(Tango) 
    366     { 
    367         String s = new String!(char)(a); 
    368         return s.compare(b); 
    369     } 
    370     else 
    371     { 
    372         return cmp(a, b); 
    373     } 
    374 
    375  
    376 //============================================================================== 
    377 int findStr(char[] str, char[] match) 
    378 
    379     version(Tango) 
    380     { 
    381         int i = locatePattern(str, match); 
    382         return (i == str.length) ? -1 : i; 
    383     } 
    384     else 
    385     { 
    386         return find(str, match); 
    387     } 
    388 
    389  
    390 //============================================================================== 
    391 char[][] splitString(char[] str, char[] delim) 
    392 
    393     version(Tango) 
    394     { 
    395         return demarcate(str, delim); 
    396     } 
    397     else 
    398     { 
    399         return split(str, delim); 
    400     } 
    401 
    402  
    403 //============================================================================== 
    404 char* toCString(char[] str) 
    405 
    406     version(Tango) 
    407     { 
    408         return toUtf8z(str); 
    409     } 
    410     else 
    411     { 
    412         return toStringz(str); 
    413     } 
    414 
    415  
    416 //============================================================================== 
    417 int execute(char[] cmd) 
    418 
    419     version(Tango) 
    420     { 
    421         auto p = new Process(cmd, null); 
    422         p.execute(); 
    423         Result r = p.wait(); 
    424         return r.status; 
    425     } 
    426     else 
    427     { 
    428         return system(toStringz(cmd)); 
    429     } 
    430 
     257    } 
     258*/ 
     259return ""; 
     260
  • trunk/examples/sdl_ex1.d

    r161 r228  
    1111 
    1212import derelict.sdl.sdl;    // required to use SDL through Derelict 
    13 import std.stdio;           // for writefln 
     13 
     14 
     15version(Tango) 
     16
     17    import tango.stdc.stdio; 
     18
    1419 
    1520SDL_Surface* screen;        // pointer to the screen surface object 
     
    7883    if(SDL_Init(SDL_INIT_VIDEO) < 0) 
    7984    { 
    80         writefln("Unable to init SDL: %s", SDL_GetError()); 
     85        printf("Unable to init SDL: %s\n", SDL_GetError()); 
    8186        SDL_Quit(); 
    8287        return 1; 
     
    8792    if(screen is null) 
    8893    { 
    89         writefln("Unable to set 640x480 video: %s", SDL_GetError()); 
     94        printf("Unable to set 640x480 video: %s\n", SDL_GetError()); 
    9095        SDL_Quit(); 
    9196        return 1;