Skip to content

1. Templates and variables ​

The fobos of First steps repeats itself: compiler = gnu five times, the program's file three times, -O2 three times. Each copy is a place to forget when something changes. Two fobos features remove the copies:

  • a template is a section whose keys a mode inherits with template = NAME; a template can itself use a template;
  • a variable is a key starting with $, in any section, replaced wherever $NAME appears.
ini
[project]
name    = quad
version = 0.1.0
authors = Ada Fortran

[modes]
modes = debug release static shared coverage

[common-variables]
$PROGRAM = src/integrate.F90
$LIBRARY = src/quad_rules.F90
$OPT     = -O2

[template-gnu]
compiler = gnu
src      = ./src/

[template-library]
template    = template-gnu
target      = $LIBRARY
track_build = True

[debug]
help      = Checks on, no optimisation
template  = template-gnu
cflags    = -c -O0 -g -fcheck=all -Wall
src       = ./src/ ./test/
build_dir = ./build/debug/
target    = $PROGRAM

[release]
help      = Optimised
template  = template-gnu
cflags    = -c $OPT
build_dir = ./build/release/
target    = $PROGRAM

[static]
help      = The library, static
template  = template-library
cflags    = -c $OPT
build_dir = ./build/static/
mklib     = static
output    = libquad.a

[shared]
help      = The library, shared
template  = template-library
cflags    = -c $OPT -fPIC
build_dir = ./build/shared/
mklib     = shared
output    = libquad.so

[coverage]
help      = Instrumented for coverage
template  = template-gnu
cflags    = -c -O0 -g
coverage  = True
src       = ./src/ ./test/
build_dir = ./build/coverage/
target    = $PROGRAM

[dependencies]
penf = https://github.com/szaghi/PENF :: tag=v2.0.1

[template-library] builds on [template-gnu] and adds what both libraries share; each library mode keeps only what is its own. A mode's own keys win over the template's.

The modes are the same:

console
$ fobis build --lmodes
The fobos file defines the following modes:
  - "debug" Checks on, no optimisation
  - "release" Optimised
  - "static" The library, static
  - "shared" The library, shared
  - "coverage" Instrumented for coverage

and resolve to the same options: introspect shows what a mode ends up with, after templates and variables:

console
$ fobis introspect --compiler --buildoptions --mode shared
{
  "compiler": {
    "name": "gnu",
    "binary": "",
    "cflags": "-c -O2 -fPIC",
    "lflags": "",
    "preproc": "",
    "cc": "gcc",
    "c_cflags": "-c"
  },
  "buildoptions": {
    "mode": "shared",
    "build_dir": "./build/shared/",
    "obj_dir": "./obj/",
    "mod_dir": "./mod/",
    "mklib": "shared",
    "jobs": 1
  }
}

Since the flags did not change, the objects of the previous chapters are still up to date:

console
$ fobis build --mode release --quiet

Building src/integrate.F90
Nothing to compile, all objects are up-to-date
Linking build/release/integrate
Target src/integrate.F90 has been successfully built
console
$ fobis build --mode static --quiet

Building src/quad_rules.F90
Compiling src/quad_rules.F90 serially
Linking build/static/libquad.a
Target src/quad_rules.F90 has been successfully built
Track building of src/quad_rules.F90

What you learned

Templates (template = NAME, chained), $variables, and fobis introspect to see the result. Reference: templates, variables, introspect.

Next: 2. Build profiles and features.