1 module main;
2 import scriptlike;
3 
4 immutable string[] hosts = ["arm-unknown-linux-gnueabi",
5     "arm-unknown-linux-gnueabihf",
6     "i686-unknown-linux-gnu",
7     "i686-w64-mingw32",
8     "x86_64-unknown-linux-gnu",
9     "x86_64-w64-mingw32"];
10 
11 immutable string[] gccVersions = ["4.8", "4.9", "5", "6", "7"];
12 
13 enum string[string] compilerPath = [
14     "arm-unknown-linux-gnueabi": "arm-unknown-linux-gnueabihf",
15     "arm-unknown-linux-gnueabihf": "arm-unknown-linux-gnueabihf",
16     "i686-unknown-linux-gnu": "x86_64-unknown-linux-gnu",
17     "i686-w64-mingw32": "i686-w64-mingw32",
18     "x86_64-unknown-linux-gnu": "x86_64-unknown-linux-gnu",
19     "x86_64-w64-mingw32": "x86_64-w64-mingw32"
20 ];
21 
22 enum string[string] compilerFlags = [
23     "arm-unknown-linux-gnueabi": "-mfloat-abi=soft",
24     "arm-unknown-linux-gnueabihf": "",
25     "i686-unknown-linux-gnu": "-m32",
26     "i686-w64-mingw32": "",
27     "x86_64-unknown-linux-gnu": "",
28     "x86_64-w64-mingw32": ""
29 ];
30 
31 void main(string[] args)
32 {
33     scriptlikeEcho = true;
34 
35     foreach(host; hosts)
36     {
37         writefln("Compiling for host: %s", host);
38         auto hostparts = findSplit(compilerPath[host], "-");
39         auto xhost = hostparts[0] ~ "_host-" ~ hostparts[2];
40         auto compilerPath = Path("/home/build/share/host-toolchains/") ~ Path(compilerPath[host]) ~ "xbin";
41         auto strip = compilerPath ~ (xhost ~ "-strip");
42         auto gdc = compilerPath ~ (xhost ~ "-gdc");
43 
44         foreach(gccVersion; gccVersions)
45         {
46             auto installDir = Path("/home/build/share/gdmd") ~ host ~ gccVersion;
47             installDir.tryMkdirRecurse();
48             auto config = "gdc" ~ gccVersion;
49 
50             compileGDMD(compilerFlags[host], gdc, strip, config, installDir, "gdmd");
51             compileGDMD(compilerFlags[host] ~ " -fversion=UseSystemAR", gdc, strip, config, installDir, "gdmd_native");
52         }
53     }
54 }
55 
56 void compileGDMD(string dflags, Path gdc, Path strip, string config, Path installDir, string installName)
57 {
58     run(mixin(interp!`DFLAGS="${dflags}" dub build -f -v --compiler=${gdc} --config=${config}`));
59     auto compiledGDMD = "gdmd";
60     if(!compiledGDMD.exists)
61         compiledGDMD = "gdmd.exe";
62     run(mixin(interp!`${strip} ${compiledGDMD}`));
63     run(mixin(interp!`chmod +x ${compiledGDMD}`));
64 
65     run(mixin(interp!`mv ${compiledGDMD} ${installDir ~ installName.setExtension(compiledGDMD.extension)}`));
66 }