From ArchWiki
Revision as of 23:39, 17 February 2011 by KerrickStaley (talk | contribs) (Usage: Added --asdeps flag to code line. Use --asdeps so that the dependencies can be tracked and removed when no longer needed.)
Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary heading Template:Article summary link Template:Article summary link Template:Article summary end

makepkg is used for compiling and building packages suitable for installation with pacman, Arch Linux's package manager. makepkg is a script that automates the building of packages; it can download and validate source files, check dependencies, configure build-time settings, compile the sources, install into a temporary root, make customizations, generate meta-info, and package everything together.

makepkg is provided by the Template:Package Official package.


Template:Filename is the main configuration file for makepkg. Most users will wish to fine-tune makepkg configuration options prior to building any packages.

Architecture, compile flags

The MAKEFLAGS, CFLAGS and CXXFLAGS options are used by make, gcc, and g++ whilst compiling software with makepkg. By default, these options generate generic packages that can be installed on a wide range of machines. A performance improvement can be achieved by tuning compilation for the host machine. The downside is that packages compiled specifically for the host's processor may not run on others.


The default makepkg.conf CFLAGS and CXXFLAGS are compatible with all machines within their respective architectures. Further optimizing for CPU type can theoretically enhance performance for packages built with such optimizations, though such gains are most likely not human-perceivable.

As of version 4.3.0, the gcc compiler offers the Template:Codeline switch that enables CPU auto-detection and automatically selects optimizations supported by the local machine at gcc runtime. To use it, just modify the default settings by changing the CFLAGS and CXXFLAGS lines as follows:

CFLAGS="-march=native -O2 -pipe"

To see exactly what the march=native switch is providing, execute the following command:

gcc -c -Q -march=native --help=target

See the gcc man page for a complete list of available options. The Gentoo Compilation Optimization Guide and Safe Cflags wiki article provide more in-depth information.

The MAKEFLAGS option can be used to specify additional options for make. Users with multi-core/multi-processor systems can specify the number of jobs to run simultaneously. Generally Template:Codeline, plus 1 for each additional core/processor is an adequate choice. Optimizing for multiple cores can sometimes increase compiling performance, shortening compile times. However, be warned that occasionally using anything but the default can cause compilation problems, though many have agreed that Template:Codeline is fairly safe to use for the majority of packages.


See the make man page for a complete list of available options.

Note: Do keep in mind that not all package Makefiles will use your exported variables. Some of them override them in the original Makefiles or the PKGBUILD.

Package output

Next, one can configure where source files and packages should be placed and identify themselves as the packager. This step is optional; packages will be created in the working directory where makepkg is run by default.


For example, create the directory:

$ mkdir /home/$USER/packages

Then modify the PKGDEST variable in Template:Filename accordingly.

The PACKAGER variable will set the packager value within compiled packages' Template:Filename metadata file. By default, user-compiled packages will display:




This is useful if multiple users will be compiling packages on a system, or you are otherwise distributing your packages to other users.

Unprivileged access

To be able to install dependencies with makepkg as an unprivileged user (with Template:Codeline, see below) install sudo and add desired users to Template:Filename:

USER_NAME ALL=(ALL) NOPASSWD: /usr/bin/pacman

The above will negate the need to enter a password when with pacman. See the sudo wiki article for detailed information.


Before continuing, ensure the "base-devel" group is installed. Packages belonging to this group are not required to be listed as dependencies in PKGBUILD files. Install the "base-devel" group by issuing (as root):

# pacman -S base-devel
Note: Before complaining about missing (make)dependencies, remember that the "base" group is assumed to be installed on all Arch Linux systems. The group "base-devel" is assumed to be installed when building with makepkg.

To build a package, one must first create a PKGBUILD, or build script, as described in Creating Packages, or obtain one from the ABS tree, Arch User Repository, or some other source.

Warning: Only build/install packages from trusted sources.

Once in possession of a Template:Filename, change to the directory where it is saved and issue the following command to build the package described by said Template:Filename:

$ makepkg

To have makepkg clean out leftover files and folders, such as files extracted to the $srcdir, add the following option. This is useful for multiple builds of the same package or updating the package version, while using the same build folder. It prevents obsolete and remnant files from carrying over to the new builds.

$ makepkg -c

If required dependencies are missing, makepkg will issue a warning before failing. To build the package and install needed dependencies automatically, simply use the command:

$ makepkg -s

Note that these dependencies must be available in the configured repositories; see pacman#Repositories for details. Alternatively, one can manually install dependencies prior to building (Template:Codeline).

Once all dependencies are satisfied and the package builds successfully, a package file (Template:Filename) will be created in the working directory. To install, run (as root):

# pacman -U pkgname-pkgver.pkg.tar.xz

Tips and Tricks

WARNING:Referencing $srcdir in PKGBUILD

Somehow, $srcdir of $pkgdir ended up in one of the installed files in your package.

To identify which files, run the following from the makepkg build dir:

grep -R "$(pwd)/src" pkg/

[Link] to discussion thread.