annotate configure.d @ 123:0d427170a805

Move to 64-bit
author David Bryant <bagnose@gmail.com>
date Wed, 04 May 2011 22:19:44 +0930
parents 6c3993f4c3eb
children 1da160a2c373
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
1 // Configure script, to be run with rdmd.
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
2 //
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
3 // Checks dependencies, sets up a build directory, builds
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
4 // a local copy of the builder into the build directory,
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
5 // and puts assorted scripts into the build directory to
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
6 // facilitate building.
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
7 //
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
8 // If your project depends on installed libraries, you need to
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
9 // add an options file containing command-line options such as:
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
10 // -L-lgtkd
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
11 // You also need to install the libraries somewhere that the compiler
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
12 // can find them. Two simple options are:
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
13 // * In the dmd installation directory, or
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
14 // * Elsewhere, and edit dmd.conf to point to there.
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
15 //
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
16 //
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
17 // The source paths you depend on need to be listed in a uses file.
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
18 // Uses files are not transitive - only the one in the directory
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
19 // you execute the configure script applies.
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
20 //
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
21 // Usage: rdmd configure.d <target-path>
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
22 //
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
23 // eg: rdmd configure.d ~/builds/myproject
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
24 //
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
25
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
26
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
27 import std.stdio;
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
28 import std.path;
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
29 import std.file;
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
30 import std.string;
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
31 import std.stdio;
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
32 import std.process;
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
33
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
34
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
35 int main(string[] args) {
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
36
59
860e18c87255 Stylistics
"David Bryant <bagnose@gmail.com>"
parents: 43
diff changeset
37 string sourcePath = getcwd;
28
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
38
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
39 // parse command-line options
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
40 if (args.length < 2) {
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
41 writefln("Error - usage is: rdmd <configure.d-path> <build-path>");
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
42 return -1;
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
43 }
59
860e18c87255 Stylistics
"David Bryant <bagnose@gmail.com>"
parents: 43
diff changeset
44 string targetPath = args[1];
28
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
45
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
46 // check that source_path looks like a source tree by making sure
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
47 // that a README and options file are present
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
48 writefln("Examining source");
123
0d427170a805 Move to 64-bit
David Bryant <bagnose@gmail.com>
parents: 62
diff changeset
49 if (!std.path.join(sourcePath, "README").exists || !std.path.join(sourcePath, "options").exists) {
28
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
50 writefln("Error - current directory must contain README and options");
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
51 return -1;
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
52 }
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
53
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
54 // ensure that target_path exists
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
55 writefln("Establishing build directory");
59
860e18c87255 Stylistics
"David Bryant <bagnose@gmail.com>"
parents: 43
diff changeset
56 if (targetPath.exists) {
860e18c87255 Stylistics
"David Bryant <bagnose@gmail.com>"
parents: 43
diff changeset
57 writefln("Error - %s exists - abandoning configure", targetPath);
28
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
58 return -1;
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
59 }
59
860e18c87255 Stylistics
"David Bryant <bagnose@gmail.com>"
parents: 43
diff changeset
60 targetPath.mkdirRecurse;
123
0d427170a805 Move to 64-bit
David Bryant <bagnose@gmail.com>
parents: 62
diff changeset
61 string binPath = std.path.join(targetPath, "bin");
59
860e18c87255 Stylistics
"David Bryant <bagnose@gmail.com>"
parents: 43
diff changeset
62 binPath.mkdir;
28
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
63
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
64 // compile builder into bin_path
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
65 writefln("Building the builder");
123
0d427170a805 Move to 64-bit
David Bryant <bagnose@gmail.com>
parents: 62
diff changeset
66 int ret = system(format("dmd -m64 -w -wi %s -O -of%s",
0d427170a805 Move to 64-bit
David Bryant <bagnose@gmail.com>
parents: 62
diff changeset
67 std.path.join(sourcePath, "builder.d"), std.path.join(binPath, "builder")));
28
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
68 if (ret) {
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
69 writefln("Error - builder failed to compile");
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
70 return -1;
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
71 }
123
0d427170a805 Move to 64-bit
David Bryant <bagnose@gmail.com>
parents: 62
diff changeset
72 std.path.join(binPath, "builder.o").remove;
28
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
73
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
74 // set up scripts
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
75 {
123
0d427170a805 Move to 64-bit
David Bryant <bagnose@gmail.com>
parents: 62
diff changeset
76 auto file = File(std.path.join(targetPath, "build"), "w");
28
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
77 file.writefln("#!/bin/bash");
123
0d427170a805 Move to 64-bit
David Bryant <bagnose@gmail.com>
parents: 62
diff changeset
78 file.writefln("%s %s %s", std.path.join(binPath, "builder"), sourcePath, targetPath);
28
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
79 }
123
0d427170a805 Move to 64-bit
David Bryant <bagnose@gmail.com>
parents: 62
diff changeset
80 system("chmod +x " ~ std.path.join(targetPath, "build"));
28
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
81 writefln("All done");
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
82
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
83 return 0;
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
diff changeset
84 }