| 1 |
#!/usr/bin/env dmd -run |
|---|
| 2 |
/+ |
|---|
| 3 |
To run this program, and see usage options, use this command: |
|---|
| 4 |
|
|---|
| 5 |
dmd -run cairooo-build.d --help |
|---|
| 6 |
|
|---|
| 7 |
If "dmd -run ..." does not work or produces errors, then use the |
|---|
| 8 |
following: |
|---|
| 9 |
|
|---|
| 10 |
build -clean cairooo-build.d |
|---|
| 11 |
cairooo-build --help |
|---|
| 12 |
+/ |
|---|
| 13 |
/** |
|---|
| 14 |
* Object-oriented cairo binding for D build script |
|---|
| 15 |
* |
|---|
| 16 |
* Copyright: © 2006 Daniel Keep |
|---|
| 17 |
* License: BSD <http://www.opensource.org/licenses/bsd-license.php> |
|---|
| 18 |
*/ |
|---|
| 19 |
/* |
|---|
| 20 |
* Copyright (c) 2006 Daniel Keep |
|---|
| 21 |
* All rights reserved. |
|---|
| 22 |
* |
|---|
| 23 |
* Redistribution and use in source and binary forms, with or without |
|---|
| 24 |
* modification, are permitted provided that the following conditions are |
|---|
| 25 |
* met: |
|---|
| 26 |
* |
|---|
| 27 |
* * Redistributions of source code must retain the above copyright |
|---|
| 28 |
* notice, this list of conditions and the following disclaimer. |
|---|
| 29 |
* |
|---|
| 30 |
* * Redistributions in binary form must reproduce the above copyright |
|---|
| 31 |
* notice, this list of conditions and the following disclaimer in the |
|---|
| 32 |
* documentation and/or other materials provided with the distribution. |
|---|
| 33 |
* |
|---|
| 34 |
* * Neither the name of this software, nor the names of its contributors |
|---|
| 35 |
* may be used to endorse or promote products derived from this software |
|---|
| 36 |
* without specific prior written permission. |
|---|
| 37 |
* |
|---|
| 38 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|---|
| 39 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
|---|
| 40 |
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|---|
| 41 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|---|
| 42 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|---|
| 43 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|---|
| 44 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|---|
| 45 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|---|
| 46 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|---|
| 47 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|---|
| 48 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 49 |
*/ |
|---|
| 50 |
module cairooo_build; |
|---|
| 51 |
import util.script; |
|---|
| 52 |
mixin Script; |
|---|
| 53 |
|
|---|
| 54 |
/* ************************************************************************* */ |
|---|
| 55 |
|
|---|
| 56 |
const SCRIPT_NAME = "Object oriented cairo binding build script"; |
|---|
| 57 |
|
|---|
| 58 |
const Target |
|---|
| 59 |
TARGET_CAIRO = {name:"cairooo", type:"lib", target:"lib/cairooo", |
|---|
| 60 |
sources:["cairooo/all.d"]}, |
|---|
| 61 |
TARGET_GLITZ = {name:"glitzoo", type:"lib", target:"lib/cairooo_glitz", |
|---|
| 62 |
sources:["cairooo/glitz/all.d"]}, |
|---|
| 63 |
TARGET_PNG = {name:"pngoo", type:"lib", target:"lib/cairooo_png", |
|---|
| 64 |
sources:["cairooo/png/all.d"]}, |
|---|
| 65 |
TARGET_WIN32 = {name:"win32oo", type:"lib", target:"lib/cairooo_win32", |
|---|
| 66 |
flags:["-Xwin32"], sources:["cairooo/win32/all.d"]}, |
|---|
| 67 |
TARGET_WIN32_DFL = {name:"win32oo-dfl", type:"lib", |
|---|
| 68 |
target:"lib/cairooo_win32_dfl", |
|---|
| 69 |
flags:["-Xwin32","-Xdfl","-version=cairo_dfl"], |
|---|
| 70 |
sources:["cairooo/win32/all.d"]}, |
|---|
| 71 |
TARGET_XLIB = {name:"xliboo", type:"lib", target:"lib/cairooo_xlib", |
|---|
| 72 |
sources:["cairooo/xlib/all.d"]}, |
|---|
| 73 |
TARGET_EXTRA = {name:"extra", type:"lib", target:"lib/cairooo_extra", |
|---|
| 74 |
sources:["cairooo/extra/all.d"]}; |
|---|
| 75 |
|
|---|
| 76 |
version(Windows) |
|---|
| 77 |
const Target |
|---|
| 78 |
TARGET_ALL = {name:"all", type:"dummy", |
|---|
| 79 |
deps:[&TARGET_CAIRO, &TARGET_GLITZ, &TARGET_PNG, &TARGET_WIN32, |
|---|
| 80 |
&TARGET_EXTRA]}; |
|---|
| 81 |
version(linux) |
|---|
| 82 |
const Target |
|---|
| 83 |
TARGET_ALL = {name:"all", type:"dummy", |
|---|
| 84 |
deps:[&TARGET_CAIRO, &TARGET_GLITZ, &TARGET_PNG, &TARGET_XLIB, |
|---|
| 85 |
&TARGET_EXTRA]}; |
|---|
| 86 |
|
|---|
| 87 |
const Target[] TARGETS = |
|---|
| 88 |
[TARGET_ALL, TARGET_PNG, TARGET_CAIRO, TARGET_GLITZ, TARGET_WIN32, |
|---|
| 89 |
TARGET_WIN32_DFL, TARGET_XLIB, TARGET_EXTRA]; |
|---|
| 90 |
const DEFAULT_TARGET = &TARGET_ALL; |
|---|
| 91 |
const DEBUG_TARGET_SUFFIX = "_debug"; |
|---|
| 92 |
|
|---|
| 93 |
const char[][] FLAGS = ["-allobj","-cleanup"]; |
|---|
| 94 |
const char[][] FLAGS_DEBUG = ["-debug","-unittest","-version=Unittest","-g"]; |
|---|
| 95 |
const char[][] FLAGS_RELEASE = ["-release","-inline","-O"]; |
|---|
| 96 |
|
|---|
| 97 |
/* ************************************************************************* */ |
|---|
| 98 |
|
|---|
| 99 |
struct Target |
|---|
| 100 |
{ |
|---|
| 101 |
char[] name; |
|---|
| 102 |
char[] type; /// "exe", "lib" or "dummy" |
|---|
| 103 |
char[] target; |
|---|
| 104 |
char[][] sources = []; |
|---|
| 105 |
char[][] flags = []; |
|---|
| 106 |
Target*[] deps = []; |
|---|
| 107 |
|
|---|
| 108 |
int |
|---|
| 109 |
opCmp(Target other) |
|---|
| 110 |
{ |
|---|
| 111 |
return std.string.cmp(this.name, other.name); |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
int |
|---|
| 115 |
opEquals(Target other) |
|---|
| 116 |
{ |
|---|
| 117 |
return cast(int) (std.string.cmp(this.name, other.name) == 0); |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
char[] |
|---|
| 121 |
toString() |
|---|
| 122 |
{ |
|---|
| 123 |
return this.name; |
|---|
| 124 |
} |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
char[][] |
|---|
| 128 |
names(Target[] ts) |
|---|
| 129 |
{ |
|---|
| 130 |
char[][] result; |
|---|
| 131 |
foreach( t ; ts ) |
|---|
| 132 |
{ |
|---|
| 133 |
result.pushBack(t.name); |
|---|
| 134 |
} |
|---|
| 135 |
return result; |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
static |
|---|
| 139 |
this() |
|---|
| 140 |
{ |
|---|
| 141 |
TARGETS.sort; |
|---|
| 142 |
} |
|---|
| 143 |
|
|---|
| 144 |
void |
|---|
| 145 |
showHelp() |
|---|
| 146 |
{ |
|---|
| 147 |
echof( |
|---|
| 148 |
`%s |
|---|
| 149 |
Usage: |
|---|
| 150 |
%s [OPTIONS] [TARGET...] |
|---|
| 151 |
|
|---|
| 152 |
Options: |
|---|
| 153 |
--debug Add debugging code, symbols and unit tests. |
|---|
| 154 |
--release Strip out debug code, and enable optimisations. |
|---|
| 155 |
--verbose Verbose script commands. |
|---|
| 156 |
--very-verbose Verbose script AND toolchain commands. |
|---|
| 157 |
--help This message. |
|---|
| 158 |
|
|---|
| 159 |
Supported targets: |
|---|
| 160 |
%s |
|---|
| 161 |
|
|---|
| 162 |
The default target is "%s".`, |
|---|
| 163 |
SCRIPT_NAME, |
|---|
| 164 |
"dmd -run cairooo-build.d", |
|---|
| 165 |
std.string.join(names(TARGETS), ", "), |
|---|
| 166 |
DEFAULT_TARGET.name); |
|---|
| 167 |
} |
|---|
| 168 |
|
|---|
| 169 |
bool |
|---|
| 170 |
contains(Target[] ts, Target value) |
|---|
| 171 |
{ |
|---|
| 172 |
foreach( t ; ts ) |
|---|
| 173 |
if( t == value ) |
|---|
| 174 |
return true; |
|---|
| 175 |
return false; |
|---|
| 176 |
} |
|---|
| 177 |
|
|---|
| 178 |
template pushBack(T) |
|---|
| 179 |
{ |
|---|
| 180 |
void |
|---|
| 181 |
pushBack(inout T[] a, T value) |
|---|
| 182 |
{ |
|---|
| 183 |
a.length = a.length + 1; |
|---|
| 184 |
a[$-1] = value; |
|---|
| 185 |
} |
|---|
| 186 |
} |
|---|
| 187 |
|
|---|
| 188 |
int |
|---|
| 189 |
main(char[][] args) |
|---|
| 190 |
{ |
|---|
| 191 |
bool debugVersion = false; |
|---|
| 192 |
bool veryVerbose = false; |
|---|
| 193 |
char[][] targetNames; |
|---|
| 194 |
|
|---|
| 195 |
// Check for flags |
|---|
| 196 |
foreach( arg ; args[1..$] ) |
|---|
| 197 |
{ |
|---|
| 198 |
if( arg == "--debug" ) |
|---|
| 199 |
debugVersion = true; |
|---|
| 200 |
else if( arg == "--release" ) |
|---|
| 201 |
debugVersion = false; |
|---|
| 202 |
else if( arg == "--verbose" ) |
|---|
| 203 |
verboseCommands = true; |
|---|
| 204 |
else if( arg == "--very-verbose" ) |
|---|
| 205 |
veryVerbose = true; |
|---|
| 206 |
else if( arg == "--help" ) |
|---|
| 207 |
{ |
|---|
| 208 |
showHelp(); |
|---|
| 209 |
return 0; |
|---|
| 210 |
} |
|---|
| 211 |
else if( arg[0..2] == "--" ) |
|---|
| 212 |
{ |
|---|
| 213 |
echof("Unknown argument: %s", arg); |
|---|
| 214 |
return 2; |
|---|
| 215 |
} |
|---|
| 216 |
else |
|---|
| 217 |
targetNames.pushBack(arg); |
|---|
| 218 |
} |
|---|
| 219 |
|
|---|
| 220 |
if( targetNames.length == 0 ) |
|---|
| 221 |
targetNames.pushBack(DEFAULT_TARGET.name); |
|---|
| 222 |
|
|---|
| 223 |
// Ok, build list of targets to build |
|---|
| 224 |
Target[] targets; |
|---|
| 225 |
|
|---|
| 226 |
TargetNames: |
|---|
| 227 |
foreach( targetName ; targetNames ) |
|---|
| 228 |
{ |
|---|
| 229 |
foreach( target ; TARGETS ) |
|---|
| 230 |
{ |
|---|
| 231 |
if( target.name == targetName ) |
|---|
| 232 |
{ |
|---|
| 233 |
if( !targets.contains(target) && target.type != "dummy" ) |
|---|
| 234 |
targets.pushBack(target); |
|---|
| 235 |
|
|---|
| 236 |
foreach( deptarget ; target.deps ) |
|---|
| 237 |
if( !targets.contains(*deptarget) |
|---|
| 238 |
&& deptarget.type != "dummy" ) |
|---|
| 239 |
targets.pushBack(*deptarget); |
|---|
| 240 |
|
|---|
| 241 |
continue TargetNames; |
|---|
| 242 |
} |
|---|
| 243 |
} |
|---|
| 244 |
} |
|---|
| 245 |
|
|---|
| 246 |
// Ok, start building! |
|---|
| 247 |
foreach( target ; targets ) |
|---|
| 248 |
{ |
|---|
| 249 |
if( verboseCommands ) echof(`Building target "%s"...`, target.name); |
|---|
| 250 |
|
|---|
| 251 |
// Build list of flags |
|---|
| 252 |
char[][] flags; |
|---|
| 253 |
flags ~= FLAGS; |
|---|
| 254 |
if( debugVersion ) |
|---|
| 255 |
flags ~= FLAGS_DEBUG; |
|---|
| 256 |
else |
|---|
| 257 |
flags ~= FLAGS_RELEASE; |
|---|
| 258 |
|
|---|
| 259 |
switch( target.type ) |
|---|
| 260 |
{ |
|---|
| 261 |
case "exe": |
|---|
| 262 |
flags ~= "-nolib"; |
|---|
| 263 |
break; |
|---|
| 264 |
|
|---|
| 265 |
case "lib": |
|---|
| 266 |
flags ~= "-lib"; |
|---|
| 267 |
break; |
|---|
| 268 |
} |
|---|
| 269 |
|
|---|
| 270 |
if( debugVersion ) |
|---|
| 271 |
flags ~= "-T" ~ target.target ~ DEBUG_TARGET_SUFFIX; |
|---|
| 272 |
else |
|---|
| 273 |
flags ~= "-T" ~ target.target; |
|---|
| 274 |
|
|---|
| 275 |
if( veryVerbose ) |
|---|
| 276 |
flags ~= "-v"; |
|---|
| 277 |
|
|---|
| 278 |
// Do the build |
|---|
| 279 |
build(flags ~ target.flags ~ target.sources); |
|---|
| 280 |
} |
|---|
| 281 |
|
|---|
| 282 |
return 0; |
|---|
| 283 |
} |
|---|