Gwbuild-Advanced Usage¶
- Inhaltsverzeichnis
- Gwbuild-Advanced Usage
Custom Build Commands¶
Gwbuild can be instructed to create files using custom commands. Gwbuild takes care of dependency handling if needed.
Example 1: Merging XML Files in AqHBCI¶
The following is taken from AqHBCI (part of AqBanking, file src/libs/pluginsbackends/aqhbci/applayer/xml/0BUILD) and modified for clarity:
<buildFiles name="merge-base-xml" auto="TRUE" >
<input>
hbciallgrp.xml
hbci210seg.xml
hbci210job.xml
hbci201seg.xml
hbci201job.xml
hbci220seg.xml
hbci220job.xml
fints300seg.xml
fints300job.xml
hbciallseg.xml
</input>
<output>
base.xml
</output>
<cmd tool="$(xmlmerge)" checkDates="true" >
-v --compact -o $(OUTPUT[]) $(INPUT[])
</cmd>
<buildMessage>
Merging XML files into $(OUTPUT[0])
</buildMessage>
</buildFiles>
In <buildFiles> the attribute auto is set to "TRUE" (default value if omitted) which means this process is automatically run like every other build command (e.g. like command for compiling C-source files).
If auto is set to "FALSE" then this is only run if you specify the name with the gwbuild command (e.g. gwbuild -Bmerge-base-xml).
In the first tutorial (see Gwbuild-Tutorial1) you learned how tools/apps can be searched for on the build system.
This example uses the tool xmlmerge.
As you can see there is an XML element containing a list of input files (<input>) and another containing the name of the output file (<output>).
In the cmd element we use the tool xmlmerge. For dependency tracking the dates are checked which means the output file will only be re-created if one of the input files changed.
In <buildMessage> an informational message can be provided.
Example 2: Building Translation Catalogs¶
This is also taken from AqBanking.
<ifVarMatches name="xgettext_EXISTS" value="TRUE" >
<buildFiles name="i18n-src" auto="FALSE" >
<input>
<files match="*.c" />
<files match="*.cpp" />
</input>
<output>
aqbanking.pot
</output>
<cmd tool="$(xgettext)" checkDates="TRUE" deleteOutFileFirst="TRUE" >
-C -c -ki18n -ktr2i18n -kI18N -kI18S -kI18N_NOOP -ktranslate -kaliasLocale -ktr -ktrUtf8
--msgid-bugs-address=aqbanking-user@lists.aqbanking.de
-o $(OUTPUT[0]) $(INPUT[])
</cmd>
<buildMessage>
Extracting I18N strings into $(OUTPUT[0])
</buildMessage>
</buildFiles>
</ifVarMatches>
This is not automatically called (auto=FALSE), in order to run this you need to issue the following command:
gwbuild -B i18n-src
Example 3: Formatting Source Files in-place¶
This is the only example which in fact modifies the source files!
<ifVarMatches name="astyle_EXISTS" value="TRUE" >
<buildFiles name="format-src" auto="FALSE" >
<input>
<files match="*.c" />
<files match="*.cpp" />
<files match="*.h" />
</input>
<output>
</output>
<cmd tool="$(astyle)" checkDates="FALSE" >
--style=stroustrup
-s2
--min-conditional-indent=0
--indent-labels
--max-continuation-indent=80
--pad-comma
--pad-header
--unpad-paren
--align-pointer=name
--break-closing-braces
--break-one-line-headers
--attach-return-type
--convert-tabs
--max-code-length=120
--break-after-logical
--preserve-date
--suffix=none
$(INPUT[])
</cmd>
<buildMessage>
Formatting source files in-place.
</buildMessage>
</buildFiles>
</ifVarMatches>
Obviously, this is also not automatically called (auto=FALSE), in order to run this you need to issue the following command:
gwbuild -B format-src
Advanced Use of <options>¶
Again, an example from AqBanking:
<option id="backends" type="stringlist" definePrefix="AQBANKING_WITH_PLUGIN_BACKEND_" >
<choices>aqhbci aqofxconnect aqebics aqpaypal aqfints aqnone</choices>
<alias name="all">aqhbci aqofxconnect aqebics aqpaypal aqnone</alias>
<default>all</default>
</option>
In this example we define an option called backends which in this case receives a list of backends to compile when building AqBanking.
If the attribute definePrefix is set then it will be used to create a #define line in config.h consisting of that given prefix and the uppercase'd string.
So if the option is given like this:
gwbuild -s ../ -Obackends="aqhbci aqpaypal"
then the following defines will be added to config.h:
#define AQBANKING_WITH_PLUGIN_BACKEND_AQHBCI 1
#define AQBANKING_WITH_PLUGIN_BACKEND_AQPAYPAL 1
Using <options> to Set Global Compiler Options (Optimization, Debug Symbols)¶
<option id="debug" type="string">
<default>TRUE</default>
<choices>TRUE FALSE</choices>
</option>
<ifVarMatches name="option_debug" value="TRUE" >
<setVar name="CFLAGS">-ggdb -Wall -O0</setVar>
<setVar name="CXXFLAGS">-ggdb -Wall -O0</setVar>
</ifVarMatches>
So if the option is given like this:
gwbuild -s ../ -Odebug=true
then global CFLAGS and CXXFLAGS are set to -ggdb -Wall -O0.