Deprecate $WIN32 variables name in place of $WINDOWS* variables names, and eliminate...
[scons.git] / doc / user / variants.sgml
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 &build_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   <programlisting>
65     platform = ARGUMENTS.get('OS', Platform())
66
67     include = "#export/$PLATFORM/include"
68     lib = "#export/$PLATFORM/lib"
69     bin = "#export/$PLATFORM/bin"
70
71     env = Environment(PLATFORM = platform,
72                       BINDIR = bin,
73                       INCDIR = include,
74                       LIBDIR = lib,
75                       CPPPATH = [include],
76                       LIBPATH = [lib],
77                       LIBS = 'world')
78
79     Export('env')
80
81     env.SConscript('src/SConscript', build_dir='build/$PLATFORM')
82   </programlisting>
83
84   <para>
85
86   This SConstruct file,
87   when run on a Linux system, yields:
88
89   </para>
90
91   <screen>
92     % <userinput>scons -Q OS=linux</userinput>
93     Install file: "build/linux/world/world.h" as "export/linux/include/world.h"
94     cc -Iexport/linux/include -c -o build/linux/hello/hello.o build/linux/hello/hello.c
95     cc -Iexport/linux/include -c -o build/linux/world/world.o build/linux/world/world.c
96     ar r build/linux/world/libworld.a build/linux/world/world.o
97     ranlib build/linux/world/libworld.a
98     Install file: "build/linux/world/libworld.a" as "export/linux/lib/libworld.a"
99     cc -o build/linux/hello/hello build/linux/hello/hello.o -Lexport/linux/lib -lworld
100     Install file: "build/linux/hello/hello" as "export/linux/bin/hello"
101   </screen>
102
103   <para>
104
105   The same SConstruct file on Windows would build:
106
107   </para>
108
109   <screen>
110     C:\><userinput>scons -Q OS=windows</userinput>
111     Install file: "build/windows/world/world.h" as "export/windows/include/world.h"
112     cl /nologo /Iexport\windows\include /c build\windows\hello\hello.c /Fobuild\windows\hello\hello.obj
113     cl /nologo /Iexport\windows\include /c build\windows\world\world.c /Fobuild\windows\world\world.obj
114     lib /nologo /OUT:build\windows\world\world.lib build\windows\world\world.obj
115     Install file: "build/windows/world/world.lib" as "export/windows/lib/world.lib"
116     link /nologo /OUT:build\windows\hello\hello.exe /LIBPATH:export\windows\lib world.lib build\windows\hello\hello.obj
117     Install file: "build/windows/hello/hello.exe" as "export/windows/bin/hello.exe"
118   </screen>
119
120   <!--
121
122   <scons_example name="ex_var2">
123     <file name="SConstruct" printme="1">
124     env = Environment(OS = ARGUMENTS.get('OS'))
125     for os in ['newell', 'post']:
126         SConscript('src/SConscript', build_dir='build/' + os)
127     </file>
128   </scons_example>
129
130   <scons_output example="ex_var2">
131     <scons_output_command>scons -Q</scons_output_command>
132   </scons_output>
133
134   -->