Difference between revisions of "PKGBUILD"

From ArchWiki
Jump to: navigation, search
m (install: added the word "right" to match the other sentenses)
(source: eliminate too short note)
 
(235 intermediate revisions by 53 users not shown)
Line 9: Line 9:
 
[[ja:PKGBUILD]]
 
[[ja:PKGBUILD]]
 
[[pl:PKGBUILD]]
 
[[pl:PKGBUILD]]
[[pt:PKGBUILD]]
 
 
[[ru:PKGBUILD]]
 
[[ru:PKGBUILD]]
 
[[sr:PKGBUILD]]
 
[[sr:PKGBUILD]]
 
[[zh-CN:PKGBUILD]]
 
[[zh-CN:PKGBUILD]]
 
[[zh-TW:PKGBUILD]]
 
[[zh-TW:PKGBUILD]]
{{Article summary start}}
+
{{Related articles start}}
{{Article summary text|This article provides an explanation of PKGBUILD variables used when [[Creating Packages|creating packages]]. A PKGBUILD is a script that describes how software is to be compiled and packaged. Writing installation functions and general packaging information is covered in [[Creating Packages]] and other [[:Category:Package development|package development]] articles}}
+
{{Related|Arch packaging standards}}
{{Article summary heading|Overview}}
+
{{Related|Arch Build System}}
{{Article summary text|{{Package management overview}}}}
+
{{Related|Creating packages}}
{{Article summary heading|Related}}
+
{{Related|.SRCINFO}}
{{Article summary wiki|Arch Packaging Standards}}
+
{{Related|:Category:Package development}}
{{Article summary wiki|Creating Packages}}
+
{{Related|Pacman tips}}
{{Article summary wiki|Custom local repository}}
+
{{Related|Arch User Repository}}
{{Article summary wiki|pacman Tips}}
+
{{Related|makepkg}}
{{Article summary wiki|PKGBUILD Templates}}
+
{{Related|pacman}}
{{Article summary heading|Resources}}
+
{{Related articles end}}
{{Article summary link|PKGBUILD(5) Manual Page|https://www.archlinux.org/pacman/PKGBUILD.5.html}}
+
{{Article summary end}}
+
  
A '''PKGBUILD''' is an [[Arch Linux]] package build description file (actually it is a shell script) used when [[Creating Packages|creating packages]].
+
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 {{ic|man PKGBUILD}}.
  
Packages in Arch Linux are built using the [[makepkg]] utility and information stored in PKGBUILDs. When '''makepkg''' is run, it searches for a {{Ic|PKGBUILD}} in the current directory and follows the instructions therein to either compile or otherwise acquire the files to build a package file ({{ic|''pkgname''.pkg.tar.xz}}). The resulting package contains binary files and installation instructions, readily installed with [[pacman]].
+
A PKGBUILD is a shell script containing the build information required by [[Arch Linux]] packages.
  
== Variables ==
+
Packages in Arch Linux are built using the [[makepkg]] utility. When ''makepkg'' is run, it searches for a {{ic|PKGBUILD}} file in the current directory and follows the instructions therein to either compile or otherwise acquire the files to build a package archive ({{ic|''pkgname''.pkg.tar.xz}}). The resulting package contains binary files and installation instructions, readily installable with [[pacman]].
The following are variables that can be filled out in the PKGBUILD file.
+
  
It is 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.
+
Mandatory variables are {{ic|pkgname}}, {{ic|pkgver}}, {{ic|pkgrel}}, and {{ic|arch}}. {{ic|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 ==
 +
 
 +
=== pkgbase ===
 +
 
 +
An optional global directive is available when building a split package. {{ic|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 {{ic|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]], [[#Sources]], and [[#Integrity]] variables can be overridden within each split package's {{ic|package()}} function.
  
 
=== pkgname ===
 
=== pkgname ===
The name of the package. It should consist of ''alphanumeric and any of the following characters @ . _ + - (at symbol, dot, underscore, plus, hyphen)''. All letters should be ''lowercase'' and ''names are not allowed to start with hyphens''. For the sake of consistency, {{ic|pkgname}} should match the name of the source tarball of the software you are packaging. For instance, if the software is in {{ic|foobar-2.5.tar.gz}}, the {{ic|pkgname}} value should be {{Ic|foobar}}. The present working directory the PKGBUILD file is in should also match the {{ic|pkgname}}.
+
 
 +
The name(s) of the package(s). This should consist of lowercase alphanumerics and any of the following characters: {{ic|@}}, {{ic|.}}, {{ic|_}}, {{ic|+}}, {{ic|-}} (at symbol, dot, underscore, plus, hyphen). Names are not allowed to start with hyphens. For the sake of consistency, {{ic|pkgname}} should match the name of the source tarball of the software: for instance, if the software is in {{ic|foobar-2.5.tar.gz}}, use {{ic|1=pkgname=foobar}}. The name of the directory containing the PKGBUILD should also match the {{ic|pkgname}}.
 +
 
 +
Split packages should be defined as an array, e.g. {{ic|1=pkgname=('foo' 'bar')}}.
 +
 
 +
== Version ==
  
 
=== pkgver ===
 
=== pkgver ===
The version of the package. The value should be the same as the version released by the author of the package. It can contain letters, numbers, periods and underscore but CANNOT contain a hyphen. If the author of the package uses a hyphen in their version numbering scheme, replace it with an underscore. For instance, if the version is ''0.99-10'', it should be changed to ''0.99_10''. If the {{ic|pkgver}} variable is used later in the PKGBUILD then the underscore can easily be substituted for a dash on usage e.g.:
+
 
source=($pkgname-${pkgver//_/-}.tar.gz)
+
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 ({{ic|-}}). If the author of the software uses one, replace it with an underscore ({{ic|_}}). If the {{ic|pkgver}} variable is used later in the PKGBUILD, then the underscore can easily be substituted for a hyphen, e.g. {{ic|1=source=("$pkgname-${pkgver//_/-}.tar.gz")}}.
 +
 
 +
{{Note|If upstream uses a timestamp versioning such as {{ic|30102014}}, ensure to use the reversed date, i.e. {{ic|20141030}} ([[Wikipedia:ISO 8601|ISO 8601]] format). Otherwise it will not appear as a newer version.}}
 +
 
 +
{{Tip|
 +
* The ordering of uncommon values can be tested with [https://www.archlinux.org/pacman/vercmp.8.html vercmp], which is provided by the [[pacman]] package.
 +
* [[makepkg]] can automatically [http://allanmcrae.com/2013/04/pacman-4-1-released/ update] this variable by defining a {{ic|pkgver()}} function in the PKGBUILD. See [[VCS package guidelines#The pkgver() function]] for details.
 +
}}
  
 
=== pkgrel ===
 
=== pkgrel ===
The release number of the package specific to Arch Linux. This value allows users to differentiate between consecutive builds of the same version of a package. When a new package version is first released, the '''release number starts at 1'''.  As fixes and optimizations are made to the {{ic|PKGBUILD}} file, the package will be '''re-released''' and the '''release number''' will increment by 1. When a new version of the package comes out, the release number resets to 1.
 
  
=== pkgdir ===
+
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 {{ic|pkgrel}} 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''.
This variable reflects the root directory of what will be put into the package. It is commonly used in {{ic|1=make DESTDIR="$pkgdir" install}}.
+
  
 
=== epoch ===
 
=== epoch ===
An integer value, specific to Arch Linux, representing what 'lifetime' to compare version numbers against. This value allows overrides of the normal version comparison rules for packages that have inconsistent version numbering, require a downgrade, change numbering schemes, etc. By default, packages are assumed to have an epoch value of ''0''. Do not use this unless you know what you are doing.
 
  
=== pkgbase ===
+
{{Warning|{{ic|epoch}} should only be used when absolutely required to do so.}}
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. All options and directives for the 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: pkgver, pkgrel, epoch, pkgdesc, arch, url, license, groups, depends, optdepends, provides, conflicts, replaces, backup, options, install and changelog. The variable is not allowed to begin with a hyphen.
+
 
 +
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. For example:
 +
 
 +
{{hc|1=
 +
pkgver=5.13
 +
pkgrel=2
 +
epoch=1
 +
|2=
 +
1:5.13-2
 +
}}
 +
 
 +
See [https://www.archlinux.org/pacman/pacman.8.html pacman(8)] for more information on version comparisons.
 +
 
 +
== Generic ==
  
 
=== pkgdesc ===
 
=== pkgdesc ===
The description of the package. The description should be about 80 characters or less and should not include the package name in a self-referencing way.  For instance, "Nedit is a text editor for X11" should be written as "A text editor for X11."
 
  
{{Note|Do not follow this rule thoughtlessly when submitting packages to [[AUR]]. If package name differs from application name for some reason, inclusion of full name into description can be the only way to ensure that package can be found during search.}}
+
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 {{ic|1=pkgdesc="Text editor for X11"}} instead of {{ic|1=pkgdesc="Nedit is a text editor for X11"}}.
 +
 
 +
Also it is important to use keywords wisely to increase the chances of appearing in relevant search queries.
  
 
=== arch ===
 
=== arch ===
An array of architectures that the {{ic|PKGBUILD}} file is known to build and work on. Currently, it should contain {{ic|i686}} and/or {{ic|x86_64}}, {{ic|1=arch=('i686' 'x86_64')}}.  The value {{ic|any}} can also be used for architecture-independent packages.
 
  
You can access the target architecture with the variable {{ic|$CARCH}} during a build, and even when defining variables. See also {{bug|16352}}. Example:
+
An array of architectures that the PKGBUILD is intended to build and work on. Arch officially supports only {{ic|i686}} and {{ic|x86_64}}, but projects like [http://archlinuxarm.org/ Arch Linux ARM] provide support for other architectures such as {{ic|arm}} for armv5, {{ic|armv6h}} for armv6 hardfloat, {{ic|armv7h}} for armv7 hardfloat, and {{ic|aarch64}} for armv8 64bit.
 +
 
 +
If a package is architecture-independent in its compiled state (shell scripts, fonts, themes, many types of extensions, etc.) then use {{ic|1=arch=('any')}}. Please note that, as this is intended for packages that can be built once and used on any architecture, it will cause the package to be labeled {{ic|-any}} as opposed to {{ic|-i686}}, {{ic|-x86_64}}, etc.
 +
 
 +
If instead a package can be compiled for any architecture, but is architecture-specific once compiled, specify all architectures officially supported by Arch, i.e. {{ic|1=arch=('i686' 'x86_64')}}.
  
depends=(foobar)
+
The target architecture can be accessed with the variable {{ic|$CARCH}} during a build.
if test "$CARCH" == x86_64; then
+
  depends+=(lib32-glibc)
+
fi
+
  
 
=== url ===
 
=== url ===
Line 75: Line 102:
  
 
=== license ===
 
=== license ===
The license under which the software is distributed. A {{pkg|licenses}} package has been created in {{ic|[core]}} that stores common licenses in {{ic|/usr/share/licenses/common}}, e.g. {{ic|/usr/share/licenses/common/GPL}}. If a package is licensed under one of these licenses, the value should be set to the directory name, e.g. {{ic|1=license=('GPL')}}. If the appropriate license is not included in the official {{Pkg|licenses}} package, several things must be done:
+
The license under which the software is distributed. The {{pkg|licenses}} package contains many commonly used licenses, which are installed to {{ic|/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. {{ic|1=license=('GPL')}}. If the appropriate license is not included, several things must be done:
  
# The license file(s) should be included in: {{ic|/usr/share/licenses/''pkgname''/}}, e.g. {{ic|/usr/share/licenses/foobar/LICENSE}}.
+
# Add {{ic|custom}} to the {{ic|license}} array. Optionally, you can replace {{ic|custom}} with {{ic|custom:''name of license''}}. Once a license is used in two or more packages in an official repository (including {{ic|[community]}}), it becomes a part of the {{Pkg|licenses}} package.
# If the source tarball does NOT contain the license details and the license is only displayed elsewhere, e.g. a website, then you need to copy the license to a file and include it.
+
# Install the license in: {{ic|/usr/share/licenses/''pkgname''/}}, e.g. {{ic|/usr/share/licenses/foobar/LICENSE}}.
# Add {{ic|custom}} to the {{ic|license}} array. Optionally, you can replace {{ic|custom}} with {{ic|custom:name of license}}. Once a license is used in two or more packages in an official repository (including {{ic|[community]}}), it becomes a part of the {{Pkg|licenses}} package.
+
# If the license is only found in a website, then you need to separately include it in the package.
* The [[Wikipedia:BSD License|BSD]], [[Wikipedia:MIT License|MIT]], [[Wikipedia:ZLIB license|zlib/png]] and [[Wikipedia:Python License|Python]] licenses are special cases and could not be included in the {{pkg|licenses}} package. For the sake of the {{ic|license}} array, it is treated as a common license ({{ic|1=license=('BSD')}}, {{ic|1=license=('MIT')}}, {{ic|1=license=('ZLIB')}} and {{ic|1=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 {{ic|/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. {{ic|1=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, {{ic|PKGBUILD.proto}} suggests using {{ic|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 in separate file during {{Ic|build}} phase with something like this: {{Ic|sed -n '/'''This software'''/,/'''  thereof.'''/p' ReadMe.txt > LICENSE}}.}}
+
* The [[Wikipedia:BSD License|BSD]], [[Wikipedia:MIT License|MIT]], [[Wikipedia:ZLIB license|zlib/png]] and [[Wikipedia:Python License|Python]] licenses are special cases and could not be included in the {{pkg|licenses}} package. For the sake of the {{ic|license}} array, it is treated as a common license ({{ic|1=license=('BSD')}}, {{ic|1=license=('MIT')}}, {{ic|1=license=('ZLIB')}} and {{ic|1=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 {{ic|/usr/share/licenses/''pkgname''}}. Some packages may not be covered by a single license. In these cases, multiple entries may be made in the {{ic|license}} array, e.g. {{ic|1=license=('GPL' 'custom:''name of license''')}}.
 +
* (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, [https://projects.archlinux.org/pacman.git/tree/proto/PKGBUILD.proto PKGBUILD.proto] suggests using {{ic|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 {{ic|ReadMe.txt}}. This information can be extracted to a separate file during {{ic|build()}} with something like {{ic|sed -n '/'''This software'''/,/'''  thereof.'''/p' ReadMe.txt > LICENSE}}}}
  
 
=== groups ===
 
=== groups ===
The group the package belongs in. For instance, when you install the {{Grp|kdebase}} package, it installs all packages that belong in the {{Grp|kde}} group.
+
 
 +
The [[Creating packages#Meta packages and groups|group]] the package belongs in. For instance, when installing the {{Grp|kdebase}} package, it installs all packages belonging in that group.
 +
 
 +
== Dependencies ==
 +
 
 +
{{Note|Additional architecture-specific arrays can be added by appending an underscore and the architecture name, e.g. {{ic|1=depends_i686=()}}, {{ic|1=optdepends_x86_64=()}}.
 +
}}
  
 
=== depends ===
 
=== depends ===
An array of package names that must be installed before this software can be run. If a software requires a minimum version of a dependency, the {{ic|1=>=}} operator should be used to point this out, e.g. {{ic|1=depends=('foobar>=1.8.0')}}. You do not need to list packages that your software depends on if other packages your software depends on already have those packages listed in their dependency. For instance, {{pkg|gtk2}} depends on {{pkg|glib2}} and {{pkg|glibc}}. However, {{pkg|glibc}} does not need to be listed as a dependency for {{pkg|gtk2}} because it is a dependency for {{pkg|glib2}}.
+
An array of packages that must be installed before the software can be run. Version restrictions can be specified with comparison operators, e.g. {{ic|1=depends=('foobar>=1.8.0')}}; if multiple restrictions are needed, the dependency can be repeated for each, e.g. {{ic|1=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 {{ic|depends}} array.
  
 
=== optdepends ===
 
=== optdepends ===
An array of package names that are not needed for the software to function but provides additional features. A short description of what each package provides should also be noted. An {{ic|optdepends}} may look like this:
 
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 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.[https://lists.archlinux.org/pipermail/arch-general/2014-December/038124.html] If the software works on multiple alternative dependencies, all of them can be listed here, instead of the {{ic|depends}} array.
An array of package names that must be installed to build the software but unnecessary for using the software after installation. You can specify the minimum version dependency of the packages in the same format as the {{ic|depends}} array.
+
  
{{Note|Specifying packages that are already in {{ic|depends}} is not necessary.}}
+
A short description of the extra functionality each optdepend provides should also be noted:
{{Warning|The group {{Grp|base-devel}} is assumed already installed when building with makepkg . Members of "base-devel" '''should not''' be included in {{ic|makedepends}} arrays.}}
+
 
 +
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 {{ic|depends}} array. The packages in the {{ic|depends}} array are implicitly required to build the package, they should not be duplicated here.
 +
 
 +
{{Tip|The following can be used to see if a particular package is either in the {{Grp|base-devel}} group or pulled in by a members of the group:
 +
 
 +
<nowiki>$ LC_ALL=C pacman -Si $(pactree -rl ''package'') 2>/dev/null | grep -q "^Groups *:.*base-devel"</nowiki>
 +
 
 +
}}
 +
 
 +
{{Note|The group {{Grp|base-devel}} is assumed to be already installed when building with ''makepkg''. Members of this group '''should not''' be included in {{ic|makedepends}} array.}}
  
 
=== checkdepends ===
 
=== checkdepends ===
An array of packages this package 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 [[Creating Packages#The check() function|check()]] function is present and is to be run by makepkg.
+
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 {{ic|depends}}. These dependencies are only considered when the [[Creating packages#check()|check()]] function is present and is to be run by makepkg.  
 +
 
 +
{{Note|The group {{Grp|base-devel}} is assumed to be already installed when building with ''makepkg''. Members of this group '''should not''' be included in {{ic|checkdepends}} array.}}
 +
 
 +
== Package relations ==
 +
 
 +
{{Note|Additional architecture-specific arrays can be added by appending an underscore and the architecture name, e.g. {{ic|1=provides_i686=()}}, {{ic|1=conflicts_x86_64=()}}.}}
  
 
=== provides ===
 
=== provides ===
An array of package names that this package provides the features of (or a virtual package such as {{Ic|cron}} or {{Ic|sh}}). Packages that provide the same things can be installed at the same time unless conflict with each other (see below). If you use this variable, you should add the version ({{ic|pkgver}} and perhaps the {{ic|pkgrel}}) that this package will provide if dependencies may be affected by it. For instance, if you are providing a modified ''qt'' package named ''qt-foobar'' version 3.3.8 which provides ''qt'' then the {{ic|provides}} array should look like {{ic|1=provides=('qt=3.3.8')}}. Putting {{ic|1=provides=('qt')}} will cause to fail those dependencies that require a specific version of ''qt''. Do not add {{ic|pkgname}} to your provides array, this is done automatically.
+
An array of additional packages that the software provides the features of (or a virtual package such as {{Ic|cron}} or {{Ic|sh}}). Packages providing the same item can be installed side-by-side, unless at least one of them uses a {{ic|conflicts}} array.
 +
 
 +
{{Warning|A version that the package provides should be mentioned ({{ic|pkgver}} and perhaps the {{ic|pkgrel}}), if packages needing the software may require one. For instance, a modified ''qt'' package version 3.3.8, named ''qt-foobar'', should use {{ic|1=provides=('qt=3.3.8')}}; using {{ic|1=provides=('qt')}} would cause the dependencies that require a specific version of ''qt'' to fail. Do not add {{ic|pkgname}} to the {{ic|provides}} array, as it is done automatically.}}
  
 
=== conflicts ===
 
=== conflicts ===
An array of package names that may cause problems with this package if installed. Package with this name and all packages which {{Ic|provides}} virtual packages with this name will be removed. You can also specify the version properties of the conflicting packages in the same format as the {{ic|depends}} array.
+
 
 +
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 {{ic|depends}} array.
  
 
=== replaces ===
 
=== replaces ===
An array of obsolete package names that are replaced by this package, e.g. {{ic|1=replaces=('ethereal')}} for the {{pkg|wireshark}} package. After syncing with {{ic|pacman -Sy}}, it will immediately replace an installed package upon encountering another package with the matching {{ic|replaces}} in the repositories. If you are providing an alternate version of an already existing package, use the {{ic|conflicts}} variable which is only evaluated when actually installing the conflicting package.
+
An array of obsolete packages that are replaced by the package, e.g. {{pkg|wireshark-gtk}} uses {{ic|1=replaces=('wireshark')}}. When syncing, ''pacman'' will immediately replace an installed package upon encountering another package with the matching {{ic|replaces}} in the repositories. If providing an alternate version of an already existing package or uploading to the [[AUR]], use the {{ic|conflicts}} and {{ic|provides}} arrays, which are only evaluated when actually installing the conflicting package.
 +
 
 +
== Others ==
  
 
=== backup ===
 
=== 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 {{ic|/etc}}.
 
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 {{ic|/etc}}.
  
When updating, new version may be saved as {{ic|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 {{ic|file.pacsave}} unless the package was removed with {{ic|pacman -Rn}} command.  
+
Files in this array should use '''relative''' paths without the leading slash ({{ic|/}}) (e.g. {{ic|etc/pacman.conf}}, instead of {{ic|/etc/pacman.conf}}).
  
The file paths in this array should be relative paths (e.g. {{ic|etc/pacman.conf}}) not absolute paths (e.g. {{ic|/etc/pacman.conf}}). See also [[Pacnew and Pacsave Files]].
+
When updating, new versions may be saved as {{ic|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 files will be preserved as {{ic|file.pacsave}} unless the package was removed with the {{ic|pacman -Rn}} command.
 +
 
 +
See also [[Pacnew and Pacsave files]].
  
 
=== options ===
 
=== options ===
This array allows you to override some of the default behavior of {{ic|makepkg}}, defined in {{Ic|/etc/makepkg.conf}}. To set an option, include the option name in the array. To reverse the default behavior, place an '''{{ic|!}}''' at the front of the option. The following options may be placed in the array:
+
This array allows overriding some of the default behavior of ''makepkg'', defined in {{Ic|/etc/makepkg.conf}}. To set an option, include the name in the array. To reverse the default behavior, place an '''{{ic|!}}''' at the front.
  
* '''''strip''''' - Strips symbols from binaries and libraries. If you frequently use a debugger on programs or libraries, it may be helpful to disable this option.
+
The full list of the available options can be found in [https://www.archlinux.org/pacman/PKGBUILD.5.html PKGBUILD(5)].
* '''''docs''''' - Save {{ic|/doc}} directories.
+
* '''''libtool''''' - Leave ''libtool'' ({{ic|.la}}) files in packages.
+
* '''''staticlibs''''' - Leave static library (.a) files in packages
+
* '''''emptydirs''''' - Leave empty directories in packages.
+
* '''''zipman''''' - Compress ''man'' and ''info'' pages with ''gzip''.
+
* '''''purge''''' - Remove files specified by the {{ic|PURGE_TARGETS}} variable from the package.
+
* '''''upx''''' - Compress binary executable files using UPX. Additional options can be passed to UPX by specifying the {{ic|UPXFLAGS}} variable.
+
* '''''ccache''''' - Allow the use of {{ic|ccache}} during build. More useful in its negative form {{ic|!ccache}} with select packages that have problems building with {{ic|ccache}}.
+
* '''''distcc''''' - Allow the use of {{ic|distcc}} during build. More useful in its negative form {{ic|!distcc}} with select packages that have problems building with {{ic|distcc}}.
+
* '''''buildflags''''' - Allow the use of user-specific {{ic|buildflags}} (CFLAGS, CXXFLAGS, LDFLAGS) during build. More useful in its negative form {{ic|!buildflags}} with select packages that have problems building with custom {{ic|buildflags}}.
+
* '''''makeflags''''' - Allow the use of user-specific {{ic|makeflags}} during build. More useful in its negative form {{ic|!makeflags}} with select packages that have problems building with custom {{ic|makeflags}}.
+
  
 
=== install ===
 
=== install ===
The name of the {{ic|.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 name of the {{ic|.install}} script to be included in the package. This should be the same as {{ic|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:
 +
 
 +
* {{ic|pre_install}} — The script is run right before files are extracted. One argument is passed: new package version.
 +
* {{ic|post_install}} — The script is run right after files are extracted. One argument is passed: new package version.
 +
* {{ic|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.
 +
* {{ic|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.
 +
* {{ic|pre_remove}} — The script is run right before files are removed. One argument is passed: old package version.
 +
* {{ic|post_remove}} — The script is run right after files are removed. One argument is passed: old package version.
  
* '''''pre_install''''' - The script is run right before files are extracted. One argument is passed: new package version.
+
Each function is run [[chroot]]ed inside the ''pacman'' install directory. See [https://bbs.archlinux.org/viewtopic.php?pid=913891 this thread].
* '''''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 [https://bbs.archlinux.org/viewtopic.php?pid=913891 this thread].
+
{{Tip|A prototype {{ic|.install}} is provided at [https://projects.archlinux.org/pacman.git/plain/proto/proto.install /usr/share/pacman/proto.install].}}
  
{{Tip|A prototype {{ic|.install}} is provided at {{ic|/usr/share/pacman/proto.install}}.}}
+
{{Note|Do not end the script with {{ic|exit}}. This would prevent the contained functions from executing.}}
  
 
=== changelog ===
 
=== changelog ===
 +
 
The name of the package changelog. To view changelogs for installed packages (that have this file):
 
The name of the package changelog. To view changelogs for installed packages (that have this file):
pacman -Qc ''pkgname''
 
  
{{Tip|A prototype changelog file is provided at {{ic|/usr/share/pacman/ChangeLog.proto}}.}}
+
$ pacman -Qc ''pkgname''
 +
 
 +
== Sources ==
  
 
=== source ===
 
=== source ===
An array of files which are 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 {{ic|pkgname}} and {{ic|pkgver}} can be used effectively here (e.g. {{ic|<nowiki>source=(http://example.com/$pkgname-$pkgver.tar.gz)</nowiki>}})
 
  
{{Note|If you need to supply files which are not downloadable on the fly, e.g. self-made patches, you simply put those into the same directory where your {{ic|PKGBUILD}} file is in and add the filename to this array. Any paths you add here are resolved relative to the directory where the {{ic|PKGBUILD}} lies. Before the actual build process is started, all of the files referenced in this array will be downloaded or checked for existence, and {{ic|makepkg}} will not proceed if any are missing.}}
+
{{Note|Additional architecture-specific arrays can be added by appending an underscore and the architecture name, e.g. {{ic|1=source_i686=()}}. There must be a corresponding integrity array with checksums, e.g. {{ic|1=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 {{ic|pkgname}} and {{ic|pkgver}} can be used effectively here (e.g. {{ic|<nowiki>source=("https://example.com/$pkgname-$pkgver.tar.gz")</nowiki>}}).
 +
 
 +
Files can also be supplied directly in the location of the {{ic|PKGBUILD}} and added to this array. These paths are resolved relative to the directory of the {{ic|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.
 +
 
 +
''.install'' files are recognized automatically by ''makepkg'' and should not be included in the source array. Files in the source 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.
 +
 
 +
{{Note|File names of downloaded sources should be globally unique, because the [[makepkg#Package_output|SRCDEST]] variable could be the same directory for all packages. This can be ensured by specifying an alternative source name with the syntax {{ic|1=source=(<nowiki>'</nowiki>''filename''::''fileuri''<nowiki>'</nowiki>)}}, where the chosen {{ic|''filename''}} should be related to the package name:
  
{{Tip|You can specify a different name for the downloaded file - if the downloaded file has a different name for some reason like the URL had a GET parameter - using the following syntax: {{Ic|''filename''::''fileuri''}}, for example {{Ic|$pkgname-$pkgver.zip::<nowiki>http://199.91.152.193/7pd0l2tpkidg/jg2e1cynwii/Warez_collection_16.4.exe</nowiki>}}}}
+
{{bc|<nowiki>source=("project_name::hg+https://googlefontdirectory.googlecode.com/hg/")</nowiki>}}}}
  
 
=== noextract ===
 
=== noextract ===
An array of files listed under the {{ic|source}} array which should not be extracted from their archive format by {{ic|makepkg}}. This most commonly applies to archives which cannot be handled by {{ic|/usr/bin/bsdtar}} because {{Pkg|libarchive}} processes all files as streams rather than random access as {{Pkg|unzip}} does. In these situations, the alternative unarchiving tool (e.g., {{ic|unzip}}, {{ic|p7zip}}, etc.) should be added in the {{ic|makedepends}} array and the first line of the [[Creating Packages#The prepare() function|prepare()]] function should extract the source archive manually; for example:
 
  
unzip [source].zip
+
An array of files listed under {{ic|source}}, which should not be extracted from their archive format by ''makepkg''. This can be used with archives that cannot be handled by {{ic|/usr/bin/bsdtar}} or those that need to be installed as-is. If an alternative unarchiving tool is used (e.g. {{Pkg|lrzip}}), it should be added in the {{ic|makedepends}} array and the first line of the [[Creating packages#prepare()|prepare()]] function should extract the source archive manually; for example:
  
Note that while the {{ic|source}} array accepts URLs, {{ic|noextract}} is '''just''' the file name portion. So, for example, you would do something like this (simplified from [https://projects.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/grub grub2's PKGBUILD]):
+
prepare() {
 +
  lrzip -d ''source''.tar.lrz
 +
}
  
source=(<nowiki>"http://ftp.archlinux.org/other/grub2/grub2_extras_lua_r20.tar.xz"</nowiki>)
+
Note that while the {{ic|source}} array accepts URLs, {{ic|noextract}} is '''just''' the file name portion:
noextract=("grub2_extras_lua_r20.tar.xz")
+
  
To extract ''nothing'', you can do something fancy like this (taken from [https://projects.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/firefox-i18n#n123 firefox-i18n]):
+
<nowiki>source=("http://foo.org/bar/foobar.tar.xz")</nowiki>
 +
noextract=('foobar.tar.xz')
  
noextract=(${source[@]%%::*})
+
To extract ''nothing'', you can do something like this (taken from [https://projects.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/firefox-i18n#n123 firefox-i18n's PKGBUILD]):
  
{{Note|More conservative Bash substitution would include quotes, or possibly even a loop that calls {{ic|basename}}. If you have read this far, you should get the idea.}}
+
noextract=("${source[@]%%::*}")
 +
 
 +
=== 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 {{ic|gpg --list-keys --fingerprint <KEYID>}} to find out the fingerprint of the appropriate key.}}
 +
 
 +
== Integrity ==
 +
 
 +
{{Note|Additional architecture-specific arrays can be added by appending an underscore and the architecture name, e.g. {{ic|1=md5sums_i686=()}}, {{ic|1=sha256sums_x86_64=()}}.
 +
}}
 +
 
 +
These variables are arrays whose items are checksum strings that will be used to verify the integrity of the respective files in the [[#source|source]] array. You can also insert {{ic|SKIP}} for a particular file, and its checksum will not be tested.
 +
 
 +
Checksums are intended to verify the ''integrity'' of the downloaded files, '''not''' their ''authenticity'': for this reason, even though the MD5 algorithm is known to have considerable [[Wikipedia:MD5#Security|vulnerabilities]] when used for other purposes, it is recommended for file integrity as a faster alternative to SHA-2 hashes, especially when large files are present in the {{ic|source}} array. If possible, however, always test the authenticity of the files by adding their signatures to the {{ic|source}} array: in this case you will also be able to safely skip their checksum verification altogether, as described above.
 +
 
 +
The values for these variables can be auto-generated by [[makepkg]]'s {{ic|-g}}/{{ic|--geninteg}} option, then commonly appended with {{ic|makepkg -g >> PKGBUILD}}. The {{ic|updpkgsums}} command 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 {{ic|md5sums}} if none is set.
 +
 
 +
The file integrity checks to use can be set up with the {{ic|INTEGRITY_CHECK}} option in {{ic|/etc/makepkg.conf}}. See [https://www.archlinux.org/pacman/makepkg.conf.5.html makepkg.conf(5)].
  
 
=== md5sums ===
 
=== md5sums ===
An array of MD5 checksums of the files listed in the {{ic|source}} array. Once all files in the {{ic|source}} array are available, an MD5 hash of each file will be automatically generated and compared with the values of this array in the same order they appear in the {{ic|source}} array. While the order of the source files itself does not matter, it is important that it matches the order of this array since {{ic|makepkg}} cannot guess which checksum belongs to what source file. You can generate this array quickly and easily using the commands {{ic|updpkgsums}} or {{ic|makepkg -g}} in the directory that contains the {{ic|PKGBUILD}} file.
+
 
{{Note|The MD5 algorithm is known to have weaknesses, you should consider using a stronger alternative.}}
+
An array of 128-bit [[Wikipedia:MD5|MD5]] checksums of the files listed in the {{ic|source}} array.
  
 
=== sha1sums ===
 
=== sha1sums ===
An array of SHA-1 160-bit checksums. This is an alternative to {{ic|md5sums}} described above, but it is also known to have weaknesses, so you should consider using a stronger alternative. To enable use and generation of these checksums, be sure to set up the {{ic|INTEGRITY_CHECK}} option in {{ic|/etc/makepkg.conf}}. See {{ic|man makepkg.conf}}.
 
  
=== sha256sums, sha384sums, sha512sums ===
+
An array of 160-bit [[Wikipedia:SHA-1|SHA-1]] checksums of the files listed in the {{ic|source}} array.
An array of SHA-2 checksums with digest sizes 256, 384 and 512 bits respectively. These are alternatives to {{ic|md5sums}} described above and are generally believed to be stronger. To enable use and generation of these checksums, be sure to set up the {{ic|INTEGRITY_CHECK}} option in {{ic|/etc/makepkg.conf}}. See {{ic|man makepkg.conf}}.
+
 
 +
=== sha256sums ===
 +
 
 +
An array of [[Wikipedia:SHA-2|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 {{ic|sha256sums}}.
  
 
== See also ==
 
== See also ==
*[http://ix.io/66p Example PKGBUILD file]
+
*[https://www.archlinux.org/pacman/PKGBUILD.5.html PKGBUILD(5) Manual Page]
*[http://ix.io/66o Example .install file]
+
*[https://projects.archlinux.org/pacman.git/plain/proto/PKGBUILD.proto Example PKGBUILD file]

Latest revision as of 19:57, 24 July 2016

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

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

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, #Sources, 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

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 30102014, ensure to use the reversed date, i.e. 20141030 (ISO 8601 format). Otherwise it will not appear as a newer version.
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 pkgrel 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

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

pkgver=5.13
pkgrel=2
epoch=1
1:5.13-2

See pacman(8) 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 pkgdesc="Text editor for X11" instead of pkgdesc="Nedit is a text editor for X11".

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 i686 and x86_64, but projects like Arch Linux ARM provide support for other architectures such as arm for armv5, armv6h for armv6 hardfloat, armv7h for armv7 hardfloat, and aarch64 for armv8 64bit.

If a package is architecture-independent in its compiled state (shell scripts, fonts, themes, many types of extensions, etc.) then use arch=('any'). Please note that, as this is intended for packages that can be built once and used on any architecture, it will cause the package to be labeled -any as opposed to -i686, -x86_64, etc.

If instead a package can be compiled for any architecture, but is architecture-specific once compiled, specify all architectures officially supported by Arch, i.e. arch=('i686' 'x86_64').

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 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').
  • (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.

Dependencies

Note: Additional architecture-specific arrays can be added by appending an underscore and the architecture name, e.g. depends_i686=(), 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. The packages in the depends array are implicitly required to build the package, they should not be duplicated here.

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:
$ LC_ALL=C 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 relations

Note: Additional architecture-specific arrays can be added by appending an underscore and the architecture name, e.g. provides_i686=(), 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 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 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.

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. etc/pacman.conf, instead of /etc/pacman.conf).

When updating, new versions 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 files 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.
Note: Do not end the script with exit. This would prevent the contained functions from executing.

changelog

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

$ pacman -Qc pkgname

Sources

source

Note: Additional architecture-specific arrays can be added by appending an underscore and the architecture name, e.g. source_i686=(). 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.

.install files are recognized automatically by makepkg and should not be included in the source array. Files in the source 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.

Note: File names of downloaded sources should be globally unique, because the SRCDEST variable could be the same directory for all packages. This can be ensured by specifying an alternative source name with the syntax source=('filename::fileuri'), where the chosen filename should be related to the package name:
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[@]%%::*}")

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.

Integrity

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

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 SKIP for a particular file, and its checksum will not be tested.

Checksums are intended to verify the integrity of the downloaded files, not their authenticity: for this reason, even though the MD5 algorithm is known to have considerable vulnerabilities when used for other purposes, it is recommended for file integrity as a faster alternative to SHA-2 hashes, especially when large files are present in the source array. If possible, however, always test the authenticity of the files by adding their signatures to the source array: in this case you will also be able to safely skip their checksum verification altogether, as described above.

The values for these variables can be auto-generated by makepkg's -g/--geninteg option, then commonly appended with makepkg -g >> PKGBUILD. The updpkgsums command 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 md5sums if none is set.

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

md5sums

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

sha1sums

An array of 160-bit SHA-1 checksums of the files listed in the source 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 sha256sums.

See also