Ensure Build Systems Install to the Right Location

Understand the details of installing packages into the right directories.

Preface

Most projects that we may package as APKBUILD have some build system, like a Makefile, CMake, or meson. By default, these systems don’t necessarily install to the correct locations that are defined by the Alpine FHS. That means that we have to explicitly specify what location they should be installed to.

Common problems

By default, most build systems assume that user installs are done, not system installs. This means that the build system will try to install content to /usr/local. While this may be correct for installing packages without the package manager, it’s the wrong location when installing it with our package manager (apk). To fix this, we usually have to specify a different prefix. The prefix specifies a common directory that all files of a package are installed to, like /usr. How we specify this prefix differs depending on the build system, as we’ll see later in this lesson. (Note that sometimes packages also install files to the wrong directory. One example of this is installing binary files to /usr/share. This isn’t correct since /usr/share should only contain architecture-independent files according to the Alpine FHS.)

Makefiles

Makefiles are a simple format for specifying how a package will be built. The problem with Makefiles is that they aren’t well standardized across packages. As such, there are subtle differences in each Makefile build system for each different package. However, it’s common for Makefiles to have some configuration options that are at the top of the file, like so:

Get hands-on with 1200+ tech skills courses.