1 module Build; 2 3 import std.algorithm; 4 import std.array; 5 import std.file; 6 import std.getopt; 7 import std.path; 8 import std.process; 9 import std.stdio; 10 import std.string; 11 12 string dcflags; 13 string ldflags; 14 15 int main(string[] args) 16 { 17 version(Posix) 18 { 19 writeln("This build script is currently Windows only."); 20 return(1); 21 } 22 23 getopt(args, "dcflags", &dcflags, "ldflags", &ldflags); 24 args.popFront(); 25 26 foreach ( arg; args ) 27 { 28 if ( !["gtkd", "gtkdgl", "sv", "gstreamer", "vte", "all"].canFind(arg) ) 29 { 30 writefln("Unknown option: %s", arg); 31 return 1; 32 } 33 } 34 35 if ( args.length == 0 ) 36 args = ["gtkd", "gtkdgl", "sv"]; 37 38 if ( args.canFind("all") ) 39 args = ["gtkd", "gtkdgl", "sv", "gstreamer", "vte"]; 40 41 foreach ( arg; args ) 42 { 43 switch ( arg ) 44 { 45 case "gtkd": 46 build("src", "gtkd"); 47 break; 48 case "gtkdgl": 49 build("srcgl", "gtkdgl"); 50 break; 51 case "sv": 52 build("srcsv", "gtkdsv"); 53 break; 54 case "gstreamer": 55 build("srcgstreamer", "gstreamerd"); 56 break; 57 case "vte": 58 build("srcvte", "vted"); 59 break; 60 default: 61 assert(false); 62 break; 63 } 64 } 65 66 return(0); 67 } 68 69 void build(string dir, string lib) 70 { 71 version(Win64) 72 { 73 std.file.write("build.rf", format("-m64 -c -lib %s %s -Isrc -of%s.lib %s", dcflags, ldflags, lib, dFiles(dir))); 74 executeShell("dmd @build.rf"); 75 } 76 else 77 { 78 std.file.write("build.rf", format("-c %s -Isrc -of%s.obj %s", dcflags, lib, dFiles(dir))); 79 executeShell("dmd @build.rf"); 80 executeShell(format("dmd -lib %s -of%s.lib %s.obj", ldflags, lib, lib)); 81 std.file.remove(lib ~".obj"); 82 } 83 84 std.file.remove("build.rf"); 85 } 86 87 string dFiles(string sourceDir) 88 { 89 string files; 90 auto entries = dirEntries(sourceDir, SpanMode.breadth); 91 92 foreach ( DirEntry entry; entries ) 93 { 94 if ( entry.isDir == false && entry.name.extension == ".d" ) 95 { 96 files ~= entry.name ~ " "; 97 } 98 } 99 100 return files; 101 }