<?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=Amanison</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=Amanison"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Amanison"/>
	<updated>2026-05-03T01:12:08Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Creating_an_Alpine_package&amp;diff=4823</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=4823"/>
		<updated>2011-01-10T16:58:02Z</updated>

		<summary type="html">&lt;p&gt;Amanison: /* Installing and configuring the alpine-sdk */&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;
We also need to prepare the location that the build process caches files when they are downloaded. By default this is /var/cache/distfiles. To create this directory and ensure that it is writeable, enter the following commands:&lt;br /&gt;
&lt;br /&gt;
  sudo mkdir -p /var/cache/distfiles&lt;br /&gt;
  sudo chmod a+w /var/cache/distfiles&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>Amanison</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_a_SSH_server&amp;diff=3310</id>
		<title>Setting up a SSH server</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_a_SSH_server&amp;diff=3310"/>
		<updated>2010-01-24T17:38:21Z</updated>

		<summary type="html">&lt;p&gt;Amanison: /* Make it autostart */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= General =&lt;br /&gt;
If you need to administer a Alpine Linux box, you can install and use openssh.&amp;lt;BR&amp;gt;&lt;br /&gt;
Openssh is used to provide a secure encrypted communications between you and the host where openssh is running (the ssh-server is called &#039;&#039;sshd&#039;&#039; and the ssh-client is called &#039;&#039;ssh&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
== Initial Setup ==&lt;br /&gt;
We assume you are running a &#039;&#039;alpine-1.8.x&#039;&#039;. If not, please follow [http://wiki.alpinelinux.org/w/index.php?title=Installing_Alpine Installing_Alpine] on how to setup Alpine.&lt;br /&gt;
&lt;br /&gt;
== Install programs ==&lt;br /&gt;
Installing programs in Alpine Linux is easy.&amp;lt;BR&amp;gt;&lt;br /&gt;
In this case we only need to install one program:&lt;br /&gt;
 apk_add openssh&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; If you want the ACF-frontend for openssh, you should install &#039;acf-openssh&#039; instead (assuming that you have setup-webconf)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Make it autostart ==&lt;br /&gt;
Next time you reboot your Linux box, you would probably want your &#039;&#039;sshd&#039;&#039; to automatically start.&lt;br /&gt;
 rc-update add sshd&lt;br /&gt;
&lt;br /&gt;
You can check your boot sequence:&lt;br /&gt;
 rc_status&lt;br /&gt;
&lt;br /&gt;
== Start it up now ==&lt;br /&gt;
The reason we want to manually start &#039;&#039;sshd&#039;&#039; at this moment is...&amp;lt;BR&amp;gt;&lt;br /&gt;
We want &#039;&#039;sshd&#039;&#039; to create some initial files that he needs. After they are created, we can permanently save them.&amp;lt;BR&amp;gt;&lt;br /&gt;
Next reason is... we don&#039;t have time to wait for the box to reboot ;-)&lt;br /&gt;
 /etc/init.d/sshd start&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; Don&#039;t forget to permanently save your settings by using the &#039;lbu ci&#039; command when you are done.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
= Fine tuning =&lt;br /&gt;
The default config that comes with openssh has pretty good default values.&amp;lt;BR&amp;gt;&lt;br /&gt;
But sometimes you would like to fine-tune things. We show some examples below on what you might want to do.&amp;lt;BR&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; You are _not_ required to follow this [[#Fine_tuning]] section. You can skip it if you want to make things easy!&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The fine-tuning is done by editing &#039;&#039;&#039;/etc/ssh/sshd_config&#039;&#039;&#039;&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;quot;#&amp;quot; marks that the rest of the line should be ignored by &#039;&#039;sshd&#039;&#039;. Everything right to the &amp;quot;#&amp;quot; is treated as comments.&lt;br /&gt;
 UseDNS no   # By setting this to no, you could increase speed when the client starts to connect to this ssh-server&lt;br /&gt;
 PasswordAuthentication no   # Instead you could use private/public keys to authenticate to this box (this increases security for the box)&lt;br /&gt;
Many other options are found in &#039;&#039;&#039;/etc/ssh/sshd_config&#039;&#039;&#039;. The describing text that comes in the same file will guide you in your fine-tuning.&lt;br /&gt;
&lt;br /&gt;
= Firewalling =&lt;br /&gt;
As default, sshd will communicate on port &#039;&#039;&#039;&#039;22&#039;&#039;&#039;&#039; using protocol &#039;&#039;&#039;&#039;TCP&#039;&#039;&#039;&#039;.&amp;lt;BR&amp;gt;&lt;br /&gt;
You would need to make sure that the box where &#039;&#039;sshd&#039;&#039; is running, doesn&#039;t block your connection attempts on &#039;&#039;&#039;22TCP&#039;&#039;&#039;.&amp;lt;BR&amp;gt;&lt;br /&gt;
If you still have trouble accessing your box, make sure that there is no other firewall blocking your connection.&lt;br /&gt;
&lt;br /&gt;
Sometimes &#039;&#039;&#039;22TCP&#039;&#039;&#039; is blocked by some firewall that you can not control. In those cases you might want to configure &#039;&#039;&#039;sshd&#039;&#039;&#039; to communicate on some other port.&amp;lt;BR&amp;gt;&lt;br /&gt;
In that case you change &#039;&#039;&#039;/etc/ssh/sshd_config&#039;&#039;&#039; to reflect your needs.&amp;lt;BR&amp;gt;&lt;br /&gt;
But before you do so, you need to check so you don&#039;t use a port that already is in use. (You can check this by using the command &#039;&#039;&#039;&#039;netstat -ln&#039;&#039;&#039;&#039; on the box where you plan to run &#039;&#039;sshd&#039;&#039;)&lt;br /&gt;
 Port 443   # Use whatever port number that fits your needs&lt;br /&gt;
&lt;br /&gt;
You need to restart &#039;&#039;sshd&#039;&#039; after you done you modifications.&lt;br /&gt;
 /etc/init.d/sshd restart&lt;br /&gt;
&lt;br /&gt;
= Save settings =&lt;br /&gt;
If you already haven&#039;t done so, save all your settings&lt;br /&gt;
 lbu ci&lt;/div&gt;</summary>
		<author><name>Amanison</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_Configuration_Framework_Design&amp;diff=3276</id>
		<title>Alpine Configuration Framework Design</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_Configuration_Framework_Design&amp;diff=3276"/>
		<updated>2009-11-27T18:37:22Z</updated>

		<summary type="html">&lt;p&gt;Amanison: /* Starting ACF */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Alpine Configuration Framework  =&lt;br /&gt;
&lt;br /&gt;
The Alpine Configuration Framework (ACF) is a mvc-style application for configuring an Alpine device. The primary focus is for a web interface - ACF&#039;s main goal is to be a light-weight MVC &amp;quot;webmin&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
== Why Haserl + Lua  ==&lt;br /&gt;
&lt;br /&gt;
Other competitors in the arena were Webmin, Ruby on Rails, PHP with templates. &lt;br /&gt;
&lt;br /&gt;
A full webmin (Perl), RoR or PHP implementation each require several MB of installed code, and can have very slow startup times, especially when used in &amp;quot;cgi&amp;quot; mode. After evaluating many options, we found that [http://www.lua.org Lua] has the following advantages: &lt;br /&gt;
&lt;br /&gt;
*It is small (typically ~200KB of compiled code) &lt;br /&gt;
*It compiles and runs much faster than [http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&amp;amp;lang=lua&amp;amp;lang2=php PHP], [http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&amp;amp;lang=lua&amp;amp;lang2=perl Perl] or [http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&amp;amp;lang=lua&amp;amp;lang2=ruby Ruby] &lt;br /&gt;
*It provides a &amp;quot;normal&amp;quot; scripting language with [http://en.wikipedia.org/wiki/Lua_(programming_language)#Features features] similar to PHP, perl, java, awk, etc.&lt;br /&gt;
&lt;br /&gt;
Haserl + Lua provides a &#039;good enough&#039; toolset to build a full-featured web application. &lt;br /&gt;
&lt;br /&gt;
== Why ACF is MVC  ==&lt;br /&gt;
&lt;br /&gt;
The MVC design pattern is used to separate presentation information from control logic. By MVC we mean: &lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Model&#039;&#039;&#039; - code that reads / writes a config file, starts / stops daemons, or does other work modifying the router. &lt;br /&gt;
*&#039;&#039;&#039;View&#039;&#039;&#039; - code that formats data for output &lt;br /&gt;
*&#039;&#039;&#039;Controller&#039;&#039;&#039; - code that glues the two together&lt;br /&gt;
&lt;br /&gt;
Note the lack of words like: HTML, XML, OO, AJAX, etc. The purpose of ACF&#039;s MVC is simply to separate the configuration logic from the presentation of the output. &lt;br /&gt;
&lt;br /&gt;
The flow of a single transaction is: &lt;br /&gt;
&lt;br /&gt;
start -&amp;amp;gt; execute requested function in &#039;&#039;&#039;controller&#039;&#039;&#039;, optionally reading/writing a file using functions in the &#039;&#039;&#039;model&#039;&#039;&#039; -&amp;amp;gt; execute the &#039;&#039;&#039;view&#039;&#039;&#039; to format the output -&amp;amp;gt; end &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Every&#039;&#039; transaction follows this pattern. For ACF developers, the focus should be on getting a model that does a proper job of abstracting the config file into useable entities and then building a controller that presents useable &amp;quot;actions&amp;quot; based on the model. The presentation layer should be last on the priority list. &lt;br /&gt;
&lt;br /&gt;
For good background information on what ACF attempts to do, please see Terence Parr&#039;s paper &amp;quot;Enforcing Strict Model-View Separation in Template Engines&amp;quot; at [http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf http://www.cs.usfcs.edu] or the [[Media:Mvc.templates.pdf|local copy]] of the pdf. &lt;br /&gt;
&lt;br /&gt;
= Starting ACF  =&lt;br /&gt;
&lt;br /&gt;
The easiest way to start ACF is to run the &#039;&#039;setup-webconf&#039;&#039; script (renamed to &#039;&#039;setup-acf&#039;&#039; in Alpine beta 4 and later). This script will install mini-httpd, create a certificate, and start mini-httpd in HTTPS mode. &#039;&#039;&#039;WARNING - This will give anyone on the network access to your machine.&#039;&#039;&#039; The script will also install the two packages that are necessary for basic ACF: acf-core and acf-alpine-baselayout. To view ACF, simply browse to your machine (https://&amp;amp;lt;hostname&amp;amp;gt;/). &lt;br /&gt;
&lt;br /&gt;
Alternately, you can manually install ACF and your web server. Once again, the two critical ACF packages are acf-core and acf-alpine-baselayout. The ACF packages will install to /usr/share/acf. You can configure your web server to give access to /usr/share/acf/www and run cgi scripts from /usr/share/acf/www/cgi-bin, and you should be able to view ACF. &lt;br /&gt;
&lt;br /&gt;
If you would like to play with other ACF packages, we recommend you install the acf-apk-tools package. This package will allow you to install / delete other packages using ACF. You can then load any other acf-* packages you are interested in. &lt;br /&gt;
&lt;br /&gt;
In alpine 1.8, the system includes two default users: &#039;&#039;alpine&#039;&#039; and &#039;&#039;foo&#039;&#039;. &#039;alpine&#039; is given ADMIN rights and &#039;foo&#039; is given USER rights. The default password for both users is &#039;&#039;test123&#039;&#039;. &#039;&#039;&#039;Replace the default users as soon as possible.&#039;&#039;&#039; In alpine 1.9, you will be prompted to create an initial user the first time you try to log in. (As of 1.9.1, the initial user is already created and is the root account for the system.)&lt;br /&gt;
&lt;br /&gt;
[[Managing ACF|Managing Your ACF Installation]]&lt;br /&gt;
&lt;br /&gt;
= ACF Developer&#039;s Guides  =&lt;br /&gt;
&lt;br /&gt;
#[[ACF mvc.lua reference|mvc.lua reference]] - mvc.lua is the core of ACF &lt;br /&gt;
#[[ACF mvc.lua example|mvc.lua example]] - build a simple (command-line) application &lt;br /&gt;
#[[ACF acf www-controller.lua reference|acf www-controller reference]] - ACF www application functions &lt;br /&gt;
#[[ACF acf www example|acf www-controller example]] - webify the above examples &lt;br /&gt;
#[[ACF how to write]] - Step by step howto for writing acfs &lt;br /&gt;
#[[ACF core principles]] - Things that are standard across the application &lt;br /&gt;
#[[LPOSIX]] - Documentation for the Lua Posix functions &lt;br /&gt;
#[[ACF Libraries]] - Document the libraries and common functions &lt;br /&gt;
#[[Writing ACF Views]] - Guide for writing a view &lt;br /&gt;
#[[Writing ACF Controllers]] - Guide for writing a controller &lt;br /&gt;
#[[Writing ACF Models]] - Guide for writing a model&lt;br /&gt;
&lt;br /&gt;
== Other useful links  ==&lt;br /&gt;
&lt;br /&gt;
#[http://www.lua.org/manual/5.1/ Lua 5.1 Reference Manual] &lt;br /&gt;
#[http://www.lua.org/pil/ Programming in Lua (first edition)]&lt;br /&gt;
&lt;br /&gt;
= ACF Layout  =&lt;br /&gt;
&lt;br /&gt;
ACF has support for multiple skins.&amp;lt;br&amp;gt;Only a few skins are available. Feel free to contribute in programming css-stylesheets for ACF. &lt;br /&gt;
&lt;br /&gt;
== Howto contribute  ==&lt;br /&gt;
&lt;br /&gt;
First download ACF using git or installing available acf&#039;s using apk_add.&amp;lt;br&amp;gt;Easiest is if you download latest Alpine ISO, boot a box on that and then run &#039;setup-alpine&#039; and &#039;setup-webconf -a&#039; (renamed to &#039;&#039;setup-acf&#039;&#039; in Alpine beta 4 and later)that way you get a running environment fast and easy!&amp;lt;br&amp;gt;Some example skins are available &lt;br /&gt;
&lt;br /&gt;
*/usr/share/acf/www/skins/ice/ &lt;br /&gt;
*/usr/share/acf/www/skins/snow/&lt;br /&gt;
&lt;br /&gt;
Make a new skin-folder &lt;br /&gt;
&lt;br /&gt;
 mkdir /usr/share/acf/www/skins/myskin&lt;br /&gt;
&lt;br /&gt;
Create a css file called as the folder. &lt;br /&gt;
&lt;br /&gt;
 touch /usr/share/acf/www/skins/myskin/myskin.css&lt;br /&gt;
&lt;br /&gt;
Now you can start editing your myskin.css.&amp;lt;br&amp;gt;If you have ACF running on a computer, you can browse to this ACF-page and switch to your new skin (called myskin) and see the results of your changes. &lt;br /&gt;
&lt;br /&gt;
Pack your myskin-folder, containing your css-file (and images, if there is any).&amp;lt;br&amp;gt;Send this patch to acf@lists.alpinelinux.org &#039;&#039;(&#039;&#039;&#039;Note:&#039;&#039;&#039; Don&#039;t forget to [http://wiki.alpinelinux.org/w/index.php?title=Mailing_lists subscribe] before sending your patch)&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
= ACF Packages  =&lt;br /&gt;
&lt;br /&gt;
Look at [http://wiki.alpinelinux.org/w/index.php?title=ACF_packages ACF packages] to see available ACF modules and their status.&lt;/div&gt;</summary>
		<author><name>Amanison</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Creating_an_Alpine_package&amp;diff=3274</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=3274"/>
		<updated>2009-11-24T09:27:55Z</updated>

		<summary type="html">&lt;p&gt;Amanison: /* pkgdesc */&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;
  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;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The &#039;packagename&#039; is a parameter to the -n option so order of -c and -n matters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This will copy the sample initd and confd files to the build directory.&amp;lt;BR&amp;gt;&lt;br /&gt;
A third file sample.install file will be copied as well (we will discuss this later on).&lt;br /&gt;
&lt;br /&gt;
=== Modify your APKBUILD ===&lt;br /&gt;
Edit APKBUILD and fill in the needed info (especially pkgname, pkgver, pkgdesc, url, license, depends and source). &lt;br /&gt;
&lt;br /&gt;
If you are going to use any of the variables for directories like $pkgdir, always make sure they are double quoted like: &lt;br /&gt;
&lt;br /&gt;
 &amp;quot;$pkgdir&amp;quot;/somedir&lt;br /&gt;
&lt;br /&gt;
This will prevent issues with spaces/special characters in the future. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; 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.&#039;&#039;&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. When you are finished adding them you can execute the following command to add their checksums to the APKBUILD file: &lt;br /&gt;
&lt;br /&gt;
 abuild checksum&lt;br /&gt;
&lt;br /&gt;
Another thing to note is when a package is using sourceforge for hosting. If so you should specify the special mirrors link used by sf: &lt;br /&gt;
&lt;br /&gt;
 http://downloads.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.gz &lt;br /&gt;
&lt;br /&gt;
(or similar depending on the package). &lt;br /&gt;
&lt;br /&gt;
Currently abuild supports the following archives/extensions: &lt;br /&gt;
&lt;br /&gt;
 *.tar.gz, *.tgz, *.tar.bz2, *.tar.lzma, *.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 Archlinux (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/ Archlinux 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;
==== 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;
A brief, one line, description of what the package does. Useful for the package management system. &amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example from apk_info&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
openssh-client-5.1_p1-r1 - Port of OpenBSD&#039;s free SSH release - client&amp;lt;br&amp;gt;&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;
editme &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 extra. If you are not sure your package works at all you need to use testing.&lt;/div&gt;</summary>
		<author><name>Amanison</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Creating_an_Alpine_package&amp;diff=3273</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=3273"/>
		<updated>2009-11-24T09:26:35Z</updated>

		<summary type="html">&lt;p&gt;Amanison: /* pkgdesc */&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;
  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;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The &#039;packagename&#039; is a parameter to the -n option so order of -c and -n matters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This will copy the sample initd and confd files to the build directory.&amp;lt;BR&amp;gt;&lt;br /&gt;
A third file sample.install file will be copied as well (we will discuss this later on).&lt;br /&gt;
&lt;br /&gt;
=== Modify your APKBUILD ===&lt;br /&gt;
Edit APKBUILD and fill in the needed info (especially pkgname, pkgver, pkgdesc, url, license, depends and source). &lt;br /&gt;
&lt;br /&gt;
If you are going to use any of the variables for directories like $pkgdir, always make sure they are double quoted like: &lt;br /&gt;
&lt;br /&gt;
 &amp;quot;$pkgdir&amp;quot;/somedir&lt;br /&gt;
&lt;br /&gt;
This will prevent issues with spaces/special characters in the future. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; 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.&#039;&#039;&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. When you are finished adding them you can execute the following command to add their checksums to the APKBUILD file: &lt;br /&gt;
&lt;br /&gt;
 abuild checksum&lt;br /&gt;
&lt;br /&gt;
Another thing to note is when a package is using sourceforge for hosting. If so you should specify the special mirrors link used by sf: &lt;br /&gt;
&lt;br /&gt;
 http://downloads.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.gz &lt;br /&gt;
&lt;br /&gt;
(or similar depending on the package). &lt;br /&gt;
&lt;br /&gt;
Currently abuild supports the following archives/extensions: &lt;br /&gt;
&lt;br /&gt;
 *.tar.gz, *.tgz, *.tar.bz2, *.tar.lzma, *.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 Archlinux (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/ Archlinux 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;
==== 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&amp;lt;br&amp;gt; &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;
A brief, one line, description of what the package does. Useful for the package management system. &amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example from apk_info&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
openssh-client-5.1_p1-r1 - Port of OpenBSD&#039;s free SSH release - client&amp;lt;br&amp;gt;&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;
editme &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 extra. If you are not sure your package works at all you need to use testing.&lt;/div&gt;</summary>
		<author><name>Amanison</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Creating_an_Alpine_package&amp;diff=3272</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=3272"/>
		<updated>2009-11-24T09:25:52Z</updated>

		<summary type="html">&lt;p&gt;Amanison: /* pkgdesc */&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;
  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;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The &#039;packagename&#039; is a parameter to the -n option so order of -c and -n matters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This will copy the sample initd and confd files to the build directory.&amp;lt;BR&amp;gt;&lt;br /&gt;
A third file sample.install file will be copied as well (we will discuss this later on).&lt;br /&gt;
&lt;br /&gt;
=== Modify your APKBUILD ===&lt;br /&gt;
Edit APKBUILD and fill in the needed info (especially pkgname, pkgver, pkgdesc, url, license, depends and source). &lt;br /&gt;
&lt;br /&gt;
If you are going to use any of the variables for directories like $pkgdir, always make sure they are double quoted like: &lt;br /&gt;
&lt;br /&gt;
 &amp;quot;$pkgdir&amp;quot;/somedir&lt;br /&gt;
&lt;br /&gt;
This will prevent issues with spaces/special characters in the future. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; 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.&#039;&#039;&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. When you are finished adding them you can execute the following command to add their checksums to the APKBUILD file: &lt;br /&gt;
&lt;br /&gt;
 abuild checksum&lt;br /&gt;
&lt;br /&gt;
Another thing to note is when a package is using sourceforge for hosting. If so you should specify the special mirrors link used by sf: &lt;br /&gt;
&lt;br /&gt;
 http://downloads.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.gz &lt;br /&gt;
&lt;br /&gt;
(or similar depending on the package). &lt;br /&gt;
&lt;br /&gt;
Currently abuild supports the following archives/extensions: &lt;br /&gt;
&lt;br /&gt;
 *.tar.gz, *.tgz, *.tar.bz2, *.tar.lzma, *.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 Archlinux (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/ Archlinux 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;
==== 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. &amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Here is an example from apk_info&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
 pkgdesc=&amp;quot;Port of OpenBSD&#039;s free SSH release - client&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== pkgver  ====&lt;br /&gt;
&lt;br /&gt;
A brief, one line, description of what the package does. Useful for the package management system. &amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example from apk_info&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
openssh-client-5.1_p1-r1 - Port of OpenBSD&#039;s free SSH release - client&amp;lt;br&amp;gt;&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;
editme &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 extra. If you are not sure your package works at all you need to use testing.&lt;/div&gt;</summary>
		<author><name>Amanison</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Creating_an_Alpine_package&amp;diff=3271</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=3271"/>
		<updated>2009-11-24T09:23:23Z</updated>

		<summary type="html">&lt;p&gt;Amanison: /* license */&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;
  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;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The &#039;packagename&#039; is a parameter to the -n option so order of -c and -n matters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This will copy the sample initd and confd files to the build directory.&amp;lt;BR&amp;gt;&lt;br /&gt;
A third file sample.install file will be copied as well (we will discuss this later on).&lt;br /&gt;
&lt;br /&gt;
=== Modify your APKBUILD ===&lt;br /&gt;
Edit APKBUILD and fill in the needed info (especially pkgname, pkgver, pkgdesc, url, license, depends and source). &lt;br /&gt;
&lt;br /&gt;
If you are going to use any of the variables for directories like $pkgdir, always make sure they are double quoted like: &lt;br /&gt;
&lt;br /&gt;
 &amp;quot;$pkgdir&amp;quot;/somedir&lt;br /&gt;
&lt;br /&gt;
This will prevent issues with spaces/special characters in the future. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; 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.&#039;&#039;&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. When you are finished adding them you can execute the following command to add their checksums to the APKBUILD file: &lt;br /&gt;
&lt;br /&gt;
 abuild checksum&lt;br /&gt;
&lt;br /&gt;
Another thing to note is when a package is using sourceforge for hosting. If so you should specify the special mirrors link used by sf: &lt;br /&gt;
&lt;br /&gt;
 http://downloads.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.gz &lt;br /&gt;
&lt;br /&gt;
(or similar depending on the package). &lt;br /&gt;
&lt;br /&gt;
Currently abuild supports the following archives/extensions: &lt;br /&gt;
&lt;br /&gt;
 *.tar.gz, *.tgz, *.tar.bz2, *.tar.lzma, *.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 Archlinux (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/ Archlinux 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;
==== 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;
editme &lt;br /&gt;
&lt;br /&gt;
==== pkgver  ====&lt;br /&gt;
&lt;br /&gt;
A brief, one line, description of what the package does. Useful for the package management system. &amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example from apk_info&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
openssh-client-5.1_p1-r1 - Port of OpenBSD&#039;s free SSH release - client&amp;lt;br&amp;gt;&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;
editme &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 extra. If you are not sure your package works at all you need to use testing.&lt;/div&gt;</summary>
		<author><name>Amanison</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Creating_an_Alpine_package&amp;diff=3270</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=3270"/>
		<updated>2009-11-24T09:19:35Z</updated>

		<summary type="html">&lt;p&gt;Amanison: /* depends &amp;amp;amp; makedepends */&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;
  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;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The &#039;packagename&#039; is a parameter to the -n option so order of -c and -n matters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This will copy the sample initd and confd files to the build directory.&amp;lt;BR&amp;gt;&lt;br /&gt;
A third file sample.install file will be copied as well (we will discuss this later on).&lt;br /&gt;
&lt;br /&gt;
=== Modify your APKBUILD ===&lt;br /&gt;
Edit APKBUILD and fill in the needed info (especially pkgname, pkgver, pkgdesc, url, license, depends and source). &lt;br /&gt;
&lt;br /&gt;
If you are going to use any of the variables for directories like $pkgdir, always make sure they are double quoted like: &lt;br /&gt;
&lt;br /&gt;
 &amp;quot;$pkgdir&amp;quot;/somedir&lt;br /&gt;
&lt;br /&gt;
This will prevent issues with spaces/special characters in the future. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; 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.&#039;&#039;&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. When you are finished adding them you can execute the following command to add their checksums to the APKBUILD file: &lt;br /&gt;
&lt;br /&gt;
 abuild checksum&lt;br /&gt;
&lt;br /&gt;
Another thing to note is when a package is using sourceforge for hosting. If so you should specify the special mirrors link used by sf: &lt;br /&gt;
&lt;br /&gt;
 http://downloads.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.gz &lt;br /&gt;
&lt;br /&gt;
(or similar depending on the package). &lt;br /&gt;
&lt;br /&gt;
Currently abuild supports the following archives/extensions: &lt;br /&gt;
&lt;br /&gt;
 *.tar.gz, *.tgz, *.tar.bz2, *.tar.lzma, *.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 Archlinux (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/ Archlinux 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 into the doc subpackage. Please follow the following guideline to add a proper license. Locate the license file inside the source package. Add to $subpackages variable the following: &lt;br /&gt;
&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-doc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And add a similar line to your build() function depending on the license: &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 automaticly add the license to the package-doc apk for you. &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;
editme &lt;br /&gt;
&lt;br /&gt;
==== pkgver  ====&lt;br /&gt;
&lt;br /&gt;
A brief, one line, description of what the package does. Useful for the package management system. &amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example from apk_info&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
openssh-client-5.1_p1-r1 - Port of OpenBSD&#039;s free SSH release - client&amp;lt;br&amp;gt;&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;
editme &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 extra. If you are not sure your package works at all you need to use testing.&lt;/div&gt;</summary>
		<author><name>Amanison</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Creating_an_Alpine_package&amp;diff=3269</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=3269"/>
		<updated>2009-11-24T09:13:51Z</updated>

		<summary type="html">&lt;p&gt;Amanison: /* source */&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;
  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;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The &#039;packagename&#039; is a parameter to the -n option so order of -c and -n matters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This will copy the sample initd and confd files to the build directory.&amp;lt;BR&amp;gt;&lt;br /&gt;
A third file sample.install file will be copied as well (we will discuss this later on).&lt;br /&gt;
&lt;br /&gt;
=== Modify your APKBUILD ===&lt;br /&gt;
Edit APKBUILD and fill in the needed info (especially pkgname, pkgver, pkgdesc, url, license, depends and source). &lt;br /&gt;
&lt;br /&gt;
If you are going to use any of the variables for directories like $pkgdir, always make sure they are double quoted like: &lt;br /&gt;
&lt;br /&gt;
 &amp;quot;$pkgdir&amp;quot;/somedir&lt;br /&gt;
&lt;br /&gt;
This will prevent issues with spaces/special characters in the future. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; 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.&#039;&#039;&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. When you are finished adding them you can execute the following command to add their checksums to the APKBUILD file: &lt;br /&gt;
&lt;br /&gt;
 abuild checksum&lt;br /&gt;
&lt;br /&gt;
Another thing to note is when a package is using sourceforge for hosting. If so you should specify the special mirrors link used by sf: &lt;br /&gt;
&lt;br /&gt;
 http://downloads.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.gz &lt;br /&gt;
&lt;br /&gt;
(or similar depending on the package). &lt;br /&gt;
&lt;br /&gt;
Currently abuild supports the following archives/extensions: &lt;br /&gt;
&lt;br /&gt;
 *.tar.gz, *.tgz, *.tar.bz2, *.tar.lzma, *.zip&lt;br /&gt;
&lt;br /&gt;
==== depends &amp;amp;amp; makedepends  ====&lt;br /&gt;
&lt;br /&gt;
Depends are the actual running dependencies which a package would need when you are using it. 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 anymore. The best way to find out what depends and makedepeds are of a package 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 by doing: &lt;br /&gt;
&lt;br /&gt;
 abuild unpack&lt;br /&gt;
&lt;br /&gt;
It 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 loosing to many features. The exact disable/enable options are decided the package builder but please try to follow Alpines design concept as much as possible. &lt;br /&gt;
&lt;br /&gt;
An easy way of quickly finding out build info of a package is to check Archlinux (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/ Archlinux 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 which is not present in the $depends variable. We do this be 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;
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 into the doc subpackage. Please follow the following guideline to add a proper license. Locate the license file inside the source package. Add to $subpackages variable the following: &lt;br /&gt;
&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-doc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And add a similar line to your build() function depending on the license: &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 automaticly add the license to the package-doc apk for you. &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;
editme &lt;br /&gt;
&lt;br /&gt;
==== pkgver  ====&lt;br /&gt;
&lt;br /&gt;
A brief, one line, description of what the package does. Useful for the package management system. &amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example from apk_info&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
openssh-client-5.1_p1-r1 - Port of OpenBSD&#039;s free SSH release - client&amp;lt;br&amp;gt;&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;
editme &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 extra. If you are not sure your package works at all you need to use testing.&lt;/div&gt;</summary>
		<author><name>Amanison</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Creating_an_Alpine_package&amp;diff=3268</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=3268"/>
		<updated>2009-11-24T09:11:18Z</updated>

		<summary type="html">&lt;p&gt;Amanison: /* Modify your APKBUILD */&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;
  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;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The &#039;packagename&#039; is a parameter to the -n option so order of -c and -n matters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This will copy the sample initd and confd files to the build directory.&amp;lt;BR&amp;gt;&lt;br /&gt;
A third file sample.install file will be copied as well (we will discuss this later on).&lt;br /&gt;
&lt;br /&gt;
=== Modify your APKBUILD ===&lt;br /&gt;
Edit APKBUILD and fill in the needed info (especially pkgname, pkgver, pkgdesc, url, license, depends and source). &lt;br /&gt;
&lt;br /&gt;
If you are going to use any of the variables for directories like $pkgdir, always make sure they are double quoted like: &lt;br /&gt;
&lt;br /&gt;
 &amp;quot;$pkgdir&amp;quot;/somedir&lt;br /&gt;
&lt;br /&gt;
This will prevent issues with spaces/special characters in the future. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; 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.&#039;&#039;&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. When you are finished adding them you can execute the following cmd to add checksum&#039;s to the APKBUILD file: &lt;br /&gt;
&lt;br /&gt;
 abuild checksum&lt;br /&gt;
&lt;br /&gt;
Another thing to note is when a package is using sourceforge as hosting, if so you should add special mirrors link used by sf: &lt;br /&gt;
&lt;br /&gt;
 http://downloads.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.gz &lt;br /&gt;
&lt;br /&gt;
(or similar depending on the package). &lt;br /&gt;
&lt;br /&gt;
Currently abuild support the following archives/extensions: &lt;br /&gt;
&lt;br /&gt;
 *.tar.gz, *.tgz, *.tar.bz2, *.tar.lzma, *.zip&lt;br /&gt;
&lt;br /&gt;
==== depends &amp;amp;amp; makedepends  ====&lt;br /&gt;
&lt;br /&gt;
Depends are the actual running dependencies which a package would need when you are using it. 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 anymore. The best way to find out what depends and makedepeds are of a package 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 by doing: &lt;br /&gt;
&lt;br /&gt;
 abuild unpack&lt;br /&gt;
&lt;br /&gt;
It 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 loosing to many features. The exact disable/enable options are decided the package builder but please try to follow Alpines design concept as much as possible. &lt;br /&gt;
&lt;br /&gt;
An easy way of quickly finding out build info of a package is to check Archlinux (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/ Archlinux 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 which is not present in the $depends variable. We do this be 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;
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 into the doc subpackage. Please follow the following guideline to add a proper license. Locate the license file inside the source package. Add to $subpackages variable the following: &lt;br /&gt;
&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-doc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And add a similar line to your build() function depending on the license: &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 automaticly add the license to the package-doc apk for you. &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;
editme &lt;br /&gt;
&lt;br /&gt;
==== pkgver  ====&lt;br /&gt;
&lt;br /&gt;
A brief, one line, description of what the package does. Useful for the package management system. &amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example from apk_info&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
openssh-client-5.1_p1-r1 - Port of OpenBSD&#039;s free SSH release - client&amp;lt;br&amp;gt;&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;
editme &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 extra. If you are not sure your package works at all you need to use testing.&lt;/div&gt;</summary>
		<author><name>Amanison</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Creating_an_Alpine_package&amp;diff=3251</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=3251"/>
		<updated>2009-11-06T17:58:26Z</updated>

		<summary type="html">&lt;p&gt;Amanison: /* Installing and configuring the alpine-sdk */&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;
  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;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The &#039;packagename&#039; is a parameter to the -n option so order of -c and -n matters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This will copy the sample initd and confd files to the build directory.&amp;lt;BR&amp;gt;&lt;br /&gt;
A third file sample.install file will be copied as well (we will discuss this later on).&lt;br /&gt;
&lt;br /&gt;
=== Modify your APKBUILD ===&lt;br /&gt;
Edit APKBUILD and fill in the needed info (especially pkgname, pkgver, pkgdesc, url, license, depends and source). &lt;br /&gt;
&lt;br /&gt;
If you are going to use any of the variables for directory&#039;s 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;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; 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.&#039;&#039;&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. When you are finished adding them you can execute the following cmd to add checksum&#039;s to the APKBUILD file: &lt;br /&gt;
&lt;br /&gt;
 abuild checksum&lt;br /&gt;
&lt;br /&gt;
Another thing to note is when a package is using sourceforge as hosting, if so you should add special mirrors link used by sf: &lt;br /&gt;
&lt;br /&gt;
 http://downloads.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.gz &lt;br /&gt;
&lt;br /&gt;
(or similar depending on the package). &lt;br /&gt;
&lt;br /&gt;
Currently abuild support the following archives/extensions: &lt;br /&gt;
&lt;br /&gt;
 *.tar.gz, *.tgz, *.tar.bz2, *.tar.lzma, *.zip&lt;br /&gt;
&lt;br /&gt;
==== depends &amp;amp;amp; makedepends  ====&lt;br /&gt;
&lt;br /&gt;
Depends are the actual running dependencies which a package would need when you are using it. 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 anymore. The best way to find out what depends and makedepeds are of a package 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 by doing: &lt;br /&gt;
&lt;br /&gt;
 abuild unpack&lt;br /&gt;
&lt;br /&gt;
It 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 loosing to many features. The exact disable/enable options are decided the package builder but please try to follow Alpines design concept as much as possible. &lt;br /&gt;
&lt;br /&gt;
An easy way of quickly finding out build info of a package is to check Archlinux (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/ Archlinux 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 which is not present in the $depends variable. We do this be 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;
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 into the doc subpackage. Please follow the following guideline to add a proper license. Locate the license file inside the source package. Add to $subpackages variable the following: &lt;br /&gt;
&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-doc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And add a similar line to your build() function depending on the license: &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 automaticly add the license to the package-doc apk for you. &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;
editme &lt;br /&gt;
&lt;br /&gt;
==== pkgver  ====&lt;br /&gt;
&lt;br /&gt;
A brief, one line, description of what the package does. Useful for the package management system. &amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example from apk_info&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
openssh-client-5.1_p1-r1 - Port of OpenBSD&#039;s free SSH release - client&amp;lt;br&amp;gt;&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;
editme &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 extra. If you are not sure your package works at all you need to use testing.&lt;/div&gt;</summary>
		<author><name>Amanison</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Creating_an_Alpine_package&amp;diff=3250</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=3250"/>
		<updated>2009-11-06T16:34:43Z</updated>

		<summary type="html">&lt;p&gt;Amanison: /* Installing and configuring the alpine-sdk */&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;
  vi /etc/abuild.conf&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;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The &#039;packagename&#039; is a parameter to the -n option so order of -c and -n matters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This will copy the sample initd and confd files to the build directory.&amp;lt;BR&amp;gt;&lt;br /&gt;
A third file sample.install file will be copied as well (we will discuss this later on).&lt;br /&gt;
&lt;br /&gt;
=== Modify your APKBUILD ===&lt;br /&gt;
Edit APKBUILD and fill in the needed info (especially pkgname, pkgver, pkgdesc, url, license, depends and source). &lt;br /&gt;
&lt;br /&gt;
If you are going to use any of the variables for directory&#039;s 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;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; 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.&#039;&#039;&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. When you are finished adding them you can execute the following cmd to add checksum&#039;s to the APKBUILD file: &lt;br /&gt;
&lt;br /&gt;
 abuild checksum&lt;br /&gt;
&lt;br /&gt;
Another thing to note is when a package is using sourceforge as hosting, if so you should add special mirrors link used by sf: &lt;br /&gt;
&lt;br /&gt;
 http://downloads.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.gz &lt;br /&gt;
&lt;br /&gt;
(or similar depending on the package). &lt;br /&gt;
&lt;br /&gt;
Currently abuild support the following archives/extensions: &lt;br /&gt;
&lt;br /&gt;
 *.tar.gz, *.tgz, *.tar.bz2, *.tar.lzma, *.zip&lt;br /&gt;
&lt;br /&gt;
==== depends &amp;amp;amp; makedepends  ====&lt;br /&gt;
&lt;br /&gt;
Depends are the actual running dependencies which a package would need when you are using it. 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 anymore. The best way to find out what depends and makedepeds are of a package 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 by doing: &lt;br /&gt;
&lt;br /&gt;
 abuild unpack&lt;br /&gt;
&lt;br /&gt;
It 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 loosing to many features. The exact disable/enable options are decided the package builder but please try to follow Alpines design concept as much as possible. &lt;br /&gt;
&lt;br /&gt;
An easy way of quickly finding out build info of a package is to check Archlinux (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/ Archlinux 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 which is not present in the $depends variable. We do this be 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;
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 into the doc subpackage. Please follow the following guideline to add a proper license. Locate the license file inside the source package. Add to $subpackages variable the following: &lt;br /&gt;
&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-doc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And add a similar line to your build() function depending on the license: &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 automaticly add the license to the package-doc apk for you. &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;
editme &lt;br /&gt;
&lt;br /&gt;
==== pkgver  ====&lt;br /&gt;
&lt;br /&gt;
A brief, one line, description of what the package does. Useful for the package management system. &amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example from apk_info&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
openssh-client-5.1_p1-r1 - Port of OpenBSD&#039;s free SSH release - client&amp;lt;br&amp;gt;&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;
editme &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 extra. If you are not sure your package works at all you need to use testing.&lt;/div&gt;</summary>
		<author><name>Amanison</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Creating_an_Alpine_package&amp;diff=3249</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=3249"/>
		<updated>2009-11-06T16:26:15Z</updated>

		<summary type="html">&lt;p&gt;Amanison: /* Installing and configuring the alpine-sdk */&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 create or modifying APKBUILD files we need to setup abuild to our system/user. Please edit the file abuild.conf to your liking. &lt;br /&gt;
&lt;br /&gt;
  vi /etc/abuild.conf&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;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The &#039;packagename&#039; is a parameter to the -n option so order of -c and -n matters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This will copy the sample initd and confd files to the build directory.&amp;lt;BR&amp;gt;&lt;br /&gt;
A third file sample.install file will be copied as well (we will discuss this later on).&lt;br /&gt;
&lt;br /&gt;
=== Modify your APKBUILD ===&lt;br /&gt;
Edit APKBUILD and fill in the needed info (especially pkgname, pkgver, pkgdesc, url, license, depends and source). &lt;br /&gt;
&lt;br /&gt;
If you are going to use any of the variables for directory&#039;s 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;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; 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.&#039;&#039;&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. When you are finished adding them you can execute the following cmd to add checksum&#039;s to the APKBUILD file: &lt;br /&gt;
&lt;br /&gt;
 abuild checksum&lt;br /&gt;
&lt;br /&gt;
Another thing to note is when a package is using sourceforge as hosting, if so you should add special mirrors link used by sf: &lt;br /&gt;
&lt;br /&gt;
 http://downloads.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.gz &lt;br /&gt;
&lt;br /&gt;
(or similar depending on the package). &lt;br /&gt;
&lt;br /&gt;
Currently abuild support the following archives/extensions: &lt;br /&gt;
&lt;br /&gt;
 *.tar.gz, *.tgz, *.tar.bz2, *.tar.lzma, *.zip&lt;br /&gt;
&lt;br /&gt;
==== depends &amp;amp;amp; makedepends  ====&lt;br /&gt;
&lt;br /&gt;
Depends are the actual running dependencies which a package would need when you are using it. 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 anymore. The best way to find out what depends and makedepeds are of a package 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 by doing: &lt;br /&gt;
&lt;br /&gt;
 abuild unpack&lt;br /&gt;
&lt;br /&gt;
It 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 loosing to many features. The exact disable/enable options are decided the package builder but please try to follow Alpines design concept as much as possible. &lt;br /&gt;
&lt;br /&gt;
An easy way of quickly finding out build info of a package is to check Archlinux (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/ Archlinux 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 which is not present in the $depends variable. We do this be 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;
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 into the doc subpackage. Please follow the following guideline to add a proper license. Locate the license file inside the source package. Add to $subpackages variable the following: &lt;br /&gt;
&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-doc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And add a similar line to your build() function depending on the license: &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 automaticly add the license to the package-doc apk for you. &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;
editme &lt;br /&gt;
&lt;br /&gt;
==== pkgver  ====&lt;br /&gt;
&lt;br /&gt;
A brief, one line, description of what the package does. Useful for the package management system. &amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example from apk_info&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
openssh-client-5.1_p1-r1 - Port of OpenBSD&#039;s free SSH release - client&amp;lt;br&amp;gt;&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;
editme &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 extra. If you are not sure your package works at all you need to use testing.&lt;/div&gt;</summary>
		<author><name>Amanison</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Creating_an_Alpine_package&amp;diff=3233</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=3233"/>
		<updated>2009-10-23T18:06:40Z</updated>

		<summary type="html">&lt;p&gt;Amanison: /* Installing and configuring the alpine-sdk */&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;
To install those packages: &lt;br /&gt;
&lt;br /&gt;
 apk add alpine-sdk&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 create or modifying APKBUILD files we need to setup abuild to our system/user. Please edit the file abuild.conf to your likings. &lt;br /&gt;
&lt;br /&gt;
  vi /etc/abuild.conf&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;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The &#039;packagename&#039; is a parameter to the -n option so order of -c and -n matters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This will copy the sample initd and confd files to the build directory.&amp;lt;BR&amp;gt;&lt;br /&gt;
A third file sample.install file will be copied as well (we will discuss this later on).&lt;br /&gt;
&lt;br /&gt;
=== Modify your APKBUILD ===&lt;br /&gt;
Edit APKBUILD and fill in the needed info (especially pkgname, pkgver, pkgdesc, url, license, depends and source). &lt;br /&gt;
&lt;br /&gt;
If you are going to use any of the variables for directory&#039;s 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;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; 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.&#039;&#039;&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. When you are finished adding them you can execute the following cmd to add checksum&#039;s to the APKBUILD file: &lt;br /&gt;
&lt;br /&gt;
 abuild checksum&lt;br /&gt;
&lt;br /&gt;
Another thing to note is when a package is using sourceforge as hosting, if so you should add special mirrors link used by sf: &lt;br /&gt;
&lt;br /&gt;
 http://downloads.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.gz &lt;br /&gt;
&lt;br /&gt;
(or similar depending on the package). &lt;br /&gt;
&lt;br /&gt;
Currently abuild support the following archives/extensions: &lt;br /&gt;
&lt;br /&gt;
 *.tar.gz, *.tgz, *.tar.bz2, *.tar.lzma, *.zip&lt;br /&gt;
&lt;br /&gt;
==== depends &amp;amp;amp; makedepends  ====&lt;br /&gt;
&lt;br /&gt;
Depends are the actual running dependencies which a package would need when you are using it. 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 anymore. The best way to find out what depends and makedepeds are of a package 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 by doing: &lt;br /&gt;
&lt;br /&gt;
 abuild unpack&lt;br /&gt;
&lt;br /&gt;
It 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 loosing to many features. The exact disable/enable options are decided the package builder but please try to follow Alpines design concept as much as possible. &lt;br /&gt;
&lt;br /&gt;
An easy way of quickly finding out build info of a package is to check Archlinux (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/ Archlinux 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 which is not present in the $depends variable. We do this be 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;
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 into the doc subpackage. Please follow the following guideline to add a proper license. Locate the license file inside the source package. Add to $subpackages variable the following: &lt;br /&gt;
&lt;br /&gt;
 subpackages=&amp;quot;$pkgname-doc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And add a similar line to your build() function depending on the license: &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 automaticly add the license to the package-doc apk for you. &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;
editme &lt;br /&gt;
&lt;br /&gt;
==== pkgver  ====&lt;br /&gt;
&lt;br /&gt;
A brief, one line, description of what the package does. Useful for the package management system. &amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example from apk_info&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
openssh-client-5.1_p1-r1 - Port of OpenBSD&#039;s free SSH release - client&amp;lt;br&amp;gt;&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;
editme &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 extra. If you are not sure your package works at all you need to use testing.&lt;/div&gt;</summary>
		<author><name>Amanison</name></author>
	</entry>
</feed>