Bakefile provides miscellaneous utilities in the form of Python functions which can be used in your bakefiles. Unlike tags and rules provided through modules, the functions documented in this section are available everywhere in Bakefile.
Except where explicitely stated differently, all functions accept as arguments Python strings.
Python instructions and thus also Python calls to functions, can
be used in bakefile wrapping them into the $( )
symbols. E.g. suppose you want to use the
fileList function described below to
set variable A
; you should then write:
<set var="A"> $(fileList('mypath/*.c')) </set>
The following Python functions are defined:
Returns true if the given string is the name of an option previously declared in the bakefile.
Returns true if the given string is the name of an option or a variable previously declared in the bakefile.
Allows to write if-then-else constructs inside bakefiles. The arguments are respectively the if condition (use Python syntax!), the Python expression to execute in case the condition results true and the Python expression to execute in case the condition results false.
Creates a reference to the given var variable which will be evaluated only in the final stage of bakefile processing.
Returns true if the given string is the name of a conditional target whose condition is never met.
Returns the value of the dictionary entry whose key matches the value of the variable or option named var. E.g.
<set var="A"> $(substituteFromDict(OPTION,{'1':'value1','0':'value0'})) </set>
sets A to value1 if OPTION is 1 or to value2 if OPTION is 0. Note that Python requires curly brackets to define a dictionary.
Returns the given string with the /
characters
substituted by the content of the DIRSEP
variable (see the Variables section).
Returns the value string prefixed with prefix, unless value is empty.
Adds prefix to every item in value interpreted as whitespace-separated list. E.g.
<set var="A"> $(addPrefixToList('file','1.txt 2.txt 3.txt')) </set>
sets the A variable to file1.txt file2.txt file3.txt
Splits the given string like the built-in split() Python function
but, unlike the Python split()
function,
recognizes that an expression like
"$(myPythonFuncCall(arg1, arg2)) item2"
must be split as
[ "$(myPythonFuncCall(arg1, arg2))", "item2" ]
and not as the built-in split() function would do
[ "$(myPythonFuncCall(arg1,", "arg2))", "item2" ]
Returns a string containing a space-separed list of all files found in the given path. path typically is a relative path (absolute paths should be avoided in well-designed bakefiles) with a mask used to match only wanted files.
When the given path is relative, it must be relative to the SRCDIR global variable; remember that SRCDIR is in turn relative to the location of the generated makefile (see OUTPUT_FILE).
Additionally this function can accept Python lists of strings, too. The returned value is the list of all files found in all the paths of the list. E.g.
<sources>$(fileList('../src/*.cpp'))</sources> <sources>$(fileList(['../src/*.cpp', '../src/*.c']))</sources>