<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Papiris</id>
	<title>Alpine Linux - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Papiris"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Papiris"/>
	<updated>2026-05-01T23:50:49Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_Package_Keeper&amp;diff=26240</id>
		<title>Alpine Package Keeper</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_Package_Keeper&amp;diff=26240"/>
		<updated>2024-01-12T11:56:56Z</updated>

		<summary type="html">&lt;p&gt;Papiris: /* Commit hooks */ : replace advice about symlinking executables, with advice about using absolute paths; for security&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--For searching: apk, APK--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{TOC right}}&lt;br /&gt;
&lt;br /&gt;
Because Alpine Linux is designed to run from RAM, package management involves two phases:&lt;br /&gt;
* Installing / Upgrading / Deleting packages on a running system.&lt;br /&gt;
* Restoring a system to a previously configured state (e.g. after reboot), including all previously installed packages and locally modified configuration files. &#039;&#039;&#039;(RAM-Based Installs Only)&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;apk&#039;&#039;&#039; is the tool used to install, upgrade, or delete software on a running system.&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;lbu&#039;&#039;&#039; is the tool used to capture the data necessary to restore a system to a previously configured state.&lt;br /&gt;
&lt;br /&gt;
This page documents the [https://git.alpinelinux.org/apk-tools/ apk tool] - See the [[Alpine_local_backup|Alpine Local Backup page]] for the lbu tool.&lt;br /&gt;
&lt;br /&gt;
= Overview =&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;apk&#039;&#039;&#039; tool supports the following operations:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
| [[#Add a Package|add]] &lt;br /&gt;
| Add new packages or upgrade packages to the running system&lt;br /&gt;
|-&lt;br /&gt;
| [[#Remove a Package|del]]&lt;br /&gt;
| Delete packages from the running system&lt;br /&gt;
|-&lt;br /&gt;
| fix &lt;br /&gt;
| Attempt to repair or upgrade an installed package &lt;br /&gt;
|-&lt;br /&gt;
| [[#Update the Package list|update]] &lt;br /&gt;
| Update the index of available packages&lt;br /&gt;
|-&lt;br /&gt;
| [[#Information on Packages|info]]&lt;br /&gt;
| Prints information about installed or available packages&lt;br /&gt;
|-&lt;br /&gt;
| [[#Search for Packages|search]] &lt;br /&gt;
| Search for packages or descriptions with wildcard patterns&lt;br /&gt;
|-&lt;br /&gt;
| [[#Upgrade a Running System|upgrade]]&lt;br /&gt;
| Upgrade the currently installed packages&lt;br /&gt;
|-&lt;br /&gt;
| [[#Cache maintenance|cache]]&lt;br /&gt;
| Maintenance operations for locally cached package repository&lt;br /&gt;
|-&lt;br /&gt;
| version &lt;br /&gt;
| Compare version differences between installed and available packages&lt;br /&gt;
|-&lt;br /&gt;
| index &lt;br /&gt;
| create a repository index from a list of packages&lt;br /&gt;
|-&lt;br /&gt;
| fetch &lt;br /&gt;
| download (but not install) packages&lt;br /&gt;
|-&lt;br /&gt;
| audit &lt;br /&gt;
| List changes to the file system from pristine package install state&lt;br /&gt;
|-&lt;br /&gt;
| verify &lt;br /&gt;
| Verify a package signature&lt;br /&gt;
|- &lt;br /&gt;
| dot&lt;br /&gt;
| Create a [https://graphviz.org/ graphviz] graph description for a given package&lt;br /&gt;
|- &lt;br /&gt;
| [[#apk_policy|policy]]&lt;br /&gt;
| Display the repository that updates a given package, plus repositories that also offer the package&lt;br /&gt;
|- &lt;br /&gt;
| stats &lt;br /&gt;
| Display statistics, including number of packages installed and available, number of directories and files, etc.&lt;br /&gt;
|- &lt;br /&gt;
| manifest&lt;br /&gt;
| Display checksums for files contained in a given package&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Packages and Repositories =&lt;br /&gt;
&lt;br /&gt;
Software packages for Alpine Linux are digitally signed tar.gz archives containing programs, configuration files, and dependency metadata. They have the extension &amp;lt;code&amp;gt;.apk&amp;lt;/code&amp;gt;, and are often called &amp;quot;a-packs&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The packages are stored in one or more &#039;&#039;repositories&#039;&#039;. A repository is simply a directory with a collection of *.apk files.  The directory must include a special index file, named {{Path|APKINDEX.tar.gz}} to be considered a repository.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;apk&#039;&#039;&#039; utility can install packages from multiple repositories.  The list of repositories to check is stored in {{Path|/etc/apk/repositories}}, one repository per line. If you booted from a USB stick ({{Path|/media/sda1}}) or CD-ROM ({{Path|/media/cdrom}}), your repository file probably looks something like this:&lt;br /&gt;
&lt;br /&gt;
{{Cat|/etc/apk/repositories|/media/sda1/apks/}}&lt;br /&gt;
&lt;br /&gt;
In addition to local repositories, the &#039;&#039;&#039;apk&#039;&#039;&#039; utility uses &#039;&#039;&#039;busybox wget&#039;&#039;&#039; to fetch packages using &#039;&#039;http:&#039;&#039;, &#039;&#039;https:&#039;&#039;, &#039;&#039;ftp:&#039;&#039; or &#039;&#039;rsync:&#039;&#039; protocols. The following is a valid repository file:&lt;br /&gt;
&lt;br /&gt;
{{Cat|/etc/apk/repositories|&lt;br /&gt;
/media/sda1/apks&lt;br /&gt;
http://dl-3.alpinelinux.org/alpine/v2.6/main&lt;br /&gt;
https://dl-3.alpinelinux.org/alpine/v2.6/main&lt;br /&gt;
ftp://dl-3.alpinelinux.org/alpine/v2.6/main&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Note|  A list of public repositories is in [https://mirrors.alpinelinux.org/ mirrors.alpinelinux.org].  Accepted protocols vary.}}&lt;br /&gt;
&lt;br /&gt;
== Repository pinning ==&lt;br /&gt;
&lt;br /&gt;
You can specify additional &amp;quot;tagged&amp;quot; repositories in {{Path|/etc/apk/repositories}}:&lt;br /&gt;
&lt;br /&gt;
{{Cat|/etc/apk/repositories|&lt;br /&gt;
https://dl-cdn.alpinelinux.org/alpine/v3.18/main&lt;br /&gt;
https://dl-cdn.alpinelinux.org/alpine/v3.18/community&lt;br /&gt;
@personal https:/personal-repo.example.com/alpine-apks/&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
After which you can &amp;quot;pin&amp;quot; dependencies to these tags using:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add application@personal}}&lt;br /&gt;
&lt;br /&gt;
apk will by default only use the untagged repositories, but adding a package with a @tag:&lt;br /&gt;
&lt;br /&gt;
1. will prefer the repository with that tag for the named package, even if a later version of the package is available in another repository&lt;br /&gt;
&lt;br /&gt;
2. &#039;&#039;allows&#039;&#039; pulling in dependencies for the tagged package from the tagged repository (though it &#039;&#039;prefers&#039;&#039; to use untagged repositories to satisfy dependencies if possible)&lt;br /&gt;
&lt;br /&gt;
== Commandline repository options ==&lt;br /&gt;
&lt;br /&gt;
By default, the &#039;&#039;&#039;apk&#039;&#039;&#039; utility will use the system repositories for all operations. This behavior can be overridden by the following options:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
| --repositories-file REPOFILE&lt;br /&gt;
| Override the system repositories by specifying a repositories file.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;nowiki&amp;gt;-X|--repository REPO&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| Specify a supplemental repository that will be used in addition to the system repositories. This option can be provided multiple times.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Update the Package list =&lt;br /&gt;
&lt;br /&gt;
Remote repositories change as packages are added and upgraded.   To get the latest list of available packages, use the &#039;&#039;update&#039;&#039; command.  The command downloads the {{Path|APKINDEX.tar.gz}} from each repository and stores it in the local cache, typically {{Path|/var/cache/apk/}}, {{Path|/var/lib/apk/}} or {{Path|/etc/apk/cache/}}.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk update}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
fetch https://dl-3.alpinelinux.org/alpine/v2.1/main/APKINDEX.tar.gz&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adding the &amp;lt;code&amp;gt;--update-cache&amp;lt;/code&amp;gt;, or for short &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; switch to another apk command, as in &amp;lt;code&amp;gt;apk --update-cache upgrade&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;apk -U add ...&amp;lt;/code&amp;gt;, the command has the same effect as first running &amp;lt;code&amp;gt;apk update&amp;lt;/code&amp;gt; before the other apk command.&lt;br /&gt;
&lt;br /&gt;
{{Tip|With remote repositories, it is a good idea to always do an &#039;&#039;&#039;update&#039;&#039;&#039; right &#039;&#039;&#039;before&#039;&#039;&#039; doing an &#039;&#039;&#039;upgrade or add&#039;&#039;&#039; command. That way the command will install the latest available packages.}}&lt;br /&gt;
&lt;br /&gt;
= Add a Package =&lt;br /&gt;
&lt;br /&gt;
Use &#039;&#039;&#039;add&#039;&#039;&#039; to install packages from a repository. Any necessary dependencies are also installed. If you have multiple repositories, the &#039;&#039;&#039;add&#039;&#039;&#039; command installs the newest package.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add openssh&lt;br /&gt;
apk add openssh openntp vim}}&lt;br /&gt;
&lt;br /&gt;
If you only have the main repository enabled in your configuration, apk will not include packages from the other repositories. To install a package from the edge/testing repository without changing your repository configuration file, use the command below. This will tell apk to use that particular repository.&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add cherokee --update-cache --repository https://dl-cdn.alpinelinux.org/alpine/edge/testing/ --allow-untrusted}}&lt;br /&gt;
&lt;br /&gt;
{{Note|Be careful when using third-party or the testing repository. Your system can go down.}}&lt;br /&gt;
&lt;br /&gt;
= Add a local Package =&lt;br /&gt;
&lt;br /&gt;
To install a locally available apk package, for example if this device has no internet access but you can upload apk packages directly to it, use the &#039;&#039;&#039;--allow-untrusted&#039;&#039;&#039; flag:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add --allow-untrusted /path/to/file.apk}}&lt;br /&gt;
&lt;br /&gt;
Note that multiple packages can be given.  When installing a local package, all dependencies should also be specified.  For example:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add --allow-untrusted /var/tig-2.2-r0.apk /var/git-2.11.1-20.apk}}&lt;br /&gt;
&lt;br /&gt;
= Remove a Package  =&lt;br /&gt;
Use &#039;&#039;&#039;del&#039;&#039;&#039; to remove a package (and dependencies that are no longer needed.)  &lt;br /&gt;
&lt;br /&gt;
{{cmd|apk del openssh&lt;br /&gt;
apk del openssh openntp vim}}&lt;br /&gt;
&lt;br /&gt;
= Upgrade a Running System =&lt;br /&gt;
&lt;br /&gt;
=== Packages in general ===&lt;br /&gt;
&lt;br /&gt;
To get the latest security upgrades and bugfixes available for the &#039;&#039;installed&#039;&#039; packages of a running system, first &#039;&#039;&#039;update&#039;&#039;&#039; the list of available packages and then &#039;&#039;&#039;upgrade&#039;&#039;&#039; the installed packages:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk update&lt;br /&gt;
apk upgrade&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Or, combining the same into one single command:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk -U upgrade&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Here is an example, showing the procedure on a system that has several additional [[#Repository_pinning|repositories pinned]]:&lt;br /&gt;
&lt;br /&gt;
 # apk update&lt;br /&gt;
 fetch &amp;lt;nowiki&amp;gt;https://dl-3.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 fetch &amp;lt;nowiki&amp;gt;https://dl-3.alpinelinux.org/alpine/v3.6/community/x86_64/APKINDEX.tar.gz&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 fetch &amp;lt;nowiki&amp;gt;https://dl-3.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 fetch &amp;lt;nowiki&amp;gt;https://dl-3.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 fetch &amp;lt;nowiki&amp;gt;https://dl-3.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 v3.6.2-191-gf98d79930f &amp;lt;nowiki&amp;gt;[https://dl-3.alpinelinux.org/alpine/v3.6/main]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 v3.6.2-190-ga5d68c47df &amp;lt;nowiki&amp;gt;[https://dl-3.alpinelinux.org/alpine/v3.6/community]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 v3.6.0-4618-g0bf77c9821 &amp;lt;nowiki&amp;gt;[https://dl-3.alpinelinux.org/alpine/edge/main]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 v3.6.0-4605-g85ed51dd83 &amp;lt;nowiki&amp;gt;[https://dl-3.alpinelinux.org/alpine/edge/community]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 v3.6.0-4624-g11f1b9c8ab &amp;lt;nowiki&amp;gt;[https://dl-3.alpinelinux.org/alpine/edge/testing]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 OK: 20118 distinct packages available&lt;br /&gt;
 &lt;br /&gt;
 # apk upgrade&lt;br /&gt;
 (1/2) Upgrading extra-cmake-modules@testing (5.38.0-r0 -&amp;gt; 5.39.0-r0)&lt;br /&gt;
 (2/2) Upgrading extra-cmake-modules-doc@testing (5.38.0-r0 -&amp;gt; 5.39.0-r0)&lt;br /&gt;
 Executing mdocml-apropos-1.14.1-r0.trigger&lt;br /&gt;
 OK: 2635 MiB in 803 packages&lt;br /&gt;
&lt;br /&gt;
To upgrade only &#039;&#039;specific&#039;&#039; packages, use the &#039;&#039;&#039;upgrade&#039;&#039;&#039; command and specify them:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk update&lt;br /&gt;
apk upgrade busybox&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To enable unattended, automatic upgrades of packages, see the {{pkg|apk-autoupdate}} package.&lt;br /&gt;
&lt;br /&gt;
To upgrade to a newer release, refer to the corresponding release notes and [[Upgrading_Alpine]].&lt;br /&gt;
&lt;br /&gt;
=== Upgrading &amp;quot;diskless&amp;quot; and &amp;quot;data&amp;quot; disk mode installs ===&lt;br /&gt;
&lt;br /&gt;
If booting a &amp;quot;diskless&amp;quot; system from a read-only device, or iso image on writable media, it&#039;s not possible to update the boot files (kernel, modules, firmware, ...) that reside on that device.&lt;br /&gt;
&lt;br /&gt;
It becomes possible to update the boot files, though, if using a boot device that is writable and has been prepared with &amp;lt;code&amp;gt;[[Alpine_setup_scripts#setup-bootable|setup-bootable]]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
However, even then, the kernel, with its modules and firmware files, can still not be updated directly through regular packages updates. Instead, there is the &amp;lt;code&amp;gt;update-kernel&amp;lt;/code&amp;gt; script that can generate initfs images and install them together with upgraded kernels.&lt;br /&gt;
&lt;br /&gt;
Upgrading can be done as follows.&lt;br /&gt;
{{cmd|apk add mkinitfs&lt;br /&gt;
}}&lt;br /&gt;
This package is required for the generation of the initial filesystem used during boot.&lt;br /&gt;
* Additional initfs features that are missing in the default configuration, like the [[Btrfs|btrfs]] filesystem support (at the time of writing, to allow loading .apkovl configs and package cache during boot), may be enabled in &amp;lt;code&amp;gt;/etc/mkinitfs/mkinitfs.conf&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Available initfs features may be listed with &amp;lt;code&amp;gt;ls /etc/mkinitfs/features.d&amp;lt;/code&amp;gt;&lt;br /&gt;
{{cmd|ls /etc/mkinitfs/features.d&lt;br /&gt;
apk add nano&lt;br /&gt;
nano /etc/mkinitfs/mkinitfs.conf&lt;br /&gt;
lbu commit&lt;br /&gt;
}}&lt;br /&gt;
Finally update the kernel and its boot environment.&lt;br /&gt;
{{cmd|update-kernel /media/sdXY/boot/&lt;br /&gt;
}}&lt;br /&gt;
* An &amp;lt;code&amp;gt;update-kernel&amp;lt;/code&amp;gt; run needs at least 8 GB free ram memory to avoid a broken modloop-image.&lt;br /&gt;
* See &amp;lt;code&amp;gt;update-kernel --help&amp;lt;/code&amp;gt; for options to manually add additional module or firmware packages.&lt;br /&gt;
&lt;br /&gt;
= Search for Packages =&lt;br /&gt;
The &#039;&#039;&#039;search&#039;&#039;&#039; command searches the repository Index files for installable packages. &lt;br /&gt;
&lt;br /&gt;
The return format is &#039;&#039;&#039;Package&#039;&#039;&#039;-&#039;&#039;&#039;Version&#039;&#039;&#039;. Omit &#039;&#039;&#039;Version&#039;&#039;&#039; for &#039;&#039;apk add &#039;&#039;&#039;Package&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
* To list all packages available, along with their descriptions: {{cmd|apk search -v}}&lt;br /&gt;
* To list all packages are part of the ACF system: {{cmd|apk search -v &#039;acf*&#039; }}&lt;br /&gt;
* To list all packages that list NTP as part of their description, use the &#039;&#039;-d&#039;&#039; or &#039;&#039;--description&#039;&#039; option: {{cmd|apk search -v --description &#039;NTP&#039; }}&lt;br /&gt;
&lt;br /&gt;
= Information on Packages =&lt;br /&gt;
&lt;br /&gt;
== apk info ==&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;info&#039;&#039;&#039; command provides information on the contents of packages, their dependencies, and which files belong to a package.&lt;br /&gt;
&lt;br /&gt;
For a given package, each element can be chosen (for example, &#039;&#039;-w&#039;&#039; to show just the webpage information), or all information displayed with the &#039;&#039;-a&#039;&#039; command.&lt;br /&gt;
&lt;br /&gt;
Example: {{cmd|apk info -a zlib}}&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 description:&#039;&#039;&#039;&lt;br /&gt;
 A compression/decompression Library&lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 webpage:&#039;&#039;&#039;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;https://zlib.net&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 installed size:&#039;&#039;&#039;&lt;br /&gt;
 94208&lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 depends on:&#039;&#039;&#039;&lt;br /&gt;
 libc0.9.32&lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 is required by:&#039;&#039;&#039;&lt;br /&gt;
 libcrypto1.0-1.0.0-r0&lt;br /&gt;
 apk-tools-2.0.2-r4&lt;br /&gt;
 openssh-client-5.4_p1-r2&lt;br /&gt;
 openssh-5.4_p1-r2&lt;br /&gt;
 libssl1.0-1.0.0-r0&lt;br /&gt;
 freeswitch-1.0.6-r6&lt;br /&gt;
 atop-1.25-r0 &lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 contains:&#039;&#039;&#039;&lt;br /&gt;
 lib/libz.so.1.2.5&lt;br /&gt;
 lib/libz.so.1&lt;br /&gt;
 lib/libz.so &lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 triggers:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As shown in the example you can determine&lt;br /&gt;
* The &#039;&#039;&#039;description&#039;&#039;&#039; of the package (&#039;&#039;-d&#039;&#039; or &#039;&#039;--description&#039;&#039;)&lt;br /&gt;
* The &#039;&#039;&#039;webpage&#039;&#039;&#039; where the application is hosted (&#039;&#039;-w&#039;&#039; or &#039;&#039;--webpage&#039;&#039;)&lt;br /&gt;
* The &#039;&#039;&#039;size&#039;&#039;&#039; the package will require once installed (in bytes) (&#039;&#039;-s&#039;&#039; or &#039;&#039;--size&#039;&#039;)&lt;br /&gt;
* What packages are required to use this one  (&#039;&#039;&#039;depends&#039;&#039;&#039;) (&#039;&#039;-R&#039;&#039; or &#039;&#039;--depends&#039;&#039;)&lt;br /&gt;
* What packages require this one to be installed (&#039;&#039;&#039;required by&#039;&#039;&#039;) (&#039;&#039;-r&#039;&#039; or &#039;&#039;--rdepends&#039;&#039;)&lt;br /&gt;
* The &#039;&#039;&#039;contents&#039;&#039;&#039; of the package, that is, which files it installs (&#039;&#039;-L&#039;&#039; or &#039;&#039;--contents&#039;&#039;)&lt;br /&gt;
* Any &#039;&#039;&#039;triggers&#039;&#039;&#039; this package sets. (&#039;&#039;-t&#039;&#039; or &#039;&#039;--triggers&#039;&#039;) Listed here are directories that are watched; if a change happens to the directory, then the trigger script is run at the end of the apk add/delete. For example, doing a depmod once after installing all packages that add kernel modules.&lt;br /&gt;
&lt;br /&gt;
{{Tip|The &#039;&#039;&#039;info&#039;&#039;&#039; command is also useful to determine which package a file belongs to.  For example: {{cmd|apk info --who-owns /sbin/lbu}} will display&lt;br /&gt;
&lt;br /&gt;
 /sbin/lbu is owned by alpine-conf-x.x-rx&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Listing installed packages ===&lt;br /&gt;
&lt;br /&gt;
To list all installed packages, use:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk info}}&lt;br /&gt;
&lt;br /&gt;
To list all installed packages in alphabetical order, with a description of each, do:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk -vv info|sort}}&lt;br /&gt;
&lt;br /&gt;
The apk tool does not have a subcommand to list manually-installed packages that do not have reverse dependencies. To get this information on a traditional system that is not using [[Alpine local backup|lbu]], try this script. Note that this approach will also list core packages like alpine-base that should not be removed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/sh&lt;br /&gt;
apk info | grep -ve &#039;-doc$&#039; | sort | while read pkg&lt;br /&gt;
        do&lt;br /&gt;
                rdep=`apk info -qr &amp;quot;$pkg&amp;quot;`&lt;br /&gt;
                [ -z &amp;quot;$rdep&amp;quot; ] &amp;amp;&amp;amp; echo $pkg&lt;br /&gt;
        done&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== apk policy ==&lt;br /&gt;
&lt;br /&gt;
To display the repository a package was installed from and will be updated from, plus any [[#Repository_pinning|tagged]] or enabled repositories where it is also offered, if any, for this architecture - its &#039;&#039;&#039;policy&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk policy &#039;&#039;package&#039;&#039;}}&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 $ apk policy vlc&lt;br /&gt;
 vlc policy:&lt;br /&gt;
  2.2.6-r1:&lt;br /&gt;
    lib/apk/db/installed&lt;br /&gt;
    https://dl-3.alpinelinux.org/alpine/v3.7/community&lt;br /&gt;
  3.0.0_rc2-r1:&lt;br /&gt;
    @edgecommunity https://dl-3.alpinelinux.org/alpine/edge/community&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Additional apk Commands =&lt;br /&gt;
In progress...&lt;br /&gt;
&lt;br /&gt;
= Local Cache =&lt;br /&gt;
&lt;br /&gt;
{{:Local_APK_cache}}&lt;br /&gt;
&lt;br /&gt;
= Advanced APK Usage =&lt;br /&gt;
&lt;br /&gt;
== Holding a specific package back ==&lt;br /&gt;
&lt;br /&gt;
In certain cases, you may want to upgrade a system, but keep a specific package at a back level. It is possible to add &amp;quot;sticky&amp;quot; or versioned dependencies. For instance, to hold the &#039;&#039;asterisk&#039;&#039; package to the 1.6.2 level or lower:&lt;br /&gt;
{{cmd|1=apk add asterisk=1.6.0.21-r0}}&lt;br /&gt;
or&lt;br /&gt;
{{cmd|apk add &#039;asterisk&amp;lt;1.6.1&#039;}}&lt;br /&gt;
&lt;br /&gt;
after which a {{cmd|apk upgrade}}&lt;br /&gt;
&lt;br /&gt;
will upgrade the entire system, keeping the asterisk package at the 1.6.0 or lower level&lt;br /&gt;
&lt;br /&gt;
To later upgrade to the current version,&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add &#039;asterisk&amp;gt;1.6.1&#039;}}&lt;br /&gt;
&lt;br /&gt;
will ensure that 1.6.1 is the minimum version used.&lt;br /&gt;
&lt;br /&gt;
You can also use &amp;quot;fuzzy&amp;quot; version matching to pin the version to a major/minor release.  For example:&lt;br /&gt;
&lt;br /&gt;
{{cmd|1=apk add &#039;asterisk=~1.6&#039;}}&lt;br /&gt;
&lt;br /&gt;
will match any version of asterisk that starts with 1.6 (such as 1.6.0.21-r0 or 1.6.9.31-r9)  &amp;lt;ref&amp;gt;[https://git.alpinelinux.org/apk-tools/commit/?id=693b4bcdb0f22904a521a7c8ac4f13e697dc4d71 Alpine source commit message]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you desire deterministic, repeatable package installation (such as with containerized environments) via package pinning, it is important to understand your package repo&#039;s version retention rules.  For example, most Alpine package repos contain an &amp;quot;edge&amp;quot; branch, which may drop package versions that are not deemed fit to make it into a stable branch.  This means that pinning to a version on the edge branch may stop working after the package version is revoked from the repo.  Always pin to a package version that is intended for your current Alpine Linux version.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Commit hooks ==&lt;br /&gt;
&lt;br /&gt;
If you&#039;d like to trigger an action or run a certain script on every commit made by apk, there&#039;s a built-in method for that. On every commit apk looks for executables located in the &amp;quot;/etc/apk/commit_hooks.d/&amp;quot; directory, and executes them both before and after the commit. To provide some way to selectively run hooks either before or after a change is commited by apk, the scripts are called with &amp;quot;pre-commit&amp;quot; or &amp;quot;post-commit&amp;quot; as argument 1.&lt;br /&gt;
This is an example of a hook to do different things before and after commit:&lt;br /&gt;
&lt;br /&gt;
{{cmd|1=#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;pre-commit&amp;quot; ]; then&lt;br /&gt;
    do_something&lt;br /&gt;
&lt;br /&gt;
elif [ &amp;quot;$1&amp;quot; = &amp;quot;post-commit&amp;quot; ]; then&lt;br /&gt;
    do_something_else&lt;br /&gt;
fi}}&lt;br /&gt;
&lt;br /&gt;
Commit hooks are $PATH-aware, so for the sake of security it&#039;s recommended to specify absolute paths to executables.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Table of comparison with other Linux/Unix-like OSes for packages =&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! OS !! File Format !! Tools&lt;br /&gt;
|-&lt;br /&gt;
| Alpine || .apk || apk&lt;br /&gt;
|-&lt;br /&gt;
| Debian || .deb || apt, aptitude, dpkg&lt;br /&gt;
|-&lt;br /&gt;
| Gentoo || .tbz2 || emerge&lt;br /&gt;
|-&lt;br /&gt;
| FreeBSD || .txz || pkg&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Troubleshooting =&lt;br /&gt;
&lt;br /&gt;
== &amp;quot;apk-tools is old&amp;quot; == &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;apk update&#039;&#039;&#039;, &#039;&#039;&#039;apk upgrade&#039;&#039;&#039; or &#039;&#039;&#039;apk add&#039;&#039;&#039; may report the following: &lt;br /&gt;
 WARNING: This apk-tools is OLD! Some packages might not function properly&lt;br /&gt;
&lt;br /&gt;
This may happen if you are running Alpine Linux stable version with a certain edge/main, edge/community or testing package(s) also installed.  One resolution is to consider upgrading {{pkg|apk-tools}}.  If edge is already [https://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management#Repository_pinning tagged] in your repositories, then try:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add --upgrade apk-tools@edge}}&lt;br /&gt;
&lt;br /&gt;
== ERROR:  UNTRUSTED signature ==&lt;br /&gt;
&lt;br /&gt;
This happens when the release version changes. You need to update the local apk keys.&lt;br /&gt;
&lt;br /&gt;
If you have already updated your repositories, allow them to update without the trusted key:&lt;br /&gt;
{{Cmd|apk update --allow-untrusted}}&lt;br /&gt;
&lt;br /&gt;
Then install the keys upgrade:&lt;br /&gt;
{{Cmd|apk fix --upgrade --allow-untrusted alpine-keys}}&lt;br /&gt;
&lt;br /&gt;
Now updates and upgrades should proceed normally.&lt;br /&gt;
&lt;br /&gt;
Alternative, the updated alpine-keys package may be obtained, verified, installed directly, as covered earlier, prior to a repository update.&lt;br /&gt;
&lt;br /&gt;
= External Links =&lt;br /&gt;
* [https://www.cyberciti.biz/faq/10-alpine-linux-apk-command-examples/ 10 Alpine Linux apk Command Examples]  Vivek Gite 2019&lt;br /&gt;
&lt;br /&gt;
[[Category:Package Manager]]&lt;/div&gt;</summary>
		<author><name>Papiris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Talk:Governance&amp;diff=26124</id>
		<title>Talk:Governance</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Talk:Governance&amp;diff=26124"/>
		<updated>2024-01-04T10:43:39Z</updated>

		<summary type="html">&lt;p&gt;Papiris: question: is governance information still valid?&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page was last edited four years ago, and currently has no pages linking to it.&lt;br /&gt;
&lt;br /&gt;
Is the information still valid?&lt;br /&gt;
If so, maybe we should make it more easily reached.&lt;br /&gt;
&lt;br /&gt;
If not, maybe we should revise it and then make it more easily reached.&lt;/div&gt;</summary>
		<author><name>Papiris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Papiris&amp;diff=25821</id>
		<title>User:Papiris</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Papiris&amp;diff=25821"/>
		<updated>2023-11-26T16:09:59Z</updated>

		<summary type="html">&lt;p&gt;Papiris: Add user papiris&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://hackaday.io/papiris Maintainer and developer of Free software, -hardware and -culture projects ]&lt;/div&gt;</summary>
		<author><name>Papiris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_Linux:Glossary&amp;diff=25818</id>
		<title>Alpine Linux:Glossary</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_Linux:Glossary&amp;diff=25818"/>
		<updated>2023-11-23T16:50:53Z</updated>

		<summary type="html">&lt;p&gt;Papiris: Add entry for &amp;quot;community&amp;quot; repo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{TOC right}}&lt;br /&gt;
The Glossary is an extensive list of terms and Alpine Linux features with definitions and considerable explanations. A great place for reference and general browsing.&lt;br /&gt;
&lt;br /&gt;
== A ==&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{{Define |Topic |Description}}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Define|abuild|The tool to build packages from sources using APKBUILD is [[Abuild and Helpers|abuild]].&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Define|ACF|&#039;&#039;&#039;A&#039;&#039;&#039;lpine Linux &#039;&#039;&#039;C&#039;&#039;&#039;onfiguration &#039;&#039;&#039;F&#039;&#039;&#039;ramework is an [[Glossary#MVC |mvc-style]] application for configuring an Alpine Linux device. The primary focus is for a web interface - ACF&#039;s main goal is to be a light-weight MVC &amp;quot;[https://en.wikipedia.org/wiki/Webmin webmin]&amp;quot;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Define|apk|&#039;&#039;&#039;A&#039;&#039;&#039;lpine Linux &#039;&#039;&#039;P&#039;&#039;&#039;ackage &#039;&#039;&#039;K&#039;&#039;&#039;eeper - A) The [[:category:Package Manager |package manager]] for Alpine, used to install, query and remove software packages on a running Alpine system. Also the suffix of the binary packages, even if those basically are gzipped tar files.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Define|APKBUILD|A build recipe that is used to build Alpine packages for &#039;&#039;apk&#039;&#039;. It holds information of package name, version, license, dependencies, sources etc and how to compile the sources and package the binaries.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Define |apkovl |[[Alpine local backup#Committing_your_changes  |&#039;&#039;&#039;A&#039;&#039;&#039;pkovl]] is a file storing configuration files that have changed from the default ones.  It is used when running from ram.  The contents are overlaid on top of the contents of the apks that are loaded on boot.  The filename is &amp;lt;hostname&amp;gt;.apkovl.tar.gz and is stored on removable media whose path is defined in /etc/lbu/lbu.conf.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== B ==&lt;br /&gt;
{{Define|Busybox| [https://www.busybox.net/ Busybox] is a utility that combines many common Linux tools into a single program.  Most of the command-line tools in the core Alpine distribution are part of Busybox.&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{{Define|BSD| Berkeley Software Distribution (BSD) is a Unix operating system derivative developed and distributed from 1977 to 1995 by members of the University of California, Berkeley.&lt;br /&gt;
}}--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Define|bash| [https://www.gnu.org/software/bash/ bash] is a command-line interpreter or &amp;quot;shell&amp;quot; that provides a command line user interface.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
{{Define|cgit|[https://git.zx2c4.com/cgit/ cgit] provides easy access to all [https://git.alpinelinux.org/ git repositories] hosted on the Alpine infrastructure.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Define|community|The so-called [https://nl.alpinelinux.org/alpine/edge/community/ &amp;lt;tt&amp;gt;community&amp;lt;/tt&amp;gt;] repository contains software. Packages in community are considered stable, but aren&#039;t considered as vital as those in the main repository.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== D ==&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== E ==&lt;br /&gt;
{{Define|edge|[[Repositories#Edge|edge]] is the name of the development tree of Alpine Linux.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== F ==&lt;br /&gt;
{{Define |Flatpak |[[Flatpak]] is a technology for distributing [[:category: desktop |desktop]] applications on GNU/Linux. &lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== G ==&lt;br /&gt;
{{Define|git|The distributed version control system that Alpine uses. ([[:category: Git]])}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== H ==&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== I ==&lt;br /&gt;
{{Define|IRC| Internet Relay Chat (IRC) is a protocol for  Internet text messaging in real-time. Alpine-specific details can be found [[IRC| here]].}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== J ==&lt;br /&gt;
== K ==&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== L ==&lt;br /&gt;
{{Define|lbu|[[Alpine local backup |Local Backup Utility]]. A tool to make backups of user configuration. Since the system typically runs from RAM, &#039;&#039;&#039;lbu&#039;&#039;&#039; is used to save the state of the system to a file that is restored to bring the system back to its previous state.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Define|LEAF|Linux Embedded Appliance Framework. Alpine Linux started as a fork of the LEAF project. A secure, feature-rich, customizable embedded Linux network appliance for use in a variety of network topologies. Although it can be used in other ways; it&#039;s primarily used as a Internet gateway, router, firewall, and wireless access point.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== M ==&lt;br /&gt;
{{Define|main|The so-called [https://nl.alpinelinux.org/alpine/v3.10/main/ &amp;lt;tt&amp;gt;main&amp;lt;/tt&amp;gt;] repository contains software. Those packages are mature.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Define|MVC|The [https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller MVC] design pattern is used in ACF to separate presentation information from control logic. By MVC we mean:&lt;br /&gt;
:*&#039;&#039;&#039;M&#039;&#039;&#039;odel - code that reads / writes a config file, starts / stops daemons, or does other work modifying the router.&lt;br /&gt;
:*&#039;&#039;&#039;V&#039;&#039;&#039;iew - code that formats data for output&lt;br /&gt;
:*&#039;&#039;&#039;C&#039;&#039;&#039;ontroller - code that glues the two together&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Define|mkinitfs|Tool to generate the [https://en.wikipedia.org/wiki/Initial_ramdisk initramfs image] for the kernel.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Define|modloop|Loopback [https://en.wikipedia.org/wiki/Cramfs cramfs] image where kernel modules are stored for tmpfs installs.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{define |musl |[https://www.etalabs.net/compare_libcs.html musl] is a C standard library implementation for GNU/Linux. Musl libc is not [https://en.wikipedia.org/wiki/Application_binary_interface ABI] compatible with [[Running_glibc_programs | uClibc]].&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== N ==&lt;br /&gt;
{{Define|NTP|Network Time Protocol ([https://en.wikipedia.org/wiki/Network_Time_Protocol NTP]) is a protocol for synchronizing the clocks of computer systems. Alpine provides &amp;lt;tt&amp;gt;[[Alpine setup scripts#setup-ntp|setup-ntp]]&amp;lt;/tt&amp;gt; for setting up.&amp;lt;/br&amp;gt;&#039;&#039;([http://lists.busybox.net/pipermail/busybox/2014-September/081668.html What&#039;s the easiest way to make Busybox keep correct time?] 2014)&#039;&#039;}}{{insecure url|Server presents invalid certificate}}&lt;br /&gt;
&lt;br /&gt;
== O ==&lt;br /&gt;
{{Define|OpenRC|[https://wiki.gentoo.org/wiki/Project:OpenRC OpenRC] is a dependency based universal init system that works with the system provided [[Writing Init Scripts | init program]].&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== P ==&lt;br /&gt;
== Q ==&lt;br /&gt;
== R ==&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== S ==&lt;br /&gt;
{{Define|setup-*|Alpine contains a lot of scripts to configure a system. All those scripts start with &amp;lt;tt&amp;gt;setup-*&amp;lt;/tt&amp;gt;. The most important one is &amp;lt;tt&amp;gt;[[Setup-alpine|setup-alpine]]&amp;lt;/tt&amp;gt;.&amp;lt;/br&amp;gt;(&amp;lt;tt&amp;gt;find / -name setup* -print &amp;amp;#124; sort&amp;lt;/tt&amp;gt;)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== T ==&lt;br /&gt;
{{Define|testing|The so-called &amp;lt;tt&amp;gt;testing&amp;lt;/tt&amp;gt; repository contains software packages which are new/untested/experimental.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Define|tmpfs|[https://en.wikipedia.org/wiki/Tmpfs tmpfs] is a filesystem that exists in (virtual) memory only, like a [https://en.wikipedia.org/wiki/RAM_drive RAM disk].}}&lt;br /&gt;
&lt;br /&gt;
== U ==&lt;br /&gt;
{{Define|uClibc| [https://en.wikipedia.org/wiki/UClibc uClibc] (aka µClibc/pronounced yew-see-lib-see) is a C library for developing embedded Linux systems. It is much smaller than the [https://www.gnu.org/software/libc/libc.html GNU C Library], but nearly all applications supported by glibc also work perfectly with uClibc.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== V ==&lt;br /&gt;
{{Define|vServer|[https://en.wikipedia.org/wiki/Linux-VServer Linux-VServer] provides virtualization for GNU/Linux systems by kernel level isolation. This way it&#039;s possible to run multiple virtual units at once.}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== W ==&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== X ==&lt;br /&gt;
{{Define|Xfce| [https://www.xfce.org/ Xfce] is a lightweight [[:category: desktop |desktop environment]] that is available in the Alpine Linux repositories. &lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Y ==&lt;br /&gt;
{{Define |Topic |Description}}&lt;br /&gt;
&lt;br /&gt;
== Z ==&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[category: Newbie]]&lt;/div&gt;</summary>
		<author><name>Papiris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_Package_Keeper&amp;diff=25646</id>
		<title>Alpine Package Keeper</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_Package_Keeper&amp;diff=25646"/>
		<updated>2023-11-12T20:29:11Z</updated>

		<summary type="html">&lt;p&gt;Papiris: /* Advanced APK Usage */ : Add paragraph about apk commit hooks&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--For searching: apk, APK--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{TOC right}}&lt;br /&gt;
&lt;br /&gt;
Because Alpine Linux is designed to run from RAM, package management involves two phases:&lt;br /&gt;
* Installing / Upgrading / Deleting packages on a running system.&lt;br /&gt;
* Restoring a system to a previously configured state (e.g. after reboot), including all previously installed packages and locally modified configuration files. &#039;&#039;&#039;(RAM-Based Installs Only)&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;apk&#039;&#039;&#039; is the tool used to install, upgrade, or delete software on a running system.&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;lbu&#039;&#039;&#039; is the tool used to capture the data necessary to restore a system to a previously configured state.&lt;br /&gt;
&lt;br /&gt;
This page documents the [https://git.alpinelinux.org/apk-tools/ apk tool] - See the [[Alpine_local_backup|Alpine Local Backup page]] for the lbu tool.&lt;br /&gt;
&lt;br /&gt;
= Overview =&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;apk&#039;&#039;&#039; tool supports the following operations:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
| [[#Add a Package|add]] &lt;br /&gt;
| Add new packages or upgrade packages to the running system&lt;br /&gt;
|-&lt;br /&gt;
| [[#Remove a Package|del]]&lt;br /&gt;
| Delete packages from the running system&lt;br /&gt;
|-&lt;br /&gt;
| fix &lt;br /&gt;
| Attempt to repair or upgrade an installed package &lt;br /&gt;
|-&lt;br /&gt;
| [[#Update the Package list|update]] &lt;br /&gt;
| Update the index of available packages&lt;br /&gt;
|-&lt;br /&gt;
| [[#Information on Packages|info]]&lt;br /&gt;
| Prints information about installed or available packages&lt;br /&gt;
|-&lt;br /&gt;
| [[#Search for Packages|search]] &lt;br /&gt;
| Search for packages or descriptions with wildcard patterns&lt;br /&gt;
|-&lt;br /&gt;
| [[#Upgrade a Running System|upgrade]]&lt;br /&gt;
| Upgrade the currently installed packages&lt;br /&gt;
|-&lt;br /&gt;
| [[#Cache maintenance|cache]]&lt;br /&gt;
| Maintenance operations for locally cached package repository&lt;br /&gt;
|-&lt;br /&gt;
| version &lt;br /&gt;
| Compare version differences between installed and available packages&lt;br /&gt;
|-&lt;br /&gt;
| index &lt;br /&gt;
| create a repository index from a list of packages&lt;br /&gt;
|-&lt;br /&gt;
| fetch &lt;br /&gt;
| download (but not install) packages&lt;br /&gt;
|-&lt;br /&gt;
| audit &lt;br /&gt;
| List changes to the file system from pristine package install state&lt;br /&gt;
|-&lt;br /&gt;
| verify &lt;br /&gt;
| Verify a package signature&lt;br /&gt;
|- &lt;br /&gt;
| dot&lt;br /&gt;
| Create a [https://graphviz.org/ graphviz] graph description for a given package&lt;br /&gt;
|- &lt;br /&gt;
| [[#apk_policy|policy]]&lt;br /&gt;
| Display the repository that updates a given package, plus repositories that also offer the package&lt;br /&gt;
|- &lt;br /&gt;
| stats &lt;br /&gt;
| Display statistics, including number of packages installed and available, number of directories and files, etc.&lt;br /&gt;
|- &lt;br /&gt;
| manifest&lt;br /&gt;
| Display checksums for files contained in a given package&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Packages and Repositories =&lt;br /&gt;
&lt;br /&gt;
Software packages for Alpine Linux are digitally signed tar.gz archives containing programs, configuration files, and dependency metadata. They have the extension &amp;lt;code&amp;gt;.apk&amp;lt;/code&amp;gt;, and are often called &amp;quot;a-packs&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The packages are stored in one or more &#039;&#039;repositories&#039;&#039;. A repository is simply a directory with a collection of *.apk files.  The directory must include a special index file, named {{Path|APKINDEX.tar.gz}} to be considered a repository.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;apk&#039;&#039;&#039; utility can install packages from multiple repositories.  The list of repositories to check is stored in {{Path|/etc/apk/repositories}}, one repository per line. If you booted from a USB stick ({{Path|/media/sda1}}) or CD-ROM ({{Path|/media/cdrom}}), your repository file probably looks something like this:&lt;br /&gt;
&lt;br /&gt;
{{Cat|/etc/apk/repositories|/media/sda1/apks/}}&lt;br /&gt;
&lt;br /&gt;
In addition to local repositories, the &#039;&#039;&#039;apk&#039;&#039;&#039; utility uses &#039;&#039;&#039;busybox wget&#039;&#039;&#039; to fetch packages using &#039;&#039;http:&#039;&#039;, &#039;&#039;https:&#039;&#039;, &#039;&#039;ftp:&#039;&#039; or &#039;&#039;rsync:&#039;&#039; protocols. The following is a valid repository file:&lt;br /&gt;
&lt;br /&gt;
{{Cat|/etc/apk/repositories|&lt;br /&gt;
/media/sda1/apks&lt;br /&gt;
http://dl-3.alpinelinux.org/alpine/v2.6/main&lt;br /&gt;
https://dl-3.alpinelinux.org/alpine/v2.6/main&lt;br /&gt;
ftp://dl-3.alpinelinux.org/alpine/v2.6/main&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Note|  A list of public repositories is in [https://mirrors.alpinelinux.org/ mirrors.alpinelinux.org].  Accepted protocols vary.}}&lt;br /&gt;
&lt;br /&gt;
== Repository pinning ==&lt;br /&gt;
&lt;br /&gt;
You can specify additional &amp;quot;tagged&amp;quot; repositories in {{Path|/etc/apk/repositories}}:&lt;br /&gt;
&lt;br /&gt;
{{Cat|/etc/apk/repositories|&lt;br /&gt;
https://dl-cdn.alpinelinux.org/alpine/v3.18/main&lt;br /&gt;
https://dl-cdn.alpinelinux.org/alpine/v3.18/community&lt;br /&gt;
@personal https:/personal-repo.example.com/alpine-apks/&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
After which you can &amp;quot;pin&amp;quot; dependencies to these tags using:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add application@personal}}&lt;br /&gt;
&lt;br /&gt;
apk will by default only use the untagged repositories, but adding a package with a @tag:&lt;br /&gt;
&lt;br /&gt;
1. will prefer the repository with that tag for the named package, even if a later version of the package is available in another repository&lt;br /&gt;
&lt;br /&gt;
2. &#039;&#039;allows&#039;&#039; pulling in dependencies for the tagged package from the tagged repository (though it &#039;&#039;prefers&#039;&#039; to use untagged repositories to satisfy dependencies if possible)&lt;br /&gt;
&lt;br /&gt;
== Commandline repository options ==&lt;br /&gt;
&lt;br /&gt;
By default, the &#039;&#039;&#039;apk&#039;&#039;&#039; utility will use the system repositories for all operations. This behavior can be overridden by the following options:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
| --repositories-file REPOFILE&lt;br /&gt;
| Override the system repositories by specifying a repositories file.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;nowiki&amp;gt;-X|--repository REPO&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| Specify a supplemental repository that will be used in addition to the system repositories. This option can be provided multiple times.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Update the Package list =&lt;br /&gt;
&lt;br /&gt;
Remote repositories change as packages are added and upgraded.   To get the latest list of available packages, use the &#039;&#039;update&#039;&#039; command.  The command downloads the {{Path|APKINDEX.tar.gz}} from each repository and stores it in the local cache, typically {{Path|/var/cache/apk/}}, {{Path|/var/lib/apk/}} or {{Path|/etc/apk/cache/}}.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk update}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
fetch https://dl-3.alpinelinux.org/alpine/v2.1/main/APKINDEX.tar.gz&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adding the &amp;lt;code&amp;gt;--update-cache&amp;lt;/code&amp;gt;, or for short &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; switch to another apk command, as in &amp;lt;code&amp;gt;apk --update-cache upgrade&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;apk -U add ...&amp;lt;/code&amp;gt;, the command has the same effect as first running &amp;lt;code&amp;gt;apk update&amp;lt;/code&amp;gt; before the other apk command.&lt;br /&gt;
&lt;br /&gt;
{{Tip|With remote repositories, it is a good idea to always do an &#039;&#039;&#039;update&#039;&#039;&#039; right &#039;&#039;&#039;before&#039;&#039;&#039; doing an &#039;&#039;&#039;upgrade or add&#039;&#039;&#039; command. That way the command will install the latest available packages.}}&lt;br /&gt;
&lt;br /&gt;
= Add a Package =&lt;br /&gt;
&lt;br /&gt;
Use &#039;&#039;&#039;add&#039;&#039;&#039; to install packages from a repository. Any necessary dependencies are also installed. If you have multiple repositories, the &#039;&#039;&#039;add&#039;&#039;&#039; command installs the newest package.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add openssh&lt;br /&gt;
apk add openssh openntp vim}}&lt;br /&gt;
&lt;br /&gt;
If you only have the main repository enabled in your configuration, apk will not include packages from the other repositories. To install a package from the edge/testing repository without changing your repository configuration file, use the command below. This will tell apk to use that particular repository.&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add cherokee --update-cache --repository https://dl-cdn.alpinelinux.org/alpine/edge/testing/ --allow-untrusted}}&lt;br /&gt;
&lt;br /&gt;
{{Note|Be careful when using third-party or the testing repository. Your system can go down.}}&lt;br /&gt;
&lt;br /&gt;
= Add a local Package =&lt;br /&gt;
&lt;br /&gt;
To install a locally available apk package, for example if this device has no internet access but you can upload apk packages directly to it, use the &#039;&#039;&#039;--allow-untrusted&#039;&#039;&#039; flag:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add --allow-untrusted /path/to/file.apk}}&lt;br /&gt;
&lt;br /&gt;
Note that multiple packages can be given.  When installing a local package, all dependencies should also be specified.  For example:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add --allow-untrusted /var/tig-2.2-r0.apk /var/git-2.11.1-20.apk}}&lt;br /&gt;
&lt;br /&gt;
= Remove a Package  =&lt;br /&gt;
Use &#039;&#039;&#039;del&#039;&#039;&#039; to remove a package (and dependencies that are no longer needed.)  &lt;br /&gt;
&lt;br /&gt;
{{cmd|apk del openssh&lt;br /&gt;
apk del openssh openntp vim}}&lt;br /&gt;
&lt;br /&gt;
= Upgrade a Running System =&lt;br /&gt;
&lt;br /&gt;
=== Packages in general ===&lt;br /&gt;
&lt;br /&gt;
To get the latest security upgrades and bugfixes available for the &#039;&#039;installed&#039;&#039; packages of a running system, first &#039;&#039;&#039;update&#039;&#039;&#039; the list of available packages and then &#039;&#039;&#039;upgrade&#039;&#039;&#039; the installed packages:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk update&lt;br /&gt;
apk upgrade&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Or, combining the same into one single command:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk -U upgrade&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Here is an example, showing the procedure on a system that has several additional [[#Repository_pinning|repositories pinned]]:&lt;br /&gt;
&lt;br /&gt;
 # apk update&lt;br /&gt;
 fetch &amp;lt;nowiki&amp;gt;https://dl-3.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 fetch &amp;lt;nowiki&amp;gt;https://dl-3.alpinelinux.org/alpine/v3.6/community/x86_64/APKINDEX.tar.gz&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 fetch &amp;lt;nowiki&amp;gt;https://dl-3.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 fetch &amp;lt;nowiki&amp;gt;https://dl-3.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 fetch &amp;lt;nowiki&amp;gt;https://dl-3.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 v3.6.2-191-gf98d79930f &amp;lt;nowiki&amp;gt;[https://dl-3.alpinelinux.org/alpine/v3.6/main]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 v3.6.2-190-ga5d68c47df &amp;lt;nowiki&amp;gt;[https://dl-3.alpinelinux.org/alpine/v3.6/community]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 v3.6.0-4618-g0bf77c9821 &amp;lt;nowiki&amp;gt;[https://dl-3.alpinelinux.org/alpine/edge/main]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 v3.6.0-4605-g85ed51dd83 &amp;lt;nowiki&amp;gt;[https://dl-3.alpinelinux.org/alpine/edge/community]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 v3.6.0-4624-g11f1b9c8ab &amp;lt;nowiki&amp;gt;[https://dl-3.alpinelinux.org/alpine/edge/testing]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 OK: 20118 distinct packages available&lt;br /&gt;
 &lt;br /&gt;
 # apk upgrade&lt;br /&gt;
 (1/2) Upgrading extra-cmake-modules@testing (5.38.0-r0 -&amp;gt; 5.39.0-r0)&lt;br /&gt;
 (2/2) Upgrading extra-cmake-modules-doc@testing (5.38.0-r0 -&amp;gt; 5.39.0-r0)&lt;br /&gt;
 Executing mdocml-apropos-1.14.1-r0.trigger&lt;br /&gt;
 OK: 2635 MiB in 803 packages&lt;br /&gt;
&lt;br /&gt;
To upgrade only &#039;&#039;specific&#039;&#039; packages, use the &#039;&#039;&#039;upgrade&#039;&#039;&#039; command and specify them:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk update&lt;br /&gt;
apk upgrade busybox&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To enable unattended, automatic upgrades of packages, see the {{pkg|apk-autoupdate}} package.&lt;br /&gt;
&lt;br /&gt;
To upgrade to a newer release, refer to the corresponding release notes and [[Upgrading_Alpine]].&lt;br /&gt;
&lt;br /&gt;
=== Upgrading &amp;quot;diskless&amp;quot; and &amp;quot;data&amp;quot; disk mode installs ===&lt;br /&gt;
&lt;br /&gt;
If booting a &amp;quot;diskless&amp;quot; system from a read-only device, or iso image on writable media, it&#039;s not possible to update the boot files (kernel, modules, firmware, ...) that reside on that device.&lt;br /&gt;
&lt;br /&gt;
It becomes possible to update the boot files, though, if using a boot device that is writable and has been prepared with &amp;lt;code&amp;gt;[[Alpine_setup_scripts#setup-bootable|setup-bootable]]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
However, even then, the kernel, with its modules and firmware files, can still not be updated directly through regular packages updates. Instead, there is the &amp;lt;code&amp;gt;update-kernel&amp;lt;/code&amp;gt; script that can generate initfs images and install them together with upgraded kernels.&lt;br /&gt;
&lt;br /&gt;
Upgrading can be done as follows.&lt;br /&gt;
{{cmd|apk add mkinitfs&lt;br /&gt;
}}&lt;br /&gt;
This package is required for the generation of the initial filesystem used during boot.&lt;br /&gt;
* Additional initfs features that are missing in the default configuration, like the [[Btrfs|btrfs]] filesystem support (at the time of writing, to allow loading .apkovl configs and package cache during boot), may be enabled in &amp;lt;code&amp;gt;/etc/mkinitfs/mkinitfs.conf&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Available initfs features may be listed with &amp;lt;code&amp;gt;ls /etc/mkinitfs/features.d&amp;lt;/code&amp;gt;&lt;br /&gt;
{{cmd|ls /etc/mkinitfs/features.d&lt;br /&gt;
apk add nano&lt;br /&gt;
nano /etc/mkinitfs/mkinitfs.conf&lt;br /&gt;
lbu commit&lt;br /&gt;
}}&lt;br /&gt;
Finally update the kernel and its boot environment.&lt;br /&gt;
{{cmd|update-kernel /media/sdXY/boot/&lt;br /&gt;
}}&lt;br /&gt;
* An &amp;lt;code&amp;gt;update-kernel&amp;lt;/code&amp;gt; run needs at least 8 GB free ram memory to avoid a broken modloop-image.&lt;br /&gt;
* See &amp;lt;code&amp;gt;update-kernel --help&amp;lt;/code&amp;gt; for options to manually add additional module or firmware packages.&lt;br /&gt;
&lt;br /&gt;
= Search for Packages =&lt;br /&gt;
The &#039;&#039;&#039;search&#039;&#039;&#039; command searches the repository Index files for installable packages. &lt;br /&gt;
&lt;br /&gt;
The return format is &#039;&#039;&#039;Package&#039;&#039;&#039;-&#039;&#039;&#039;Version&#039;&#039;&#039;. Omit &#039;&#039;&#039;Version&#039;&#039;&#039; for &#039;&#039;apk add &#039;&#039;&#039;Package&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
* To list all packages available, along with their descriptions: {{cmd|apk search -v}}&lt;br /&gt;
* To list all packages are part of the ACF system: {{cmd|apk search -v &#039;acf*&#039; }}&lt;br /&gt;
* To list all packages that list NTP as part of their description, use the &#039;&#039;-d&#039;&#039; or &#039;&#039;--description&#039;&#039; option: {{cmd|apk search -v --description &#039;NTP&#039; }}&lt;br /&gt;
&lt;br /&gt;
= Information on Packages =&lt;br /&gt;
&lt;br /&gt;
== apk info ==&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;info&#039;&#039;&#039; command provides information on the contents of packages, their dependencies, and which files belong to a package.&lt;br /&gt;
&lt;br /&gt;
For a given package, each element can be chosen (for example, &#039;&#039;-w&#039;&#039; to show just the webpage information), or all information displayed with the &#039;&#039;-a&#039;&#039; command.&lt;br /&gt;
&lt;br /&gt;
Example: {{cmd|apk info -a zlib}}&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 description:&#039;&#039;&#039;&lt;br /&gt;
 A compression/decompression Library&lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 webpage:&#039;&#039;&#039;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;https://zlib.net&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 installed size:&#039;&#039;&#039;&lt;br /&gt;
 94208&lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 depends on:&#039;&#039;&#039;&lt;br /&gt;
 libc0.9.32&lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 is required by:&#039;&#039;&#039;&lt;br /&gt;
 libcrypto1.0-1.0.0-r0&lt;br /&gt;
 apk-tools-2.0.2-r4&lt;br /&gt;
 openssh-client-5.4_p1-r2&lt;br /&gt;
 openssh-5.4_p1-r2&lt;br /&gt;
 libssl1.0-1.0.0-r0&lt;br /&gt;
 freeswitch-1.0.6-r6&lt;br /&gt;
 atop-1.25-r0 &lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 contains:&#039;&#039;&#039;&lt;br /&gt;
 lib/libz.so.1.2.5&lt;br /&gt;
 lib/libz.so.1&lt;br /&gt;
 lib/libz.so &lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 triggers:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As shown in the example you can determine&lt;br /&gt;
* The &#039;&#039;&#039;description&#039;&#039;&#039; of the package (&#039;&#039;-d&#039;&#039; or &#039;&#039;--description&#039;&#039;)&lt;br /&gt;
* The &#039;&#039;&#039;webpage&#039;&#039;&#039; where the application is hosted (&#039;&#039;-w&#039;&#039; or &#039;&#039;--webpage&#039;&#039;)&lt;br /&gt;
* The &#039;&#039;&#039;size&#039;&#039;&#039; the package will require once installed (in bytes) (&#039;&#039;-s&#039;&#039; or &#039;&#039;--size&#039;&#039;)&lt;br /&gt;
* What packages are required to use this one  (&#039;&#039;&#039;depends&#039;&#039;&#039;) (&#039;&#039;-R&#039;&#039; or &#039;&#039;--depends&#039;&#039;)&lt;br /&gt;
* What packages require this one to be installed (&#039;&#039;&#039;required by&#039;&#039;&#039;) (&#039;&#039;-r&#039;&#039; or &#039;&#039;--rdepends&#039;&#039;)&lt;br /&gt;
* The &#039;&#039;&#039;contents&#039;&#039;&#039; of the package, that is, which files it installs (&#039;&#039;-L&#039;&#039; or &#039;&#039;--contents&#039;&#039;)&lt;br /&gt;
* Any &#039;&#039;&#039;triggers&#039;&#039;&#039; this package sets. (&#039;&#039;-t&#039;&#039; or &#039;&#039;--triggers&#039;&#039;) Listed here are directories that are watched; if a change happens to the directory, then the trigger script is run at the end of the apk add/delete. For example, doing a depmod once after installing all packages that add kernel modules.&lt;br /&gt;
&lt;br /&gt;
{{Tip|The &#039;&#039;&#039;info&#039;&#039;&#039; command is also useful to determine which package a file belongs to.  For example: {{cmd|apk info --who-owns /sbin/lbu}} will display&lt;br /&gt;
&lt;br /&gt;
 /sbin/lbu is owned by alpine-conf-x.x-rx&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Listing installed packages ===&lt;br /&gt;
&lt;br /&gt;
To list all installed packages, use:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk info}}&lt;br /&gt;
&lt;br /&gt;
To list all installed packages in alphabetical order, with a description of each, do:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk -vv info|sort}}&lt;br /&gt;
&lt;br /&gt;
The apk tool does not have a subcommand to list manually-installed packages that do not have reverse dependencies. To get this information on a traditional system that is not using [[Alpine local backup|lbu]], try this script. Note that this approach will also list core packages like alpine-base that should not be removed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/sh&lt;br /&gt;
apk info | grep -ve &#039;-doc$&#039; | sort | while read pkg&lt;br /&gt;
        do&lt;br /&gt;
                rdep=`apk info -qr &amp;quot;$pkg&amp;quot;`&lt;br /&gt;
                [ -z &amp;quot;$rdep&amp;quot; ] &amp;amp;&amp;amp; echo $pkg&lt;br /&gt;
        done&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== apk policy ==&lt;br /&gt;
&lt;br /&gt;
To display the repository a package was installed from and will be updated from, plus any [[#Repository_pinning|tagged]] or enabled repositories where it is also offered, if any, for this architecture - its &#039;&#039;&#039;policy&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk policy &#039;&#039;package&#039;&#039;}}&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 $ apk policy vlc&lt;br /&gt;
 vlc policy:&lt;br /&gt;
  2.2.6-r1:&lt;br /&gt;
    lib/apk/db/installed&lt;br /&gt;
    https://dl-3.alpinelinux.org/alpine/v3.7/community&lt;br /&gt;
  3.0.0_rc2-r1:&lt;br /&gt;
    @edgecommunity https://dl-3.alpinelinux.org/alpine/edge/community&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Additional apk Commands =&lt;br /&gt;
In progress...&lt;br /&gt;
&lt;br /&gt;
= Local Cache =&lt;br /&gt;
&lt;br /&gt;
{{:Local_APK_cache}}&lt;br /&gt;
&lt;br /&gt;
= Advanced APK Usage =&lt;br /&gt;
&lt;br /&gt;
== Holding a specific package back ==&lt;br /&gt;
&lt;br /&gt;
In certain cases, you may want to upgrade a system, but keep a specific package at a back level. It is possible to add &amp;quot;sticky&amp;quot; or versioned dependencies. For instance, to hold the &#039;&#039;asterisk&#039;&#039; package to the 1.6.2 level or lower:&lt;br /&gt;
{{cmd|1=apk add asterisk=1.6.0.21-r0}}&lt;br /&gt;
or&lt;br /&gt;
{{cmd|apk add &#039;asterisk&amp;lt;1.6.1&#039;}}&lt;br /&gt;
&lt;br /&gt;
after which a {{cmd|apk upgrade}}&lt;br /&gt;
&lt;br /&gt;
will upgrade the entire system, keeping the asterisk package at the 1.6.0 or lower level&lt;br /&gt;
&lt;br /&gt;
To later upgrade to the current version,&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add &#039;asterisk&amp;gt;1.6.1&#039;}}&lt;br /&gt;
&lt;br /&gt;
will ensure that 1.6.1 is the minimum version used.&lt;br /&gt;
&lt;br /&gt;
You can also use &amp;quot;fuzzy&amp;quot; version matching to pin the version to a major/minor release.  For example:&lt;br /&gt;
&lt;br /&gt;
{{cmd|1=apk add &#039;asterisk=~1.6&#039;}}&lt;br /&gt;
&lt;br /&gt;
will match any version of asterisk that starts with 1.6 (such as 1.6.0.21-r0 or 1.6.9.31-r9)  &amp;lt;ref&amp;gt;[https://git.alpinelinux.org/apk-tools/commit/?id=693b4bcdb0f22904a521a7c8ac4f13e697dc4d71 Alpine source commit message]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you desire deterministic, repeatable package installation (such as with containerized environments) via package pinning, it is important to understand your package repo&#039;s version retention rules.  For example, most Alpine package repos contain an &amp;quot;edge&amp;quot; branch, which may drop package versions that are not deemed fit to make it into a stable branch.  This means that pinning to a version on the edge branch may stop working after the package version is revoked from the repo.  Always pin to a package version that is intended for your current Alpine Linux version.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Commit hooks ==&lt;br /&gt;
&lt;br /&gt;
If you&#039;d like to trigger an action or run a certain script on every commit made by apk, there&#039;s a built-in method for that. On every commit apk looks for executables located in the &amp;quot;/etc/apk/commit_hooks.d/&amp;quot; directory, and executes them both before and after the commit. To provide some way to selectively run hooks either before or after a change is commited by apk, the scripts are called with &amp;quot;pre-commit&amp;quot; or &amp;quot;post-commit&amp;quot; as argument 1.&lt;br /&gt;
This is an example of a hook to do different things before and after commit:&lt;br /&gt;
&lt;br /&gt;
{{cmd|1=#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;pre-commit&amp;quot; ]; then&lt;br /&gt;
    do_something&lt;br /&gt;
&lt;br /&gt;
elif [ &amp;quot;$1&amp;quot; = &amp;quot;post-commit&amp;quot; ]; then&lt;br /&gt;
    do_something_else&lt;br /&gt;
fi}}&lt;br /&gt;
&lt;br /&gt;
If you have a script or piece of software that accepts &amp;quot;pre-commit&amp;quot; and &amp;quot;post-commit&amp;quot; arguments directly, you can save a bit of space by softlinking it into the hooks directory rather than using a helper script.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Table of comparison with other Linux/Unix-like OSes for packages =&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! OS !! File Format !! Tools&lt;br /&gt;
|-&lt;br /&gt;
| Alpine || .apk || apk&lt;br /&gt;
|-&lt;br /&gt;
| Debian || .deb || apt, aptitude, dpkg&lt;br /&gt;
|-&lt;br /&gt;
| Gentoo || .tbz2 || emerge&lt;br /&gt;
|-&lt;br /&gt;
| FreeBSD || .txz || pkg&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Troubleshooting =&lt;br /&gt;
&lt;br /&gt;
== &amp;quot;apk-tools is old&amp;quot; == &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;apk update&#039;&#039;&#039;, &#039;&#039;&#039;apk upgrade&#039;&#039;&#039; or &#039;&#039;&#039;apk add&#039;&#039;&#039; may report the following: &lt;br /&gt;
 WARNING: This apk-tools is OLD! Some packages might not function properly&lt;br /&gt;
&lt;br /&gt;
This may happen if you are running Alpine Linux stable version with a certain edge/main, edge/community or testing package(s) also installed.  One resolution is to consider upgrading {{pkg|apk-tools}}.  If edge is already [https://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management#Repository_pinning tagged] in your repositories, then try:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add --upgrade apk-tools@edge}}&lt;br /&gt;
&lt;br /&gt;
== ERROR:  UNTRUSTED signature ==&lt;br /&gt;
&lt;br /&gt;
This happens when the release version changes. You need to update the local apk keys.&lt;br /&gt;
&lt;br /&gt;
If you have already updated your repositories, allow them to update without the trusted key:&lt;br /&gt;
{{Cmd|apk update --allow-untrusted}}&lt;br /&gt;
&lt;br /&gt;
Then install the keys upgrade:&lt;br /&gt;
{{Cmd|apk fix --upgrade --allow-untrusted alpine-keys}}&lt;br /&gt;
&lt;br /&gt;
Now updates and upgrades should proceed normally.&lt;br /&gt;
&lt;br /&gt;
Alternative, the updated alpine-keys package may be obtained, verified, installed directly, as covered earlier, prior to a repository update.&lt;br /&gt;
&lt;br /&gt;
= External Links =&lt;br /&gt;
* [https://www.cyberciti.biz/faq/10-alpine-linux-apk-command-examples/ 10 Alpine Linux apk Command Examples]  Vivek Gite 2019&lt;br /&gt;
&lt;br /&gt;
[[Category:Package Manager]]&lt;/div&gt;</summary>
		<author><name>Papiris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Creating_an_Alpine_package&amp;diff=25479</id>
		<title>Creating an Alpine package</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Creating_an_Alpine_package&amp;diff=25479"/>
		<updated>2023-11-08T22:37:14Z</updated>

		<summary type="html">&lt;p&gt;Papiris: Add reference to CODINGSTYLE.md and COMMITSTYLE.md in =code review= section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{TOC right}}&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
To build a package for Alpine Linux you need an Alpine Linux installation. Check the [[Installation]] page to see all available installation options.&lt;br /&gt;
&lt;br /&gt;
== Setup your system and account  ==&lt;br /&gt;
{{:Include:Setup_your_system_and_account_for_building_packages}}&lt;br /&gt;
&lt;br /&gt;
== Getting some help ==&lt;br /&gt;
&lt;br /&gt;
It might be wise to start by checking what the [[Abuild|abuild]] program can/cannot do.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|abuild -h}}&lt;br /&gt;
&lt;br /&gt;
For real help, you can also go on #alpine-devel on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
A reference for APKBUILD files is available as [[APKBUILD Reference]] wiki page or a man page in the &#039;abuild-doc&#039; package:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|man APKBUILD}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Creating an APKBUILD file  ==&lt;br /&gt;
&lt;br /&gt;
=== Use a template APKBUILD ===&lt;br /&gt;
&lt;br /&gt;
To create the actual APKBUILD file {{Pkg|newapkbuild}} can serve you a template to start with. It will create a directory with the given package name, place an example/template APKBUILD file to the given directory, and fill some variables if those are provided. Please check the [[Package_policies| package policies]] page about naming details.&lt;br /&gt;
&lt;br /&gt;
If you doubt to which repository your package belongs to you can safely use &#039;&#039;&#039;testing&#039;&#039;&#039;. Building package in your aports/testing directory is not mandatory but this way the package is already at the right place.&lt;br /&gt;
&lt;br /&gt;
{{:Include:Newapkbuild}}&lt;br /&gt;
&lt;br /&gt;
{{Note|On older Alpine systems, abuild -c -n &#039;&#039;packagename&#039;&#039; was the way to create APKBUILD files. The &#039;packagename&#039; was a parameter to the -n option so order of -c and -n matters. }}&lt;br /&gt;
&lt;br /&gt;
[[Abuild_and_Helpers#apkbuild-cpan|apkbuild-cpan]] simplifies the creation of perl packages from CPAN and [[Abuild_and_Helpers#apkbuild-pypi|apkbuild-pypi]] ease the generation of APKBUILD files for python packages from PyPi.  &lt;br /&gt;
&lt;br /&gt;
If you are creating a daemon package which needs initd scripts you can add the -c making it: &lt;br /&gt;
&lt;br /&gt;
{{Cmd|newapkbuild -c &#039;&#039;packagename&#039;&#039;}}&lt;br /&gt;
&lt;br /&gt;
This will copy the sample initd and confd files to the build directory.&amp;lt;BR&amp;gt;&lt;br /&gt;
A third file sample.install file will be copied as well (we will discuss this later on).&lt;br /&gt;
&lt;br /&gt;
=== Modify your APKBUILD ===&lt;br /&gt;
Edit APKBUILD and fill in the needed info (especially pkgname, pkgver, pkgdesc, url, license, depends and source). &lt;br /&gt;
&lt;br /&gt;
If you are going to use any of the variables for directories like $pkgdir, always make sure they are double quoted like: &lt;br /&gt;
&lt;br /&gt;
 &amp;quot;$pkgdir&amp;quot;/somedir&lt;br /&gt;
&lt;br /&gt;
This will prevent issues with spaces/special characters in the future. &lt;br /&gt;
&lt;br /&gt;
{{Note|If you like syntax highlighting we suggest you to install vim. We have setup vim to recognize the APKBUILD file as a bash scripts so its easier to read them.}}&lt;br /&gt;
&lt;br /&gt;
=== APKBUILD variables/functions  ===&lt;br /&gt;
&lt;br /&gt;
==== source  ====&lt;br /&gt;
&lt;br /&gt;
The source variable is not only used to list the remote source files to fetch, it is also used to list the local files that abuild will need in order to build the apk. Examples of such local files include: init.d files, conf.d files, install files (see [[Creating an Alpine package#install|install variable]]), patches, and all other necessary files.&lt;br /&gt;
&lt;br /&gt;
Here are few things to note:&lt;br /&gt;
&lt;br /&gt;
* When you are finished adding local and/or remote files to &#039;&#039;source&#039;&#039;, you can execute the following command to add their checksums to the APKBUILD file:&lt;br /&gt;
: {{cmd|abuild checksum}}&lt;br /&gt;
: {{Note|When later updating the content of &#039;&#039;source&#039;&#039;, or updating a file that is listed in &#039;&#039;source&#039;&#039;, you must also update their checksums again with the same command.}}&lt;br /&gt;
&lt;br /&gt;
* When the remote file is hosted at SourceForge, it&#039;s best to specify the special mirrors link used by SourceForge:&lt;br /&gt;
: &amp;lt;pre&amp;gt;http://downloads.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
: (or similar depending on the package).&lt;br /&gt;
&lt;br /&gt;
* When the remote filename is not specified in the URI (ie, does not end in &#039;/software-1.0.tar.gz&#039;), such as:&lt;br /&gt;
: &amp;lt;pre&amp;gt;http://oss.example.org/?get=software&amp;amp;ver=1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
: You must prepend &#039;${pkgname}-${pkgver}.tar.gz::&#039; to the protocol, like so:&lt;br /&gt;
: &amp;lt;pre&amp;gt;source=&amp;quot;${pkgname}-${pkgver}.tar.gz::http://oss.example.org/?get=software&amp;amp;ver=1.0&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
: This causes the file to be saved as &#039;&#039;software-1.0.tar.gz&#039;&#039; where abuild can use it, instead of &#039;&#039;?get=software&amp;amp;ver=1.0&#039;&#039;, where abuild cannot use it.&lt;br /&gt;
&lt;br /&gt;
* Some projects didn&#039;t provide a release tarball. Beware that some git services (gitweg, cgit, …?) doesn’t provide &#039;&#039;stable&#039;&#039; tarballs, so when you point source to an tarball like &amp;lt;tt&amp;gt;https://repo.or.cz/w/gitstats.git/snapshot/ad7efbb9399e60cee6cb217c6b47e604174a8093.tar.gz&amp;lt;/tt&amp;gt;, then you will run into issues because the checksum changes when downloading on the build system. This is not a problem on GitHub, GitLab and other decent services provides, they provide &#039;&#039;stable&#039;&#039; tarballs.&lt;br /&gt;
&lt;br /&gt;
* abuild currently supports the following protocols for remote file retrieval:&lt;br /&gt;
** http&lt;br /&gt;
** https&lt;br /&gt;
** ftp&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--: {{Note|If the you want to download from https, you need GNU wget installed on your system.}}--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
* abuild currently supports the following archive types/archive file extensions:&lt;br /&gt;
** .tar&lt;br /&gt;
** .tar.gz / .tgz&lt;br /&gt;
** .tar.bz2&lt;br /&gt;
** .tar.lz (only in Alpine &amp;gt;=3.7)&lt;br /&gt;
** .tar.lzma&lt;br /&gt;
** .tar.xz&lt;br /&gt;
** .zip&lt;br /&gt;
&lt;br /&gt;
==== depends &amp;amp;amp; makedepends  ====&lt;br /&gt;
&lt;br /&gt;
Depends are the actual running dependencies that a package would need when it is running. Makedepends are only needed when you are building a package. If you set a package in depends, you do not need to add it to makedepends as well. The best way to find out what the depends and makedepends of a package are is to [https://en.wikipedia.org/wiki/Rtfm RTFM]. &lt;br /&gt;
&lt;br /&gt;
No kidding, lots of important information can be found in the package INSTALL and README files (or the likes). Another good way is the run &amp;lt;code&amp;gt;./configure --help&amp;lt;/code&amp;gt; from the source directory to see which options are needed for configure to finish without errors. If you do not yet have a source directory you can create one with the command: &lt;br /&gt;
&lt;br /&gt;
{{Cmd|abuild unpack}}&lt;br /&gt;
&lt;br /&gt;
Running &amp;lt;code&amp;gt;configure&amp;lt;/code&amp;gt; will also show you how you can disable a specific option for this package. For instance, a good example is &amp;quot;--disable-nls&amp;quot; which will disable native language support and thus does not depend on gettext (libiconv, glib, ...). &lt;br /&gt;
&lt;br /&gt;
Alpine likes to keep things small, so we try to disable as much as possible without losing too many features. The exact disable/enable options are decided by the package builder but please try to follow Alpine&#039;s design concept as much as possible.&lt;br /&gt;
&lt;br /&gt;
An easy way of quickly finding out the build info for a package is to check Arch Linux (Alpine package management and build scripts are similar) or Gentoo Linux ebuilds (previous versions of Alpine were based on Gentoo).&lt;br /&gt;
&lt;br /&gt;
* [https://gitweb.gentoo.org/repo/gentoo.git/tree/ Gentoo Ebuilds] &lt;br /&gt;
* [https://archlinux.org/packages/?q=search Arch Linux packages] [https://aur.archlinux.org/ Arch Linux User Repository]&lt;br /&gt;
&lt;br /&gt;
==== license  ====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;license&#039;&#039;&#039; tag must reflect the license of the source code. Please check the source tarball for COPYING, LICENSE, or other files with names that indicates that it contains licensing information. Beside the license file most developer include headers in the source code files with licensing details.&lt;br /&gt;
&lt;br /&gt;
If the license is on the [https://spdx.org/licenses/ SPDX License List] or [https://spdx.org/licenses/exceptions-index.html SPDX License Exceptions], use the identifier specified by SPDX.&lt;br /&gt;
&lt;br /&gt;
If a package has a special/custom license or is not listed as [https://opensource.org/licenses/alphabetical OSI approved], use the identifier &amp;quot;custom&amp;quot;. We additionally need to provide the license file with the release. Because we want to save space and don&#039;t like to have licenses all over our system we have decided to include the license in the doc subpackage. Please follow the following guidelines to add a proper license. Locate the license file inside the source package. Add the doc subpackage to the $subpackages variable as follows: &lt;br /&gt;
&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-doc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Add a similar line to the following to your package() function, depending on the license description file: &lt;br /&gt;
&lt;br /&gt;
{{Cmd|install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING}}&lt;br /&gt;
&lt;br /&gt;
If you follow these steps then abuild will automatically add the license to the package-doc apk for you.&lt;br /&gt;
&lt;br /&gt;
{{Warning|It is not acceptable to package software with &amp;quot;unknown&amp;quot; license! If you can&#039;t find the license of the source code, please contact the author and ask them to specify the license. }}&lt;br /&gt;
&lt;br /&gt;
==== arch ====&lt;br /&gt;
&lt;br /&gt;
The package architecture(s) to build for.  This can be one of: &#039;&#039;x86, x86_64, all,&#039;&#039; or &#039;&#039;noarch&#039;&#039;, where &#039;&#039;all&#039;&#039; means all architectures, and &#039;&#039;noarch&#039;&#039; means it&#039;s architecture-independent (e.g., a pure-python package).&lt;br /&gt;
{{Tip|To determine if your APKBUILD can use &#039;&#039;noarch&#039;&#039;, build the package for your architecture and then run &amp;quot;scanelf -R pkg&amp;quot; from the directory that the APKBUILD resides in, in order to scan for ELF files in the &#039;&#039;./pkg&#039;&#039; directory.  If you do NOT get output from this, then &#039;&#039;noarch&#039;&#039; can be used.}}&lt;br /&gt;
&lt;br /&gt;
==== url  ====&lt;br /&gt;
&lt;br /&gt;
Website address for the program. This is useful later on when either finding documentation or other information about the package.&lt;br /&gt;
&lt;br /&gt;
==== pkgdesc  ====&lt;br /&gt;
&lt;br /&gt;
A brief, one line, description of what the package does. Useful for the package management system. It should start with a capital letter and does &#039;&#039;&#039;not&#039;&#039;&#039; end with a period.&lt;br /&gt;
&lt;br /&gt;
Here is an example from apk_info for the OpenSSH client package:&lt;br /&gt;
&lt;br /&gt;
 pkgdesc=&amp;quot;Port of OpenBSD&#039;s free SSH release - client&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== pkgver  ====&lt;br /&gt;
&lt;br /&gt;
Provide the release number of the package you are building.&lt;br /&gt;
&lt;br /&gt;
==== pkgrel  ====&lt;br /&gt;
&lt;br /&gt;
The $pkgrel versioning is made so that if you change something in your APKBUILD file without changing the actual $pkgver, you can increment pkgrel so apk tools will detect it as an update. For instance, if you forget to add a dependency, you can add it afterward and you can +1 pkgver so apk finds this update and adds the missing dependency. When there&#039;s an upstream version change, we reset the pkgrel to 0.&lt;br /&gt;
&lt;br /&gt;
==== pkgname  ====&lt;br /&gt;
&lt;br /&gt;
The base name of the package you are creating.  For Freeswitch 1.0.6, you would use &amp;quot;freeswitch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== install  ====&lt;br /&gt;
&lt;br /&gt;
There are 6 different kinds of install scripts. Each script is called with the $pkgname.&#039;&#039;&amp;lt;action&amp;gt;&#039;&#039; where &#039;&#039;&amp;lt;action&amp;gt;&#039;&#039; is one of the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt;$pkgname.pre-install&lt;br /&gt;
&amp;lt;dd&amp;gt;This script is executed before package is installed. Typical use is when package needs a group and a user to be created. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
addgroup -S clamav 2&amp;gt;/dev/null&lt;br /&gt;
adduser -S -D -H -s /bin/false -G clamav -g clamav clamav 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Note the &#039;&#039;exit 0&#039;&#039; at the end. If the script exits with failure (if the user already exist), the package will not be installed and &amp;lt;code&amp;gt;apk add&amp;lt;/code&amp;gt; will exit with failure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;dt&amp;gt;$pkgname.post-install&lt;br /&gt;
&amp;lt;dd&amp;gt;This script is executed after the package is installed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;dt&amp;gt;$pkgname.pre-upgrade&lt;br /&gt;
&amp;lt;dd&amp;gt;Same as pre-install but is executed before upgrading/downgrading/reinstalling an already installed package. Note that exiting with failure will not cause apk to exit with failure, but will mark the package as broken.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;dt&amp;gt;$pkgname.post-upgrade&lt;br /&gt;
&amp;lt;dd&amp;gt;Same as post-install but is executed after upgrading/downgrading/reinstalling an already installed package. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;dt&amp;gt;$pkgname.pre-deinstall&lt;br /&gt;
&amp;lt;dd&amp;gt;This script is executed before uninstalling a package. If script exits with failure apk will not uninstall the package.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;dt&amp;gt;$pkgname.post-deinstall&lt;br /&gt;
&amp;lt;dd&amp;gt;This script is executed after a package have been uninstalled. For example, can be used to restore busybox links:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
busybox --install -s&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the package has a pre-install and post-install script the APKBUILD should have the &#039;&#039;install&#039;&#039; variable defined:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
install=&amp;quot;$pkgname.pre-install $pkgname.post-install&amp;quot;&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== subpackages  ====&lt;br /&gt;
&lt;br /&gt;
$subpackages are made to split up the normal &amp;quot;make install&amp;quot; into separate packages. The most common subpackages we use are doc and dev. Because we like to keep our target system small we move documentation and development files (only needed when building packages) into separate packages. To use the specific program a user only need to install the base apk without package-doc or package-dev, but if he wants to read the manual he will need to install package-doc. &lt;br /&gt;
&lt;br /&gt;
The easiest way to find out if you need to use -dev and -doc is to first build the package without these options set and wait until the build finishes. When its finished you should have a pkg directory which is the fake root directory. Inside this directory you will see the structure as how it would be installed in / on the target system. &lt;br /&gt;
&lt;br /&gt;
To see if you need the -dev package you can run the following cmd: &lt;br /&gt;
&lt;br /&gt;
{{Cmd|find pkg/usr/ -name &#039;*.[acho]&#039; -o -name &#039;*.la&#039;}}&lt;br /&gt;
&lt;br /&gt;
If this returns any files you need to include the -dev package. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; To see if you need the -doc package you can run the following cmd: &lt;br /&gt;
&lt;br /&gt;
{{Cmd|find pkg/usr/share -name doc -o -name man -o -name info -o -name html -o -name sgml -o -name licenses}}&lt;br /&gt;
&lt;br /&gt;
If this returns any directories you need to include the -doc package. &lt;br /&gt;
&lt;br /&gt;
===== Custom subpackages  =====&lt;br /&gt;
&lt;br /&gt;
Some software additionally has non-essential files that do not qualify as either documentation or development content. These files should be placed in their own, specialized subpackage(s). Some packages include large test suites which are only needed in specific circumstances or binaries which have depends which we prefer not to install. To handle those we create our own package/function. In the APKBUILD below the build() function we create another function: &lt;br /&gt;
&lt;br /&gt;
 test() {&lt;br /&gt;
        mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
        mv &amp;quot;$pkgdir&amp;quot;/usr/package-test &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
        # or amove usr/package-test&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
We also need to add the package info to $subpackages variable: &lt;br /&gt;
&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-doc $pkgname-dev $pkgname-test&amp;quot;&lt;br /&gt;
&lt;br /&gt;
After we finish building the package you should see another apk called packagename-test.apk which includes the files which we moved to the $subpkgdir dir. &lt;br /&gt;
&lt;br /&gt;
The above mentioned variables can also be used in our custom function. If we want for instance to build the test() function with perl support we would add: &lt;br /&gt;
&lt;br /&gt;
 depends=&amp;quot;perl&amp;quot;&lt;br /&gt;
 makedepends=&amp;quot;perl-dev&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If we would install the base package it would not install perl, but if we install the package-test package it would.&lt;br /&gt;
&lt;br /&gt;
==== Patches  ====&lt;br /&gt;
&lt;br /&gt;
Please make sure you always submit human readable patches. Ways to create them are: &lt;br /&gt;
&lt;br /&gt;
directory compare: &lt;br /&gt;
&lt;br /&gt;
{{Cmd|diff -Nurp original_directory new_directory &amp;amp;gt; filename.patch}}&lt;br /&gt;
&lt;br /&gt;
file compare: &lt;br /&gt;
&lt;br /&gt;
{{Cmd|diff -up original.file new.file &amp;amp;gt; filename.patch}}&lt;br /&gt;
&lt;br /&gt;
If a patch contains a completely new file but not *.rej or *.orig file, you need to add -N option to diff, but you may need to add exclusions with &amp;lt;code&amp;gt;--exclude PATTERN&amp;lt;/code&amp;gt; so that you do not inadvertently add files.  You may need to manually delete unwanted files inside the patch file.&lt;br /&gt;
&lt;br /&gt;
Because multiple patches can patch the same file, they can change the offsets required by subsequent patches. To make sure we always patch in a specific way, we should number the patches as follows: &lt;br /&gt;
&lt;br /&gt;
 10-patch1.patch 20-patch2.patch 30-patch3.patch&lt;br /&gt;
&lt;br /&gt;
This way we are always sure that patch 1 is applied first, and if we want to add additional patches between them we can use appropriate indexes (e.g. 11, 12, 21, 22).&lt;br /&gt;
&lt;br /&gt;
Add the names of the patch files to the &#039;&#039;source&#039;&#039; variable. If you haven&#039;t declared a custom &#039;&#039;prepare&#039;&#039; function, no further action is necessary. Otherwise, be sure to call &#039;&#039;default_prepare&#039;&#039; in your &#039;&#039;prepare&#039;&#039; function. For example:&lt;br /&gt;
&lt;br /&gt;
 prepare() {&lt;br /&gt;
 	default_prepare&lt;br /&gt;
 &lt;br /&gt;
 	# do your stuff&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Note: Some older packages contain a &#039;&#039;for&#039;&#039; loop in the &#039;&#039;prepare&#039;&#039; function to apply patches. This is not needed anymore, as patches are handled by &#039;&#039;default_prepare&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In Alpine &amp;gt;=3.4 you can define patch_args to supply the patch level.  This only works if all the patches have the same patch level.  If there are a lot of patches from different sources, there is a good chance that you may need to edit them, as discussed below.&lt;br /&gt;
&lt;br /&gt;
To automatically patch the package (available only in Alpine &amp;gt;=3.4) if it uses a patch level (-pX) other than the default (-p1), you need to carefully modify the patch.  First, you&#039;ll need a text editor that does not automatically convert  between Windows and Unix new lines (or, disable this feature) so that it preserves the old code.  The next thing you&#039;ll need to do is modify the paths on &amp;quot;+++&amp;quot; and &amp;quot;---&amp;quot; lines in the .patch file.  You can begin the path with a/ and b/ like shown below.  Next, you need to adjust the paths so that the relative base path is from inside $builddir.  Anything to the left of $builddir, including $builddir itself, needs to be removed from the path.  So, if $builddir is /home/USER/aports/community/chromium/src/chromium-65, you need to erase it on the &amp;quot;+++&amp;quot; and &amp;quot;---&amp;quot; lines.  Inside the chromium-65 folder you can see a src folder that has 3rdparty as a descendant.  If a patch originally has a deeper patch level, you may need to fill in the missing portion of the path.  For example, use the &amp;lt;code&amp;gt;find . -name &amp;quot;Assertions.cpp&amp;quot;&amp;lt;/code&amp;gt; command to find the full path to the file relative to the base.&lt;br /&gt;
&lt;br /&gt;
{{Cat|example.patch|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
Author: John Doe &amp;lt;johndoe@mail.com&amp;gt;&lt;br /&gt;
URL: http://.....&lt;br /&gt;
Summary: Fixes musl compatibility&lt;br /&gt;
----&lt;br /&gt;
--- a/src/3rdparty/chromium/third_party/WebKit/Source/wtf/Assertions.cpp.orig&lt;br /&gt;
+++ b/src/3rdparty/chromium/third_party/WebKit/Source/wtf/Assertions.cpp&lt;br /&gt;
@@ -142,7 +142,7 @@&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 FrameToNameScope::FrameToNameScope(void* addr) : m_name(0), m_cxaDemangled(0) {&lt;br /&gt;
-#if OS(MACOSX) || (OS(LINUX) &amp;amp;&amp;amp; !defined(__UCLIBC__))&lt;br /&gt;
+#if OS(MACOSX) || (OS(LINUX) &amp;amp;&amp;amp; defined(__GLIBC__))&lt;br /&gt;
   Dl_info info;&lt;br /&gt;
   if (!dladdr(addr, &amp;amp;info) || !info.dli_sname)&lt;br /&gt;
return;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Portions of the patch may be outdated, removed completely as in the source code file completely removed, or moved or renamed files.  You need to delete that section of the patch or find where that section of code changed and re-diff it.&lt;br /&gt;
&lt;br /&gt;
It is good etiquette to give credit at the top and the location of where you originally found them with notes.&lt;br /&gt;
&lt;br /&gt;
Excluding patches with global variable resembling patch_opts is not available on Alpine.  To exclude patches you need to create your own custom prepare().&lt;br /&gt;
&lt;br /&gt;
If you have a monolithic patch where there are a bunch of patches in one big patch, you could use filterdiff which is available in the patchutils package.&lt;br /&gt;
&lt;br /&gt;
Just do something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
makedepends=&amp;quot;patchutils&amp;quot;&lt;br /&gt;
&lt;br /&gt;
prepare() {&lt;br /&gt;
  ...&lt;br /&gt;
  cd &amp;quot;$builddir&amp;quot;&lt;br /&gt;
  filterdiff -x &#039;*drivers/video/logo*&#039; &amp;quot;$srcdir&amp;quot;/original.patch &amp;gt; &amp;quot;$builddir&amp;quot;/modified.patch&lt;br /&gt;
  patch -p1 -i &amp;quot;$builddir&amp;quot;/modified.patch&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to put the wildcard pattern in single quotes for it to work.&lt;br /&gt;
&lt;br /&gt;
==== Configure options  ====&lt;br /&gt;
&lt;br /&gt;
Alpine has some default configure options we set by default. We use /usr for prefix to make sure everything is installed with /usr in front of it. If you notice that anything is installed in the wrong directory please run {{Cmd|./configure --help}} and see if you can set the correct location. &lt;br /&gt;
&lt;br /&gt;
We are not covering the depend switches here we have discussed this already in the depend section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Make options  ====&lt;br /&gt;
&lt;br /&gt;
If you notice weird problems when compiling or installing the package with make/make install you could try to disable [https://www.gnu.org/software/make/manual/make.html#Parallel parallel] building/installing. A normal make line would be: &lt;br /&gt;
&lt;br /&gt;
{{Cmd|make}}&lt;br /&gt;
&lt;br /&gt;
To disable parallel we use: &lt;br /&gt;
&lt;br /&gt;
{{Cmd|make -j1}}&lt;br /&gt;
&lt;br /&gt;
We can use the same for make install. &lt;br /&gt;
&lt;br /&gt;
Because we do not want to install the package in our build environment but we want to install it in a fake root directory we need to tell &#039;make install&#039; to use another destination directory instead of &#039;/&#039;. We do this by setting a variable when we execute make install as followed: &lt;br /&gt;
&lt;br /&gt;
{{Cmd|make DESTDIR{{=}}&amp;quot;$pkgdir&amp;quot; install}}&lt;br /&gt;
&lt;br /&gt;
Please note that some Makefiles do not support this variable and will always install software in &#039;/&#039;. To make sure you do not mess up your build system NEVER run your build system as root but always use a custom user and doas when needed. If by accident the Makefile does not support DESTDIR variable it will fail to install in our build system system directories.&lt;br /&gt;
&lt;br /&gt;
==== builddir ====&lt;br /&gt;
If you used &amp;lt;tt&amp;gt;newapkbuild&amp;lt;/tt&amp;gt; to create your APKBUILD file, you must specify the path to your unpacked sources. Inside the sections during the prepare/build/install process &#039;&#039;builddir&#039;&#039; is used. Most of the time a combination of &#039;&#039;$srcdir&#039;&#039; and &#039;&#039;$pkgname-$pkgver&#039;&#039; will work. When not, check the /src directory or the source tarball for the right string. Especially when you are working with automatically generated tarballs (like from github and gitorious), this needs to be adjusted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Additional files  ====&lt;br /&gt;
&lt;br /&gt;
If you want/need to install additional files not mentioned above you can use the following cmd (this is an example of a conf file): &lt;br /&gt;
&lt;br /&gt;
{{Cmd|install -Dm644 doc/$pkgname.conf &amp;quot;$pkgdir&amp;quot;/etc/$pkgname.conf}}&lt;br /&gt;
&lt;br /&gt;
== Build the package  ==&lt;br /&gt;
&lt;br /&gt;
If you did not already create the checksums as mentioned above you can do so now: &lt;br /&gt;
&lt;br /&gt;
{{Cmd|cd $pkgname&lt;br /&gt;
abuild checksum}}&lt;br /&gt;
&lt;br /&gt;
It&#039;s about time we build our package. Because a build system should never have all the package installed to prevent linking to packages we don&#039;t want it to link we use a abuild recursively with the &#039;&#039;&#039;-r&#039;&#039;&#039; switch. It will install all dependencies from your repository and builds it, afterwards it will uninstall all those depending packages again.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|abuild -r}}&lt;br /&gt;
&lt;br /&gt;
See also [[Abuild_and_Helpers|Abuild and Helpers]].&lt;br /&gt;
&lt;br /&gt;
== Testing the package locally ==&lt;br /&gt;
&lt;br /&gt;
When it completes, your package will be found in a subfolder of &amp;lt;code&amp;gt;~/packages&amp;lt;/code&amp;gt;.  You may want to test it on your machine but only if the package is not a critical system package like musl or apk-tools package.  To avoid borking your system (as in making it impossible to use &amp;lt;code&amp;gt;apk add&amp;lt;/code&amp;gt; or to restore back the system and the compiler toolchain) for a critical system package, you should test on a chroot first before using it live.&lt;br /&gt;
&lt;br /&gt;
The best way to test a package locally is to modify your &amp;lt;code&amp;gt;/etc/apk/repositories&amp;lt;/code&amp;gt; so that it includes the indexes to your locally built packages - the directories that contain &amp;lt;code&amp;gt;ARCH/APKINDEX.tar.gz&amp;lt;/code&amp;gt;. For example the &amp;lt;code&amp;gt;/etc/apk/repositories&amp;lt;/code&amp;gt; below includes locally built packages in testing, community and main. To use this example change &amp;lt;code&amp;gt;USER&amp;lt;/code&amp;gt; to your login name.&lt;br /&gt;
&lt;br /&gt;
{{Cat|/etc/apk/repositories|/home/USER/packages/testing/&lt;br /&gt;
/home/USER/packages/main/&lt;br /&gt;
/home/USER/packages/community/&lt;br /&gt;
https://dl-cdn.alpinelinux.org/alpine/edge/main&lt;br /&gt;
https://dl-cdn.alpinelinux.org/alpine/edge/community&lt;br /&gt;
https://dl-cdn.alpinelinux.org/alpine/edge/testing&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
If you prefer to test a package without changing any other configuration you can use the &amp;lt;code&amp;gt;-X, --repository&amp;lt;/code&amp;gt; option to &amp;lt;code&amp;gt;apk&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|doas apk add --repository /home/USER/packages/testing $pkgname}}&lt;br /&gt;
&lt;br /&gt;
== Code review ==&lt;br /&gt;
&lt;br /&gt;
To successfully have your package pass through code reviewers (as of Feb 18, 2018 are nmeum and jirutka on GitHub) and possible increased acceptance, the following conventions need to be followed:&lt;br /&gt;
&lt;br /&gt;
# Custom global variables should be prefixed with underscore (_).&lt;br /&gt;
# Compact code as in merged commands, removed unused variables, removal of functions that do the same thing that are automatically handled by abuild.&lt;br /&gt;
# Versioning is done properly.  For details see [[APKBUILD_Reference#pkgver]].&lt;br /&gt;
# Licensing is done properly. Remove unnecessary copying of licensing that is already OSI approved.&lt;br /&gt;
# Naming conventions rules for unofficial variables as in _gitrev is preferred over commit.&lt;br /&gt;
# Indent with tabs not spaces.&lt;br /&gt;
# Removal of explicit return 1.  (They are still found the old APKBUILD files if you are learning but are now strongly discouraged.)&lt;br /&gt;
# Disabling check() requires either (1) a comment (#) stating next to options=&amp;quot;!check&amp;quot; that there is no test suite/unit tests or (2) functioning working check() function.&lt;br /&gt;
# Explicit call to subpackages=&amp;quot;$pkgname-doc&amp;quot; must be used instead of explicit gzip man page compression.&lt;br /&gt;
# Ideally, lines should be no more than 80 columns wide&lt;br /&gt;
&lt;br /&gt;
Additionally, make sure to run the linter on your package:&lt;br /&gt;
{{Cmd|doas apk add atools&lt;br /&gt;
apkbuild-lint APKBUILD}}&lt;br /&gt;
&lt;br /&gt;
For more information see [[Development using git:Quality assurance]] and [[Package_policies]].&lt;br /&gt;
Also check out [https://gitlab.alpinelinux.org/alpine/aports/-/blob/master/COMMITSTYLE.md?ref_type=heads aports/COMMITSTYLE.md] and [https://gitlab.alpinelinux.org/alpine/aports/-/blob/master/CODINGSTYLE.md?ref_type=heads aports/CODINGSTYLE.md]&lt;br /&gt;
&lt;br /&gt;
== Commit your work  ==&lt;br /&gt;
&lt;br /&gt;
After you successfully build your package and properly followed the conventions and requirements in the code review section, you can submit your APKBUILD to Alpine&#039;s git repository. &lt;br /&gt;
&lt;br /&gt;
Update your git repo, before adding new files: &lt;br /&gt;
&lt;br /&gt;
{{Cmd|cd $aportsdir&lt;br /&gt;
git pull}}&lt;br /&gt;
&lt;br /&gt;
This should pull all the changes made by others into your local git repo.&lt;br /&gt;
&lt;br /&gt;
When you think you are ready you can add your files to git: &lt;br /&gt;
&lt;br /&gt;
NOTE: when using our Gitlab instance, you can create MR&#039;s for each package. Please squash all commits related to the same package into a single one per MR.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|cd $aportsdir&lt;br /&gt;
git add testing/$pkgdir (include any other files needed for the build; $pkgname.install...)&lt;br /&gt;
git commit}}&lt;br /&gt;
&lt;br /&gt;
Use the following commit message template for new aports (without the comments):&lt;br /&gt;
&lt;br /&gt;
{{Cat|template|testing/$pkgname: new aport   # this will be the subject line&lt;br /&gt;
                              # a blank line&lt;br /&gt;
$url                          # project homepage&lt;br /&gt;
$pkgdesc                      # one line description}}&lt;br /&gt;
&lt;br /&gt;
Or you could add the following and &amp;lt;code&amp;gt;chmod +x ports/.git/hooks/prepare-commit-msg&amp;lt;/code&amp;gt; to automatically generate commit message which the default aports/.githooks/ does not:&lt;br /&gt;
&lt;br /&gt;
{{Cat|aports/.git/hooks/prepare-commit-msg|&amp;lt;nowiki&amp;gt;#!/bin/sh&lt;br /&gt;
case &amp;quot;$2,$3&amp;quot; in&lt;br /&gt;
  ,|template,)&lt;br /&gt;
    if git diff-index --diff-filter=A --name-only --cached HEAD \&lt;br /&gt;
        | grep -q &#039;/APKBUILD$&#039;; then&lt;br /&gt;
      meta() { git diff --staged | grep &amp;quot;^+$1&amp;quot; | sed &#039;s/.*=&amp;quot;\?//;s/&amp;quot;$//&#039;;}&lt;br /&gt;
      printf &#039;testing/%s: new aport\n\n%s\n%s\n&#039; &amp;quot;$(meta pkgname)&amp;quot; \&lt;br /&gt;
        &amp;quot;$(meta url)&amp;quot; &amp;quot;$(meta pkgdesc)&amp;quot; &amp;quot;$(cat $1)&amp;quot; &amp;gt; &amp;quot;$1&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      printf &#039;%s\n\n%s&#039; `git diff-index --name-only --cached HEAD \&lt;br /&gt;
        | sed -n &#039;s/\/APKBUILD$//p;q&#039;` &amp;quot;$(cat $1)&amp;quot; &amp;gt; &amp;quot;$1&amp;quot;&lt;br /&gt;
    fi;;&lt;br /&gt;
esac&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Now your changes are only available locally in your repository.&lt;br /&gt;
&lt;br /&gt;
Because you do not have push rights to the Alpine aports repository you need to create a merge request to [https://gitlab.alpinelinux.org/alpine/aports Alpine&#039;s GitLab instance].&lt;br /&gt;
&lt;br /&gt;
Alternatively you can also create a diff (patch) of the changes you made and send this patch to the &lt;br /&gt;
[https://lists.alpinelinux.org/~alpine/aports  alpine-aports mailinglist].&lt;br /&gt;
&lt;br /&gt;
To create a diff patch:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|git format-patch HEAD^}}&lt;br /&gt;
&lt;br /&gt;
or if you have sprunge, you can create a link to your patch for convenience&lt;br /&gt;
&lt;br /&gt;
{{Cmd|git format-patch HEAD^ --stdout &amp;lt;nowiki&amp;gt;|&amp;lt;/nowiki&amp;gt; sprunge}}&lt;br /&gt;
&lt;br /&gt;
== Automated flagging of outdated ports ==&lt;br /&gt;
Consider adding your port to [https://release-monitoring.org/ Anitya], so it will be flagged as outdated&lt;br /&gt;
as soon as a new stable version is released by upstream.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[APKBUILD Reference]]&lt;br /&gt;
* [[APKBUILD examples]]&lt;br /&gt;
* [[Development using git]]&lt;br /&gt;
* [[Development using git:Quality assurance]]&lt;br /&gt;
&lt;br /&gt;
[[category: Package Manager]]&lt;/div&gt;</summary>
		<author><name>Papiris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=25478</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=25478"/>
		<updated>2023-11-08T22:31:40Z</updated>

		<summary type="html">&lt;p&gt;Papiris: fix formatting of maintainer snippet&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;APKBUILDs are the scripts that are created in order to build Alpine packages using the [[abuild]] tool.&lt;br /&gt;
&lt;br /&gt;
See [[aports]] for details on Alpine&#039;s official ports repository.&lt;br /&gt;
&lt;br /&gt;
This page is intended to serve as a reference for creating APKBUILDs; if this is your first time creating a package for Alpine Linux, please see [[Creating an Alpine package]].&lt;br /&gt;
&lt;br /&gt;
= Legend =&lt;br /&gt;
The following notes will assist you in understanding this document.&lt;br /&gt;
&lt;br /&gt;
In description text:&lt;br /&gt;
* If a variable is not prefixed with a &#039;&#039;$&#039;&#039;, it will be represented by italics (i.e., &#039;&#039;srcdir&#039;&#039; ).&lt;br /&gt;
* Functions will also be represented by italics, but will also end with a pair of parentheses (i.e., &#039;&#039;build()&#039;&#039; ).&lt;br /&gt;
* Shell commands will be represented &amp;lt;code&amp;gt;like this&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Variables =&lt;br /&gt;
{{Note|Variables that contain a path (e.g. &#039;&#039;$srcdir&#039;&#039; and &#039;&#039;$pkgdir&#039;&#039;) should always be quoted using double quotes (i.e., &#039;&#039;&amp;quot;$srcdir&amp;quot;&#039;&#039;).  This is done to prevent things from breaking, should the user have the APKBUILD in a directory path that contains spaces.}}&lt;br /&gt;
{{Note|All arbitrary variable and function names should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (for example, &#039;&#039;_luaversions&#039;&#039;).}}&lt;br /&gt;
&lt;br /&gt;
These variables are all well documented in &amp;lt;code&amp;gt;man 5 APKBUILD&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== abuild-defined variables ==&lt;br /&gt;
The following variables are defined by abuild:&lt;br /&gt;
&lt;br /&gt;
==== startdir ====&lt;br /&gt;
: The directory where the APKBUILD script is.&lt;br /&gt;
==== srcdir ====&lt;br /&gt;
: The directory where sources, from the &#039;&#039;source&#039;&#039; variable, are downloaded to and unpacked to.&lt;br /&gt;
==== pkgdir ====&lt;br /&gt;
: This directory should receive the files for the main package.  For example, a normal [https://en.wikipedia.org/wiki/GNU_Autotools autotools] package would have &amp;lt;code&amp;gt;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&amp;lt;/code&amp;gt; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
==== subpkgdir ====&lt;br /&gt;
: This directory should receive the files for a subpackage. This variable should only be used from subpackage functions.&lt;br /&gt;
==== builddir ====&lt;br /&gt;
: This variable should point to the directory inside the &#039;&#039;srcdir&#039;&#039; where the main package source is unpacked.  This is typically &#039;&#039;$srcdir/$pkgname-$pkgver&#039;&#039;.  It’s used by the default &#039;&#039;prepare()&#039;&#039; function as a working directory when applying patches.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
==== Maintainer ====&lt;br /&gt;
: Name and email address of the maintainer of the project (not your package).&lt;br /&gt;
: A well-formatted example is &amp;lt;code&amp;gt;# Maintainer: John Snow &amp;lt;john_snow@thewall.net&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== arch ====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one or several seperated by whitespace of: &#039;&#039;&#039;[[x86]], [[x86_64]], [[armv7]], [[armhf]], [[aarch64]], [[ppc64le]], [[s390x]], [[riscv64]], all&#039;&#039;&#039;, or &#039;&#039;&#039;noarch&#039;&#039;&#039;, where &#039;&#039;&#039;all&#039;&#039;&#039; means all architectures, and &#039;&#039;&#039;noarch&#039;&#039;&#039; means it&#039;s architecture-independent (e.g., a pure-python package). Architectures can be negated using the ! character to exclude them from the list of supported architectures. E.g. &#039;&#039;&#039;arch=&amp;quot;all !ppc64le&amp;quot;&#039;&#039;&#039; means that the package is allowed to be built on all architectures but the ppc64le architecture.&lt;br /&gt;
: {{Tip|To determine if your APKBUILD can use &#039;&#039;&#039;noarch&#039;&#039;&#039;: First specify &#039;&#039;&#039;all&#039;&#039;&#039; and then build the package by executing &amp;lt;code&amp;gt;abuild -r&amp;lt;/code&amp;gt;.  Watch the output towards the end for warnings saying that &#039;&#039;&#039;noarch&#039;&#039;&#039; can be used.  If the main package and all subpackages, if you have any subpackages, give a warning saying that &#039;&#039;&#039;noarch&#039;&#039;&#039; can be used, then you can use &#039;&#039;&#039;noarch&#039;&#039;&#039;.}}&lt;br /&gt;
&lt;br /&gt;
==== depends ====&lt;br /&gt;
: Run-time dependency package(s) that are not shared-object dependencies.  Shared objects dependencies are auto-detected and should not be specified here. To specify a conflicting package, add the package name prefixed with a &#039;!&#039;.&lt;br /&gt;
&lt;br /&gt;
==== depends_dev ====&lt;br /&gt;
: Run-time dependency package(s) for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; subpackage.&lt;br /&gt;
&lt;br /&gt;
: {{Note|From ncopa on IRC: To find out if you need to add a package to depends_dev have a look at *requires* in usr/lib/pkgconfig/*.pc. With libtool it gets more complicated, but we should delete the .la files. Also check if there are any  /usr/bin/*-configure #!/bin/bash #!/usr/bin/perl or Python. Sometimes scripts or similar are generated at build time (i.e autoconf automake) then you normally don&#039;t need add those to depends_dev. You can also just add all -dev makedepends to depends_dev but it will slow the build process a little bit (more build dependencies).}}&lt;br /&gt;
&lt;br /&gt;
==== depends_doc ====&lt;br /&gt;
: Run-time dependency package(s) for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; subpackage.&lt;br /&gt;
&lt;br /&gt;
==== depends_openrc ====&lt;br /&gt;
: Run-time dependency package(s) for the &#039;&#039;&#039;$pkgname-openrc&#039;&#039;&#039; subpackage.&lt;br /&gt;
&lt;br /&gt;
==== depends_libs ====&lt;br /&gt;
: Run-time dependency package(s) for the &#039;&#039;&#039;$pkgname-libs&#039;&#039;&#039; subpackage.&lt;br /&gt;
&lt;br /&gt;
==== depends_static ====&lt;br /&gt;
: Run-time dependency package(s) for the &#039;&#039;&#039;$pkgname-static&#039;&#039;&#039; subpackage.&lt;br /&gt;
&lt;br /&gt;
==== checkdepends ====&lt;br /&gt;
: Dependencies that are only required during the check phase, they are only installed if the check option is enabled&lt;br /&gt;
&lt;br /&gt;
==== giturl ====&lt;br /&gt;
:Git repository from which &amp;lt;code&amp;gt;abuild checkout&amp;lt;/code&amp;gt; checks out. You can checkout a specific branch in git by adding &amp;lt;code&amp;gt;-b $branch&amp;lt;/code&amp;gt;.&lt;br /&gt;
==== install ====&lt;br /&gt;
: There are 6 different types of install scripts.  Install scripts are named &#039;&#039;&#039;$pkgname.action&#039;&#039;&#039;, where &#039;&#039;&#039;action&#039;&#039;&#039; can be:  &#039;&#039;&#039;pre-install, post-install, pre-upgrade, post-upgrade, pre-deinstall&#039;&#039;&#039;, or &#039;&#039;&#039;post-deinstall&#039;&#039;&#039;.  For example, if &#039;&#039;pkgname&#039;&#039; is set to &#039;&#039;&#039;mypackage&#039;&#039;&#039; and &#039;&#039;install&#039;&#039; is set to &#039;&#039;&#039;$pkgname.post-install&#039;&#039;&#039;, then a script named &#039;&#039;&#039;mypackage.post-install&#039;&#039;&#039; must exist along-side the APKBUILD.&lt;br /&gt;
&amp;lt;blockquote&amp;gt;{{Note|Always use &amp;lt;code&amp;gt;/bin/sh&amp;lt;/code&amp;gt; for the command-line interpreter on the [https://en.wikipedia.org/wiki/Shebang_%28Unix%29 shebang line] of your install scripts.}}&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following are the different types of install scripts in detail:&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-install =====&lt;br /&gt;
: This script is executed &#039;&#039;before installing&#039;&#039; the package.  Typical use is when the package needs a group and a user to be created. For example:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
addgroup -S clamav 2&amp;gt;/dev/null&lt;br /&gt;
adduser -S -D -H -s /sbin/nologin -G clamav -g clamav clamav 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
{{Note|If the script exits with a failure (e.g., if the user already exists), the package will not be installed and &amp;lt;code&amp;gt;apk&amp;lt;/code&amp;gt; will exit with failure, hence the &amp;lt;code&amp;gt;exit 0&amp;lt;/code&amp;gt; at the end.}}&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-install =====&lt;br /&gt;
: This script is executed &#039;&#039;after installing&#039;&#039; the package.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;before upgrading/downgrading/reinstalling&#039;&#039; the package. Note that exiting with failure will not cause apk to exit with failure, but will mark the package as broken.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;after upgrading/downgrading/reinstalling&#039;&#039; the package.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-deinstall =====&lt;br /&gt;
: This script is executed &#039;&#039;before uninstalling&#039;&#039; the package.&lt;br /&gt;
: {{Note|If the script exits with failure, &amp;lt;code&amp;gt;apk&amp;lt;/code&amp;gt; will not uninstall the package.}}&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-deinstall =====&lt;br /&gt;
: This script is executed &#039;&#039;after uninstalling&#039;&#039; the package.&lt;br /&gt;
&lt;br /&gt;
==== install_if ====&lt;br /&gt;
:install_if can be used when a package needs to be installed when some packages are already installed or are in the dependency tree. It works in reverse to the &#039;&#039;recommends&#039;&#039; feature, that other package managers provide.&lt;br /&gt;
&lt;br /&gt;
: Typically this is used in a subpackage that should provide files which make sense with another package. For example:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
subpackages=&amp;quot;$pkgname-bash-completion:bashcomp:noarch&amp;quot;&lt;br /&gt;
...&lt;br /&gt;
bashcomp() {&lt;br /&gt;
	pkgdesc=&amp;quot;Bash completions for $pkgname&amp;quot;&lt;br /&gt;
	install_if=&amp;quot;$pkgname=$pkgver-r$pkgrel bash-completion&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	install -Dm644 &amp;quot;$builddir&amp;quot;/doc/bash_completion/aria2c \&lt;br /&gt;
		&amp;quot;$subpkgdir&amp;quot;/usr/share/bash-completion/completions/_aria2c&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From the aria2c APKBUILD. Note that the custom bashcomp() function is only necessary, because the files are not in /usr/share/bash-completion.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:In general, install_if should only be used with &#039;&#039;&#039;at least one versioned constraint&#039;&#039;&#039;. Otherwise, a package that was implicitly installed by install_if and then removed from the binary repositories, will not get purged with &amp;lt;code&amp;gt;apk upgrade&amp;lt;/code&amp;gt;. [https://gitlab.alpinelinux.org/alpine/apk-tools/-/issues/10720#note_121298]&lt;br /&gt;
&lt;br /&gt;
==== license ====&lt;br /&gt;
: License(s) for the package, for example &amp;lt;code&amp;gt;GPL-3.0-or-later&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;BSD-2-Clause&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;MIT&amp;lt;/code&amp;gt; [[Creating_an_Alpine_package#license|(details)]].&lt;br /&gt;
&lt;br /&gt;
==== makedepends ====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
==== md5sums/sha256sums/sha512sums ====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated and updated by executing &amp;lt;code&amp;gt;abuild checksum&amp;lt;/code&amp;gt; and should be the last item in the APKBUILD.&lt;br /&gt;
&lt;br /&gt;
New packages should use only sha512sums.&lt;br /&gt;
&lt;br /&gt;
==== options ====&lt;br /&gt;
: Build-time options for the package.&lt;br /&gt;
&lt;br /&gt;
: {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Option&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!archcheck&amp;lt;/code&amp;gt;&lt;br /&gt;
| Do not try to verify that the architecture of the binary files is the same architecture as abuild should build for. One example where it makes sense to set this are packages with firmware files, that get executed on another CPU (such as WiFi firmware).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!check&amp;lt;/code&amp;gt;&lt;br /&gt;
| Do not try to run the &amp;lt;code&amp;gt;check()&amp;lt;/code&amp;gt; function. Please always add a short comment after the &amp;lt;code&amp;gt;!check&amp;lt;/code&amp;gt; about why it&#039;s disabled. [https://github.com/alpinelinux/aports/pull/2322#discussion_r142545300] Creating a very simple check function, that calls &amp;lt;code&amp;gt;program --version&amp;lt;/code&amp;gt; is worse than disabling tests completely because it gives the false impression that the package is thoroughly tested with the testsuite from upstream. [https://github.com/alpinelinux/aports/pull/7326#discussion_r278797457]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;checkroot&amp;lt;/code&amp;gt;&lt;br /&gt;
| Specifies that the package&#039;s test suite will be run in &#039;&#039;fakeroot&#039;&#039;. This is necessary for some test suites which fail when run as non-root.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;net&amp;lt;/code&amp;gt;&lt;br /&gt;
| Allows network access when run in &#039;&#039;rootbld&#039;&#039;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!strip&amp;lt;/code&amp;gt;&lt;br /&gt;
| Avoid stripping symbols from binaries.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;suid&amp;lt;/code&amp;gt;&lt;br /&gt;
| Allow [https://en.wikipedia.org/wiki/Setuid setuid] binaries.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!tracedeps&amp;lt;/code&amp;gt;&lt;br /&gt;
| Do not automatically find dependencies (e.g. by using &amp;lt;code&amp;gt;ldd&amp;lt;/code&amp;gt; to find dynamic libraries, which the resulting binary links against).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;chmod-clean&amp;lt;/code&amp;gt;&lt;br /&gt;
| Make all files writable in the src/ directory. Useful for packages that make files read-only in the process of building packages (go modules).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;toolchain&amp;lt;/code&amp;gt;&lt;br /&gt;
| Don&#039;t warn when g++ is in makedepends&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!dbg&amp;lt;/code&amp;gt;&lt;br /&gt;
| Don&#039;t create debugging subpackage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ldpath-recursive&amp;lt;/code&amp;gt;&lt;br /&gt;
| Scan directories recursively when creating .so providers&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!spdx&amp;lt;/code&amp;gt;&lt;br /&gt;
| Do not check if the license= field has a SPDX compliant license&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;textrels&amp;lt;/code&amp;gt;&lt;br /&gt;
| Don&#039;t error out when text relocations are found&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;charset.alias&amp;lt;/code&amp;gt;&lt;br /&gt;
| Don&#039;t error out if /usr/lib/charset.alias is found&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;libtool&amp;lt;/code&amp;gt;&lt;br /&gt;
| Don&#039;t delete libtool .la files&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!fhs&amp;lt;/code&amp;gt;&lt;br /&gt;
| Don&#039;t enforce checks on path that follow the FHS&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== pkgdesc ====&lt;br /&gt;
: A brief, one-line description of what the package does.&lt;br /&gt;
&lt;br /&gt;
: Here&#039;s an example from the OpenSSH client package:&lt;br /&gt;
: &amp;lt;pre&amp;gt;pkgdesc=&amp;quot;Port of OpenBSD&#039;s free SSH release - client&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
==== pkggroups ====&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in the &#039;&#039;&#039;[[APKBUILD Reference#.24pkgname.pre-install|$pkgname.pre-install]]&#039;&#039;&#039; script, so that the system group(s) are also created prior to package installation for run-time use.&lt;br /&gt;
==== pkgname ====&lt;br /&gt;
: The name of the package.  All letters should be lowercase.&lt;br /&gt;
: {{Note|When creating an APKBUILD of a module or library for another package, we use some common package prefixes, such as: &#039;&#039;lua-&#039;&#039;, &#039;&#039;perl-&#039;&#039;, &#039;&#039;php-&#039;&#039;, and &#039;&#039;py3-&#039;&#039;.  Search aports for other common prefixes.}}&lt;br /&gt;
&lt;br /&gt;
==== pkgrel ====&lt;br /&gt;
: Alpine package release number.  Starts at 0 (zero).  Always increment &#039;&#039;pkgrel&#039;&#039; when making updates to an aport; reset &#039;&#039;pkgrel&#039;&#039; to 0 (zero) when incrementing &#039;&#039;pkgver&#039;&#039;.&lt;br /&gt;
==== pkgusers ====&lt;br /&gt;
: System user(s) to be created during build-time.  System user(s) should also be created in the &#039;&#039;&#039;[[APKBUILD Reference#.24pkgname.pre-install|$pkgname.pre-install]]&#039;&#039;&#039; script, so that the system user(s) are also created prior to package installation for run-time use.&lt;br /&gt;
==== pkgver ====&lt;br /&gt;
: The version of the software being packaged. Format for valid versions: &amp;lt;code&amp;gt;{digit}{.digit}...{letter}{_suf{#}}...{-r#}&amp;lt;/code&amp;gt; [https://git.alpinelinux.org/cgit/apk-tools/tree/src/version.c#n17]&lt;br /&gt;
: A Suffix &amp;lt;code&amp;gt;suf&amp;lt;/code&amp;gt; in the above format can be one of the following to indicate that the release is &#039;&#039;less recent&#039;&#039; than the version without the suffix: &amp;lt;code&amp;gt;alpha&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;beta&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;pre&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;rc&amp;lt;/code&amp;gt; [https://git.alpinelinux.org/cgit/apk-tools/tree/src/version.c#n75]&lt;br /&gt;
: These are for indicating &#039;&#039;more recent&#039;&#039; releases: &amp;lt;code&amp;gt;cvs&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;svn&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;git&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;hg&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;p&amp;lt;/code&amp;gt; [https://git.alpinelinux.org/cgit/apk-tools/tree/src/version.c#n76]&lt;br /&gt;
: All other suffices are invalid. To package a specific git commit, the date of the commit gets appended to the latest release, e.g. &amp;lt;code&amp;gt;1.0.0_git20180204&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== provides ====&lt;br /&gt;
: List of package names (and optionally version info) this package provides.&lt;br /&gt;
&lt;br /&gt;
: If package with a version is provided (provides=&#039;foo=1.2&#039;) apk will consider it as an alternate name and it will automatically consider the package for installation by the alternate name, and conflict with other packages having the same name, or provides.&lt;br /&gt;
&lt;br /&gt;
: If version is not provided (provides=&#039;foo&#039;), apk will consider it as virtual package name. Several package with same non-versioned provides can be installed simultaneously. However, none of them will be installed by default when requested by the virtual name - instead, error message is given and user is asked to choose which package providing the virtual name should be installed.&lt;br /&gt;
==== provider_priority ====&lt;br /&gt;
: A numeric value which is used by apk-tools to break ties when choosing a virtual package to satisfy a dependency. Higher values have higher priority. The primary use case is to specify the primary package that satisfies a virtual (provider).&lt;br /&gt;
==== replaces ====&lt;br /&gt;
: Allow this package to be installed at the same time as the listed packages, even if they have conflicting files. The files from this package will override (&amp;quot;take over&amp;quot;) the conflicting files.&lt;br /&gt;
&lt;br /&gt;
: This can be used to override config files with &amp;quot;policy packages&amp;quot; [https://gitlab.alpinelinux.org/alpine/apk-tools/-/commit/89d003f8c2e5a92655ee778f7bfa5c0e85ddbed4].&lt;br /&gt;
&lt;br /&gt;
: Another use case is renaming packages (or moving files from one package to another): &amp;quot;replaces&amp;quot; will avoid the file conflict error that apk reports if it happens to install the new package before uninstalling the old package [https://gitlab.alpinelinux.org/alpine/apk-tools/-/issues/10724#note_132872].&lt;br /&gt;
&lt;br /&gt;
: A common misconception is that &amp;quot;replaces&amp;quot; is used to replace packages (like in [https://wiki.archlinux.org/index.php/PKGBUILD#replaces PKGBUILD]). This is not the case, it is only for solving file conflicts. To let apk consider installing one package instead of another one, refer to [[#provides|provides]] (with the version).&lt;br /&gt;
&lt;br /&gt;
==== replaces_priority ====&lt;br /&gt;
: The priority of the replaces. If multiple packages replace files of each other, then the package with the highest &#039;&#039;replaces_priority&#039;&#039; will win.&lt;br /&gt;
&lt;br /&gt;
==== source ====&lt;br /&gt;
: The source variable is not only used to list the remote source files to fetch, it is also used to list the local files that abuild will need in order to build the apk. Examples of such local files include: init.d files, conf.d files, install files (see [[APKBUILD Reference#install|install variable]]), patches, and all other necessary files.&lt;br /&gt;
&lt;br /&gt;
: Here are few things to note:&lt;br /&gt;
&lt;br /&gt;
:* When you are finished adding local and/or remote files to &#039;&#039;source&#039;&#039;, you can execute the following command to add their checksums to the APKBUILD file:&lt;br /&gt;
:: {{Cmd|abuild checksum}}&lt;br /&gt;
:: {{Note|When later updating the content of &#039;&#039;source&#039;&#039;, or updating a file that is listed in &#039;&#039;source&#039;&#039;, you must also update their checksums again with the same command.}}&lt;br /&gt;
&lt;br /&gt;
:* When the remote file is hosted at SourceForge, it&#039;s best to specify the special mirrors link used by SourceForge:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;http://downloads.sourceforge.net/software/software-$pkgver.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
:: (or similar depending on the package).&lt;br /&gt;
&lt;br /&gt;
:* You can set target filename (eg &#039;save as...&#039;) by prefixing the URI with &#039;&#039;filename::&#039;&#039;. This is useful when the remote filename is not specified in the URI (ie, does not end in &#039;/software-1.0.tar.gz&#039;), such as:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;http://oss.example.org/?get=software&amp;amp;ver=1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
:: or when the filename is braindead, like githubs&#039; download tags:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;https://github.com/software/software/archive/v$pkgver.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
:: The above two examples needs a target filename prefix:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;$pkgname-$pkgver.tar.gz::http://oss.example.org/?get=software&amp;amp;ver=$pkgver&amp;lt;/pre&amp;gt;&lt;br /&gt;
:: and:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;$pkgname-$pkgver.tar.gz::https://github.com/software/software/archive/v$pkgver.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:* abuild currently supports the following protocols for remote file retrieval:&lt;br /&gt;
:** http&lt;br /&gt;
:** https&lt;br /&gt;
:** ftp&lt;br /&gt;
&lt;br /&gt;
:* abuild currently supports the following archive types/archive file extensions:&lt;br /&gt;
:** .tar (only in Alpine &amp;gt;= 2.5)&lt;br /&gt;
:** .tar.gz / .tgz&lt;br /&gt;
:** .tar.bz2&lt;br /&gt;
:** .tar.lz (only in Alpine &amp;gt;=3.7)&lt;br /&gt;
:** .tar.lzma&lt;br /&gt;
:** .tar.xz&lt;br /&gt;
:** .zip&lt;br /&gt;
&lt;br /&gt;
:* &amp;lt;code&amp;gt;source&amp;lt;/code&amp;gt; should only include variables that change often like &amp;lt;code&amp;gt;pkgver&amp;lt;/code&amp;gt; or a commit ID. CI will warn you if you include &amp;lt;code&amp;gt;pkgname&amp;lt;/code&amp;gt; in source. Other variables like for example &amp;lt;code&amp;gt;_pkgname&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;_pyname&amp;lt;/code&amp;gt; do not belong in &amp;lt;code&amp;gt;source&amp;lt;/code&amp;gt; either.&lt;br /&gt;
&lt;br /&gt;
==== subpackages ====&lt;br /&gt;
: Subpackages built from this APKBUILD.  abuild will parse this variable and try to find a subpackage split function.  The split function must &#039;&#039;move&#039;&#039; files that do not belong in the main package, from &#039;&#039;$pkgdir&#039;&#039; to &#039;&#039;$subpkgdir&#039;&#039;.  Files and directories can also be &#039;&#039;copied&#039;&#039; from &#039;&#039;$startdir&#039;&#039; and &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: The split function can be specified in 1 of 3 different methods:&lt;br /&gt;
:# subpkgname:&#039;&#039;&#039;splitfunc&#039;&#039;&#039;&lt;br /&gt;
:# $pkgname-&#039;&#039;&#039;splitfunc&#039;&#039;&#039;&lt;br /&gt;
:# &#039;&#039;&#039;splitfunc&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
: {{Note|Split function names &#039;&#039;&#039;cannot&#039;&#039;&#039; use hyphens; use the first method above if the subpackage name contains a hyphen (-) character, like this: &#039;&#039;subpkg-name:subpkg_name&#039;&#039;, where &amp;lt;code&amp;gt;subpkg-name&amp;lt;/code&amp;gt; is the name of the &#039;&#039;&#039;subpackage&#039;&#039;&#039; and &amp;lt;code&amp;gt;subpkg_name&amp;lt;/code&amp;gt; is the name of the &#039;&#039;&#039;subpackage&#039;s split function&#039;&#039;&#039;.}}&lt;br /&gt;
&lt;br /&gt;
: {{Tip|For more information, see the [[APKBUILD_examples:Subpackages|Subpackages example]].}}&lt;br /&gt;
&lt;br /&gt;
==== triggers ====&lt;br /&gt;
: Apk-tools can &amp;quot;monitor&amp;quot; directories and execute a trigger if any package installed/uninstalled any file in the monitored dir. The triggers are always executed after the apk action (install, uninstall, upgrade).&lt;br /&gt;
&lt;br /&gt;
: The triggers are specified in the format: &#039;&#039;scriptname&#039;&#039;=&#039;&#039;pathlist&#039;&#039; where &#039;&#039;scriptname&#039;&#039; is the (sub)package name + .trigger suffix and pathlist is : separated list of the dirs to monitor.&lt;br /&gt;
&lt;br /&gt;
: The &#039;&#039;&#039;triggers&#039;&#039;&#039; variable must include the triggers for subpackages too if they have any.&lt;br /&gt;
&lt;br /&gt;
: It is possible to use wildcards (*) in the dir list.&lt;br /&gt;
&lt;br /&gt;
==== url ====&lt;br /&gt;
: The homepage for the package.  This is to help users find upstream documentation and other information regarding the package.&lt;br /&gt;
&lt;br /&gt;
==== langdir ====&lt;br /&gt;
: Path to where the language files are located for the &#039;&#039;&#039;-lang&#039;&#039;&#039; subpackage, defaults to &#039;&#039;&#039;/usr/share/locale&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== pcprefix ====&lt;br /&gt;
: Prefix all provides derived from parsing pkg-config Requires: with the value in this variable, example: &#039;&#039;&#039;&#039;pcprefix=&amp;quot;foo:&amp;quot;&#039;&#039;&#039; will produce &#039;&#039;&#039;pc:foo:bar&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== sonameprefix ====&lt;br /&gt;
: Prefix all provides derived from parsing shared objects with the value in this variable, example: &#039;&#039;&#039;sonameprefix=&amp;quot;foo&amp;quot;&#039;&#039;&#039; will produce &#039;&#039;&#039;so:foo:bar.so.X&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions that are not &#039;&#039;prepare()&#039;&#039;, &#039;&#039;build()&#039;&#039;, &#039;&#039;check()&#039;&#039; and &#039;&#039;package()&#039;&#039; should consider the current working directory as undefined, and should therefore use the [[APKBUILD Reference#abuild-defined_variables|abuild-defined directory variables]] to their advantage.}}&lt;br /&gt;
&lt;br /&gt;
 sanitycheck() -&amp;gt; clean()-&amp;gt; fetch() -&amp;gt; verify() -&amp;gt; unpack() -&amp;gt; prepare() -&amp;gt; mkusers() -&amp;gt; build() -&amp;gt; check() -&amp;gt; package() -&amp;gt; subpackages() -&amp;gt; language packs -&amp;gt; apk -&amp;gt; cleanup()&lt;br /&gt;
&lt;br /&gt;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden, but it is strongly discouraged on code review for some functions:&lt;br /&gt;
&lt;br /&gt;
==== fetch() ====&lt;br /&gt;
: Downloads remote sources listed in &#039;&#039;source&#039;&#039; to &#039;&#039;SRCDEST&#039;&#039; (&#039;&#039;SRCDEST&#039;&#039; is configured in &#039;&#039;/etc/abuild.conf&#039;&#039;) and creates symlinks in &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
==== unpack() ====&lt;br /&gt;
: unpack() will call default_unpack().&lt;br /&gt;
&lt;br /&gt;
: [https://github.com/alpinelinux/abuild/blob/v3.1.0/abuild.in#L403 default_unpack()] unpacks .tar, .tgz, .tar.gz, .tar.lz (only available in Alpine &amp;gt;=3.7), .tar.bz2, .tar.lzma, .tar.xz, and .zip archives from a symlink in &#039;&#039;$srcdir&#039;&#039; associated with &#039;&#039;$SRCDEST&#039;&#039; (or distfiles folder) resulting in an unpacked folder in &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== dev() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package is used to collect developer files and folders for use in other packages in the compilation process nothing more.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call its internal &#039;&#039;dev()&#039;&#039; function, which in turn calls default_dev().&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;[https://github.com/alpinelinux/abuild/blob/v3.1.0/abuild.in#L1605 default_dev()]&#039;&#039; will move any &#039;&#039;include&#039;&#039; folder and folders containing &#039;&#039;*.[acho]&#039;&#039; (static archive, c source, c header file, object file), &#039;&#039;*.prl&#039;&#039; file extension patterns in &#039;&#039;&amp;quot;$pkgdir&amp;quot;/{lib,usr}&#039;&#039; to &#039;&#039;&amp;quot;$subpkgdir&amp;quot;/{lib,usr}&#039;&#039; recursively; and &#039;&#039;*.so&#039;&#039; files from &#039;&#039;&amp;quot;$pkgdir&amp;quot;/{lib,usr/lib}&#039;&#039; to &#039;&#039;&amp;quot;$subpkgdir&amp;quot;/{lib,usr/lib}&#039;&#039;.  It will also scan and move &#039;&#039;usr/{include,lib/{pkgconfig,cmake,qt*/mkspecs},share/{aclocal,gettext,vala/vapi,gir-[0-9]*,qt*/mkspecs},bin/*-config}}&#039;&#039; developer only folders in &#039;&#039;$pkgdir&#039;&#039; and transfer them to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: In general, default_dev() will support packages that share pkg-config, C programming language API, shared and static libraries, Autotools, gettext, Vala programming language bindings, Python GObject introspection, a provided custom pkg-config like command (*-config), Qt, and CMake.  If you have packages that have C++, other languages, other build system, etc; you need to manually move those developer files only if they are to be used in other packages.&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;&#039;Important&#039;&#039;&#039;: For default_dev() to be called as in no dev(), you need to explicitly add subpackages=&amp;quot;$pkgname-dev&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== doc() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package whose job is only to collect documentation folders from $pkgdir nothing more.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call its internal &#039;&#039;doc()&#039;&#039; function, which in turn calls default_doc().&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;[https://github.com/alpinelinux/abuild/blob/v3.1.0/abuild.in#L1519 default_doc()]&#039;&#039; will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/{doc,man,info,html,sgml,licenses,gtk-doc,ri,help}&#039;&#039; to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: Overriding this function is strongly discouraged.  Packaging docs should be done in the package() function while letting abuild automatically collect the doc folders.&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;&#039;Important&#039;&#039;&#039;: For default_doc() to be called as in no doc(), you need to explicitly add subpackages=&amp;quot;$pkgname-doc&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== openrc() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-openrc&#039;&#039;&#039; package whose job is to collect OpenRC service files that are in /etc/init.d and /etc/conf.d.&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;[https://github.com/alpinelinux/abuild/blob/v3.1.0/abuild.in#L1661 default_openrc()]&#039;&#039; will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/etc/{conf,init}.d&#039;&#039; to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: Overriding this function is strongly discouraged. Packaging OpenRC service definitions should be in the package() function while letting abuild automatically collect the openrc folders.&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;&#039;Important&#039;&#039;&#039;: for default_openrc() to be called as in no openrc(), you need to explicitly add subpackages=&amp;quot;$pkgname-openrc&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== static() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-static&#039;&#039;&#039; package whose job is to collect static libraries that are stored in /lib and /usr/lib.&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;[https://github.com/alpinelinux/abuild/blob/v3.4.0_rc4/abuild.in#L1748 default_static()]&#039;&#039; will move all static libraries (files ending with .a) from &#039;&#039;&amp;quot;$pkgdir&amp;quot;/lib&#039;&#039; and &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/lib&#039;&#039; to their equivalents in &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: Overriding this function is strongly discouraged. Packaging static libraries should be done in the package() function while letting abuild automatically collect the static libraries.&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;&#039;Important&#039;&#039;&#039;: for default_static() to be called as in no static(), you need to explicitly add subpackages=&amp;quot;$pkgname-static&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== snapshot() ====&lt;br /&gt;
: &#039;&#039;&#039;Optional&#039;&#039;&#039;.  For live APKBUILDs or those with a _cvs, _svn, _git, _hg in their version number, you should create a snapshot function only if there is no download link to an archive file (.zip, .tar.gz, ...) to the commit/hash/tag.  The purpose of the snapshot function is to create an archive of the source code so that the package source code is deterministic, and it doesn&#039;t waste time to fetch the source code but bypasses the download step after snapshotting.  Those that download the source code from a git repository will follow head or the latest change to the source code.  It is better to archive the source code as a zip / tar.gz / tar.bz2 up to the commit or the tag which you are trying to build a package.  If it is not deterministic or not every part of the code frozen in time for every dependency and the main project, then the patches will fail or the package may fail to compile when you revisit the package months or years to backport a patch.&lt;br /&gt;
&lt;br /&gt;
: The default [https://github.com/alpinelinux/abuild/blob/v3.1.0/abuild.in#L2310 snapshot()] function has variables associated with it:&lt;br /&gt;
:* $disturl - the base-url of the place to autoupload the snapshot&lt;br /&gt;
:* $svnurl - Subversion repository &lt;br /&gt;
:* $giturl - Git repository&lt;br /&gt;
&lt;br /&gt;
: The default snapshot() can only support one repository.  It is better to override it if there are multiple repositories involved in your package.  CVS, Mercurial (hg), and alternative version control systems must override the default snapshot().&lt;br /&gt;
&lt;br /&gt;
: See [[APKBUILD_examples:Git_checkout]] to how to use it with git.  It takes 2-3 general steps.  Clone the repository; check it out at a specific revision/commit or tag; then you use an archiver to dump it in the &#039;&#039;$SRCDEST&#039;&#039; variable which points to the distfiles folder and the base path to the full path to the archive that you want to create.  You do this for every internal dependency that the package pulls.&lt;br /&gt;
&lt;br /&gt;
: After you have created your snapshot function, you use &amp;lt;code&amp;gt;abuild snapshot&amp;lt;/code&amp;gt; to run it.  &lt;br /&gt;
&lt;br /&gt;
: The archives produced by the snapshot will be saved in &#039;&#039;/var/cache/distfiles&#039;&#039; or whatever you set for &#039;&#039;$SRCDEST&#039;&#039;.  You may need to create symlinks to the archive if the archive is not saved to the Alpine server.&lt;br /&gt;
&lt;br /&gt;
: After you snapshot it, you need to produce the checksums with &amp;lt;code&amp;gt;abuild checksum&amp;lt;/code&amp;gt; to use it in the APKBUILD creation process.&lt;br /&gt;
&lt;br /&gt;
: This feature is available since Alpine &amp;gt;=2.6.&lt;br /&gt;
&lt;br /&gt;
==== default_prepare() ====&lt;br /&gt;
&lt;br /&gt;
:  Before build preparation it handles set of patches inside &amp;lt;code&amp;gt;$srcdir&amp;lt;/code&amp;gt; and prints failed ones.&lt;br /&gt;
&lt;br /&gt;
== User-defined functions ==&lt;br /&gt;
The following functions should be defined by the user: &lt;br /&gt;
&lt;br /&gt;
==== prepare() ====&lt;br /&gt;
: {{note|Please adjust old APKBUILDs, which still have a &#039;&#039;prepare()&#039;&#039; function that does the same as the &#039;&#039;default_prepare()&#039;&#039; when you edit them anyway.}}&lt;br /&gt;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here. When you don&#039;t specify a custom &#039;&#039;prepare()&#039;&#039;, the built-in &#039;&#039;default_prepare()&#039;&#039; from abuild will be used. It applies patches already (always prepare them in the &amp;lt;code&amp;gt;-p1&amp;lt;/code&amp;gt; format), so &#039;&#039;&#039;usually it makes sense to not create a custom &#039;&#039;prepare()&#039;&#039; function at all!&#039;&#039;&#039; If you do create one, call &#039;&#039;default_prepare()&#039;&#039; inside it:&lt;br /&gt;
&lt;br /&gt;
: Before default_prepare gets called, you can define &#039;&#039;patch_args&#039;&#039; to supply the argument to the patch command in global scope then throw away prepare() so it is unnecessary to use the old template code floating around to patch.  patch_args and autopatching is only available in Alpine &amp;gt;=3.4.  See [[Creating_an_Alpine_package#Patches]] to fix the patch that uses a different patch level (-pX).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
prepare() {&lt;br /&gt;
    default_prepare&lt;br /&gt;
    # your custom code here&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== build() ====&lt;br /&gt;
: &#039;&#039;&#039;Required.&#039;&#039;&#039;  This is the compilation stage.  This function will be called as the current user (unless the &#039;&#039;package()&#039;&#039; function is missing - for compatibility reasons).  If no compilation is needed, this function can contain a single line: &amp;lt;code&amp;gt;return 0&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
: To enable or disable CFLAGS, CXXFLAGS, CMake with option, or configure option per arch, use the CARCH variable:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
local cmakeoptions=&lt;br /&gt;
case &amp;quot;$CARCH&amp;quot; in&lt;br /&gt;
        aarch64*|arm*|ppc64le|x86|s390x) cmakeoptions=&amp;quot;$cmakeoptions -DWITH_OPENMP=OFF&amp;quot; ;;&lt;br /&gt;
        x86_64)                          cmakeoptions=&amp;quot;$cmakeoptions -DWITH_OPENMP=ON&amp;quot; ;;&lt;br /&gt;
        *)                               msg &amp;quot;Unable to determine architecture from (CARCH=$CARCH)&amp;quot; ; return 1 ;;&lt;br /&gt;
esac&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
: The block can be used in other parts of the APKBUILD even in global.&lt;br /&gt;
&lt;br /&gt;
==== check() ====&lt;br /&gt;
: &#039;&#039;&#039;Required if functionality exists.&#039;&#039;&#039; This function is called right after the build stage.  It should check that the packaged thing is actually working, typically by running (integration) tests, if provided by upstream.  If there’s no (easy) way how to test the package, you can declare that it does not want to use &#039;&#039;check()&#039;&#039; by adding &amp;quot;!check&amp;quot; into the &#039;&#039;options&#039;&#039; variable (&amp;lt;code&amp;gt;options=&amp;quot;!check&amp;quot;&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
: default_check() does nothing.  You need to manually explicitly call the unit tests or test suite yourself.  When you run the test, the program should return with an exit code of 0, indicating the tests were a success.  Unit tests or test suites will do feature tests, per function correctness check, fuzz testing, benchmarks.&lt;br /&gt;
&lt;br /&gt;
: A package may also require additional testing frameworks packages that are external dependencies.  You should add those to the &#039;&#039;checkdepends=&#039;&#039; in Alpine &amp;gt;=3.6 or &#039;&#039;makedepends=&#039;&#039; for older for backporters.  If the testing framework is not available, you need to create a package for it.  If it requires a specific version of a testing framework, consider making it an internal dependency or a new package with a package name containing the major and minor version number like the python packages.&lt;br /&gt;
&lt;br /&gt;
: Generally speaking, you should define the check functions for libraries, large programs like web browsers, or compilers and interpreters, cryptographic/security/anonymity stuff, mission critical stuff, PCI compliance/money/accounting software, server software with a lot of stakeholders or consumers.  Soon for the new policy change will have virtually &#039;&#039;&#039;all packages with testing capabilities be required to have a working and defined check() function&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: There are times when the unit tests do not work, just because the test itself is broken, new unimplemented feature, external factors not taken into consideration, unbundling path differences, breakage caused by ccache, missing test dependency or version mismatch dependency as in python2 vs python3, test scripts only work for particular language implementation like only supporting python2 but not python3 having used the 2to3 conversion script.  If a unit test is known not to work, you may need to patch it to omit that test or fix it; but, certain tests should not be disabled if it is important.  You may need to alter the references to uncompiled internal dependencies to work with the external dependencies instead.  For ccache, you can either disable it or remove it from the PATH environmental variable before running tests.&lt;br /&gt;
&lt;br /&gt;
{{Note|Tests for graphical applications and toolkits might work on a X11 user setup but will fail on the server unless run with xvfb-run.}}&lt;br /&gt;
&lt;br /&gt;
: If you don&#039;t add the &#039;&#039;check()&#039;&#039; and the &#039;&#039;options=&#039;&#039;, this is what you will see:&lt;br /&gt;
&lt;br /&gt;
  &amp;gt;&amp;gt;&amp;gt; WARNING: py-webtest*: APKBUILD does not run any tests!&lt;br /&gt;
    Alpine policy will soon require that packages have any relevant testsuites run during the build process.&lt;br /&gt;
    To fix, either define a check() function, or declare !check in $options to indicate the package does not have a testsuite.&lt;br /&gt;
&lt;br /&gt;
: If you do not do a check or disable it, you must state there is no testsuite in comment form (#) next to options=&amp;quot;!check&amp;quot; for the code reviewers.&lt;br /&gt;
&lt;br /&gt;
: To run test suite with autotools do:&lt;br /&gt;
&lt;br /&gt;
  make check&lt;br /&gt;
&lt;br /&gt;
: To run the test suite with python setuptools:&lt;br /&gt;
&lt;br /&gt;
  python2 setup.py test&lt;br /&gt;
  python3 setup.py test&lt;br /&gt;
&lt;br /&gt;
: For python it should be &#039;&#039;&#039;test&#039;&#039;&#039; not check.  Check for python setuptools will check the packaging metadata fields[https://docs.python.org/3/distutils/examples.html#checking-a-package] only but not run the unit tests.  There should be verbose output also.  The dependencies for the tests are found in test_require in the setup.py.&lt;br /&gt;
&lt;br /&gt;
: If it says &amp;lt;code&amp;gt;Ran 0 tests in 0.000s&amp;lt;/code&amp;gt; that is not acceptable.  check() will say it was good but it is not actually correct.  It needs to run the test suite with an alternative method like &amp;lt;code&amp;gt;tox -e py27,py36&amp;lt;/code&amp;gt; if you see a tox.ini file.&lt;br /&gt;
&lt;br /&gt;
: You want to do it for each implementation to ensure that the API calls are correct per implementation but ncopa said it was just fine with python3.&lt;br /&gt;
&lt;br /&gt;
: If there is a circular dependency for the checkdepends=, you need to disable the check and put the reason next to &amp;lt;code&amp;gt;options=&amp;quot;!check&amp;quot;&amp;lt;/code&amp;gt; that there is a circular dependency.  You should disable it for the package that package that is least important or least security risk.  The other solution is to make the conflicting dependency an internal dependency but making sure that it doesn&#039;t pull it at check time.  This way they can both preform tests properly.&lt;br /&gt;
&lt;br /&gt;
==== package() ====&lt;br /&gt;
: &#039;&#039;&#039;Required.&#039;&#039;&#039;  This is the packaging stage.  Here, the built application and support files should be installed into &#039;&#039;&#039;$pkgdir&#039;&#039;&#039;.  If this is a metapackage, this function can contain a single line: &amp;lt;code&amp;gt;mkdir -p &amp;quot;$pkgdir&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|Building in fakeroot will reduce performance for parallel builds dramatically.  It is for this reason that we split the build and package process into two separate functions.}}&lt;br /&gt;
&lt;br /&gt;
= Special Operators =&lt;br /&gt;
&lt;br /&gt;
== $pkgname~$pkgver ==&lt;br /&gt;
&lt;br /&gt;
Specifies a required &amp;lt;code&amp;gt;$pkgver&amp;lt;/code&amp;gt; for [[apk]] to satisfy the &amp;lt;code&amp;gt;$pkgname&amp;lt;/code&amp;gt; requirement. &amp;lt;code&amp;gt;~&amp;lt;/code&amp;gt; ignores revisions of the package version. For example &amp;lt;code&amp;gt;superd~0.6&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;$depends&amp;lt;/code&amp;gt; will ensure superd with package version 0.6 is installed as a run-time dependency for the package.&lt;br /&gt;
&lt;br /&gt;
== $pkgname&amp;gt;=$pkgver ==&lt;br /&gt;
&lt;br /&gt;
Specifies the installed package version must be greater than or equal to &amp;lt;code&amp;gt;$pkgver&amp;lt;/code&amp;gt; for [[apk]] to satisfy the &amp;lt;code&amp;gt;$pkgname&amp;lt;/code&amp;gt; requirement.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
The [[APKBUILD examples]] page will assist you in understanding how to create an APKBUILD.&lt;br /&gt;
&lt;br /&gt;
= Version =&lt;br /&gt;
&lt;br /&gt;
This document assumes abuild for Alpine Edge.  For older releases of abuild, some of these features may not be available if you are using an older release.  A link to the implementation is linked for researchers and backporters.&lt;br /&gt;
&lt;br /&gt;
For more information see [[APKBUILD_versions]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Papiris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=25477</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=25477"/>
		<updated>2023-11-08T22:28:03Z</updated>

		<summary type="html">&lt;p&gt;Papiris: fix indent&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;APKBUILDs are the scripts that are created in order to build Alpine packages using the [[abuild]] tool.&lt;br /&gt;
&lt;br /&gt;
See [[aports]] for details on Alpine&#039;s official ports repository.&lt;br /&gt;
&lt;br /&gt;
This page is intended to serve as a reference for creating APKBUILDs; if this is your first time creating a package for Alpine Linux, please see [[Creating an Alpine package]].&lt;br /&gt;
&lt;br /&gt;
= Legend =&lt;br /&gt;
The following notes will assist you in understanding this document.&lt;br /&gt;
&lt;br /&gt;
In description text:&lt;br /&gt;
* If a variable is not prefixed with a &#039;&#039;$&#039;&#039;, it will be represented by italics (i.e., &#039;&#039;srcdir&#039;&#039; ).&lt;br /&gt;
* Functions will also be represented by italics, but will also end with a pair of parentheses (i.e., &#039;&#039;build()&#039;&#039; ).&lt;br /&gt;
* Shell commands will be represented &amp;lt;code&amp;gt;like this&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Variables =&lt;br /&gt;
{{Note|Variables that contain a path (e.g. &#039;&#039;$srcdir&#039;&#039; and &#039;&#039;$pkgdir&#039;&#039;) should always be quoted using double quotes (i.e., &#039;&#039;&amp;quot;$srcdir&amp;quot;&#039;&#039;).  This is done to prevent things from breaking, should the user have the APKBUILD in a directory path that contains spaces.}}&lt;br /&gt;
{{Note|All arbitrary variable and function names should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (for example, &#039;&#039;_luaversions&#039;&#039;).}}&lt;br /&gt;
&lt;br /&gt;
These variables are all well documented in &amp;lt;code&amp;gt;man 5 APKBUILD&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== abuild-defined variables ==&lt;br /&gt;
The following variables are defined by abuild:&lt;br /&gt;
&lt;br /&gt;
==== startdir ====&lt;br /&gt;
: The directory where the APKBUILD script is.&lt;br /&gt;
==== srcdir ====&lt;br /&gt;
: The directory where sources, from the &#039;&#039;source&#039;&#039; variable, are downloaded to and unpacked to.&lt;br /&gt;
==== pkgdir ====&lt;br /&gt;
: This directory should receive the files for the main package.  For example, a normal [https://en.wikipedia.org/wiki/GNU_Autotools autotools] package would have &amp;lt;code&amp;gt;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&amp;lt;/code&amp;gt; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
==== subpkgdir ====&lt;br /&gt;
: This directory should receive the files for a subpackage. This variable should only be used from subpackage functions.&lt;br /&gt;
==== builddir ====&lt;br /&gt;
: This variable should point to the directory inside the &#039;&#039;srcdir&#039;&#039; where the main package source is unpacked.  This is typically &#039;&#039;$srcdir/$pkgname-$pkgver&#039;&#039;.  It’s used by the default &#039;&#039;prepare()&#039;&#039; function as a working directory when applying patches.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
==== Maintainer ====&lt;br /&gt;
: Name and email address of the maintainer of the project (not your package).&lt;br /&gt;
: A well-formatted example is &#039;&#039;&#039;# Maintainer: John Snow &amp;lt;john_snow@thewall.net&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== arch ====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one or several seperated by whitespace of: &#039;&#039;&#039;[[x86]], [[x86_64]], [[armv7]], [[armhf]], [[aarch64]], [[ppc64le]], [[s390x]], [[riscv64]], all&#039;&#039;&#039;, or &#039;&#039;&#039;noarch&#039;&#039;&#039;, where &#039;&#039;&#039;all&#039;&#039;&#039; means all architectures, and &#039;&#039;&#039;noarch&#039;&#039;&#039; means it&#039;s architecture-independent (e.g., a pure-python package). Architectures can be negated using the ! character to exclude them from the list of supported architectures. E.g. &#039;&#039;&#039;arch=&amp;quot;all !ppc64le&amp;quot;&#039;&#039;&#039; means that the package is allowed to be built on all architectures but the ppc64le architecture.&lt;br /&gt;
: {{Tip|To determine if your APKBUILD can use &#039;&#039;&#039;noarch&#039;&#039;&#039;: First specify &#039;&#039;&#039;all&#039;&#039;&#039; and then build the package by executing &amp;lt;code&amp;gt;abuild -r&amp;lt;/code&amp;gt;.  Watch the output towards the end for warnings saying that &#039;&#039;&#039;noarch&#039;&#039;&#039; can be used.  If the main package and all subpackages, if you have any subpackages, give a warning saying that &#039;&#039;&#039;noarch&#039;&#039;&#039; can be used, then you can use &#039;&#039;&#039;noarch&#039;&#039;&#039;.}}&lt;br /&gt;
&lt;br /&gt;
==== depends ====&lt;br /&gt;
: Run-time dependency package(s) that are not shared-object dependencies.  Shared objects dependencies are auto-detected and should not be specified here. To specify a conflicting package, add the package name prefixed with a &#039;!&#039;.&lt;br /&gt;
&lt;br /&gt;
==== depends_dev ====&lt;br /&gt;
: Run-time dependency package(s) for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; subpackage.&lt;br /&gt;
&lt;br /&gt;
: {{Note|From ncopa on IRC: To find out if you need to add a package to depends_dev have a look at *requires* in usr/lib/pkgconfig/*.pc. With libtool it gets more complicated, but we should delete the .la files. Also check if there are any  /usr/bin/*-configure #!/bin/bash #!/usr/bin/perl or Python. Sometimes scripts or similar are generated at build time (i.e autoconf automake) then you normally don&#039;t need add those to depends_dev. You can also just add all -dev makedepends to depends_dev but it will slow the build process a little bit (more build dependencies).}}&lt;br /&gt;
&lt;br /&gt;
==== depends_doc ====&lt;br /&gt;
: Run-time dependency package(s) for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; subpackage.&lt;br /&gt;
&lt;br /&gt;
==== depends_openrc ====&lt;br /&gt;
: Run-time dependency package(s) for the &#039;&#039;&#039;$pkgname-openrc&#039;&#039;&#039; subpackage.&lt;br /&gt;
&lt;br /&gt;
==== depends_libs ====&lt;br /&gt;
: Run-time dependency package(s) for the &#039;&#039;&#039;$pkgname-libs&#039;&#039;&#039; subpackage.&lt;br /&gt;
&lt;br /&gt;
==== depends_static ====&lt;br /&gt;
: Run-time dependency package(s) for the &#039;&#039;&#039;$pkgname-static&#039;&#039;&#039; subpackage.&lt;br /&gt;
&lt;br /&gt;
==== checkdepends ====&lt;br /&gt;
: Dependencies that are only required during the check phase, they are only installed if the check option is enabled&lt;br /&gt;
&lt;br /&gt;
==== giturl ====&lt;br /&gt;
:Git repository from which &amp;lt;code&amp;gt;abuild checkout&amp;lt;/code&amp;gt; checks out. You can checkout a specific branch in git by adding &amp;lt;code&amp;gt;-b $branch&amp;lt;/code&amp;gt;.&lt;br /&gt;
==== install ====&lt;br /&gt;
: There are 6 different types of install scripts.  Install scripts are named &#039;&#039;&#039;$pkgname.action&#039;&#039;&#039;, where &#039;&#039;&#039;action&#039;&#039;&#039; can be:  &#039;&#039;&#039;pre-install, post-install, pre-upgrade, post-upgrade, pre-deinstall&#039;&#039;&#039;, or &#039;&#039;&#039;post-deinstall&#039;&#039;&#039;.  For example, if &#039;&#039;pkgname&#039;&#039; is set to &#039;&#039;&#039;mypackage&#039;&#039;&#039; and &#039;&#039;install&#039;&#039; is set to &#039;&#039;&#039;$pkgname.post-install&#039;&#039;&#039;, then a script named &#039;&#039;&#039;mypackage.post-install&#039;&#039;&#039; must exist along-side the APKBUILD.&lt;br /&gt;
&amp;lt;blockquote&amp;gt;{{Note|Always use &amp;lt;code&amp;gt;/bin/sh&amp;lt;/code&amp;gt; for the command-line interpreter on the [https://en.wikipedia.org/wiki/Shebang_%28Unix%29 shebang line] of your install scripts.}}&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following are the different types of install scripts in detail:&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-install =====&lt;br /&gt;
: This script is executed &#039;&#039;before installing&#039;&#039; the package.  Typical use is when the package needs a group and a user to be created. For example:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
addgroup -S clamav 2&amp;gt;/dev/null&lt;br /&gt;
adduser -S -D -H -s /sbin/nologin -G clamav -g clamav clamav 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
{{Note|If the script exits with a failure (e.g., if the user already exists), the package will not be installed and &amp;lt;code&amp;gt;apk&amp;lt;/code&amp;gt; will exit with failure, hence the &amp;lt;code&amp;gt;exit 0&amp;lt;/code&amp;gt; at the end.}}&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-install =====&lt;br /&gt;
: This script is executed &#039;&#039;after installing&#039;&#039; the package.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;before upgrading/downgrading/reinstalling&#039;&#039; the package. Note that exiting with failure will not cause apk to exit with failure, but will mark the package as broken.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;after upgrading/downgrading/reinstalling&#039;&#039; the package.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-deinstall =====&lt;br /&gt;
: This script is executed &#039;&#039;before uninstalling&#039;&#039; the package.&lt;br /&gt;
: {{Note|If the script exits with failure, &amp;lt;code&amp;gt;apk&amp;lt;/code&amp;gt; will not uninstall the package.}}&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-deinstall =====&lt;br /&gt;
: This script is executed &#039;&#039;after uninstalling&#039;&#039; the package.&lt;br /&gt;
&lt;br /&gt;
==== install_if ====&lt;br /&gt;
:install_if can be used when a package needs to be installed when some packages are already installed or are in the dependency tree. It works in reverse to the &#039;&#039;recommends&#039;&#039; feature, that other package managers provide.&lt;br /&gt;
&lt;br /&gt;
: Typically this is used in a subpackage that should provide files which make sense with another package. For example:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
subpackages=&amp;quot;$pkgname-bash-completion:bashcomp:noarch&amp;quot;&lt;br /&gt;
...&lt;br /&gt;
bashcomp() {&lt;br /&gt;
	pkgdesc=&amp;quot;Bash completions for $pkgname&amp;quot;&lt;br /&gt;
	install_if=&amp;quot;$pkgname=$pkgver-r$pkgrel bash-completion&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	install -Dm644 &amp;quot;$builddir&amp;quot;/doc/bash_completion/aria2c \&lt;br /&gt;
		&amp;quot;$subpkgdir&amp;quot;/usr/share/bash-completion/completions/_aria2c&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From the aria2c APKBUILD. Note that the custom bashcomp() function is only necessary, because the files are not in /usr/share/bash-completion.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:In general, install_if should only be used with &#039;&#039;&#039;at least one versioned constraint&#039;&#039;&#039;. Otherwise, a package that was implicitly installed by install_if and then removed from the binary repositories, will not get purged with &amp;lt;code&amp;gt;apk upgrade&amp;lt;/code&amp;gt;. [https://gitlab.alpinelinux.org/alpine/apk-tools/-/issues/10720#note_121298]&lt;br /&gt;
&lt;br /&gt;
==== license ====&lt;br /&gt;
: License(s) for the package, for example &amp;lt;code&amp;gt;GPL-3.0-or-later&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;BSD-2-Clause&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;MIT&amp;lt;/code&amp;gt; [[Creating_an_Alpine_package#license|(details)]].&lt;br /&gt;
&lt;br /&gt;
==== makedepends ====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
==== md5sums/sha256sums/sha512sums ====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated and updated by executing &amp;lt;code&amp;gt;abuild checksum&amp;lt;/code&amp;gt; and should be the last item in the APKBUILD.&lt;br /&gt;
&lt;br /&gt;
New packages should use only sha512sums.&lt;br /&gt;
&lt;br /&gt;
==== options ====&lt;br /&gt;
: Build-time options for the package.&lt;br /&gt;
&lt;br /&gt;
: {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Option&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!archcheck&amp;lt;/code&amp;gt;&lt;br /&gt;
| Do not try to verify that the architecture of the binary files is the same architecture as abuild should build for. One example where it makes sense to set this are packages with firmware files, that get executed on another CPU (such as WiFi firmware).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!check&amp;lt;/code&amp;gt;&lt;br /&gt;
| Do not try to run the &amp;lt;code&amp;gt;check()&amp;lt;/code&amp;gt; function. Please always add a short comment after the &amp;lt;code&amp;gt;!check&amp;lt;/code&amp;gt; about why it&#039;s disabled. [https://github.com/alpinelinux/aports/pull/2322#discussion_r142545300] Creating a very simple check function, that calls &amp;lt;code&amp;gt;program --version&amp;lt;/code&amp;gt; is worse than disabling tests completely because it gives the false impression that the package is thoroughly tested with the testsuite from upstream. [https://github.com/alpinelinux/aports/pull/7326#discussion_r278797457]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;checkroot&amp;lt;/code&amp;gt;&lt;br /&gt;
| Specifies that the package&#039;s test suite will be run in &#039;&#039;fakeroot&#039;&#039;. This is necessary for some test suites which fail when run as non-root.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;net&amp;lt;/code&amp;gt;&lt;br /&gt;
| Allows network access when run in &#039;&#039;rootbld&#039;&#039;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!strip&amp;lt;/code&amp;gt;&lt;br /&gt;
| Avoid stripping symbols from binaries.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;suid&amp;lt;/code&amp;gt;&lt;br /&gt;
| Allow [https://en.wikipedia.org/wiki/Setuid setuid] binaries.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!tracedeps&amp;lt;/code&amp;gt;&lt;br /&gt;
| Do not automatically find dependencies (e.g. by using &amp;lt;code&amp;gt;ldd&amp;lt;/code&amp;gt; to find dynamic libraries, which the resulting binary links against).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;chmod-clean&amp;lt;/code&amp;gt;&lt;br /&gt;
| Make all files writable in the src/ directory. Useful for packages that make files read-only in the process of building packages (go modules).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;toolchain&amp;lt;/code&amp;gt;&lt;br /&gt;
| Don&#039;t warn when g++ is in makedepends&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!dbg&amp;lt;/code&amp;gt;&lt;br /&gt;
| Don&#039;t create debugging subpackage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ldpath-recursive&amp;lt;/code&amp;gt;&lt;br /&gt;
| Scan directories recursively when creating .so providers&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!spdx&amp;lt;/code&amp;gt;&lt;br /&gt;
| Do not check if the license= field has a SPDX compliant license&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;textrels&amp;lt;/code&amp;gt;&lt;br /&gt;
| Don&#039;t error out when text relocations are found&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;charset.alias&amp;lt;/code&amp;gt;&lt;br /&gt;
| Don&#039;t error out if /usr/lib/charset.alias is found&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;libtool&amp;lt;/code&amp;gt;&lt;br /&gt;
| Don&#039;t delete libtool .la files&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!fhs&amp;lt;/code&amp;gt;&lt;br /&gt;
| Don&#039;t enforce checks on path that follow the FHS&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== pkgdesc ====&lt;br /&gt;
: A brief, one-line description of what the package does.&lt;br /&gt;
&lt;br /&gt;
: Here&#039;s an example from the OpenSSH client package:&lt;br /&gt;
: &amp;lt;pre&amp;gt;pkgdesc=&amp;quot;Port of OpenBSD&#039;s free SSH release - client&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
==== pkggroups ====&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in the &#039;&#039;&#039;[[APKBUILD Reference#.24pkgname.pre-install|$pkgname.pre-install]]&#039;&#039;&#039; script, so that the system group(s) are also created prior to package installation for run-time use.&lt;br /&gt;
==== pkgname ====&lt;br /&gt;
: The name of the package.  All letters should be lowercase.&lt;br /&gt;
: {{Note|When creating an APKBUILD of a module or library for another package, we use some common package prefixes, such as: &#039;&#039;lua-&#039;&#039;, &#039;&#039;perl-&#039;&#039;, &#039;&#039;php-&#039;&#039;, and &#039;&#039;py3-&#039;&#039;.  Search aports for other common prefixes.}}&lt;br /&gt;
&lt;br /&gt;
==== pkgrel ====&lt;br /&gt;
: Alpine package release number.  Starts at 0 (zero).  Always increment &#039;&#039;pkgrel&#039;&#039; when making updates to an aport; reset &#039;&#039;pkgrel&#039;&#039; to 0 (zero) when incrementing &#039;&#039;pkgver&#039;&#039;.&lt;br /&gt;
==== pkgusers ====&lt;br /&gt;
: System user(s) to be created during build-time.  System user(s) should also be created in the &#039;&#039;&#039;[[APKBUILD Reference#.24pkgname.pre-install|$pkgname.pre-install]]&#039;&#039;&#039; script, so that the system user(s) are also created prior to package installation for run-time use.&lt;br /&gt;
==== pkgver ====&lt;br /&gt;
: The version of the software being packaged. Format for valid versions: &amp;lt;code&amp;gt;{digit}{.digit}...{letter}{_suf{#}}...{-r#}&amp;lt;/code&amp;gt; [https://git.alpinelinux.org/cgit/apk-tools/tree/src/version.c#n17]&lt;br /&gt;
: A Suffix &amp;lt;code&amp;gt;suf&amp;lt;/code&amp;gt; in the above format can be one of the following to indicate that the release is &#039;&#039;less recent&#039;&#039; than the version without the suffix: &amp;lt;code&amp;gt;alpha&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;beta&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;pre&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;rc&amp;lt;/code&amp;gt; [https://git.alpinelinux.org/cgit/apk-tools/tree/src/version.c#n75]&lt;br /&gt;
: These are for indicating &#039;&#039;more recent&#039;&#039; releases: &amp;lt;code&amp;gt;cvs&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;svn&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;git&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;hg&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;p&amp;lt;/code&amp;gt; [https://git.alpinelinux.org/cgit/apk-tools/tree/src/version.c#n76]&lt;br /&gt;
: All other suffices are invalid. To package a specific git commit, the date of the commit gets appended to the latest release, e.g. &amp;lt;code&amp;gt;1.0.0_git20180204&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== provides ====&lt;br /&gt;
: List of package names (and optionally version info) this package provides.&lt;br /&gt;
&lt;br /&gt;
: If package with a version is provided (provides=&#039;foo=1.2&#039;) apk will consider it as an alternate name and it will automatically consider the package for installation by the alternate name, and conflict with other packages having the same name, or provides.&lt;br /&gt;
&lt;br /&gt;
: If version is not provided (provides=&#039;foo&#039;), apk will consider it as virtual package name. Several package with same non-versioned provides can be installed simultaneously. However, none of them will be installed by default when requested by the virtual name - instead, error message is given and user is asked to choose which package providing the virtual name should be installed.&lt;br /&gt;
==== provider_priority ====&lt;br /&gt;
: A numeric value which is used by apk-tools to break ties when choosing a virtual package to satisfy a dependency. Higher values have higher priority. The primary use case is to specify the primary package that satisfies a virtual (provider).&lt;br /&gt;
==== replaces ====&lt;br /&gt;
: Allow this package to be installed at the same time as the listed packages, even if they have conflicting files. The files from this package will override (&amp;quot;take over&amp;quot;) the conflicting files.&lt;br /&gt;
&lt;br /&gt;
: This can be used to override config files with &amp;quot;policy packages&amp;quot; [https://gitlab.alpinelinux.org/alpine/apk-tools/-/commit/89d003f8c2e5a92655ee778f7bfa5c0e85ddbed4].&lt;br /&gt;
&lt;br /&gt;
: Another use case is renaming packages (or moving files from one package to another): &amp;quot;replaces&amp;quot; will avoid the file conflict error that apk reports if it happens to install the new package before uninstalling the old package [https://gitlab.alpinelinux.org/alpine/apk-tools/-/issues/10724#note_132872].&lt;br /&gt;
&lt;br /&gt;
: A common misconception is that &amp;quot;replaces&amp;quot; is used to replace packages (like in [https://wiki.archlinux.org/index.php/PKGBUILD#replaces PKGBUILD]). This is not the case, it is only for solving file conflicts. To let apk consider installing one package instead of another one, refer to [[#provides|provides]] (with the version).&lt;br /&gt;
&lt;br /&gt;
==== replaces_priority ====&lt;br /&gt;
: The priority of the replaces. If multiple packages replace files of each other, then the package with the highest &#039;&#039;replaces_priority&#039;&#039; will win.&lt;br /&gt;
&lt;br /&gt;
==== source ====&lt;br /&gt;
: The source variable is not only used to list the remote source files to fetch, it is also used to list the local files that abuild will need in order to build the apk. Examples of such local files include: init.d files, conf.d files, install files (see [[APKBUILD Reference#install|install variable]]), patches, and all other necessary files.&lt;br /&gt;
&lt;br /&gt;
: Here are few things to note:&lt;br /&gt;
&lt;br /&gt;
:* When you are finished adding local and/or remote files to &#039;&#039;source&#039;&#039;, you can execute the following command to add their checksums to the APKBUILD file:&lt;br /&gt;
:: {{Cmd|abuild checksum}}&lt;br /&gt;
:: {{Note|When later updating the content of &#039;&#039;source&#039;&#039;, or updating a file that is listed in &#039;&#039;source&#039;&#039;, you must also update their checksums again with the same command.}}&lt;br /&gt;
&lt;br /&gt;
:* When the remote file is hosted at SourceForge, it&#039;s best to specify the special mirrors link used by SourceForge:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;http://downloads.sourceforge.net/software/software-$pkgver.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
:: (or similar depending on the package).&lt;br /&gt;
&lt;br /&gt;
:* You can set target filename (eg &#039;save as...&#039;) by prefixing the URI with &#039;&#039;filename::&#039;&#039;. This is useful when the remote filename is not specified in the URI (ie, does not end in &#039;/software-1.0.tar.gz&#039;), such as:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;http://oss.example.org/?get=software&amp;amp;ver=1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
:: or when the filename is braindead, like githubs&#039; download tags:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;https://github.com/software/software/archive/v$pkgver.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
:: The above two examples needs a target filename prefix:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;$pkgname-$pkgver.tar.gz::http://oss.example.org/?get=software&amp;amp;ver=$pkgver&amp;lt;/pre&amp;gt;&lt;br /&gt;
:: and:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;$pkgname-$pkgver.tar.gz::https://github.com/software/software/archive/v$pkgver.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:* abuild currently supports the following protocols for remote file retrieval:&lt;br /&gt;
:** http&lt;br /&gt;
:** https&lt;br /&gt;
:** ftp&lt;br /&gt;
&lt;br /&gt;
:* abuild currently supports the following archive types/archive file extensions:&lt;br /&gt;
:** .tar (only in Alpine &amp;gt;= 2.5)&lt;br /&gt;
:** .tar.gz / .tgz&lt;br /&gt;
:** .tar.bz2&lt;br /&gt;
:** .tar.lz (only in Alpine &amp;gt;=3.7)&lt;br /&gt;
:** .tar.lzma&lt;br /&gt;
:** .tar.xz&lt;br /&gt;
:** .zip&lt;br /&gt;
&lt;br /&gt;
:* &amp;lt;code&amp;gt;source&amp;lt;/code&amp;gt; should only include variables that change often like &amp;lt;code&amp;gt;pkgver&amp;lt;/code&amp;gt; or a commit ID. CI will warn you if you include &amp;lt;code&amp;gt;pkgname&amp;lt;/code&amp;gt; in source. Other variables like for example &amp;lt;code&amp;gt;_pkgname&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;_pyname&amp;lt;/code&amp;gt; do not belong in &amp;lt;code&amp;gt;source&amp;lt;/code&amp;gt; either.&lt;br /&gt;
&lt;br /&gt;
==== subpackages ====&lt;br /&gt;
: Subpackages built from this APKBUILD.  abuild will parse this variable and try to find a subpackage split function.  The split function must &#039;&#039;move&#039;&#039; files that do not belong in the main package, from &#039;&#039;$pkgdir&#039;&#039; to &#039;&#039;$subpkgdir&#039;&#039;.  Files and directories can also be &#039;&#039;copied&#039;&#039; from &#039;&#039;$startdir&#039;&#039; and &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: The split function can be specified in 1 of 3 different methods:&lt;br /&gt;
:# subpkgname:&#039;&#039;&#039;splitfunc&#039;&#039;&#039;&lt;br /&gt;
:# $pkgname-&#039;&#039;&#039;splitfunc&#039;&#039;&#039;&lt;br /&gt;
:# &#039;&#039;&#039;splitfunc&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
: {{Note|Split function names &#039;&#039;&#039;cannot&#039;&#039;&#039; use hyphens; use the first method above if the subpackage name contains a hyphen (-) character, like this: &#039;&#039;subpkg-name:subpkg_name&#039;&#039;, where &amp;lt;code&amp;gt;subpkg-name&amp;lt;/code&amp;gt; is the name of the &#039;&#039;&#039;subpackage&#039;&#039;&#039; and &amp;lt;code&amp;gt;subpkg_name&amp;lt;/code&amp;gt; is the name of the &#039;&#039;&#039;subpackage&#039;s split function&#039;&#039;&#039;.}}&lt;br /&gt;
&lt;br /&gt;
: {{Tip|For more information, see the [[APKBUILD_examples:Subpackages|Subpackages example]].}}&lt;br /&gt;
&lt;br /&gt;
==== triggers ====&lt;br /&gt;
: Apk-tools can &amp;quot;monitor&amp;quot; directories and execute a trigger if any package installed/uninstalled any file in the monitored dir. The triggers are always executed after the apk action (install, uninstall, upgrade).&lt;br /&gt;
&lt;br /&gt;
: The triggers are specified in the format: &#039;&#039;scriptname&#039;&#039;=&#039;&#039;pathlist&#039;&#039; where &#039;&#039;scriptname&#039;&#039; is the (sub)package name + .trigger suffix and pathlist is : separated list of the dirs to monitor.&lt;br /&gt;
&lt;br /&gt;
: The &#039;&#039;&#039;triggers&#039;&#039;&#039; variable must include the triggers for subpackages too if they have any.&lt;br /&gt;
&lt;br /&gt;
: It is possible to use wildcards (*) in the dir list.&lt;br /&gt;
&lt;br /&gt;
==== url ====&lt;br /&gt;
: The homepage for the package.  This is to help users find upstream documentation and other information regarding the package.&lt;br /&gt;
&lt;br /&gt;
==== langdir ====&lt;br /&gt;
: Path to where the language files are located for the &#039;&#039;&#039;-lang&#039;&#039;&#039; subpackage, defaults to &#039;&#039;&#039;/usr/share/locale&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== pcprefix ====&lt;br /&gt;
: Prefix all provides derived from parsing pkg-config Requires: with the value in this variable, example: &#039;&#039;&#039;&#039;pcprefix=&amp;quot;foo:&amp;quot;&#039;&#039;&#039; will produce &#039;&#039;&#039;pc:foo:bar&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== sonameprefix ====&lt;br /&gt;
: Prefix all provides derived from parsing shared objects with the value in this variable, example: &#039;&#039;&#039;sonameprefix=&amp;quot;foo&amp;quot;&#039;&#039;&#039; will produce &#039;&#039;&#039;so:foo:bar.so.X&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions that are not &#039;&#039;prepare()&#039;&#039;, &#039;&#039;build()&#039;&#039;, &#039;&#039;check()&#039;&#039; and &#039;&#039;package()&#039;&#039; should consider the current working directory as undefined, and should therefore use the [[APKBUILD Reference#abuild-defined_variables|abuild-defined directory variables]] to their advantage.}}&lt;br /&gt;
&lt;br /&gt;
 sanitycheck() -&amp;gt; clean()-&amp;gt; fetch() -&amp;gt; verify() -&amp;gt; unpack() -&amp;gt; prepare() -&amp;gt; mkusers() -&amp;gt; build() -&amp;gt; check() -&amp;gt; package() -&amp;gt; subpackages() -&amp;gt; language packs -&amp;gt; apk -&amp;gt; cleanup()&lt;br /&gt;
&lt;br /&gt;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden, but it is strongly discouraged on code review for some functions:&lt;br /&gt;
&lt;br /&gt;
==== fetch() ====&lt;br /&gt;
: Downloads remote sources listed in &#039;&#039;source&#039;&#039; to &#039;&#039;SRCDEST&#039;&#039; (&#039;&#039;SRCDEST&#039;&#039; is configured in &#039;&#039;/etc/abuild.conf&#039;&#039;) and creates symlinks in &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
==== unpack() ====&lt;br /&gt;
: unpack() will call default_unpack().&lt;br /&gt;
&lt;br /&gt;
: [https://github.com/alpinelinux/abuild/blob/v3.1.0/abuild.in#L403 default_unpack()] unpacks .tar, .tgz, .tar.gz, .tar.lz (only available in Alpine &amp;gt;=3.7), .tar.bz2, .tar.lzma, .tar.xz, and .zip archives from a symlink in &#039;&#039;$srcdir&#039;&#039; associated with &#039;&#039;$SRCDEST&#039;&#039; (or distfiles folder) resulting in an unpacked folder in &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== dev() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package is used to collect developer files and folders for use in other packages in the compilation process nothing more.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call its internal &#039;&#039;dev()&#039;&#039; function, which in turn calls default_dev().&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;[https://github.com/alpinelinux/abuild/blob/v3.1.0/abuild.in#L1605 default_dev()]&#039;&#039; will move any &#039;&#039;include&#039;&#039; folder and folders containing &#039;&#039;*.[acho]&#039;&#039; (static archive, c source, c header file, object file), &#039;&#039;*.prl&#039;&#039; file extension patterns in &#039;&#039;&amp;quot;$pkgdir&amp;quot;/{lib,usr}&#039;&#039; to &#039;&#039;&amp;quot;$subpkgdir&amp;quot;/{lib,usr}&#039;&#039; recursively; and &#039;&#039;*.so&#039;&#039; files from &#039;&#039;&amp;quot;$pkgdir&amp;quot;/{lib,usr/lib}&#039;&#039; to &#039;&#039;&amp;quot;$subpkgdir&amp;quot;/{lib,usr/lib}&#039;&#039;.  It will also scan and move &#039;&#039;usr/{include,lib/{pkgconfig,cmake,qt*/mkspecs},share/{aclocal,gettext,vala/vapi,gir-[0-9]*,qt*/mkspecs},bin/*-config}}&#039;&#039; developer only folders in &#039;&#039;$pkgdir&#039;&#039; and transfer them to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: In general, default_dev() will support packages that share pkg-config, C programming language API, shared and static libraries, Autotools, gettext, Vala programming language bindings, Python GObject introspection, a provided custom pkg-config like command (*-config), Qt, and CMake.  If you have packages that have C++, other languages, other build system, etc; you need to manually move those developer files only if they are to be used in other packages.&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;&#039;Important&#039;&#039;&#039;: For default_dev() to be called as in no dev(), you need to explicitly add subpackages=&amp;quot;$pkgname-dev&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== doc() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package whose job is only to collect documentation folders from $pkgdir nothing more.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call its internal &#039;&#039;doc()&#039;&#039; function, which in turn calls default_doc().&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;[https://github.com/alpinelinux/abuild/blob/v3.1.0/abuild.in#L1519 default_doc()]&#039;&#039; will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/{doc,man,info,html,sgml,licenses,gtk-doc,ri,help}&#039;&#039; to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: Overriding this function is strongly discouraged.  Packaging docs should be done in the package() function while letting abuild automatically collect the doc folders.&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;&#039;Important&#039;&#039;&#039;: For default_doc() to be called as in no doc(), you need to explicitly add subpackages=&amp;quot;$pkgname-doc&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== openrc() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-openrc&#039;&#039;&#039; package whose job is to collect OpenRC service files that are in /etc/init.d and /etc/conf.d.&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;[https://github.com/alpinelinux/abuild/blob/v3.1.0/abuild.in#L1661 default_openrc()]&#039;&#039; will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/etc/{conf,init}.d&#039;&#039; to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: Overriding this function is strongly discouraged. Packaging OpenRC service definitions should be in the package() function while letting abuild automatically collect the openrc folders.&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;&#039;Important&#039;&#039;&#039;: for default_openrc() to be called as in no openrc(), you need to explicitly add subpackages=&amp;quot;$pkgname-openrc&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== static() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-static&#039;&#039;&#039; package whose job is to collect static libraries that are stored in /lib and /usr/lib.&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;[https://github.com/alpinelinux/abuild/blob/v3.4.0_rc4/abuild.in#L1748 default_static()]&#039;&#039; will move all static libraries (files ending with .a) from &#039;&#039;&amp;quot;$pkgdir&amp;quot;/lib&#039;&#039; and &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/lib&#039;&#039; to their equivalents in &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: Overriding this function is strongly discouraged. Packaging static libraries should be done in the package() function while letting abuild automatically collect the static libraries.&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;&#039;Important&#039;&#039;&#039;: for default_static() to be called as in no static(), you need to explicitly add subpackages=&amp;quot;$pkgname-static&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== snapshot() ====&lt;br /&gt;
: &#039;&#039;&#039;Optional&#039;&#039;&#039;.  For live APKBUILDs or those with a _cvs, _svn, _git, _hg in their version number, you should create a snapshot function only if there is no download link to an archive file (.zip, .tar.gz, ...) to the commit/hash/tag.  The purpose of the snapshot function is to create an archive of the source code so that the package source code is deterministic, and it doesn&#039;t waste time to fetch the source code but bypasses the download step after snapshotting.  Those that download the source code from a git repository will follow head or the latest change to the source code.  It is better to archive the source code as a zip / tar.gz / tar.bz2 up to the commit or the tag which you are trying to build a package.  If it is not deterministic or not every part of the code frozen in time for every dependency and the main project, then the patches will fail or the package may fail to compile when you revisit the package months or years to backport a patch.&lt;br /&gt;
&lt;br /&gt;
: The default [https://github.com/alpinelinux/abuild/blob/v3.1.0/abuild.in#L2310 snapshot()] function has variables associated with it:&lt;br /&gt;
:* $disturl - the base-url of the place to autoupload the snapshot&lt;br /&gt;
:* $svnurl - Subversion repository &lt;br /&gt;
:* $giturl - Git repository&lt;br /&gt;
&lt;br /&gt;
: The default snapshot() can only support one repository.  It is better to override it if there are multiple repositories involved in your package.  CVS, Mercurial (hg), and alternative version control systems must override the default snapshot().&lt;br /&gt;
&lt;br /&gt;
: See [[APKBUILD_examples:Git_checkout]] to how to use it with git.  It takes 2-3 general steps.  Clone the repository; check it out at a specific revision/commit or tag; then you use an archiver to dump it in the &#039;&#039;$SRCDEST&#039;&#039; variable which points to the distfiles folder and the base path to the full path to the archive that you want to create.  You do this for every internal dependency that the package pulls.&lt;br /&gt;
&lt;br /&gt;
: After you have created your snapshot function, you use &amp;lt;code&amp;gt;abuild snapshot&amp;lt;/code&amp;gt; to run it.  &lt;br /&gt;
&lt;br /&gt;
: The archives produced by the snapshot will be saved in &#039;&#039;/var/cache/distfiles&#039;&#039; or whatever you set for &#039;&#039;$SRCDEST&#039;&#039;.  You may need to create symlinks to the archive if the archive is not saved to the Alpine server.&lt;br /&gt;
&lt;br /&gt;
: After you snapshot it, you need to produce the checksums with &amp;lt;code&amp;gt;abuild checksum&amp;lt;/code&amp;gt; to use it in the APKBUILD creation process.&lt;br /&gt;
&lt;br /&gt;
: This feature is available since Alpine &amp;gt;=2.6.&lt;br /&gt;
&lt;br /&gt;
==== default_prepare() ====&lt;br /&gt;
&lt;br /&gt;
:  Before build preparation it handles set of patches inside &amp;lt;code&amp;gt;$srcdir&amp;lt;/code&amp;gt; and prints failed ones.&lt;br /&gt;
&lt;br /&gt;
== User-defined functions ==&lt;br /&gt;
The following functions should be defined by the user: &lt;br /&gt;
&lt;br /&gt;
==== prepare() ====&lt;br /&gt;
: {{note|Please adjust old APKBUILDs, which still have a &#039;&#039;prepare()&#039;&#039; function that does the same as the &#039;&#039;default_prepare()&#039;&#039; when you edit them anyway.}}&lt;br /&gt;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here. When you don&#039;t specify a custom &#039;&#039;prepare()&#039;&#039;, the built-in &#039;&#039;default_prepare()&#039;&#039; from abuild will be used. It applies patches already (always prepare them in the &amp;lt;code&amp;gt;-p1&amp;lt;/code&amp;gt; format), so &#039;&#039;&#039;usually it makes sense to not create a custom &#039;&#039;prepare()&#039;&#039; function at all!&#039;&#039;&#039; If you do create one, call &#039;&#039;default_prepare()&#039;&#039; inside it:&lt;br /&gt;
&lt;br /&gt;
: Before default_prepare gets called, you can define &#039;&#039;patch_args&#039;&#039; to supply the argument to the patch command in global scope then throw away prepare() so it is unnecessary to use the old template code floating around to patch.  patch_args and autopatching is only available in Alpine &amp;gt;=3.4.  See [[Creating_an_Alpine_package#Patches]] to fix the patch that uses a different patch level (-pX).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
prepare() {&lt;br /&gt;
    default_prepare&lt;br /&gt;
    # your custom code here&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== build() ====&lt;br /&gt;
: &#039;&#039;&#039;Required.&#039;&#039;&#039;  This is the compilation stage.  This function will be called as the current user (unless the &#039;&#039;package()&#039;&#039; function is missing - for compatibility reasons).  If no compilation is needed, this function can contain a single line: &amp;lt;code&amp;gt;return 0&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
: To enable or disable CFLAGS, CXXFLAGS, CMake with option, or configure option per arch, use the CARCH variable:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
local cmakeoptions=&lt;br /&gt;
case &amp;quot;$CARCH&amp;quot; in&lt;br /&gt;
        aarch64*|arm*|ppc64le|x86|s390x) cmakeoptions=&amp;quot;$cmakeoptions -DWITH_OPENMP=OFF&amp;quot; ;;&lt;br /&gt;
        x86_64)                          cmakeoptions=&amp;quot;$cmakeoptions -DWITH_OPENMP=ON&amp;quot; ;;&lt;br /&gt;
        *)                               msg &amp;quot;Unable to determine architecture from (CARCH=$CARCH)&amp;quot; ; return 1 ;;&lt;br /&gt;
esac&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
: The block can be used in other parts of the APKBUILD even in global.&lt;br /&gt;
&lt;br /&gt;
==== check() ====&lt;br /&gt;
: &#039;&#039;&#039;Required if functionality exists.&#039;&#039;&#039; This function is called right after the build stage.  It should check that the packaged thing is actually working, typically by running (integration) tests, if provided by upstream.  If there’s no (easy) way how to test the package, you can declare that it does not want to use &#039;&#039;check()&#039;&#039; by adding &amp;quot;!check&amp;quot; into the &#039;&#039;options&#039;&#039; variable (&amp;lt;code&amp;gt;options=&amp;quot;!check&amp;quot;&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
: default_check() does nothing.  You need to manually explicitly call the unit tests or test suite yourself.  When you run the test, the program should return with an exit code of 0, indicating the tests were a success.  Unit tests or test suites will do feature tests, per function correctness check, fuzz testing, benchmarks.&lt;br /&gt;
&lt;br /&gt;
: A package may also require additional testing frameworks packages that are external dependencies.  You should add those to the &#039;&#039;checkdepends=&#039;&#039; in Alpine &amp;gt;=3.6 or &#039;&#039;makedepends=&#039;&#039; for older for backporters.  If the testing framework is not available, you need to create a package for it.  If it requires a specific version of a testing framework, consider making it an internal dependency or a new package with a package name containing the major and minor version number like the python packages.&lt;br /&gt;
&lt;br /&gt;
: Generally speaking, you should define the check functions for libraries, large programs like web browsers, or compilers and interpreters, cryptographic/security/anonymity stuff, mission critical stuff, PCI compliance/money/accounting software, server software with a lot of stakeholders or consumers.  Soon for the new policy change will have virtually &#039;&#039;&#039;all packages with testing capabilities be required to have a working and defined check() function&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: There are times when the unit tests do not work, just because the test itself is broken, new unimplemented feature, external factors not taken into consideration, unbundling path differences, breakage caused by ccache, missing test dependency or version mismatch dependency as in python2 vs python3, test scripts only work for particular language implementation like only supporting python2 but not python3 having used the 2to3 conversion script.  If a unit test is known not to work, you may need to patch it to omit that test or fix it; but, certain tests should not be disabled if it is important.  You may need to alter the references to uncompiled internal dependencies to work with the external dependencies instead.  For ccache, you can either disable it or remove it from the PATH environmental variable before running tests.&lt;br /&gt;
&lt;br /&gt;
{{Note|Tests for graphical applications and toolkits might work on a X11 user setup but will fail on the server unless run with xvfb-run.}}&lt;br /&gt;
&lt;br /&gt;
: If you don&#039;t add the &#039;&#039;check()&#039;&#039; and the &#039;&#039;options=&#039;&#039;, this is what you will see:&lt;br /&gt;
&lt;br /&gt;
  &amp;gt;&amp;gt;&amp;gt; WARNING: py-webtest*: APKBUILD does not run any tests!&lt;br /&gt;
    Alpine policy will soon require that packages have any relevant testsuites run during the build process.&lt;br /&gt;
    To fix, either define a check() function, or declare !check in $options to indicate the package does not have a testsuite.&lt;br /&gt;
&lt;br /&gt;
: If you do not do a check or disable it, you must state there is no testsuite in comment form (#) next to options=&amp;quot;!check&amp;quot; for the code reviewers.&lt;br /&gt;
&lt;br /&gt;
: To run test suite with autotools do:&lt;br /&gt;
&lt;br /&gt;
  make check&lt;br /&gt;
&lt;br /&gt;
: To run the test suite with python setuptools:&lt;br /&gt;
&lt;br /&gt;
  python2 setup.py test&lt;br /&gt;
  python3 setup.py test&lt;br /&gt;
&lt;br /&gt;
: For python it should be &#039;&#039;&#039;test&#039;&#039;&#039; not check.  Check for python setuptools will check the packaging metadata fields[https://docs.python.org/3/distutils/examples.html#checking-a-package] only but not run the unit tests.  There should be verbose output also.  The dependencies for the tests are found in test_require in the setup.py.&lt;br /&gt;
&lt;br /&gt;
: If it says &amp;lt;code&amp;gt;Ran 0 tests in 0.000s&amp;lt;/code&amp;gt; that is not acceptable.  check() will say it was good but it is not actually correct.  It needs to run the test suite with an alternative method like &amp;lt;code&amp;gt;tox -e py27,py36&amp;lt;/code&amp;gt; if you see a tox.ini file.&lt;br /&gt;
&lt;br /&gt;
: You want to do it for each implementation to ensure that the API calls are correct per implementation but ncopa said it was just fine with python3.&lt;br /&gt;
&lt;br /&gt;
: If there is a circular dependency for the checkdepends=, you need to disable the check and put the reason next to &amp;lt;code&amp;gt;options=&amp;quot;!check&amp;quot;&amp;lt;/code&amp;gt; that there is a circular dependency.  You should disable it for the package that package that is least important or least security risk.  The other solution is to make the conflicting dependency an internal dependency but making sure that it doesn&#039;t pull it at check time.  This way they can both preform tests properly.&lt;br /&gt;
&lt;br /&gt;
==== package() ====&lt;br /&gt;
: &#039;&#039;&#039;Required.&#039;&#039;&#039;  This is the packaging stage.  Here, the built application and support files should be installed into &#039;&#039;&#039;$pkgdir&#039;&#039;&#039;.  If this is a metapackage, this function can contain a single line: &amp;lt;code&amp;gt;mkdir -p &amp;quot;$pkgdir&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|Building in fakeroot will reduce performance for parallel builds dramatically.  It is for this reason that we split the build and package process into two separate functions.}}&lt;br /&gt;
&lt;br /&gt;
= Special Operators =&lt;br /&gt;
&lt;br /&gt;
== $pkgname~$pkgver ==&lt;br /&gt;
&lt;br /&gt;
Specifies a required &amp;lt;code&amp;gt;$pkgver&amp;lt;/code&amp;gt; for [[apk]] to satisfy the &amp;lt;code&amp;gt;$pkgname&amp;lt;/code&amp;gt; requirement. &amp;lt;code&amp;gt;~&amp;lt;/code&amp;gt; ignores revisions of the package version. For example &amp;lt;code&amp;gt;superd~0.6&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;$depends&amp;lt;/code&amp;gt; will ensure superd with package version 0.6 is installed as a run-time dependency for the package.&lt;br /&gt;
&lt;br /&gt;
== $pkgname&amp;gt;=$pkgver ==&lt;br /&gt;
&lt;br /&gt;
Specifies the installed package version must be greater than or equal to &amp;lt;code&amp;gt;$pkgver&amp;lt;/code&amp;gt; for [[apk]] to satisfy the &amp;lt;code&amp;gt;$pkgname&amp;lt;/code&amp;gt; requirement.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
The [[APKBUILD examples]] page will assist you in understanding how to create an APKBUILD.&lt;br /&gt;
&lt;br /&gt;
= Version =&lt;br /&gt;
&lt;br /&gt;
This document assumes abuild for Alpine Edge.  For older releases of abuild, some of these features may not be available if you are using an older release.  A link to the implementation is linked for researchers and backporters.&lt;br /&gt;
&lt;br /&gt;
For more information see [[APKBUILD_versions]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Papiris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=25476</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=25476"/>
		<updated>2023-11-08T22:26:17Z</updated>

		<summary type="html">&lt;p&gt;Papiris: Add explanation of Maintainer, user defined variable&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;APKBUILDs are the scripts that are created in order to build Alpine packages using the [[abuild]] tool.&lt;br /&gt;
&lt;br /&gt;
See [[aports]] for details on Alpine&#039;s official ports repository.&lt;br /&gt;
&lt;br /&gt;
This page is intended to serve as a reference for creating APKBUILDs; if this is your first time creating a package for Alpine Linux, please see [[Creating an Alpine package]].&lt;br /&gt;
&lt;br /&gt;
= Legend =&lt;br /&gt;
The following notes will assist you in understanding this document.&lt;br /&gt;
&lt;br /&gt;
In description text:&lt;br /&gt;
* If a variable is not prefixed with a &#039;&#039;$&#039;&#039;, it will be represented by italics (i.e., &#039;&#039;srcdir&#039;&#039; ).&lt;br /&gt;
* Functions will also be represented by italics, but will also end with a pair of parentheses (i.e., &#039;&#039;build()&#039;&#039; ).&lt;br /&gt;
* Shell commands will be represented &amp;lt;code&amp;gt;like this&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Variables =&lt;br /&gt;
{{Note|Variables that contain a path (e.g. &#039;&#039;$srcdir&#039;&#039; and &#039;&#039;$pkgdir&#039;&#039;) should always be quoted using double quotes (i.e., &#039;&#039;&amp;quot;$srcdir&amp;quot;&#039;&#039;).  This is done to prevent things from breaking, should the user have the APKBUILD in a directory path that contains spaces.}}&lt;br /&gt;
{{Note|All arbitrary variable and function names should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (for example, &#039;&#039;_luaversions&#039;&#039;).}}&lt;br /&gt;
&lt;br /&gt;
These variables are all well documented in &amp;lt;code&amp;gt;man 5 APKBUILD&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== abuild-defined variables ==&lt;br /&gt;
The following variables are defined by abuild:&lt;br /&gt;
&lt;br /&gt;
==== startdir ====&lt;br /&gt;
: The directory where the APKBUILD script is.&lt;br /&gt;
==== srcdir ====&lt;br /&gt;
: The directory where sources, from the &#039;&#039;source&#039;&#039; variable, are downloaded to and unpacked to.&lt;br /&gt;
==== pkgdir ====&lt;br /&gt;
: This directory should receive the files for the main package.  For example, a normal [https://en.wikipedia.org/wiki/GNU_Autotools autotools] package would have &amp;lt;code&amp;gt;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&amp;lt;/code&amp;gt; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
==== subpkgdir ====&lt;br /&gt;
: This directory should receive the files for a subpackage. This variable should only be used from subpackage functions.&lt;br /&gt;
==== builddir ====&lt;br /&gt;
: This variable should point to the directory inside the &#039;&#039;srcdir&#039;&#039; where the main package source is unpacked.  This is typically &#039;&#039;$srcdir/$pkgname-$pkgver&#039;&#039;.  It’s used by the default &#039;&#039;prepare()&#039;&#039; function as a working directory when applying patches.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
==== Maintainer ====&lt;br /&gt;
: Name and email address of the maintainer of the project (not your package).&lt;br /&gt;
A well-formatted example is &#039;&#039;&#039;# Maintainer: John Snow &amp;lt;john_snow@thewall.net&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== arch ====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one or several seperated by whitespace of: &#039;&#039;&#039;[[x86]], [[x86_64]], [[armv7]], [[armhf]], [[aarch64]], [[ppc64le]], [[s390x]], [[riscv64]], all&#039;&#039;&#039;, or &#039;&#039;&#039;noarch&#039;&#039;&#039;, where &#039;&#039;&#039;all&#039;&#039;&#039; means all architectures, and &#039;&#039;&#039;noarch&#039;&#039;&#039; means it&#039;s architecture-independent (e.g., a pure-python package). Architectures can be negated using the ! character to exclude them from the list of supported architectures. E.g. &#039;&#039;&#039;arch=&amp;quot;all !ppc64le&amp;quot;&#039;&#039;&#039; means that the package is allowed to be built on all architectures but the ppc64le architecture.&lt;br /&gt;
: {{Tip|To determine if your APKBUILD can use &#039;&#039;&#039;noarch&#039;&#039;&#039;: First specify &#039;&#039;&#039;all&#039;&#039;&#039; and then build the package by executing &amp;lt;code&amp;gt;abuild -r&amp;lt;/code&amp;gt;.  Watch the output towards the end for warnings saying that &#039;&#039;&#039;noarch&#039;&#039;&#039; can be used.  If the main package and all subpackages, if you have any subpackages, give a warning saying that &#039;&#039;&#039;noarch&#039;&#039;&#039; can be used, then you can use &#039;&#039;&#039;noarch&#039;&#039;&#039;.}}&lt;br /&gt;
&lt;br /&gt;
==== depends ====&lt;br /&gt;
: Run-time dependency package(s) that are not shared-object dependencies.  Shared objects dependencies are auto-detected and should not be specified here. To specify a conflicting package, add the package name prefixed with a &#039;!&#039;.&lt;br /&gt;
&lt;br /&gt;
==== depends_dev ====&lt;br /&gt;
: Run-time dependency package(s) for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; subpackage.&lt;br /&gt;
&lt;br /&gt;
: {{Note|From ncopa on IRC: To find out if you need to add a package to depends_dev have a look at *requires* in usr/lib/pkgconfig/*.pc. With libtool it gets more complicated, but we should delete the .la files. Also check if there are any  /usr/bin/*-configure #!/bin/bash #!/usr/bin/perl or Python. Sometimes scripts or similar are generated at build time (i.e autoconf automake) then you normally don&#039;t need add those to depends_dev. You can also just add all -dev makedepends to depends_dev but it will slow the build process a little bit (more build dependencies).}}&lt;br /&gt;
&lt;br /&gt;
==== depends_doc ====&lt;br /&gt;
: Run-time dependency package(s) for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; subpackage.&lt;br /&gt;
&lt;br /&gt;
==== depends_openrc ====&lt;br /&gt;
: Run-time dependency package(s) for the &#039;&#039;&#039;$pkgname-openrc&#039;&#039;&#039; subpackage.&lt;br /&gt;
&lt;br /&gt;
==== depends_libs ====&lt;br /&gt;
: Run-time dependency package(s) for the &#039;&#039;&#039;$pkgname-libs&#039;&#039;&#039; subpackage.&lt;br /&gt;
&lt;br /&gt;
==== depends_static ====&lt;br /&gt;
: Run-time dependency package(s) for the &#039;&#039;&#039;$pkgname-static&#039;&#039;&#039; subpackage.&lt;br /&gt;
&lt;br /&gt;
==== checkdepends ====&lt;br /&gt;
: Dependencies that are only required during the check phase, they are only installed if the check option is enabled&lt;br /&gt;
&lt;br /&gt;
==== giturl ====&lt;br /&gt;
:Git repository from which &amp;lt;code&amp;gt;abuild checkout&amp;lt;/code&amp;gt; checks out. You can checkout a specific branch in git by adding &amp;lt;code&amp;gt;-b $branch&amp;lt;/code&amp;gt;.&lt;br /&gt;
==== install ====&lt;br /&gt;
: There are 6 different types of install scripts.  Install scripts are named &#039;&#039;&#039;$pkgname.action&#039;&#039;&#039;, where &#039;&#039;&#039;action&#039;&#039;&#039; can be:  &#039;&#039;&#039;pre-install, post-install, pre-upgrade, post-upgrade, pre-deinstall&#039;&#039;&#039;, or &#039;&#039;&#039;post-deinstall&#039;&#039;&#039;.  For example, if &#039;&#039;pkgname&#039;&#039; is set to &#039;&#039;&#039;mypackage&#039;&#039;&#039; and &#039;&#039;install&#039;&#039; is set to &#039;&#039;&#039;$pkgname.post-install&#039;&#039;&#039;, then a script named &#039;&#039;&#039;mypackage.post-install&#039;&#039;&#039; must exist along-side the APKBUILD.&lt;br /&gt;
&amp;lt;blockquote&amp;gt;{{Note|Always use &amp;lt;code&amp;gt;/bin/sh&amp;lt;/code&amp;gt; for the command-line interpreter on the [https://en.wikipedia.org/wiki/Shebang_%28Unix%29 shebang line] of your install scripts.}}&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following are the different types of install scripts in detail:&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-install =====&lt;br /&gt;
: This script is executed &#039;&#039;before installing&#039;&#039; the package.  Typical use is when the package needs a group and a user to be created. For example:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
addgroup -S clamav 2&amp;gt;/dev/null&lt;br /&gt;
adduser -S -D -H -s /sbin/nologin -G clamav -g clamav clamav 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
{{Note|If the script exits with a failure (e.g., if the user already exists), the package will not be installed and &amp;lt;code&amp;gt;apk&amp;lt;/code&amp;gt; will exit with failure, hence the &amp;lt;code&amp;gt;exit 0&amp;lt;/code&amp;gt; at the end.}}&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-install =====&lt;br /&gt;
: This script is executed &#039;&#039;after installing&#039;&#039; the package.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;before upgrading/downgrading/reinstalling&#039;&#039; the package. Note that exiting with failure will not cause apk to exit with failure, but will mark the package as broken.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;after upgrading/downgrading/reinstalling&#039;&#039; the package.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-deinstall =====&lt;br /&gt;
: This script is executed &#039;&#039;before uninstalling&#039;&#039; the package.&lt;br /&gt;
: {{Note|If the script exits with failure, &amp;lt;code&amp;gt;apk&amp;lt;/code&amp;gt; will not uninstall the package.}}&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-deinstall =====&lt;br /&gt;
: This script is executed &#039;&#039;after uninstalling&#039;&#039; the package.&lt;br /&gt;
&lt;br /&gt;
==== install_if ====&lt;br /&gt;
:install_if can be used when a package needs to be installed when some packages are already installed or are in the dependency tree. It works in reverse to the &#039;&#039;recommends&#039;&#039; feature, that other package managers provide.&lt;br /&gt;
&lt;br /&gt;
: Typically this is used in a subpackage that should provide files which make sense with another package. For example:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
subpackages=&amp;quot;$pkgname-bash-completion:bashcomp:noarch&amp;quot;&lt;br /&gt;
...&lt;br /&gt;
bashcomp() {&lt;br /&gt;
	pkgdesc=&amp;quot;Bash completions for $pkgname&amp;quot;&lt;br /&gt;
	install_if=&amp;quot;$pkgname=$pkgver-r$pkgrel bash-completion&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	install -Dm644 &amp;quot;$builddir&amp;quot;/doc/bash_completion/aria2c \&lt;br /&gt;
		&amp;quot;$subpkgdir&amp;quot;/usr/share/bash-completion/completions/_aria2c&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From the aria2c APKBUILD. Note that the custom bashcomp() function is only necessary, because the files are not in /usr/share/bash-completion.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:In general, install_if should only be used with &#039;&#039;&#039;at least one versioned constraint&#039;&#039;&#039;. Otherwise, a package that was implicitly installed by install_if and then removed from the binary repositories, will not get purged with &amp;lt;code&amp;gt;apk upgrade&amp;lt;/code&amp;gt;. [https://gitlab.alpinelinux.org/alpine/apk-tools/-/issues/10720#note_121298]&lt;br /&gt;
&lt;br /&gt;
==== license ====&lt;br /&gt;
: License(s) for the package, for example &amp;lt;code&amp;gt;GPL-3.0-or-later&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;BSD-2-Clause&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;MIT&amp;lt;/code&amp;gt; [[Creating_an_Alpine_package#license|(details)]].&lt;br /&gt;
&lt;br /&gt;
==== makedepends ====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
==== md5sums/sha256sums/sha512sums ====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated and updated by executing &amp;lt;code&amp;gt;abuild checksum&amp;lt;/code&amp;gt; and should be the last item in the APKBUILD.&lt;br /&gt;
&lt;br /&gt;
New packages should use only sha512sums.&lt;br /&gt;
&lt;br /&gt;
==== options ====&lt;br /&gt;
: Build-time options for the package.&lt;br /&gt;
&lt;br /&gt;
: {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Option&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!archcheck&amp;lt;/code&amp;gt;&lt;br /&gt;
| Do not try to verify that the architecture of the binary files is the same architecture as abuild should build for. One example where it makes sense to set this are packages with firmware files, that get executed on another CPU (such as WiFi firmware).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!check&amp;lt;/code&amp;gt;&lt;br /&gt;
| Do not try to run the &amp;lt;code&amp;gt;check()&amp;lt;/code&amp;gt; function. Please always add a short comment after the &amp;lt;code&amp;gt;!check&amp;lt;/code&amp;gt; about why it&#039;s disabled. [https://github.com/alpinelinux/aports/pull/2322#discussion_r142545300] Creating a very simple check function, that calls &amp;lt;code&amp;gt;program --version&amp;lt;/code&amp;gt; is worse than disabling tests completely because it gives the false impression that the package is thoroughly tested with the testsuite from upstream. [https://github.com/alpinelinux/aports/pull/7326#discussion_r278797457]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;checkroot&amp;lt;/code&amp;gt;&lt;br /&gt;
| Specifies that the package&#039;s test suite will be run in &#039;&#039;fakeroot&#039;&#039;. This is necessary for some test suites which fail when run as non-root.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;net&amp;lt;/code&amp;gt;&lt;br /&gt;
| Allows network access when run in &#039;&#039;rootbld&#039;&#039;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!strip&amp;lt;/code&amp;gt;&lt;br /&gt;
| Avoid stripping symbols from binaries.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;suid&amp;lt;/code&amp;gt;&lt;br /&gt;
| Allow [https://en.wikipedia.org/wiki/Setuid setuid] binaries.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!tracedeps&amp;lt;/code&amp;gt;&lt;br /&gt;
| Do not automatically find dependencies (e.g. by using &amp;lt;code&amp;gt;ldd&amp;lt;/code&amp;gt; to find dynamic libraries, which the resulting binary links against).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;chmod-clean&amp;lt;/code&amp;gt;&lt;br /&gt;
| Make all files writable in the src/ directory. Useful for packages that make files read-only in the process of building packages (go modules).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;toolchain&amp;lt;/code&amp;gt;&lt;br /&gt;
| Don&#039;t warn when g++ is in makedepends&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!dbg&amp;lt;/code&amp;gt;&lt;br /&gt;
| Don&#039;t create debugging subpackage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ldpath-recursive&amp;lt;/code&amp;gt;&lt;br /&gt;
| Scan directories recursively when creating .so providers&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!spdx&amp;lt;/code&amp;gt;&lt;br /&gt;
| Do not check if the license= field has a SPDX compliant license&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;textrels&amp;lt;/code&amp;gt;&lt;br /&gt;
| Don&#039;t error out when text relocations are found&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;charset.alias&amp;lt;/code&amp;gt;&lt;br /&gt;
| Don&#039;t error out if /usr/lib/charset.alias is found&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;libtool&amp;lt;/code&amp;gt;&lt;br /&gt;
| Don&#039;t delete libtool .la files&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;!fhs&amp;lt;/code&amp;gt;&lt;br /&gt;
| Don&#039;t enforce checks on path that follow the FHS&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== pkgdesc ====&lt;br /&gt;
: A brief, one-line description of what the package does.&lt;br /&gt;
&lt;br /&gt;
: Here&#039;s an example from the OpenSSH client package:&lt;br /&gt;
: &amp;lt;pre&amp;gt;pkgdesc=&amp;quot;Port of OpenBSD&#039;s free SSH release - client&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
==== pkggroups ====&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in the &#039;&#039;&#039;[[APKBUILD Reference#.24pkgname.pre-install|$pkgname.pre-install]]&#039;&#039;&#039; script, so that the system group(s) are also created prior to package installation for run-time use.&lt;br /&gt;
==== pkgname ====&lt;br /&gt;
: The name of the package.  All letters should be lowercase.&lt;br /&gt;
: {{Note|When creating an APKBUILD of a module or library for another package, we use some common package prefixes, such as: &#039;&#039;lua-&#039;&#039;, &#039;&#039;perl-&#039;&#039;, &#039;&#039;php-&#039;&#039;, and &#039;&#039;py3-&#039;&#039;.  Search aports for other common prefixes.}}&lt;br /&gt;
&lt;br /&gt;
==== pkgrel ====&lt;br /&gt;
: Alpine package release number.  Starts at 0 (zero).  Always increment &#039;&#039;pkgrel&#039;&#039; when making updates to an aport; reset &#039;&#039;pkgrel&#039;&#039; to 0 (zero) when incrementing &#039;&#039;pkgver&#039;&#039;.&lt;br /&gt;
==== pkgusers ====&lt;br /&gt;
: System user(s) to be created during build-time.  System user(s) should also be created in the &#039;&#039;&#039;[[APKBUILD Reference#.24pkgname.pre-install|$pkgname.pre-install]]&#039;&#039;&#039; script, so that the system user(s) are also created prior to package installation for run-time use.&lt;br /&gt;
==== pkgver ====&lt;br /&gt;
: The version of the software being packaged. Format for valid versions: &amp;lt;code&amp;gt;{digit}{.digit}...{letter}{_suf{#}}...{-r#}&amp;lt;/code&amp;gt; [https://git.alpinelinux.org/cgit/apk-tools/tree/src/version.c#n17]&lt;br /&gt;
: A Suffix &amp;lt;code&amp;gt;suf&amp;lt;/code&amp;gt; in the above format can be one of the following to indicate that the release is &#039;&#039;less recent&#039;&#039; than the version without the suffix: &amp;lt;code&amp;gt;alpha&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;beta&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;pre&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;rc&amp;lt;/code&amp;gt; [https://git.alpinelinux.org/cgit/apk-tools/tree/src/version.c#n75]&lt;br /&gt;
: These are for indicating &#039;&#039;more recent&#039;&#039; releases: &amp;lt;code&amp;gt;cvs&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;svn&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;git&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;hg&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;p&amp;lt;/code&amp;gt; [https://git.alpinelinux.org/cgit/apk-tools/tree/src/version.c#n76]&lt;br /&gt;
: All other suffices are invalid. To package a specific git commit, the date of the commit gets appended to the latest release, e.g. &amp;lt;code&amp;gt;1.0.0_git20180204&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== provides ====&lt;br /&gt;
: List of package names (and optionally version info) this package provides.&lt;br /&gt;
&lt;br /&gt;
: If package with a version is provided (provides=&#039;foo=1.2&#039;) apk will consider it as an alternate name and it will automatically consider the package for installation by the alternate name, and conflict with other packages having the same name, or provides.&lt;br /&gt;
&lt;br /&gt;
: If version is not provided (provides=&#039;foo&#039;), apk will consider it as virtual package name. Several package with same non-versioned provides can be installed simultaneously. However, none of them will be installed by default when requested by the virtual name - instead, error message is given and user is asked to choose which package providing the virtual name should be installed.&lt;br /&gt;
==== provider_priority ====&lt;br /&gt;
: A numeric value which is used by apk-tools to break ties when choosing a virtual package to satisfy a dependency. Higher values have higher priority. The primary use case is to specify the primary package that satisfies a virtual (provider).&lt;br /&gt;
==== replaces ====&lt;br /&gt;
: Allow this package to be installed at the same time as the listed packages, even if they have conflicting files. The files from this package will override (&amp;quot;take over&amp;quot;) the conflicting files.&lt;br /&gt;
&lt;br /&gt;
: This can be used to override config files with &amp;quot;policy packages&amp;quot; [https://gitlab.alpinelinux.org/alpine/apk-tools/-/commit/89d003f8c2e5a92655ee778f7bfa5c0e85ddbed4].&lt;br /&gt;
&lt;br /&gt;
: Another use case is renaming packages (or moving files from one package to another): &amp;quot;replaces&amp;quot; will avoid the file conflict error that apk reports if it happens to install the new package before uninstalling the old package [https://gitlab.alpinelinux.org/alpine/apk-tools/-/issues/10724#note_132872].&lt;br /&gt;
&lt;br /&gt;
: A common misconception is that &amp;quot;replaces&amp;quot; is used to replace packages (like in [https://wiki.archlinux.org/index.php/PKGBUILD#replaces PKGBUILD]). This is not the case, it is only for solving file conflicts. To let apk consider installing one package instead of another one, refer to [[#provides|provides]] (with the version).&lt;br /&gt;
&lt;br /&gt;
==== replaces_priority ====&lt;br /&gt;
: The priority of the replaces. If multiple packages replace files of each other, then the package with the highest &#039;&#039;replaces_priority&#039;&#039; will win.&lt;br /&gt;
&lt;br /&gt;
==== source ====&lt;br /&gt;
: The source variable is not only used to list the remote source files to fetch, it is also used to list the local files that abuild will need in order to build the apk. Examples of such local files include: init.d files, conf.d files, install files (see [[APKBUILD Reference#install|install variable]]), patches, and all other necessary files.&lt;br /&gt;
&lt;br /&gt;
: Here are few things to note:&lt;br /&gt;
&lt;br /&gt;
:* When you are finished adding local and/or remote files to &#039;&#039;source&#039;&#039;, you can execute the following command to add their checksums to the APKBUILD file:&lt;br /&gt;
:: {{Cmd|abuild checksum}}&lt;br /&gt;
:: {{Note|When later updating the content of &#039;&#039;source&#039;&#039;, or updating a file that is listed in &#039;&#039;source&#039;&#039;, you must also update their checksums again with the same command.}}&lt;br /&gt;
&lt;br /&gt;
:* When the remote file is hosted at SourceForge, it&#039;s best to specify the special mirrors link used by SourceForge:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;http://downloads.sourceforge.net/software/software-$pkgver.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
:: (or similar depending on the package).&lt;br /&gt;
&lt;br /&gt;
:* You can set target filename (eg &#039;save as...&#039;) by prefixing the URI with &#039;&#039;filename::&#039;&#039;. This is useful when the remote filename is not specified in the URI (ie, does not end in &#039;/software-1.0.tar.gz&#039;), such as:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;http://oss.example.org/?get=software&amp;amp;ver=1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
:: or when the filename is braindead, like githubs&#039; download tags:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;https://github.com/software/software/archive/v$pkgver.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
:: The above two examples needs a target filename prefix:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;$pkgname-$pkgver.tar.gz::http://oss.example.org/?get=software&amp;amp;ver=$pkgver&amp;lt;/pre&amp;gt;&lt;br /&gt;
:: and:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;$pkgname-$pkgver.tar.gz::https://github.com/software/software/archive/v$pkgver.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:* abuild currently supports the following protocols for remote file retrieval:&lt;br /&gt;
:** http&lt;br /&gt;
:** https&lt;br /&gt;
:** ftp&lt;br /&gt;
&lt;br /&gt;
:* abuild currently supports the following archive types/archive file extensions:&lt;br /&gt;
:** .tar (only in Alpine &amp;gt;= 2.5)&lt;br /&gt;
:** .tar.gz / .tgz&lt;br /&gt;
:** .tar.bz2&lt;br /&gt;
:** .tar.lz (only in Alpine &amp;gt;=3.7)&lt;br /&gt;
:** .tar.lzma&lt;br /&gt;
:** .tar.xz&lt;br /&gt;
:** .zip&lt;br /&gt;
&lt;br /&gt;
:* &amp;lt;code&amp;gt;source&amp;lt;/code&amp;gt; should only include variables that change often like &amp;lt;code&amp;gt;pkgver&amp;lt;/code&amp;gt; or a commit ID. CI will warn you if you include &amp;lt;code&amp;gt;pkgname&amp;lt;/code&amp;gt; in source. Other variables like for example &amp;lt;code&amp;gt;_pkgname&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;_pyname&amp;lt;/code&amp;gt; do not belong in &amp;lt;code&amp;gt;source&amp;lt;/code&amp;gt; either.&lt;br /&gt;
&lt;br /&gt;
==== subpackages ====&lt;br /&gt;
: Subpackages built from this APKBUILD.  abuild will parse this variable and try to find a subpackage split function.  The split function must &#039;&#039;move&#039;&#039; files that do not belong in the main package, from &#039;&#039;$pkgdir&#039;&#039; to &#039;&#039;$subpkgdir&#039;&#039;.  Files and directories can also be &#039;&#039;copied&#039;&#039; from &#039;&#039;$startdir&#039;&#039; and &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: The split function can be specified in 1 of 3 different methods:&lt;br /&gt;
:# subpkgname:&#039;&#039;&#039;splitfunc&#039;&#039;&#039;&lt;br /&gt;
:# $pkgname-&#039;&#039;&#039;splitfunc&#039;&#039;&#039;&lt;br /&gt;
:# &#039;&#039;&#039;splitfunc&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
: {{Note|Split function names &#039;&#039;&#039;cannot&#039;&#039;&#039; use hyphens; use the first method above if the subpackage name contains a hyphen (-) character, like this: &#039;&#039;subpkg-name:subpkg_name&#039;&#039;, where &amp;lt;code&amp;gt;subpkg-name&amp;lt;/code&amp;gt; is the name of the &#039;&#039;&#039;subpackage&#039;&#039;&#039; and &amp;lt;code&amp;gt;subpkg_name&amp;lt;/code&amp;gt; is the name of the &#039;&#039;&#039;subpackage&#039;s split function&#039;&#039;&#039;.}}&lt;br /&gt;
&lt;br /&gt;
: {{Tip|For more information, see the [[APKBUILD_examples:Subpackages|Subpackages example]].}}&lt;br /&gt;
&lt;br /&gt;
==== triggers ====&lt;br /&gt;
: Apk-tools can &amp;quot;monitor&amp;quot; directories and execute a trigger if any package installed/uninstalled any file in the monitored dir. The triggers are always executed after the apk action (install, uninstall, upgrade).&lt;br /&gt;
&lt;br /&gt;
: The triggers are specified in the format: &#039;&#039;scriptname&#039;&#039;=&#039;&#039;pathlist&#039;&#039; where &#039;&#039;scriptname&#039;&#039; is the (sub)package name + .trigger suffix and pathlist is : separated list of the dirs to monitor.&lt;br /&gt;
&lt;br /&gt;
: The &#039;&#039;&#039;triggers&#039;&#039;&#039; variable must include the triggers for subpackages too if they have any.&lt;br /&gt;
&lt;br /&gt;
: It is possible to use wildcards (*) in the dir list.&lt;br /&gt;
&lt;br /&gt;
==== url ====&lt;br /&gt;
: The homepage for the package.  This is to help users find upstream documentation and other information regarding the package.&lt;br /&gt;
&lt;br /&gt;
==== langdir ====&lt;br /&gt;
: Path to where the language files are located for the &#039;&#039;&#039;-lang&#039;&#039;&#039; subpackage, defaults to &#039;&#039;&#039;/usr/share/locale&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== pcprefix ====&lt;br /&gt;
: Prefix all provides derived from parsing pkg-config Requires: with the value in this variable, example: &#039;&#039;&#039;&#039;pcprefix=&amp;quot;foo:&amp;quot;&#039;&#039;&#039; will produce &#039;&#039;&#039;pc:foo:bar&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== sonameprefix ====&lt;br /&gt;
: Prefix all provides derived from parsing shared objects with the value in this variable, example: &#039;&#039;&#039;sonameprefix=&amp;quot;foo&amp;quot;&#039;&#039;&#039; will produce &#039;&#039;&#039;so:foo:bar.so.X&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions that are not &#039;&#039;prepare()&#039;&#039;, &#039;&#039;build()&#039;&#039;, &#039;&#039;check()&#039;&#039; and &#039;&#039;package()&#039;&#039; should consider the current working directory as undefined, and should therefore use the [[APKBUILD Reference#abuild-defined_variables|abuild-defined directory variables]] to their advantage.}}&lt;br /&gt;
&lt;br /&gt;
 sanitycheck() -&amp;gt; clean()-&amp;gt; fetch() -&amp;gt; verify() -&amp;gt; unpack() -&amp;gt; prepare() -&amp;gt; mkusers() -&amp;gt; build() -&amp;gt; check() -&amp;gt; package() -&amp;gt; subpackages() -&amp;gt; language packs -&amp;gt; apk -&amp;gt; cleanup()&lt;br /&gt;
&lt;br /&gt;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden, but it is strongly discouraged on code review for some functions:&lt;br /&gt;
&lt;br /&gt;
==== fetch() ====&lt;br /&gt;
: Downloads remote sources listed in &#039;&#039;source&#039;&#039; to &#039;&#039;SRCDEST&#039;&#039; (&#039;&#039;SRCDEST&#039;&#039; is configured in &#039;&#039;/etc/abuild.conf&#039;&#039;) and creates symlinks in &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
==== unpack() ====&lt;br /&gt;
: unpack() will call default_unpack().&lt;br /&gt;
&lt;br /&gt;
: [https://github.com/alpinelinux/abuild/blob/v3.1.0/abuild.in#L403 default_unpack()] unpacks .tar, .tgz, .tar.gz, .tar.lz (only available in Alpine &amp;gt;=3.7), .tar.bz2, .tar.lzma, .tar.xz, and .zip archives from a symlink in &#039;&#039;$srcdir&#039;&#039; associated with &#039;&#039;$SRCDEST&#039;&#039; (or distfiles folder) resulting in an unpacked folder in &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== dev() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package is used to collect developer files and folders for use in other packages in the compilation process nothing more.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call its internal &#039;&#039;dev()&#039;&#039; function, which in turn calls default_dev().&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;[https://github.com/alpinelinux/abuild/blob/v3.1.0/abuild.in#L1605 default_dev()]&#039;&#039; will move any &#039;&#039;include&#039;&#039; folder and folders containing &#039;&#039;*.[acho]&#039;&#039; (static archive, c source, c header file, object file), &#039;&#039;*.prl&#039;&#039; file extension patterns in &#039;&#039;&amp;quot;$pkgdir&amp;quot;/{lib,usr}&#039;&#039; to &#039;&#039;&amp;quot;$subpkgdir&amp;quot;/{lib,usr}&#039;&#039; recursively; and &#039;&#039;*.so&#039;&#039; files from &#039;&#039;&amp;quot;$pkgdir&amp;quot;/{lib,usr/lib}&#039;&#039; to &#039;&#039;&amp;quot;$subpkgdir&amp;quot;/{lib,usr/lib}&#039;&#039;.  It will also scan and move &#039;&#039;usr/{include,lib/{pkgconfig,cmake,qt*/mkspecs},share/{aclocal,gettext,vala/vapi,gir-[0-9]*,qt*/mkspecs},bin/*-config}}&#039;&#039; developer only folders in &#039;&#039;$pkgdir&#039;&#039; and transfer them to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: In general, default_dev() will support packages that share pkg-config, C programming language API, shared and static libraries, Autotools, gettext, Vala programming language bindings, Python GObject introspection, a provided custom pkg-config like command (*-config), Qt, and CMake.  If you have packages that have C++, other languages, other build system, etc; you need to manually move those developer files only if they are to be used in other packages.&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;&#039;Important&#039;&#039;&#039;: For default_dev() to be called as in no dev(), you need to explicitly add subpackages=&amp;quot;$pkgname-dev&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== doc() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package whose job is only to collect documentation folders from $pkgdir nothing more.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call its internal &#039;&#039;doc()&#039;&#039; function, which in turn calls default_doc().&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;[https://github.com/alpinelinux/abuild/blob/v3.1.0/abuild.in#L1519 default_doc()]&#039;&#039; will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/{doc,man,info,html,sgml,licenses,gtk-doc,ri,help}&#039;&#039; to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: Overriding this function is strongly discouraged.  Packaging docs should be done in the package() function while letting abuild automatically collect the doc folders.&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;&#039;Important&#039;&#039;&#039;: For default_doc() to be called as in no doc(), you need to explicitly add subpackages=&amp;quot;$pkgname-doc&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== openrc() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-openrc&#039;&#039;&#039; package whose job is to collect OpenRC service files that are in /etc/init.d and /etc/conf.d.&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;[https://github.com/alpinelinux/abuild/blob/v3.1.0/abuild.in#L1661 default_openrc()]&#039;&#039; will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/etc/{conf,init}.d&#039;&#039; to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: Overriding this function is strongly discouraged. Packaging OpenRC service definitions should be in the package() function while letting abuild automatically collect the openrc folders.&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;&#039;Important&#039;&#039;&#039;: for default_openrc() to be called as in no openrc(), you need to explicitly add subpackages=&amp;quot;$pkgname-openrc&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== static() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-static&#039;&#039;&#039; package whose job is to collect static libraries that are stored in /lib and /usr/lib.&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;[https://github.com/alpinelinux/abuild/blob/v3.4.0_rc4/abuild.in#L1748 default_static()]&#039;&#039; will move all static libraries (files ending with .a) from &#039;&#039;&amp;quot;$pkgdir&amp;quot;/lib&#039;&#039; and &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/lib&#039;&#039; to their equivalents in &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: Overriding this function is strongly discouraged. Packaging static libraries should be done in the package() function while letting abuild automatically collect the static libraries.&lt;br /&gt;
&lt;br /&gt;
: &#039;&#039;&#039;Important&#039;&#039;&#039;: for default_static() to be called as in no static(), you need to explicitly add subpackages=&amp;quot;$pkgname-static&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== snapshot() ====&lt;br /&gt;
: &#039;&#039;&#039;Optional&#039;&#039;&#039;.  For live APKBUILDs or those with a _cvs, _svn, _git, _hg in their version number, you should create a snapshot function only if there is no download link to an archive file (.zip, .tar.gz, ...) to the commit/hash/tag.  The purpose of the snapshot function is to create an archive of the source code so that the package source code is deterministic, and it doesn&#039;t waste time to fetch the source code but bypasses the download step after snapshotting.  Those that download the source code from a git repository will follow head or the latest change to the source code.  It is better to archive the source code as a zip / tar.gz / tar.bz2 up to the commit or the tag which you are trying to build a package.  If it is not deterministic or not every part of the code frozen in time for every dependency and the main project, then the patches will fail or the package may fail to compile when you revisit the package months or years to backport a patch.&lt;br /&gt;
&lt;br /&gt;
: The default [https://github.com/alpinelinux/abuild/blob/v3.1.0/abuild.in#L2310 snapshot()] function has variables associated with it:&lt;br /&gt;
:* $disturl - the base-url of the place to autoupload the snapshot&lt;br /&gt;
:* $svnurl - Subversion repository &lt;br /&gt;
:* $giturl - Git repository&lt;br /&gt;
&lt;br /&gt;
: The default snapshot() can only support one repository.  It is better to override it if there are multiple repositories involved in your package.  CVS, Mercurial (hg), and alternative version control systems must override the default snapshot().&lt;br /&gt;
&lt;br /&gt;
: See [[APKBUILD_examples:Git_checkout]] to how to use it with git.  It takes 2-3 general steps.  Clone the repository; check it out at a specific revision/commit or tag; then you use an archiver to dump it in the &#039;&#039;$SRCDEST&#039;&#039; variable which points to the distfiles folder and the base path to the full path to the archive that you want to create.  You do this for every internal dependency that the package pulls.&lt;br /&gt;
&lt;br /&gt;
: After you have created your snapshot function, you use &amp;lt;code&amp;gt;abuild snapshot&amp;lt;/code&amp;gt; to run it.  &lt;br /&gt;
&lt;br /&gt;
: The archives produced by the snapshot will be saved in &#039;&#039;/var/cache/distfiles&#039;&#039; or whatever you set for &#039;&#039;$SRCDEST&#039;&#039;.  You may need to create symlinks to the archive if the archive is not saved to the Alpine server.&lt;br /&gt;
&lt;br /&gt;
: After you snapshot it, you need to produce the checksums with &amp;lt;code&amp;gt;abuild checksum&amp;lt;/code&amp;gt; to use it in the APKBUILD creation process.&lt;br /&gt;
&lt;br /&gt;
: This feature is available since Alpine &amp;gt;=2.6.&lt;br /&gt;
&lt;br /&gt;
==== default_prepare() ====&lt;br /&gt;
&lt;br /&gt;
:  Before build preparation it handles set of patches inside &amp;lt;code&amp;gt;$srcdir&amp;lt;/code&amp;gt; and prints failed ones.&lt;br /&gt;
&lt;br /&gt;
== User-defined functions ==&lt;br /&gt;
The following functions should be defined by the user: &lt;br /&gt;
&lt;br /&gt;
==== prepare() ====&lt;br /&gt;
: {{note|Please adjust old APKBUILDs, which still have a &#039;&#039;prepare()&#039;&#039; function that does the same as the &#039;&#039;default_prepare()&#039;&#039; when you edit them anyway.}}&lt;br /&gt;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here. When you don&#039;t specify a custom &#039;&#039;prepare()&#039;&#039;, the built-in &#039;&#039;default_prepare()&#039;&#039; from abuild will be used. It applies patches already (always prepare them in the &amp;lt;code&amp;gt;-p1&amp;lt;/code&amp;gt; format), so &#039;&#039;&#039;usually it makes sense to not create a custom &#039;&#039;prepare()&#039;&#039; function at all!&#039;&#039;&#039; If you do create one, call &#039;&#039;default_prepare()&#039;&#039; inside it:&lt;br /&gt;
&lt;br /&gt;
: Before default_prepare gets called, you can define &#039;&#039;patch_args&#039;&#039; to supply the argument to the patch command in global scope then throw away prepare() so it is unnecessary to use the old template code floating around to patch.  patch_args and autopatching is only available in Alpine &amp;gt;=3.4.  See [[Creating_an_Alpine_package#Patches]] to fix the patch that uses a different patch level (-pX).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
prepare() {&lt;br /&gt;
    default_prepare&lt;br /&gt;
    # your custom code here&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== build() ====&lt;br /&gt;
: &#039;&#039;&#039;Required.&#039;&#039;&#039;  This is the compilation stage.  This function will be called as the current user (unless the &#039;&#039;package()&#039;&#039; function is missing - for compatibility reasons).  If no compilation is needed, this function can contain a single line: &amp;lt;code&amp;gt;return 0&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
: To enable or disable CFLAGS, CXXFLAGS, CMake with option, or configure option per arch, use the CARCH variable:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
local cmakeoptions=&lt;br /&gt;
case &amp;quot;$CARCH&amp;quot; in&lt;br /&gt;
        aarch64*|arm*|ppc64le|x86|s390x) cmakeoptions=&amp;quot;$cmakeoptions -DWITH_OPENMP=OFF&amp;quot; ;;&lt;br /&gt;
        x86_64)                          cmakeoptions=&amp;quot;$cmakeoptions -DWITH_OPENMP=ON&amp;quot; ;;&lt;br /&gt;
        *)                               msg &amp;quot;Unable to determine architecture from (CARCH=$CARCH)&amp;quot; ; return 1 ;;&lt;br /&gt;
esac&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
: The block can be used in other parts of the APKBUILD even in global.&lt;br /&gt;
&lt;br /&gt;
==== check() ====&lt;br /&gt;
: &#039;&#039;&#039;Required if functionality exists.&#039;&#039;&#039; This function is called right after the build stage.  It should check that the packaged thing is actually working, typically by running (integration) tests, if provided by upstream.  If there’s no (easy) way how to test the package, you can declare that it does not want to use &#039;&#039;check()&#039;&#039; by adding &amp;quot;!check&amp;quot; into the &#039;&#039;options&#039;&#039; variable (&amp;lt;code&amp;gt;options=&amp;quot;!check&amp;quot;&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
: default_check() does nothing.  You need to manually explicitly call the unit tests or test suite yourself.  When you run the test, the program should return with an exit code of 0, indicating the tests were a success.  Unit tests or test suites will do feature tests, per function correctness check, fuzz testing, benchmarks.&lt;br /&gt;
&lt;br /&gt;
: A package may also require additional testing frameworks packages that are external dependencies.  You should add those to the &#039;&#039;checkdepends=&#039;&#039; in Alpine &amp;gt;=3.6 or &#039;&#039;makedepends=&#039;&#039; for older for backporters.  If the testing framework is not available, you need to create a package for it.  If it requires a specific version of a testing framework, consider making it an internal dependency or a new package with a package name containing the major and minor version number like the python packages.&lt;br /&gt;
&lt;br /&gt;
: Generally speaking, you should define the check functions for libraries, large programs like web browsers, or compilers and interpreters, cryptographic/security/anonymity stuff, mission critical stuff, PCI compliance/money/accounting software, server software with a lot of stakeholders or consumers.  Soon for the new policy change will have virtually &#039;&#039;&#039;all packages with testing capabilities be required to have a working and defined check() function&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: There are times when the unit tests do not work, just because the test itself is broken, new unimplemented feature, external factors not taken into consideration, unbundling path differences, breakage caused by ccache, missing test dependency or version mismatch dependency as in python2 vs python3, test scripts only work for particular language implementation like only supporting python2 but not python3 having used the 2to3 conversion script.  If a unit test is known not to work, you may need to patch it to omit that test or fix it; but, certain tests should not be disabled if it is important.  You may need to alter the references to uncompiled internal dependencies to work with the external dependencies instead.  For ccache, you can either disable it or remove it from the PATH environmental variable before running tests.&lt;br /&gt;
&lt;br /&gt;
{{Note|Tests for graphical applications and toolkits might work on a X11 user setup but will fail on the server unless run with xvfb-run.}}&lt;br /&gt;
&lt;br /&gt;
: If you don&#039;t add the &#039;&#039;check()&#039;&#039; and the &#039;&#039;options=&#039;&#039;, this is what you will see:&lt;br /&gt;
&lt;br /&gt;
  &amp;gt;&amp;gt;&amp;gt; WARNING: py-webtest*: APKBUILD does not run any tests!&lt;br /&gt;
    Alpine policy will soon require that packages have any relevant testsuites run during the build process.&lt;br /&gt;
    To fix, either define a check() function, or declare !check in $options to indicate the package does not have a testsuite.&lt;br /&gt;
&lt;br /&gt;
: If you do not do a check or disable it, you must state there is no testsuite in comment form (#) next to options=&amp;quot;!check&amp;quot; for the code reviewers.&lt;br /&gt;
&lt;br /&gt;
: To run test suite with autotools do:&lt;br /&gt;
&lt;br /&gt;
  make check&lt;br /&gt;
&lt;br /&gt;
: To run the test suite with python setuptools:&lt;br /&gt;
&lt;br /&gt;
  python2 setup.py test&lt;br /&gt;
  python3 setup.py test&lt;br /&gt;
&lt;br /&gt;
: For python it should be &#039;&#039;&#039;test&#039;&#039;&#039; not check.  Check for python setuptools will check the packaging metadata fields[https://docs.python.org/3/distutils/examples.html#checking-a-package] only but not run the unit tests.  There should be verbose output also.  The dependencies for the tests are found in test_require in the setup.py.&lt;br /&gt;
&lt;br /&gt;
: If it says &amp;lt;code&amp;gt;Ran 0 tests in 0.000s&amp;lt;/code&amp;gt; that is not acceptable.  check() will say it was good but it is not actually correct.  It needs to run the test suite with an alternative method like &amp;lt;code&amp;gt;tox -e py27,py36&amp;lt;/code&amp;gt; if you see a tox.ini file.&lt;br /&gt;
&lt;br /&gt;
: You want to do it for each implementation to ensure that the API calls are correct per implementation but ncopa said it was just fine with python3.&lt;br /&gt;
&lt;br /&gt;
: If there is a circular dependency for the checkdepends=, you need to disable the check and put the reason next to &amp;lt;code&amp;gt;options=&amp;quot;!check&amp;quot;&amp;lt;/code&amp;gt; that there is a circular dependency.  You should disable it for the package that package that is least important or least security risk.  The other solution is to make the conflicting dependency an internal dependency but making sure that it doesn&#039;t pull it at check time.  This way they can both preform tests properly.&lt;br /&gt;
&lt;br /&gt;
==== package() ====&lt;br /&gt;
: &#039;&#039;&#039;Required.&#039;&#039;&#039;  This is the packaging stage.  Here, the built application and support files should be installed into &#039;&#039;&#039;$pkgdir&#039;&#039;&#039;.  If this is a metapackage, this function can contain a single line: &amp;lt;code&amp;gt;mkdir -p &amp;quot;$pkgdir&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|Building in fakeroot will reduce performance for parallel builds dramatically.  It is for this reason that we split the build and package process into two separate functions.}}&lt;br /&gt;
&lt;br /&gt;
= Special Operators =&lt;br /&gt;
&lt;br /&gt;
== $pkgname~$pkgver ==&lt;br /&gt;
&lt;br /&gt;
Specifies a required &amp;lt;code&amp;gt;$pkgver&amp;lt;/code&amp;gt; for [[apk]] to satisfy the &amp;lt;code&amp;gt;$pkgname&amp;lt;/code&amp;gt; requirement. &amp;lt;code&amp;gt;~&amp;lt;/code&amp;gt; ignores revisions of the package version. For example &amp;lt;code&amp;gt;superd~0.6&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;$depends&amp;lt;/code&amp;gt; will ensure superd with package version 0.6 is installed as a run-time dependency for the package.&lt;br /&gt;
&lt;br /&gt;
== $pkgname&amp;gt;=$pkgver ==&lt;br /&gt;
&lt;br /&gt;
Specifies the installed package version must be greater than or equal to &amp;lt;code&amp;gt;$pkgver&amp;lt;/code&amp;gt; for [[apk]] to satisfy the &amp;lt;code&amp;gt;$pkgname&amp;lt;/code&amp;gt; requirement.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
The [[APKBUILD examples]] page will assist you in understanding how to create an APKBUILD.&lt;br /&gt;
&lt;br /&gt;
= Version =&lt;br /&gt;
&lt;br /&gt;
This document assumes abuild for Alpine Edge.  For older releases of abuild, some of these features may not be available if you are using an older release.  A link to the implementation is linked for researchers and backporters.&lt;br /&gt;
&lt;br /&gt;
For more information see [[APKBUILD_versions]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Papiris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Talk:APKBUILD_examples:Simple&amp;diff=25475</id>
		<title>Talk:APKBUILD examples:Simple</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Talk:APKBUILD_examples:Simple&amp;diff=25475"/>
		<updated>2023-11-08T22:15:48Z</updated>

		<summary type="html">&lt;p&gt;Papiris: Avoid empty MAINTAINER field in APKBUILD examples&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I find many examples of APKBUILDs with an empty MAINTAINER field, including this one.&lt;br /&gt;
I suggest we add an example person and email address to the maintainer field in this example, to show that it isn&#039;t supposed to be empty&lt;/div&gt;</summary>
		<author><name>Papiris</name></author>
	</entry>
</feed>