forked from gtkd-developers/GtkD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild.d
executable file
·161 lines (137 loc) · 3.25 KB
/
Build.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
module Build;
import core.stdc.stdlib: exit;
import std.algorithm;
import std.array;
import std.conv;
import std.file;
import std.getopt;
import std.path;
import std.process;
import std.range;
import std.stdio;
import std.string;
string dcflags;
string ldflags;
version(DigitalMars)
{
string DC = "dmd";
string OUTPUT = "-of";
version(Win32) version = DMD32;
}
else version(LDC)
{
string DC = "ldc2";
string OUTPUT = "-od=objects -oq -of";
}
else version(GNU)
{
string DC = "gdc";
string OUTPUT = "-o ";
}
else
{
static assert(false, "Unsupported compiler");
}
int main(string[] args)
{
version(Posix)
{
writeln("This build script is currently Windows only.");
return(1);
}
getopt(args, "dcflags", &dcflags, "ldflags", &ldflags);
args.popFront();
foreach ( arg; args )
{
if ( !["gtkd", "gtkdgl", "sv", "gstreamer", "vte", "peas", "all"].canFind(arg) )
{
writefln("Unknown option: %s", arg);
return 1;
}
}
if ( args.length == 0 )
args = ["gtkd", "sv"];
if ( args.canFind("all") )
args = ["gtkd", "sv", "gstreamer", "peas"];
foreach ( arg; args )
{
switch ( arg )
{
case "gtkd":
build("generated\\gtkd", "gtkd");
break;
case "gtkdgl":
build("generated\\gtkdgl", "gtkdgl");
break;
case "sv":
build("generated\\sourceview", "gtkdsv");
break;
case "gstreamer":
build("generated\\gstreamer", "gstreamerd");
break;
case "peas":
build("generated\\peas", "peasd");
break;
default:
assert(false);
break;
}
}
return(0);
}
void build(string dir, string lib)
{
version(DMD32)
{
if (lib == "gtkd")
{
string[] subDirs = ["atk", "cairo", "gdk", "gdkpixbuf", "gio", "glib", "gobject", "gthread", "gtkc", "gtkd", "pango", "rsvg"];
foreach(directory; subDirs)
buildObj(dFiles("generated\\gtkd\\"~ directory), directory);
string[] files = dFiles("generated\\gtkd\\gtk").split();
files.chunks((files.length / 4) + 1).enumerate(1).each!((index, value){buildObj(value.join(' '), "gtk"~to!string(index));});
string objects;
foreach(directory; subDirs)
objects ~= directory ~".obj ";
objects ~= "gtk1.obj gtk2.obj gtk3.obj gtk4.obj";
executeShell(format("%s -lib %s %s%s.lib %s", DC, ldflags, OUTPUT, lib, objects));
foreach(string obj; objects.split())
std.file.remove(obj);
}
else
{
buildObj(dFiles(dir), lib);
executeShell(format("%s -lib %s %s%s.lib %s.obj", DC, ldflags, OUTPUT, lib, lib));
std.file.remove(lib ~".obj");
}
}
else
{
std.file.write("build.rf", format("-m64 -c -lib %s %s -Igenerated/gtkd -%s%s.lib %s", dcflags, ldflags, OUTPUT ,lib, dFiles(dir)));
auto pid = spawnProcess([DC, "@build.rf"]);
if ( wait(pid) != 0 )
exit(1);
}
version(LDC)std.file.rmdirRecurse("objects");
std.file.remove("build.rf");
}
void buildObj(string files, string objName)
{
std.file.write("build.rf", format("-c %s -Igenerated/gtkd %s%s.obj %s", dcflags, OUTPUT, objName, files));
auto pid = spawnProcess(["dmd", "@build.rf"]);
if ( wait(pid) != 0 )
exit(1);
}
string dFiles(string sourceDir)
{
string files;
auto entries = dirEntries(sourceDir, SpanMode.breadth);
foreach ( DirEntry entry; entries )
{
if ( entry.isDir == false && entry.name.extension == ".d" )
{
files ~= entry.name ~ " ";
}
}
return files;
}