Checkin of in-progress work on the User Guide.
[scons.git] / doc / user / variants.sgml
1 <!--
2
3   Copyright (c) 2001, 2002, 2003 Steven Knight
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
31 =head2 Hello, World! for baNaNa and peAcH OS's
32
33 Variant builds require just another simple extension. Let's take as an
34 example a requirement to allow builds for both the baNaNa and peAcH
35 operating systems. In this case, we are using a distributed file system,
36 such as NFS to access the particular system, and only one or the other of
37 the systems has to be compiled for any given invocation of C<cons>. Here's
38 one way we could set up the F<Construct> file for our B<Hello, World!>
39 application:
40
41   # Construct file for Hello, World!
42
43   die qq(OS must be specified) unless $OS = $ARG{OS};
44   die qq(OS must be "peach" or "banana")
45         if $OS ne "peach" && $OS ne "banana";
46
47   # Where to put all our shared products.
48   $EXPORT = "#export/$OS";
49
50   Export qw( CONS INCLUDE LIB BIN );
51
52   # Standard directories for sharing products.
53   $INCLUDE = "$EXPORT/include";
54   $LIB = "$EXPORT/lib";
55   $BIN = "$EXPORT/bin";
56
57   # A standard construction environment.
58   $CONS = new cons (
59         CPPPATH => $INCLUDE,    # Include path for C Compilations
60         LIBPATH => $LIB,        # Library path for linking programs
61         LIBS => '-lworld',      # List of standard libraries
62   );
63
64   # $BUILD is where we will derive everything.
65   $BUILD = "#build/$OS";
66
67   # Tell cons where the source files for $BUILD are.
68   Link $BUILD => 'src';
69
70   Build (
71         "$BUILD/hello/Conscript",
72         "$BUILD/world/Conscript",
73   );
74
75 Now if we login to a peAcH system, we can build our B<Hello, World!>
76 application for that platform:
77
78   % cons export OS=peach
79   Install build/peach/world/world.h as export/peach/include/world.h
80   cc -Iexport/peach/include -c build/peach/hello/hello.c -o build/peach/hello/hello.o
81   cc -Iexport/peach/include -c build/peach/world/world.c -o build/peach/world/world.o
82   ar r build/peach/world/libworld.a build/peach/world/world.o
83   ar: creating build/peach/world/libworld.a
84   ranlib build/peach/world/libworld.a
85   Install build/peach/world/libworld.a as export/peach/lib/libworld.a
86   cc -o build/peach/hello/hello build/peach/hello/hello.o -Lexport/peach/lib -lworld
87   Install build/peach/hello/hello as export/peach/bin/hello
88
89
90 =head2 Variations on a theme
91
92 Other variations of this model are possible. For example, you might decide
93 that you want to separate out your include files into platform dependent and
94 platform independent files. In this case, you'd have to define an
95 alternative to C<$INCLUDE> for platform-dependent files. Most F<Conscript>
96 files, generating purely platform-independent include files, would not have
97 to change.
98
99 You might also want to be able to compile your whole system with debugging
100 or profiling, for example, enabled. You could do this with appropriate
101 command line options, such as C<DEBUG=on>. This would then be translated
102 into the appropriate platform-specific requirements to enable debugging
103 (this might include turning off optimization, for example). You could
104 optionally vary the name space for these different types of systems, but, as
105 we'll see in the next section, it's not B<essential> to do this, since Cons
106 is pretty smart about rebuilding things when you change options.
107
108 -->
109
110  <para>
111
112    X
113
114  </para>
115
116  <section>
117  <title>X</title>
118
119    <para>
120
121    X
122
123    </para>
124
125  </section>