Skip to content
Stefano Zaghi edited this page Feb 10, 2015 · 1 revision

Rules: using fobos file for performing minor (repetitive) tasks

Among the others, one useful feature of GNU Make is the ability to perform heterogeneous tasks other than the code building. In general, a makefile can contain generic rules designed to perform any kind of tasks (not only to compile and link codes), e.g. it is often useful to define rule for creating documentation or to generate an archive containing the whole project, just to cite the two most common minor-tasks performed. The fobos file has a similar feature.

For both single and many building-modes fobos file, it is possible to define as many rules as you want by means of a special set of fobos sections. The name of such a section must start with the prefix rule- and can have many defined options named with the starting prefix rule containing the commands that must be executed. For example

...
[rule-makedoc]
help = Rule for building documentation from source files
rule = doxygen doxy.config
...
[rule-maketar]
quiet   = True
help    = Rule for building project archive
rule_rm = rm -f project.tar
rule_mk = tar cf project.tar *
...

this defines two (auto explicative) rules. Note that three different options can be defined: help contains the help message describing the aim of the rule, quiet makes less verbose the output of rules execution and list (suppressing the commands printing, it overrides the -q switch of CLI) and rule that actually defines the rule's commands. Note also that if more than one options have the same name, only the last command is executed. In order to use the defined rules, FoBiS.py must be invoked by means of rule execution: the rules are not usable in the build and clean executions switches. The rule execution has the following CLI:

FoBiS.py rule -h

This will echo:

usage: FoBiS.py rule [-h] [-f FOBOS] [-ex RULE] [-ls]

optional arguments:
  -h, --help            show this help message and exit
  -f FOBOS, --fobos FOBOS
                        Specify a "fobos" file named differently from "fobos"
  -ex RULE, --execute RULE
                        Specify a rule (defined into fobos file) to be
                        executed
  -ls, --list           List the rules defined into a fobos file
  -q, --quiet           Less verbose than default

Assuming to have defined the 2 rules of the example above, to list the defined rules type

FoBiS.py rule --list

This will echo:

The fobos file defines the following rules:
 - "makedoc" Rule for building the documentation from source files
       Command => doxygen doxy.config
  - "maketar" Rule for building project archive

To execute one rule type

FoBiS.py rule --execute makedoc

Note that if a typo is made when selecting the rule, an error message is prompted

FoBiS.py rule --execute makedocs

This will echo:

Error: the rule "makedocs" is not defined into the fobos file. Defined rules are:
  - "makedoc" Rule for building the documentation from source files
       Command => doxygen doxy.config
  - "maketar" Rule for building project archive
Clone this wiki locally