Skip to content

fobos modes variables

Tomas Bylund edited this page Feb 10, 2015 · 2 revisions

If your modus_operandi consists on one fobos file with many (and many) modes, you surely like the possibility to define variables that can be shared within the modes you define.

Let us consider the following fobos

[modes]
modes = shared-lib1 static-lib1
        shared-lib2 static-lib2

[shared-lib1]cflags = -c -fPIC -O2
lflags = -shared
build_dir = ./build/
…
target = lib1.f90

[static-lib1]cflags = -c -O2
build_dir = ./build/
…
target = lib1.f90

[shared-lib2]cflags = -c -fPIC -O2
lflags = -shared
build_dir = ./build/
…
target = lib2.f90

[static-lib2]cflags = -c -O2
build_dir = ./build/
…
target = lib2.f90

There are many repetitions! Defining fobos variables make our life simpler

[modes]
modes = shared-lib1 static-lib1
        shared-lib2 static-lib2

# variables
[common-variables]
$CFLAGS_SHARED = -c -fPIC -O2
$CFLAGS_STATIC = -c -O2
$LFLAGS_SHARED = -shared

# main modes
[shared-lib1]cflags = $CFLAGS_SHARED
lflags = $LFLAGS_SHARED
build_dir = ./build/
…
target = lib1.f90

[static-lib1]cflags = $CFLAGS_STATIC
build_dir = ./build/
…
target = lib1.f90

[shared-lib2]cflags = $CFLAGS_SHARED
lflags = $LFLAGS_SHARED
build_dir = ./build/
…
target = lib2.f90

[static-lib2]cflags = $CFLAGS_STATIC
build_dir = ./build/
…
target = lib2.f90

Now there are less repetitions, thus mantaining the files is less errors-prone.

The definition of fobos variables can happen elsewhere inside the fobos file: a variable is defined simply by the symbol $ prefixing its name. When use at the right-hand-side as an option value its value is replaced by its definition. It is worth noting that recursion is not allowed in the definition of a variable, but more than one variable can be used defining and option. Moreover, it is worthy to note that variables must be defined inside a section (or more than one), but the section name has no relevance: in previous example the [common-variables] is not actually a building mode rather a container that can be used for sharing options that are common into different building modes, thus the name of the section(s) containing the variables is(are) irrelevant.

This fobos feature can be coupled with the templates one making fobos very powerful.

Clone this wiki locally