| name | aur-makepkg |
| description | Comprehensive guide for building Arch Linux packages using makepkg, covering the build process, configuration, debugging, and optimization. |
Skill: aur-makepkg
Purpose
Comprehensive guide for building Arch Linux packages using makepkg. Covers the build process, configuration, environment variables, debugging, and optimization for creating packages from PKGBUILDs.
When to Use This Skill
This skill should be used when:
- Building packages from PKGBUILDs
- Configuring makepkg behavior
- Debugging build failures
- Optimizing build process
- Creating custom package configurations
When NOT to Use This Skill
- For using pacman directly (see aur-pacman skill)
- For official package building (uses devtools)
- For non-Arch Linux systems
Overview
makepkg is a script provided by the pacman package that automates building packages. It reads a PKGBUILD and performs these steps in order:
- Verify - Check if dependencies and makedepends are met
- Download - Fetch sources and verify integrity (hashes or PGP signatures)
- Extract - Unpack sources and apply patches (prepare() function)
- Build - Compile software (build() function)
- Package - Install into fake root ($pkgdir), strip symbols, compress man pages
- Archive - Create .pkg.tar.zst file
Basic Usage
Simple Build
makepkg -s
makepkg -si
makepkg
Cleaning
makepkg -c
makepkg -C
Force Overwrite
makepkg -f
Output Control
PKGDEST=/home/packages
SRCDEST=/home/sources
makepkg --sign
Configuration Files
Configuration hierarchy (later files override earlier ones):
/etc/makepkg.conf - Global
/etc/makepkg.conf.d/*.conf - System-wide drops
~/.makepkg.conf or $XDG_CONFIG_HOME/pacman/makepkg.conf - User-specific
/etc/makepkg.conf
Global configuration for all users.
PKGDEST=/home/packages
SRCDEST=/home/sources
LOGDEST=/home/buildlogs
GPGKEY="your fingerprint"
MAKEFLAGS="-j$(nproc)"
~/.makepkg.conf
User-specific overrides.
MAKEFLAGS="-j$(nproc)"
USE_COLOR=1
Environment Variables
| Variable | Purpose |
|---|
| MAKEFLAGS | Compiler flags (e.g., -j4) |
| PKGDEST | Package output directory |
| SRCDEST | Source download directory |
| SRCPKGDEST | Source package directory |
| LOGDEST | Build log directory |
| PACKAGER | Package maintainer name (email obfuscated) |
| GPGKEY | GPG key for signing |
| BUILDENV | Build tools (ccache, distcc) |
Example Usage
MAKEFLAGS="-j4" PKGDEST="/tmp/packages" makepkg -s
PACKAGER="Your Name <you at example dot com>" makepkg
Build Process Stages
1. Package Verification
makepkg --verifysource
makepkg --nobuild
2. Dependency Resolution
makepkg -s
3. Source Extraction
makepkg --noextract
4. Building
makepkg
MAKEFLAGS="-j$(nproc)" makepkg
5. Package Creation
makepkg
makepkg --pkg
makepkg --sign
Debugging Builds
View Build Log
less ./mypackage.log
LOGDEST=/tmp/logs makepkg
Interactive Build
makepkg --log
makepkg --debug
Common Build Issues
Missing Dependencies
makepkg -s
makepkg -o 2>&1 | grep "could not satisfy"
Permission Errors
runuser -u nobody -- makepkg -s
chown -R $USER:$USER ./mypackage
Checksum Mismatch
updpkgsums PKGBUILD
makepkg -g >> PKGBUILD
Network Issues
export HTTP_PROXY=http://proxy:8080
export HTTPS_PROXY=http://proxy:8080
DLAGENTS=("ftp::/usr/bin/curl -fC - -o %o %u")
Incompatible Flags
If build succeeds manually but fails via makepkg, incompatible makepkg.conf settings may be the cause. Disable defaults in PKGBUILD:
options=('!makeflags' '!buildflags' '!debug')
Package Signing
Generate GPG Key
gpg --full-gen-key
Sign Package
makepkg --sign
gpg --detach-sign package.pkg.tar.zst
gpg --armor --detach-sign --yes
Verify Package
gpg --verify package.pkg.tar.zst.sig
pacman -U package.pkg.tar.zst
Optimization
Parallel Compilation
MAKEFLAGS="-j$(nproc)"
MAKEFLAGS="-j$(nproc)" makepkg
Build Environment
Mold Linker (Optional)
For faster builds, use the mold linker:
pacman -S mold
LDFLAGS="-fuse-ld=mold"
CCACHE
pacman -S ccache
BUILDENV=(!distcc color ccache !check)
DistCC
pacman -S distcc
BUILDENV=(distcc !color !ccache !check)
DISTCC_HOSTS="localhost host1 host2"
Source Management
Unique Filenames (:: Syntax)
When a source URL doesn't include a useful filename, use :: to specify one:
source=("https://example.com/download.php?file=12345::https://example.com/file.tar.gz")
This renames the downloaded file to 12345 instead of the query-string filename.
Generating .SRCINFO
For AUR submission, generate .SRCINFO:
makepkg --printsrcinfo > .SRCINFO
Mandatory for AUR: Regenerate .SRCINFO whenever metadata changes (pkgver, depends, etc.). The AUR web interface uses this file - if missing or outdated, the correct version won't display.
Custom Download Agents
DLAGENTS=('http::/usr/bin/curl -LC - -b cookies.txt -c cookies.txt -o %o %u'
'https::/usr/bin/wget --passive-ftp -O %o %u'
'git::git clone %u %o')
Offline Build
makepkg --verifysource
makepkg
PKGBUILD Testing
Dry Run
makepkg --nobuild
makepkg --noprepare
Debug Functions
bash -x PKGBUILD
Package Output
Formats
makepkg
makepkg --source
makepkg --allsource
makepkg --pkg
Package Naming
The package name and version are defined in the PKGBUILD via pkgname and pkgver variables - they cannot be overridden via command-line flags.
Common Commands Summary
| Command | Purpose |
|---|
makepkg -s | Syncdeps: Install missing dependencies |
makepkg -i | Install: Build and install with pacman |
makepkg -c | Clean: Remove work files after build |
makepkg -C | Cleanbuild: Remove $srcdir before build |
makepkg -f | Force: Overwrite existing package |
makepkg -g | Geninteg: Generate integrity checksums |
updpkgsums | Preferred tool to update checksums |
makepkg --allsource | Create source package with all sources |
makepkg --printsrcinfo | Generate .SRCINFO for AUR |
makepkg --sign | Sign the package |
makepkg --verifysource | Verify: Download and check integrity |
makepkg --skippgpcheck | Skip PGP signature verification |
Best Practices
- Never build as root - Use a normal user (PKGBUILDs can contain arbitrary commands)
- Always verify sources - Check checksums with
updpkgsums
- Keep build logs - Use
makepkg --log for debugging
- Use ABS - Get official PKGBUILDs with
abs
- Test in clean environment - Use
archbuild or containers
- Sign packages - For secure distribution
- Configure output dirs - Keep organized
- Use SPDX license identifiers - E.g.,
GPL-3.0-or-later, not GPL3
- Quote variables - Use
"$pkgdir" and "$srcdir" to handle spaces
- License AUR submissions - Recommend 0BSD license for repo files
- Use namcap - Audit PKGBUILDs and packages for common errors
- Never use $pkgdir/$srcdir in .install - Scripts run chrooted on target system, not build environment
Auditing Tools
pacman -S namcap
namcap PKGBUILD
namcap package.pkg.tar.zst
shellcheck --shell=bash --exclude=SC2034,SC2154,SC2164 PKGBUILD
Install Scripts
.install scripts run chrooted in the target system's installation directory. They do NOT have access to build-time variables like $pkgdir or $srcdir. Only use actual system paths:
post_install() {
rm -rf "$pkgdir"/usr/share/cache
}
post_install() {
rm -rf /usr/share/cache
}
Related Skills
- aur-guides - Main dispatcher
- aur-pkgbuild - PKGBUILD creation
- aur-audit - Validation
- aur-submission - AUR submission
- aur-package-guidelines - Standards