root/trunk/cairo/cairo-build.d

Revision 228, 8.4 kB (checked in by DRK, 4 years ago)

* Updated the bindings to support cairo 1.2 and cairo 1.4. Support for these can be enabled with the cairo_1_2 and cairo_1_4 version identifiers.
* Added pdf, ps and svg support.
* Updated the build script appropriately.
* Note that cairooo is not likely to receive any further updates in its current form. It is being forked and rewritten for Tango's graphics package, although a port back to Phobos isn't out of the question.

Line 
1 #!/usr/bin/env dmd -run
2 /+
3     To run this program, and see usage options, use this command:
4
5     dmd -run cairo-build.d --help
6
7     If "dmd -run ..." does not work or produces errors, then use the
8     following:
9
10     build -clean cairo-build.d
11     cairo-build --help
12 +/
13 /**
14  * 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 cairo_build;
51 import util.script;
52 mixin Script;
53
54 /* ************************************************************************* */
55
56 const SCRIPT_NAME = "cairo binding build script";
57
58 const Target
59     TARGET_CAIRO = {name:"cairo", type:"lib", target:"lib/cairo",
60         sources:["cairo/cairo.d"]},
61     TARGET_GLITZ = {name:"glitz", type:"lib", target:"lib/cairo_glitz",
62         sources:["cairo/glitz/cairo_glitz.d"]},
63     TARGET_PDF = {name:"pdf", type:"lib", target:"lib/cairo_pdf",
64         sources:["cairo/pdf/cairo_pdf.d"]},
65     TARGET_PNG = {name:"png", type:"lib", target:"lib/cairo_png",
66         sources:["cairo/png/cairo_png.d"]},
67     TARGET_PS = {name:"ps", type:"lib", target:"lib/cairo_ps",
68         sources:["cairo/ps/cairo_ps.d"]},
69     TARGET_SVG = {name:"svg", type:"lib", target:"lib/cairo_svg",
70         sources:["cairo/svg/cairo_svg.d"]},
71     TARGET_WIN32 = {name:"win32", type:"lib", target:"lib/cairo_win32",
72         flags:["-Xwin32"], sources:["cairo/win32/cairo_win32.d"]},
73     TARGET_WIN32_DFL = {name:"win32-dfl", type:"lib",
74         target:"lib/cairo_win32_dfl",
75         flags:["-Xwin32","-Xdfl","-version=cairo_dfl"],
76         sources:["cairo/win32/cairo_win32.d"]},
77     TARGET_XLIB = {name:"xlib", type:"lib", target:"lib/cairo_xlib",
78         sources:["cairo/xlib/cairo_xlib.d"]};
79
80 version(Windows)
81     const Target
82         TARGET_ALL = {name:"all", type:"dummy",
83             deps:[&TARGET_CAIRO, &TARGET_GLITZ, &TARGET_PDF,
84                   &TARGET_PNG, &TARGET_PS, &TARGET_SVG,
85                   &TARGET_WIN32]};
86 version(linux)
87     const Target
88         TARGET_ALL = {name:"all", type:"dummy",
89             deps:[&TARGET_CAIRO, &TARGET_GLITZ, &TARGET_PDF,
90                   &TARGET_PNG, &TARGET_PS, &TARGET_SVG,
91                   &TARGET_XLIB]};
92
93 const Target[] TARGETS =
94     [TARGET_ALL, TARGET_PNG, TARGET_CAIRO, TARGET_GLITZ, TARGET_WIN32,
95      TARGET_WIN32_DFL, TARGET_XLIB, TARGET_PDF, TARGET_PS, TARGET_SVG];
96 const DEFAULT_TARGET = &TARGET_ALL;
97 const DEBUG_TARGET_SUFFIX = "_debug";
98
99 const char[][] FLAGS = ["-allobj","-cleanup"];
100 const char[][] FLAGS_DEBUG = ["-debug","-unittest","-version=Unittest","-g"];
101 const char[][] FLAGS_RELEASE = ["-release","-inline","-O"];
102
103 /* ************************************************************************* */
104
105 struct Target
106 {
107     char[] name;
108     char[] type; /// "exe", "lib" or "dummy"
109     char[] target;
110     char[][] sources = [];
111     char[][] flags = [];
112     Target*[] deps = [];
113
114     int
115     opCmp(Target other)
116     {
117         return std.string.cmp(this.name, other.name);
118     }
119    
120     int
121     opEquals(Target other)
122     {
123         return cast(int) (std.string.cmp(this.name, other.name) == 0);
124     }
125
126     char[]
127     toString()
128     {
129         return this.name;
130     }
131 }
132
133 char[][]
134 names(Target[] ts)
135 {
136     char[][] result;
137     foreach( t ; ts )
138     {
139         result.pushBack(t.name);
140     }
141     return result;
142 }
143
144 static
145 this()
146 {
147     TARGETS.sort;
148 }
149
150 void
151 showHelp()
152 {
153     echof(
154 `%s
155 Usage:
156     %s [OPTIONS] [TARGET...]
157
158 Options:
159     --debug         Add debugging code, symbols and unit tests.
160     --release       Strip out debug code, and enable optimisations.
161     --verbose       Verbose script commands.
162     --very-verbose  Verbose script AND toolchain commands.
163     --help          This message.
164     +arg            "arg" is passed on to the compiler verbatim.
165
166 Supported targets:
167     %s
168
169 The default target is "%s".`,
170             SCRIPT_NAME,
171             "dmd -run cairo-build.d",
172             std.string.join(names(TARGETS), ", "),
173             DEFAULT_TARGET.name);
174 }
175
176 bool
177 contains(Target[] ts, Target value)
178 {
179     foreach( t ; ts )
180         if( t == value )
181             return true;
182     return false;
183 }
184
185 template pushBack(T)
186 {
187     void
188     pushBack(inout T[] a, T value)
189     {
190         a.length = a.length + 1;
191         a[$-1] = value;
192     }
193 }
194
195 int
196 main(char[][] args)
197 {
198     bool debugVersion = false;
199     bool veryVerbose = false;
200     char[][] targetNames;
201     char[][] extraFlags;
202    
203     // Check for flags
204     foreach( arg ; args[1..$] )
205     {
206         if( arg == "--debug" )
207             debugVersion = true;
208         else if( arg == "--release" )
209             debugVersion = false;
210         else if( arg == "--verbose" )
211             verboseCommands = true;
212         else if( arg == "--very-verbose" )
213             veryVerbose = true;
214         else if( arg == "--help" )
215         {
216             showHelp();
217             return 0;
218         }
219         else if( arg[0] == '+' )
220         {
221             extraFlags.pushBack(arg[1..$]);
222         }
223         else if( arg[0..2] == "--" )
224         {
225             echof("Unknown argument: %s", arg);
226             return 2;
227         }
228         else
229             targetNames.pushBack(arg);
230     }
231
232     if( targetNames.length == 0 )
233         targetNames.pushBack(DEFAULT_TARGET.name);
234
235     // Ok, build list of targets to build
236     Target[] targets;
237
238 TargetNames:
239     foreach( targetName ; targetNames )
240     {
241         foreach( target ; TARGETS )
242         {
243             if( target.name == targetName )
244             {
245                 if( !targets.contains(target) && target.type != "dummy" )
246                     targets.pushBack(target);
247
248                 foreach( deptarget ; target.deps )
249                     if( !targets.contains(*deptarget)
250                             && deptarget.type != "dummy" )
251                         targets.pushBack(*deptarget);
252
253                 continue TargetNames;
254             }
255         }
256     }
257
258     // Ok, start building!
259     foreach( target ; targets )
260     {
261         if( verboseCommands ) echof(`Building target "%s"...`, target.name);
262        
263         // Build list of flags
264         char[][] flags;
265         flags ~= FLAGS;
266         if( debugVersion )
267             flags ~= FLAGS_DEBUG;
268         else
269             flags ~= FLAGS_RELEASE;
270
271         switch( target.type )
272         {
273             case "exe":
274                 flags ~= "-nolib";
275                 break;
276
277             case "lib":
278                 flags ~= "-lib";
279                 break;
280         }
281
282         if( debugVersion )
283             flags ~= "-T" ~ target.target ~ DEBUG_TARGET_SUFFIX;
284         else
285             flags ~= "-T" ~ target.target;
286
287         if( veryVerbose )
288             flags ~= "-v";
289
290         // Do the build
291         build(flags ~ target.flags ~ extraFlags ~ target.sources);
292     }
293
294     return 0;
295 }
Note: See TracBrowser for help on using the browser.