megarpi
archlinuxarm
bobo_logo_orange

Creating Software Packages for Arch Linux Build System

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.

Preparations

Important: Each of the following steps must be executed within a normal user account, not within the root user account.

# 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.

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.

#!/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.

Creating the Package

Run it

Sources:


Free University of Bolzano - Faculty of Computer Science - 2013-2016

unibz_cs_logo