Mastering the `makepkg` Command (with examples)
- Linux
- December 17, 2024
The makepkg
command is an essential tool in the Arch Linux ecosystem, fundamental for package builders and maintainers. It facilitates the creation of packages intended to be installed via the pacman
package manager. The command reads a PKGBUILD
file, which contains all the necessary information about how a package should be constructed, including source files, dependencies, build instructions, and metadata. The following sections illustrate specific use cases of the makepkg
command, each with its unique arguments and functionalities.
Use case 1: Make a package
Code:
makepkg
Motivation:
In an environment where you need to compile software from source on an Arch-based system, makepkg
becomes exceedingly useful. By running this command, a package can be created directly from source utilizing the instructions provided in the PKGBUILD
file. It’s a basic yet powerful utility when you intend to create an Arch package repository, contribute to the AUR (Arch User Repository), or compile custom applications not yet available in the repository.
Explanation:
The command makepkg
without any additional options will use the default PKGBUILD
file in the present working directory to compile the software, bundle it into a compressed package, and prepare it for installation via pacman
.
Example output:
==> Making package: your-package 1.0-1 (Thu Dec 9 10:20:31 2023)
==> Checking runtime dependencies...
==> Checking build-time dependencies...
==> Retrieving sources...
==> Extracting sources...
==> Removing existing $pkgdir/ directory...
==> Entering fakeroot environment...
==> Starting build()...
==> Tidying install...
==> Creating package "your-package"...
==> Leaving fakeroot environment...
==> Finished making: your-package 1.0-1 (Thu Dec 9 10:21:42 2023)
Use case 2: Make a package and install its dependencies
Code:
makepkg --syncdeps
Motivation:
Building software often requires specific libraries or tools that are not present in a clean system environment. By using the --syncdeps
option, makepkg
will automatically synchronize and install all necessary dependencies using pacman
, ensuring a smooth building process. This feature is essential for minimizing manual efforts and avoiding errors caused by missing dependencies.
Explanation:
The --syncdeps
argument instructs makepkg
to resolve and install all dependencies defined in the PKGBUILD
file directly, leveraging pacman
. This ensures that all requirements are met prior to initiating the build process.
Example output:
==> Making package: your-package 1.0-1 (Thu Dec 9 10:22:31 2023)
==> Checking runtime dependencies...
==> Installing missing dependencies...
resolving dependencies...
looking for conflicting packages...
Packages (2) dep1-2.4.6-1 dep2-4.6.0-2
:: Proceed with installation? [Y/n]
...
==> Retrieving sources...
==> Extracting sources...
...
Use case 3: Make a package, install its dependencies, then install it to the system
Code:
makepkg --syncdeps --install
Motivation: After successfully creating a package and installing its dependencies, it is often desirable to immediately install the built package on your system. This command simplifies the entire process into a single step, useful for testing or using the application right after the build.
Explanation:
--syncdeps
will install all necessary dependencies as previously detailed, while the --install
flag tells makepkg
to install the finished package onto the system via pacman
. This automatic installation is time-saving and convenient for those who intend to use the software immediately.
Example output:
==> Making package: your-package 1.0-1 (Thu Dec 9 10:25:31 2023)
==> Checking runtime dependencies...
==> Installing missing dependencies...
...
==> Finished making: your-package 1.0-1 (Thu Dec 9 10:26:20 2023)
==> Installing package...
loading packages...
...
Use case 4: Make a package, but skip checking the source’s hashes
Code:
makepkg --skipchecksums
Motivation:
In certain situations, you may be unable to update source hash sums in the PKGBUILD
file, such as when testing changes. This option allows you to bypass checksum verification, useful in a controlled environment where source integrity has been manually verified.
Explanation:
The --skipchecksums
flag allows the makepkg
process to proceed without verifying the source file checksums stated in the PKGBUILD
, which are usually required to ensure file integrity. Avoid using this option in production systems without manual verification of source files, as it poses a security risk.
Example output:
==> Making package: your-package 1.0-1 (Thu Dec 9 10:30:31 2023)
==> WARNING: Skipping source checksums.
...
==> Creating package "your-package"...
...
Use case 5: Clean up work directories after a successful build
Code:
makepkg --clean
Motivation:
After the package is successfully built, residual temporary files and directories used during the build process remain. These can consume valuable disk space, especially when building highly complex applications. With the --clean
option, you ensure a neat environment, leaving only essential files post-build.
Explanation:
Using --clean
tells makepkg
to remove the src
and pkg
directories, which contain intermediate files and directories from the build process. This action streamlines the local directory structure post-compilation, keeping it organized.
Example output:
==> Finished making: your-package 1.0-1 (Thu Dec 9 10:31:31 2023)
==> Cleaning up...
-> Removing src directory...
-> Removing pkg directory...
Use case 6: Verify the hashes of the sources
Code:
makepkg --verifysource
Motivation: Verifying source hashes is crucial for security and integrity, ensuring that the files have not been tampered with or corrupted. This step helps maintain the integrity of your build process, serving as a preventative measure against corrupted or malicious code.
Explanation:
By invoking --verifysource
, makepkg
reads the hashes listed in the PKGBUILD
file and compares them to the current source files. If discrepancies are found, it implies potential issues with file integrity.
Example output:
==> Verifying source file signatures with sha256sums...
source1 ... Passed
source2 ... Passed
...
Use case 7: Generate and save the source information into .SRCINFO
Code:
makepkg --printsrcinfo > .SRCINFO
Motivation:
The .SRCINFO
file is crucial when managing packages for the Arch User Repository (AUR), as it provides metadata about a package, excluding build-specific instructions. It’s a helpful way to document external dependencies and other package metadata that makepkg
might not parse during a standard build.
Explanation:
The --printsrcinfo
option generates a summary of the information present in the PKGBUILD
file and formats it appropriately for storage within .SRCINFO
. Redirecting this to a file with >
saves the output conveniently for further usage or distribution.
Example output:
Content of .SRCINFO
:
pkgbase = your-package
pkgdesc = A brief description of your package
depends = dep1
depends = dep2
source = http://example.com/source1
sha256sums = SKIP
...
Conclusion
The makepkg
command is a powerful utility for anyone interested in packaging software under the Arch Linux ecosystem. Its flexibility and the various options available make it suitable for both simple and sophisticated build environments. Understanding its various use cases ensures you can efficiently and effectively manage software builds, installations, and package management in a streamlined and intuitive manner. Whether you are dealing with personal projects or contributing to community repositories like the AUR, makepkg
offers the tools needed to facilitate the process.