<?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=Mattx86</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=Mattx86"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Mattx86"/>
	<updated>2026-04-26T01:05:56Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/qwn:Enabling_ccache&amp;diff=5080</id>
		<title>User:Mattx86/qwn:Enabling ccache</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/qwn:Enabling_ccache&amp;diff=5080"/>
		<updated>2011-04-05T06:33:42Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&amp;quot;ccache is a compiler cache. It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again. Supported languages are C, C++, Objective-C and Objective-C++.&amp;quot;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To enable ccache, first install ccache:&lt;br /&gt;
{{Cmd|apk add ccache}}&lt;br /&gt;
&lt;br /&gt;
Next, add it to your path by placing the following in your &amp;lt;code&amp;gt;~/.profile&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;ash&amp;lt;/code&amp;gt;) or &amp;lt;code&amp;gt;~/.bash_profile&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt;).&lt;br /&gt;
&amp;lt;pre&amp;gt;export PATH=&amp;quot;/usr/lib/ccache/bin:$PATH&amp;quot;&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/qwn:Enabling_ccache&amp;diff=5079</id>
		<title>User:Mattx86/qwn:Enabling ccache</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/qwn:Enabling_ccache&amp;diff=5079"/>
		<updated>2011-04-05T04:33:23Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: Created page with &amp;quot;&amp;#039;&amp;#039;&amp;quot;ccache is a compiler cache. It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again. Supported languages are C,...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&amp;quot;ccache is a compiler cache. It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again. Supported languages are C, C++, Objective-C and Objective-C++.&amp;quot;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To enable ccache, first install ccache:&lt;br /&gt;
{{Cmd|apk add ccache}}&lt;br /&gt;
&lt;br /&gt;
Next, add it to your path by placing the following in your &amp;lt;code&amp;gt;~/.profile&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;ash&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;~/.bash_profile&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;pre&amp;gt;export PATH=&amp;quot;/usr/lib/ccache/bin:$PATH&amp;quot;&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86&amp;diff=5078</id>
		<title>User:Mattx86</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86&amp;diff=5078"/>
		<updated>2011-04-05T04:22:31Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* My personal pages:&lt;br /&gt;
** [[User:Mattx86/Bash Profile]]&lt;br /&gt;
** [[User:Mattx86/tmux config]]&lt;br /&gt;
** [[User:Mattx86/Alpine Fresh Installation]] (mostly outdated)&lt;br /&gt;
&lt;br /&gt;
* My quick wiki notes:&lt;br /&gt;
** [[User:Mattx86/qwn:Install x86-2.1.5 and Upgrade to x86_64-edge]]&lt;br /&gt;
** [[User:Mattx86/qwn:Switching from Alpine Standard/Mini to Alpine VServer]]&lt;br /&gt;
** [[User:Mattx86/qwn:Renaming a network interface]]&lt;br /&gt;
** [[User:Mattx86/qwn:Enabling APK Caching]]&lt;br /&gt;
** [[User:Mattx86/qwn:Enabling ccache]]&lt;br /&gt;
&lt;br /&gt;
* Wiki draft pages:&lt;br /&gt;
** [[User:Mattx86/Obtaining Alpine Linux]]&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=5077</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=5077"/>
		<updated>2011-04-05T03:30:33Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: /* subpackages */ added note about split functions with hyphens&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;
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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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 (i.e., &#039;&#039;_builddir&#039;&#039;).}}&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
==== subpkgdir ====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
==== arch ====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, 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).&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 &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039;.  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;
==== 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.&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;
==== 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;
&lt;br /&gt;
: First, a few notes regarding install scripts:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;{{Note|When using install scripts, &#039;&#039;$install&#039;&#039; should be included in &#039;&#039;source&#039;&#039; so that checksums can be generated and used for the install scripts specified in &#039;&#039;install&#039;&#039;.  For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
install=&amp;quot;$pkgname.pre-install $pkgname.post-install&amp;quot;&lt;br /&gt;
source=&amp;quot;http://....&lt;br /&gt;
       $install&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;}}&lt;br /&gt;
{{Note|Always use &amp;lt;code&amp;gt;/bin/sh&amp;lt;/code&amp;gt; for the command-line interpreter on the [http://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 user/group 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;
adduser -H -s /bin/false -D clamav 2&amp;gt;/dev/null&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 &#039;&#039;&#039;&#039;&#039;exit 0&#039;&#039;&#039;&#039;&#039; 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&#039;&#039; the package.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;after upgrading&#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;
==== license ====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
==== makedepends ====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
==== md5sums ====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated and updated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
==== options ====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&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;py-&#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.&lt;br /&gt;
==== replaces ====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&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/$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;saveas-&#039; to the protocol and append &#039;/software-1.0.tar.gz&#039; (for instance) to the end of the URI, like so:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;saveas-http://oss.example.org/?get=software&amp;amp;ver=1.0/software-1.0.tar.gz&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;
:* 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.gz / .tgz&lt;br /&gt;
:** .tar.bz2&lt;br /&gt;
:** .tar.lzma&lt;br /&gt;
:** .tar.xz&lt;br /&gt;
:** .zip&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 &#039;&#039;&#039;&#039;&#039;subpkg-name&#039;&#039;&#039;&#039;&#039; is the name of the &#039;&#039;&#039;subpackage&#039;&#039;&#039; and &#039;&#039;&#039;&#039;&#039;subpkg_name&#039;&#039;&#039;&#039;&#039; 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 Reference#Subpackages_Example|Subpackages Example]].}}&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;
= Functions =&lt;br /&gt;
{{Note|All functions 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;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
==== dev() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
==== doc() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;&#039;&#039;return 0&#039;&#039;&#039;&#039;&#039;&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: &#039;&#039;&#039;&#039;&#039;mkdir -p &amp;quot;$pkgdir&amp;quot; &amp;amp;&amp;amp; return 0&#039;&#039;&#039;&#039;&#039;&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;
&lt;br /&gt;
= Examples =&lt;br /&gt;
The following APKBUILD examples will assist you in understanding how to create an APKBUILD.&lt;br /&gt;
&lt;br /&gt;
== Subpackages Example ==&lt;br /&gt;
Consider the following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It will ...&lt;br /&gt;
* create the following 5 packages:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
* using the following 5 package functions (respectively) to fill them with files:&lt;br /&gt;
# &#039;&#039;package()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$pkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;dev()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;doc()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
&lt;br /&gt;
== Simple APKBUILD ==&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== APKBUILD with Multiple Subpackages ==&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/qwn:Enabling_APK_Caching&amp;diff=5075</id>
		<title>User:Mattx86/qwn:Enabling APK Caching</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/qwn:Enabling_APK_Caching&amp;diff=5075"/>
		<updated>2011-03-24T04:08:02Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To enable the caching of downloaded APKs, do the following steps.&lt;br /&gt;
&lt;br /&gt;
Create the cache directory and symlink:&lt;br /&gt;
{{Cmd|mkdir -p /var/cache/apk&lt;br /&gt;
ln -s /var/cache/apk /etc/apk/cache}}&lt;br /&gt;
&lt;br /&gt;
Next, update apk in order to initialize the cache:&lt;br /&gt;
{{Cmd|apk update}}&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/qwn:Enabling_APK_Caching&amp;diff=5074</id>
		<title>User:Mattx86/qwn:Enabling APK Caching</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/qwn:Enabling_APK_Caching&amp;diff=5074"/>
		<updated>2011-03-24T04:06:15Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: Created page with &amp;quot;Create the cache directory and symlink: {{Cmd|mkdir -p /var/cache/apk ln -s /var/cache/apk /etc/apk/cache}}  Next, update apk in order to initialize the cache: {{Cmd|apk update}}&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Create the cache directory and symlink:&lt;br /&gt;
{{Cmd|mkdir -p /var/cache/apk&lt;br /&gt;
ln -s /var/cache/apk /etc/apk/cache}}&lt;br /&gt;
&lt;br /&gt;
Next, update apk in order to initialize the cache:&lt;br /&gt;
{{Cmd|apk update}}&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86&amp;diff=5073</id>
		<title>User:Mattx86</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86&amp;diff=5073"/>
		<updated>2011-03-24T03:55:57Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* My personal pages:&lt;br /&gt;
** [[User:Mattx86/Bash Profile]]&lt;br /&gt;
** [[User:Mattx86/tmux config]]&lt;br /&gt;
** [[User:Mattx86/Alpine Fresh Installation]] (mostly outdated)&lt;br /&gt;
&lt;br /&gt;
* My quick wiki notes:&lt;br /&gt;
** [[User:Mattx86/qwn:Install x86-2.1.5 and Upgrade to x86_64-edge]]&lt;br /&gt;
** [[User:Mattx86/qwn:Switching from Alpine Standard/Mini to Alpine VServer]]&lt;br /&gt;
** [[User:Mattx86/qwn:Renaming a network interface]]&lt;br /&gt;
** [[User:Mattx86/qwn:Enabling APK Caching]]&lt;br /&gt;
&lt;br /&gt;
* Wiki draft pages:&lt;br /&gt;
** [[User:Mattx86/Obtaining Alpine Linux]]&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/qwn:Renaming_a_network_interface&amp;diff=5059</id>
		<title>User:Mattx86/qwn:Renaming a network interface</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/qwn:Renaming_a_network_interface&amp;diff=5059"/>
		<updated>2011-03-15T10:42:18Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: Created page with &amp;quot;Supppose I had an interface named &amp;lt;code&amp;gt;eth3&amp;lt;/code&amp;gt; and I want to rename it as &amp;lt;code&amp;gt;neweth3&amp;lt;/code&amp;gt;.  Start out by specifying: {{Cmd|auto neweth3 iface neweth3 inet static}}  Fol...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Supppose I had an interface named &amp;lt;code&amp;gt;eth3&amp;lt;/code&amp;gt; and I want to rename it as &amp;lt;code&amp;gt;neweth3&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Start out by specifying:&lt;br /&gt;
{{Cmd|auto neweth3&lt;br /&gt;
iface neweth3 inet static}}&lt;br /&gt;
&lt;br /&gt;
Followed by the &amp;lt;code&amp;gt;address&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netmask&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;gateway&amp;lt;/code&amp;gt;, etc., and then add this line:&lt;br /&gt;
{{Cmd|pre-up nameif -s neweth3 00:11:22:33:44:55}}&lt;br /&gt;
&lt;br /&gt;
This sets the interface name to &amp;lt;code&amp;gt;neweth3&amp;lt;/code&amp;gt;, where the MAC address of the interface is &amp;lt;code&amp;gt;00:11:22:33:44:55&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a full example:&lt;br /&gt;
{{Cmd|auto neweth3&lt;br /&gt;
iface neweth3 inet static&lt;br /&gt;
        address 10.100.100.1&lt;br /&gt;
        netmask 255.255.255.0&lt;br /&gt;
        network 10.100.100.0&lt;br /&gt;
        broadcast 10.100.100.255&lt;br /&gt;
        pre-up nameif -s neweth3 00:11:22:33:44:55}}&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86&amp;diff=5058</id>
		<title>User:Mattx86</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86&amp;diff=5058"/>
		<updated>2011-03-15T10:28:46Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* My personal pages:&lt;br /&gt;
** [[User:Mattx86/Bash Profile]]&lt;br /&gt;
** [[User:Mattx86/tmux config]]&lt;br /&gt;
** [[User:Mattx86/Alpine Fresh Installation]] (mostly outdated)&lt;br /&gt;
&lt;br /&gt;
* My quick wiki notes:&lt;br /&gt;
** [[User:Mattx86/qwn:Install x86-2.1.5 and Upgrade to x86_64-edge]]&lt;br /&gt;
** [[User:Mattx86/qwn:Switching from Alpine Standard/Mini to Alpine VServer]]&lt;br /&gt;
** [[User:Mattx86/qwn:Renaming a network interface]]&lt;br /&gt;
&lt;br /&gt;
* Wiki draft pages:&lt;br /&gt;
** [[User:Mattx86/Obtaining Alpine Linux]]&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/qwn:Switching_from_Alpine_Standard/Mini_to_Alpine_VServer&amp;diff=5057</id>
		<title>User:Mattx86/qwn:Switching from Alpine Standard/Mini to Alpine VServer</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/qwn:Switching_from_Alpine_Standard/Mini_to_Alpine_VServer&amp;diff=5057"/>
		<updated>2011-03-15T10:26:39Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: Created page with &amp;quot;&amp;lt;pre&amp;gt; Switching from Alpine Standard/Mini to Alpine VServer -----------------------------------------------------  # apk add linux-vserver util-vserver # vi /boot/extlinux.conf  ...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Switching from Alpine Standard/Mini to Alpine VServer&lt;br /&gt;
-----------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
# apk add linux-vserver util-vserver&lt;br /&gt;
# vi /boot/extlinux.conf&lt;br /&gt;
  * copy and paste grsec configuration&lt;br /&gt;
  * change grsec to vserver in the copied grsec configuration&lt;br /&gt;
  * change default line to vserver&lt;br /&gt;
  * save and exit&lt;br /&gt;
# reboot&lt;br /&gt;
&lt;br /&gt;
Creating a vserver template:&lt;br /&gt;
# mkdir /tmp/vstpl&lt;br /&gt;
# apk add --initdb --root /tmp/vstpl --repositories-file /etc/apk/repositories --keys-dir /etc/apk/keys -U alpine-base&lt;br /&gt;
# chroot /tmp/vstpl /sbin/rc-update add syslog boot&lt;br /&gt;
  * the vserver .. build command seems to add syslog to the boot runlevel, so this may be unnecessary.&lt;br /&gt;
# cd /tmp/vstpl &amp;amp;&amp;amp; tar -czf /tmp/vstpl.tar.gz *&lt;br /&gt;
# rm /tmp/vstpl -rf&lt;br /&gt;
&lt;br /&gt;
Creating a vserver guest:&lt;br /&gt;
# vserver guest1 build --interface eth0:192.168.1.26/24 --hostname guest1 -m template -- -t /tmp/vstpl.tar.gz -d alpine&lt;br /&gt;
&lt;br /&gt;
Starting the vserver guest:&lt;br /&gt;
# vserver guest1 start&lt;br /&gt;
  * I need to see why this happens:&lt;br /&gt;
    mount: permission denied (are you root?)&lt;br /&gt;
    mount: permission denied (are you root?)&lt;br /&gt;
&lt;br /&gt;
Entering the vserver guest:&lt;br /&gt;
# vserver guest1 enter&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86&amp;diff=5056</id>
		<title>User:Mattx86</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86&amp;diff=5056"/>
		<updated>2011-03-15T10:26:01Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* My personal pages:&lt;br /&gt;
** [[User:Mattx86/Bash Profile]]&lt;br /&gt;
** [[User:Mattx86/tmux config]]&lt;br /&gt;
** [[User:Mattx86/Alpine Fresh Installation]] (mostly outdated)&lt;br /&gt;
&lt;br /&gt;
* My quick wiki notes:&lt;br /&gt;
** [[User:Mattx86/qwn:Install x86-2.1.5 and Upgrade to x86_64-edge]]&lt;br /&gt;
** [[User:Mattx86/qwn:Switching from Alpine Standard/Mini to Alpine VServer]]&lt;br /&gt;
&lt;br /&gt;
* Wiki draft pages:&lt;br /&gt;
** [[User:Mattx86/Obtaining Alpine Linux]]&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/qwn:Install_x86-2.1.5_and_Upgrade_to_x86_64-edge&amp;diff=5055</id>
		<title>User:Mattx86/qwn:Install x86-2.1.5 and Upgrade to x86 64-edge</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/qwn:Install_x86-2.1.5_and_Upgrade_to_x86_64-edge&amp;diff=5055"/>
		<updated>2011-03-15T10:24:45Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The eventual goal with this document is to show how to upgrade a production 32-bit Alpine Linux installation to 64-bit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Installing Alpine 2.1.5 and upgrading to Edge 64-bit&lt;br /&gt;
----------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
# setup-alpine&lt;br /&gt;
# setup-disk&lt;br /&gt;
# wget http://dl-4.alpinelinux.org/alpine/edge/releases/x86_64/alpine-edge-110310-x86_64.iso&lt;br /&gt;
# mkdir /media/iso&lt;br /&gt;
# mount -t loop /root/alpine-edge-110310-x86_64.iso /media/iso&lt;br /&gt;
# mount /dev/sda3 /mnt&lt;br /&gt;
# mount /dev/sda1 /mnt/boot&lt;br /&gt;
# vi /mnt/etc/apk/repositories&lt;br /&gt;
  * remove cdrom listing if present&lt;br /&gt;
  * add http://dl-4.alpinelinux.org/alpine/edge/x86_64/main/&lt;br /&gt;
  * add http://dl-4.alpinelinux.org/alpine/edge/x86_64/testing/&lt;br /&gt;
  * save and exit&lt;br /&gt;
# apk add --allow-untrusted --root /mnt --repositories-file /etc/apk/repositories --keys-dir /etc/apk/keys -Uaf upgrade&lt;br /&gt;
  * as many times necessary to get past the upgrade script errors&lt;br /&gt;
# cp /media/iso/boot/grsec.gz /mnt/boot/initramfs-2.6.37.2-grsec&lt;br /&gt;
# cd /mnt/boot&lt;br /&gt;
# rm initramfs-2.6.35.11-grsec&lt;br /&gt;
# rm initramfs-grsec&lt;br /&gt;
# ln -s initramfs-2.6.37.2-grsec initramfs-grsec&lt;br /&gt;
# rm vmlinuz-grsec&lt;br /&gt;
# ln -s vmlinuz-2.6.37.2-grsec vmlinuz-grsec&lt;br /&gt;
# cd /&lt;br /&gt;
# umount /media/iso&lt;br /&gt;
# umount /mnt/boot&lt;br /&gt;
# umount /mnt&lt;br /&gt;
# reboot&lt;br /&gt;
&lt;br /&gt;
After reboot:&lt;br /&gt;
# apk fix -r `cat /var/lib/apk/world`&lt;br /&gt;
# apk -Ua upgrade&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/qwn:Install_x86-2.1.5_and_Upgrade_to_x86_64-edge&amp;diff=5054</id>
		<title>User:Mattx86/qwn:Install x86-2.1.5 and Upgrade to x86 64-edge</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/qwn:Install_x86-2.1.5_and_Upgrade_to_x86_64-edge&amp;diff=5054"/>
		<updated>2011-03-15T10:24:23Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: Created page with &amp;quot;The eventual goal with this document is to show how to upgrade a production 32-bit Alpine Linux installation to 64-bit.  &amp;lt;pre&amp;gt; Installing Alpine 2.1.5 and upgrading to Edge 64-bi...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The eventual goal with this document is to show how to upgrade a production 32-bit Alpine Linux installation to 64-bit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Installing Alpine 2.1.5 and upgrading to Edge 64-bit&lt;br /&gt;
----------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
# setup-alpine&lt;br /&gt;
# setup-disk&lt;br /&gt;
# wget http://dl-4.alpinelinux.org/alpine/edge/releases/x86_64/alpine-edge-110310-x86_64.iso&lt;br /&gt;
# mkdir /media/iso&lt;br /&gt;
# mount -t loop /root/alpine-edge-110310-x86_64.iso /media/iso&lt;br /&gt;
# mount /dev/sda3 /mnt&lt;br /&gt;
# mount /dev/sda1 /mnt/boot&lt;br /&gt;
# vi /mnt/etc/apk/repositories&lt;br /&gt;
  * remove cdrom listing if present&lt;br /&gt;
  * add http://dl-4.alpinelinux.org/alpine/edge/x86_64/main/&lt;br /&gt;
  * add http://dl-4.alpinelinux.org/alpine/edge/x86_64/testing/&lt;br /&gt;
  * save and exit&lt;br /&gt;
# apk add --allow-untrusted --root /mnt --repositories-file /etc/apk/repositories --keys-dir /etc/apk/keys -Uaf upgrade&lt;br /&gt;
  * as many times necessary to get paste the upgrade script errors&lt;br /&gt;
# cp /media/iso/boot/grsec.gz /mnt/boot/initramfs-2.6.37.2-grsec&lt;br /&gt;
# cd /mnt/boot&lt;br /&gt;
# rm initramfs-2.6.35.11-grsec&lt;br /&gt;
# rm initramfs-grsec&lt;br /&gt;
# ln -s initramfs-2.6.37.2-grsec initramfs-grsec&lt;br /&gt;
# rm vmlinuz-grsec&lt;br /&gt;
# ln -s vmlinuz-2.6.37.2-grsec vmlinuz-grsec&lt;br /&gt;
# cd /&lt;br /&gt;
# umount /media/iso&lt;br /&gt;
# umount /mnt/boot&lt;br /&gt;
# umount /mnt&lt;br /&gt;
# reboot&lt;br /&gt;
&lt;br /&gt;
After reboot:&lt;br /&gt;
# apk fix -r `cat /var/lib/apk/world`&lt;br /&gt;
# apk -Ua upgrade&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86&amp;diff=5053</id>
		<title>User:Mattx86</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86&amp;diff=5053"/>
		<updated>2011-03-15T10:16:23Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* My personal pages:&lt;br /&gt;
** [[User:Mattx86/Bash Profile]]&lt;br /&gt;
** [[User:Mattx86/tmux config]]&lt;br /&gt;
** [[User:Mattx86/Alpine Fresh Installation]] (mostly outdated)&lt;br /&gt;
&lt;br /&gt;
* My quick wiki notes:&lt;br /&gt;
** [[User:Mattx86/qwn:Install x86-2.1.5 and Upgrade to x86_64-edge]]&lt;br /&gt;
&lt;br /&gt;
* Wiki draft pages:&lt;br /&gt;
** [[User:Mattx86/Obtaining Alpine Linux]]&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Configure_Networking&amp;diff=5052</id>
		<title>Configure Networking</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Configure_Networking&amp;diff=5052"/>
		<updated>2011-03-15T10:07:13Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: Added note, stating that the loopback configuration must appear first in the interfaces configuration.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page will assist you in setting up networking on Alpine Linux.&lt;br /&gt;
{{Note|You must be logged in as root in order to perform the actions on this page.}}&lt;br /&gt;
&lt;br /&gt;
= Setting System Hostname =&lt;br /&gt;
To set the system hostname, do something like the following:&lt;br /&gt;
{{Cmd|echo &amp;quot;hostname.domain.com&amp;quot; &amp;gt; /etc/hostname}}&lt;br /&gt;
&lt;br /&gt;
Then, to activate the change, do the following:&lt;br /&gt;
{{Cmd|hostname -F /etc/hostname}}&lt;br /&gt;
&lt;br /&gt;
If you&#039;re using IPv6, you should also add the following special IPv6 addresses to your &amp;lt;code&amp;gt;/etc/hosts&amp;lt;/code&amp;gt; file:&lt;br /&gt;
&amp;lt;pre&amp;gt;::1             localhost ipv6-localhost ipv6-loopback&lt;br /&gt;
fe00::0         ipv6-localnet&lt;br /&gt;
ff00::0         ipv6-mcastprefix&lt;br /&gt;
ff02::1         ipv6-allnodes&lt;br /&gt;
ff02::2         ipv6-allrouters&lt;br /&gt;
ff02::3         ipv6-allhosts&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Tip|If you are going to use automatic IP configuration, such as IPv4 DHCP or IPv6 Stateless Autoconfiguration, you can skip ahead to [[#Configuring_DNS|Configuring DNS]].  Otherwise, if you are going to use a static IPv4 or IPv6 address, continue below.}}&lt;br /&gt;
&lt;br /&gt;
For a static IP configuration, it&#039;s common to also add the machine&#039;s hostname you just set (above) to the &amp;lt;code&amp;gt;/etc/hosts&amp;lt;/code&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s an IPv4 example:&lt;br /&gt;
&amp;lt;pre&amp;gt;192.168.1.150   hostname.domain.com&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And here&#039;s an IPv6 example:&lt;br /&gt;
&amp;lt;pre&amp;gt;2001:470:ffff:ff::2   hostname.domain.com&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring DNS =&lt;br /&gt;
{{Tip|&#039;&#039;&#039;For users of IPv4 DHCP:&#039;&#039;&#039; Please note that &amp;lt;code&amp;gt;/etc/resolv.conf&amp;lt;/code&amp;gt; will be completely overwritten with any nameservers provided by DHCP. Also, if DHCP does not provide any nameservers, then &amp;lt;code&amp;gt;/etc/resolv.conf&amp;lt;/code&amp;gt; will still be overwritten, but will not contain any nameservers!}}&lt;br /&gt;
&lt;br /&gt;
For using a static IP and static nameservers, use one of the following examples.&lt;br /&gt;
&lt;br /&gt;
For IPv4 nameservers, edit your &amp;lt;code&amp;gt;/etc/resolv.conf&amp;lt;/code&amp;gt; file to look like this:&amp;lt;br /&amp;gt;&lt;br /&gt;
The following example uses [http://en.wikipedia.org/wiki/Google_Public_DNS Google&#039;s Public DNS servers].&lt;br /&gt;
 nameserver 8.8.8.8&lt;br /&gt;
 nameserver 8.8.4.4&lt;br /&gt;
&lt;br /&gt;
For IPv6 nameservers, edit your &amp;lt;code&amp;gt;/etc/resolv.conf&amp;lt;/code&amp;gt; file to look like this:&amp;lt;br /&amp;gt;&lt;br /&gt;
The following example uses [http://www.he.net/ Hurricane Electric&#039;s] public DNS server.&lt;br /&gt;
 nameserver 2001:470:20::2&lt;br /&gt;
You can also use Hurricane Electric&#039;s public DNS server via IPv4:&lt;br /&gt;
 nameserver 74.82.42.42&lt;br /&gt;
&lt;br /&gt;
{{Tip|If you decide to use Hurricane Electric&#039;s nameserver, be aware that it is &#039;Google-whitelisted&#039;. What does this mean?  It allows you access to many of Google&#039;s services via IPv6. (Just don&#039;t add other, non-whitelisted, nameservers to &amp;lt;code&amp;gt;/etc/resolv.conf&amp;lt;/code&amp;gt; — ironically, such as Google&#039;s Public DNS Servers.) Read [http://www.google.com/intl/en/ipv6/ here] for more information.}}&lt;br /&gt;
&lt;br /&gt;
= Enabling IPv6 (Optional) =&lt;br /&gt;
&lt;br /&gt;
If you use IPv6, do the following to enable IPv6 for now and at each boot:&lt;br /&gt;
{{Cmd|modprobe ipv6&lt;br /&gt;
echo &amp;quot;ipv6&amp;quot; &amp;gt;&amp;gt; /etc/modules}}&lt;br /&gt;
&lt;br /&gt;
= Interface Configuration =&lt;br /&gt;
&lt;br /&gt;
== Loopback Configuration (Required) ==&lt;br /&gt;
{{Note|The loopback configuration must appear first in &amp;lt;code&amp;gt;/etc/network/interfaces&amp;lt;/code&amp;gt; to prevent networking issues.}}&lt;br /&gt;
To configure loopback, add the following to a new file &amp;lt;code&amp;gt;/etc/network/interfaces&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;auto lo&lt;br /&gt;
iface lo inet loopback&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above works to setup the IPv4 loopback address (127.0.0.1), and the IPv6 loopback address (&amp;lt;code&amp;gt;::1&amp;lt;/code&amp;gt;) — if you enabled IPv6.&lt;br /&gt;
&lt;br /&gt;
== Ethernet Configuration ==&lt;br /&gt;
For the following Ethernet configuration examples, we will assume that you are using Ethernet device &amp;lt;code&amp;gt;eth0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Initial Configuration ===&lt;br /&gt;
Add the following to the file &amp;lt;code&amp;gt;/etc/network/interfaces&amp;lt;/code&amp;gt;, above any IP configuration for &amp;lt;code&amp;gt;eth0&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;auto eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== IPv4 DHCP Configuration ===&lt;br /&gt;
Add the following to the file &amp;lt;code&amp;gt;/etc/network/interfaces&amp;lt;/code&amp;gt;, below the &amp;lt;code&amp;gt;auto eth0&amp;lt;/code&amp;gt; definition:&lt;br /&gt;
&amp;lt;pre&amp;gt;iface eth0 inet dhcp&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== IPv4 Static Address Configuration ===&lt;br /&gt;
Add the following to the file &amp;lt;code&amp;gt;/etc/network/interfaces&amp;lt;/code&amp;gt;, below the &amp;lt;code&amp;gt;auto eth0&amp;lt;/code&amp;gt; definition:&lt;br /&gt;
&amp;lt;pre&amp;gt;iface eth0 inet static&lt;br /&gt;
        address 192.168.1.150&lt;br /&gt;
        netmask 255.255.255.0&lt;br /&gt;
        gateway 192.168.1.1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== IPv6 Stateless Autoconfiguration ===&lt;br /&gt;
Add the following to the file &amp;lt;code&amp;gt;/etc/network/interfaces&amp;lt;/code&amp;gt;, below the &amp;lt;code&amp;gt;auto eth0&amp;lt;/code&amp;gt; definition:&lt;br /&gt;
&amp;lt;pre&amp;gt;iface eth0 inet6 manual&lt;br /&gt;
        pre-up echo 1 &amp;gt; /proc/sys/net/ipv6/conf/eth0/accept_ra&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Tip|The &amp;quot;inet6 manual&amp;quot; method is available in busybox 1.17.3-r3 and later.}}&lt;br /&gt;
&lt;br /&gt;
=== IPv6 Static Address Configuration ===&lt;br /&gt;
Add the following to the file &amp;lt;code&amp;gt;/etc/network/interfaces&amp;lt;/code&amp;gt;, below the &amp;lt;code&amp;gt;auto eth0&amp;lt;/code&amp;gt; definition:&lt;br /&gt;
&amp;lt;pre&amp;gt;iface eth0 inet6 static&lt;br /&gt;
        address 2001:470:ffff:ff::2&lt;br /&gt;
        netmask 64&lt;br /&gt;
        gateway 2001:470:ffff:ff::1&lt;br /&gt;
        pre-up echo 0 &amp;gt; /proc/sys/net/ipv6/conf/eth0/accept_ra&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example: Dual-Stack Configuration ==&lt;br /&gt;
This example shows a dual-stack configuration.&lt;br /&gt;
&amp;lt;pre&amp;gt;auto lo&lt;br /&gt;
iface lo inet loopback&lt;br /&gt;
&lt;br /&gt;
auto eth0&lt;br /&gt;
&lt;br /&gt;
iface eth0 inet static&lt;br /&gt;
        address 192.168.1.150&lt;br /&gt;
        netmask 255.255.255.0&lt;br /&gt;
        gateway 192.168.1.1&lt;br /&gt;
&lt;br /&gt;
iface eth0 inet6 static&lt;br /&gt;
        address 2001:470:ffff:ff::2&lt;br /&gt;
        netmask 64&lt;br /&gt;
        gateway 2001:470:ffff:ff::1&lt;br /&gt;
        pre-up echo 0 &amp;gt; /proc/sys/net/ipv6/conf/eth0/accept_ra&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Firewalling with iptables and ip6tables =&lt;br /&gt;
== Install iptables/ip6tables ==&lt;br /&gt;
* To install iptables:&lt;br /&gt;
: {{Cmd|apk add iptables}}&lt;br /&gt;
&lt;br /&gt;
* To install ip6tables:&lt;br /&gt;
: {{Cmd|apk add ip6tables}}&lt;br /&gt;
&lt;br /&gt;
* To install the man pages for iptables and ip6tables:&lt;br /&gt;
: {{Cmd|apk add iptables-doc}}&lt;br /&gt;
&lt;br /&gt;
== Configure iptables/ip6tables ==&lt;br /&gt;
{{ Tip| Good examples of how to write iptables rules can be found at the Linux Home Networking Wiki http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch14_:_Linux_Firewalls_Using_iptables }}&lt;br /&gt;
&lt;br /&gt;
== Save Firewall Rules ==&lt;br /&gt;
&lt;br /&gt;
=== For iptables ===&lt;br /&gt;
# Set iptables to start on reboot&lt;br /&gt;
#* {{ Cmd| rc-update add iptables }}&lt;br /&gt;
# Write the firewall rules to disk&lt;br /&gt;
#* {{ Cmd| /etc/init.d/iptables save}}&lt;br /&gt;
# If you use Alpine Local Backup:&lt;br /&gt;
## Add the firewall rules to Alpine Local Backup&lt;br /&gt;
##* {{ Cmd| lbu add /var/lib/iptables/rules-save }}&lt;br /&gt;
## Save the configuration&lt;br /&gt;
##* {{ Cmd| lbu ci }}&lt;br /&gt;
&lt;br /&gt;
=== For ip6tables ===&lt;br /&gt;
# Set ip6tables to start on reboot&lt;br /&gt;
#* {{ Cmd| rc-update add ip6tables }}&lt;br /&gt;
# Write the firewall rules to disk&lt;br /&gt;
#* {{ Cmd| /etc/init.d/ip6tables save}}&lt;br /&gt;
# If you use Alpine Local Backup:&lt;br /&gt;
## Add the firewall rules to Alpine Local Backup&lt;br /&gt;
##* {{ Cmd| lbu add /var/lib/ip6tables/rules-save }}&lt;br /&gt;
## Save the configuration&lt;br /&gt;
##* {{ Cmd| lbu ci }}&lt;br /&gt;
&lt;br /&gt;
= Activating Changes and Testing Connectivity =&lt;br /&gt;
Changes made to &amp;lt;code&amp;gt;/etc/network/interfaces&amp;lt;/code&amp;gt; can be activated by running:&lt;br /&gt;
{{Cmd|/etc/init.d/networking restart}}&lt;br /&gt;
If you did not get any errors, you can now test that networking is configured properly by attempting to ping out:&lt;br /&gt;
{{Cmd|ping www.google.com}}&lt;br /&gt;
&amp;lt;pre&amp;gt;PING www.l.google.com (74.125.47.103) 56(84) bytes of data.&lt;br /&gt;
64 bytes from yw-in-f103.1e100.net (74.125.47.103): icmp_seq=1 ttl=48 time=58.5 ms&lt;br /&gt;
64 bytes from yw-in-f103.1e100.net (74.125.47.103): icmp_seq=2 ttl=48 time=56.4 ms&lt;br /&gt;
64 bytes from yw-in-f103.1e100.net (74.125.47.103): icmp_seq=3 ttl=48 time=57.0 ms&lt;br /&gt;
64 bytes from yw-in-f103.1e100.net (74.125.47.103): icmp_seq=4 ttl=48 time=60.2 ms&lt;br /&gt;
^C&lt;br /&gt;
--- www.l.google.com ping statistics ---&lt;br /&gt;
4 packets transmitted, 4 received, 0% packet loss, time 3007ms&lt;br /&gt;
rtt min/avg/max/mdev = 56.411/58.069/60.256/1.501 ms&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For an IPv6 traceroute (&amp;lt;code&amp;gt;traceroute6&amp;lt;/code&amp;gt;), you will first need to install the &amp;lt;code&amp;gt;iputils&amp;lt;/code&amp;gt; package:&lt;br /&gt;
{{Cmd|apk add iputils}}&lt;br /&gt;
&lt;br /&gt;
Then run &amp;lt;code&amp;gt;traceroute6&amp;lt;/code&amp;gt;:&lt;br /&gt;
{{Cmd|traceroute6 ipv6.google.com}}&lt;br /&gt;
&amp;lt;pre&amp;gt;traceroute to ipv6.l.google.com (2001:4860:8009::67) from 2001:470:ffff:ff::2, 30 hops max, 16 byte packets&lt;br /&gt;
 1  2001:470:ffff:ff::1 (2001:470:ffff:ff::1)  3.49 ms  0.62 ms  0.607 ms&lt;br /&gt;
 2  *  *  *&lt;br /&gt;
 3  *  *  *&lt;br /&gt;
 4  pr61.iad07.net.google.com (2001:504:0:2:0:1:5169:1)  134.313 ms  95.342 ms  88.425 ms&lt;br /&gt;
 5  2001:4860::1:0:9ff (2001:4860::1:0:9ff)  100.759 ms  100.537 ms  89.907 ms&lt;br /&gt;
 6  2001:4860::1:0:5db (2001:4860::1:0:5db)  115.563 ms  102.946 ms  106.191 ms&lt;br /&gt;
 7  2001:4860::2:0:a7 (2001:4860::2:0:a7)  101.754 ms  100.475 ms  100.512 ms&lt;br /&gt;
 8  2001:4860:0:1::c3 (2001:4860:0:1::c3)  99.272 ms  111.989 ms  99.835 ms&lt;br /&gt;
 9  yw-in-x67.1e100.net (2001:4860:8009::67)  101.545 ms  109.675 ms  99.431 ms&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/Bash_Profile&amp;diff=4884</id>
		<title>User:Mattx86/Bash Profile</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/Bash_Profile&amp;diff=4884"/>
		<updated>2011-01-26T12:27:09Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here&#039;s the &amp;lt;code&amp;gt;~/.bash_profile&amp;lt;/code&amp;gt; that I use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Aliases&lt;br /&gt;
alias sudo=&#039;sudo &#039;		# sudo: make aliases work&lt;br /&gt;
alias nano=&#039;nano -wcAiLS&#039;	# nano: -w: don&#039;t wrap long lines&lt;br /&gt;
				#       -c: constantly show cursor position&lt;br /&gt;
				#	-A: enable smart home key&lt;br /&gt;
				#	-i: automatically indent new lines&lt;br /&gt;
				#	-L: don&#039;t add newlines to the ends of files&lt;br /&gt;
				#	-S: scroll by line instead of half-screen&lt;br /&gt;
alias apk=&#039;apk --progress&#039;	# apk: show progress bar&lt;br /&gt;
&lt;br /&gt;
# Shell Options&lt;br /&gt;
shopt -s checkwinsize&lt;br /&gt;
&lt;br /&gt;
# Color Definitions for .bashrc&lt;br /&gt;
COL_YEL=&amp;quot;\[\e[1;33m\]&amp;quot;&lt;br /&gt;
COL_GRA=&amp;quot;\[\e[0;37m\]&amp;quot;&lt;br /&gt;
COL_WHI=&amp;quot;\[\e[1;37m\]&amp;quot;&lt;br /&gt;
COL_GRE=&amp;quot;\[\e[1;32m\]&amp;quot;&lt;br /&gt;
COL_RED=&amp;quot;\[\e[1;31m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Bash Prompt&lt;br /&gt;
if test &amp;quot;$UID&amp;quot; -eq 0 ; then&lt;br /&gt;
	_COL_USER=$COL_RED&lt;br /&gt;
	_p=&amp;quot; #&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
	_COL_USER=$COL_GRE&lt;br /&gt;
	_p=&amp;quot;&amp;gt;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
COLORIZED_PROMPT=&amp;quot;${_COL_USER}\u${COL_WHI}@${COL_YEL}\h${COL_WHI}:\w${_p} \[\e[m\]&amp;quot;&lt;br /&gt;
case $TERM in&lt;br /&gt;
	*term | rxvt | screen )&lt;br /&gt;
		PS1=&amp;quot;${COLORIZED_PROMPT}\[\e]0;\u@\h:\w\007\]&amp;quot; ;;&lt;br /&gt;
	linux )&lt;br /&gt;
		PS1=&amp;quot;${COLORIZED_PROMPT}&amp;quot; ;;&lt;br /&gt;
	* )&lt;br /&gt;
		PS1=&amp;quot;\u@\h:\w${_p} &amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Tip|Be sure to symlink &amp;lt;code&amp;gt;.bashrc&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;.bash_profile&amp;lt;/code&amp;gt;.}}&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/Bash_Profile&amp;diff=4883</id>
		<title>User:Mattx86/Bash Profile</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/Bash_Profile&amp;diff=4883"/>
		<updated>2011-01-26T11:40:03Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here&#039;s the &amp;lt;code&amp;gt;~/.bash_profile&amp;lt;/code&amp;gt; that I use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Aliases&lt;br /&gt;
alias sudo=&#039;sudo &#039;		# sudo: make aliases work&lt;br /&gt;
alias nano=&#039;nano -wc&#039;		# nano: -w: don&#039;t wrap long lines&lt;br /&gt;
				#       -c: constantly show cursor position&lt;br /&gt;
alias apk=&#039;apk --progress&#039;	# apk: show progress bar&lt;br /&gt;
&lt;br /&gt;
# Shell Options&lt;br /&gt;
shopt -s checkwinsize&lt;br /&gt;
&lt;br /&gt;
# Color Definitions for .bashrc&lt;br /&gt;
COL_YEL=&amp;quot;\[\e[1;33m\]&amp;quot;&lt;br /&gt;
COL_GRA=&amp;quot;\[\e[0;37m\]&amp;quot;&lt;br /&gt;
COL_WHI=&amp;quot;\[\e[1;37m\]&amp;quot;&lt;br /&gt;
COL_GRE=&amp;quot;\[\e[1;32m\]&amp;quot;&lt;br /&gt;
COL_RED=&amp;quot;\[\e[1;31m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Bash Prompt&lt;br /&gt;
if test &amp;quot;$UID&amp;quot; -eq 0 ; then&lt;br /&gt;
	_COL_USER=$COL_RED&lt;br /&gt;
	_p=&amp;quot; #&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
	_COL_USER=$COL_GRE&lt;br /&gt;
	_p=&amp;quot;&amp;gt;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
COLORIZED_PROMPT=&amp;quot;${_COL_USER}\u${COL_WHI}@${COL_YEL}\h${COL_WHI}:\w${_p} \[\e[m\]&amp;quot;&lt;br /&gt;
case $TERM in&lt;br /&gt;
	*term | rxvt | screen )&lt;br /&gt;
		PS1=&amp;quot;${COLORIZED_PROMPT}\[\e]0;\u@\h:\w\007\]&amp;quot; ;;&lt;br /&gt;
	linux )&lt;br /&gt;
		PS1=&amp;quot;${COLORIZED_PROMPT}&amp;quot; ;;&lt;br /&gt;
	* )&lt;br /&gt;
		PS1=&amp;quot;\u@\h:\w${_p} &amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Tip|Be sure to symlink &amp;lt;code&amp;gt;.bashrc&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;.bash_profile&amp;lt;/code&amp;gt;.}}&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86&amp;diff=4878</id>
		<title>User:Mattx86</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86&amp;diff=4878"/>
		<updated>2011-01-25T07:58:47Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* My personal pages:&lt;br /&gt;
** [[User:Mattx86/Bash Profile]]&lt;br /&gt;
** [[User:Mattx86/tmux config]]&lt;br /&gt;
** [[User:Mattx86/Alpine Fresh Installation]] (mostly outdated)&lt;br /&gt;
&lt;br /&gt;
* Wiki draft pages:&lt;br /&gt;
** [[User:Mattx86/Obtaining Alpine Linux]]&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86&amp;diff=4877</id>
		<title>User:Mattx86</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86&amp;diff=4877"/>
		<updated>2011-01-25T07:58:23Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* My personal pages:&lt;br /&gt;
** [[User:Mattx86/Alpine Fresh Installation]] (mostly outdated)&lt;br /&gt;
** [[User:Mattx86/Bash Profile]]&lt;br /&gt;
** [[User:Mattx86/tmux config]]&lt;br /&gt;
&lt;br /&gt;
* Wiki draft pages:&lt;br /&gt;
** [[User:Mattx86/Obtaining Alpine Linux]]&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/tmux_config&amp;diff=4876</id>
		<title>User:Mattx86/tmux config</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86/tmux_config&amp;diff=4876"/>
		<updated>2011-01-25T07:41:47Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: Created page with &amp;quot;The following is the &amp;lt;code&amp;gt;~/.tmux.conf&amp;lt;/code&amp;gt; file I use:  &amp;lt;pre&amp;gt; # Basic settings bind z source-file ~/.tmux.conf		# Reload tmux config	(Ctrl+b, z) set -g history-limit 1000 set...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The following is the &amp;lt;code&amp;gt;~/.tmux.conf&amp;lt;/code&amp;gt; file I use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Basic settings&lt;br /&gt;
bind z source-file ~/.tmux.conf		# Reload tmux config	(Ctrl+b, z)&lt;br /&gt;
set -g history-limit 1000&lt;br /&gt;
set-window-option -g mode-keys vi&lt;br /&gt;
&lt;br /&gt;
# Window panes&lt;br /&gt;
unbind %&lt;br /&gt;
bind | split-window -h		# Split window horizontally	(Ctrl+b, |) (i.e., hold Ctrl, hit &#039;b&#039;, and then get the pipe character)&lt;br /&gt;
bind - split-window -v		# Split window vertically	(Ctrl+b, -) (i.e., hold Ctrl, hit &#039;b&#039;, and then hit the minus key)&lt;br /&gt;
bind-key C-u resize-pane -U	# Resize window up		(Ctrl+b, u) (i.e., hold Ctrl and alternate hitting &#039;b&#039; and &#039;u&#039;)&lt;br /&gt;
bind-key C-d resize-pane -D	# Resize window down		(Ctrl+b, d) (similar)&lt;br /&gt;
bind-key C-l resize-pane -L	# Resize window left		(Ctrl+b, l) (similar)&lt;br /&gt;
bind-key C-r resize-pane -R	# Resize window right		(Ctrl+b, r) (similar)&lt;br /&gt;
set -g mouse-select-pane off&lt;br /&gt;
set -g pane-active-border-fg green&lt;br /&gt;
set -g pane-active-border-bg default&lt;br /&gt;
&lt;br /&gt;
# Status bar&lt;br /&gt;
set -g status-bg black&lt;br /&gt;
set -g status-fg white&lt;br /&gt;
#set -g status-left &#039;#[fg=green]#(whoami)#[default]@#[fg=yellow]#H#[default]&#039;&lt;br /&gt;
set -g status-left &#039;&#039;&lt;br /&gt;
set -g status-left-length 0&lt;br /&gt;
set -g status-right-length 60&lt;br /&gt;
set -g status-right &#039;#[fg=cyan]#(whoami)@#H#[default] #[fg=yellow]#(cut -d &amp;quot; &amp;quot; -f 1-3 /proc/loadavg)#[default] #[bg=blue]%a %b %d, %H:%M#[default]&#039;&lt;br /&gt;
set-window-option -g window-status-current-bg black&lt;br /&gt;
set-window-option -g window-status-current-fg green&lt;br /&gt;
set -g status-justify centre&lt;br /&gt;
&lt;br /&gt;
# Remote Terminal: Window title&lt;br /&gt;
set-option -g set-titles on&lt;br /&gt;
set-option -g set-titles-string &#039;#S:#I.#P #T&#039;&lt;br /&gt;
set-window-option -g automatic-rename on&lt;br /&gt;
&lt;br /&gt;
# Remote Terminal: Enable mouse scrolling from, e.g., gnome-terminal.&lt;br /&gt;
# The alternative is to enter tmux copy mode (Ctrl+b, [), and then use&lt;br /&gt;
# the PgUp/PgDn/Arrow keys.  When done, quit copy mode (q).&lt;br /&gt;
set -g terminal-overrides &#039;xterm*:smcup@:rmcup@&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86&amp;diff=4875</id>
		<title>User:Mattx86</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Mattx86&amp;diff=4875"/>
		<updated>2011-01-25T07:37:12Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: Added link to my &amp;#039;tmux config&amp;#039; page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* My personal pages:&lt;br /&gt;
** [[User:Mattx86/Alpine Fresh Installation]]&lt;br /&gt;
** [[User:Mattx86/Bash Profile]]&lt;br /&gt;
** [[User:Mattx86/tmux config]]&lt;br /&gt;
&lt;br /&gt;
* Wiki draft pages:&lt;br /&gt;
** [[User:Mattx86/Obtaining Alpine Linux]]&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4855</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4855"/>
		<updated>2011-01-18T01:09:22Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: /* install */&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;
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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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 (i.e., &#039;&#039;_builddir&#039;&#039;).}}&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
==== subpkgdir ====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
==== arch ====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, 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).&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 &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039;.  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;
==== 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.&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;
==== 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;
&lt;br /&gt;
: First, a few notes regarding install scripts:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;{{Note|When using install scripts, &#039;&#039;$install&#039;&#039; should be included in &#039;&#039;source&#039;&#039; so that checksums can be generated and used for the install scripts specified in &#039;&#039;install&#039;&#039;.  For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
install=&amp;quot;$pkgname.pre-install $pkgname.post-install&amp;quot;&lt;br /&gt;
source=&amp;quot;http://....&lt;br /&gt;
       $install&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;}}&lt;br /&gt;
{{Note|Always use &amp;lt;code&amp;gt;/bin/sh&amp;lt;/code&amp;gt; for the command-line interpreter on the [http://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 user/group 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;
adduser -H -s /bin/false -D clamav 2&amp;gt;/dev/null&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 &#039;&#039;&#039;&#039;&#039;exit 0&#039;&#039;&#039;&#039;&#039; 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&#039;&#039; the package.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;after upgrading&#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;
==== license ====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
==== makedepends ====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
==== md5sums ====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated and updated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
==== options ====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&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;py-&#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.&lt;br /&gt;
==== replaces ====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&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/$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;saveas-&#039; to the protocol and append &#039;/software-1.0.tar.gz&#039; (for instance) to the end of the URI, like so:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;saveas-http://oss.example.org/?get=software&amp;amp;ver=1.0/software-1.0.tar.gz&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;
:* 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.gz / .tgz&lt;br /&gt;
:** .tar.bz2&lt;br /&gt;
:** .tar.lzma&lt;br /&gt;
:** .tar.xz&lt;br /&gt;
:** .zip&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 ways:&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;
: For more information, see the [[APKBUILD Reference#Subpackages_Example|Subpackages Example]].&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;
= Functions =&lt;br /&gt;
{{Note|All functions 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;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
==== dev() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
==== doc() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;&#039;&#039;return 0&#039;&#039;&#039;&#039;&#039;&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: &#039;&#039;&#039;&#039;&#039;mkdir -p &amp;quot;$pkgdir&amp;quot; &amp;amp;&amp;amp; return 0&#039;&#039;&#039;&#039;&#039;&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;
&lt;br /&gt;
= Examples =&lt;br /&gt;
The following APKBUILD examples will assist you in understanding how to create an APKBUILD.&lt;br /&gt;
&lt;br /&gt;
== Subpackages Example ==&lt;br /&gt;
Consider the following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It will ...&lt;br /&gt;
* create the following 5 packages:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
* using the following 5 package functions (respectively) to fill them with files:&lt;br /&gt;
# &#039;&#039;package()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$pkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;dev()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;doc()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
&lt;br /&gt;
== Simple APKBUILD ==&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== APKBUILD with Multiple Subpackages ==&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4854</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4854"/>
		<updated>2011-01-18T01:05:53Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: &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;
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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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 (i.e., &#039;&#039;_builddir&#039;&#039;).}}&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
==== subpkgdir ====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
==== arch ====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, 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).&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 &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039;.  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;
==== 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.&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;
==== 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;
&lt;br /&gt;
: First, a few notes regarding install scripts:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;{{Note|When using install scripts, &#039;&#039;$install&#039;&#039; should be included in &#039;&#039;source&#039;&#039; so that checksums can be generated and used for the install scripts specified in &#039;&#039;install&#039;&#039;.  For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
install=&amp;quot;$pkgname.pre-install $pkgname.post-install&amp;quot;&lt;br /&gt;
source=&amp;quot;http://....&lt;br /&gt;
       $install&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;}}&lt;br /&gt;
{{Note|Always use &amp;lt;code&amp;gt;/bin/sh&amp;lt;/code&amp;gt; for the command-line interpreter on the [http://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&#039;&#039; the package is installed.  Typical use is when the package needs a user/group 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;
adduser -H -s /bin/false -D clamav 2&amp;gt;/dev/null&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 &#039;&#039;&#039;&#039;&#039;exit 0&#039;&#039;&#039;&#039;&#039; 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&#039;&#039; the package is installed.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;before upgrading&#039;&#039; the package.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;after upgrading&#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;
==== license ====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
==== makedepends ====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
==== md5sums ====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated and updated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
==== options ====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&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;py-&#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.&lt;br /&gt;
==== replaces ====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&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/$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;saveas-&#039; to the protocol and append &#039;/software-1.0.tar.gz&#039; (for instance) to the end of the URI, like so:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;saveas-http://oss.example.org/?get=software&amp;amp;ver=1.0/software-1.0.tar.gz&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;
:* 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.gz / .tgz&lt;br /&gt;
:** .tar.bz2&lt;br /&gt;
:** .tar.lzma&lt;br /&gt;
:** .tar.xz&lt;br /&gt;
:** .zip&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 ways:&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;
: For more information, see the [[APKBUILD Reference#Subpackages_Example|Subpackages Example]].&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;
= Functions =&lt;br /&gt;
{{Note|All functions 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;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
==== dev() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
==== doc() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;&#039;&#039;return 0&#039;&#039;&#039;&#039;&#039;&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: &#039;&#039;&#039;&#039;&#039;mkdir -p &amp;quot;$pkgdir&amp;quot; &amp;amp;&amp;amp; return 0&#039;&#039;&#039;&#039;&#039;&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;
&lt;br /&gt;
= Examples =&lt;br /&gt;
The following APKBUILD examples will assist you in understanding how to create an APKBUILD.&lt;br /&gt;
&lt;br /&gt;
== Subpackages Example ==&lt;br /&gt;
Consider the following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It will ...&lt;br /&gt;
* create the following 5 packages:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
* using the following 5 package functions (respectively) to fill them with files:&lt;br /&gt;
# &#039;&#039;package()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$pkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;dev()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;doc()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
&lt;br /&gt;
== Simple APKBUILD ==&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== APKBUILD with Multiple Subpackages ==&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4853</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4853"/>
		<updated>2011-01-17T08:55:04Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: /* pkgname */&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;
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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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 (i.e., &#039;&#039;_builddir&#039;&#039;).}}&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
==== subpkgdir ====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
==== arch ====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, 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).&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 &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039;.  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;
==== 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.&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;
==== 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;
&lt;br /&gt;
: First, a few notes regarding install scripts:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;{{Note|When using install scripts, &#039;&#039;$install&#039;&#039; should be included in &#039;&#039;source&#039;&#039; so that checksums can be generated and used for the install scripts specified in &#039;&#039;install&#039;&#039;.  For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
install=&amp;quot;$pkgname.pre-install $pkgname.post-install&amp;quot;&lt;br /&gt;
source=&amp;quot;http://....&lt;br /&gt;
       $install&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;}}&lt;br /&gt;
{{Note|Always use &amp;lt;code&amp;gt;/bin/sh&amp;lt;/code&amp;gt; for the command-line interpreter on the [http://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&#039;&#039; the package is installed.  Typical use is when the package needs a user/group 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;
adduser -H -s /bin/false -D clamav 2&amp;gt;/dev/null&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 &#039;&#039;&#039;&#039;&#039;exit 0&#039;&#039;&#039;&#039;&#039; 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&#039;&#039; the package is installed.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;before upgrading&#039;&#039; the package.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;after upgrading&#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;
==== license ====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
==== makedepends ====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
==== md5sums ====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated and updated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
==== options ====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&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;py-&#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.&lt;br /&gt;
==== replaces ====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&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/$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;saveas-&#039; to the protocol and append &#039;/software-1.0.tar.gz&#039; (for instance) to the end of the URI, like so:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;saveas-http://oss.example.org/?get=software&amp;amp;ver=1.0/software-1.0.tar.gz&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;
:* 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.gz / .tgz&lt;br /&gt;
:** .tar.bz2&lt;br /&gt;
:** .tar.lzma&lt;br /&gt;
:** .tar.xz&lt;br /&gt;
:** .zip&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 ways:&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;
==== 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;
= Functions =&lt;br /&gt;
{{Note|All functions 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;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
==== dev() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
==== doc() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;&#039;&#039;return 0&#039;&#039;&#039;&#039;&#039;&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: &#039;&#039;&#039;&#039;&#039;mkdir -p &amp;quot;$pkgdir&amp;quot; &amp;amp;&amp;amp; return 0&#039;&#039;&#039;&#039;&#039;&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;
&lt;br /&gt;
= Examples =&lt;br /&gt;
The following APKBUILD examples will assist you in understanding how to create an APKBUILD.&lt;br /&gt;
&lt;br /&gt;
== Subpackages Example ==&lt;br /&gt;
Consider the following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It will ...&lt;br /&gt;
* create the following 5 packages:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
* using the following 5 package functions (respectively) to fill them with files:&lt;br /&gt;
# &#039;&#039;package()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$pkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;dev()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;doc()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
&lt;br /&gt;
== Simple APKBUILD ==&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== APKBUILD with Multiple Subpackages ==&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4852</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4852"/>
		<updated>2011-01-17T08:50:10Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: /* Variables */&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;
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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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 (i.e., &#039;&#039;_builddir&#039;&#039;).}}&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
==== subpkgdir ====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
==== arch ====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, 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).&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 &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039;.  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;
==== 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.&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;
==== 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;
&lt;br /&gt;
: First, a few notes regarding install scripts:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;{{Note|When using install scripts, &#039;&#039;$install&#039;&#039; should be included in &#039;&#039;source&#039;&#039; so that checksums can be generated and used for the install scripts specified in &#039;&#039;install&#039;&#039;.  For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
install=&amp;quot;$pkgname.pre-install $pkgname.post-install&amp;quot;&lt;br /&gt;
source=&amp;quot;http://....&lt;br /&gt;
       $install&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;}}&lt;br /&gt;
{{Note|Always use &amp;lt;code&amp;gt;/bin/sh&amp;lt;/code&amp;gt; for the command-line interpreter on the [http://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&#039;&#039; the package is installed.  Typical use is when the package needs a user/group 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;
adduser -H -s /bin/false -D clamav 2&amp;gt;/dev/null&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 &#039;&#039;&#039;&#039;&#039;exit 0&#039;&#039;&#039;&#039;&#039; 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&#039;&#039; the package is installed.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;before upgrading&#039;&#039; the package.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;after upgrading&#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;
==== license ====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
==== makedepends ====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
==== md5sums ====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated and updated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
==== options ====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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.&lt;br /&gt;
==== replaces ====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&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/$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;saveas-&#039; to the protocol and append &#039;/software-1.0.tar.gz&#039; (for instance) to the end of the URI, like so:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;saveas-http://oss.example.org/?get=software&amp;amp;ver=1.0/software-1.0.tar.gz&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;
:* 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.gz / .tgz&lt;br /&gt;
:** .tar.bz2&lt;br /&gt;
:** .tar.lzma&lt;br /&gt;
:** .tar.xz&lt;br /&gt;
:** .zip&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 ways:&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;
==== 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;
= Functions =&lt;br /&gt;
{{Note|All functions 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;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
==== dev() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
==== doc() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;&#039;&#039;return 0&#039;&#039;&#039;&#039;&#039;&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: &#039;&#039;&#039;&#039;&#039;mkdir -p &amp;quot;$pkgdir&amp;quot; &amp;amp;&amp;amp; return 0&#039;&#039;&#039;&#039;&#039;&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;
&lt;br /&gt;
= Examples =&lt;br /&gt;
The following APKBUILD examples will assist you in understanding how to create an APKBUILD.&lt;br /&gt;
&lt;br /&gt;
== Subpackages Example ==&lt;br /&gt;
Consider the following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It will ...&lt;br /&gt;
* create the following 5 packages:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
* using the following 5 package functions (respectively) to fill them with files:&lt;br /&gt;
# &#039;&#039;package()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$pkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;dev()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;doc()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
&lt;br /&gt;
== Simple APKBUILD ==&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== APKBUILD with Multiple Subpackages ==&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4851</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4851"/>
		<updated>2011-01-17T06:16:43Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: &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;
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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
{{Tip|All arbitrary variable and function names should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
==== subpkgdir ====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
==== arch ====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, 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).&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 &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039;.  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;
==== 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.&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;
==== 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;
&lt;br /&gt;
: First, a few notes regarding install scripts:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;{{Note|When using install scripts, &#039;&#039;$install&#039;&#039; should be included in &#039;&#039;source&#039;&#039; so that checksums can be generated and used for the install scripts specified in &#039;&#039;install&#039;&#039;.  For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
install=&amp;quot;$pkgname.pre-install $pkgname.post-install&amp;quot;&lt;br /&gt;
source=&amp;quot;http://....&lt;br /&gt;
       $install&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;}}&lt;br /&gt;
{{Note|Always use &amp;lt;code&amp;gt;/bin/sh&amp;lt;/code&amp;gt; for the command-line interpreter on the [http://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&#039;&#039; the package is installed.  Typical use is when the package needs a user/group 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;
adduser -H -s /bin/false -D clamav 2&amp;gt;/dev/null&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 &#039;&#039;&#039;&#039;&#039;exit 0&#039;&#039;&#039;&#039;&#039; 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&#039;&#039; the package is installed.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;before upgrading&#039;&#039; the package.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;after upgrading&#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;
==== license ====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
==== makedepends ====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
==== md5sums ====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated and updated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
==== options ====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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.&lt;br /&gt;
==== replaces ====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&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/$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;saveas-&#039; to the protocol and append &#039;/software-1.0.tar.gz&#039; (for instance) to the end of the URI, like so:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;saveas-http://oss.example.org/?get=software&amp;amp;ver=1.0/software-1.0.tar.gz&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;
:* 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.gz / .tgz&lt;br /&gt;
:** .tar.bz2&lt;br /&gt;
:** .tar.lzma&lt;br /&gt;
:** .tar.xz&lt;br /&gt;
:** .zip&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 ways:&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;
==== 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;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions 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;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
==== dev() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
==== doc() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;&#039;&#039;return 0&#039;&#039;&#039;&#039;&#039;&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: &#039;&#039;&#039;&#039;&#039;mkdir -p &amp;quot;$pkgdir&amp;quot; &amp;amp;&amp;amp; return 0&#039;&#039;&#039;&#039;&#039;&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;
&lt;br /&gt;
= Examples =&lt;br /&gt;
The following APKBUILD examples will assist you in understanding how to create an APKBUILD.&lt;br /&gt;
&lt;br /&gt;
== Subpackages Example ==&lt;br /&gt;
Consider the following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It will ...&lt;br /&gt;
* create the following 5 packages:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
* using the following 5 package functions (respectively) to fill them with files:&lt;br /&gt;
# &#039;&#039;package()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$pkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;dev()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;doc()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
&lt;br /&gt;
== Simple APKBUILD ==&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== APKBUILD with Multiple Subpackages ==&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4850</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4850"/>
		<updated>2011-01-17T06:13:04Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: /* install */&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;
This page is intended to serve as a quick 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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
{{Tip|All arbitrary variable and function names should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
==== subpkgdir ====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
==== arch ====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, 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).&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 &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039;.  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;
==== 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.&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;
==== 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;
&lt;br /&gt;
: First, a few notes regarding install scripts:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;{{Note|When using install scripts, &#039;&#039;$install&#039;&#039; should be included in &#039;&#039;source&#039;&#039; so that checksums can be generated and used for the install scripts specified in &#039;&#039;install&#039;&#039;.  For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
install=&amp;quot;$pkgname.pre-install $pkgname.post-install&amp;quot;&lt;br /&gt;
source=&amp;quot;http://....&lt;br /&gt;
       $install&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;}}&lt;br /&gt;
{{Note|Always use &amp;lt;code&amp;gt;/bin/sh&amp;lt;/code&amp;gt; for the command-line interpreter on the [http://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&#039;&#039; the package is installed.  Typical use is when the package needs a user/group 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;
adduser -H -s /bin/false -D clamav 2&amp;gt;/dev/null&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 &#039;&#039;&#039;&#039;&#039;exit 0&#039;&#039;&#039;&#039;&#039; 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&#039;&#039; the package is installed.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;before upgrading&#039;&#039; the package.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;after upgrading&#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;
==== license ====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
==== makedepends ====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
==== md5sums ====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated and updated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
==== options ====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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.&lt;br /&gt;
==== replaces ====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&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/$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;saveas-&#039; to the protocol and append &#039;/software-1.0.tar.gz&#039; (for instance) to the end of the URI, like so:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;saveas-http://oss.example.org/?get=software&amp;amp;ver=1.0/software-1.0.tar.gz&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;
:* 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.gz / .tgz&lt;br /&gt;
:** .tar.bz2&lt;br /&gt;
:** .tar.lzma&lt;br /&gt;
:** .tar.xz&lt;br /&gt;
:** .zip&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 ways:&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;
==== 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;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions 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;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
==== dev() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
==== doc() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;&#039;&#039;return 0&#039;&#039;&#039;&#039;&#039;&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: &#039;&#039;&#039;&#039;&#039;mkdir -p &amp;quot;$pkgdir&amp;quot; &amp;amp;&amp;amp; return 0&#039;&#039;&#039;&#039;&#039;&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;
&lt;br /&gt;
= Examples =&lt;br /&gt;
The following APKBUILD examples will assist you in understanding how to create an APKBUILD.&lt;br /&gt;
&lt;br /&gt;
== Subpackages Example ==&lt;br /&gt;
Consider the following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It will ...&lt;br /&gt;
* create the following 5 packages:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
* using the following 5 package functions (respectively) to fill them with files:&lt;br /&gt;
# &#039;&#039;package()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$pkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;dev()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;doc()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
&lt;br /&gt;
== Simple APKBUILD ==&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== APKBUILD with Multiple Subpackages ==&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4849</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4849"/>
		<updated>2011-01-17T06:08:29Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: WIP: Aggregating important information from the &amp;quot;Creating an Alpine package&amp;quot; page&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;
This page is intended to serve as a quick 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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
{{Tip|All arbitrary variable and function names should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
==== subpkgdir ====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
==== arch ====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, 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).&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 &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039;.  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;
==== 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.&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;
==== 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, pre-upgrade, pre-deinstall, post-install, post-upgrade&#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;
&lt;br /&gt;
: First, a few notes regarding install scripts:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;{{Note|When using install scripts, &#039;&#039;$install&#039;&#039; should be included in &#039;&#039;source&#039;&#039; so that checksums can be generated and used for the install scripts specified in &#039;&#039;install&#039;&#039;.  For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
install=&amp;quot;$pkgname.pre-install $pkgname.post-install&amp;quot;&lt;br /&gt;
source=&amp;quot;http://....&lt;br /&gt;
       $install&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;}}&lt;br /&gt;
{{Note|Always use &amp;lt;code&amp;gt;/bin/sh&amp;lt;/code&amp;gt; for the command-line interpreter on the [http://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&#039;&#039; the package is installed.  Typical use is when the package needs a user/group 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;
adduser -H -s /bin/false -D clamav 2&amp;gt;/dev/null&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 &#039;&#039;&#039;&#039;&#039;exit 0&#039;&#039;&#039;&#039;&#039; 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&#039;&#039; the package is installed.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;before upgrading&#039;&#039; the package.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-upgrade =====&lt;br /&gt;
: This script is executed &#039;&#039;after upgrading&#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;
==== license ====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
==== makedepends ====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
==== md5sums ====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated and updated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
==== options ====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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.&lt;br /&gt;
==== replaces ====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&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/$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;saveas-&#039; to the protocol and append &#039;/software-1.0.tar.gz&#039; (for instance) to the end of the URI, like so:&lt;br /&gt;
:: &amp;lt;pre&amp;gt;saveas-http://oss.example.org/?get=software&amp;amp;ver=1.0/software-1.0.tar.gz&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;
:* 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.gz / .tgz&lt;br /&gt;
:** .tar.bz2&lt;br /&gt;
:** .tar.lzma&lt;br /&gt;
:** .tar.xz&lt;br /&gt;
:** .zip&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 ways:&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;
==== 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;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions 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;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
==== dev() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
==== doc() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;&#039;&#039;return 0&#039;&#039;&#039;&#039;&#039;&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: &#039;&#039;&#039;&#039;&#039;mkdir -p &amp;quot;$pkgdir&amp;quot; &amp;amp;&amp;amp; return 0&#039;&#039;&#039;&#039;&#039;&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;
&lt;br /&gt;
= Examples =&lt;br /&gt;
The following APKBUILD examples will assist you in understanding how to create an APKBUILD.&lt;br /&gt;
&lt;br /&gt;
== Subpackages Example ==&lt;br /&gt;
Consider the following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It will ...&lt;br /&gt;
* create the following 5 packages:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
* using the following 5 package functions (respectively) to fill them with files:&lt;br /&gt;
# &#039;&#039;package()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$pkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;dev()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;doc()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
&lt;br /&gt;
== Simple APKBUILD ==&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== APKBUILD with Multiple Subpackages ==&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4847</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4847"/>
		<updated>2011-01-17T04:22:17Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: Moved &amp;quot;Subpackages Example&amp;quot; into the &amp;quot;Examples&amp;quot; section, expanded TOC for &amp;quot;Examples&amp;quot; section, moved a few a note or two, updated some wording&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;
This page is intended to serve as a quick 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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
{{Tip|All arbitrary variable and function names should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
==== subpkgdir ====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
==== arch ====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, 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).&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 &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039;.  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;
==== 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.&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;
==== install ====&lt;br /&gt;
: Pre/Post- Install/Upgrade/Deinstall scripts.  These are used to provide additional help when installing/upgrading/deinstalling a package, and are named &#039;&#039;&#039;$pkgname.{pre,post}-{install,upgrade,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;
==== license ====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
==== makedepends ====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
==== md5sums ====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated and updated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
==== options ====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&lt;br /&gt;
==== pkgdesc ====&lt;br /&gt;
: Short description of the package.&lt;br /&gt;
==== pkggroups ====&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in a &#039;&#039;&#039;$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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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 a &#039;&#039;&#039;$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.&lt;br /&gt;
==== replaces ====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&lt;br /&gt;
==== source ====&lt;br /&gt;
: URL(s) to sources and patches.  It can also list local files included along-side the APKBUILD, such as patches, init.d scripts, conf.d files, etc.&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 ways:&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;
==== 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;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions 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;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
==== dev() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
==== doc() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;&#039;&#039;return 0&#039;&#039;&#039;&#039;&#039;&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: &#039;&#039;&#039;&#039;&#039;mkdir -p &amp;quot;$pkgdir&amp;quot; &amp;amp;&amp;amp; return 0&#039;&#039;&#039;&#039;&#039;&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;
&lt;br /&gt;
= Examples =&lt;br /&gt;
The following APKBUILD examples will assist you in understanding how to create an APKBUILD.&lt;br /&gt;
&lt;br /&gt;
== Subpackages Example ==&lt;br /&gt;
Consider the following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It will ...&lt;br /&gt;
* create the following 5 packages:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
* using the following 5 package functions (respectively) to fill them with files:&lt;br /&gt;
# &#039;&#039;package()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$pkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;dev()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;doc()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
&lt;br /&gt;
== Simple APKBUILD ==&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== APKBUILD with Multiple Subpackages ==&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4846</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4846"/>
		<updated>2011-01-17T03:59:33Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: Absorbed &amp;quot;Subpackages&amp;quot; section into the &amp;quot;subpackages&amp;quot; variable description&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;
This page is intended to serve as a quick 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;
* 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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
==== subpkgdir ====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
==== arch ====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, all&#039;&#039;&#039;, or &#039;&#039;&#039;noarch&#039;&#039;&#039;, where &#039;&#039;&#039;&#039;&#039;all&#039;&#039;&#039;&#039;&#039; means all architectures, and &#039;&#039;&#039;&#039;&#039;noarch&#039;&#039;&#039;&#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;&#039;noarch&#039;&#039;&#039;: First specify &#039;&#039;&#039;all&#039;&#039;&#039; and then build the package by executing &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039;.  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;
==== 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.&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;
==== install ====&lt;br /&gt;
: Pre/Post- Install/Upgrade/Deinstall scripts.  These are used to provide additional help when installing/upgrading/deinstalling a package, and are named &#039;&#039;&#039;$pkgname.{pre,post}-{install,upgrade,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;
==== license ====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
==== makedepends ====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
==== md5sums ====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated and updated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
==== options ====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&lt;br /&gt;
==== pkgdesc ====&lt;br /&gt;
: Short description of the package.&lt;br /&gt;
==== pkggroups ====&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in a &#039;&#039;&#039;$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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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 a &#039;&#039;&#039;$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.&lt;br /&gt;
==== replaces ====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&lt;br /&gt;
==== source ====&lt;br /&gt;
: URL(s) to sources and patches.  It can also list local files included along-side the APKBUILD, such as patches, init.d scripts, conf.d files, etc.&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 ways:&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;
===== Subpackages Example =====&lt;br /&gt;
: Consider the following APKBUILD snippet:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;pre&amp;gt;pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&amp;lt;/pre&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
: It will ...&lt;br /&gt;
:* create the following 5 packages:&lt;br /&gt;
:# foo (main)&lt;br /&gt;
:# foo-dev (sub)&lt;br /&gt;
:# foo-doc (sub)&lt;br /&gt;
:# py-foo (sub)&lt;br /&gt;
:# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
:* using the following 5 package functions (respectively) to fill them with files:&lt;br /&gt;
:# &#039;&#039;package()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$pkgdir&#039;&#039; variable).&lt;br /&gt;
:# &#039;&#039;dev()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;dev()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
:# &#039;&#039;doc()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;doc()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
:# &#039;&#039;pysub()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
:# &#039;&#039;libfoo()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&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;
{{Tip|All custom user-specified variables and functions should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions 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;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
==== dev() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
==== doc() ====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;&#039;&#039;return 0&#039;&#039;&#039;&#039;&#039;&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: &#039;&#039;&#039;&#039;&#039;mkdir -p &amp;quot;$pkgdir&amp;quot; &amp;amp;&amp;amp; return 0&#039;&#039;&#039;&#039;&#039;&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;
&lt;br /&gt;
= Examples =&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4845</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4845"/>
		<updated>2011-01-17T02:34:55Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: Updated wording in &amp;quot;Subpackages Example&amp;quot; section and updated the description of the &amp;quot;md5sums&amp;quot; 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;
This page is intended to serve as a quick 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;
* 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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
===== subpkgdir =====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
===== arch =====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, all&#039;&#039;&#039;, or &#039;&#039;&#039;noarch&#039;&#039;&#039;, where &#039;&#039;&#039;&#039;&#039;all&#039;&#039;&#039;&#039;&#039; means all architectures, and &#039;&#039;&#039;&#039;&#039;noarch&#039;&#039;&#039;&#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;&#039;noarch&#039;&#039;&#039;: First specify &#039;&#039;&#039;all&#039;&#039;&#039; and then build the package by executing &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039;.  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.&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;
===== install =====&lt;br /&gt;
: Pre/Post- Install/Upgrade/Deinstall scripts.  These are used to provide additional help when installing/upgrading/deinstalling a package, and are named &#039;&#039;&#039;$pkgname.{pre,post}-{install,upgrade,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;
===== license =====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
===== makedepends =====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
===== md5sums =====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated and updated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
===== options =====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&lt;br /&gt;
===== pkgdesc =====&lt;br /&gt;
: Short description of the package.&lt;br /&gt;
===== pkggroups =====&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in a &#039;&#039;&#039;$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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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 a &#039;&#039;&#039;$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.&lt;br /&gt;
===== replaces =====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&lt;br /&gt;
===== source =====&lt;br /&gt;
: URL(s) to sources and patches.  It can also list local files included along-side the APKBUILD, such as patches, init.d scripts, conf.d files, etc.&lt;br /&gt;
===== subpackages =====&lt;br /&gt;
: Subpackages built from this APKBUILD.  Subpackages are usually prefixed with &#039;&#039;&#039;$pkgname-&#039;&#039;&#039;, with the remainder of the subpackage name being used as the name of the package function for the subpackage.  For example, if &#039;&#039;subpackages&#039;&#039; is set to &#039;&#039;&#039;$pkgname-extra&#039;&#039;&#039;, this will create a subpackage called &#039;&#039;&#039;&#039;&#039;$pkgname&#039;&#039;-extra&#039;&#039;&#039;, which is packaged using a custom &#039;&#039;extra()&#039;&#039; function. (See the [[APKBUILD Reference#Subpackages_2|Subpackages]] section below for more information.)&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;
{{Tip|All custom user-specified variables and functions should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions 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;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
===== dev() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
===== doc() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;&#039;&#039;return 0&#039;&#039;&#039;&#039;&#039;&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: &#039;&#039;&#039;&#039;&#039;mkdir -p &amp;quot;$pkgdir&amp;quot; &amp;amp;&amp;amp; return 0&#039;&#039;&#039;&#039;&#039;&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;
&lt;br /&gt;
= Subpackages =&lt;br /&gt;
Subpackages are specified in the &#039;&#039;subpackages&#039;&#039; variable.  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 ways:&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;
== Subpackages Example ==&lt;br /&gt;
The following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* will create the following 5 packages:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
* using the following 5 package functions (respectively) to fill them with files:&lt;br /&gt;
# &#039;&#039;package()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$pkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;dev()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039;: will be provided by abuild unless we override it, by providing our own &#039;&#039;doc()&#039;&#039; function (which can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039;: will be provided by the user (and can make use of the &#039;&#039;$subpkgdir&#039;&#039; variable).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4838</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4838"/>
		<updated>2011-01-13T08:56:49Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: Inserted some line breaks; should be final edit for a while&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;
This page is intended to serve as a quick 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;
* 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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
===== subpkgdir =====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
===== arch =====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, all&#039;&#039;&#039;, or &#039;&#039;&#039;noarch&#039;&#039;&#039;, where &#039;&#039;&#039;&#039;&#039;all&#039;&#039;&#039;&#039;&#039; means all architectures, and &#039;&#039;&#039;&#039;&#039;noarch&#039;&#039;&#039;&#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;&#039;noarch&#039;&#039;&#039;: First specify &#039;&#039;&#039;all&#039;&#039;&#039; and then build the package by executing &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039;.  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.&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;
===== install =====&lt;br /&gt;
: Pre/Post- Install/Upgrade/Deinstall scripts.  These are used to provide additional help when installing/upgrading/deinstalling a package, and are named &#039;&#039;&#039;$pkgname.{pre,post}-{install,upgrade,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;
===== license =====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
===== makedepends =====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
===== md5sums =====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
===== options =====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&lt;br /&gt;
===== pkgdesc =====&lt;br /&gt;
: Short description of the package.&lt;br /&gt;
===== pkggroups =====&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in a &#039;&#039;&#039;$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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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 a &#039;&#039;&#039;$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.&lt;br /&gt;
===== replaces =====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&lt;br /&gt;
===== source =====&lt;br /&gt;
: URL(s) to sources and patches.  It can also list local files included along-side the APKBUILD, such as patches, init.d scripts, conf.d files, etc.&lt;br /&gt;
===== subpackages =====&lt;br /&gt;
: Subpackages built from this APKBUILD.  Subpackages are usually prefixed with &#039;&#039;&#039;$pkgname-&#039;&#039;&#039;, with the remainder of the subpackage name being used as the name of the package function for the subpackage.  For example, if &#039;&#039;subpackages&#039;&#039; is set to &#039;&#039;&#039;$pkgname-extra&#039;&#039;&#039;, this will create a subpackage called &#039;&#039;&#039;&#039;&#039;$pkgname&#039;&#039;-extra&#039;&#039;&#039;, which is packaged using a custom &#039;&#039;extra()&#039;&#039; function. (See the [[APKBUILD Reference#Subpackages_2|Subpackages]] section below for more information.)&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;
{{Tip|All custom user-specified variables and functions should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions 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;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
===== dev() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
===== doc() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;&#039;&#039;return 0&#039;&#039;&#039;&#039;&#039;&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: &#039;&#039;&#039;&#039;&#039;mkdir -p &amp;quot;$pkgdir&amp;quot; &amp;amp;&amp;amp; return 0&#039;&#039;&#039;&#039;&#039;&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;
&lt;br /&gt;
= Subpackages =&lt;br /&gt;
Subpackages are specified in the &#039;&#039;subpackages&#039;&#039; variable.  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 ways:&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;
== Subpackages Example ==&lt;br /&gt;
The following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
... will create the 5 packages in total:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
The split functions for the 4 subpackages are:&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039; (provided by the user)&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039; (provided by the user)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4837</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4837"/>
		<updated>2011-01-13T06:37:39Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: /* arch */ Updated info on determining use of noarch&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;
This page is intended to serve as a quick 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;
* 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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
===== subpkgdir =====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
===== arch =====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, all&#039;&#039;&#039;, or &#039;&#039;&#039;noarch&#039;&#039;&#039;, where &#039;&#039;&#039;&#039;&#039;all&#039;&#039;&#039;&#039;&#039; means all architectures, and &#039;&#039;&#039;&#039;&#039;noarch&#039;&#039;&#039;&#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;&#039;noarch&#039;&#039;&#039;: First specify &#039;&#039;&#039;all&#039;&#039;&#039; and then build the package by executing &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039;.  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.&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;
===== install =====&lt;br /&gt;
: Pre/Post- Install/Upgrade/Deinstall scripts.  These are used to provide additional help when installing/upgrading/deinstalling a package, and are named &#039;&#039;&#039;$pkgname.{pre,post}-{install,upgrade,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;
===== license =====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
===== makedepends =====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
===== md5sums =====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
===== options =====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&lt;br /&gt;
===== pkgdesc =====&lt;br /&gt;
: Short description of the package.&lt;br /&gt;
===== pkggroups =====&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in a &#039;&#039;&#039;$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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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 a &#039;&#039;&#039;$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.&lt;br /&gt;
===== replaces =====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&lt;br /&gt;
===== source =====&lt;br /&gt;
: URL(s) to sources and patches.  It can also list local files included along-side the APKBUILD, such as patches, init.d scripts, conf.d files, etc.&lt;br /&gt;
===== subpackages =====&lt;br /&gt;
: Subpackages built from this APKBUILD.  Subpackages are usually prefixed with &#039;&#039;&#039;$pkgname-&#039;&#039;&#039;, with the remainder of the subpackage name being used as the name of the package function for the subpackage.  For example, if &#039;&#039;subpackages&#039;&#039; is set to &#039;&#039;&#039;$pkgname-extra&#039;&#039;&#039;, this will create a subpackage called &#039;&#039;&#039;&#039;&#039;$pkgname&#039;&#039;-extra&#039;&#039;&#039;, which is packaged using a custom &#039;&#039;extra()&#039;&#039; function. (See the [[APKBUILD Reference#Subpackages_2|Subpackages]] section below for more information.)&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;
{{Tip|All custom user-specified variables and functions should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions 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;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
===== dev() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
===== doc() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;&#039;&#039;return 0&#039;&#039;&#039;&#039;&#039;&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: &#039;&#039;&#039;&#039;&#039;mkdir -p &amp;quot;$pkgdir&amp;quot; &amp;amp;&amp;amp; return 0&#039;&#039;&#039;&#039;&#039;&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;
= Subpackages =&lt;br /&gt;
Subpackages are specified in the &#039;&#039;subpackages&#039;&#039; variable.  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 ways:&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;
== Subpackages Example ==&lt;br /&gt;
The following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
... will create the 5 packages in total:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
The split functions for the 4 subpackages are:&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039; (provided by the user)&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039; (provided by the user)&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4836</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4836"/>
		<updated>2011-01-13T06:26:56Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: /* arch */ Updated wording&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;
This page is intended to serve as a quick 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;
* 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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
===== subpkgdir =====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
===== arch =====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, all&#039;&#039;&#039;, or &#039;&#039;&#039;noarch&#039;&#039;&#039;, where &#039;&#039;&#039;&#039;&#039;all&#039;&#039;&#039;&#039;&#039; means all architectures, and &#039;&#039;&#039;&#039;&#039;noarch&#039;&#039;&#039;&#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;&#039;noarch&#039;&#039;&#039;: First specify &#039;&#039;&#039;all&#039;&#039;&#039; and then build the package by executing &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039;.  Once built, execute &#039;&#039;&#039;&#039;&#039;scanelf -R pkg&#039;&#039;&#039;&#039;&#039;.  (This scans for ELF files in the &#039;&#039;./pkg&#039;&#039; directory.)  If you do not get output from this, then &#039;&#039;&#039;noarch&#039;&#039;&#039; can be used.}}&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.&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;
===== install =====&lt;br /&gt;
: Pre/Post- Install/Upgrade/Deinstall scripts.  These are used to provide additional help when installing/upgrading/deinstalling a package, and are named &#039;&#039;&#039;$pkgname.{pre,post}-{install,upgrade,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;
===== license =====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
===== makedepends =====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
===== md5sums =====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
===== options =====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&lt;br /&gt;
===== pkgdesc =====&lt;br /&gt;
: Short description of the package.&lt;br /&gt;
===== pkggroups =====&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in a &#039;&#039;&#039;$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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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 a &#039;&#039;&#039;$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.&lt;br /&gt;
===== replaces =====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&lt;br /&gt;
===== source =====&lt;br /&gt;
: URL(s) to sources and patches.  It can also list local files included along-side the APKBUILD, such as patches, init.d scripts, conf.d files, etc.&lt;br /&gt;
===== subpackages =====&lt;br /&gt;
: Subpackages built from this APKBUILD.  Subpackages are usually prefixed with &#039;&#039;&#039;$pkgname-&#039;&#039;&#039;, with the remainder of the subpackage name being used as the name of the package function for the subpackage.  For example, if &#039;&#039;subpackages&#039;&#039; is set to &#039;&#039;&#039;$pkgname-extra&#039;&#039;&#039;, this will create a subpackage called &#039;&#039;&#039;&#039;&#039;$pkgname&#039;&#039;-extra&#039;&#039;&#039;, which is packaged using a custom &#039;&#039;extra()&#039;&#039; function. (See the [[APKBUILD Reference#Subpackages_2|Subpackages]] section below for more information.)&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;
{{Tip|All custom user-specified variables and functions should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions 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;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
===== dev() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
===== doc() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;&#039;&#039;return 0&#039;&#039;&#039;&#039;&#039;&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: &#039;&#039;&#039;&#039;&#039;mkdir -p &amp;quot;$pkgdir&amp;quot; &amp;amp;&amp;amp; return 0&#039;&#039;&#039;&#039;&#039;&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;
= Subpackages =&lt;br /&gt;
Subpackages are specified in the &#039;&#039;subpackages&#039;&#039; variable.  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 ways:&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;
== Subpackages Example ==&lt;br /&gt;
The following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
... will create the 5 packages in total:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
The split functions for the 4 subpackages are:&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039; (provided by the user)&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039; (provided by the user)&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4835</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4835"/>
		<updated>2011-01-13T06:15:20Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: /* User-defined functions */&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;
This page is intended to serve as a quick 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;
* 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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
===== subpkgdir =====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
===== arch =====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, all&#039;&#039;&#039;, or &#039;&#039;&#039;noarch&#039;&#039;&#039;, where &#039;&#039;&#039;&#039;&#039;all&#039;&#039;&#039;&#039;&#039; means all architectures, and &#039;&#039;&#039;&#039;&#039;noarch&#039;&#039;&#039;&#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;&#039;noarch&#039;&#039;&#039;, first specify &#039;&#039;&#039;all&#039;&#039;&#039;, build the package by running &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039; and once built, execute &#039;&#039;&#039;&#039;&#039;scanelf -R pkg&#039;&#039;&#039;&#039;&#039;.  This scans for ELF files in the &#039;&#039;./pkg&#039;&#039; directory, where all sub-/package files reside.  If you do not get output from this, then &#039;&#039;&#039;noarch&#039;&#039;&#039; can be used.}}&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.&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;
===== install =====&lt;br /&gt;
: Pre/Post- Install/Upgrade/Deinstall scripts.  These are used to provide additional help when installing/upgrading/deinstalling a package, and are named &#039;&#039;&#039;$pkgname.{pre,post}-{install,upgrade,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;
===== license =====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
===== makedepends =====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
===== md5sums =====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
===== options =====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&lt;br /&gt;
===== pkgdesc =====&lt;br /&gt;
: Short description of the package.&lt;br /&gt;
===== pkggroups =====&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in a &#039;&#039;&#039;$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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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 a &#039;&#039;&#039;$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.&lt;br /&gt;
===== replaces =====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&lt;br /&gt;
===== source =====&lt;br /&gt;
: URL(s) to sources and patches.  It can also list local files included along-side the APKBUILD, such as patches, init.d scripts, conf.d files, etc.&lt;br /&gt;
===== subpackages =====&lt;br /&gt;
: Subpackages built from this APKBUILD.  Subpackages are usually prefixed with &#039;&#039;&#039;$pkgname-&#039;&#039;&#039;, with the remainder of the subpackage name being used as the name of the package function for the subpackage.  For example, if &#039;&#039;subpackages&#039;&#039; is set to &#039;&#039;&#039;$pkgname-extra&#039;&#039;&#039;, this will create a subpackage called &#039;&#039;&#039;&#039;&#039;$pkgname&#039;&#039;-extra&#039;&#039;&#039;, which is packaged using a custom &#039;&#039;extra()&#039;&#039; function. (See the [[APKBUILD Reference#Subpackages_2|Subpackages]] section below for more information.)&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;
{{Tip|All custom user-specified variables and functions should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions 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;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
===== dev() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
===== doc() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;&#039;&#039;return 0&#039;&#039;&#039;&#039;&#039;&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: &#039;&#039;&#039;&#039;&#039;mkdir -p &amp;quot;$pkgdir&amp;quot; &amp;amp;&amp;amp; return 0&#039;&#039;&#039;&#039;&#039;&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;
= Subpackages =&lt;br /&gt;
Subpackages are specified in the &#039;&#039;subpackages&#039;&#039; variable.  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 ways:&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;
== Subpackages Example ==&lt;br /&gt;
The following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
... will create the 5 packages in total:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
The split functions for the 4 subpackages are:&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039; (provided by the user)&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039; (provided by the user)&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4834</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4834"/>
		<updated>2011-01-13T06:14:06Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: /* package() */ Updated information on metapackages&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;
This page is intended to serve as a quick 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;
* 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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
===== subpkgdir =====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
===== arch =====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, all&#039;&#039;&#039;, or &#039;&#039;&#039;noarch&#039;&#039;&#039;, where &#039;&#039;&#039;&#039;&#039;all&#039;&#039;&#039;&#039;&#039; means all architectures, and &#039;&#039;&#039;&#039;&#039;noarch&#039;&#039;&#039;&#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;&#039;noarch&#039;&#039;&#039;, first specify &#039;&#039;&#039;all&#039;&#039;&#039;, build the package by running &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039; and once built, execute &#039;&#039;&#039;&#039;&#039;scanelf -R pkg&#039;&#039;&#039;&#039;&#039;.  This scans for ELF files in the &#039;&#039;./pkg&#039;&#039; directory, where all sub-/package files reside.  If you do not get output from this, then &#039;&#039;&#039;noarch&#039;&#039;&#039; can be used.}}&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.&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;
===== install =====&lt;br /&gt;
: Pre/Post- Install/Upgrade/Deinstall scripts.  These are used to provide additional help when installing/upgrading/deinstalling a package, and are named &#039;&#039;&#039;$pkgname.{pre,post}-{install,upgrade,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;
===== license =====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
===== makedepends =====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
===== md5sums =====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
===== options =====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&lt;br /&gt;
===== pkgdesc =====&lt;br /&gt;
: Short description of the package.&lt;br /&gt;
===== pkggroups =====&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in a &#039;&#039;&#039;$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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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 a &#039;&#039;&#039;$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.&lt;br /&gt;
===== replaces =====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&lt;br /&gt;
===== source =====&lt;br /&gt;
: URL(s) to sources and patches.  It can also list local files included along-side the APKBUILD, such as patches, init.d scripts, conf.d files, etc.&lt;br /&gt;
===== subpackages =====&lt;br /&gt;
: Subpackages built from this APKBUILD.  Subpackages are usually prefixed with &#039;&#039;&#039;$pkgname-&#039;&#039;&#039;, with the remainder of the subpackage name being used as the name of the package function for the subpackage.  For example, if &#039;&#039;subpackages&#039;&#039; is set to &#039;&#039;&#039;$pkgname-extra&#039;&#039;&#039;, this will create a subpackage called &#039;&#039;&#039;&#039;&#039;$pkgname&#039;&#039;-extra&#039;&#039;&#039;, which is packaged using a custom &#039;&#039;extra()&#039;&#039; function. (See the [[APKBUILD Reference#Subpackages_2|Subpackages]] section below for more information.)&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;
{{Tip|All custom user-specified variables and functions should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions 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;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
===== dev() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
===== doc() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;return 0&#039;&#039;&#039;&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: &#039;&#039;&#039;mkdir -p &amp;quot;$pkgdir&amp;quot; &amp;amp;&amp;amp; return 0&#039;&#039;&#039;&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;
= Subpackages =&lt;br /&gt;
Subpackages are specified in the &#039;&#039;subpackages&#039;&#039; variable.  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 ways:&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;
== Subpackages Example ==&lt;br /&gt;
The following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
... will create the 5 packages in total:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
The split functions for the 4 subpackages are:&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039; (provided by the user)&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039; (provided by the user)&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4833</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4833"/>
		<updated>2011-01-13T04:16:44Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: /* subpackages */ updated wiki link to the main &amp;quot;Subpackages&amp;quot; section&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;
This page is intended to serve as a quick 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;
* 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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
===== subpkgdir =====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
===== arch =====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, all&#039;&#039;&#039;, or &#039;&#039;&#039;noarch&#039;&#039;&#039;, where &#039;&#039;&#039;&#039;&#039;all&#039;&#039;&#039;&#039;&#039; means all architectures, and &#039;&#039;&#039;&#039;&#039;noarch&#039;&#039;&#039;&#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;&#039;noarch&#039;&#039;&#039;, first specify &#039;&#039;&#039;all&#039;&#039;&#039;, build the package by running &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039; and once built, execute &#039;&#039;&#039;&#039;&#039;scanelf -R pkg&#039;&#039;&#039;&#039;&#039;.  This scans for ELF files in the &#039;&#039;./pkg&#039;&#039; directory, where all sub-/package files reside.  If you do not get output from this, then &#039;&#039;&#039;noarch&#039;&#039;&#039; can be used.}}&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.&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;
===== install =====&lt;br /&gt;
: Pre/Post- Install/Upgrade/Deinstall scripts.  These are used to provide additional help when installing/upgrading/deinstalling a package, and are named &#039;&#039;&#039;$pkgname.{pre,post}-{install,upgrade,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;
===== license =====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
===== makedepends =====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
===== md5sums =====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
===== options =====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&lt;br /&gt;
===== pkgdesc =====&lt;br /&gt;
: Short description of the package.&lt;br /&gt;
===== pkggroups =====&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in a &#039;&#039;&#039;$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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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 a &#039;&#039;&#039;$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.&lt;br /&gt;
===== replaces =====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&lt;br /&gt;
===== source =====&lt;br /&gt;
: URL(s) to sources and patches.  It can also list local files included along-side the APKBUILD, such as patches, init.d scripts, conf.d files, etc.&lt;br /&gt;
===== subpackages =====&lt;br /&gt;
: Subpackages built from this APKBUILD.  Subpackages are usually prefixed with &#039;&#039;&#039;$pkgname-&#039;&#039;&#039;, with the remainder of the subpackage name being used as the name of the package function for the subpackage.  For example, if &#039;&#039;subpackages&#039;&#039; is set to &#039;&#039;&#039;$pkgname-extra&#039;&#039;&#039;, this will create a subpackage called &#039;&#039;&#039;&#039;&#039;$pkgname&#039;&#039;-extra&#039;&#039;&#039;, which is packaged using a custom &#039;&#039;extra()&#039;&#039; function. (See the [[APKBUILD Reference#Subpackages_2|Subpackages]] section below for more information.)&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;
{{Tip|All custom user-specified variables and functions should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions 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;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
===== dev() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
===== doc() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;return 0&#039;&#039;&#039;&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: &#039;&#039;&#039;return 0&#039;&#039;&#039;&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;
= Subpackages =&lt;br /&gt;
Subpackages are specified in the &#039;&#039;subpackages&#039;&#039; variable.  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 ways:&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;
== Subpackages Example ==&lt;br /&gt;
The following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
... will create the 5 packages in total:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
The split functions for the 4 subpackages are:&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039; (provided by the user)&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039; (provided by the user)&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4832</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4832"/>
		<updated>2011-01-13T04:12:24Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: /* Functions */ updated wording&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;
This page is intended to serve as a quick 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;
* 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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
===== subpkgdir =====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
===== arch =====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, all&#039;&#039;&#039;, or &#039;&#039;&#039;noarch&#039;&#039;&#039;, where &#039;&#039;&#039;&#039;&#039;all&#039;&#039;&#039;&#039;&#039; means all architectures, and &#039;&#039;&#039;&#039;&#039;noarch&#039;&#039;&#039;&#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;&#039;noarch&#039;&#039;&#039;, first specify &#039;&#039;&#039;all&#039;&#039;&#039;, build the package by running &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039; and once built, execute &#039;&#039;&#039;&#039;&#039;scanelf -R pkg&#039;&#039;&#039;&#039;&#039;.  This scans for ELF files in the &#039;&#039;./pkg&#039;&#039; directory, where all sub-/package files reside.  If you do not get output from this, then &#039;&#039;&#039;noarch&#039;&#039;&#039; can be used.}}&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.&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;
===== install =====&lt;br /&gt;
: Pre/Post- Install/Upgrade/Deinstall scripts.  These are used to provide additional help when installing/upgrading/deinstalling a package, and are named &#039;&#039;&#039;$pkgname.{pre,post}-{install,upgrade,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;
===== license =====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
===== makedepends =====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
===== md5sums =====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
===== options =====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&lt;br /&gt;
===== pkgdesc =====&lt;br /&gt;
: Short description of the package.&lt;br /&gt;
===== pkggroups =====&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in a &#039;&#039;&#039;$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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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 a &#039;&#039;&#039;$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.&lt;br /&gt;
===== replaces =====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&lt;br /&gt;
===== source =====&lt;br /&gt;
: URL(s) to sources and patches.  It can also list local files included along-side the APKBUILD, such as patches, init.d scripts, conf.d files, etc.&lt;br /&gt;
===== subpackages =====&lt;br /&gt;
: Subpackages built from this APKBUILD.  Subpackages are usually prefixed with &#039;&#039;&#039;$pkgname-&#039;&#039;&#039;, with the remainder of the subpackage name being used as the name of the package function for the subpackage.  For example, if &#039;&#039;subpackages&#039;&#039; is set to &#039;&#039;&#039;$pkgname-extra&#039;&#039;&#039;, this will create a subpackage called &#039;&#039;&#039;&#039;&#039;$pkgname&#039;&#039;-extra&#039;&#039;&#039;, which is packaged using a custom &#039;&#039;extra()&#039;&#039; function. (See the [[APKBUILD Reference#Subpackages|Subpackages]] section below for more information.)&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;
{{Tip|All custom user-specified variables and functions should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions 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;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
===== dev() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
===== doc() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;return 0&#039;&#039;&#039;&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: &#039;&#039;&#039;return 0&#039;&#039;&#039;&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;
= Subpackages =&lt;br /&gt;
Subpackages are specified in the &#039;&#039;subpackages&#039;&#039; variable.  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 ways:&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;
== Subpackages Example ==&lt;br /&gt;
The following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
... will create the 5 packages in total:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
The split functions for the 4 subpackages are:&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039; (provided by the user)&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039; (provided by the user)&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4831</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4831"/>
		<updated>2011-01-13T04:10:38Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: /* package() */ updated wording&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;
This page is intended to serve as a quick 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;
* 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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
===== subpkgdir =====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
===== arch =====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, all&#039;&#039;&#039;, or &#039;&#039;&#039;noarch&#039;&#039;&#039;, where &#039;&#039;&#039;&#039;&#039;all&#039;&#039;&#039;&#039;&#039; means all architectures, and &#039;&#039;&#039;&#039;&#039;noarch&#039;&#039;&#039;&#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;&#039;noarch&#039;&#039;&#039;, first specify &#039;&#039;&#039;all&#039;&#039;&#039;, build the package by running &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039; and once built, execute &#039;&#039;&#039;&#039;&#039;scanelf -R pkg&#039;&#039;&#039;&#039;&#039;.  This scans for ELF files in the &#039;&#039;./pkg&#039;&#039; directory, where all sub-/package files reside.  If you do not get output from this, then &#039;&#039;&#039;noarch&#039;&#039;&#039; can be used.}}&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.&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;
===== install =====&lt;br /&gt;
: Pre/Post- Install/Upgrade/Deinstall scripts.  These are used to provide additional help when installing/upgrading/deinstalling a package, and are named &#039;&#039;&#039;$pkgname.{pre,post}-{install,upgrade,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;
===== license =====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
===== makedepends =====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
===== md5sums =====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
===== options =====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&lt;br /&gt;
===== pkgdesc =====&lt;br /&gt;
: Short description of the package.&lt;br /&gt;
===== pkggroups =====&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in a &#039;&#039;&#039;$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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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 a &#039;&#039;&#039;$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.&lt;br /&gt;
===== replaces =====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&lt;br /&gt;
===== source =====&lt;br /&gt;
: URL(s) to sources and patches.  It can also list local files included along-side the APKBUILD, such as patches, init.d scripts, conf.d files, etc.&lt;br /&gt;
===== subpackages =====&lt;br /&gt;
: Subpackages built from this APKBUILD.  Subpackages are usually prefixed with &#039;&#039;&#039;$pkgname-&#039;&#039;&#039;, with the remainder of the subpackage name being used as the name of the package function for the subpackage.  For example, if &#039;&#039;subpackages&#039;&#039; is set to &#039;&#039;&#039;$pkgname-extra&#039;&#039;&#039;, this will create a subpackage called &#039;&#039;&#039;&#039;&#039;$pkgname&#039;&#039;-extra&#039;&#039;&#039;, which is packaged using a custom &#039;&#039;extra()&#039;&#039; function. (See the [[APKBUILD Reference#Subpackages|Subpackages]] section below for more information.)&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;
{{Tip|All custom user-specified variables and functions should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions should consider the current working directory as undefined, and therefore should use the [[APKBUILD Reference#abuild-defined_variables|abuild-defined directory variables]] to their advantage.}}&lt;br /&gt;
&lt;br /&gt;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
===== dev() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
===== doc() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;return 0&#039;&#039;&#039;&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: &#039;&#039;&#039;return 0&#039;&#039;&#039;&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;
= Subpackages =&lt;br /&gt;
Subpackages are specified in the &#039;&#039;subpackages&#039;&#039; variable.  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 ways:&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;
== Subpackages Example ==&lt;br /&gt;
The following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
... will create the 5 packages in total:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
The split functions for the 4 subpackages are:&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039; (provided by the user)&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039; (provided by the user)&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4830</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4830"/>
		<updated>2011-01-13T04:05:40Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: /* User-defined functions */ Added information to package() about metapackages&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;
This page is intended to serve as a quick 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;
* 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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
===== subpkgdir =====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
===== arch =====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, all&#039;&#039;&#039;, or &#039;&#039;&#039;noarch&#039;&#039;&#039;, where &#039;&#039;&#039;&#039;&#039;all&#039;&#039;&#039;&#039;&#039; means all architectures, and &#039;&#039;&#039;&#039;&#039;noarch&#039;&#039;&#039;&#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;&#039;noarch&#039;&#039;&#039;, first specify &#039;&#039;&#039;all&#039;&#039;&#039;, build the package by running &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039; and once built, execute &#039;&#039;&#039;&#039;&#039;scanelf -R pkg&#039;&#039;&#039;&#039;&#039;.  This scans for ELF files in the &#039;&#039;./pkg&#039;&#039; directory, where all sub-/package files reside.  If you do not get output from this, then &#039;&#039;&#039;noarch&#039;&#039;&#039; can be used.}}&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.&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;
===== install =====&lt;br /&gt;
: Pre/Post- Install/Upgrade/Deinstall scripts.  These are used to provide additional help when installing/upgrading/deinstalling a package, and are named &#039;&#039;&#039;$pkgname.{pre,post}-{install,upgrade,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;
===== license =====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
===== makedepends =====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
===== md5sums =====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
===== options =====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&lt;br /&gt;
===== pkgdesc =====&lt;br /&gt;
: Short description of the package.&lt;br /&gt;
===== pkggroups =====&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in a &#039;&#039;&#039;$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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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 a &#039;&#039;&#039;$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.&lt;br /&gt;
===== replaces =====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&lt;br /&gt;
===== source =====&lt;br /&gt;
: URL(s) to sources and patches.  It can also list local files included along-side the APKBUILD, such as patches, init.d scripts, conf.d files, etc.&lt;br /&gt;
===== subpackages =====&lt;br /&gt;
: Subpackages built from this APKBUILD.  Subpackages are usually prefixed with &#039;&#039;&#039;$pkgname-&#039;&#039;&#039;, with the remainder of the subpackage name being used as the name of the package function for the subpackage.  For example, if &#039;&#039;subpackages&#039;&#039; is set to &#039;&#039;&#039;$pkgname-extra&#039;&#039;&#039;, this will create a subpackage called &#039;&#039;&#039;&#039;&#039;$pkgname&#039;&#039;-extra&#039;&#039;&#039;, which is packaged using a custom &#039;&#039;extra()&#039;&#039; function. (See the [[APKBUILD Reference#Subpackages|Subpackages]] section below for more information.)&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;
{{Tip|All custom user-specified variables and functions should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions should consider the current working directory as undefined, and therefore should use the [[APKBUILD Reference#abuild-defined_variables|abuild-defined directory variables]] to their advantage.}}&lt;br /&gt;
&lt;br /&gt;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
===== dev() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
===== doc() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;return 0&#039;&#039;&#039;&lt;br /&gt;
===== package() =====&lt;br /&gt;
: &#039;&#039;&#039;Required.&#039;&#039;&#039;  This is the packaging stage.  This is where the built application and support files should be installed in &#039;&#039;&#039;$pkgdir&#039;&#039;&#039;.  If this is a metapackage, this function can contain a single line: &#039;&#039;&#039;return 0&#039;&#039;&#039;&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;
= Subpackages =&lt;br /&gt;
Subpackages are specified in the &#039;&#039;subpackages&#039;&#039; variable.  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 ways:&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;
== Subpackages Example ==&lt;br /&gt;
The following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
... will create the 5 packages in total:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
The split functions for the 4 subpackages are:&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039; (provided by the user)&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039; (provided by the user)&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4829</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4829"/>
		<updated>2011-01-13T04:02:48Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: /* User-defined functions */&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;
This page is intended to serve as a quick 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;
* 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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
===== subpkgdir =====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
===== arch =====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, all&#039;&#039;&#039;, or &#039;&#039;&#039;noarch&#039;&#039;&#039;, where &#039;&#039;&#039;&#039;&#039;all&#039;&#039;&#039;&#039;&#039; means all architectures, and &#039;&#039;&#039;&#039;&#039;noarch&#039;&#039;&#039;&#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;&#039;noarch&#039;&#039;&#039;, first specify &#039;&#039;&#039;all&#039;&#039;&#039;, build the package by running &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039; and once built, execute &#039;&#039;&#039;&#039;&#039;scanelf -R pkg&#039;&#039;&#039;&#039;&#039;.  This scans for ELF files in the &#039;&#039;./pkg&#039;&#039; directory, where all sub-/package files reside.  If you do not get output from this, then &#039;&#039;&#039;noarch&#039;&#039;&#039; can be used.}}&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.&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;
===== install =====&lt;br /&gt;
: Pre/Post- Install/Upgrade/Deinstall scripts.  These are used to provide additional help when installing/upgrading/deinstalling a package, and are named &#039;&#039;&#039;$pkgname.{pre,post}-{install,upgrade,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;
===== license =====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
===== makedepends =====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
===== md5sums =====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
===== options =====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&lt;br /&gt;
===== pkgdesc =====&lt;br /&gt;
: Short description of the package.&lt;br /&gt;
===== pkggroups =====&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in a &#039;&#039;&#039;$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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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 a &#039;&#039;&#039;$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.&lt;br /&gt;
===== replaces =====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&lt;br /&gt;
===== source =====&lt;br /&gt;
: URL(s) to sources and patches.  It can also list local files included along-side the APKBUILD, such as patches, init.d scripts, conf.d files, etc.&lt;br /&gt;
===== subpackages =====&lt;br /&gt;
: Subpackages built from this APKBUILD.  Subpackages are usually prefixed with &#039;&#039;&#039;$pkgname-&#039;&#039;&#039;, with the remainder of the subpackage name being used as the name of the package function for the subpackage.  For example, if &#039;&#039;subpackages&#039;&#039; is set to &#039;&#039;&#039;$pkgname-extra&#039;&#039;&#039;, this will create a subpackage called &#039;&#039;&#039;&#039;&#039;$pkgname&#039;&#039;-extra&#039;&#039;&#039;, which is packaged using a custom &#039;&#039;extra()&#039;&#039; function. (See the [[APKBUILD Reference#Subpackages|Subpackages]] section below for more information.)&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;
{{Tip|All custom user-specified variables and functions should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions should consider the current working directory as undefined, and therefore should use the [[APKBUILD Reference#abuild-defined_variables|abuild-defined directory variables]] to their advantage.}}&lt;br /&gt;
&lt;br /&gt;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
===== dev() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
===== doc() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&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;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;return 0&#039;&#039;&#039;&lt;br /&gt;
===== package() =====&lt;br /&gt;
: &#039;&#039;&#039;Required.&#039;&#039;&#039;  This is the packaging stage.  This is where the built application and support files should be installed in &#039;&#039;&#039;$pkgdir&#039;&#039;&#039;.&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;
= Subpackages =&lt;br /&gt;
Subpackages are specified in the &#039;&#039;subpackages&#039;&#039; variable.  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 ways:&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;
== Subpackages Example ==&lt;br /&gt;
The following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
... will create the 5 packages in total:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
The split functions for the 4 subpackages are:&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039; (provided by the user)&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039; (provided by the user)&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4828</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4828"/>
		<updated>2011-01-13T03:53:40Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: expanded TOC, updated some wording&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;
This page is intended to serve as a quick 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;
* 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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
===== subpkgdir =====&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
===== arch =====&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, all&#039;&#039;&#039;, or &#039;&#039;&#039;noarch&#039;&#039;&#039;, where &#039;&#039;&#039;&#039;&#039;all&#039;&#039;&#039;&#039;&#039; means all architectures, and &#039;&#039;&#039;&#039;&#039;noarch&#039;&#039;&#039;&#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;&#039;noarch&#039;&#039;&#039;, first specify &#039;&#039;&#039;all&#039;&#039;&#039;, build the package by running &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039; and once built, execute &#039;&#039;&#039;&#039;&#039;scanelf -R pkg&#039;&#039;&#039;&#039;&#039;.  This scans for ELF files in the &#039;&#039;./pkg&#039;&#039; directory, where all sub-/package files reside.  If you do not get output from this, then &#039;&#039;&#039;noarch&#039;&#039;&#039; can be used.}}&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.&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;
===== install =====&lt;br /&gt;
: Pre/Post- Install/Upgrade/Deinstall scripts.  These are used to provide additional help when installing/upgrading/deinstalling a package, and are named &#039;&#039;&#039;$pkgname.{pre,post}-{install,upgrade,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;
===== license =====&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
===== makedepends =====&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
===== md5sums =====&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
===== options =====&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&lt;br /&gt;
===== pkgdesc =====&lt;br /&gt;
: Short description of the package.&lt;br /&gt;
===== pkggroups =====&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in a &#039;&#039;&#039;$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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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 a &#039;&#039;&#039;$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.&lt;br /&gt;
===== replaces =====&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&lt;br /&gt;
===== source =====&lt;br /&gt;
: URL(s) to sources and patches.  It can also list local files included along-side the APKBUILD, such as patches, init.d scripts, conf.d files, etc.&lt;br /&gt;
===== subpackages =====&lt;br /&gt;
: Subpackages built from this APKBUILD.  Subpackages are usually prefixed with &#039;&#039;&#039;$pkgname-&#039;&#039;&#039;, with the remainder of the subpackage name being used as the name of the package function for the subpackage.  For example, if &#039;&#039;subpackages&#039;&#039; is set to &#039;&#039;&#039;$pkgname-extra&#039;&#039;&#039;, this will create a subpackage called &#039;&#039;&#039;&#039;&#039;$pkgname&#039;&#039;-extra&#039;&#039;&#039;, which is packaged using a custom &#039;&#039;extra()&#039;&#039; function. (See the [[APKBUILD Reference#Subpackages|Subpackages]] section below for more information.)&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;
{{Tip|All custom user-specified variables and functions should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions should consider the current working directory as undefined, and therefore should use the [[APKBUILD Reference#abuild-defined_variables|abuild-defined directory variables]] to their advantage.}}&lt;br /&gt;
&lt;br /&gt;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
===== dev() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
===== doc() =====&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== User-defined functions ==&lt;br /&gt;
===== prepare() =====&lt;br /&gt;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;return 0&#039;&#039;&#039;&lt;br /&gt;
===== package() =====&lt;br /&gt;
: &#039;&#039;&#039;Required.&#039;&#039;&#039;  This is the packaging stage.  This is where the built application and support files should be installed in &#039;&#039;&#039;$pkgdir&#039;&#039;&#039;.&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;
&lt;br /&gt;
= Subpackages =&lt;br /&gt;
Subpackages are specified in the &#039;&#039;subpackages&#039;&#039; variable.  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 ways:&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;
== Subpackages Example ==&lt;br /&gt;
The following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
... will create the 5 packages in total:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
The split functions for the 4 subpackages are:&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039; (provided by the user)&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039; (provided by the user)&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4827</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4827"/>
		<updated>2011-01-13T01:00:28Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: /* Subpackages Example */&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;
This page is intended to serve as a quick 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;
* 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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
&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 found.&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
; subpkgdir&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
; arch&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, all&#039;&#039;&#039;, or &#039;&#039;&#039;noarch&#039;&#039;&#039;, where &#039;&#039;&#039;&#039;&#039;all&#039;&#039;&#039;&#039;&#039; means all architectures, and &#039;&#039;&#039;&#039;&#039;noarch&#039;&#039;&#039;&#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;&#039;noarch&#039;&#039;&#039;, first specify &#039;&#039;&#039;all&#039;&#039;&#039;, build the package by running &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039; and once built, execute &#039;&#039;&#039;&#039;&#039;scanelf -R pkg&#039;&#039;&#039;&#039;&#039;.  This scans for ELF files in the &#039;&#039;./pkg&#039;&#039; directory, where all sub-/package files reside.  If you do not get output from this, then &#039;&#039;&#039;noarch&#039;&#039;&#039; can be used.}}&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.&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;
; install&lt;br /&gt;
: Pre/Post- Install/Upgrade/Deinstall scripts.  These are used to provide additional help when installing/upgrading/deinstalling a package, and are named &#039;&#039;&#039;$pkgname.{pre,post}-{install,upgrade,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;
; license&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
; makedepends&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
; md5sums&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
; options&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&lt;br /&gt;
; pkgdesc&lt;br /&gt;
: Short description of the package.&lt;br /&gt;
; pkggroups&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in a &#039;&#039;&#039;$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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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 a &#039;&#039;&#039;$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.&lt;br /&gt;
; replaces&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&lt;br /&gt;
; source&lt;br /&gt;
: URL(s) to sources and patches.  It can also list local files included along-side the APKBUILD, such as patches, init.d scripts, conf.d files, etc.&lt;br /&gt;
; subpackages&lt;br /&gt;
: Subpackages built from this APKBUILD.  Subpackages are usually prefixed with &#039;&#039;&#039;$pkgname-&#039;&#039;&#039;, with the remainder of the subpackage name being used as the name of the package function for the subpackage.  For example, if &#039;&#039;subpackages&#039;&#039; is set to &#039;&#039;&#039;$pkgname-extra&#039;&#039;&#039;, this will create a subpackage called &#039;&#039;&#039;&#039;&#039;$pkgname&#039;&#039;-extra&#039;&#039;&#039;, which is packaged using a custom &#039;&#039;extra()&#039;&#039; function. (See the [[APKBUILD Reference#Subpackages|Subpackages]] section below for more information.)&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;
{{Tip|All custom user-specified variables and functions should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions should consider the current working directory as undefined, and therefore should use the [[APKBUILD Reference#abuild-defined_variables|abuild-defined directory variables]] to their advantage.}}&lt;br /&gt;
&lt;br /&gt;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
; dev()&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
; doc()&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== User-defined functions ==&lt;br /&gt;
; prepare()&lt;br /&gt;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;return 0&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
; package()&lt;br /&gt;
: &#039;&#039;&#039;Required.&#039;&#039;&#039;  This is the packaging stage.  This is where the built application and support files should be installed in &#039;&#039;&#039;$pkgdir&#039;&#039;&#039;.&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;
&lt;br /&gt;
= Subpackages =&lt;br /&gt;
Subpackages are specified in the &#039;&#039;subpackages&#039;&#039; variable.  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 ways:&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;
== Subpackages Example ==&lt;br /&gt;
The following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
... will create the 5 packages in total:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
The split functions for the 4 subpackages are:&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039; (provided by the user)&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039; (provided by the user)&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4826</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4826"/>
		<updated>2011-01-13T00:59:03Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: &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;
This page is intended to serve as a quick 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;
* 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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
&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 found.&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
; subpkgdir&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
; arch&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, all&#039;&#039;&#039;, or &#039;&#039;&#039;noarch&#039;&#039;&#039;, where &#039;&#039;&#039;&#039;&#039;all&#039;&#039;&#039;&#039;&#039; means all architectures, and &#039;&#039;&#039;&#039;&#039;noarch&#039;&#039;&#039;&#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;&#039;noarch&#039;&#039;&#039;, first specify &#039;&#039;&#039;all&#039;&#039;&#039;, build the package by running &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039; and once built, execute &#039;&#039;&#039;&#039;&#039;scanelf -R pkg&#039;&#039;&#039;&#039;&#039;.  This scans for ELF files in the &#039;&#039;./pkg&#039;&#039; directory, where all sub-/package files reside.  If you do not get output from this, then &#039;&#039;&#039;noarch&#039;&#039;&#039; can be used.}}&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.&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;
; install&lt;br /&gt;
: Pre/Post- Install/Upgrade/Deinstall scripts.  These are used to provide additional help when installing/upgrading/deinstalling a package, and are named &#039;&#039;&#039;$pkgname.{pre,post}-{install,upgrade,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;
; license&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
; makedepends&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
; md5sums&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
; options&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&lt;br /&gt;
; pkgdesc&lt;br /&gt;
: Short description of the package.&lt;br /&gt;
; pkggroups&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in a &#039;&#039;&#039;$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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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 a &#039;&#039;&#039;$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.&lt;br /&gt;
; replaces&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&lt;br /&gt;
; source&lt;br /&gt;
: URL(s) to sources and patches.  It can also list local files included along-side the APKBUILD, such as patches, init.d scripts, conf.d files, etc.&lt;br /&gt;
; subpackages&lt;br /&gt;
: Subpackages built from this APKBUILD.  Subpackages are usually prefixed with &#039;&#039;&#039;$pkgname-&#039;&#039;&#039;, with the remainder of the subpackage name being used as the name of the package function for the subpackage.  For example, if &#039;&#039;subpackages&#039;&#039; is set to &#039;&#039;&#039;$pkgname-extra&#039;&#039;&#039;, this will create a subpackage called &#039;&#039;&#039;&#039;&#039;$pkgname&#039;&#039;-extra&#039;&#039;&#039;, which is packaged using a custom &#039;&#039;extra()&#039;&#039; function. (See the [[APKBUILD Reference#Subpackages|Subpackages]] section below for more information.)&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;
{{Tip|All custom user-specified variables and functions should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions should consider the current working directory as undefined, and therefore should use the [[APKBUILD Reference#abuild-defined_variables|abuild-defined directory variables]] to their advantage.}}&lt;br /&gt;
&lt;br /&gt;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
; dev()&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;dev()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;dev()&#039;&#039; function, which in turn calls &#039;&#039;default_dev()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
; doc()&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;doc()&#039;&#039; function, abuild will call it&#039;s internal &#039;&#039;doc()&#039;&#039; function, which in turn calls &#039;&#039;default_doc()&#039;&#039;, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== User-defined functions ==&lt;br /&gt;
; prepare()&lt;br /&gt;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;return 0&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
; package()&lt;br /&gt;
: &#039;&#039;&#039;Required.&#039;&#039;&#039;  This is the packaging stage.  This is where the built application and support files should be installed in &#039;&#039;&#039;$pkgdir&#039;&#039;&#039;.&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;
&lt;br /&gt;
= Subpackages =&lt;br /&gt;
Subpackages are specified in the &#039;&#039;subpackages&#039;&#039; variable.  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 ways:&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;
== Subpackages Example ==&lt;br /&gt;
The following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
... will create the 5 packages in total:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
The split functions for the 4 subpackages are:&lt;br /&gt;
# &#039;&#039;dev()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;doc()&#039;&#039; (provided by abuild)&lt;br /&gt;
# &#039;&#039;pysub()&#039;&#039; (provided by user)&lt;br /&gt;
# &#039;&#039;libfoo()&#039;&#039; (provided by user)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4825</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4825"/>
		<updated>2011-01-13T00:50:36Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: revamped page&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;
This page is intended to serve as a quick 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;
* 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 by italics and bold type (i.e., &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039;).&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;
&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 found.&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 contain the files for the main package.  For example, a normal [http://en.wikipedia.org/wiki/GNU_build_system autotools] package would have &#039;&#039;&#039;&#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;&#039;&#039;&#039; in the &#039;&#039;package()&#039;&#039; function.&lt;br /&gt;
; subpkgdir&lt;br /&gt;
: This directory should contain the files for a subpackage.  This variable should only be used from subpackage functions.&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by the user:&lt;br /&gt;
; arch&lt;br /&gt;
: Package architecture(s) to build for.  Can be one of: &#039;&#039;&#039;x86, x86_64, all&#039;&#039;&#039;, or &#039;&#039;&#039;noarch&#039;&#039;&#039;, where &#039;&#039;&#039;&#039;&#039;all&#039;&#039;&#039;&#039;&#039; means all architectures, and &#039;&#039;&#039;&#039;&#039;noarch&#039;&#039;&#039;&#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;&#039;noarch&#039;&#039;&#039;, first specify &#039;&#039;&#039;all&#039;&#039;&#039;, build the package by running &#039;&#039;&#039;&#039;&#039;abuild -r&#039;&#039;&#039;&#039;&#039; and once built, execute &#039;&#039;&#039;&#039;&#039;scanelf -R pkg&#039;&#039;&#039;&#039;&#039;.  This scans for ELF files in the &#039;&#039;./pkg&#039;&#039; directory, where all sub-/package files reside.  If you do not get output from this, then &#039;&#039;&#039;noarch&#039;&#039;&#039; can be used.}}&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.&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;
; install&lt;br /&gt;
: Pre/Post- Install/Upgrade/Deinstall scripts.  These are used to provide additional help when installing/upgrading/deinstalling a package, and are named &#039;&#039;&#039;$pkgname.{pre,post}-{install,upgrade,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;
; license&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
; makedepends&lt;br /&gt;
: Build-time dependency package(s).&lt;br /&gt;
; md5sums&lt;br /&gt;
: Checksums for the files/URLs listed in &#039;&#039;source&#039;&#039;.  The checksums are normally generated by executing &#039;&#039;&#039;&#039;&#039;abuild checksum&#039;&#039;&#039;&#039;&#039; and should be the last item in the APKBUILD.&lt;br /&gt;
; options&lt;br /&gt;
: Build-time options for the package.  Can be: &#039;&#039;&#039;!strip&#039;&#039;&#039; - to avoid stripping symbols from binaries.&lt;br /&gt;
; pkgdesc&lt;br /&gt;
: Short description of the package.&lt;br /&gt;
; pkggroups&lt;br /&gt;
: System group(s) to be created during build-time.  System group(s) should also be created in a &#039;&#039;&#039;$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;
: {{Tip|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;py-&#039;&#039;.  Search aports for other common prefixes.}}&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 a &#039;&#039;&#039;$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.&lt;br /&gt;
; replaces&lt;br /&gt;
: Package(s) that this package replaces.  This package will &amp;quot;take over&amp;quot; files owned by packages listed in the &#039;&#039;replaces&#039;&#039; variable.  This is useful when files move from one sub-/package to another, or when a package gets renamed.&lt;br /&gt;
; source&lt;br /&gt;
: URL(s) to sources and patches.  It can also list local files included along-side the APKBUILD, such as patches, init.d scripts, conf.d files, etc.&lt;br /&gt;
; subpackages&lt;br /&gt;
: Subpackages built from this APKBUILD.  Subpackages are usually prefixed with &#039;&#039;&#039;$pkgname-&#039;&#039;&#039;, with the remainder of the subpackage name being used as the name of the package function for the subpackage.  For example, if &#039;&#039;subpackages&#039;&#039; is set to &#039;&#039;&#039;$pkgname-extra&#039;&#039;&#039;, this will create a subpackage called &#039;&#039;&#039;&#039;&#039;$pkgname&#039;&#039;-extra&#039;&#039;&#039;, which is packaged using a custom &#039;&#039;extra()&#039;&#039; function. (See the [[APKBUILD Reference#Subpackages|Subpackages]] section below for more information.)&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;
{{Tip|All custom user-specified variables and functions should be prefixed with an underscore character ( _ ) to avoid name clashes with the internals of abuild (i.e., &#039;&#039;_builddir&#039;&#039;).}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
{{Note|All functions should consider the current working directory as undefined, and therefore should use the [[APKBUILD Reference#abuild-defined_variables|abuild-defined directory variables]] to their advantage.}}&lt;br /&gt;
&lt;br /&gt;
== abuild-defined functions ==&lt;br /&gt;
The following functions are provided by abuild and can be overridden:&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;
: Unpacks .tgz, .tar.gz, .tar.bz2, .tar.lzma, .tar.xz, and .zip archives in &#039;&#039;$srcdir&#039;&#039; to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
; dev()&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-dev&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;&#039;dev()&#039;&#039;&#039; function, abuild will call &#039;&#039;&#039;default_dev()&#039;&#039;&#039; by default, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
; doc()&lt;br /&gt;
: Subpackage function for the &#039;&#039;&#039;$pkgname-doc&#039;&#039;&#039; package.  Without specifying a custom &#039;&#039;&#039;doc()&#039;&#039;&#039; function, abuild will call &#039;&#039;&#039;default_doc()&#039;&#039;&#039; by default, which will move &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/doc&#039;&#039;, &#039;&#039;&amp;quot;$pkgdir&amp;quot;/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== User-defined functions ==&lt;br /&gt;
; prepare()&lt;br /&gt;
: &#039;&#039;&#039;&#039;&#039;Optional&#039;&#039;.&#039;&#039;&#039;  Used for build preparation: patches, etc, should be applied here.  This function is available for your convenience.&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: &#039;&#039;&#039;return 0&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
; package()&lt;br /&gt;
: &#039;&#039;&#039;Required.&#039;&#039;&#039;  This is the packaging stage.  This is where the built application and support files should be installed in &#039;&#039;&#039;$pkgdir&#039;&#039;&#039;.&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;
&lt;br /&gt;
= Subpackages =&lt;br /&gt;
Subpackages are specified in the &#039;&#039;subpackages&#039;&#039; variable.  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 ways:&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;
== Subpackages Example ==&lt;br /&gt;
The following APKBUILD snippet:&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
... will create the 5 packages in total:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
The split functions for the 4 subpackages are:&lt;br /&gt;
# dev() (provided by abuild)&lt;br /&gt;
# doc() (provided by abuild)&lt;br /&gt;
# pysub() (provided by user)&lt;br /&gt;
# libfoo() (provided by user)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
Simple APKBUILD with -doc subpackage, using abuild&#039;s default &#039;&#039;doc()&#039;&#039; function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A more complex APKBUILD with -doc, -dev and python subpackages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Creating_an_Alpine_package&amp;diff=4723</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=4723"/>
		<updated>2011-01-01T03:31:33Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: /* source */ revamped wording for source variable section (should be the final edit ;)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== General ==&lt;br /&gt;
&lt;br /&gt;
This document assumes that you have a working [[Setting up the build environment|build environment]], or use a diskbased alpine installation. &lt;br /&gt;
&lt;br /&gt;
=== The APKBUILDs  ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;[http://dev.alpinelinux.org/cgit/abuild/ abuild]&#039;&#039; script reads the &#039;&#039;[http://dev.alpinelinux.org/cgit/abuild/tree/sample.APKBUILD APKBUILD]&#039;&#039; and executes the steps needed to create a package. &lt;br /&gt;
&lt;br /&gt;
=== The aports tree  ===&lt;br /&gt;
&lt;br /&gt;
The [http://dev.alpinelinux.org/cgit/aports aports] tree is a [http://dev.alpinelinux.org/cgit/aports/tree directory tree] with many APKBUILDs. Those files are used when building alpine from source. &lt;br /&gt;
&lt;br /&gt;
== Installing and configuring the alpine-sdk  ==&lt;br /&gt;
&lt;br /&gt;
The alpine-sdk is a metapackage that pulls in the most essential packages used to build new packages.&amp;lt;BR&amp;gt;&lt;br /&gt;
Install those packages now: &lt;br /&gt;
&lt;br /&gt;
  apk add alpine-sdk&lt;br /&gt;
&lt;br /&gt;
This would be a good time to create a normal user account for you to work in. (You weren&#039;t going to develop as root now, were you!) To create the user:&lt;br /&gt;
&lt;br /&gt;
  adduser &amp;lt;yourusername&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To make life easier later, it&#039;s a good idea to add this user to /etc/sudoers. Append the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;yourusername&amp;gt;    ALL=(ALL) ALL&lt;br /&gt;
&lt;br /&gt;
using the command:&lt;br /&gt;
&lt;br /&gt;
  visudo&lt;br /&gt;
&lt;br /&gt;
Now logout of the root account, and login as &amp;lt;yourusername&amp;gt;. From here on everything can be done in a normal user account, and operations that require superuser privileges can be done with sudo.&lt;br /&gt;
&lt;br /&gt;
The aports tree is in git so before we clone the aports tree we should configure git.&lt;br /&gt;
&lt;br /&gt;
  git config --global user.name &amp;quot;Your Full Name&amp;quot;&lt;br /&gt;
  git config --global user.email &amp;quot;your@email.address&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Now we can clone the aports tree. &lt;br /&gt;
&lt;br /&gt;
  git clone git://dev.alpinelinux.org/aports&lt;br /&gt;
&lt;br /&gt;
Before we start creating or modifying APKBUILD files we need to setup abuild to our system/user. Edit the file abuild.conf to your requirements. Most of the defaults can be left alone, unless you are developing for a custom platform, in which case the comments in the file should guide you. The one field to edit is PACKAGER, so that you can get credit (or blame) for packages you create.&lt;br /&gt;
&lt;br /&gt;
  sudo vi /etc/abuild.conf&lt;br /&gt;
&lt;br /&gt;
The last step in preparation is to configure the security keys for abuild with the command:&lt;br /&gt;
&lt;br /&gt;
  abuild-keygen -a -i&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 program can/cannot do.&lt;br /&gt;
&lt;br /&gt;
 abuild -h&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 abuild has the option -n (new). It will simply copy an example/template APKBUILD file to the given directory and fill some variables.&amp;lt;BR&amp;gt;&lt;br /&gt;
If you are create a daemon package which needs initd scripts you can add the -c making it: &lt;br /&gt;
&lt;br /&gt;
 abuild -c -n &#039;&#039;packagename&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{{Note|The &#039;packagename&#039; is a parameter to the -n option so order of -c and -n matters.  Further, on newer Alpine systems, &#039;newapkbuild&#039; has replaced abuild with the -n switch.}}&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;
: &amp;lt;pre&amp;gt;abuild checksum&amp;lt;/pre&amp;gt;&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;saveas-&#039; to the protocol and append &#039;/software-1.0.tar.gz&#039; (for instance) to the end of the URI, like so:&lt;br /&gt;
: &amp;lt;pre&amp;gt;saveas-http://oss.example.org/?get=software&amp;amp;ver=1.0/software-1.0.tar.gz&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;
* 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.gz / .tgz&lt;br /&gt;
** .tar.bz2&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 [http://en.wikipedia.org/wiki/Rtfm RTFM]. &lt;br /&gt;
&lt;br /&gt;
No kidding, lots of important information can be found it the package INSTALL and README file (or the likes). Another good way is the run ./configure --help from the source directory to see which options are needed for configure to finish without errors. If you do not yet have a src directory you can create one with the command: &lt;br /&gt;
&lt;br /&gt;
 abuild unpack&lt;br /&gt;
&lt;br /&gt;
Running configure will also show you how you can disable a specific option for this package. A good example is for instance &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 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;
* [http://www.gentoo-portage.com Search ebuilds] &lt;br /&gt;
* [http://sources.gentoo.org/viewcvs.py/gentoo-x86/ Gentoo CVS] &lt;br /&gt;
* [http://www.archlinux.org/packages/search/ Arch Linux packages] &lt;br /&gt;
&lt;br /&gt;
After the package is successfully compiled and created we should make sure it didn&#039;t link to any package that is not present in the $depends variable. We do this by using scanelf. If scanelf is not yet installed on your system you can do that by installing pax-utils. &lt;br /&gt;
&lt;br /&gt;
 scanelf -nR pkg&lt;br /&gt;
&lt;br /&gt;
An example output of libcurl would be: &lt;br /&gt;
&lt;br /&gt;
 ET_DYN libssl.so.0.9.8,libcrypto.so.0.9.8,libz.so.1,libc.so.0,ld-uClibc.so.0 pkg/usr/lib/libcurl.so.4.1.1&lt;br /&gt;
&lt;br /&gt;
You can see the needed files and should be able to find out which file belongs to which package.&lt;br /&gt;
&lt;br /&gt;
==== license  ====&lt;br /&gt;
&lt;br /&gt;
If a package has a special/custom license we need to provide it 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 build() function, depending on the license description file: &lt;br /&gt;
&lt;br /&gt;
 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;
==== 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 (ie, 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 usefully 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.&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 if you change something to your APKBUILD file without changing the actual $pkgver you can higer 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 add the missing dependency. &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;
===== $pkgname.pre-install =====&lt;br /&gt;
This script is executed before package is installed. Typical use is when package needs a user/group to be created. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
adduser -H -s /bin/false -D clamav 2&amp;gt;/dev/null&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 apk add will exit with failure.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-install =====&lt;br /&gt;
This script is executed after package is installed. Can be used to generate font cache and similar.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-upgrade =====&lt;br /&gt;
Same as pre-install but is executed before upgrading an already installed package.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-upgrade =====&lt;br /&gt;
Same as post-install but is executed after upgrading an already installed package. &lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-deinstall =====&lt;br /&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;
===== $pkgname.post-deinstall =====&lt;br /&gt;
This script is executed after a package have been uninstalled. Can be used to update font caches and restore busybox links. For example:&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;
&lt;br /&gt;
If the package have an pre-install and post-install script the APKBUILD should have the &#039;&#039;install&#039;&#039; variable defined and the scripts should also be added to the source variable:&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;
source=&amp;quot;http://....&lt;br /&gt;
       $install&amp;quot;&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;
 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;
 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 applications will have except doc and dev files other non needed at run time files which we want to separate away from the base package. 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;
 }&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. Way&#039;s to create them are: &lt;br /&gt;
&lt;br /&gt;
directory compare: &lt;br /&gt;
&lt;br /&gt;
 diff -urp original_directory new_directory &amp;amp;gt; filename.patch&lt;br /&gt;
&lt;br /&gt;
file compare: &lt;br /&gt;
&lt;br /&gt;
 diff -up original.file new.file &amp;amp;gt; filename.patch&lt;br /&gt;
&lt;br /&gt;
If you are going to use multiple patches for a single package, the preferred way to handle those is a loop and numbering the patches. &lt;br /&gt;
&lt;br /&gt;
 for i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
        msg &amp;quot;Applying ${i}&amp;quot;&lt;br /&gt;
        patch -p0 -i $i || return 1&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Because multiple patches can patch the same file, we could create offset for the next patch. To make sure we always patch in a specified way we should number the patches as followed: &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 patch 1 is first and if we want to add additional patches between them we can use 11,12,21,22... &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 everyting is installed with /usr in front of it. If you notice that anything is installed in the wrong directory please run ./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;
==== 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 [http://www.gnu.org/software/make/manual/make.html#Parallel parallel] building/installing. A normal make line would be: &lt;br /&gt;
&lt;br /&gt;
 make || return 1&lt;br /&gt;
&lt;br /&gt;
To disable parallel we use: &lt;br /&gt;
&lt;br /&gt;
 make -j1 || return 1&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;
 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 sudo 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;
==== 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;
 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;
 cd $pkgname&lt;br /&gt;
 abuild checksum&lt;br /&gt;
&lt;br /&gt;
Its about time we build our package. Because a build system should never have all the package installed to prevent linking to packages we dont want it to link we use a abuild recursively with the -r switch. It will install all dependency&#039;s from your repository and builds it, afterwards it will uninstall all those depending packages again. You could also use the -R switch which would build your package including the dependency packages. &lt;br /&gt;
&lt;br /&gt;
 abuild -r&lt;br /&gt;
&lt;br /&gt;
== Commit your work  ==&lt;br /&gt;
&lt;br /&gt;
After you successfully build your package you can submit your APKBUILD to alpine git repository. &lt;br /&gt;
&lt;br /&gt;
Update you git repo, before adding new files: &lt;br /&gt;
&lt;br /&gt;
 cd $aportsdir&lt;br /&gt;
 git pull&lt;br /&gt;
&lt;br /&gt;
This should pull all the changes made by others into you local git repo. When you think you are ready you can add your files to git: &lt;br /&gt;
&lt;br /&gt;
 cd $apkbuilddir&lt;br /&gt;
 git add APKBUILD (include any other files needed for the build; $pkgname.install...)&lt;br /&gt;
 git commit&lt;br /&gt;
&lt;br /&gt;
Now your changes are only available locally in your repo. Because you do not have push rights to the alpine repo you need to create diff (patch) of the changes you made: &lt;br /&gt;
&lt;br /&gt;
 git format-patch -1&lt;br /&gt;
&lt;br /&gt;
Where -1 sets how many commits you want to go back (mostly this is 1). This should create a patch called 0001......patch. &lt;br /&gt;
&lt;br /&gt;
An easy way to send this patch to the list is with an program called &#039;email&#039;. &lt;br /&gt;
&lt;br /&gt;
 apk_add email&lt;br /&gt;
&lt;br /&gt;
to send to the mailing list you would do: &lt;br /&gt;
&lt;br /&gt;
 email -a 0001...patch alpine-devel@lists.alpinelinux.org&lt;br /&gt;
&lt;br /&gt;
And provide a subject and body after you execute the above cmd. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; If you doubt to which repo your package belongs to you can safely use testing.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[APKBUILD Reference]]&lt;br /&gt;
* [[Development using git]]&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Creating_an_Alpine_package&amp;diff=4722</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=4722"/>
		<updated>2010-12-31T17:16:57Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: /* source */ updated the wording&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== General ==&lt;br /&gt;
&lt;br /&gt;
This document assumes that you have a working [[Setting up the build environment|build environment]], or use a diskbased alpine installation. &lt;br /&gt;
&lt;br /&gt;
=== The APKBUILDs  ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;[http://dev.alpinelinux.org/cgit/abuild/ abuild]&#039;&#039; script reads the &#039;&#039;[http://dev.alpinelinux.org/cgit/abuild/tree/sample.APKBUILD APKBUILD]&#039;&#039; and executes the steps needed to create a package. &lt;br /&gt;
&lt;br /&gt;
=== The aports tree  ===&lt;br /&gt;
&lt;br /&gt;
The [http://dev.alpinelinux.org/cgit/aports aports] tree is a [http://dev.alpinelinux.org/cgit/aports/tree directory tree] with many APKBUILDs. Those files are used when building alpine from source. &lt;br /&gt;
&lt;br /&gt;
== Installing and configuring the alpine-sdk  ==&lt;br /&gt;
&lt;br /&gt;
The alpine-sdk is a metapackage that pulls in the most essential packages used to build new packages.&amp;lt;BR&amp;gt;&lt;br /&gt;
Install those packages now: &lt;br /&gt;
&lt;br /&gt;
  apk add alpine-sdk&lt;br /&gt;
&lt;br /&gt;
This would be a good time to create a normal user account for you to work in. (You weren&#039;t going to develop as root now, were you!) To create the user:&lt;br /&gt;
&lt;br /&gt;
  adduser &amp;lt;yourusername&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To make life easier later, it&#039;s a good idea to add this user to /etc/sudoers. Append the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;yourusername&amp;gt;    ALL=(ALL) ALL&lt;br /&gt;
&lt;br /&gt;
using the command:&lt;br /&gt;
&lt;br /&gt;
  visudo&lt;br /&gt;
&lt;br /&gt;
Now logout of the root account, and login as &amp;lt;yourusername&amp;gt;. From here on everything can be done in a normal user account, and operations that require superuser privileges can be done with sudo.&lt;br /&gt;
&lt;br /&gt;
The aports tree is in git so before we clone the aports tree we should configure git.&lt;br /&gt;
&lt;br /&gt;
  git config --global user.name &amp;quot;Your Full Name&amp;quot;&lt;br /&gt;
  git config --global user.email &amp;quot;your@email.address&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Now we can clone the aports tree. &lt;br /&gt;
&lt;br /&gt;
  git clone git://dev.alpinelinux.org/aports&lt;br /&gt;
&lt;br /&gt;
Before we start creating or modifying APKBUILD files we need to setup abuild to our system/user. Edit the file abuild.conf to your requirements. Most of the defaults can be left alone, unless you are developing for a custom platform, in which case the comments in the file should guide you. The one field to edit is PACKAGER, so that you can get credit (or blame) for packages you create.&lt;br /&gt;
&lt;br /&gt;
  sudo vi /etc/abuild.conf&lt;br /&gt;
&lt;br /&gt;
The last step in preparation is to configure the security keys for abuild with the command:&lt;br /&gt;
&lt;br /&gt;
  abuild-keygen -a -i&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 program can/cannot do.&lt;br /&gt;
&lt;br /&gt;
 abuild -h&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 abuild has the option -n (new). It will simply copy an example/template APKBUILD file to the given directory and fill some variables.&amp;lt;BR&amp;gt;&lt;br /&gt;
If you are create a daemon package which needs initd scripts you can add the -c making it: &lt;br /&gt;
&lt;br /&gt;
 abuild -c -n &#039;&#039;packagename&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{{Note|The &#039;packagename&#039; is a parameter to the -n option so order of -c and -n matters.  Further, on newer Alpine systems, &#039;newapkbuild&#039; has replaced abuild with the -n switch.}}&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;
Source is not only the link from which abuild will fetch the source, it should also hold all files abuild needs to build the apk. This could mean initd file, confd file, install file, patches or any other file needed.&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 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;
: &amp;lt;pre&amp;gt;abuild checksum&amp;lt;/pre&amp;gt;&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 a package is using SourceForge for hosting, you should 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 a package&#039;s filename is not specified in the URI (ie, does not end in &#039;/software-1.0.tar.gz&#039;):&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;saveas-&#039; to the protocol and append &#039;/software-1.0.tar.gz&#039; (for instance) to the end of the URI:&lt;br /&gt;
: &amp;lt;pre&amp;gt;saveas-http://oss.example.org/?get=software&amp;amp;ver=1.0/software-1.0.tar.gz&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 can NOT use it.&lt;br /&gt;
&lt;br /&gt;
* abuild currently supports the following protocols:&lt;br /&gt;
: &amp;lt;pre&amp;gt;http, https, ftp&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* abuild currently supports the following archives/extensions:&lt;br /&gt;
: &amp;lt;pre&amp;gt;*.tar.gz, *.tgz, *.tar.bz2, *.tar.lzma, *.zip&amp;lt;/pre&amp;gt;&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 [http://en.wikipedia.org/wiki/Rtfm RTFM]. &lt;br /&gt;
&lt;br /&gt;
No kidding, lots of important information can be found it the package INSTALL and README file (or the likes). Another good way is the run ./configure --help from the source directory to see which options are needed for configure to finish without errors. If you do not yet have a src directory you can create one with the command: &lt;br /&gt;
&lt;br /&gt;
 abuild unpack&lt;br /&gt;
&lt;br /&gt;
Running configure will also show you how you can disable a specific option for this package. A good example is for instance &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 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;
* [http://www.gentoo-portage.com Search ebuilds] &lt;br /&gt;
* [http://sources.gentoo.org/viewcvs.py/gentoo-x86/ Gentoo CVS] &lt;br /&gt;
* [http://www.archlinux.org/packages/search/ Arch Linux packages] &lt;br /&gt;
&lt;br /&gt;
After the package is successfully compiled and created we should make sure it didn&#039;t link to any package that is not present in the $depends variable. We do this by using scanelf. If scanelf is not yet installed on your system you can do that by installing pax-utils. &lt;br /&gt;
&lt;br /&gt;
 scanelf -nR pkg&lt;br /&gt;
&lt;br /&gt;
An example output of libcurl would be: &lt;br /&gt;
&lt;br /&gt;
 ET_DYN libssl.so.0.9.8,libcrypto.so.0.9.8,libz.so.1,libc.so.0,ld-uClibc.so.0 pkg/usr/lib/libcurl.so.4.1.1&lt;br /&gt;
&lt;br /&gt;
You can see the needed files and should be able to find out which file belongs to which package.&lt;br /&gt;
&lt;br /&gt;
==== license  ====&lt;br /&gt;
&lt;br /&gt;
If a package has a special/custom license we need to provide it 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 build() function, depending on the license description file: &lt;br /&gt;
&lt;br /&gt;
 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;
==== 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 (ie, 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 usefully 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.&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 if you change something to your APKBUILD file without changing the actual $pkgver you can higer 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 add the missing dependency. &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;
===== $pkgname.pre-install =====&lt;br /&gt;
This script is executed before package is installed. Typical use is when package needs a user/group to be created. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
adduser -H -s /bin/false -D clamav 2&amp;gt;/dev/null&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 apk add will exit with failure.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-install =====&lt;br /&gt;
This script is executed after package is installed. Can be used to generate font cache and similar.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-upgrade =====&lt;br /&gt;
Same as pre-install but is executed before upgrading an already installed package.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-upgrade =====&lt;br /&gt;
Same as post-install but is executed after upgrading an already installed package. &lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-deinstall =====&lt;br /&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;
===== $pkgname.post-deinstall =====&lt;br /&gt;
This script is executed after a package have been uninstalled. Can be used to update font caches and restore busybox links. For example:&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;
&lt;br /&gt;
If the package have an pre-install and post-install script the APKBUILD should have the &#039;&#039;install&#039;&#039; variable defined and the scripts should also be added to the source variable:&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;
source=&amp;quot;http://....&lt;br /&gt;
       $install&amp;quot;&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;
 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;
 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 applications will have except doc and dev files other non needed at run time files which we want to separate away from the base package. 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;
 }&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. Way&#039;s to create them are: &lt;br /&gt;
&lt;br /&gt;
directory compare: &lt;br /&gt;
&lt;br /&gt;
 diff -urp original_directory new_directory &amp;amp;gt; filename.patch&lt;br /&gt;
&lt;br /&gt;
file compare: &lt;br /&gt;
&lt;br /&gt;
 diff -up original.file new.file &amp;amp;gt; filename.patch&lt;br /&gt;
&lt;br /&gt;
If you are going to use multiple patches for a single package, the preferred way to handle those is a loop and numbering the patches. &lt;br /&gt;
&lt;br /&gt;
 for i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
        msg &amp;quot;Applying ${i}&amp;quot;&lt;br /&gt;
        patch -p0 -i $i || return 1&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Because multiple patches can patch the same file, we could create offset for the next patch. To make sure we always patch in a specified way we should number the patches as followed: &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 patch 1 is first and if we want to add additional patches between them we can use 11,12,21,22... &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 everyting is installed with /usr in front of it. If you notice that anything is installed in the wrong directory please run ./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;
==== 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 [http://www.gnu.org/software/make/manual/make.html#Parallel parallel] building/installing. A normal make line would be: &lt;br /&gt;
&lt;br /&gt;
 make || return 1&lt;br /&gt;
&lt;br /&gt;
To disable parallel we use: &lt;br /&gt;
&lt;br /&gt;
 make -j1 || return 1&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;
 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 sudo 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;
==== 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;
 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;
 cd $pkgname&lt;br /&gt;
 abuild checksum&lt;br /&gt;
&lt;br /&gt;
Its about time we build our package. Because a build system should never have all the package installed to prevent linking to packages we dont want it to link we use a abuild recursively with the -r switch. It will install all dependency&#039;s from your repository and builds it, afterwards it will uninstall all those depending packages again. You could also use the -R switch which would build your package including the dependency packages. &lt;br /&gt;
&lt;br /&gt;
 abuild -r&lt;br /&gt;
&lt;br /&gt;
== Commit your work  ==&lt;br /&gt;
&lt;br /&gt;
After you successfully build your package you can submit your APKBUILD to alpine git repository. &lt;br /&gt;
&lt;br /&gt;
Update you git repo, before adding new files: &lt;br /&gt;
&lt;br /&gt;
 cd $aportsdir&lt;br /&gt;
 git pull&lt;br /&gt;
&lt;br /&gt;
This should pull all the changes made by others into you local git repo. When you think you are ready you can add your files to git: &lt;br /&gt;
&lt;br /&gt;
 cd $apkbuilddir&lt;br /&gt;
 git add APKBUILD (include any other files needed for the build; $pkgname.install...)&lt;br /&gt;
 git commit&lt;br /&gt;
&lt;br /&gt;
Now your changes are only available locally in your repo. Because you do not have push rights to the alpine repo you need to create diff (patch) of the changes you made: &lt;br /&gt;
&lt;br /&gt;
 git format-patch -1&lt;br /&gt;
&lt;br /&gt;
Where -1 sets how many commits you want to go back (mostly this is 1). This should create a patch called 0001......patch. &lt;br /&gt;
&lt;br /&gt;
An easy way to send this patch to the list is with an program called &#039;email&#039;. &lt;br /&gt;
&lt;br /&gt;
 apk_add email&lt;br /&gt;
&lt;br /&gt;
to send to the mailing list you would do: &lt;br /&gt;
&lt;br /&gt;
 email -a 0001...patch alpine-devel@lists.alpinelinux.org&lt;br /&gt;
&lt;br /&gt;
And provide a subject and body after you execute the above cmd. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; If you doubt to which repo your package belongs to you can safely use testing.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[APKBUILD Reference]]&lt;br /&gt;
* [[Development using git]]&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Creating_an_Alpine_package&amp;diff=4721</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=4721"/>
		<updated>2010-12-31T17:14:39Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: /* depends &amp;amp; makedepends */ added bullets to list of URLs&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== General ==&lt;br /&gt;
&lt;br /&gt;
This document assumes that you have a working [[Setting up the build environment|build environment]], or use a diskbased alpine installation. &lt;br /&gt;
&lt;br /&gt;
=== The APKBUILDs  ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;[http://dev.alpinelinux.org/cgit/abuild/ abuild]&#039;&#039; script reads the &#039;&#039;[http://dev.alpinelinux.org/cgit/abuild/tree/sample.APKBUILD APKBUILD]&#039;&#039; and executes the steps needed to create a package. &lt;br /&gt;
&lt;br /&gt;
=== The aports tree  ===&lt;br /&gt;
&lt;br /&gt;
The [http://dev.alpinelinux.org/cgit/aports aports] tree is a [http://dev.alpinelinux.org/cgit/aports/tree directory tree] with many APKBUILDs. Those files are used when building alpine from source. &lt;br /&gt;
&lt;br /&gt;
== Installing and configuring the alpine-sdk  ==&lt;br /&gt;
&lt;br /&gt;
The alpine-sdk is a metapackage that pulls in the most essential packages used to build new packages.&amp;lt;BR&amp;gt;&lt;br /&gt;
Install those packages now: &lt;br /&gt;
&lt;br /&gt;
  apk add alpine-sdk&lt;br /&gt;
&lt;br /&gt;
This would be a good time to create a normal user account for you to work in. (You weren&#039;t going to develop as root now, were you!) To create the user:&lt;br /&gt;
&lt;br /&gt;
  adduser &amp;lt;yourusername&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To make life easier later, it&#039;s a good idea to add this user to /etc/sudoers. Append the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;yourusername&amp;gt;    ALL=(ALL) ALL&lt;br /&gt;
&lt;br /&gt;
using the command:&lt;br /&gt;
&lt;br /&gt;
  visudo&lt;br /&gt;
&lt;br /&gt;
Now logout of the root account, and login as &amp;lt;yourusername&amp;gt;. From here on everything can be done in a normal user account, and operations that require superuser privileges can be done with sudo.&lt;br /&gt;
&lt;br /&gt;
The aports tree is in git so before we clone the aports tree we should configure git.&lt;br /&gt;
&lt;br /&gt;
  git config --global user.name &amp;quot;Your Full Name&amp;quot;&lt;br /&gt;
  git config --global user.email &amp;quot;your@email.address&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Now we can clone the aports tree. &lt;br /&gt;
&lt;br /&gt;
  git clone git://dev.alpinelinux.org/aports&lt;br /&gt;
&lt;br /&gt;
Before we start creating or modifying APKBUILD files we need to setup abuild to our system/user. Edit the file abuild.conf to your requirements. Most of the defaults can be left alone, unless you are developing for a custom platform, in which case the comments in the file should guide you. The one field to edit is PACKAGER, so that you can get credit (or blame) for packages you create.&lt;br /&gt;
&lt;br /&gt;
  sudo vi /etc/abuild.conf&lt;br /&gt;
&lt;br /&gt;
The last step in preparation is to configure the security keys for abuild with the command:&lt;br /&gt;
&lt;br /&gt;
  abuild-keygen -a -i&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 program can/cannot do.&lt;br /&gt;
&lt;br /&gt;
 abuild -h&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 abuild has the option -n (new). It will simply copy an example/template APKBUILD file to the given directory and fill some variables.&amp;lt;BR&amp;gt;&lt;br /&gt;
If you are create a daemon package which needs initd scripts you can add the -c making it: &lt;br /&gt;
&lt;br /&gt;
 abuild -c -n &#039;&#039;packagename&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{{Note|The &#039;packagename&#039; is a parameter to the -n option so order of -c and -n matters.  Further, on newer Alpine systems, &#039;newapkbuild&#039; has replaced abuild with the -n switch.}}&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;
Source is not only the link from which abuild will fetch the source, it should also hold all files abuild needs to build the apk. This could mean initd file, confd file, install file, patches or any other file needed.&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 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;
: &amp;lt;pre&amp;gt;abuild checksum&amp;lt;/pre&amp;gt;&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 command above.}}&lt;br /&gt;
&lt;br /&gt;
* When a package is using SourceForge for hosting, you should 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 a package&#039;s filename is not specified in the URI (ie, does not end in &#039;/software-1.0.tar.gz&#039;):&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;saveas-&#039; to the protocol and append &#039;/software-1.0.tar.gz&#039; (for instance) to the end of the URI:&lt;br /&gt;
: &amp;lt;pre&amp;gt;saveas-http://oss.example.org/?get=software&amp;amp;ver=1.0/software-1.0.tar.gz&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 can NOT use it.&lt;br /&gt;
&lt;br /&gt;
* abuild currently supports the following protocols:&lt;br /&gt;
: &amp;lt;pre&amp;gt;http, https, ftp&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* abuild currently supports the following archives/extensions:&lt;br /&gt;
: &amp;lt;pre&amp;gt;*.tar.gz, *.tgz, *.tar.bz2, *.tar.lzma, *.zip&amp;lt;/pre&amp;gt;&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 [http://en.wikipedia.org/wiki/Rtfm RTFM]. &lt;br /&gt;
&lt;br /&gt;
No kidding, lots of important information can be found it the package INSTALL and README file (or the likes). Another good way is the run ./configure --help from the source directory to see which options are needed for configure to finish without errors. If you do not yet have a src directory you can create one with the command: &lt;br /&gt;
&lt;br /&gt;
 abuild unpack&lt;br /&gt;
&lt;br /&gt;
Running configure will also show you how you can disable a specific option for this package. A good example is for instance &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 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;
* [http://www.gentoo-portage.com Search ebuilds] &lt;br /&gt;
* [http://sources.gentoo.org/viewcvs.py/gentoo-x86/ Gentoo CVS] &lt;br /&gt;
* [http://www.archlinux.org/packages/search/ Arch Linux packages] &lt;br /&gt;
&lt;br /&gt;
After the package is successfully compiled and created we should make sure it didn&#039;t link to any package that is not present in the $depends variable. We do this by using scanelf. If scanelf is not yet installed on your system you can do that by installing pax-utils. &lt;br /&gt;
&lt;br /&gt;
 scanelf -nR pkg&lt;br /&gt;
&lt;br /&gt;
An example output of libcurl would be: &lt;br /&gt;
&lt;br /&gt;
 ET_DYN libssl.so.0.9.8,libcrypto.so.0.9.8,libz.so.1,libc.so.0,ld-uClibc.so.0 pkg/usr/lib/libcurl.so.4.1.1&lt;br /&gt;
&lt;br /&gt;
You can see the needed files and should be able to find out which file belongs to which package.&lt;br /&gt;
&lt;br /&gt;
==== license  ====&lt;br /&gt;
&lt;br /&gt;
If a package has a special/custom license we need to provide it 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 build() function, depending on the license description file: &lt;br /&gt;
&lt;br /&gt;
 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;
==== 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 (ie, 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 usefully 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.&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 if you change something to your APKBUILD file without changing the actual $pkgver you can higer 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 add the missing dependency. &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;
===== $pkgname.pre-install =====&lt;br /&gt;
This script is executed before package is installed. Typical use is when package needs a user/group to be created. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
adduser -H -s /bin/false -D clamav 2&amp;gt;/dev/null&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 apk add will exit with failure.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-install =====&lt;br /&gt;
This script is executed after package is installed. Can be used to generate font cache and similar.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-upgrade =====&lt;br /&gt;
Same as pre-install but is executed before upgrading an already installed package.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-upgrade =====&lt;br /&gt;
Same as post-install but is executed after upgrading an already installed package. &lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-deinstall =====&lt;br /&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;
===== $pkgname.post-deinstall =====&lt;br /&gt;
This script is executed after a package have been uninstalled. Can be used to update font caches and restore busybox links. For example:&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;
&lt;br /&gt;
If the package have an pre-install and post-install script the APKBUILD should have the &#039;&#039;install&#039;&#039; variable defined and the scripts should also be added to the source variable:&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;
source=&amp;quot;http://....&lt;br /&gt;
       $install&amp;quot;&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;
 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;
 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 applications will have except doc and dev files other non needed at run time files which we want to separate away from the base package. 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;
 }&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. Way&#039;s to create them are: &lt;br /&gt;
&lt;br /&gt;
directory compare: &lt;br /&gt;
&lt;br /&gt;
 diff -urp original_directory new_directory &amp;amp;gt; filename.patch&lt;br /&gt;
&lt;br /&gt;
file compare: &lt;br /&gt;
&lt;br /&gt;
 diff -up original.file new.file &amp;amp;gt; filename.patch&lt;br /&gt;
&lt;br /&gt;
If you are going to use multiple patches for a single package, the preferred way to handle those is a loop and numbering the patches. &lt;br /&gt;
&lt;br /&gt;
 for i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
        msg &amp;quot;Applying ${i}&amp;quot;&lt;br /&gt;
        patch -p0 -i $i || return 1&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Because multiple patches can patch the same file, we could create offset for the next patch. To make sure we always patch in a specified way we should number the patches as followed: &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 patch 1 is first and if we want to add additional patches between them we can use 11,12,21,22... &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 everyting is installed with /usr in front of it. If you notice that anything is installed in the wrong directory please run ./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;
==== 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 [http://www.gnu.org/software/make/manual/make.html#Parallel parallel] building/installing. A normal make line would be: &lt;br /&gt;
&lt;br /&gt;
 make || return 1&lt;br /&gt;
&lt;br /&gt;
To disable parallel we use: &lt;br /&gt;
&lt;br /&gt;
 make -j1 || return 1&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;
 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 sudo 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;
==== 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;
 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;
 cd $pkgname&lt;br /&gt;
 abuild checksum&lt;br /&gt;
&lt;br /&gt;
Its about time we build our package. Because a build system should never have all the package installed to prevent linking to packages we dont want it to link we use a abuild recursively with the -r switch. It will install all dependency&#039;s from your repository and builds it, afterwards it will uninstall all those depending packages again. You could also use the -R switch which would build your package including the dependency packages. &lt;br /&gt;
&lt;br /&gt;
 abuild -r&lt;br /&gt;
&lt;br /&gt;
== Commit your work  ==&lt;br /&gt;
&lt;br /&gt;
After you successfully build your package you can submit your APKBUILD to alpine git repository. &lt;br /&gt;
&lt;br /&gt;
Update you git repo, before adding new files: &lt;br /&gt;
&lt;br /&gt;
 cd $aportsdir&lt;br /&gt;
 git pull&lt;br /&gt;
&lt;br /&gt;
This should pull all the changes made by others into you local git repo. When you think you are ready you can add your files to git: &lt;br /&gt;
&lt;br /&gt;
 cd $apkbuilddir&lt;br /&gt;
 git add APKBUILD (include any other files needed for the build; $pkgname.install...)&lt;br /&gt;
 git commit&lt;br /&gt;
&lt;br /&gt;
Now your changes are only available locally in your repo. Because you do not have push rights to the alpine repo you need to create diff (patch) of the changes you made: &lt;br /&gt;
&lt;br /&gt;
 git format-patch -1&lt;br /&gt;
&lt;br /&gt;
Where -1 sets how many commits you want to go back (mostly this is 1). This should create a patch called 0001......patch. &lt;br /&gt;
&lt;br /&gt;
An easy way to send this patch to the list is with an program called &#039;email&#039;. &lt;br /&gt;
&lt;br /&gt;
 apk_add email&lt;br /&gt;
&lt;br /&gt;
to send to the mailing list you would do: &lt;br /&gt;
&lt;br /&gt;
 email -a 0001...patch alpine-devel@lists.alpinelinux.org&lt;br /&gt;
&lt;br /&gt;
And provide a subject and body after you execute the above cmd. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; If you doubt to which repo your package belongs to you can safely use testing.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[APKBUILD Reference]]&lt;br /&gt;
* [[Development using git]]&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Creating_an_Alpine_package&amp;diff=4720</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=4720"/>
		<updated>2010-12-31T17:10:11Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: /* source */ used the Note wiki template within the &amp;#039;source&amp;#039; variable section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== General ==&lt;br /&gt;
&lt;br /&gt;
This document assumes that you have a working [[Setting up the build environment|build environment]], or use a diskbased alpine installation. &lt;br /&gt;
&lt;br /&gt;
=== The APKBUILDs  ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;[http://dev.alpinelinux.org/cgit/abuild/ abuild]&#039;&#039; script reads the &#039;&#039;[http://dev.alpinelinux.org/cgit/abuild/tree/sample.APKBUILD APKBUILD]&#039;&#039; and executes the steps needed to create a package. &lt;br /&gt;
&lt;br /&gt;
=== The aports tree  ===&lt;br /&gt;
&lt;br /&gt;
The [http://dev.alpinelinux.org/cgit/aports aports] tree is a [http://dev.alpinelinux.org/cgit/aports/tree directory tree] with many APKBUILDs. Those files are used when building alpine from source. &lt;br /&gt;
&lt;br /&gt;
== Installing and configuring the alpine-sdk  ==&lt;br /&gt;
&lt;br /&gt;
The alpine-sdk is a metapackage that pulls in the most essential packages used to build new packages.&amp;lt;BR&amp;gt;&lt;br /&gt;
Install those packages now: &lt;br /&gt;
&lt;br /&gt;
  apk add alpine-sdk&lt;br /&gt;
&lt;br /&gt;
This would be a good time to create a normal user account for you to work in. (You weren&#039;t going to develop as root now, were you!) To create the user:&lt;br /&gt;
&lt;br /&gt;
  adduser &amp;lt;yourusername&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To make life easier later, it&#039;s a good idea to add this user to /etc/sudoers. Append the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;yourusername&amp;gt;    ALL=(ALL) ALL&lt;br /&gt;
&lt;br /&gt;
using the command:&lt;br /&gt;
&lt;br /&gt;
  visudo&lt;br /&gt;
&lt;br /&gt;
Now logout of the root account, and login as &amp;lt;yourusername&amp;gt;. From here on everything can be done in a normal user account, and operations that require superuser privileges can be done with sudo.&lt;br /&gt;
&lt;br /&gt;
The aports tree is in git so before we clone the aports tree we should configure git.&lt;br /&gt;
&lt;br /&gt;
  git config --global user.name &amp;quot;Your Full Name&amp;quot;&lt;br /&gt;
  git config --global user.email &amp;quot;your@email.address&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Now we can clone the aports tree. &lt;br /&gt;
&lt;br /&gt;
  git clone git://dev.alpinelinux.org/aports&lt;br /&gt;
&lt;br /&gt;
Before we start creating or modifying APKBUILD files we need to setup abuild to our system/user. Edit the file abuild.conf to your requirements. Most of the defaults can be left alone, unless you are developing for a custom platform, in which case the comments in the file should guide you. The one field to edit is PACKAGER, so that you can get credit (or blame) for packages you create.&lt;br /&gt;
&lt;br /&gt;
  sudo vi /etc/abuild.conf&lt;br /&gt;
&lt;br /&gt;
The last step in preparation is to configure the security keys for abuild with the command:&lt;br /&gt;
&lt;br /&gt;
  abuild-keygen -a -i&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 program can/cannot do.&lt;br /&gt;
&lt;br /&gt;
 abuild -h&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 abuild has the option -n (new). It will simply copy an example/template APKBUILD file to the given directory and fill some variables.&amp;lt;BR&amp;gt;&lt;br /&gt;
If you are create a daemon package which needs initd scripts you can add the -c making it: &lt;br /&gt;
&lt;br /&gt;
 abuild -c -n &#039;&#039;packagename&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{{Note|The &#039;packagename&#039; is a parameter to the -n option so order of -c and -n matters.  Further, on newer Alpine systems, &#039;newapkbuild&#039; has replaced abuild with the -n switch.}}&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;
Source is not only the link from which abuild will fetch the source, it should also hold all files abuild needs to build the apk. This could mean initd file, confd file, install file, patches or any other file needed.&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 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;
: &amp;lt;pre&amp;gt;abuild checksum&amp;lt;/pre&amp;gt;&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 command above.}}&lt;br /&gt;
&lt;br /&gt;
* When a package is using SourceForge for hosting, you should 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 a package&#039;s filename is not specified in the URI (ie, does not end in &#039;/software-1.0.tar.gz&#039;):&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;saveas-&#039; to the protocol and append &#039;/software-1.0.tar.gz&#039; (for instance) to the end of the URI:&lt;br /&gt;
: &amp;lt;pre&amp;gt;saveas-http://oss.example.org/?get=software&amp;amp;ver=1.0/software-1.0.tar.gz&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 can NOT use it.&lt;br /&gt;
&lt;br /&gt;
* abuild currently supports the following protocols:&lt;br /&gt;
: &amp;lt;pre&amp;gt;http, https, ftp&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* abuild currently supports the following archives/extensions:&lt;br /&gt;
: &amp;lt;pre&amp;gt;*.tar.gz, *.tgz, *.tar.bz2, *.tar.lzma, *.zip&amp;lt;/pre&amp;gt;&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 [http://en.wikipedia.org/wiki/Rtfm RTFM]. &lt;br /&gt;
&lt;br /&gt;
No kidding, lots of important information can be found it the package INSTALL and README file (or the likes). Another good way is the run ./configure --help from the source directory to see which options are needed for configure to finish without errors. If you do not yet have a src directory you can create one with the command: &lt;br /&gt;
&lt;br /&gt;
 abuild unpack&lt;br /&gt;
&lt;br /&gt;
Running configure will also show you how you can disable a specific option for this package. A good example is for instance &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 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;
[http://www.gentoo-portage.com Search ebuilds] &lt;br /&gt;
&lt;br /&gt;
[http://sources.gentoo.org/viewcvs.py/gentoo-x86/ Gentoo CVS] &lt;br /&gt;
&lt;br /&gt;
[http://www.archlinux.org/packages/search/ Arch Linux packages] &lt;br /&gt;
&lt;br /&gt;
After the package is successfully compiled and created we should make sure it didn&#039;t link to any package that is not present in the $depends variable. We do this by using scanelf. If scanelf is not yet installed on your system you can do that by installing pax-utils. &lt;br /&gt;
&lt;br /&gt;
 scanelf -nR pkg&lt;br /&gt;
&lt;br /&gt;
An example output of libcurl would be: &lt;br /&gt;
&lt;br /&gt;
 ET_DYN libssl.so.0.9.8,libcrypto.so.0.9.8,libz.so.1,libc.so.0,ld-uClibc.so.0 pkg/usr/lib/libcurl.so.4.1.1&lt;br /&gt;
&lt;br /&gt;
You can see the needed files and should be able to find out which file belongs to which package.&lt;br /&gt;
&lt;br /&gt;
==== license  ====&lt;br /&gt;
&lt;br /&gt;
If a package has a special/custom license we need to provide it 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 build() function, depending on the license description file: &lt;br /&gt;
&lt;br /&gt;
 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;
==== 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 (ie, 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 usefully 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.&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 if you change something to your APKBUILD file without changing the actual $pkgver you can higer 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 add the missing dependency. &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;
===== $pkgname.pre-install =====&lt;br /&gt;
This script is executed before package is installed. Typical use is when package needs a user/group to be created. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
adduser -H -s /bin/false -D clamav 2&amp;gt;/dev/null&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 apk add will exit with failure.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-install =====&lt;br /&gt;
This script is executed after package is installed. Can be used to generate font cache and similar.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-upgrade =====&lt;br /&gt;
Same as pre-install but is executed before upgrading an already installed package.&lt;br /&gt;
&lt;br /&gt;
===== $pkgname.post-upgrade =====&lt;br /&gt;
Same as post-install but is executed after upgrading an already installed package. &lt;br /&gt;
&lt;br /&gt;
===== $pkgname.pre-deinstall =====&lt;br /&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;
===== $pkgname.post-deinstall =====&lt;br /&gt;
This script is executed after a package have been uninstalled. Can be used to update font caches and restore busybox links. For example:&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;
&lt;br /&gt;
If the package have an pre-install and post-install script the APKBUILD should have the &#039;&#039;install&#039;&#039; variable defined and the scripts should also be added to the source variable:&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;
source=&amp;quot;http://....&lt;br /&gt;
       $install&amp;quot;&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;
 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;
 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 applications will have except doc and dev files other non needed at run time files which we want to separate away from the base package. 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;
 }&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. Way&#039;s to create them are: &lt;br /&gt;
&lt;br /&gt;
directory compare: &lt;br /&gt;
&lt;br /&gt;
 diff -urp original_directory new_directory &amp;amp;gt; filename.patch&lt;br /&gt;
&lt;br /&gt;
file compare: &lt;br /&gt;
&lt;br /&gt;
 diff -up original.file new.file &amp;amp;gt; filename.patch&lt;br /&gt;
&lt;br /&gt;
If you are going to use multiple patches for a single package, the preferred way to handle those is a loop and numbering the patches. &lt;br /&gt;
&lt;br /&gt;
 for i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
        msg &amp;quot;Applying ${i}&amp;quot;&lt;br /&gt;
        patch -p0 -i $i || return 1&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Because multiple patches can patch the same file, we could create offset for the next patch. To make sure we always patch in a specified way we should number the patches as followed: &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 patch 1 is first and if we want to add additional patches between them we can use 11,12,21,22... &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 everyting is installed with /usr in front of it. If you notice that anything is installed in the wrong directory please run ./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;
==== 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 [http://www.gnu.org/software/make/manual/make.html#Parallel parallel] building/installing. A normal make line would be: &lt;br /&gt;
&lt;br /&gt;
 make || return 1&lt;br /&gt;
&lt;br /&gt;
To disable parallel we use: &lt;br /&gt;
&lt;br /&gt;
 make -j1 || return 1&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;
 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 sudo 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;
==== 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;
 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;
 cd $pkgname&lt;br /&gt;
 abuild checksum&lt;br /&gt;
&lt;br /&gt;
Its about time we build our package. Because a build system should never have all the package installed to prevent linking to packages we dont want it to link we use a abuild recursively with the -r switch. It will install all dependency&#039;s from your repository and builds it, afterwards it will uninstall all those depending packages again. You could also use the -R switch which would build your package including the dependency packages. &lt;br /&gt;
&lt;br /&gt;
 abuild -r&lt;br /&gt;
&lt;br /&gt;
== Commit your work  ==&lt;br /&gt;
&lt;br /&gt;
After you successfully build your package you can submit your APKBUILD to alpine git repository. &lt;br /&gt;
&lt;br /&gt;
Update you git repo, before adding new files: &lt;br /&gt;
&lt;br /&gt;
 cd $aportsdir&lt;br /&gt;
 git pull&lt;br /&gt;
&lt;br /&gt;
This should pull all the changes made by others into you local git repo. When you think you are ready you can add your files to git: &lt;br /&gt;
&lt;br /&gt;
 cd $apkbuilddir&lt;br /&gt;
 git add APKBUILD (include any other files needed for the build; $pkgname.install...)&lt;br /&gt;
 git commit&lt;br /&gt;
&lt;br /&gt;
Now your changes are only available locally in your repo. Because you do not have push rights to the alpine repo you need to create diff (patch) of the changes you made: &lt;br /&gt;
&lt;br /&gt;
 git format-patch -1&lt;br /&gt;
&lt;br /&gt;
Where -1 sets how many commits you want to go back (mostly this is 1). This should create a patch called 0001......patch. &lt;br /&gt;
&lt;br /&gt;
An easy way to send this patch to the list is with an program called &#039;email&#039;. &lt;br /&gt;
&lt;br /&gt;
 apk_add email&lt;br /&gt;
&lt;br /&gt;
to send to the mailing list you would do: &lt;br /&gt;
&lt;br /&gt;
 email -a 0001...patch alpine-devel@lists.alpinelinux.org&lt;br /&gt;
&lt;br /&gt;
And provide a subject and body after you execute the above cmd. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; If you doubt to which repo your package belongs to you can safely use testing.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[APKBUILD Reference]]&lt;br /&gt;
* [[Development using git]]&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4719</id>
		<title>APKBUILD Reference</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=APKBUILD_Reference&amp;diff=4719"/>
		<updated>2010-12-31T17:04:28Z</updated>

		<summary type="html">&lt;p&gt;Mattx86: updated wording for &amp;#039;arch&amp;#039; variable&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;APKBUILDs are scripts to build alpine packages using the [[abuild]]  tool. &lt;br /&gt;
&lt;br /&gt;
= Variables =&lt;br /&gt;
== abuild-defined variables ==&lt;br /&gt;
The following variables are defined by abuild:&lt;br /&gt;
; startdir&lt;br /&gt;
: The directory where APKBUILD script is found.&lt;br /&gt;
; srcdir&lt;br /&gt;
: The directory here sources are downloaded to and unpacked.&lt;br /&gt;
; pkgdir&lt;br /&gt;
: This directory should hold the data files for main package. A normal autotools package has a &#039;&#039;make DESTDIR=&amp;quot;$pkgdir&amp;quot; install&#039;&#039;.&lt;br /&gt;
; subpkgdir&lt;br /&gt;
: This directory should have the data files for a subpackage. This variable should only be used from subpackage functions.&lt;br /&gt;
{{Note|All variables that holds a path (i.e &#039;&#039;$srcdir&#039;&#039; and &#039;&#039;$pkgdir&#039;&#039;) should always be within quotes in the APKBUILD (for example: &#039;&#039;&amp;quot;$srcdir&amp;quot;&#039;&#039;). This is so things don&#039;t break in case user has the APKBUILD in a directory with spaces.}}&lt;br /&gt;
&lt;br /&gt;
== User-defined variables ==&lt;br /&gt;
The following variables should be defined by user in APKBUILD:&lt;br /&gt;
; arch&lt;br /&gt;
: Package architecture(s) to build for.  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 (ie, 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;
; depends&lt;br /&gt;
: Runtime dependencies that are not shared-object dependencies. Shared objects dependencies are autodetected and should not be specified here.&lt;br /&gt;
; depends_dev&lt;br /&gt;
: Runtime dependencies for -dev subpackage.&lt;br /&gt;
; install&lt;br /&gt;
: pre/post install/deinstall/remove scripts.&lt;br /&gt;
; license&lt;br /&gt;
: License(s) for the package.&lt;br /&gt;
; makedepends&lt;br /&gt;
: Build time dependencies.&lt;br /&gt;
; md5sums&lt;br /&gt;
: Checksums for sources and patches. This is generated with &#039;&#039;abuild checksum&#039;&#039; and should be located last in the APKBUILD.&lt;br /&gt;
; options&lt;br /&gt;
: build time options for package. Valid values are currently only &#039;&#039;!strip&#039;&#039; for avoid stripping the binaries.&lt;br /&gt;
; pkgdesc&lt;br /&gt;
: Short package description.&lt;br /&gt;
; pkggroups&lt;br /&gt;
: Groups to be created during buildtime. This group should be created in a &#039;&#039;$pkgname.pre-install&#039;&#039; script as well so group is created during runtime.&lt;br /&gt;
; pkgname&lt;br /&gt;
: The name of the package. All letters should be lowercase. Lua libraries/modules should be prefixed with &#039;&#039;lua-&#039;&#039; (for example &#039;&#039;lua-posix&#039;&#039;), perl modules with &#039;&#039;perl-&#039;&#039; (for example &#039;&#039;perl-xml-&#039;&#039;parser), php modules with &#039;&#039;php-&#039;&#039; and python modules with &#039;&#039;py--&#039;&#039;.&lt;br /&gt;
; pkgusers&lt;br /&gt;
: Users to be created during buildtime. Use &#039;&#039;$pkgname.pre-install&#039;&#039; for creating the user(s) during runtime.&lt;br /&gt;
; pkgver&lt;br /&gt;
: The package version.&lt;br /&gt;
; replaces&lt;br /&gt;
: package(s) that this package replaces. This package will &amp;quot;take over&amp;quot; files owned by packages listed in &#039;&#039;replaces&#039;&#039;. Useful when files moves from one (sub)package to another, or packages gets renamed.&lt;br /&gt;
; source&lt;br /&gt;
: URL(s) to sources and patches.&lt;br /&gt;
; subpackages&lt;br /&gt;
: Subpackages built from this APKBUILD.&lt;br /&gt;
; url&lt;br /&gt;
: The homepage for the package. This is to help users find upstream developer, documentation etc.&lt;br /&gt;
&lt;br /&gt;
{{Note|All other user specified variables, temp variables or APKBUILD specifics should be prefixed with a _ to avoid nameclashes with the abuild internals. For example: &#039;&#039;$_builddir&#039;&#039;.}}&lt;br /&gt;
&lt;br /&gt;
= Functions =&lt;br /&gt;
The following functions should be specified in the APKBUILD. The functions should consider current work directory as undefined.&lt;br /&gt;
&lt;br /&gt;
; prepare()&lt;br /&gt;
: &#039;&#039;Optional&#039;&#039;. Build preparation. Here should patches etc be applied. This is function is for convenience while working with the APKBUILD.&lt;br /&gt;
; build()&lt;br /&gt;
: &#039;&#039;Required&#039;&#039;. This is the compilation stage. This function will be called as normal user (unless the package() function is missing - for compatibility reasons). If no compilation is needed this function can contain a single &#039;&#039;return 0&#039;&#039;.&lt;br /&gt;
; package()&lt;br /&gt;
: &#039;&#039;Required&#039;&#039;. In this function the built application and files should be installed in &amp;quot;$pkgdir&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
{{Note| Building in fakeroot will reduce performance for parallell builds dramatically. That is why we do the &#039;&#039;build()&#039;&#039; and &#039;&#039;package()&#039;&#039; separation.}}&lt;br /&gt;
&lt;br /&gt;
The following functions are provided by abuild and is overrideable:&lt;br /&gt;
; fetch()&lt;br /&gt;
: download remote sources listed in $source to &#039;&#039;$SRCDEST&#039;&#039; and create symlinks to &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
; unpack()&lt;br /&gt;
: unpacks .tar.gz .tar.bz2 .tgz and .zip archives in &#039;&#039;$srcdir&#039;&#039;.&lt;br /&gt;
; dev()&lt;br /&gt;
: Subpackage function for -dev packages. By default this will only call &#039;&#039;default_dev&#039;&#039; which will move &#039;&#039;$pkgdir/usr/include&#039;&#039;, &#039;&#039;*.a&#039;&#039;, &#039;&#039;*.la&#039;&#039; and similar files to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
; doc()&lt;br /&gt;
: Subpackage function for -doc packages. By default this will only call &#039;&#039;default_doc&#039;&#039; which will move &#039;&#039;$pkgdir/usr/share/doc&#039;&#039;, &#039;&#039;$pkgdir/usr/share/man&#039;&#039; and similar to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
= Subpackages =&lt;br /&gt;
Subpackages are specified in the &#039;&#039;$subpackages&#039;&#039; variable. abuild will parse this variable and try find a subpackage split function. The split function must move files from &#039;&#039;$pkgdir&#039;&#039; to &#039;&#039;$subpkgdir&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The split function can be specified in 3 different ways:&lt;br /&gt;
# subpkgname:&#039;&#039;splitfunc&#039;&#039;&lt;br /&gt;
# pkgname-&#039;&#039;splitfunc&#039;&#039;&lt;br /&gt;
# &#039;&#039;splitfunc&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Subpackages example ==&lt;br /&gt;
 pkgname=&amp;quot;foo&amp;quot;&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-dev  $pkgname-doc py-$pkgname:pysub libfoo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
will create totally 5 packages:&lt;br /&gt;
# foo (main)&lt;br /&gt;
# foo-dev (sub)&lt;br /&gt;
# foo-doc (sub)&lt;br /&gt;
# py-foo (sub)&lt;br /&gt;
# libfoo (sub)&lt;br /&gt;
&lt;br /&gt;
The split functions for the 4 sub packages are:&lt;br /&gt;
# dev() (provided by abuild)&lt;br /&gt;
# doc() (provided by abuild)&lt;br /&gt;
# pysub() (provided by user)&lt;br /&gt;
# libfoo() (provided by user)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
Simple package with separate -doc subpackage.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Maintainer: Natanael Copa &amp;lt;ncopa@alpinelinux.org&amp;gt;&lt;br /&gt;
pkgname=m4&lt;br /&gt;
pkgver=1.4.15&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;GNU macro processor&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.gnu.org/software/m4&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;GPL&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;m4-doc&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.gnu.org/gnu/m4/$pkgname-$pkgver.tar.gz&lt;br /&gt;
	gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir&amp;quot;/$pkgname-$pkgver&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	patch -p1 -i &amp;quot;$srcdir&amp;quot;/gnulib-uclibc.patch&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr&lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make install DESTDIR=&amp;quot;$pkgdir&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;5649a2e593b6c639deae9e72ede777dd  m4-1.4.15.tar.gz&lt;br /&gt;
20a7dedec0e9e0ee7107e33e798ffdbe  gnulib-uclibc.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example with -doc, -dev and python subpackages.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Contributor: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
# Maintainer: Carlo Landmeter &amp;lt;clandmeter at gmail&amp;gt;&lt;br /&gt;
pkgname=libxml2&lt;br /&gt;
pkgver=2.7.8&lt;br /&gt;
pkgrel=0&lt;br /&gt;
pkgdesc=&amp;quot;XML parsing library, version 2&amp;quot;&lt;br /&gt;
url=&amp;quot;http://www.xmlsoft.org/&amp;quot;&lt;br /&gt;
arch=&amp;quot;all&amp;quot;&lt;br /&gt;
license=&amp;quot;MIT&amp;quot;&lt;br /&gt;
depends=&lt;br /&gt;
depends_dev=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
makedepends=&amp;quot;zlib-dev python-dev&amp;quot;&lt;br /&gt;
subpackages=&amp;quot;$pkgname-doc $pkgname-dev py-$pkgname:py $pkgname-utils&amp;quot;&lt;br /&gt;
source=&amp;quot;ftp://ftp.xmlsoft.org/${pkgname}/${pkgname}-${pkgver}.tar.gz&lt;br /&gt;
	largefile64.patch&amp;quot;&lt;br /&gt;
&lt;br /&gt;
options=&amp;quot;!strip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_builddir=&amp;quot;$srcdir/$pkgname-$pkgver&amp;quot;&lt;br /&gt;
prepare() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	for _i in &amp;quot;$srcdir&amp;quot;/*.patch; do&lt;br /&gt;
		patch -p1 -i &amp;quot;$_i&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
build() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	./configure --prefix=/usr \&lt;br /&gt;
		--sysconfdir=/etc \&lt;br /&gt;
		--mandir=/usr/share/man \&lt;br /&gt;
		--infodir=/usr/share/info &lt;br /&gt;
	make&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
package() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	make -j1 DESTDIR=&amp;quot;$pkgdir&amp;quot; install&lt;br /&gt;
	install -Dm644 COPYING &amp;quot;$pkgdir&amp;quot;/usr/share/licenses/$pkgname/COPYING&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
py() {&lt;br /&gt;
	cd &amp;quot;$_builddir&amp;quot;&lt;br /&gt;
	pkgdesc=&amp;quot;$pkgname python bindings&amp;quot;&lt;br /&gt;
	install -d &amp;quot;$subpkgdir&amp;quot;/usr/lib&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/lib/python* &amp;quot;$subpkgdir&amp;quot;/usr/lib/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
utils() {&lt;br /&gt;
	pkgdesc=&amp;quot;XML utilities&amp;quot;&lt;br /&gt;
	replaces=&amp;quot;libxml2&amp;quot;&lt;br /&gt;
	mkdir -p &amp;quot;$subpkgdir&amp;quot;/usr&lt;br /&gt;
	mv &amp;quot;$pkgdir&amp;quot;/usr/bin &amp;quot;$subpkgdir&amp;quot;/usr/&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
md5sums=&amp;quot;8127a65e8c3b08856093099b52599c86  libxml2-2.7.8.tar.gz&lt;br /&gt;
5ad4915665608ebfa5b89f7908467a72  largefile64.patch&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mattx86</name></author>
	</entry>
</feed>