Changeset 221

Show
Ignore:
Timestamp:
02/01/07 10:41:54 (2 years ago)
Author:
aldacron
Message:

Fixed more buildme.d bugs:
* the delete command for unices had been zapped in a copy-paste error
* rewrote the compilation process so that object files are passed to the lib/ar tool grouped by directory, rather than all at once or individually. This allows the DerelictGL library to be built successfully with DMD and the lib tool.

Files:

Legend:

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

    r220 r221  
    55    import std.stdio; 
    66    import std.string; 
     7    import std.c.string; 
    78    import std.c.process; 
    89    import std.file; 
     
    1718else version(linux) 
    1819{ 
    19     private static const char[] libPre = "lib";    
     20    private static const char[] delCmd = "rm -f ";     
    2021 
    2122} 
    2223else version(Unix) 
    2324{ 
    24     private static const char[] libPre = "lib";    
     25    private static const char[] delCmd = "rm -f ";     
    2526 
    2627} 
     
    5859    private static const char[] objExt = ".obj"; 
    5960    private static const char[] libExt = ".lib"; 
    60     private static const char[] libCmd = "@lib -c -n "; 
     61    private static const char[] libNewCmd = "@lib -p512 -c -n "; 
     62    private static const char[] libCmd = "@lib -p1024 -n "; 
    6163    private static const char[] libPre = "";     
    6264} 
     
    203205//============================================================================== 
    204206// DMD & GDMD 
    205 private char[] processPackage(char[] dir) 
     207private void processPackage(char[] dir, inout char[][] buffer) 
    206208{ 
    207209    writefln("Processing %s", dir); 
     
    222224        if(isdir(c)) 
    223225        { 
    224             fileList ~= processPackage(c); 
     226            processPackage(c, buffer); 
    225227        }        
    226228        // otherwise, if it is a D source file, append it to the return string 
     
    229231            if(c[$-2 .. $].cmp(".d") == 0) 
    230232            { 
     233                writefln("Found source file %s", c); 
    231234                fileList = fileList ~ " " ~ c; 
    232235            } 
    233236        } 
    234237    } 
    235     return fileList; 
     238     
     239    buffer ~= fileList; 
    236240} 
    237241 
     
    239243{ 
    240244    // build a list of source files 
    241     char[] fileList = processPackage(packageName);   
    242     char[][] files = fileList.split(); 
    243      
     245    char[][] fileList; 
     246    processPackage(packageName, fileList); 
     247    foreach(c; fileList) 
     248        writefln(c);     
     249         
    244250    // build up an import list from forBuild.txt 
    245251    char[] importList = "-IDerelictUtil -I" ~ packageName; 
     
    256262    auto flags = importList ~ COMPILE_FLAGS_COMMON; 
    257263    flags ~= (mode == Mode.Debug) ? COMPILE_FLAGS_DEBUG : COMPILE_FLAGS_RELEASE; 
    258     foreach(c; files) 
    259     { 
    260         writefln("Compiling source file %s", c); 
    261         auto cmdline = compilerCmd ~ flags ~ c; 
    262         if(system(toStringz(cmdline)) != 0) 
    263         {    
    264             throw new Exception("Failed to compile " ~ c); 
    265         } 
    266     } 
    267      
    268     // replace each .d extension with the proper object file extension for the linker 
    269     fileList = fileList.replace(".d", objExt); 
    270     writefln(fileList); 
     264    foreach(i,cc; fileList) 
     265    { 
     266        auto files = fileList[i].split(); 
     267        foreach(c;files) 
     268        { 
     269            if(c is null || c.cmp("") == 0 || strlen(c.ptr) < 3) 
     270                continue; 
     271                 
     272            writefln("Compiling source file %s", c); 
     273            auto cmdline = compilerCmd ~ flags ~ c; 
     274            if(system(toStringz(cmdline)) != 0) 
     275            {    
     276                throw new Exception("Failed to compile " ~ c); 
     277            } 
     278        } 
     279    } 
    271280     
    272281    // create the library 
    273282    auto libName = libPre ~ packageName ~ libExt; 
    274     writefln("Creating library %s...", libName); 
    275     if(system(toStringz(libCmd ~ "lib" ~ sep ~ libName ~ " " ~ fileList)) != 0) 
    276     { 
    277         throw new Exception("Failed to create library " ~ libName); 
    278     }        
    279      
    280     // delete the object files 
    281     writefln("Deleting object files..."); 
    282     system(toStringz(delCmd ~ " " ~ fileList)); 
     283    foreach(i,c; fileList) 
     284    { 
     285        if(c is null || c.cmp("") == 0 || strlen(c.ptr) < 3) 
     286                continue; 
     287                 
     288        auto a = c.replace(".d", objExt); 
     289        auto cmd = libCmd; 
     290        if(i == 0) 
     291        { 
     292            cmd = libNewCmd; 
     293            writefln("Creating library %s...", libName); 
     294        } 
     295             
     296        // add the object files to the library 
     297        writefln("Adding object files %s...", a); 
     298        if(system(toStringz(cmd ~ "lib" ~ sep ~ libName ~ " " ~ a)) != 0) 
     299        { 
     300            throw new Exception("Failed to create library " ~ libName); 
     301        } 
     302         
     303        // delete the object files 
     304        writefln("Deleting object files %s...", a); 
     305        system(toStringz(delCmd ~ a)); 
     306    } 
    283307     
    284308    // strip the library on unices