- Creating packages
- Contents
- Overview
- Preparation
- Prerequisite software
- Download and test the installation
- Creating a PKGBUILD
- Defining PKGBUILD variables
- PKGBUILD functions
- prepare()
- pkgver()
- build()
- check()
- package()
- Testing the PKGBUILD and package
- Checking package sanity
- Submitting packages to the AUR
- Summary
- Warnings
- More detailed guidelines
- PKGBUILD generators
- PKGBUILD
- Contents
- Package name
- pkgbase
- pkgname
- Version
- pkgver
- pkgrel
- epoch
- Generic
- pkgdesc
- license
- groups
- Dependencies
- depends
- makedepends
- checkdepends
- optdepends
- Package relations
- provides
- conflicts
- replaces
- Others
- backup
- options
- install
- changelog
- Sources
- source
- noextract
- validpgpkeys
- Integrity
- md5sums
- sha1sums
- sha256sums
- sha224sums, sha384sums, sha512sums
- b2sums
Creating packages
This article aims to assist users creating their own packages using the Arch Linux «ports-like» build system, also for submission in AUR. It covers creation of a PKGBUILD – a package build description file sourced by makepkg to create a binary package from source. If already in possession of a PKGBUILD , see makepkg. For instructions regarding existing rules and ways to improve package quality see Arch packaging standards.
Contents
Overview
Packages in Arch Linux are built using the makepkg utility and the information stored in a PKGBUILD file. When makepkg runs, it searches for a PKGBUILD in the current directory and follows the instructions in it to acquire the required files and/or compile them to be packed within a package file ( pkgname.pkg.tar.zst ). The resulting package contains binary files and installation instructions ready to be installed by pacman.
An Arch package is no more than a tar archive, or ‘tarball’, compressed using zstd(1) , which contains the following files generated by makepkg:
- The binary files to install.
- .PKGINFO : contains all the metadata needed by pacman to deal with packages, dependencies, etc.
- .BUILDINFO : contains information needed for reproducible builds. This file is present only if a package is built with pacman 5.1 or newer. See BUILDINFO(5) .
- .MTREE : contains hashes and timestamps of the files, which are included in the local database so that pacman can verify the integrity of the package.
- .INSTALL : an optional file used to execute commands after the install/upgrade/remove stage. (This file is present only if specified in the PKGBUILD .)
- .Changelog : an optional file kept by the package maintainer documenting the changes of the package. (It is not present in all packages.)
Preparation
Prerequisite software
First, ensure that the necessary tools are installed: the package group base-devel should be sufficient, it includes make and additional tools needed for compiling from source.
The key tool for building packages is makepkg (provided by pacman ), which does the following:
- Checks if package dependencies are installed.
- Downloads the source file(s) from the specified server(s).
- Unpacks the source file(s).
- Compiles the software and installs it under a fakeroot environment.
- Strips symbols from binaries and libraries.
- Generates the package meta file which is included with each package.
- Compresses the fakeroot environment into a package file.
- Stores the package file in the configured destination directory, which is the current working directory by default.
Download and test the installation
Download the source tarball of the software you want to package, extract it, and follow the author’s steps to install the program. Make a note of all commands and/or steps needed to compile and install it. You will be repeating those same commands in the PKGBUILD file.
Most software authors stick to the 3-step build cycle:
This is a good time to make sure the program is working correctly.
Creating a PKGBUILD
When makepkg is run, it looks for a PKGBUILD file in the current working directory. If it finds one, it downloads the software’s source code and compiles it according to the instructions specified in the PKGBUILD file. The instructions must be fully interpretable by the Bash shell. After successful completion, the resulting binaries and metadata of the package, i.e. package version and dependencies, are packed in a pkgname.pkg.tar.zst package file. The newly created package can be installed by simply using makepkg —install which will call pacman in the background, or by directly using pacman -U pkgname.pkg.tar.zst .
To start building a new package, first create a new directory for the package and change current directory into this one. Then, a PKGBUILD file needs to be created: a prototype PKGBUILD found in /usr/share/pacman/ can be used or you can start from a PKGBUILD from another package. The latter may be a good choice if a similar package already exists.
Defining PKGBUILD variables
Example PKGBUILDs are located in /usr/share/pacman/ . An explanation of possible PKGBUILD variables can be found in the PKGBUILD article.
makepkg defines two variables that you should use as part of the build and install process:
srcdir This points to the directory where makepkg extracts or symlinks all files in the source array. pkgdir This points to the directory where makepkg bundles the installed package, which becomes the root directory of your built package.
They contain absolute paths, which means you do not have to worry about your working directory if you use these variables properly.
PKGBUILD functions
When building a package, makepkg will invoke the following five functions if they have been defined in the PKGBUILD. Function package() is required in every PKGBUILD and will always be invoked. If any of the other functions is not defined, makepkg will simply skip the invocation of that function.
During the build, the functions are invoked in the order in which they are listed here.
prepare()
With this function, commands that are used to prepare sources for building are run, such as patching. This function runs right after package extraction, before pkgver() and the build function. If extraction is skipped ( makepkg —noextract ), then prepare() is not run.
pkgver()
pkgver() runs after the sources are fetched, extracted and prepare() executed. So you can update the pkgver variable during a makepkg stage.
This is particularly useful if you are making git/svn/hg/etc. packages, where the build process may remain the same, but the source could be updated every day, even every hour. The old way of doing this was to put the date into the pkgver field which, if the software was not updated, makepkg would still rebuild it thinking the version had changed. Some useful commands for this are git describe , hg identify -ni , etc. Please test these before submitting a PKGBUILD, as a failure in the pkgver() function can stop a build in its tracks.
build()
Now you need to implement the build() function in the PKGBUILD file. This function uses common shell commands in Bash syntax to automatically compile software and create a directory called pkg to install the software to. This allows makepkg to package files without having to sift through your file system.
The first step in the build() function is to change into the directory created by uncompressing the source tarball. makepkg will change the current directory to $srcdir before executing the build() function. Therefore, in most cases, like suggested in /usr/share/pacman/PKGBUILD.proto , the first command will look like this:
Now, you need to list the same commands you used when you manually compiled the software. The build() function in essence automates everything you did by hand and compiles the software in the fakeroot build environment. If the software you are packaging uses a configure script, it is good practice to use —prefix=/usr when building packages for pacman. A lot of software installs files relative to the /usr/local directory, which should only be done if you are manually building from source. All Arch Linux packages should use the /usr directory. As seen in the /usr/share/pacman/PKGBUILD.proto file, the next two lines often look like this:
check()
Place for calls to make check and similar testing routines. It is highly recommended to have check() as it helps to make sure software has been built correctly and works fine with its dependencies.
Users who do not need it (and occasionally maintainers who can not fix a package for this to pass) can disable it using BUILDENV+=(‘!check’) in PKGBUILD/makepkg.conf or call makepkg with —nocheck flag.
package()
The final step is to put the compiled files in a directory where makepkg can retrieve them to create a package. This by default is the pkg directory—a simple fakeroot environment. The pkg directory replicates the hierarchy of the root file system of the software’s installation paths. If you have to manually place files under the root of your filesystem, you should install them in the pkg directory under the same directory structure. For example, if you want to install a file to /usr/bin , it should instead be placed under $pkgdir/usr/bin . Very few install procedures require the user to copy dozens of files manually. Instead, for most software, calling make install will do so. The final line should look like the following in order to correctly install the software in the pkg directory:
makepkg —repackage runs only the package() function, so it creates a package without building. This may save time e.g. if you have changed just the depends variable of the package.
Testing the PKGBUILD and package
As you are writing the build() function, you will want to test your changes frequently to ensure there are no bugs. You can do this using the makepkg command in the directory containing the PKGBUILD file. With a properly formatted PKGBUILD , makepkg will create a package; with a broken or unfinished PKGBUILD , it will raise an error.
If makepkg finishes successfully, it will place a file named pkgname-pkgver.pkg.tar.zst in your working directory. This package can be installed with the pacman -U command. However, just because a package file was built does not imply that it is fully functional. It might conceivably contain only the directory and no files whatsoever if, for example, a prefix was specified improperly. You can use pacman’s query functions to display a list of files contained in the package and the dependencies it requires with pacman -Qlp [package file] and pacman -Qip [package file] respectively.
If the package looks sane, then you are done! However, if you plan on releasing the PKGBUILD file, it is imperative that you check and double-check the contents of the depends array.
Also ensure that the package binaries actually run flawlessly! It is annoying to release a package that contains all necessary files, but crashes because of some obscure configuration option that does not quite work well with the rest of the system. If you are only going to compile packages for your own system, though, you do not need to worry too much about this quality assurance step, as you are the only person suffering from mistakes, after all.
Checking package sanity
After testing package functionality check it for errors using namcap:
- Check PKGBUILD contents for common errors and package file hierarchy for unnecessary/misplaced files
- Scan all ELF files in package using ldd , automatically reporting which packages with required shared libraries are missing from depends and which can be omitted as transitive dependencies
- Heuristically search for missing and redundant dependencies
Get into the habit of checking your packages with namcap to avoid having to fix the simplest mistakes after package submission.
Submitting packages to the AUR
Please read AUR submission guidelines for a detailed description of the submission process.
Summary
- Download the source tarball of the software to package.
- Try compiling the package and installing it into an arbitrary directory.
- Copy over the prototype /usr/share/pacman/PKGBUILD.proto and rename it to PKGBUILD in a temporary working directory.
- Edit the PKGBUILD according to the needs of your package.
- Run makepkg and check whether the package builds correctly.
- If not, repeat the previous two steps.
Warnings
- Before you can automate the package building process, you should have done it manually at least once unless you know exactly what you are doing in advance, in which case you would not be reading this in the first place. Unfortunately, although a good bunch of program authors stick to the 3-step build cycle of » ./configure ; make ; make install «, this is not always the case, and things can get real ugly if you have to apply patches to make everything work at all. Rule of thumb: If you cannot get the program to compile from the source tarball, and make it install itself to a defined, temporary subdirectory, you do not even need to try packaging it. There is not any magic pixie dust in makepkg that makes source problems go away.
- In a few cases, the packages are not even available as source and you have to use something like sh installer.run to get it to work. You will have to do quite a bit of research (read READMEs, INSTALL instructions, man pages, perhaps ebuilds from Gentoo or other package installers, possibly even the MAKEFILEs or source code) to get it working. In some really bad cases, you have to edit the source files to get it to work at all. However, makepkg needs to be completely autonomous, with no user input. Therefore if you need to edit the makefiles, you may have to bundle a custom patch with the PKGBUILD and install it from inside the prepare() function, or you might have to issue some sed commands from inside the prepare() function.
More detailed guidelines
PKGBUILD generators
PKGBUILDs for some packages can be generated automatically.
Источник
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 ( pkgname.pkg.tar.zst ). 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 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.
Contents
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 pkgname 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. pkgname=’foo’ , or, for split packages, an array of names, e.g. pkgname=(‘foo’ ‘bar’) . 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, 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 .
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 pkgver variable is used later in the PKGBUILD , then the underscore can easily be substituted for a hyphen, e.g. source=(«$pkgname-$
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
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 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.
An array of architectures that the PKGBUILD is intended to build and work on. Arch officially supports only x86_64 , but other projects may support other architectures. For example, Arch Linux 32 provides support for i686 and pentium4 and Arch Linux ARM provides support for arm (armv5), armv6h (armv6 hardfloat), armv7h (armv7 hardfloat), and aarch64 (armv8 64-bit).
There are two types of values the array can use:
- arch=(‘any’) 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.).
- arch=(‘x86_64’) 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 $CARCH during a build.
The URL of the official site of the software being packaged.
license
The license under which the software is distributed. The licenses package (a dependency of the base meta package) contains many commonly used licenses, which are installed under /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:
- 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.
- Install the license in: /usr/share/licenses/pkgname/ , e.g. /usr/share/licenses/foobar/LICENSE . One good way to do this is by using:
- 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 licenses package. For the sake of the license array, it is treated as a common license ( license=(‘BSD’) , license=(‘ISC’) , license=(‘MIT’) , license=(‘ZLIB’) , license=(‘Python’) , 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 /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.
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 plasma , 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 package() 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. depends=(‘foobar>=1.8.0’ ‘foobar .
This article or section is a candidate for moving to Arch package guidelines.
The depends 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 python 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. depends=(‘libfoobar.so’) , 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. depends=(‘libfoobar.so=2’) .
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.
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.
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:
Package relations
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.
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.
Note that conflicts are checked against pkgname as well as names specified in the provides array. Hence, if your package provides a feature and another package provides the same feature, you do not need to specify that conflicting package in your conflicts array. Let us take a concrete example:
- netbeans implicitly provides netbeans as the pkgname itself
- netbeans-javaseAUR provides netbeans and conflicts with netbeans
- netbeans-phpAUR provides netbeans and conflicts with netbeans , but does not need to explicitly conflict with netbeans-javaseAUR since packages providing the same feature are implicitly in conflict.
replaces
An array of obsolete packages that are replaced by the package, e.g. wireshark-qt 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.
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:
- 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.
changelog
The name of the package changelog. To view changelogs for installed packages (that have this file):
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 pkgver can be used effectively here; e.g. source=(«https://example.com/$pkgname-$pkgver.tar.gz») .
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 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.
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:
Note that while the source array accepts URLs, noextract is just the file name portion:
To extract nothing, you can do something like this:
- If source contains only plain URLs without custom file names, strip the source array before the last slash:
- If source contains only entries with custom file names, strip the source 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.
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 SKIP 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: sha256 over sha1 , and sha1 over md5 . 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 / —geninteg option, then commonly appended with makepkg -g >> PKGBUILD . The updpkgsums(8) command from pacman-contrib 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 .
b2sums
An array of BLAKE2 checksums with digest size of 512 bits.
Источник