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", "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"];
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 			default:
58 				assert(false);
59 				break;
60 		}
61 	}
62 	
63 	return(0);
64 }
65 
66 void build(string dir, string lib)
67 {
68 	version(Win64)
69 	{
70 		std.file.write("build.rf", format("-m64 -c -lib %s %s -Isrc -of%s.lib %s", dcflags, ldflags, lib, dFiles(dir)));
71 		system("dmd @build.rf");
72 	}
73 	else
74 	{
75 		std.file.write("build.rf", format("-c %s -Isrc -of%s.obj %s", dcflags, lib, dFiles(dir)));
76 		system("dmd @build.rf");
77 		system(format("dmd -lib %s -of%s.lib %s.obj", ldflags, lib, lib));
78 		std.file.remove(lib ~".obj");
79 	}
80 	
81 	std.file.remove("build.rf");
82 }
83 
84 string dFiles(string sourceDir)
85 {
86 	string files;
87 	auto entries = dirEntries(sourceDir, SpanMode.breadth);
88 	
89 	foreach ( DirEntry entry; entries )
90 	{
91 		if ( entry.isDir == false && entry.name.extension == ".d" )
92 		{
93 			files ~= entry.name ~ " ";
94 		}
95 	}
96 	
97 	return files;
98 }