LinuxCommandLibrary

makepkg

Build packages from PKGBUILD files

TLDR

Make a package

$ makepkg
copy

Make a package and install its dependencies
$ makepkg [[-s|--syncdeps]]
copy

Make a package, install its dependencies then install it to the system
$ makepkg [[-si|--syncdeps --install]]
copy

Make a package, but skip checking the source's hashes
$ makepkg --skipchecksums
copy

Clean up work directories after a successful build
$ makepkg [[-c|--clean]]
copy

Verify the hashes of the sources
$ makepkg --verifysource
copy

Generate and save the source information into .SRCINFO
$ makepkg --printsrcinfo > .SRCINFO
copy

Download the source and install only the build dependencies for a program
$ makepkg [[-so|--syncdeps --nobuild]]
copy

SYNOPSIS

makepkg [options]
makepkg is typically run in a directory containing a PKGBUILD file.

PARAMETERS

-s, --syncdeps
    Syncs and installs any build-time dependencies using pacman before building.

-r, --rmdeps
    Removes installed build-time dependencies after the package is successfully built.

-f, --force
    Forces a rebuild of the package, even if a previous package file already exists.

-i, --install
    Installs the built package(s) using pacman after a successful build.

-c, --clean
    Cleans up the working directory by removing the src/ and pkg/ directories and the generated package file.

-C, --cleanbuild
    Performs a clean build by first cleaning the working directory and then building the package.

-d, --nodeps
    Skips all dependency checks, potentially leading to build failures if dependencies are missing.

-e, --noextract
    Skips the extraction of source files if they are already present in the src/ directory.

-g, --geninteg
    Generates and prints the integrity checksums (e.g., md5sums, sha256sums) for the source files, without building the package.

-o, --nobuild
    Downloads and extracts the source files but does not proceed with the build or package creation.

-p, --printsrcinfo
    Prints the .SRCINFO metadata for the PKGBUILD to standard output.

-S, --skipinteg
    Skips all integrity checks for source files (e.g., md5sums, sha256sums).

-u, --nocheck
    Skips the execution of the check() function defined in the PKGBUILD.

-W, --noprepare
    Skips the execution of the prepare() function defined in the PKGBUILD.

-T, --nosign
    Does not sign the built package even if signing is configured in makepkg.conf.

--config <file>
    Uses an alternate configuration file instead of the default /etc/makepkg.conf.

--noconfirm
    Assumes "yes" to all prompts, useful for scripting.

--chroot
    Builds the package in a clean chroot environment, enhancing reproducibility and security. Requires additional setup (e.g., extra-x86_64-build).

--ignore <packages>
    A comma-separated list of dependencies to ignore during the dependency check.

DESCRIPTION

makepkg is a command-line tool central to Arch Linux's package management, designed to automate the process of building software packages from source code. It reads instructions from a PKGBUILD file, which is a shell script containing metadata and build directives for a specific package. makepkg handles the entire build workflow: it downloads necessary source files, verifies their integrity using checksums (MD5, SHA1, SHA256, etc.) and optionally PGP signatures, extracts them, applies any required patches, compiles the software, installs it into a temporary environment, and finally packages it into a compressed pacman-compatible archive (typically .pkg.tar.zst).

This utility ensures that packages are built consistently and adhere to Arch Linux packaging standards. It integrates with pacman for dependency resolution, automatically checking for and prompting to install build dependencies before compilation. makepkg empowers users to build packages from the Arch User Repository (AUR) or their own custom sources, making Arch a highly customizable and "do-it-yourself" distribution. Its simplicity and effectiveness contribute significantly to Arch's rolling-release model and user control over their system.

CAVEATS

makepkg requires a PKGBUILD file to be present in the current working directory to function correctly. It is designed specifically for Arch Linux and its derivatives and is not portable to other distributions. For security, always review PKGBUILDs before execution, especially those from untrusted sources, as they are shell scripts and can execute arbitrary commands with user permissions. Using --chroot is highly recommended for building untrusted packages to isolate the build process from your main system, but it requires initial setup and configuration.

<B>PKGBUILD</B> FILE STRUCTURE

The PKGBUILD file is a Bash script containing variables (e.g., pkgname, pkgver, arch, depends, source) and functions (e.g., prepare(), build(), check(), package()). makepkg executes these functions sequentially to perform the build steps.

WORKING DIRECTORIES

During the build process, makepkg creates temporary directories within the working directory: src/ for extracted source files and pkg/ where the software is installed before being packaged. These can be cleaned up with the -c or -C options.

MAKEPKG.CONF

The main configuration file for makepkg is /etc/makepkg.conf. It allows users to customize various aspects of the build process, such as compiler flags (CFLAGS, CXXFLAGS), compression algorithms for packages, GPG key settings for package signing, and build environments (e.g., fakeroot settings).

HISTORY

makepkg has been an integral part of the Arch Linux ecosystem since its early days, embodying the distribution's philosophy of user control and simplicity. Developed primarily in Bash, its evolution has closely mirrored that of pacman and the PKGBUILD format. It provides a standardized way for users to build packages, contributing significantly to the success of the Arch User Repository (AUR), which relies on users sharing PKGBUILDs. Over time, features like integrity checks, PGP signing, chroot builds, and various build-time optimizations have been added, enhancing security, reproducibility, and flexibility, while maintaining its core purpose as a simple, yet powerful, package builder.

SEE ALSO

PKGBUILD(5), pacman(8), namcap(1), repo-add(8)

Copied to clipboard