makepkg-optimize
makepkg-optimizeAUR is a collection of supplemental tidy, buildenv, and executable scripts for pacman which provide macros for several kinds of optimization in the build()
and package()
stages.
Installation
Install makepkg-optimizeAUR and, to make optimizations available, install their backends: openmp, upx, optipng, and svgoAUR.
Configuration
makepkg-optimizeAUR generates a redundant configuration file, /etc/makepkg-optimize.conf
, from your current makepkg.conf(5) configuration.
This file lists supplementary COMPILE FLAGS, BUILD ENVIRONMENT options, GLOBAL PACKAGE OPTIONS, PACKAGE OUTPUT options, and COMPRESSION DEFAULTS, all of which are disabled by default.
Build an optimized package
After selecting your preferred optimizations, pass the configuration file when building:
$ makepkg -c --config /etc/makepkg-optimize.conf
$PROFDEST/pkgbase.gen
; the second moves them to $PROFDEST/pkgbase.used
and applies them.Build an optimized package in a clean chroot
Alternatively, makepkg-optimize
can be used to build optimized packages within a chroot.
Chroot setup
After setting up a chroot, a few additional steps are needed.
Install makepkg-optimize and backends
First, install some of the backends for the optimization macros to the base chroot:
$ arch-nspawn "$CHROOT"/root pacman -S openmp upx optipng
Then download and build makepkg-optimizeAUR and svgoAUR.
To install them in the base chroot, copy their package files into it and install them, e.g.:
# cp svgo-1.2.2-2-any.pkg.tar.xz "$CHROOT"/root/root/ $ arch-nspawn "$CHROOT"/root pacman -U /root/svgo-1.2.2-2-any.pkg.tar.xz
Create a PGO cache
To use PGO, create a folder in the same place, inside and outside of the chroot, to store profiles:
# mkdir -m 777 {"$CHROOT"/{root,"$USER"},}/mnt/pgo
Then edit $CHROOT/root/etc/makepkg-optimize.conf
and set PROFDEST=/mnt/pgo
.
Using the chroot
Build a package
First, edit $CHROOT/root/etc/makepkg-optimize.conf
and select your preferred optimizations.
When building, pass the configuration file to makepkg
:
$ makechrootpkg -c -r "$CHROOT" -- -c --config /etc/makepkg-optimize.conf
Building with PGO
After the first building phase, bind the PGO cache:
# mount -o bind {,"$CHROOT"/root}/mnt/pgo # mount -o bind "$CHROOT"/{root,"$USER"}/mnt/pgo
Install the package and test-run its executables.
exit()
. Persistent daemons, such as systemd, may require a reboot to produce profiles. If you have rebooted, be sure to rebind the PGO cache before rebuilding.After thoroughly utilizing the software, rebuild and reinstall the package.