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.

Configuration

/etc/makepkg.conf 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 compiling host's processor may not run on other machines.

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

The default makepkg.conf CFLAGS and CXXFLAGS are compatible with all machines within their respective architectures.

On x86_64 machines, there are rarely significant enough real world performance gains that would warrant investing the time to rebuild official packages.

As of version 4.3.0, GCC offers the -march=native 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:

Further optimizing for CPU type can theoretically enhance performance because -march=native enables all available instruction sets and improves scheduling for a particular CPU. This is especially noticeable when rebuilding applications (for example: audio/video encoding tools, scientific applications, math-heavy programs, etc.) that can take heavy advantage of newer instructions sets not enabled when using the default options (or packages) provided by Arch Linux.

It is very easy to reduce performance by using "non-standard" CFLAGS because compilers tend to heavily blow up the code size with loop unrolling, bad vectorization, crazy inlining, etc. depending on compiler switches. Unless you can verify/benchmark that something is faster, there is a very good chance it is not!

MAKEFLAGS

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. This can be accomplished with the use of nproc to determine the number of available processors, e.g. -j 4(where 4 is the output of nproc). Some PKGBUILD's specifically override this with -j1, because of race conditions in certain versions or simply because it is not supported in the first place. Packages that fail to build because of this should be reported on the bug tracker after making sure that the error is indeed being caused by your MAKEFLAGS.

See man make for a complete list of available options.

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.

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

pacman -Qi package

...
Packager : Unknown Packager
...

Afterwards:

pacman -Qi package

...
Packager : John Doe <john@doe.com>
...

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

Signature checking

The following procedure is not necessary for compiling with makepkg, for your initial configuration proceed to #Usage. To temporarily disable signature checking call the makepkg command with the --skippgpcheck option.
If a signature file in the form of .sig is part of the PKGBUILD source array, makepkg validates the authenticity of source files. For example, the signature pkgname-pkgver.tar.gz.sig is used to check the integrity of the file pkgname-pkgver.tar.gz with the gpg program. If desired, signatures by other developers can be manually added to the gpg keyring. Look into the GnuPG article for further information.

Note: The signature checking implemented in makepkg does not use pacman's keyring. Configure gpg as explained below to allow makepkg reading pacman's keyring.

The gpg keys are expected to be stored in the user's ~/.gnupg/pubring.gpg file. In case it does not contain the given signature, makepkg shows a warning.

If the pubring.gpg file does not exist it will be created for you immediatly.
You can now proceed with configuring gpg to allow compiling AUR packages submitted by Arch Linux developers with successful signature checking.
Add the following line to the end of your gpg configuration file to include the pacman keyring in your user's personal keyring.

~/.gnupg/gpg.conf

...
keyring /etc/pacman.d/gnupg/pubring.gpg

When configured as before, the output of gpg --list-keys contains a list of keyrings and developers. Now makepkg can compile AUR packages submitted by Arch Linux developers with successful signature checking.

Usage

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.

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

$ 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 (pacman -S --asdeps dep1 dep2).

Once all dependencies are satisfied and the package builds successfully, a package file (pkgname-pkgver.pkg.tar.xz) will be created in the working directory. To install, run (as root):

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

Alternatively, to install, using the -i flag is an easier way of running pacman -U pkgname-pkgver.pkg.tar.xz, as in:

$ makepkg -i

Tips and Tricks

Replace checksums in PKGBUILD automatically

Option 1

Here is a very handy script that will generate new checksums for updated files and replace them inside the PKGBUILD in one step.

Option 2

This works fine, but has the disadvantage that it requires the setconf package and does not work with multiple checksums (both md5sums and sha256sums in the same PKGBUILD, for example).

The speed is as good or better than scripts that use awk, even though makepkg is called twice.

Option 3

makepkg -g >> PKGBUILD

This technique is great to use while creating new PKGBUILDs. It adds the checksums to the end of the file and since they are the final invocation, makepkg will use them instead of checksums listed higher is the script. Just remember to clean out the old checksums before publishing the PKGBUILD to keep things clean.

WARNING: Package contains reference to $srcdir

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

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