builder is a python module to build Makefile like scripts in Python.
Here is an example called example.py:
#!/usr/bin/env python
from builder import end_rules, rule, run, end_vars, touch
VERSION = '1'
end_vars()
rule('version', run('@echo $(VERSION)'))
rule('all', None, 'req', 'target')
rule('target', touch(), 'req')
rule('req', touch())
rule('fail', run('false'))
rule('env', run('env'))
rule('clean', run('-rm -f target req'))
end_rules()
There are 2 parts in all such scripts:
- the definition of variables closed by the
end_vars()call. - the definition of rules for building targets closed by the
end_rules()call.
You can then call the script like this:
$ python example.py version VERSION=12 12
giving the version target you want to satisfy after the script
name and overload the variable VERSION to 12.
rule function takes 2 mandatory arguments:
- the name of the target.
- the function returning the function to build the target. The
returned function take 2 arguments: the target name and the list of
dependencies. Predefined functions are available to simplify
development:
runexecute the given command. If the command starts with an@then don't output the command. If the command starts with-then ignore its exit status.touchcreate the files given in argument or the target if no argument is given. If the files already exist, the modification time is updated to the current time.stepsto execute multipe steps for a rule.
The remaining optional arguments are the target dependencies.