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