Eliminate / replace remaining cPickle references in test scripts.
[scons.git] / doc / user / variants.in
1 <!--
2
3   __COPYRIGHT__
4
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:
12
13   The above copyright notice and this permission notice shall be included
14   in all copies or substantial portions of the Software.
15
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.
23
24 -->
25
26 <!--
27
28 =head1 Variant builds
29
30 =head2 Variations on a theme
31
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
37 to change.
38
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.
47
48 -->
49
50   <para>
51
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.
61
62   </para>
63
64   <scons_example name="ex_variants">
65     <file name="SConstruct" printme="1">
66     platform = ARGUMENTS.get('OS', Platform())
67
68     include = "#export/$PLATFORM/include"
69     lib = "#export/$PLATFORM/lib"
70     bin = "#export/$PLATFORM/bin"
71
72     env = Environment(PLATFORM = platform,
73                       BINDIR = bin,
74                       INCDIR = include,
75                       LIBDIR = lib,
76                       CPPPATH = [include],
77                       LIBPATH = [lib],
78                       LIBS = 'world')
79
80     Export('env')
81
82     env.SConscript('src/SConscript', variant_dir='build/$PLATFORM')
83     </file>
84     <directory name="src"></directory>
85     <directory name="src/hello"></directory>
86     <directory name="src/world"></directory>
87     <file name="src/SConscript">
88     Import('env')
89     SConscript('hello/SConscript')
90     SConscript('world/SConscript')
91     </file>
92     <file name="src/hello/SConscript">
93     Import('env')
94     hello = env.Program('hello.c')
95     env.Install('$BINDIR', hello)
96     </file>
97     <file name="src/hello/hello.c">
98     #include "world.h"
99     int main(int argc, char *argv[]) { printf "hello.c\n"; world(); }
100     </file>
101     <file name="src/world/SConscript">
102     Import('env')
103     world = env.Library('world.c')
104     env.Install('$LIBDIR', world)
105     env.Install('$INCDIR', 'world.h')
106     </file>
107     <file name="src/world/world.h">
108     #define STRING "world.h"
109     extern int world();
110     </file>
111     <file name="src/world/world.c">
112     int world() { printf "world.c\n"; }
113     </file>
114   </scons_example>
115
116   <para>
117
118   This SConstruct file,
119   when run on a Linux system, yields:
120
121   </para>
122
123   <scons_output example="ex_variants" os="posix">
124     <scons_output_command>scons -Q OS=linux</scons_output_command>
125   </scons_output>
126
127   <para>
128
129   The same SConstruct file on Windows would build:
130
131   </para>
132
133   <scons_output example="ex_variants" os="win32">
134     <scons_output_command>scons -Q OS=windows</scons_output_command>
135   </scons_output>
136
137   <!--
138
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)
144     </file>
145   </scons_example>
146
147   <scons_output example="ex_var2">
148     <scons_output_command>scons -Q</scons_output_command>
149   </scons_output>
150
151   -->