Difference between revisions of "APKBUILD Reference"

From Alpine Linux
Jump to: navigation, search
m (updated wording for noarch tip)
m (updated wording for 'arch' variable)
Line 17: Line 17:
 
The following variables should be defined by user in APKBUILD:
 
The following variables should be defined by user in APKBUILD:
 
; arch
 
; arch
: Package architecture(s) to build for.  Can be one of: ''x86, x86_64, all,'' or ''noarch''''all'' means all architectures, and ''noarch'' means it's architecture-independent (ie, a pure-python package).
+
: Package architecture(s) to build for.  Can be one of: ''x86, x86_64, all,'' or ''noarch'', where ''all'' means all architectures, and ''noarch'' means it's architecture-independent (ie, a pure-python package).
{{Tip|To determine if your APKBUILD can use ''noarch'', build the package for your architecture and then run "scanelf -R pkg" from the directory that the APKBUILD resides in, to scan for ELF files in the <package>/pkg directory.  If you do NOT get output from this, you can use ''noarch''.}}
+
{{Tip|To determine if your APKBUILD can use ''noarch'', build the package for your architecture and then run "scanelf -R pkg" from the directory that the APKBUILD resides in, in order to scan for ELF files in the ''./pkg'' directory.  If you do NOT get output from this, then ''noarch'' can be used.}}
 
; depends
 
; depends
 
: Runtime dependencies that are not shared-object dependencies. Shared objects dependencies are autodetected and should not be specified here.
 
: Runtime dependencies that are not shared-object dependencies. Shared objects dependencies are autodetected and should not be specified here.

Revision as of 17:04, 31 December 2010

APKBUILDs are scripts to build alpine packages using the abuild tool.

Variables

abuild-defined 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.
Note: All variables that holds a path (i.e $srcdir and $pkgdir) should always be within quotes in the APKBUILD (for example: "$srcdir"). This is so things don't break in case user has the APKBUILD in a directory with spaces.

User-defined variables

The following variables should be defined by user in APKBUILD:

arch
Package architecture(s) to build for. Can be one of: x86, x86_64, all, or noarch, where all means all architectures, and noarch means it's architecture-independent (ie, a pure-python package).
Tip: To determine if your APKBUILD can use noarch, build the package for your architecture and then run "scanelf -R pkg" from the directory that the APKBUILD resides in, in order to scan for ELF files in the ./pkg directory. If you do NOT get output from this, then noarch can be used.
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. This package will "take over" files owned by packages listed in replaces. Useful when files moves from one (sub)package to another, or packages gets renamed.
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.
Note: All other user specified variables, temp variables or APKBUILD specifics should be prefixed with a _ to avoid nameclashes with the abuild internals. For example: $_builddir.

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".
Note: Building in fakeroot will reduce performance for parallell builds dramatically. That is why we do the build() and package() separation.

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 archives 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:

  1. subpkgname:splitfunc
  2. pkgname-splitfunc
  3. splitfunc

Subpackages example

pkgname="foo"
subpackages="$pkgname-dev  $pkgname-doc py-$pkgname:pysub libfoo"

will create totally 5 packages:

  1. foo (main)
  2. foo-dev (sub)
  3. foo-doc (sub)
  4. py-foo (sub)
  5. libfoo (sub)

The split functions for the 4 sub packages are:

  1. dev() (provided by abuild)
  2. doc() (provided by abuild)
  3. pysub() (provided by user)
  4. libfoo() (provided by user)


Examples

Simple package with separate -doc subpackage.

# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=m4
pkgver=1.4.15
pkgrel=0
pkgdesc="GNU macro processor"
url="http://www.gnu.org/software/m4"
depends=
arch="all"
license="GPL"
subpackages="m4-doc"
source="ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz
	gnulib-uclibc.patch"

_builddir="$srcdir"/$pkgname-$pkgver
prepare() {
	cd "$_builddir"
	patch -p1 -i "$srcdir"/gnulib-uclibc.patch
}

build() {
	cd "$_builddir"
	./configure --prefix=/usr
	make
}

package() {
	cd "$_builddir"
	make install DESTDIR="$pkgdir"
}

md5sums="5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch"

Example with -doc, -dev and python subpackages.

# Contributor: Carlo Landmeter <clandmeter at gmail>
# Maintainer: Carlo Landmeter <clandmeter at gmail>
pkgname=libxml2
pkgver=2.7.8
pkgrel=0
pkgdesc="XML parsing library, version 2"
url="http://www.xmlsoft.org/"
arch="all"
license="MIT"
depends=
depends_dev="zlib-dev python-dev"
makedepends="zlib-dev python-dev"
subpackages="$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils"
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/
}

utils() {
	pkgdesc="XML utilities"
	replaces="libxml2"
	mkdir -p "$subpkgdir"/usr
	mv "$pkgdir"/usr/bin "$subpkgdir"/usr/
}

md5sums="8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz
5ad4915665608ebfa5b89f7908467a72  largefile64.patch"