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:
env = Environment() hello = env.Program('hello.c') env.Install('/usr/bin', hello)
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 /
)
for it to install anything there:
%scons -Q
cc -o hello.o -c hello.c cc -o hello hello.o %scons -Q /usr/bin
Install file: "hello" as "/usr/bin/hello"
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 install
that can expand to the specified destination directory:
env = Environment() hello = env.Program('hello.c') env.Install('/usr/bin', hello) env.Alias('install', '/usr/bin')
This then yields the more natural ability to install the program in its destination as follows:
%scons -Q
cc -o hello.o -c hello.c cc -o hello hello.o %scons -Q install
Install file: "hello" as "/usr/bin/hello"
You can install multiple files into a directory
simply by calling the Install
function multiple times:
env = Environment() hello = env.Program('hello.c') goodbye = env.Program('goodbye.c') env.Install('/usr/bin', hello) env.Install('/usr/bin', goodbye) env.Alias('install', '/usr/bin')
Or, more succinctly, listing the multiple input files in a list (just like you can do with any other builder):
env = Environment() hello = env.Program('hello.c') goodbye = env.Program('goodbye.c') env.Install('/usr/bin', [hello, goodbye]) env.Alias('install', '/usr/bin')
Either of these two examples yields:
% scons -Q install
cc -o goodbye.o -c goodbye.c
cc -o goodbye goodbye.o
Install file: "goodbye" as "/usr/bin/goodbye"
cc -o hello.o -c hello.c
cc -o hello hello.o
Install file: "hello" as "/usr/bin/hello"