<- back to docs

Writing an abuild recipe

An abuild file is a POSIX shell snippet that tells apkg how to build a package. The directory containing it must have the same name as the package.

See man apkg for full details on all options and environment variables, and man apkg-genabuild for the recipe scaffolding tool.

To quickly scaffold a new recipe from a source URL, use apkg-genabuild:

apkg-genabuild https://example.com/mypkg-1.2.3.tar.gz

This creates the directory and a skeleton abuild with name, version, release, and source already populated.

Directory structure

mypkg/
  abuild        - package recipe (required)
  info          - package metadata template (description, homepage, license, maintainer)
  depends       - dependency list, one per line (optional)
  preinstall    - script run before the package is built (optional)
  postinstall   - script run after the package is installed (optional)
  .shasum       - source checksums, auto-generated (regenerate with `apkg -g`)
  .files        - package file list, auto-generated (regenerate with `apkg -k`)

Minimal recipe

name=mypkg
version=1.2.3
release=1
source="https://example.com/$name-$version.tar.gz"

Required variables

Source formats

The source variable accepts a whitespace-separated list. Five formats are supported:

Multiple sources can be specified:

source="https://example.com/$name-$version.tar.gz
        fix-build.patch
        default-config::noextract"

If source is empty, apkg creates a dummy package: useful for meta packages that exist only to pull in dependencies.

Optional variables

Build control

Package content control

Runit services

sv="run finish mydaemon.run mydaemon.finish"

Build hooks

Custom build function

If a build() function is defined, it completely replaces the auto-detected build system. Two variables are available:

Several DESTDIR-style variables are pre-exported: DESTDIR, DEST_DIR, INSTALLROOT, install_root, INSTALL_ROOT.

build() {
    cd "$SRC/$name-$version"
    ./configure --prefix=/usr --sysconfdir=/etc
    make
    make DESTDIR="$PKG" install
}

build() runs with set -ex, so the script exits on any error and prints each command.

Pre/post build hooks

Without a build() function, you can use prebuild() and postbuild():

prebuild() {
    sed -i 's/broken/fixed/g' src/whatever.c
}

postbuild() {
    mv "$PKG/usr/bin/wrongname" "$PKG/usr/bin/rightname"
}

The execution order is: prebuild() → auto-detected build system → postbuild().

Build system auto-detection

When no build() is defined and no build_type is set, apkg checks for these files in order:

  1. meson.build: meson with LTO, PIE, wrap_mode=nodownload, buildtype=plain
  2. configure: autotools ./configure --prefix=/usr --sysconfdir=/etc ...
  3. CMakeLists.txt: cmake with Release build type, prefers ninja
  4. setup.py: python3 setup.py build && install --root=$PKG
  5. Makefile.PL: perl Makefile.PL && make && make install
  6. Makefile / makefile / GNUmakefile: raw make with standard variables

The exact flags for each build system are documented in doc/defaultbuildopts.

Post-build processing

After compilation, apkg automatically:

The info file

apkg-genabuild creates an info file alongside the abuild with package metadata:

description:
homepage:
license:
maintainer: name <name at mail dot com>

Fill in each field as appropriate. The maintainer line uses the format name <email>.

The depends file

One dependency per line. Lines starting with # are comments. Dependencies are just package names: no version constraints.

# Direct dependencies of mypkg
zlib
libpng
freetype

Dependencies are recursive: when installing with -I, apkg will resolve the full tree. Only list direct dependencies; transitive ones are handled automatically. Use apkg-redundantdeps to find and clean up transitive entries.

preinstall / postinstall scripts

These are optional executable scripts in the recipe directory:

If APKG_ROOT is set (alternative install root), these scripts run inside a chroot.

Checksums and file lists

Complete example

name=hello
version=2.12.1
release=1
source="https://ftp.gnu.org/gnu/hello/$name-$version.tar.gz"

build() {
    cd "$SRC/$name-$version"
    ./configure --prefix=/usr
    make
    make DESTDIR="$PKG" install
}

With a depends file:

zlib

With a postinstall script:

#!/bin/sh
echo "hello was installed!"

Tips

<- back to docsContributing documentation ->

Copyright © Alice Linux, 2024-2026