PKGBUILD - ArchWiki

# PKGBUILD

Related articles

- Arch packaging standards
- Arch Build System
- Creating packages
- Category:Package development
- Pacman tips
- Arch User Repository
- makepkg
- pacman

This article discusses variables definable by the maintainer in a PKGBUILD. For information on the PKGBUILD functions and creating packages in general, refer to Creating packages.

A PKGBUILD is a shell script containing the build information required by Arch Linux packages.

Packages in Arch Linux are built using the makepkg utility. When makepkg is run, it searches for a `PKGBUILD` file in the current directory and follows the instructions therein to either compile or otherwise acquire the files to build a package archive (`pkgname.pkg.tar.xz`). The resulting package contains binary files and installation instructions, readily installable with pacman.

Mandatory variables are `pkgname`, `pkgver`, `pkgrel`, and `arch`. `license` is not strictly necessary to build a package, but is recommended for any PKGBUILDs shared with others, as `makepkg` will produce a warning if not present.

It is a common practice to define the variables in the PKGBUILD in same order as given here. However, this is not mandatory, as long as correct Bash syntax is used.

## Package name variables

### pkgbase

An optional global directive is available when building a split package. Pkgbase is used to refer to the group of packages in the output of makepkg and in the naming of source-only tarballs. If not specified, the first element in the pkgname array is used. The variable is not allowed to begin with a hyphen. All values for split packages default to the global ones given in the PKGBUILD. Everything, except `makedepends`, source variables, and integrity variables can be overridden within each split package's `package()` function.

### pkgname

The name(s) of the package(s). This should consist of lowercase alphanumerics and any of the following characters: `@`, `.`, `_`, `+`, `-` (at symbol, dot, underscore, plus, hyphen). Names are not allowed to start with hyphens. For the sake of consistency, `pkgname` should match the name of the source tarball of the software: for instance, if the software is in `foobar-2.5.tar.gz`, use `pkgname=foobar`. The name of the directory containing the PKGBUILD should also match the `pkgname`.

Split packages should be defined as an array, e.g. `pkgname=('foo' 'bar')`.

## Version variables

### pkgver

The version of the package. This should be the same as the version released by the author of the package. It can contain letters, numbers, periods and underscores, but not a hyphen (`-`). If the author of the software uses one, replace it with an underscore (`_`). If the `pkgver` variable is used later in the PKGBUILD, then the underscore can easily be substituted for a hyphen, e.g. `source=("$pkgname-${pkgver//_/-}.tar.gz")`

Note: If upstream uses a timestamp versioning such as `05102014`, ensure to use the reversed date, i.e. `20141005` (ISO 8601 format). Otherwise it will not appear as a newer version.
Tip: makepkg can automatically update this variable by defining a `pkgver()` function in the PKGBUILD. See VCS_package_guidelines#The pkgver() function for details.

### pkgrel

Release number: this value allows users to differentiate between consecutive builds of the same version of a package. As fixes and additional features are added to the PKGBUILD that influence the resulting package, the pkgrel should be incremented by 1.

When a new version of the software is released, this value must be reset to 1.

### epoch

Warning: Epoch should only be used when absolutely required to do so.

Used to force the package to be seen as newer than any previous version with a lower epoch. This value is required to be a positive integer; the default is 0. It is used when the version numbering scheme of a package changes (or is alphanumeric), breaking normal version comparison logic. See pacman(8) for more information on version comparisons.

For example:

    pkgver=5.13
    pkgrel=2
    epoch=1

    1:5.13-2

## Generic variables

### pkgdesc

The description of the package. This is recommended to be 80 characters or less and should not include the package name in a self-referencing way, unless the application name differs from the package name. It is important to use keywords wisely to increase the chances of appearing in relevant search queries.

For example `pkgdesc="Text editor for X11"` instead of `pkgdsec="Nedit is a text editor for X11"`.

### arch

An array of architectures that the PKGBUILD is intended to build and work on. Currently, it should contain `i686` and/or `x86_64`, or `any` for architecture-independent packages: `arch=('i686' 'x86_64')`, `arch=('any')`.

The target architecture can be accessed with the variable `$CARCH` during a build.

### url

The URL of the official site of the software being packaged.

### license

The license under which the software is distributed. The licenses package from the official repositories contains many commonly used licenses, which are installed to `/usr/share/licenses/common`. If a package is licensed under one of these licenses, the value should be set to the directory name, e.g. `license=('GPL')`. If the appropriate license is not included, several things must be done:

1. Add `custom` to the `license` array. Optionally, you can replace `custom` with `custom:name of license`. Once a license is used in two or more packages in an official repository (including `[community]`), it becomes a part of the licenses package.
2. Install the license in: `/usr/share/licenses/pkgname/`, e.g. `/usr/share/licenses/foobar/LICENSE`.
3. If the license is only found in a website, then you need to separately include it in the package.

- The BSD, MIT, zlib/png and Python licenses are special cases and could not be included in the licenses package. For the sake of the `license` array, it is treated as a common license (`license=('BSD')`, `license=('MIT')`, `license=('ZLIB')` and `license=('Python')`), but technically each one is a custom license, because each one has its own copyright line. Any packages licensed under these four should have its own unique license stored in `/usr/share/licenses/pkgname`. Some packages may not be covered by a single license. In these cases, multiple entries may be made in the license array, e.g. `license=('GPL' 'custom:name of license')`.
- Additionally, the (L)GPL has many versions and permutations of those versions. For (L)GPL software, the convention is:
  - (L)GPL — (L)GPLv2 or any later version
  - (L)GPL2 — (L)GPL2 only
  - (L)GPL3 — (L)GPL3 or any later version
- If after researching the issue no license can be determined, PKGBUILD.proto suggests using `unknown`. However, upstream should be contacted about the conditions under which the software is (and is not) available.

Tip: Some software authors do not provide separate license file and describe distribution rules in section of common `ReadMe.txt`. This information can be extracted to a separate file during `build()` with something like `sed -n '/This software/,/ thereof./p' ReadMe.txt > LICENSE`.

### groups

The group the package belongs in. For instance, when installing the kdebase package, it installs all packages belonging in that group.

## Dependency variables

Note: Additional architecture-specific arrays can be used by appending an underscore and the architecture name, e.g. `depends_x86_64=()`, `optdepends_x86_64=()`.

### depends

An array of packages that must be installed before the software can be run. Version restrictions can be specified with comparison operators, e.g. `depends=('foobar>=1.8.0')`; if multiple restrictions are needed, the dependency can be repeated for each, e.g. `depends=('foobar>=1.8.0' 'foobar<2.0.0')`.

Dependencies that are provided by other dependencies do not need to be listed. For instance, if a package foo depends on both bar and baz, and the bar package depends in turn on baz too, baz does not need to be included in foo's `depends` array.

### optdepends

An array of packages that are not needed for the software to function, but provide additional features. This may imply that not all executables provided by a package will function without the respective optdepends.[1] If the software works on multiple alternative dependencies, all of them can be listed here, instead of the `depends` array. A short description of the extra functionality each optdepend provides should also be noted:

    optdepends=('cups: printing support'
                'sane: scanners support'
                'libgphoto2: digital cameras support'
                'alsa-lib: sound support'
                'giflib: GIF images support'
                'libjpeg: JPEG images support'
                'libpng: PNG images support')

### makedepends

An array of packages that are only required to build the software. The minimum dependency version can be specified in the same format as in the `depends` array.

Tip: The following can be used to see if a particular package is either in the base-devel group or pulled in by a members of the group:

    $ pacman -Si $(pactree -rl package) 2>/dev/null | grep -q "^Groups *:.*base-devel"

Note: The group base-devel is assumed to be already installed when building with makepkg. Members of this group should not be included in `makedepends` array.

### checkdepends

An array of packages that the software depends on to run its test suite, but are not needed at runtime. Packages in this list follow the same format as `depends`. These dependencies are only considered when the check() function is present and is to be run by makepkg.

Note: The group base-devel is assumed to be already installed when building with makepkg. Members of this group should not be included in `checkdepends` array.

## Package relation variables

Note: Additional architecture-specific arrays can be used by appending an underscore and the architecture name, e.g. `provides_x86_64=()`, `conflicts_x86_64=()`.

### provides

An array of additional packages that the software provides the features of (or a virtual package such as `cron` or `sh`). Packages providing the same item can be installed side-by-side, unless at least one of them uses a `conflicts` array.

Warning: A version that the package provides should be mentioned (`pkgver` and perhaps the `pkgrel`), if packages needing the software may require one. For instance, a modified qt package version 3.3.8, named qt-foobar, should use `provides=('qt=3.3.8')`; using `provides=('qt')` would cause the dependencies that require a specific version of qt to fail. Do not add `pkgname` to the `provides` array, as it is done automatically.

### conflicts

An array of packages that conflict with, or cause problems with the package, if installed. All packages and packages providing this item will need to be removed. The version properties of the conflicting packages can also be specified in the same format as the `depends` array.

### replaces

An array of obsolete packages that are replaced by the package, e.g. wireshark-gtk uses `replaces=('wireshark')`. When syncing, pacman will immediately replace an installed package upon encountering another package with the matching `replaces` in the repositories. If providing an alternate version of an already existing package or uploading to the AUR, use the `conflicts` and `provides` arrays, which are only evaluated when actually installing the conflicting package.

## Other variables

### backup

An array of files that can contain user-made changes and should be preserved during upgrade or removal of a package, primarily intended for configuration files in `/etc`.

Files in this array should use relative paths without the leading slash (`/`) (e.g. `etc/pacman.conf`, instead of `/etc/pacman.conf`).

When updating, new version may be saved as `file.pacnew` to avoid overwriting a file which already exists and was previously modified by the user. Similarly, when the package is removed, user-modified file will be preserved as `file.pacsave` unless the package was removed with the `pacman -Rn` command.

See also Pacnew and Pacsave files.

### options

This array allows overriding some of the default behavior of makepkg, defined in `/etc/makepkg.conf`. To set an option, include the name in the array. To reverse the default behavior, place an `!` at the front.

The full list of the available options can be found in PKGBUILD(5).

### install

The name of the `.install` script to be included in the package. This should be the same as `pkgname`. pacman has the ability to store and execute a package-specific script when it installs, removes or upgrades a package. The script contains the following functions which run at different times:

- `pre_install` — The script is run right before files are extracted. One argument is passed: new package version.
- `post_install` — The script is run right after files are extracted. One argument is passed: new package version.
- `pre_upgrade` — The script is run right before files are extracted. Two arguments are passed in the following order: new package version, old package version.
- `post_upgrade` — The script is run right after files are extracted. Two arguments are passed in the following order: new package version, old package version.
- `pre_remove` — The script is run right before files are removed. One argument is passed: old package version.
- `post_remove` — The script is run right after files are removed. One argument is passed: old package version.

Each function is run chrooted inside the pacman install directory. See this thread.

Tip: A prototype `.install` is provided at /usr/share/pacman/proto.install.

### changelog

The name of the package changelog. To view changelogs for installed packages (that have this file):

    $ pacman -Qc pkgname

## Source variables

### source

Note: Additional architecture-specific arrays can be added by appending an underscore and the architecture name, e.g. `source_x86_64=()`. There must be a corresponding integrity array with checksums, e.g. `sha256sums_x86_64=()`.

An array of files needed to build the package. It must contain the location of the software source, which in most cases is a full HTTP or FTP URL. The previously set variables `pkgname` and `pkgver` can be used effectively here (e.g. `source=("https://example.com/$pkgname-$pkgver.tar.gz")`).

Files can also be supplied directly in the location of the `PKGBUILD` and added to this array. These paths are resolved relative to the directory of the `PKGBUILD`. Before the actual build process is started, all of the files referenced in this array will be downloaded or checked for existence, and `makepkg` will not proceed, if any are missing.

Note: `.install` files should not be included.
Tip: An alternative source name for the downloaded file can be specified with the syntax `source=('filename::fileuri')`:

    source=("project_name::hg+https://googlefontdirectory.googlecode.com/hg/")

### noextract

An array of files listed under `source`, which should not be extracted from their archive format by makepkg. This can be used with archives that cannot be handled by `/usr/bin/bsdtar` or those that need to be installed as-is. If an alternative unarchiving tool is used (e.g. lrzip), it should be added in the `makedepends` array and the first line of the prepare() function should extract the source archive manually; for example:

    prepare() {
      lrzip -d source.tar.lrz
    }

Note that while the `source` array accepts URLs, `noextract` is just the file name portion:

    source=("http://foo.org/bar/foobar.tar.xz")
    noextract=('foobar.tar.xz')

To extract nothing, you can do something like this (taken from firefox-i18n's PKGBUILD):

    noextract=("${source[@]%%::*}")

## Integrity variables

For reference:

- Collision vulnerability means generation of a series of different fixed-width strings, where any two end up having identical hashes.
- Preimage vulnerability means generation of a string or a file that matches a specific, predetermined hash.

Algorithm | Collision vulnerability | Preimage vulnerability
--- | --- | ---
MD5 | Severely broken. | Theoretical.
SHA-1 | Theoretical. | Not found.
SHA-2 | Not found. | Not found.

### md5sums

An array of 128-bit MD5 checksums of the files listed in the `source` array.

Note:

- A collision can be found in 218 = 2.6 × 105 operations or less than a second on a regular computer.
- An unpractical, theoretical preimage vulnerability is estimated at 2123.4 ≈ 1.4 × 1037, instead of the intended 2128 ≈ 3.4 × 1038.

### sha1sums

An array of 160-bit SHA-1 checksums of the files listed in the `source` array.

Note:

- A theoretical collision is estimated at 261 ≈ 2.3 × 1018 operations on average, instead of the intended ≈ 1.2 × 2160 / 2 = 1.2 × 280 ≈ 1.5 × 1024.
- While no known preimage vulnerabilities exist, SHA-1 is being phased out in use of SSL certificates in at least Microsoft, Google and Mozilla by 2017.

### sha256sums

An array of SHA-2 checksums with digest size of 256. This is an alternative to `md5sums` and `sha1sums` and has no known vulnerabilities. Once all files in the `source` array are available, a SHA-2 hash of each file will be automatically generated and compared with the values of this array in the same order. This array can be generated with the `updpkgsums` utility from the same directory that contains the PKGBUILD.

To enable use and generation of these checksums, set up the `INTEGRITY_CHECK` option in `/etc/makepkg.conf`. See makepkg.conf(5).

### sha224sums, sha384sums, sha512sums

An array of SHA-2 checksums with digest sizes 224, 384, and 512 bits, respectively. These are less common alternatives to `sha256sums`.

### validpgpkeys

An array of PGP fingerprints. If used, makepkg will only accept signatures from the keys listed here and will ignore the trust values from the keyring. If the source file was signed with a subkey, makepkg will still use the primary key for comparison.

Only full fingerprints are accepted. They must be uppercase and must not contain whitespace characters.

## See also

- PKGBUILD(5) Manual Page
- Example PKGBUILD file

Category:

- Package development