APKBUILD Reference
APKBUILD Reference
APKBUILDs are scripts to build alpine packages using the abuild tool.
Variables
The following variables are defined by abuild:
- startdir
- The directory where APKBUILD script is found.
- srcdir
- The directory here sources are downloaded to and unpacked.
- pkgdir
- This directory should hold the data files for main package. A normal autotools package has a make DESTDIR="$pkgdir" install.
- subpkgdir
- This directory should have the data files for a subpackage. This variable should only be used from subpackage functions.
The following variables should be defined by user in APKBUILD:
- depends
- Runtime dependencies that are not shared-object dependencies. Shared objects dependencies are autodetected and should not be specified here.
- depends_dev
- Runtime dependencies for -dev subpackage.
- install
- pre/post install/deinstall/remove scripts.
- license
- License(s) for the package.
- makedepends
- Build time dependencies.
- md5sums
- Checksums for sources and patches. This is generated with abuild checksum and should be located last in the APKBUILD.
- options
- build time options for package. Valid values are currently only !strip for avoid stripping the binaries.
- pkgdesc
- Short package description.
- pkggroups
- Groups to be created during buildtime. This group should be created in a $pkgname.pre-install script as well so group is created during runtime.
- pkgname
- The name of the package. All letters should be lowercase. Lua libraries/modules should be prefixed with lua- (for example lua-posix), perl modules with perl- (for example perl-xml-parser), php modules with php- and python modules with py--.
- pkgusers
- Users to be created during buildtime. Use $pkgname.pre-install for creating the user(s) during runtime.
- pkgver
- The package version.
- replaces
- package(s) that this package replaces. Useful when files moves from one package to another.
- source
- URL(s) to sources and patches.
- subpackages
- Subpackages built from this APKBUILD.
- url
- The homepage for the package. This is to help users find upstream developer, documentation etc.
Functions
The following functions should be specified in the APKBUILD. The functions should consider current work directory as undefined.
- prepare()
- Optional. Build preparation. Here should patches etc be applied. This is function is for convenience while working with the APKBUILD.
- build()
- Required. This is the compilation stage. This function will be called as normal user (unless the package() function is missing - for compatibility reasons). If no compilation is needed this function can contain a single return 0.
- package()
- Required. In this function the built application and files should be installed in "$pkgdir".
The following functions are provided by abuild and is overrideable:
- fetch()
- download remote sources listed in $source to $SRCDEST and create symlinks to $srcdir.
- unpack()
- unpacks .tar.gz .tar.bz2 .tgz and .zip archices in $srcdir.
- dev()
- Subpackage function for -dev packages. By default this will only call default_dev which will move $pkgdir/usr/include, *.a, *.la and similar files to $subpkgdir.
- doc()
- Subpackage function for -doc packages. By default this will only call default_doc which will move $pkgdir/usr/share/doc, $pkgdir/usr/share/man and similar to $subpkgdir.
Subpackages
Subpackages are specified in the $subpackages variable. abuild will parse this variable and try find a subpackage split function. The split function must move files from $pkgdir to $subpkgdir.
The split function can be specified in 3 different ways:
- subpkgname:splitfunc
- pkgname-splitfunc
- splitfunc
Subpackages example
pkgname="foo" subpackages="$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo"
will create totally 5 packages:
- foo (main)
- foo-dev (sub)
- foo-doc (sub)
- py-foo (sub)
- libfoo (sub)
The split functions for the 4 sub packages are:
- dev() (provided by abuild)
- doc() (provided by abuild)
- pysub() (provided by user)
- libfoo() (provided by user)
Examples
Simple package with separate -doc subpackage.
# Maintainer: Natanael Copa <ncopa@alpinelinux.org> pkgname=m4 pkgver=1.4.13 pkgrel=0 pkgdesc="GNU macro processor" url="http://www.gnu.org/software/m4" source=ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz depends= license="GPL" subpackages="m4-doc" _builddir="$srcdir"/$pkgname-$pkgver build() { cd "$_builddir" ./configure --prefix=/usr make } package() { cd "$_builddir" make install DESTDIR="$pkgdir" } md5sums="e9e36108b5f9855a82ca4a07ebc0fd2e m4-1.4.13.tar.gz"
Example with -doc, -dev and python subpackages.
# Contributor: Carlo Landmeter <clandmeter at gmail> # Maintainer: Carlo Landmeter <clandmeter at gmail> pkgname=libxml2 pkgver=2.7.7 pkgrel=0 pkgdesc="XML parsing library, version 2" url="http://www.xmlsoft.org/" license="MIT" depends= makedepends="zlib-dev python-dev" subpackages="$pkgname-doc $pkgname-dev py-$pkgname:py" source="ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz largefile64.patch" options="!strip" _builddir="$srcdir/$pkgname-$pkgver" prepare() { cd "$_builddir" for _i in "$srcdir"/*.patch; do patch -p1 -i "$_i" done } build() { cd "$_builddir" ./configure --prefix=/usr \ --sysconfdir=/etc \ --mandir=/usr/share/man \ --infodir=/usr/share/info make } package() { cd "$_builddir" make -j1 DESTDIR="$pkgdir" install install -Dm644 COPYING "$pkgdir"/usr/share/licenses/$pkgname/COPYING } py() { cd "$_builddir" pkgdesc="$pkgname python bindings" install -d "$subpkgdir"/usr/lib mv "$pkgdir"/usr/lib/python* "$subpkgdir"/usr/lib/ } md5sums="9abc9959823ca9ff904f1fbcf21df066 libxml2-2.7.7.tar.gz 5ad4915665608ebfa5b89f7908467a72 largefile64.patch"