Table of Contents
In this chapter, we show how to use abuild with automatically generated code. The examples in this chapter use the GNU Make backend, but the principles are the same if you are using ant. Examples of using code generators with Java appear later in the document (Section 19.2, “Java Code Generator Example”).
The most important thing to realize about code generators in abuild is that code generation can be viewed as a just another service that a build item can offer, just like libraries or header files. In many build systems, code generators are problematic because you need to take special steps to make sure generated code appears before compilation or dependency generation begin. With abuild, code generators get run at the correct stage by virtue of appearing in the correct place in the dependency tree.
In order for a make-based build item
to provide code generation, it must have a
Rules.mk file. The
Rules.mk file is a GNU Make fragment that is
included by abuild only when explicitly requested. In order to
use the rules implemented in one build item's
Rules.mk file, you must depend on that build
item and also list its name in the
BUILD_ITEM_RULES variable in your
Abuild.mk file. Any rules defined in
Rules.mk are run from the abuild output
directory of the build item that is using the rules. That means
that if the rules need to refer to files inside the build item
that provides the rules, they must do so by
either accessing interface variables defined in that build item's
Abuild.interface, or prefixing the files
with a variable that abuild provides. Specifically, for a
build item named
,
abuild provides variable called
build-itemabDIR_
that can be accessed from a build-itemRules.mk file.
Note that abuild only provides these variables for build items
in your dependency chain. Also, use of these variables from
Abuild.mk files is strongly discouraged as
it can cause your build tree to contain path-based dependencies
instead of name-based dependencies which would defeat one of the
most compelling advantages of abuild. The best practice is to
refer to files in your own build item from your own files by
using the abuild-provided variable name to find your own path,
and to define interface variables for files that you intend for
other build items to access. Either way, there are certain
things that it are important to keep in mind when writing
GNU Make rules for use inside of
abuild. For a discussion of this topic, please see Section 27.2, “Guidelines for Make Rule Authors”.