Building Single Packages
Building Packages is quite easy thanks to Archlinux Build System. Essentially, we use a build script, PKGBUILD, to grab the source and compile. Generally these PKGBUILDs are simple to create and simple to update. More information can be found in the Arch Wiki
- 1 General Building Notes
- 2 Building in Qemu on an x86_64 machine
- 3 Using Distcc
- 4 Building Directly on Device
- 5 Building in a Clean-Chroot
- 6 Building the Kernels
General Building Notes
The following applies to most building methods. Follow these instructions to set up the typical build environmental then modify it to your specific build strategy.
Most general dependencies can be satisfied with the
# pacman -S base-devel
If other dependencies are needed during the build process, makepkg can install them. To prevent an an abundance of dependencies being installed on a system, see Building in a Chroot
Obtaining the PKBUILDs
All of Manjaro-Arm packages are in the form of a
PKBGUILD hosted on the Manjaro-Arm github. To clone a repo,
git must be installed.
# pacman -S github
Once installed, you can clone the repo with
$ git clone https://github.com/manjaro-arm/packages-core.git
It should create a directory named packages-core which contains all the PKGBUILDs used for Manjaro-Arm.
PKGBUILDs from other sources like the AUR can also be used in the same method described below.
The configuration file for makepkg, is located at
/etc/makepkg.conf. Most of this file is fine by default however, there are a few things you may want to change if building a single package.
# Default: put built package and cached source in build directory # #-- Destination: specify a fixed directory where all packages will be placed #PKGDEST=/home/packages #-- Source cache: specify a fixed directory where source files will be cached #SRCDEST=/home/sources #-- Source packages: specify a fixed directory where all src packages will be placed #SRCPKGDEST=/home/srcpackages #-- Log files: specify a fixed directory where all log files will be placed #LOGDEST=/home/makepkglogs #-- Packager: name/email of the person or organization building packages #PACKAGER="John Doe <firstname.lastname@example.org>" #-- Specify a key to use for package signing #GPGKEY=""
These values are simple and pretty self explanatory.
If building a large package that may take up more than space than is available at
/tmp you may want to relocate the build to a specific directory inside of the /home folder. This is useful for kernel building
#-- Specify a directory for package building. #BUILDDIR=/tmp/makepkg
To invoke the build, you only need to run
makepkg in the same directory as the
$ makepkg -sc
will build the package and resolve its build dependencies. Add
-i to install it after building
$ makepkg -sci
The resulting package will be
<pkgname>.pkg.tar.xz. Included in the <pkgname> is the architecture for which it was created. For example:
linux-raspberrypi-armv7h.pkg.tar.xz //Kernel for raspberrypi on armv7h (raspberry pi 2/3
You can install this package manually by using
# pacman -U linux-raspberrypi-armv7h.pkg.tar.xz
Building in Qemu on an x86_64 machine
Qemu is a program that allows you to virtual machines. Similar to VirtualBox or VMWare. It has a vast majority of features and uses, however, for Manjaro-Arm it is quite simple. We use a static binary that ships with qemu that allows us to run commands on an armv7h rootfs. If you need to build the rootfs Building the rootfs. By placing this binary into the rootfs, we can use chroot, systemd-nspawn, or any other similar tools to run commands on our arm rootfs while on our x86_64 machine. With this, most things are possible. Packages can be built, the system can be configured and final editing can be done prior to release.
Install Necessary Tools
First you must install
qemu and some helper packages
# pacman -S qemu $ yaourt -S binfmt-support $ yaourt -S qemu-user-static
Once these three are installed, copy the static binary into the rootfs at
# cp /usr/bin/qemu-arm-static rootfs/usr/bin //replace qemu-arm-static with qemu-aarch64-static for aarch64 rootfs
Enable binfmts for qemu-arm
# sudo update-binfmts --enable qemu-arm
It is easiest to chroot into the rootfs using arch-chroot. You can do it manually, just be sure to mount all directories properly.
# arch-chroot rootfs /bin/bash
If successful, you should be dropped to a shell for the rootfs. At this point, follow all necessary build procedures as if you were on the device.
Distcc is a tool that allows you to share a load (compile jobs in this case) with one or more machines. For Manjaro-Arm, it is generally used for the kernel builds as they can take several hours on the device and just as long using Qemu. Distcc consists of a daemon
distccd running on a
client and a
master which sends the information to the daemon. In our case, the ARM device is the
master and the x86_64 computer is the
client. The packages build on the
master and are packaged on the
client just runs a few jobs for the master. To be able to compile code that is for ARM on x86_64, you must have a crosscompiling toolchain. This is a group of tools that make it possible to compile for a different architecture. The toolchain usually has tools that you would find on any Linux Machine (gcc, etc...) but are optimized for the target architecture.
Currently, there is no official Manjaro-Arm toolchain. Several have been made but none released. For now, it may be best to use a premade one from ArchlinuxArm. Below are some instructions on how to get the toolchain and configure distccd across devices.
Building Directly on Device
If a package fails to build through qemu or you would rather build on the device itself, follow the general procedure above. Take note to change the
makepkg.conf to specify build arguments such as location and packager.
Building in a Clean-Chroot
Building in a chroot is the optimal way to build packages. It serves several purposes, the most important of which is to build on a clean system each time. It can also save your running/configured system from being bloated with dependencies that you might not need after building. The easiest way to do this is to use the devtools package from ArchLinux (devtools-alarm for ARM).
Creating the CHROOT
The first step is to make the chroot directory.
$ mkdir ~/chroot
Optionally, you can set the CHROOT variable so that you can just type $CHROOT instead of a full path each time
Now create the chroot
# mkarchroot $CHROOT/root base-devel
You can also use custom pacman.conf and makepkg.conf files
# mkarchroot -C <pacman.conf> -M <makepkg.conf> $CHROOT/root base-devel
Before each build session, update the chroot with
# arch-nspawn $CHROOT/root pacman -Syu
Then, to build a package in the chroot. You must be in the directory that contains the PKGBUILD
$ makechrootpkg -c -r $CHROOT // the -c flag cleans the chroot before building
For more information about how this works and more options, check the Arch Wiki
Building the Kernels
Building the Manjaro-Arm Kernels is much like the general instructions above. It is however, necessary to ensure that there is enough space to extract the source and build.
On the device
If building on the device, the default build directory
/tmp is usually not enough to complete the build so it is necessary that you change the entry in
/etc/makepkg.conf to a location in which there is enough space. For this example, changing it to the user's
$HOME will work fine. Uncomment and change the line appropriately
#-- Specify a directory for package building. #BUILDDIR=/home/manjaro/builds
We generally do not recommend building the release kernels using qemu but if it could work. Depending on the specs of the x86_64 machine being used, it may be necessary to make the above changes to ensure that your /tmp does not run out of space. If you receive multiple errors, it may be wise to build on the device.