5 Permission is hereby granted, free of charge, to any person obtaining
6 a copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and/or sell copies of the Software, and to
10 permit persons to whom the Software is furnished to do so, subject to
11 the following conditions:
13 The above copyright notice and this permission notice shall be included
14 in all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 =head2 Variations on a theme
32 Other variations of this model are possible. For example, you might decide
33 that you want to separate out your include files into platform dependent and
34 platform independent files. In this case, you'd have to define an
35 alternative to C<$INCLUDE> for platform-dependent files. Most F<Conscript>
36 files, generating purely platform-independent include files, would not have
39 You might also want to be able to compile your whole system with debugging
40 or profiling, for example, enabled. You could do this with appropriate
41 command line options, such as C<DEBUG=on>. This would then be translated
42 into the appropriate platform-specific requirements to enable debugging
43 (this might include turning off optimization, for example). You could
44 optionally vary the name space for these different types of systems, but, as
45 we'll see in the next section, it's not B<essential> to do this, since Cons
46 is pretty smart about rebuilding things when you change options.
52 The &BuildDir; function now gives us everything
53 we need to show how easy it is to create
54 variant builds using &SCons;.
55 Suppose, for example, that we want to
56 build a program for both Windows and Linux platforms,
57 but that we want to build it in a shared directory
58 with separate side-by-side build directories
59 for the Windows and Linux versions of the program.
63 <scons_example name="ex_variants">
64 <file name="SConstruct" printme="1">
65 platform = ARGUMENTS.get('OS', Platform())
67 include = "#export/$PLATFORM/include"
68 lib = "#export/$PLATFORM/lib"
69 bin = "#export/$PLATFORM/bin"
71 env = Environment(PLATFORM = platform,
81 env.SConscript('src/SConscript', build_dir='build/$PLATFORM')
84 #BuildDir("#build/$PLATFORM", 'src')
85 #SConscript("build/$PLATFORM/hello/SConscript")
86 #SConscript("build/$PLATFORM/world/SConscript")
88 <directory name="src"></directory>
89 <directory name="src/hello"></directory>
90 <directory name="src/world"></directory>
91 <file name="src/SConscript">
93 SConscript('hello/SConscript')
94 SConscript('world/SConscript')
96 <file name="src/hello/SConscript">
98 hello = env.Program('hello.c')
99 env.Install('$BINDIR', hello)
101 <file name="src/hello/hello.c">
103 int main(int argc, char *argv[]) { printf "hello.c\n"; world(); }
105 <file name="src/world/SConscript">
107 world = env.Library('world.c')
108 env.Install('$LIBDIR', world)
109 env.Install('$INCDIR', 'world.h')
111 <file name="src/world/world.h">
112 #define STRING "world.h"
115 <file name="src/world/world.c">
116 int world() { printf "world.c\n"; }
122 This SConstruct file,
123 when run on a Linux system, yields:
127 <scons_output example="ex_variants" os="posix">
128 <command>scons -Q OS=linux</command>
133 The same SConstruct file on Windows would build:
137 <scons_output example="ex_variants" os="win32">
138 <command>scons -Q OS=windows</command>
143 <scons_example name="ex_var2">
144 <file name="SConstruct" printme="1">
145 env = Environment(OS = ARGUMENTS.get('OS'))
146 for os in ['newell', 'post']:
147 SConscript('src/SConscript', build_dir='build/' + os)
151 <scons_output example="ex_var2">
152 <command>scons -Q</command>