Table of Contents
This chapter provides examples for advanced scenarios to demonstrate the practical use of the Waf library.
The Waf tool misc contains various routines to ease file manipulations such as substituting parameters or executing custom compilers. The objective of this section is to illustrate the principles of the current apis.
The following example illustrates how to produce a pkg-config file from a template:
def configure(conf): conf.check_tool('misc') def build(bld): obj = bld.new_task_gen('subst') obj.source = 'test.pc.in' obj.target = 'test.pc' obj.dict = {'LIBS': '-lm', 'CFLAGS': '-Wall', 'VERSION': '1.0'} # any kind of map will work, for example # obj.dict = obj.env
The variables must be declared in the template file by enclosing the names between @ characters (m4 syntax).
Name: test Description: @CFLAGS@ Version: @VERSION@ Libs: -L${libdir} @LIBS@ Cflags: -I${includedir} @CFLAGS@
The default substitution function may be replaced by changing the attribute func of the task generator.
The command-output system enables execution of system commands without requiring a shell. The following example illustrates how to execute a script present in the source directory each time it is executed.
import time import miscdef build(bld): out1 = bld.new_task_gen('command-output') out1.stdout = 'test1'
out1.stdin = 'wscript_build'
#out1.command_is_external = False out1.command = 'some-script'
out1.argv =
['--output-md5', misc.output_file('test1.md5')
] out1.vars = 'COINCOIN' out1.env['COINCOIN'] = time.time()
![]()
misc is the Waf module providing the command-output features | |
The standard output will be redirected to the file test1 | |
The file 'wscript_build' will be passed to the standard input | |
The program to execute is assumed to be present in the directory of the wscript file, unless command_is_external is set to True | |
Additional parameters are provided in the argv attribute, as a list. | |
Parameters representing files must be added through the special classes input_file, output_file, input_dir and output_dir to resolve the paths properly | |
An additional dependency is added on the time, the task will be executed whenever the time changes |