a263f658b3b3be168d9cae7080b2ed4962e222c1
[scons.git] / doc / user / install.in
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   <para>
27
28   Once a program is built,
29   it is often appropriate to install it in another
30   directory for public use.
31   You use the &Install; method 
32   to arrange for a program, or any other file,
33   to be copied into a destination directory:
34
35   </para>
36
37   <scons_example name="ex1">
38      <file name="SConstruct" printme="1">
39      env = Environment()
40      hello = env.Program('hello.c')
41      env.Install('__ROOT__/usr/bin', hello)
42      </file>
43      <file name="hello.c">
44      int main() { printf("Hello, world!\n"); }
45      </file>
46   </scons_example>
47
48   <para>
49
50   Note, however, that installing a file is
51   still considered a type of file "build."
52   This is important when you remember that
53   the default behavior of &SCons; is
54   to build files in or below the current directory.
55   If, as in the example above,
56   you are installing files in a directory
57   outside of the top-level &SConstruct; file's directory tree,
58   you must specify that directory
59   (or a higher directory, such as <literal>/</literal>)
60   for it to install anything there:
61
62   </para>
63
64   <scons_output example="ex1">
65      <command>scons</command>
66      <command>scons __ROOT__/usr/bin</command>
67   </scons_output>
68
69   <para>
70
71   It can, however, be cumbersome to remember
72   (and type) the specific destination directory
73   in which the program (or any other file)
74   should be installed.
75   This is an area where the &Alias;
76   function comes in handy,
77   allowing you, for example,
78   to create a pseudo-target named <literal>install</literal>
79   that can expand to the specified destination directory:
80
81   </para>
82
83   <scons_example name="ex2">
84     <file name="SConstruct" printme="1">
85      env = Environment()
86      hello = env.Program('hello.c')
87      env.Install('__ROOT__/usr/bin', hello)
88      env.Alias('install', '__ROOT__/usr/bin')
89     </file>
90     <file name="hello.c">
91     int main() { printf("Hello, world!\n"); }
92     </file>
93   </scons_example>
94
95   <para>
96
97   This then yields the more natural
98   ability to install the program
99   in its destination as follows:
100
101   </para>
102
103   <scons_output example="ex1">
104      <command>scons</command>
105      <command>scons install</command>
106   </scons_output>
107
108   <section>
109   <title>Installing Multiple Files in a Directory</title>
110
111     <para>
112
113     You can install multiple files into a directory
114     simply by calling the &Install; function multiple times:
115
116     </para>
117
118     <scons_example name="ex3">
119       <file name="SConstruct" printme="1">
120        env = Environment()
121        hello = env.Program('hello.c')
122        goodbye = env.Program('goodbye.c')
123        env.Install('__ROOT__/usr/bin', hello)
124        env.Install('__ROOT__/usr/bin', goodbye)
125        env.Alias('install', '__ROOT__/usr/bin')
126       </file>
127       <file name="hello.c">
128       int main() { printf("Hello, world!\n"); }
129       </file>
130     </scons_example>
131
132     <para>
133
134     Or, more succinctly, listing the multiple input
135     files in a list
136     (just like you can do with any other builder):
137
138     </para>
139
140     <sconstruct>
141        env = Environment()
142        hello = env.Program('hello.c')
143        goodbye = env.Program('goodbye.c')
144        env.Install('__ROOT__/usr/bin', [hello, goodbye])
145        env.Alias('install', '__ROOT__/usr/bin')
146     </sconstruct>
147
148     <para>
149
150     Either of these two examples yields:
151
152     </para>
153
154     <scons_output example="ex3">
155        <command>scons install</command>
156     </scons_output>
157
158   </section>
159
160   <section>
161   <title>Installing a File Under a Different Name</title>
162
163     <para>
164
165     The &Install; method preserves the name
166     of the file when it is copied into the
167     destination directory.
168     If you need to change the name of the file
169     when you copy it, use the &InstallAs; function:
170
171     </para>
172
173     <scons_example name="ex4">
174       <file name="SConstruct" printme="1">
175        env = Environment()
176        hello = env.Program('hello.c')
177        env.InstallAs('__ROOT__/usr/bin/hello-new', hello)
178        env.Alias('install', '__ROOT__/usr/bin')
179       </file>
180       <file name="hello.c">
181       int main() { printf("Hello, world!\n"); }
182       </file>
183     </scons_example>
184
185     <para>
186
187     This installs the <literal>hello</literal>
188     program with the name <literal>hello-new</literal>
189     as follows:
190
191     </para>
192
193     <scons_output example="ex4">
194        <command>scons install</command>
195     </scons_output>
196
197   </section>
198
199   <section>
200   <title>Installing Multiple Files Under Different Names</title>
201
202     <para>
203
204     Lastly, if you have multiple files that all
205     need to be installed with different file names,
206     you can either call the &InstallAs; function
207     multiple times, or as a shorthand,
208     you can supply same-length lists
209     for the both the target and source arguments:
210
211     </para>
212
213     <scons_example name="ex5">
214       <file name="SConstruct" printme="1">
215        env = Environment()
216        hello = env.Program('hello.c')
217        goodbye = env.Program('goodbye.c')
218        env.InstallAs(['__ROOT__/usr/bin/hello-new',
219                       '__ROOT__/usr/bin/goodbye-new'],
220                      [hello, goodbye])
221       </file>
222       <file name="hello.c">
223       int main() { printf("Hello, world!\n"); }
224       </file>
225     </scons_example>
226
227     <para>
228
229     In this case, the &InstallAs; function
230     loops through both lists simultaneously,
231     and copies each source file into its corresponding
232     target file name:
233
234     </para>
235
236     <scons_output example="ex5">
237        <command>scons install</command>
238     </scons_output>
239
240   </section>