Chapter 23. Alias Targets

We've already seen how you can use the Alias function to create a target named install:


     env = Environment()
     hello = env.Program('hello.c')
     env.Install('/usr/bin', hello)
     env.Alias('install', '/usr/bin')
  

You can then use this alias on the command line to tell SCons more naturally that you want to install files:


     % scons -Q install
     cc -o hello.o -c hello.c
     cc -o hello hello.o
     Install file: "hello" as "/usr/bin/hello"
  

Like other Builder methods, though, the Alias method returns an object representing the alias being built. You can then use this object as input to anothother Builder. This is especially useful if you use such an object as input to another call to the Alias Builder, allowing you to create a hierarchy of nested aliases:


     env = Environment()
     p = env.Program('foo.c')
     l = env.Library('bar.c')
     env.Install('/usr/bin', p)
     env.Install('/usr/lib', l)
     ib = env.Alias('install-bin', '/usr/bin')
     il = env.Alias('install-lib', '/usr/lib')
     env.Alias('install', [ib, il])
  

This example defines separate install, install-bin, and install-lib aliases, allowing you finer control over what gets installed:


     % scons -Q install-bin
     cc -o foo.o -c foo.c
     cc -o foo foo.o
     Install file: "foo" as "/usr/bin/foo"
     % scons -Q install-lib
     cc -o bar.o -c bar.c
     ar rc libbar.a bar.o
     ranlib libbar.a
     Install file: "libbar.a" as "/usr/lib/libbar.a"
     % scons -Q -c /
     Removed foo.o
     Removed foo
     Removed /usr/bin/foo
     Removed bar.o
     Removed libbar.a
     Removed /usr/lib/libbar.a
     % scons -Q install
     cc -o foo.o -c foo.c
     cc -o foo foo.o
     Install file: "foo" as "/usr/bin/foo"
     cc -o bar.o -c bar.c
     ar rc libbar.a bar.o
     ranlib libbar.a
     Install file: "libbar.a" as "/usr/lib/libbar.a"