summaryrefslogtreecommitdiff
path: root/doc/user/install.in
blob: 7d8afa6fdb048832c81357cd0121ccfa90673d22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!--

  Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 The SCons Foundation

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files (the
  "Software"), to deal in the Software without restriction, including
  without limitation the rights to use, copy, modify, merge, publish,
  distribute, sublicense, and/or sell copies of the Software, and to
  permit persons to whom the Software is furnished to do so, subject to
  the following conditions:

  The above copyright notice and this permission notice shall be included
  in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

-->

  <para>

  Once a program is built,
  it is often appropriate to install it in another
  directory for public use.
  You use the &Install; method 
  to arrange for a program, or any other file,
  to be copied into a destination directory:

  </para>

  <scons_example name="ex1">
     <file name="SConstruct" printme="1">
     env = Environment()
     hello = env.Program('hello.c')
     env.Install('__ROOT__/usr/bin', hello)
     </file>
     <file name="hello.c">
     int main() { printf("Hello, world!\n"); }
     </file>
  </scons_example>

  <para>

  Note, however, that installing a file is
  still considered a type of file "build."
  This is important when you remember that
  the default behavior of &SCons; is
  to build files in or below the current directory.
  If, as in the example above,
  you are installing files in a directory
  outside of the top-level &SConstruct; file's directory tree,
  you must specify that directory
  (or a higher directory, such as <literal>/</literal>)
  for it to install anything there:

  </para>

  <scons_output example="ex1">
     <scons_output_command>scons -Q</scons_output_command>
     <scons_output_command>scons -Q __ROOT__/usr/bin</scons_output_command>
  </scons_output>

  <para>

  It can, however, be cumbersome to remember
  (and type) the specific destination directory
  in which the program (or any other file)
  should be installed.
  This is an area where the &Alias;
  function comes in handy,
  allowing you, for example,
  to create a pseudo-target named <literal>install</literal>
  that can expand to the specified destination directory:

  </para>

  <scons_example name="ex2">
    <file name="SConstruct" printme="1">
     env = Environment()
     hello = env.Program('hello.c')
     env.Install('__ROOT__/usr/bin', hello)
     env.Alias('install', '__ROOT__/usr/bin')
    </file>
    <file name="hello.c">
    int main() { printf("Hello, world!\n"); }
    </file>
  </scons_example>

  <para>

  This then yields the more natural
  ability to install the program
  in its destination as follows:

  </para>

  <scons_output example="ex2">
     <scons_output_command>scons -Q</scons_output_command>
     <scons_output_command>scons -Q install</scons_output_command>
  </scons_output>

  <section>
  <title>Installing Multiple Files in a Directory</title>

    <para>

    You can install multiple files into a directory
    simply by calling the &Install; function multiple times:

    </para>

    <scons_example name="ex3">
      <file name="SConstruct" printme="1">
       env = Environment()
       hello = env.Program('hello.c')
       goodbye = env.Program('goodbye.c')
       env.Install('__ROOT__/usr/bin', hello)
       env.Install('__ROOT__/usr/bin', goodbye)
       env.Alias('install', '__ROOT__/usr/bin')
      </file>
      <file name="hello.c">
      int main() { printf("Hello, world!\n"); }
      </file>
      <file name="goodbye.c">
      int main() { printf("Goodbye, world!\n"); }
      </file>
    </scons_example>

    <para>

    Or, more succinctly, listing the multiple input
    files in a list
    (just like you can do with any other builder):

    </para>

    <sconstruct>
       env = Environment()
       hello = env.Program('hello.c')
       goodbye = env.Program('goodbye.c')
       env.Install('__ROOT__/usr/bin', [hello, goodbye])
       env.Alias('install', '__ROOT__/usr/bin')
    </sconstruct>

    <para>

    Either of these two examples yields:

    </para>

    <scons_output example="ex3">
       <scons_output_command>scons -Q install</scons_output_command>
    </scons_output>

  </section>

  <section>
  <title>Installing a File Under a Different Name</title>

    <para>

    The &Install; method preserves the name
    of the file when it is copied into the
    destination directory.
    If you need to change the name of the file
    when you copy it, use the &InstallAs; function:

    </para>

    <scons_example name="ex4">
      <file name="SConstruct" printme="1">
       env = Environment()
       hello = env.Program('hello.c')
       env.InstallAs('__ROOT__/usr/bin/hello-new', hello)
       env.Alias('install', '__ROOT__/usr/bin')
      </file>
      <file name="hello.c">
      int main() { printf("Hello, world!\n"); }
      </file>
    </scons_example>

    <para>

    This installs the <literal>hello</literal>
    program with the name <literal>hello-new</literal>
    as follows:

    </para>

    <scons_output example="ex4">
       <scons_output_command>scons -Q install</scons_output_command>
    </scons_output>

  </section>

  <section>
  <title>Installing Multiple Files Under Different Names</title>

    <para>

    Lastly, if you have multiple files that all
    need to be installed with different file names,
    you can either call the &InstallAs; function
    multiple times, or as a shorthand,
    you can supply same-length lists
    for both the target and source arguments:

    </para>

    <scons_example name="ex5">
      <file name="SConstruct" printme="1">
       env = Environment()
       hello = env.Program('hello.c')
       goodbye = env.Program('goodbye.c')
       env.InstallAs(['__ROOT__/usr/bin/hello-new',
                      '__ROOT__/usr/bin/goodbye-new'],
                     [hello, goodbye])
       env.Alias('install', '__ROOT__/usr/bin')
      </file>
      <file name="hello.c">
      int main() { printf("Hello, world!\n"); }
      </file>
      <file name="goodbye.c">
      int main() { printf("Goodbye, world!\n"); }
      </file>
    </scons_example>

    <para>

    In this case, the &InstallAs; function
    loops through both lists simultaneously,
    and copies each source file into its corresponding
    target file name:

    </para>

    <scons_output example="ex5">
       <scons_output_command>scons -Q install</scons_output_command>
    </scons_output>

  </section>