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 &variant_dir; keyword argument of
53 the &SConscript; function provides everything
54 we need to show how easy it is to create
55 variant builds using &SCons;.
56 Suppose, for example, that we want to
57 build a program for both Windows and Linux platforms,
58 but that we want to build it in a shared directory
59 with separate side-by-side build directories
60 for the Windows and Linux versions of the program.
64 <scons_example name="ex_variants">
65 <file name="SConstruct" printme="1">
66 platform = ARGUMENTS.get('OS', Platform())
68 include = "#export/$PLATFORM/include"
69 lib = "#export/$PLATFORM/lib"
70 bin = "#export/$PLATFORM/bin"
72 env = Environment(PLATFORM = platform,
82 env.SConscript('src/SConscript', variant_dir='build/$PLATFORM')
84 <directory name="src"></directory>
85 <directory name="src/hello"></directory>
86 <directory name="src/world"></directory>
87 <file name="src/SConscript">
89 SConscript('hello/SConscript')
90 SConscript('world/SConscript')
92 <file name="src/hello/SConscript">
94 hello = env.Program('hello.c')
95 env.Install('$BINDIR', hello)
97 <file name="src/hello/hello.c">
99 int main(int argc, char *argv[]) { printf "hello.c\n"; world(); }
101 <file name="src/world/SConscript">
103 world = env.Library('world.c')
104 env.Install('$LIBDIR', world)
105 env.Install('$INCDIR', 'world.h')
107 <file name="src/world/world.h">
108 #define STRING "world.h"
111 <file name="src/world/world.c">
112 int world() { printf "world.c\n"; }
118 This SConstruct file,
119 when run on a Linux system, yields:
123 <scons_output example="ex_variants" os="posix">
124 <scons_output_command>scons -Q OS=linux</scons_output_command>
129 The same SConstruct file on Windows would build:
133 <scons_output example="ex_variants" os="win32">
134 <scons_output_command>scons -Q OS=windows</scons_output_command>
139 <scons_example name="ex_var2">
140 <file name="SConstruct" printme="1">
141 env = Environment(OS = ARGUMENTS.get('OS'))
142 for os in ['newell', 'post']:
143 SConscript('src/SConscript', variant_dir='build/' + os)
147 <scons_output example="ex_var2">
148 <scons_output_command>scons -Q</scons_output_command>