Eliminate / replace remaining cPickle references in test scripts.
[scons.git] / doc / user / install.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   <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      <scons_output_command>scons -Q</scons_output_command>
66      <scons_output_command>scons -Q __ROOT__/usr/bin</scons_output_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="ex2">
104      <scons_output_command>scons -Q</scons_output_command>
105      <scons_output_command>scons -Q install</scons_output_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       <file name="goodbye.c">
131       int main() { printf("Goodbye, world!\n"); }
132       </file>
133     </scons_example>
134
135     <para>
136
137     Or, more succinctly, listing the multiple input
138     files in a list
139     (just like you can do with any other builder):
140
141     </para>
142
143     <sconstruct>
144        env = Environment()
145        hello = env.Program('hello.c')
146        goodbye = env.Program('goodbye.c')
147        env.Install('__ROOT__/usr/bin', [hello, goodbye])
148        env.Alias('install', '__ROOT__/usr/bin')
149     </sconstruct>
150
151     <para>
152
153     Either of these two examples yields:
154
155     </para>
156
157     <scons_output example="ex3">
158        <scons_output_command>scons -Q install</scons_output_command>
159     </scons_output>
160
161   </section>
162
163   <section>
164   <title>Installing a File Under a Different Name</title>
165
166     <para>
167
168     The &Install; method preserves the name
169     of the file when it is copied into the
170     destination directory.
171     If you need to change the name of the file
172     when you copy it, use the &InstallAs; function:
173
174     </para>
175
176     <scons_example name="ex4">
177       <file name="SConstruct" printme="1">
178        env = Environment()
179        hello = env.Program('hello.c')
180        env.InstallAs('__ROOT__/usr/bin/hello-new', hello)
181        env.Alias('install', '__ROOT__/usr/bin')
182       </file>
183       <file name="hello.c">
184       int main() { printf("Hello, world!\n"); }
185       </file>
186     </scons_example>
187
188     <para>
189
190     This installs the <literal>hello</literal>
191     program with the name <literal>hello-new</literal>
192     as follows:
193
194     </para>
195
196     <scons_output example="ex4">
197        <scons_output_command>scons -Q install</scons_output_command>
198     </scons_output>
199
200   </section>
201
202   <section>
203   <title>Installing Multiple Files Under Different Names</title>
204
205     <para>
206
207     Lastly, if you have multiple files that all
208     need to be installed with different file names,
209     you can either call the &InstallAs; function
210     multiple times, or as a shorthand,
211     you can supply same-length lists
212     for both the target and source arguments:
213
214     </para>
215
216     <scons_example name="ex5">
217       <file name="SConstruct" printme="1">
218        env = Environment()
219        hello = env.Program('hello.c')
220        goodbye = env.Program('goodbye.c')
221        env.InstallAs(['__ROOT__/usr/bin/hello-new',
222                       '__ROOT__/usr/bin/goodbye-new'],
223                      [hello, goodbye])
224        env.Alias('install', '__ROOT__/usr/bin')
225       </file>
226       <file name="hello.c">
227       int main() { printf("Hello, world!\n"); }
228       </file>
229       <file name="goodbye.c">
230       int main() { printf("Goodbye, world!\n"); }
231       </file>
232     </scons_example>
233
234     <para>
235
236     In this case, the &InstallAs; function
237     loops through both lists simultaneously,
238     and copies each source file into its corresponding
239     target file name:
240
241     </para>
242
243     <scons_output example="ex5">
244        <scons_output_command>scons -Q install</scons_output_command>
245     </scons_output>
246
247   </section>