Parch

source: handbook ch. 34, 51

PKGBUILD reference

A PKGBUILD is a shell script that makepkg executes to produce a package. It contains metadata variables, integrity arrays, and up to four functions. This page is the complete reference for the format; the example packages page shows four fully worked PKGBUILDs and the command reference covers the tools around them.

Required variables

VariableExampleMeaning
pkgnameparch-examplePackage name: lowercase letters, digits, hyphens. See naming and versioning.
pkgver1.4.2Upstream version. Must not contain spaces, hyphens, or colons.
pkgrel1Your package release number. Reset to 1 on every pkgver bump, increment on PKGBUILD-only changes.
pkgdesc"Example CLI todo manager"One-line description shown by pacman -Si and search tools.
arch('x86_64')Architectures the package builds for. Use ('any') for architecture-independent content.

Optional metadata variables

VariableExampleMeaning
epoch1Integer that forces the version to compare newer than any without it. Only for broken upstream versioning schemes.
url"https://github.com/parchlinux/example"Project homepage.
license('MIT')SPDX license identifiers. Use custom plus a custom: qualifier for nonstandard licenses.
groups('parch-apps')Package groups the package belongs to.
changelog"${pkgname}.changelog"Optional changelog file shipped with the package.

Dependency variables

VariableNeeded atNotes
dependsRuntime and buildEverything the built software links against or calls at runtime.
makedependsBuild onlyCompilers, build systems, headers. Not needed after the build.
checkdependscheck() onlyTest frameworks used only by the test suite.
optdependsOptional runtimeOne string per entry: "libpulse: audio backend support".

Declare what the software actually uses, no more and no less. Virtual dependencies are expressed with the provides array of the supplying package, not by guessing names.

Relationship variables

VariableExampleMeaning
provides('libexample.so=3-64')Names this package supplies to satisfy other packages' dependencies.
conflicts('example-bin')Packages that cannot be installed at the same time. Implies a conflict both ways.
replaces('example-old')Packages this one supersedes; pacman offers to remove them on upgrade. Use sparingly.
backup('etc/example/example.conf')Files pacman preserves as .pacnew/.pacsave instead of overwriting.

Source and integrity variables

VariableExampleMeaning
sourcesee belowArray of remote URLs, VCS URLs, and local files.
noextract('huge-archive.tar.gz')Sources to download and verify but not extract (useful when an archive must stay packaged as-is).
validpgpkeys('A1B2...')Full-length fingerprints accepted for detached source signatures.
options('!strip' 'docs')Build behavior toggles: strip, docs, libtool, staticlibs, emptydirs, zipman, debug, lto, makeflags. Prefix with ! to disable.
install"${pkgname}.install"Pacman hook script shipped alongside the package.

Sources that need a different local filename use the name::url renaming syntax, which also pins a stable name when upstream archives lack version numbers:

Source array with renaming
source=(
  "${pkgname}-${pkgver}.tar.gz::https://github.com/parchlinux/example/archive/refs/tags/v${pkgver}.tar.gz"
  "example.desktop::assets/example.desktop.in"
  "fix-build.patch"
)

Integrity arrays

Use sha256sums as the default. Use b2sums where a stronger digest is wanted. SKIP is only valid for VCS sources such as git+https://..., where the git object itself is the integrity guarantee. Never append checksums: replace them with updpkgsums, or print them with makepkg -g and edit them into the file.

Generate or update checksums
$ updpkgsums                 # rewrites the integrity arrays in place
$ makepkg -g                 # prints them, for review or manual editing

The four functions

FunctionRuns whenTypical content
prepare()After extractionpatch -Np1 -i ..., git apply, environment fixes. Start with cd into the source dir.
build()After prepareConfigure and compile. May be empty or omitted for data-only packages.
check()After build, only with makepkg --checkRun the upstream test suite.
package()Always, once per split packageCopy the results into pkgdir. Required for every package.

Both srcdir/ (extracted sources) and pkgdir/ (the package root) are available in all four. package() must never touch the host system: it only writes under pkgdir, usually with install (-Dm755, -Dm644, -Dt) rather than cp.

Complete example: a Rust CLI

A small command-line application built from source with cargo. The values are illustrative for the packaging shape, checksums must always be generated from the real sources with updpkgsums.

PKGBUILD for a Rust CLI application
# Maintainer: Parch Developers <contact@parchlinux.com>
# Contributor: Your Name <you@example.com>

pkgname=example-todo
pkgver=1.4.2
pkgrel=1
pkgdesc="Command-line todo manager for the terminal"
arch=('x86_64')
url="https://github.com/parchlinux/example-todo"
license=('MIT')
depends=('glibc' 'gcc-libs')
makedepends=('cargo')
checkdepends=()
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/parchlinux/example-todo/archive/refs/tags/v${pkgver}.tar.gz")
sha256sums=('0f3c9a2b4e6d1a8c7f5e0b3d9a4c8e2f6b1d7a5c9e3f8b2d6a4c1e7f3b9d5a2c')

prepare() {
  cd "${pkgname}-${pkgver}"
  export RUSTUP_TOOLCHAIN=stable
  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${pkgname}-${pkgver}"
  export RUSTUP_TOOLCHAIN=stable
  export CARGO_TARGET_DIR=target
  cargo build --frozen --release --all-features
}

check() {
  cd "${pkgname}-${pkgver}"
  export RUSTUP_TOOLCHAIN=stable
  cargo test --frozen --all-features
}

package() {
  cd "${pkgname}-${pkgver}"
  install -Dm755 -t "${pkgdir}/usr/bin" "target/release/${pkgname#example-}"
  install -Dm644 README.md -t "${pkgdir}/usr/share/doc/${pkgname}/README.md"
  install -Dm644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

Validation

From the package directory, as an unprivileged user:

Three checks before any build
$ bash -n PKGBUILD                                  # shell syntax check
$ makepkg --printsrcinfo > .SRCINFO                 # metadata must generate cleanly
$ namcap PKGBUILD                                   # policy lint

namcap output uses W: for warnings and E: for errors. Fix errors, evaluate each warning, and repeat after the build with the package file itself. The full pre-submission sequence is on the testing and validation page.