This guide will show you by an example how to build software package for Arch Linux ARM that can be installed with pacman
. The example will install a simple "Hello World" script in one of the variable PATH
defined software directory.
pacman -Syu
and install the needed build environment with pacman -S base-devel
and acknowledge the proposed package selections.Important: Each of the following steps must be executed within a normal user account, not within the root user account.
helloworld
.PKGBUILD
.PKGBUILD
in nano
and paste following content into it:# Maintainer: Julian Sanin <sanin89julian@gmail.com>
pkgname=helloworld
pkgver=0.1
pkgrel=1
arch=('any')
license=('BSD')
install="${pkgname}.install"
source=("${pkgname}")
package() {
install -o root -g root -Dm755 "${pkgname}" "${pkgdir}/usr/local/bin/${pkgname}"
}
By convention the PKGBUILD
file needs the mandatory variables pkgname
, pkgver
, pkgrel
, and arch
. They define file name of the final package including the package name, version, release and processor architecture. The variable license
is optional but makepkg
will produce a warning if not present. The variables install
and source
are also optional but they are useful to indicate an additional install file for install messages and to add further source code files beside the default src
subdirectory.
The package build environment uses some of the variables which are useful for example pkgname
as defined by the user will be replaced with its package name or pkgdir
as a replacement for the installation parent directory.
Also required is the function package()
. It indicates where the software package files should be installed and which permissions should be applied. In our case we will install a script file called helloworld
in the directory /usr/local/bin/
and we apply to the file the owner and group root with permission 755
, short form for rwx
by root and r-x
for anybody else.
Not required but as a form of courtesy the first line of the PKGBUILD
file should contain a info about package maintainer who is responsible for the software package.
nano
and create a new empty file called helloworld.install
and paste following content:post_install() {
post_upgrade "${@}"
}
post_upgrade() {
cat << MSG
>>> Installed `helloworld`
MSG
}
post_remove() {
cat << MSG
>>> Removed `helloworld`
MSG
}
Similar like the PKGBUILD
file also the .install
file contains some predefined functions. In this case for example for the events of installing, upgrading and removing a package with pacman
. Here we put only a simple message that will be printed on install and remove of the package, but this file allows also to execute any shell command just like as in a shell script.
helloworld
and paste following content:#!/bin/bash
echo "Hello World!"
exit 0
As you can see the script is very simple and does only print a simple "Hello World" message.
updpkgsums
and makepkg
.updpkgsums
will add a MD5 check sum to the PKGBUILD
file that is required to check the integrity of the final software package. Note: If you are committing to a code reposity you have to remove in the PKGBUILD
file the last line containing the md5sums
variable since it could be that someone could potentialy update the code but then the package build would fail because the check sum is not the same anymore.makepkg
builds the software package and produces a .pkg.tar.xz
for example in our case helloworld-0.1-1-any.pkg.tar.xz
file that can be transfered to another machine and installed by pacman
.pacman -U helloworld-0.1-1-any.pkg.tar.xz
as root. The helloworld script will be installed in the filesystem and be available as a command helloworld
.pacman -R helloworld
as root.