spac

rules: Rules describing building targets


Each file in the rules directory describes makefile rule to build a target. There are three types of rules:

  1. Static rules describe a single target. They are stored in files named the same as that target.
  2. Pattern rules describe a set of targets. Currently the only supported pattern is is dot-extension matching. Pattern rules are named default.EXT, where EXT is the extension to match.
  3. Default rules describe targets on a try-fail basis - each default rule is tried until one completes without raising an exception, and its result is used. Default rules are named default=EXT, where EXT has is unused.

When a target matching one of the above rules shows up as a dependancy for another target, the rule will be copied into the makefile, and makemake will attempt to recursively satisfy all dependancies of the rule, either with other rules, with files from the files directory, or with source files.

These rule files are composed of three sections:

  1. All lines up to the first line starting with a colon (:), if present, are Python commands, and are executed in the Python interpreter.
  2. The first line starting with a colon seperates the Python commands from the make commands. Everything following the colon on that line is prepended to the list of dependancies.
  3. The remaining lines contain the make commands used to build this target or pattern. They will be indented automatically when they are written out to the makefile.

The following objects are defined for use in the Python code:
Name Type Description
base Global If this is a pattern rule, the target filename stripped of its extension, otherwise None.
command(cmd) Function Adds the command to the list of commands for make to execute.
dir Global The directory prefix to the target
dependon(item) Function Adds the item (which may be a list) to the end of the dependancies list.
glob(pattern) Function Returns a list of files matching the given pattern
os Module Standard OS module
re Module Standard regular expression module
readlist(filename[, dirname]) Function Opens the file, reads its contents as a list of lines, and strips off all the trailing newlines and whitespace. If dirname is set, all files in the returned list are prefixed with that directory name. All returned filenames are normalized to remove dir/../.
string Module Standard string module
target Global The filename of the target of this rule.

The following string substitutions may be used in either the dependancy line or any of the make commands following it:

In addition, any of the variables created in the Python code section above may be inserted by the same method.