This is kind of a quick and direct introduction to how to work with abuild and APKBUILDs in a low-level way.
abuild(1) takes a list of targets, much like make(1) does. If you do not specify any targets,
it defaults to a default set of targets. This functionality is provided by
all() in abuild.
What this means is that we can run specific targets and get specific effects, which is useful when you are debugging an APKBUILD.
Installing the build dependencies for an APKBUILD
abuild(1) uses the builddeps() target to determine dependencies and depending on how it is invoked,
synthesize a transaction in the package manager to install a set of packages pinned as dependencies
.makedepends-$pkgname. This behaviour is derived from similar behaviour in Debian's pbuilder(1).
Thusly, we can invoke the
builddeps target in order to install our dependencies, like so:
As all of our dependencies are pinned to
.makedepends-$pkgname, removing them when we are done is
also fairly easy:
Splitting up build logic into substeps
Some packages, such as the Xen hypervisor consist of many different components integrated into a single APKBUILD. In the case of Xen, we have the hypervisor itself, management tools, stub domains, and documentation. Splitting up these components into individual build targets allows us to debug the build process of the individual components, without having to build the other components. This saves time when the build process is relatively time-consuming.
For a practical example of this, we will look at the relevant parts of the APKBUILD of Xen 4.3:
These are the individual build steps for building each component. abuild(1) itself calls the
build target, so we will need to have our APKBUILD fan out to each build step. We provide our
build function to glue it all together, although I hope to be able to improve abuild(1)
where this will eventually be unnecessary.
This is our
return 1 at the end of each step is important. It ensures that abuild(1) gives up if
any of the components fail to properly build.
What this nets us is the ability to do the following:
In the event that we only need to look at building the hypervisor, or the management tools, this work has now cut our build times significantly.
You can also add utility targets, such as invoking
make menuconfig in the kernel. Here is
an example of that, from the linux-vanilla APKBUILD:
As you can see, the ability to declare custom targets in APKBUILDs allows for versatile control over the build process.