Targets are installed when Waf is run with the following command-line waf install. If the targets are not built, they will be installed as soon as they are built. We will now describe the three main ways of installing the targets.
Source files may be installed directly by using the install methods of the build context bld:
def build(bld): bld.install_files('${PREFIX}/include', 'a1.h') bld.install_as('${PREFIX}/dir/bar.png', 'foo.png') bld.symlink_as('${PREFIX}/lib/libfoo.so.1', 'libfoo.so.1.2.3')
The variables in curly brackets are substituted by values found in bld.env, for example ${PREFIX} is substituted by the value of bld.env['PREFIX']. An environment parameter may be provided if necessary:
def build(bld): env2 = bld.env.copy() env2['PREFIX'] = '/opt' bld.install_files('${PREFIX}/include', 'a1.h', env=env2)
Though the substitution is only performed on the first parameter, it is possible to re-use the method bld.get_install_path or the function Utils.subst_vars
def build(bld): print(bld.get_install_path('${PREFIX}/bin')) import Utils print(Utils.subst_vars('${PREFIX}/${LANG}/po', bld.env))
By providing the attribute install_path, tasks generators will install the target (in this example, a program) in the given path.
def build(bld): bld.new_task_gen( features = 'cc cprogram', source = 'main.c test.c', target = 'test_c_program', install_path = '${PREFIX}/sbin', chmod = 0755)
The variables in curly brackets are substituted as described in the previous paragraph, using main.env instead of bld.env. The chmod attribute is optional, and is used to change the permissions of the installed file (by default it is set to 0644).
To prevent the installation of a target (by default, programs and shared libraries are installed), set install_path to None
def build(bld): bld.new_task_gen( features = 'cc cprogram', source = 'main.c test.c', target = 'test_c_program', install_path = None)
Task installation is disabled by default for most task types. If a method named install is provided, it will be executed immediately after the task is successfully executed. Unlike the compilation, the file installation is not run in parallel (there is little gain in copying files in parallel).