This documents defines a policy for writing APKBUILDs.
APKBUILDs are POSIX shell scripts as defined in POSIX.1-2017 Volume 3 POSIX.1-2017 volume 3. Additionally, the following extensions are supported:
- The
local
keyword for introducing variables local to a function is supported, it is briefly documented in the bash manual. - Non-POSIX parameter extensions
are supported. This includes: Substring expansions (e.g.
${var:offset:length}
) and Replacement expansions (e.g.${var/pattern/string}
). The bash manual contains further information on these two expansions.
NOTE: busybox ash
is currently used to evaluate APKBUILDs since it
supports additional POSIX shell extensions your APKBUILD might be
evaluated correctly even if it is not confirming to this policy
document.
Indent with tabs, don't use spaces. Avoid whitespaces.
Maximum line length is 80 characters, this should be considered a
recommendation and not a strict requirement which must be followed at
all costs. Most notably, automatically generated parts (e.g. by abuild checksum
) are except from this rule.
Put ; do
and ; then
on the same line as the while
, for
or if
.
- Always put the function name, the parenthesis and the curly brackets on the same line.
- Don't use spacing between function name and parenthesis.
- Do use spacing between function parenthesis and curly brackets.
- Don't indent alternatives.
- A one-line alternative needs a space after the close parenthesis of the pattern and before the
;;
. - End the last case with
;;
.
- Use
${var}
over$var
only when it is strictly necessary. Meaning: Only if the character following the variable name is an underscore or an alphanumeric character.
- Always quote string literals (exceptions are assigning
pkgname
andpkgver
, more on this below). - Always quote variables, command substitutions or shell meta characters
when used in strings. Prefer
"$var"/foo/bar
over"$var/foo/bar"
. - Never quote literal integers.
- Always use
$()
instead of backticks.
- Prefer
[
overtest(1)
.
- Lower-case, with underscores to separate words. Prefix all helper functions with an underscore character.
- Lower-case, with underscores to separate words. Prefix all non-metadata variables with an underscore character.
- Declare function-specific variables with the
local
keyword.
- Avoid command Substitutions in global variables, use parameter expansions instead.
- APKBUILDs are executed with
set -e
, explicit|| return 1
statements must not be used.
- All comments begin with an ASCII space character, e.g.
# foo
.
- Use TODO comments for code that is temporary, a short-term solution, or good-enough but not perfect.
- All APKBUILDs begin with one or more contributor comments (one per
line) containing a valid RFC 5322 address. For example,
# Contributor: Max Mustermann <[email protected]>
.
- All APKBUILDs contain exactly one maintainer comment containing a
valid RFC 5322 address. For example,
# Maintainer: Max Mustermann <[email protected]>
. - In addition to a Maintainer Comment a Contributor Comment must be present for said Maintainer.
Metadata Variables are variables used directly by abuild itself, e.g. pkgname
or depends
.
pkgname
must only contain lowercase characters.pkgname
must match the name of the directory theAPKBUILD
file is located in.
- Empty Metadata Variable assignments, e.g.
install=""
must be removed. - The Metadata Variable
builddir
defaults to$srcdir/$pkgname-$pkgver
and should only be assigned if the default values is not appropriate.
- All Metadata Variables (except checksums) must be declared before the first function declaration.
- Checksum Metadata Variables must be declared after the last function
declaration,
abuild checksum
will automatically take care of this.
- Functions should be declared in the order they are called by abuild.
- All functions are executed in
"$builddir"
explicit directory changes to$builddir
must be avoided (if possible). - Variables local to functions must always be declared with the
local
keyword.
- If the
prepare
function is overwritten it should always calldefault_prepare
.