-
Notifications
You must be signed in to change notification settings - Fork 2
Variables
These variables are set automatically during the build and available in
prepare(), build(), and package() functions.
| Variable | Description |
|---|---|
$srcdir |
Source directory where all sources are downloaded and extracted |
$pkgdir |
Package root directory. Install files here in package()
|
$startdir |
Directory containing the PKGBUILD |
The following PKGBUILD fields are also exported as environment variables:
| Variable | Description |
|---|---|
$pkgname |
Package name |
$pkgver |
Package version |
$pkgrel |
Package release number |
$epoch |
Package epoch |
$maintainer |
Package maintainer |
$url |
Upstream URL |
Any variable in the PKGBUILD that is not a recognized field is treated as a custom variable. Custom variables are exported as environment variables and available in all functions.
_buildflags="-O2 -Wall"
_srcname="${pkgname}-${pkgver}"
build() {
cd "${srcdir}/${_srcname}"
CFLAGS="${_buildflags}" make
}Custom arrays work the same way:
_patches=(
'fix-build.patch'
'add-feature.patch'
)
prepare() {
cd "${srcdir}/${_srcname}"
for p in "${_patches[@]}"; do
patch -Np1 -i "${srcdir}/${p}"
done
}Any function not recognized as a standard PKGBUILD function (build,
package, prepare, preinst, postinst, prerm, postrm, pretrans,
posttrans) is treated as a helper function.
Helper functions are injected into build scripts automatically:
_install_license() {
install -Dm 644 -t "${pkgdir}/usr/share/licenses/${pkgname}" LICENSE
}
package() {
cd "${srcdir}/${_srcname}"
make DESTDIR="${pkgdir}" install
_install_license
}Helper functions referenced by install scriptlets (preinst, postinst, etc.)
are also included automatically, with transitive dependency resolution -- if
helper A calls helper B, both are injected.
build() {
cd "${srcdir}/${pkgname}-${pkgver}"
./configure --prefix=/usr
make
}
package() {
cd "${srcdir}/${pkgname}-${pkgver}"
make DESTDIR="${pkgdir}" install
}