PKGBUILD

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. Also read PKGBUILD(5).

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 (). The resulting package contains binary files and installation instructions, readily installable with pacman.

Mandatory variables are , , , and arch. license is not strictly necessary to build a package, but is recommended for any PKGBUILD 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 the same order as given here. However, this is not mandatory, as long as correct Bash syntax is used.

Package name

pkgbase

When building regular packages, this variable should not be explicitly declared in the PKGBUILD: its value defaults to that of #pkgname.

When building a split package, this variable can be used to explicitly specify the name to be used to refer to the group of packages in the output of makepkg and in the naming of source-only tarballs. The value is not allowed to begin with a hyphen. If not specified, the value will default to the first element in the array.

All options and directives for split packages default to the global values given in the PKGBUILD. Nevertheless, the following ones can be overridden within each split package’s packaging function: #pkgdesc, #arch, #url, #license, #groups, #depends, #optdepends, #provides, #conflicts, #replaces, #backup, #options, #install, and #changelog.

pkgname

Either the name of the package, e.g. , or, for split packages, an array of names, e.g. . Package names should only consist of lowercase alphanumerics and the following characters: (at symbol, dot, underscore, plus, hyphen). Names are not allowed to start with hyphens or dots. For the sake of consistency, should match the name of the source tarball of the software: for instance, if the software is in , use .

Version

pkgver

The version of the package. This should be the same as the version published by the author of the upstream software. 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 variable is used later in the PKGBUILD, then the underscore can easily be substituted for a hyphen, e.g. source=("$pkgname-${pkgver//_/-}.tar.gz").

Tip:

pkgrel

The release number. This is usually a positive integer number that allows 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 should be incremented by 1. When a new version of the software is released, this value must be reset to 1. In exceptional cases other formats can be found in use, such as major.minor.

epoch

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 non-negative 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. For example:

See for more information on version comparisons.

Generic

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. For example, use instead of .

Also it is important to use keywords wisely to increase the chances of appearing in relevant search queries.

arch

An array of architectures that the PKGBUILD is intended to build and work on. Arch officially supports only , but other projects may support other architectures. For example, Arch Linux 32 provides support for and pentium4 and Arch Linux ARM provides support for (armv7 hardfloat) and aarch64 (armv8 64-bit).

There are two types of values the array can use:

  • indicates the package can be built once on any architecture, and once built, is architecture-independent in its compiled state (shell scripts, fonts, themes, many types of extensions, etc.).
  • with one or more architectures indicates the package can be compiled for any of the specified architectures, but is architecture-specific once compiled. For these packages, specify all architectures that the PKGBUILD officially supports. For official repository and AUR packages, this means x86_64. Optionally, AUR packages may choose to additionally support other known working architectures.

The target architecture can be accessed with the variable 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 package (a dependency of the meta package) contains many commonly used licenses, which are installed under . If a package is licensed under one of these licenses, the value should be set to the directory name, e.g. . 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 . Once a license is used in two or more packages in an official repository (including community), it becomes a part of the package.
  2. Install the license in: , e.g. . One good way to do this is by using:
    install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  3. If the license is only found in a website, then you need to separately include it in the package.
  • The BSD, ISC, MIT, zlib/png, Python and OFL licenses are special cases and could not be included in the package, due to them including copyright notices . For the sake of the license array, it is treated as a common license (, , , , , and license=('OFL')), but technically each one is a custom license, because each one has its own copyright line. Any package licensed under these five should have its own unique license file stored in .
  • Some packages may not be covered by a single license. In these cases, multiple entries may be made in the license array, e.g. .
  • (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 . However, upstream should be contacted about the conditions under which the software is (and is not) available.

See also Nonfree applications package guidelines.

Additional information and perspectives on free and open source software licenses may be found on the following pages:

groups

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

Dependencies

depends

An array of packages that must be installed for the software to build and run. Dependencies defined inside the function are only required to run the software.

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. .

The array should list all direct first level dependencies even when some are already declared transitively. For instance, if a package foo depends on both bar and baz, and the bar package depends in turn on baz too, it will ultimately lead to undesired behavior if bar stops pulling in baz. Pacman will not enforce the installation of baz on systems which newly install the foo package, or have cleaned up orphans, and foo will crash at runtime or otherwise misbehave.

In some cases this is not necessary and may or may not be listed, for example glibc cannot be uninstalled as every system needs some C library, or for a package that already depends on another python- module, as the second module must per definition depend on python and cannot ever stop pulling it in as a dependency.

Dependencies should normally include the requirements for building all optional features of a package. Alternatively, any feature whose dependencies are not included should be explicitly disabled via a configure option. Failure to do this can lead to packages with "automagic dependencies" build-time optional features that are unpredictably enabled due to transitive dependencies or unrelated software installed on the build machine, but which are not reflected in the package dependencies.

If the dependency name appears to be a library, e.g. , makepkg will try to find a binary that depends on the library in the built package and append the soname version needed by the binary. Appending the version yourself disables automatic detection, e.g. .

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 array. The packages in the array are implicitly required to build the package, they should not be duplicated here.

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 . These dependencies are only considered when the check() function is present and is to be run by makepkg.

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. If the software works on multiple alternative dependencies, all of them can be listed here, instead of the 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')

Package relations

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

provides

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

Note: The version that the package provides should be mentioned (pkgver and potentially the pkgrel), in case packages referencing the software require one. For instance, a modified qt package version 3.3.8, named qt-foobar, should use provides=('qt=3.3.8'); omitting the version number 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 these 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 array.

Note that conflicts are checked against as well as names specified in the array. Hence, if your package a feature, specifying in the array will cause a conflict between your package and all other packages that contain in their array (i.e., you do not need to specify all those conflicting package names in your array). Let us take a concrete example:

  • implicitly provides as the itself
  • provides and conflicts with
  • provides and conflicts with , but does not need to explicitly conflict with since packages providing the same feature are implicitly in conflict.

When packages provide the same feature via the array, there is a difference between explicitly adding the alternative package to the array and not adding it. If the array is explicitly declared the two packages providing the same feature will be considered as alternative; if the array is missing the two packages providing the same feature will be considered as possibly cohabiting. Packagers should always ignore the content of the variable in deciding whether to declare a variable or not.

replaces

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

Others

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. , instead of ).

When updating, new versions may be saved as to avoid overwriting a file which already exists and was previously modified by the user. Similarly, when the package is removed, user-modified files will be preserved as unless the package was removed with the 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 disable an option, place an before it.

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.

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:

  • — The script is run right before files are extracted. One argument is passed: new package version.
  • — The script is run right after files are extracted. One argument is passed: new package version.
  • — 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.
  • — The script is run right before files are removed. One argument is passed: old package version.
  • — 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.

changelog

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

$ pacman -Qc pkgname

Sources

source

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 can be used effectively here; e.g. .

Files can also be supplied in the same directory where the PKGBUILD is located, and their names added to this array. Before the actual build process starts, all the files referenced in this array will be downloaded or checked for existence, and makepkg will not proceed if any is missing.

.install files are recognized automatically by makepkg and should not be included in the array. Files in the array with extensions .sig, .sign, or .asc are recognized by makepkg as PGP signatures and will be automatically used to verify the integrity of the corresponding source file.

noextract

An array of files listed under , which should not be extracted from their archive format by makepkg. This can be used with archives that cannot be handled by or those that need to be installed as-is. If an alternative unarchiving tool is used (e.g. ), 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 array accepts URLs, 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:

  • If contains only plain URLs without custom file names, strip the array before the last slash:
  • If contains only entries with custom file names, strip the array after the separator (taken from firefox-i18n's PKGBUILD):

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.

Note: You can use gpg --list-keys --fingerprint KEYID to find out the fingerprint of the appropriate key.

Please read makepkg#Signature checking for more information.

Integrity

These variables are arrays whose items are checksum strings that will be used to verify the integrity of the respective files in the source array. You can also insert for a particular file, and its checksum will not be tested.

The checksum type and values should always be those provided by upstream, such as in release announcements. When multiple types are available, the strongest checksum is to be preferred: over , over , over , over , over sha1, sha1 over , and over . This best ensures the integrity of the downloaded files, from upstream's announcement to package building.

The values for these variables can be auto-generated by makepkg's -g/ option, then commonly appended with . The command from is able to update the variables wherever they are in the PKGBUILD. Both tools will use the variable that is already set in the PKGBUILD, or fall back to if none is set.

The file integrity checks to use can be set up with the INTEGRITY_CHECK option in /etc/makepkg.conf. See .

cksums

An array CRC32 checksums (from UNIX-standard cksum) of the files listed in the array.

md5sums

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

sha1sums

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

sha256sums

An array of SHA-2 checksums with digest size of 256 bits.

sha224sums, sha384sums, sha512sums

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

b2sums

An array of BLAKE2 checksums with digest size of 512 bits.

gollark: CraftOS-PC uses a hotkey and `term.screenshot`.
gollark: CraftOS-PC also has nice stuff like extra graphics modes and screenshot capability.
gollark: It seems to have filesystem mounting with no way to turn it off, so I... wouldn't run untrusted code in it.
gollark: There's also CraftOS-PC, which is better in some ways.
gollark: Okay, but remember - filesystems are quite hard.

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.