Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary end
This article aims to assist users creating their own packages using the Arch Linux "ports-like" build system. It covers creation of a PKGBUILD – a package build description file sourced by Template:Codeline to create a binary package from source. If already in possession of a Template:Filename, see makepkg.
- 1 Overview
- 2 Preparation
- 3 Creating a PKGBUILD
- 4 Testing the PKGBUILD and package
- 5 Submitting packages to the AUR
- 6 Summary
Packages in Arch Linux are built using the makepkg utility and the information stored in a PKGBUILD file. When Template:Codeline is run, it searches for a Template:Filename in the current directory and follows the instructions therein to either compile or otherwise acquire the required files to be packaged within a package file (Template:Filename). The resulting package contains binary files and installation instructions; readily installed with pacman.
An Arch package is no more than a gzipped tar archive, or 'tarball', which contains:
- The binary files to install
- Template:Filename: contains all the metadata needed by pacman to deal with packages, dependencies, etc.
- Template:Filename: an optional file used to execute commands after the install/upgrade/remove stage. (This file is present only if specified in the Template:Filename.)
- Template:Filename: an optional file kept by the package maintainer documenting the changes of the package. (It is not present in all packages.)
First ensure that the necessary tools are installed. The package group "base-devel" should be sufficient; it includes make and additional tools needed for compiling from source.
# pacman -S base-devel
- Checks if package dependencies are installed.
- Downloads the source file(s) from the specified server(s).
- Unpacks the source file(s).
- Compiles the software and installs it under a fakeroot environment.
- Strips symbols from binaries and libraries.
- Generates the package meta file which is included with each package.
- Compress the fakeroot environment into a package file.
- Stores the package file in the configured destination directory, which is the present working directory by default.
Download and test the installation
Download the source tarball of the software you want to package, extract it, and follow the author's steps to install the program. Make a note of all commands and/or steps needed to compile and install it. You will be repeating those same commands in the PKGBUILD file.
Most software authors stick to the 3-step build cycle:
./configure make make install
This is a good time to make sure the program is working correctly.
Creating a PKGBUILD
When you run Template:Codeline, it will look for a Template:Filename file in the present working directory. If a Template:Filename file is found it will download the software's source code and compile it according to the instructions specified in the Template:Filename file. The instructions must be fully interpretable by the Bash shell. After successful completion, the resulting binaries and metadata of the package, i.e. package version and dependencies, are packed in a Template:Filename package file that can be installed with Template:Codeline.
To begin with a new package, you should first create an empty working directory, (preferably Template:Filename), change into that directory, and create a Template:Filename file. You can either copy the prototype PKGBUILD Template:Filename to your working directory or copy a Template:Filename from a similar package. The latter may be useful if you only need to change a few options.
Defining PKGBUILD variables
The Template:Codeline function
Now you need to implement the Template:Codeline function in the Template:Filename file. This function uses common shell commands in Bash syntax to automatically compile software and create a Template:Filename directory to install the software to. This allows makepkg to package files without having sift through your filesystem.
The first step in the Template:Codeline function is to change into the directory created by uncompressing the source tarball. In most common cases the first command will look like this:
Now, you need to list the same commands you used when you manually compiled the software. The Template:Codeline function in essence automates everything you did by hand and compiles the software in the fakeroot build environment. If the software you are packaging uses a configure script, it is good practice to use Template:Codeline when building packages for pacman. A lot of software installs files relative to the Template:Filename directory, which should only be done if you are manually building from source. All Arch Linux packages should use the Template:Filename directory. As seen in the Template:Filename file, the next two lines often look like this:
./configure --prefix=/usr make || return 1
The final step in the Template:Codeline function is to put the compiled files in a directory where makepkg can retrieve them to create a package. This by default is the Template:Filename directory - a simple fakeroot environment. The Template:Filename directory replicates the hierarchy of the root file system of the software's installation paths. If you have to manually place files under the root of your filesystem, you should install them in the Template:Filename directory under the same directory structure. For example, if you want to install a file to Template:Filename, it should instead be placed under Template:Filename. Very few install procedures require the user to copy dozens of files manually. Instead, for most software, calling Template:Codeline will do so. The final line should look like the following in order to correctly install the software in the Template:Filename directory:
make DESTDIR=$pkgdir install || return 1
In some odd cases, the software expects to be run from a single directory. In such cases, it is wise to simply copy these to Template:Filename.
More often than not, the installation process of the software will create any subdirectories below the Template:Filename directory. If it does not, however, makepkg will generate a lot of errors and you will need to manually create subdirectories by adding the appropriate Template:Codeline commands in the Template:Codeline function before the installation procedure is run.
Also, makepkg defines three variables that you should use as part of the build and install process:
- This contains the absolute path to the directory where the Template:Filename file is located. This variable used to be used in combination with Template:Filename or Template:Filename postfixes, but the use of Template:Codeline and Template:Codeline variables is the modern method. Template:Codeline is not guaranteed to be the same as Template:Codeline, and likewise for Template:Codeline. Use of this variable is deprecated and strongly discouraged.
- This points to the directory where makepkg extracts or copies all source files.
- This points to the directory where makepkg bundles the installed package, which becomes the root directory of your built package.
Please read Arch Packaging Standards thoroughly for best practices and additional considerations.
Testing the PKGBUILD and package
As you are writing the Template:Codeline function, you will want to test your changes frequently to ensure there are no bugs. You can do this using the Template:Codeline command in the directory containing the Template:Filename file. With a properly formatted Template:Filename, makepkg will create a package; with a broken or unfinished Template:Filename, it will raise an error.
If makepkg finishes successfully, it will place a file named Template:Filename in your working directory. This package can be installed with the Template:Codeline command. However, just because a package file was built does not imply that it is fully functional. It might conceivably contain only the directory and no files whatsoever if, for example, a prefix was specified improperly. You can use pacman's query functions to display a list of files contained in the package and the dependencies it requires with Template:Codeline and Template:Codeline respectively.
If the package looks sane, then you are done! However, if you plan on releasing the Template:Filename file, it is imperative that you check and double-check the contents of the Template:Codeline array.
Also ensure that the package binaries actually run flawlessly! It is annoying to release a package that contains all necessary files, but crashes because of some obscure configuration option that doesn't quite work well with the rest of the system. If you're only going to compile packages for your own system, though, you don't need to worry too much about this quality assurance step, as you're the only person suffering from mistakes, after all.
Dependencies are the most common packaging error. There are two excellent tools you can use to check dependencies. The first one is ldd, which will show you the shared library dependencies of dynamic executables:
$ ldd gcc linux-gate.so.1 => (0xb7f33000) libc.so.6 => /lib/libc.so.6 (0xb7de0000) /lib/ld-linux.so.2 (0xb7f34000)
Submitting packages to the AUR
Please read AUR User Guidelines#Submitting Packages to UNSUPPORTED for a detailed description of the submission process.
- Download the source tarball of the software you want to package.
- Try compiling the package and installing it into an arbitrary directory.
- Copy over the prototype Template:Filename and rename it to Template:Filename in a temporary working directory -- preferably Template:Filename.
- Edit the Template:Filename according to the needs of your package.
- Run Template:Codeline and see whether the resulting package is built correctly.
- If not, repeat the last two steps.
- Before you can automate the package building process, you should have done it manually at least once unless you know exactly what you're doing in advance, in which case you would not be reading this in the first place. Unfortunately, although a good bunch of program authors stick to the 3-step build cycle of "Template:Codeline; Template:Codeline; Template:Codeline", this is not always the case, and things can get real ugly if you have to apply patches to make everything work at all. Rule of thumb: If you can't get the program to compile from the source tarball, and make it install itself to a defined, temporary subdirectory, you don't even need to try packaging it. There isn't any magic pixie dust in Template:Codeline that makes source problems go away.
- In a few cases, the packages are not even available as source and you have to use something like Template:Codeline to get it to work. You will have to do quite a bit of research (read READMEs, INSTALL instructions, man pages, perhaps ebuilds from Gentoo or other package installers, possibly even the MAKEFILEs or source code) to get it working. In some really bad cases, you have to edit the source files to get it to work at all. However, Template:Codeline needs to be completely autonomous, with no user input. Therefore if you need to edit the makefiles, you may have to bundle a custom patch with the Template:Filename and install it from inside the Template:Codeline function, or you might have to issue some Template:Codeline commands from inside the Template:Codeline function.