annotate build-tool/configure_functions.d @ 134:89e8b0d92f36

Ported to bob2 !!!
author David Bryant <bagnose@gmail.com>
date Thu, 02 Aug 2012 17:20:52 +0930
parents
children be50d20643a1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
134
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1 // Functions used by various configure scripts to set up a build environment
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2 // suitable for building with bob and running/deploying.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
3 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
4 // Expected to be called from a configure.d in a project directory with code like
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
5 // the following abbreviated example:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
6 /*
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
7 void main(string args[]) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
8 auto data = initialise(args, "project-name");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
9
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
10 usePackage(data, "libssh2", Constraint.AtLeast, "1.2");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
11 useHeader( data, "gcrypt.h");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
12 useLibrary(data, "libgcrypt.so");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
13 useExecutable(data, "IMAGE_MAGICK_CONVERT", ["convert"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
14
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
15 appendRunVar(data, "GST_PLUGIN_PATH", ["${DIST_PATH}/lib/plugins"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
16 appendBobVar(data, "CCFLAGS", ["-DUSE_BATHY_CHARTING_RASTER_SOURCE"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
17
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
18 finalise(data, ["open", "reuse"]); // all packages in this and specified other repos
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
19 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
20 */
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
21
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
22
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
23 module configure_functions;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
24
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
25 import std.string;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
26 import std.getopt;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
27 import std.path;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
28 import std.file;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
29 import std.process;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
30 import std.stdio;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
31 import std.conv;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
32
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
33 import core.stdc.stdlib;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
34 import core.sys.posix.sys.stat;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
35
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
36
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
37
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
38
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
39 private void setMode(string path, uint mode) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
40 chmod(toStringz(path), mode);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
41 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
42
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
43
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
44 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
45 // Config - a data structure to accumulate configure information.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
46 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
47
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
48 enum Priority { User, Env, Project, System } // highest priority first
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
49 enum Use { Inc, Bin, Lib, Pkg }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
50
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
51 struct Config {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
52 int verboseConfigure;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
53 string buildLevel;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
54 string productVersion;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
55 string backgroundCopyright;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
56 string foregroundCopyright;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
57 string buildDir;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
58 bool[string] architectures;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
59 string[][Priority][Use] dirs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
60 string[][Use] prevDirs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
61 string[][string] bobVars;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
62 string[][string] runVars;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
63 string[][string] buildVars;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
64 string reason;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
65 string[] configureOptions;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
66 string srcDir;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
67 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
68
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
69 bool[string] barred;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
70
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
71
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
72 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
73 // Return the paths that the linker (ld) searches for libraries.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
74 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
75 string[] linkerSearchPaths() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
76 // Note 1: The method used is quite hacky and probably very non-portable.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
77 // Note 2: An alternative method (no less hacky) would parse the linker script
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
78 // for SEARCH_DIR commands.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
79 string improbable_name = "this_is_an_extremely_improbable_library_name";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
80 string command_base = "LIBRARY_PATH= LD_LIBRARY_PATH= ";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
81 command_base ~= "ld --verbose -lthis_is_an_extremely_improbable_library_name < /dev/null";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
82 // First command is to check that ld is working and giving the expected error message
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
83 // Something about the ld command means the output must be piped through something (e.g. "cat -")
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
84 // otherwise std.process.shell() will throw 'Could not close pipe'.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
85 string expected_message = "ld: cannot find -l" ~ improbable_name;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
86 string command_1 = command_base ~ " 2>&1 > /dev/null | cat -";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
87
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
88 // Second command is to get the output containing the paths that ld searches for libraries.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
89 string good_prefix = "attempt to open ";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
90 string good_suffix = "lib" ~ improbable_name ~ ".so failed";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
91 string command_2 = command_base ~ " 2> /dev/null | grep '^" ~ good_prefix ~ ".*" ~ good_suffix ~ "$'";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
92
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
93 string[] result;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
94 try {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
95 //writefln("command_1=%s\n", command_1);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
96 string[] ld_lines = std.string.splitLines(std.process.shell(command_1));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
97 //if (expected_message in ld_lines) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
98 bool success = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
99 foreach (line; ld_lines) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
100 if (line == expected_message) { success = true; break; }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
101 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
102 if (success) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
103 //writefln("command_2=%s\n", command_2);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
104 ld_lines = std.string.splitLines(std.process.shell(command_2));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
105 foreach (line; ld_lines) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
106 if (line.length > good_prefix.length + good_suffix.length + 1) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
107 if (line[0 .. good_prefix.length] == good_prefix &&
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
108 line[$-good_suffix.length .. $] == good_suffix) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
109 //writefln("Match: \"%s\"", line);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
110 result ~= line[good_prefix.length .. $-good_suffix.length-1];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
111 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
112 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
113 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
114 return result;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
115 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
116 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
117 writefln("Did not get expected output from ld...\ncommand=%s\noutput:", command_1);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
118 foreach (line; ld_lines) { writefln(line); }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
119 exit(1);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
120 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
121 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
122 catch (Exception ex) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
123 writefln("Error running ld: %s", ex);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
124 exit(1);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
125 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
126 assert(0); // TODO Why aren't the above exit() calls adequate to satisfy the compiler?
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
127 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
128
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
129
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
130 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
131 // Append some tokens to the end of a bob, run or build variable,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
132 // appending only if not already present and preserving order.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
133 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
134 private void appendVar(ref string[] strings, string[] extra) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
135 foreach (string item; extra) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
136 if (item in barred) continue;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
137 bool got = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
138 foreach (string have; strings) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
139 if (item == have) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
140 got = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
141 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
142 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
143 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
144 if (!got) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
145 strings ~= item;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
146 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
147 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
148 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
149 void appendBobVar(ref Config data, string var, string[] tokens) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
150 if (data.verboseConfigure >= 2) { writefln("appendBobVar: %s %s", var, tokens); }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
151 if (var !in data.bobVars) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
152 data.bobVars[var] = null;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
153 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
154 appendVar(data.bobVars[var], tokens);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
155 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
156 void appendRunVar(ref Config data, string var, string[] tokens) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
157 if (data.verboseConfigure >= 2) { writefln("appendRunVar: %s %s", var, tokens); }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
158 if (var !in data.runVars) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
159 data.runVars[var] = null;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
160 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
161 appendVar(data.runVars[var], tokens);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
162 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
163 void appendBuildVar(ref Config data, string var, string[] tokens) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
164 if (data.verboseConfigure >= 2) { writefln("appendBuildVar: %s %s", var, tokens); }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
165 if (var !in data.buildVars) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
166 data.buildVars[var] = null;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
167 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
168 appendVar(data.buildVars[var], tokens);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
169 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
170
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
171
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
172 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
173 // Return the join of paths with extra
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
174 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
175 string[] joins(string[] paths, string extra) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
176 string[] result;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
177 foreach (path; paths) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
178 result ~= buildPath(path, extra);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
179 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
180 return result;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
181 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
182
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
183
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
184 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
185 // Return a string array of tokens parsed from a number of environment variables, using ':' as delimiter.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
186 // Duplicated are discarded.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
187 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
188 string[] fromEnv(string[] variables) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
189 string[] result;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
190 bool[string] present;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
191 foreach (variable; variables) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
192 foreach (token; split(std.process.getenv(variable), ":")) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
193 if (token !in present) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
194 present[token] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
195 result ~= token;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
196 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
197 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
198 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
199 return result;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
200 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
201
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
202
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
203
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
204 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
205 // Return a string representing the given tokens as an environment variable declaration
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
206 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
207 string toEnv(string[][Priority] tokens, string name) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
208 string result;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
209 foreach (string[] strings; tokens) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
210 foreach (string token; strings) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
211 result ~= ":" ~ token;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
212 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
213 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
214 if (result && result[0] == ':') {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
215 result = result[1..$];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
216 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
217 if (result) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
218 result = name ~ "=\"" ~ result ~ "\"";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
219 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
220 return result;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
221 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
222
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
223
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
224 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
225 // Output (to console) the current search paths being used to locate dependencies.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
226 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
227 void printSearchDirs(ref string[][Priority][Use] dirs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
228 foreach (Use use, string[][Priority] v; dirs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
229 writefln("%s", use);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
230 foreach (Priority p, string[] a; v) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
231 writefln(" %s: %s", std.string.rightJustify(std.conv.to!string(p), 7), a);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
232 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
233 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
234 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
235
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
236
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
237 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
238 // Set project-specific directories to look in for required files
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
239 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
240 void setProjectDirs(ref Config data, string[][Use] projectDirs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
241 if (data.verboseConfigure >= 3) { writefln("Updating project search paths:"); }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
242 foreach (Use use, string[] dirs; projectDirs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
243 data.prevDirs[use] = dirs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
244 data.dirs[use][Priority.Project] = dirs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
245 if (data.verboseConfigure >= 3) { writefln("Project %s: %s", use, dirs); }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
246 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
247 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
248
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
249 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
250 // Restore project-specific dirs - only one level of restoration available
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
251 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
252 void restoreProjectDirs(ref Config data) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
253 if (data.verboseConfigure >= 3) { writefln("Restoring project search paths:"); }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
254 foreach (Use use, string[] dirs; data.prevDirs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
255 data.prevDirs[use] = dirs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
256 data.dirs[use][Priority.Project] = dirs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
257 if (data.verboseConfigure >= 3) { writefln("Project %s: %s", use, dirs); }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
258 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
259 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
260
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
261
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
262 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
263 // Locate an executable (which can have any of the specified names)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
264 // in any of the dirs listed in data.dirs[Use.Bin], and:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
265 // * set the executable name to bobVar id so bob can run it efficiently.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
266 // * add the dir to runVar PATH, providing acces to other exes in the same dir.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
267 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
268 string useExecutable(ref Config data, string id, string[] names) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
269 foreach (string[] dirs; data.dirs[Use.Bin]) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
270 foreach (string dir; dirs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
271 foreach (name; names) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
272 if (exists(buildPath(dir, name))) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
273 appendBobVar(data, id, [buildPath(dir, name)]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
274 appendRunVar(data, "PATH", [dir]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
275 if (data.verboseConfigure >= 1) { writefln("Found exe %s as %s in %s", id, name, dir); }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
276 return dir;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
277 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
278 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
279 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
280 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
281 data.reason ~= format("Could not find executable %s by names %s\n", id, names);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
282 return "";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
283 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
284
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
285
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
286 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
287 // Locate an include file in any of data.dirs[Use.Inc], and:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
288 // * add the header dir to bobVar HEADERS
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
289 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
290 string useHeader(ref Config data, string name) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
291 foreach (string[] dirs; data.dirs[Use.Inc]) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
292 foreach (string dir; dirs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
293 if (exists(buildPath(dir, name))) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
294 appendBobVar(data, "HEADERS", [dir]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
295 if (data.verboseConfigure >= 1) { writefln("Found header <%s> in %s", name, dir); }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
296 return dir;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
297 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
298 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
299 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
300 data.reason ~= "Could not find header " ~ name ~ "\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
301 return "";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
302 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
303
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
304
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
305 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
306 // Locate a library file in any of data.dirs[Use.Lib], and:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
307 // * add library dir to bobVar LINKFLAGS (with '-L' prefix)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
308 // * Not add library dir to buildVar LIBRARY_PATH (Not necessary if adding -L dir to LINKFLAGS)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
309 // * add library dir to runVar LD_LIBRARY_PATH
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
310 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
311 string useLibrary(ref Config data, string name) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
312 foreach (string[] dirs; data.dirs[Use.Lib]) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
313 foreach (string dir; dirs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
314 if (exists(buildPath(dir, name))) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
315 appendBobVar(data, "LINKFLAGS", ["-L" ~ dir]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
316 appendRunVar(data, "LD_LIBRARY_PATH", [dir]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
317 if (data.verboseConfigure >= 1) { writefln("Found library %s in %s", name, dir); }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
318 return dir;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
319 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
320 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
321 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
322 data.reason ~= "Could not find library " ~ name ~ "\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
323 return "";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
324 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
325
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
326
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
327 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
328 // Locate a package .pc file in any of data.dirs[Use.Pkg], and
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
329 // use pkg-config to:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
330 // * add library dir to bobVar LINKFLAGS
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
331 // * Not add library dir to buildVar LIBRARY_PATH (Not necessary if adding -L dir to LINKFLAGS)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
332 // * add library dir to runVar LD_LIBRARY_PATH
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
333 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
334 enum Constraint { Exists, AtLeast, Exact, Max }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
335 void usePackage(ref Config data,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
336 string name,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
337 Constraint constraint = Constraint.Exists,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
338 string ver = "") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
339 string[] constraints = ["--exists", "--atleast-version=", "--exact-version=", "--max-version="];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
340 try {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
341 string prefix = toEnv(data.dirs[Use.Pkg], "PKG_CONFIG_PATH");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
342
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
343 // disable use of "uninstalled" packages (which would otherwise silently be used in preference!)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
344 if (prefix && prefix.length != 0) { prefix ~= " "; }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
345 prefix ~= "PKG_CONFIG_DISABLE_UNINSTALLED=1";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
346
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
347 //writefln("prefix=%s", prefix);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
348
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
349 string command;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
350
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
351 command = prefix ~ " pkg-config " ~ constraints[constraint] ~ ver ~ " " ~ name;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
352 //writefln("command=%s", command);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
353 shell(command);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
354
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
355 command = prefix ~ " pkg-config --cflags " ~ name;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
356 //writefln("command=%s", command);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
357 string ccflags = shell(command);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
358 foreach (flag; split(ccflags)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
359 if (flag.length > 2 && flag[0..2] == "-I") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
360 appendBobVar(data, "HEADERS", [flag[2..$]]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
361 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
362 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
363 appendBobVar(data, "CCFLAGS", [flag]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
364 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
365 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
366
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
367 command = prefix ~ " pkg-config --libs-only-L " ~ name;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
368 //writefln("command=%s", command);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
369 string linkflags = shell(command);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
370 appendBobVar(data, "LINKFLAGS", split(linkflags));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
371 foreach (flag; split(linkflags)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
372 if (flag.length > 2 && flag[0..2] == "-L") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
373 //appendBuildVar(data, "LIBRARY_PATH", [flag[2..$]]); not necessary
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
374 appendRunVar(data, "LD_LIBRARY_PATH", [flag[2..$]]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
375 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
376 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
377
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
378 if (data.verboseConfigure >= 1) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
379 command = prefix ~ " pkg-config --modversion " ~ name;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
380 //writefln("command=%s", command);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
381 string modVersion = shell(command);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
382 writefln("Found package %s (v%s)", name, chomp(modVersion));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
383 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
384 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
385 catch (Exception ex) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
386 data.reason ~= "Could not find package " ~ constraints[constraint] ~ " " ~ ver ~ " " ~ name ~ "\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
387 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
388 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
389
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
390
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
391 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
392 // Locate a corba-tao library in any of data.dirs[Use.Lib], provide access to
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
393 // required TAO utilities, and set required variables.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
394 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
395 void useTao(ref Config data) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
396 string incdir = useHeader(data, "tao/corba.h");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
397
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
398 useLibrary(data, "libTAO.so");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
399
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
400 useExecutable(data, "TAO_IDL", ["tao_idl"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
401 useExecutable(data, "TAO_NAMING_SERVICE", ["Naming_Service"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
402 useExecutable(data, "TAO_EVENT_SERVICE", ["CosEvent_Service"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
403 useExecutable(data, "TAO_INTERFACE_REPO_SERVICE", ["IFR_Service"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
404 useExecutable(data, "TAO_INTERFACE_COMPILER", ["tao_ifr"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
405
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
406 appendBobVar(data, "IDL_HEADERS", [incdir]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
407 appendBobVar(data, "GENERATE_EMPTY_SERVANT", ["false"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
408 appendBobVar(data, "CCFLAGS", ["-DTAO_HAS_TYPED_EVENT_CHANNEL"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
409 appendRunVar(data, "ACE_ROOT", [dirName(incdir)]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
410 appendRunVar(data, "TAO_ROOT", [buildPath(dirName(incdir), "TAO")]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
411 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
412
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
413
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
414 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
415 // Parse command-line arguments and return resultant Config data
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
416 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
417 Config initialise(string[] args, string projectPackage) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
418
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
419 // check that we are in the project directory
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
420 if (!exists("configure.d")) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
421 writefln("Configure must be run from the project directory, which contains configure.d");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
422 exit(1);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
423 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
424
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
425 // parse arguments
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
426
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
427 bool help;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
428 int verboseConfigure;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
429 string buildLevel = "release";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
430 string productVersion = "development from " ~ getcwd;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
431 string[] architectures;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
432 string[] packagePrefixes;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
433
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
434 immutable bool[string] validArchitectures = ["Ubuntu":true, "CentOS-4":true, "CentOS-5":true];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
435
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
436 Config data;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
437 auto argsCopy = args.dup; // remember the arguments
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
438
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
439 try {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
440 getopt(args, std.getopt.config.caseSensitive,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
441 "help|h", &help,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
442 "verbose+", &verboseConfigure,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
443 "build", &buildLevel,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
444 "product|p", &productVersion,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
445 "architecture|a", &architectures,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
446 "package-prefix", &packagePrefixes);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
447 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
448 catch (Exception ex) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
449 writefln("Invalid argument(s): %s", ex.msg);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
450 help = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
451 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
452
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
453 if (help || args.length < 2) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
454 writefln("Usage: configure [options] build-dir-path\n"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
455 " --help display this message\n"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
456 " --verbose display more configure messages (multiple)\n"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
457 " --build=level build level: debug, integrate, release (default) or profile\n"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
458 " --product=version sets product version\n"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
459 " --architecture=arch sets architecture for conditional Bobfile rules (multiple)\n"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
460 " --package-prefix=path looks for locally installed packages at path (multiple)\n");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
461 exit(1);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
462 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
463 foreach (arch; architectures) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
464 if (arch !in validArchitectures) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
465 writefln("%s is not one of these valid architectures: %s",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
466 arch, validArchitectures.keys());
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
467 exit(1);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
468 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
469 data.architectures[arch] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
470 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
471
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
472 string buildDir = args[1];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
473
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
474
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
475 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
476 // populate and return config data
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
477 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
478
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
479 data.srcDir = std.file.getcwd();
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
480
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
481 foreach (arg; argsCopy[1..$]) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
482 if (arg != buildDir) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
483 data.configureOptions ~= arg;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
484 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
485 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
486
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
487 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
488 // populate and return config data
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
489 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
490
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
491 // Populate data.dirs using packagePrefixes, environment variables, hard-coding, etc.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
492 // The Pritority.Project elements are (re)populated via a call to setProjectDirs.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
493
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
494 // add some "standard" user-specific prefixes to packagePrefixes to make life easier for users
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
495 packagePrefixes ~= ["/opt/acacia/tao", "/opt/acacia/ecw"];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
496
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
497 // System - lowest priority
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
498 data.dirs[Use.Inc][Priority.System] = ["/include", "/usr/include"];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
499 data.dirs[Use.Bin][Priority.System] = ["/bin", "/sbin", "/usr/bin", "/usr/sbin"];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
500 data.dirs[Use.Lib][Priority.System] = linkerSearchPaths(); // ["/lib", "/usr/lib"];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
501 data.dirs[Use.Pkg][Priority.System] = null; // /usr/lib/pkgconfig is automatically used
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
502
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
503 // Prevent System paths from being added to the output
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
504 foreach (Use use, string[][Priority] v; data.dirs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
505 foreach (Priority p, string[] a; v) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
506 foreach (string b; a) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
507 barred[b] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
508 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
509 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
510 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
511 // Extra protection required for library paths
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
512 foreach (string v; data.dirs[Use.Lib][Priority.System]) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
513 barred["-L" ~ v] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
514 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
515
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
516 // Project - medium priority, set by call to setProjectDirs
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
517 data.dirs[Use.Inc][Priority.Project] = null;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
518 data.dirs[Use.Bin][Priority.Project] = null;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
519 data.dirs[Use.Lib][Priority.Project] = null;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
520 data.dirs[Use.Pkg][Priority.Project] = null;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
521
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
522 // Env - high priority
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
523 data.dirs[Use.Inc][Priority.Env] = fromEnv(["CPATH"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
524 data.dirs[Use.Bin][Priority.Env] = fromEnv(["PATH"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
525 data.dirs[Use.Lib][Priority.Env] = fromEnv(["LD_LIBRARY_PATH"/*, "LIBRARY_PATH"*/]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
526 data.dirs[Use.Pkg][Priority.Env] = fromEnv(["PKG_CONFIG_PATH"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
527
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
528 // User - highest priority
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
529 data.dirs[Use.Inc][Priority.User] = joins(packagePrefixes, "include");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
530 data.dirs[Use.Bin][Priority.User] = joins(packagePrefixes, "bin");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
531 data.dirs[Use.Lib][Priority.User] = joins(packagePrefixes, "lib");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
532 data.dirs[Use.Pkg][Priority.User] = joins(packagePrefixes, "lib/pkgconfig");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
533
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
534 // Print the search paths (better to do this elsewhere/when)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
535 if (verboseConfigure >= 3) { writefln("Initial search paths:"); printSearchDirs(data.dirs); }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
536
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
537 // assorted variables
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
538
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
539 data.verboseConfigure = verboseConfigure;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
540 data.buildLevel = buildLevel;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
541 data.productVersion = productVersion;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
542 // TODO? Automatically insert the current year?
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
543 data.backgroundCopyright =
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
544 "Part or all of this software is © Copyright 1995-2011 Acacia Research Pty Ltd. "
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
545 "All rights reserved.\\n"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
546 "This software may utilise third party libraries from various sources.\\n"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
547 "These libraries are copyrighted by their respective owners.";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
548 data.foregroundCopyright =
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
549 "Parts of this software are foreground intellectual property. ";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
550
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
551 data.buildDir = buildDir;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
552
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
553 appendBobVar(data, "PROJECT-PACKAGE", [projectPackage]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
554
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
555 appendBobVar(data, "LINKFLAGS", ["-lstdc++", "-rdynamic"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
556
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
557 appendBobVar(data, "DEXTERNALS", ["std", "core"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
558
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
559 appendBobVar(data, "DFLAGS", ["-w", "-wi"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
560
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
561 appendBobVar(data, "CCFLAGS",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
562 ["-fPIC",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
563 "-pedantic",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
564 "-Werror",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
565 "-Wall",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
566 "-Wno-long-long",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
567 "-Wundef",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
568 "-Wredundant-decls"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
569
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
570 if (data.buildLevel == "debug") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
571 appendBobVar(data, "DFLAGS", ["-gc"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
572 appendBobVar(data, "CCFLAGS",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
573 ["-O1",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
574 "-DACRES_DEBUG=1",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
575 "-DACRES_INTEGRATE=1",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
576 "-fno-omit-frame-pointer",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
577 "-ggdb3"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
578 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
579 else if (data.buildLevel == "integrate") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
580 appendBobVar(data, "DFLAGS", ["-O"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
581 appendBobVar(data, "CCFLAGS",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
582 ["-O1",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
583 "-DACRES_DEBUG=0",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
584 "-DACRES_INTEGRATE=1",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
585 "-DNDEBUG",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
586 "-fno-omit-frame-pointer",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
587 "-Wno-unused-variable"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
588 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
589 else if (data.buildLevel == "profile") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
590 appendBobVar(data, "DFLAGS", ["-O"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
591 appendBobVar(data, "CCFLAGS",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
592 ["-O2",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
593 "-DACRES_DEBUG=0",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
594 "-DACRES_INTEGRATE=0",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
595 "-DNDEBUG",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
596 "-fno-omit-frame-pointer",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
597 "-Wno-unused-variable",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
598 "-ggdb3"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
599 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
600 else if (data.buildLevel == "release") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
601 appendBobVar(data, "DFLAGS", ["-O", "-release"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
602 appendBobVar(data, "CCFLAGS",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
603 ["-O2",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
604 "-DACRES_DEBUG=0",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
605 "-DACRES_INTEGRATE=0",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
606 "-DNDEBUG",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
607 "-fno-omit-frame-pointer",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
608 "-Wno-unused-variable"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
609 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
610 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
611 writefln("unsupported build level '%s'", data.buildLevel);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
612 exit(1);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
613 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
614
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
615 appendBobVar(data, "C++FLAGS",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
616 ["-Woverloaded-virtual",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
617 "-Wsign-promo",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
618 "-Wctor-dtor-privacy",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
619 "-Wnon-virtual-dtor"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
620
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
621 appendBobVar(data, "VALID_ARCHITECTURES", validArchitectures.keys);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
622 appendBobVar(data, "ARCHITECTURES", architectures);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
623
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
624 useExecutable(data, "RST2HTML", ["rst2html.py", "rst2html", "docutils-rst2html.py"]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
625
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
626 appendRunVar(data, "LD_LIBRARY_PATH", [`${DIST_PATH}/lib`]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
627 appendRunVar(data, "LD_LIBRARY_PATH", [`${DIST_PATH}/lib/plugins`]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
628 appendRunVar(data, "SYSTEM_DATA_PATH", [`${DIST_PATH}/data`]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
629 appendRunVar(data, "PATH", [`${DIST_PATH}/bin`]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
630
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
631 return data;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
632 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
633
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
634
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
635 // Write the content to the file if file doesn't already match (and optionally set executable).
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
636 // File is created if it doesn't exist.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
637 void update(ref Config data, string name, string content, bool executable) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
638 string path = buildPath(data.buildDir, name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
639 bool clean = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
640 if (exists(path)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
641 string current = cast(string) std.file.read(path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
642 clean = (current == content);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
643 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
644 if (!clean) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
645 if (data.verboseConfigure >= 2) { writefln("Setting content of %s", name); }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
646 std.file.write(path, content);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
647 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
648 if (executable) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
649 uint exeMode = octal!700;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
650 uint attr = getAttributes(path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
651 if ((attr & exeMode) != exeMode) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
652 if (data.verboseConfigure >= 4) { writefln("Setting exe mode on %s", name); }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
653 setMode(path, exeMode | attr);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
654 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
655 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
656 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
657
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
658
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
659 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
660 // Set up build environment as specified by data, or issue error messages and bail
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
661 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
662 // repos are repository names in sibling directories to the directory containing
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
663 // the configure script.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
664 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
665 void finalise(ref Config data, string[] otherRepos) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
666
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
667 // check that all is well, and bail with an explanation if not
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
668 if (data.reason.length) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
669 writefln("Configure FAILED because:\n%s\n", data.reason);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
670 exit(1);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
671 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
672
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
673 writefln("Configure checks completed ok - establishing build directory...");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
674
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
675 // create build directory
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
676 if (!exists(data.buildDir)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
677 mkdirRecurse(data.buildDir);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
678 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
679 else if (!isDir(data.buildDir)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
680 writefln("Configure FAILED because: %s is not a directory", data.buildDir);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
681 exit(1);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
682 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
683
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
684 // create Boboptions file from bobVars
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
685 string bobText;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
686 foreach (string key, string[] tokens; data.bobVars) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
687 bobText ~= key ~ " = ";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
688 if (key == "C++FLAGS") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
689 // C++FLAGS has all of CCFLAGS too
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
690 foreach (token; data.bobVars["CCFLAGS"]) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
691 bobText ~= token ~ " ";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
692 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
693 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
694 foreach (token; tokens) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
695 bobText ~= token ~ " ";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
696 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
697 bobText ~= ";\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
698 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
699 update(data, "Boboptions", bobText, false);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
700
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
701 // create version_info.h file
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
702 string versionText;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
703 versionText ~= "#ifndef VERSION_INFO__H\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
704 versionText ~= "#define VERSION_INFO__H\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
705 versionText ~= "\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
706 versionText ~= "#define PRODUCT_VERSION \"" ~ data.productVersion ~ "\"\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
707 versionText ~= "#define FOREGROUND_IP_COPYRIGHT_NOTICE \"" ~ data.foregroundCopyright ~ "\"\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
708 versionText ~= "#define BACKGROUND_IP_COPYRIGHT_NOTICE \"" ~ data.backgroundCopyright ~ "\"\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
709 versionText ~= "\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
710 versionText ~= "#endif /* VERSION_INFO__H */\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
711 update(data, "version_info.h", versionText, false);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
712
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
713 // set up string for a fix_env bash function
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
714 string fixText =
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
715 `# Remove duplicates and empty tokens from a string containing
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
716 # colon-separated tokens, preserving order.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
717 function fix_env () {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
718 local original="${1}"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
719 local IFS=':'
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
720 local result=""
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
721 for item in ${original}; do
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
722 if [ -z "${item}" ]; then
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
723 continue
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
724 fi
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
725 #echo "item: \"${item}\"" >&2
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
726 local -i found_existing=0
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
727 for existing in ${result}; do
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
728 if [ "${item}" == "${existing}" ]; then
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
729 found_existing=1
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
730 break 1
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
731 fi
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
732 done
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
733 if [ ${found_existing} -eq 0 ]; then
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
734 result="${result:+${result}:}${item}"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
735 fi
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
736 done
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
737 echo "${result}"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
738 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
739 `;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
740
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
741 // create environment-run file
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
742 string runEnvText;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
743 runEnvText ~= "# set up the run environment variables\n\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
744 runEnvText ~= fixText;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
745 runEnvText ~= `if [ -z "${DIST_PATH}" ]; then` ~ "\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
746 runEnvText ~= ` echo "DIST_PATH not set"` ~ "\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
747 runEnvText ~= " return 1\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
748 runEnvText ~= "fi\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
749 runEnvText ~= "\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
750 foreach (string key, string[] tokens; data.runVars) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
751 runEnvText ~= "export " ~ key ~ `="$(fix_env "`;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
752 foreach (token; tokens) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
753 runEnvText ~= token ~ ":";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
754 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
755 runEnvText ~= `${` ~ key ~ `}")"` ~ "\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
756 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
757 runEnvText ~= "unset fix_env\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
758 update(data, "environment-run", runEnvText, false);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
759
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
760
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
761 // create environment-build file
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
762 string buildEnvText;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
763 buildEnvText ~= "# set up the build environment variables\n\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
764 buildEnvText ~= fixText;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
765 buildEnvText ~=
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
766 `if [ ! -z "${DIST_PATH}" ]; then
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
767 echo "ERROR: DIST_PATH set when building"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
768 return 1
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
769 fi
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
770 export DIST_PATH="${PWD}/dist"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
771 `;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
772 foreach (string key, string[] tokens; data.buildVars) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
773 buildEnvText ~= "export " ~ key ~ `="$(fix_env "`;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
774 foreach (token; tokens) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
775 buildEnvText ~= token ~ ":";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
776 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
777 buildEnvText ~= `${` ~ key ~ `}")"` ~ "\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
778 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
779 buildEnvText ~= "unset fix_env\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
780 buildEnvText ~= "# also pull in the run environment\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
781 buildEnvText ~= "source ./environment-run\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
782 update(data, "environment-build", buildEnvText, false);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
783
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
784
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
785 // create build script
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
786 string buildText =
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
787 `#!/bin/bash
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
788
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
789 source ./environment-build
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
790
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
791 # Rebuild the bob executable if necessary
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
792 BOB_SRC="./src/build-tool/bob.d"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
793 BOB_EXE="./.bob/bob"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
794 if [ ! -e ${BOB_EXE} -o ${BOB_SRC} -nt ${BOB_EXE} ]; then
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
795 echo "Compiling build tool."
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
796 dmd -O -gc -w -wi ${BOB_SRC} -of${BOB_EXE}
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
797 if [ $? -ne 0 ]; then
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
798 echo "Failed to compile the build tool..."
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
799 exit 1
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
800 else
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
801 echo "Build tool compiled successfully."
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
802 fi
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
803 fi
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
804
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
805 # Test if we are running under eclipse
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
806 # Cause bob to echo commands passed to compiler to support eclipse auto discovery.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
807 # Also change the include directives to those recognised by eclipse CDT.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
808 if [ "$1" = "--eclipse" ] ; then
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
809 shift
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
810 echo "NOTE: What is displayed here on the console is not exactly what is executed by g++"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
811
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
812 ${BOB_EXE} --actions "$@" 2>&1 | sed -re "s/-iquote|-isystem/-I/g"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
813 else
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
814 ${BOB_EXE} "$@"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
815 fi
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
816 `;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
817 update(data, "build", buildText, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
818
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
819
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
820 // create clean script
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
821 string cleanText =
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
822 `#!/bin/bash
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
823
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
824 if [ $# -eq 0 ]; then
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
825 rm -rf ./dist ./priv ./obj
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
826 else
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
827 echo "Failed: $(basename ${0}) does not accept arguments - it cleans everything."
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
828 exit 2
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
829 fi
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
830 `;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
831 update(data, "clean", cleanText, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
832
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
833
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
834 // strings containing common parts of run-like scripts
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
835 string runPrologText =
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
836 `#!/bin/bash
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
837
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
838 export DIST_PATH="${PWD}/dist"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
839 source ./environment-run
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
840 exe=$(which "$1" 2> /dev/null)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
841
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
842 if [ -z "${exe}" ]; then
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
843 echo "Couldn't find \"$1\"" >&2
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
844 exit 1
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
845 fi
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
846 export TMP_PATH="$(dirname ${exe})/tmp-$(basename ${exe})"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
847 `;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
848
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
849
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
850 // create (exuberant) ctags config file
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
851 string dotCtagsText =
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
852 `--langdef=IDL
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
853 --langmap=IDL:+.idl
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
854 --regex-IDL=/^[ \t]*module[ \t]+([a-zA-Z0-9_]+)/\1/n,module,Namespace/e
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
855 --regex-IDL=/^[ \t]*enum[ \t]+([a-zA-Z0-9_]+)/\1/g,enum/e
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
856 --regex-IDL=/^[ \t]*struct[ \t]+([a-zA-Z0-9_]+)/\1/c,struct/e
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
857 --regex-IDL=/^[ \t]*exception[ \t]+([a-zA-Z0-9_]+)/\1/c,exception/e
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
858 --regex-IDL=/^[ \t]*interface[ \t]+([a-zA-Z0-9_]+)/\1/c,interface/e
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
859 --regex-IDL=/^[ \t]*typedef[ \t]+[a-zA-Z0-9_:\*<> \t]+[ \t]+([a-zA-Z0-9_]+)[ \t]*;/\1/t,typedef/e
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
860 --regex-IDL=/^[ \t]*[a-zA-Z0-9_:]+[ \t]+([a-zA-Z0-9_]+)[ \t]*[;]/\1/v,variable/e
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
861 `;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
862 update(data, ".ctags", dotCtagsText, false);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
863
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
864
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
865 // create make-tags script
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
866 string makeCtagsText =
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
867 `#!/bin/bash
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
868
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
869 SOURCE_DIR="src"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
870 TAGS_FILE="tags"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
871
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
872 find -H "${SOURCE_DIR}"/* -xdev \( \( -type d -name \.svn \) -prune \
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
873 -o -name \*.cc -o -name \*.h -o -name \*.ccg -o -name \*.hg -o -name \*.hpp -o -name \*.cpp \
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
874 -o -name \*.inl -o -name \*.i \
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
875 -o -name \*.idl \) |
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
876 grep -v ".svn" |
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
877 # maybe add other grep commands here
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
878 ctags -f "${TAGS_FILE}" -h default --langmap="c++:+.hg.ccg.inl.i" --extra=+f+q --c++-kinds=+p --tag-relative=yes --totals=yes --fields=+i -L -
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
879 `;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
880 update(data, "make-tags", makeCtagsText, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
881
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
882
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
883 // create make-cooked-tags script
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
884 string makeCookedCtagsText =
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
885 `#!/bin/bash
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
886
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
887 SOURCE_DIR="obj"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
888 TAGS_FILE="cooked-tags"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
889
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
890 find -H "${SOURCE_DIR}"/* -xdev \( \( -type d -name \.svn \) -prune \
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
891 -o -name \*.cc -o -name \*.h -o -name \*.ccg -o -name \*.hg -o -name \*.hpp -o -name \*.cpp \
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
892 -o -name \*.idl \) |
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
893 grep -v ".svn" |
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
894 # maybe add other grep commands here
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
895 ctags -f "${TAGS_FILE}" -h default --langmap="c++:+.hg.ccg" --extra=+f+q --c++-kinds=+p --tag-relative=yes --totals=yes --fields=+i -L -
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
896 `;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
897 update(data, "make-cooked-ctags", makeCookedCtagsText, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
898
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
899
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
900 // create test script
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
901 string testText;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
902 testText ~= runPrologText;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
903 testText ~=
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
904 `
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
905 if [ $# -ne 1 ]; then
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
906 echo "The test script doesn't support arguments to test executable." >&2
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
907 echo "Given: ${@}" >&2
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
908 exit 2
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
909 fi
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
910 declare -i return_value=1
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
911
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
912 run_test() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
913 # remove results and run the test to make some more
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
914 set -o pipefail
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
915 rm -f ${exe}-*
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
916
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
917 # Ensure the result file is not zero-length (Bob depends on this)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
918 echo ${exe} > ${exe}-result
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
919 ${exe} >> ${exe}-result 2>&1
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
920
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
921 # generate passed or failed file
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
922 if [ "$?" != "0" ]; then
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
923 mv ${exe}-result ${exe}-failed
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
924 echo "${exe}-failed:1: error: test failed"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
925 cat ${exe}-failed
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
926 exit 1
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
927 else
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
928 mv ${exe}-result ${exe}-passed
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
929 rm -rf ${TMP_PATH}
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
930 fi
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
931 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
932
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
933 rm -rf ${TMP_PATH} && mkdir ${TMP_PATH} && run_test
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
934 `;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
935 update(data, "test", testText, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
936
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
937
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
938 // create run script
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
939 string runText;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
940 runText ~= runPrologText;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
941 runText ~= "rm -rf ${TMP_PATH} && mkdir ${TMP_PATH} && exec \"$@\"";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
942 update(data, "run", runText, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
943
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
944 if (data.buildLevel == "profile") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
945 // create perf script
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
946 string perfText;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
947 perfText ~= runPrologText;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
948 perfText ~= "echo after exiting, run 'perf report' to see the result\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
949 perfText ~= "rm -rf ${TMP_PATH} && mkdir ${TMP_PATH} && exec perf record -g -f $@\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
950 update(data, "perf", perfText, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
951 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
952
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
953 if (data.buildLevel != "release") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
954 // create gdb script
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
955 string gdbText;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
956 gdbText ~= runPrologText;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
957 gdbText ~= "rm -rf ${TMP_PATH} && mkdir ${TMP_PATH} && exec gdb --args $@\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
958 update(data, "gdb", gdbText, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
959
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
960 // create nemiver script
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
961 string nemiverText;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
962 nemiverText ~= runPrologText;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
963 nemiverText ~= "rm -rf ${TMP_PATH} && mkdir ${TMP_PATH} && exec nemiver $@\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
964 update(data, "nemiver", nemiverText, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
965 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
966
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
967 // create valgrind script
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
968 string valgrindText;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
969 valgrindText ~= runPrologText;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
970 valgrindText ~= "rm -rf ${TMP_PATH} && mkdir ${TMP_PATH} && exec valgrind $@\n";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
971 update(data, "valgrind", valgrindText, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
972
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
973
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
974 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
975 // create src directory with symbolic links to all top-level packages in all
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
976 // specified repositories
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
977 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
978
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
979 // make src dir
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
980 string srcPath = buildPath(data.buildDir, "src");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
981 if (!exists(srcPath)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
982 mkdir(srcPath);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
983 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
984
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
985 // make a symbolic link to each top-level package in this and other specified repos
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
986 string[string] pkgPaths; // package paths keyed on package name
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
987 string project = dirName(getcwd);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
988 foreach (string repoName; otherRepos ~ baseName(getcwd)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
989 string repoPath = buildPath(project, repoName);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
990 if (isDir(repoPath)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
991 //writefln("adding source links for packages in repo %s", repoName);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
992 foreach (string path; dirEntries(repoPath, SpanMode.shallow)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
993 string pkgName = baseName(path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
994 if (isDir(path) && pkgName[0] != '.') {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
995 //writefln(" found top-level package %s", pkgName);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
996 assert(pkgName !in pkgPaths,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
997 format("Package %s found at %s and %s",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
998 pkgName, pkgPaths[pkgName], path));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
999 pkgPaths[pkgName] = path;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1000 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1001 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1002 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1003 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1004 foreach (name, path; pkgPaths) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1005 string linkPath = buildPath(srcPath, name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1006 system(format("rm -f %s; ln -sn %s %s", linkPath, path, linkPath));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1007 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1008
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1009 // print success
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1010 writefln("Build environment in %s is ready to roll", data.buildDir);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1011 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1012