6.3. Review of existing anybuilds

Anybuild:
file in shell language (bourne-compatible) with commands to build the package. That is the main technic to form distro projects from separate programs.

For the package zlib-1.2.11 its build will be located here:
ports/packages/zlib-1.2.11/zlib.build

Let's examine the contents of the file.

#!/bin/sh
# Copyright © 1999-2017 Gerard Beekmans
# Copyright © 2017-2018 Random Crew
# Distributed under the terms of MIT License.

eval "$(dumpbuild "${@}")"

src_config()
{
./configure         --prefix=${PREFIX}
}

src_compile()
{
make ${MAKEOPTS}
}

src_install()
{
make install ${MAKEOPTS} DESTDIR=${D}
}

map_direct

First string contains the command interpreter: #!/bin/sh
Mind the usage of more universal variant sh instead of bash. Anybuilds from the following examples do not use the language constructions, specific for bash.

The next string under the comment # contain supplementary information about authors and license.

The string with eval construction is needed for the possibility to launch the anybuild directly from command line like classic script. In that case the call of dumpbuild will load the library data from any build system.
For the majority of examples in the current guide anybuild will not be launched directly, but will be used as a library during the launch of specialized build command. In such a manner the string with eval will not do anything.

The function src_config(3) is dedicated to package configuration. It performs setting, which precedes the main stage of the build. In the given case there is the simple launch of typical script configure with one argument.
The variable PREFIX is set up by the engine. Its value is initialised with option any_program_prefix. That option is already set inside rdd.conf.d/, and it can be changed in file rdd.def or in command string.
The value defaults to PREFIX=/usr

Global variables, set up by the engine, completely consist of capital letters. That way they can be distinguished from local and inner variables. Detailed description of all global variables, representing API, is given in any-api(7). Let's also call such variables the interface ones, as they are part of program agreement, provided by the system.

Why to assign the value of --prefix with variable? It could be assigned directly:

./configure         --prefix=/usr
The main advantage of interfaces in the ability to change the behaviour without editing of connected parts. If there will be a further need to change the value of --prefix, then with direct assignment --prefix=/usr one will need to edit each anybuild (there could be very much of them).
If otherwise the value in anybuild has been assigned with interface variable, then it will be enough for adaptation to change for one time the value of that variable in config file, and changes will be applied centrally to all packages.

The function src_compile(3) launches the main build stage. In the example above that is traditional launch of make. MAKEOPTS is one more interface variable, which contains typical parameters for any launch of make. The example of such parameters - the values for parallelization: MAKEOPTS=-j8
With MAKEOPTS we get centralized management of build parallelization inside single package.

The function src_install(3) installs package stuff into destination dir. The key role in that function plays the variable D. It contains the path to a place of package installation. The path is composed automatically by the engine.
For each package the separate directory D is created, which does not intersect with other packages. After installation it contains only files, belonging to the current package. That property is used afterwards during the creationg of binary archives and build context for other packages.

In the end the function map_direct is called. Likewise string with eval, the given function works only during the direct call of anybuild as an executable script. In that case it launches the entire sequence of the build. With the way of the launch the current guide deals with, the function does not perform any actions.