RPM Build Tutorial
From Sukimashita
Contents |
[edit] Introduction
This tutorial is intends to help you setting up a local build environment on openSuSe in order to build your own RPMs. It is only a quickstart guide thus you should checkout further resources for more details around RPM in general.
[edit] Requirements
In order to build RPMs you will require a few things such as the correspondig software and up to 3GB disk space.
- Install the following packages:
build bzip2 gpg
- Make sure to have around 3GB free disk space.
- Make sure to have the openSuSe DVD at hand
[edit] The tool: "build"
build is a tool to automatically setup a build environment and create RPMs based on a spec file you pass to it as argument. It gets the required sources, patches and spec file from the current working directory and processes all *.spec files if available, then it dynamically creates a seperate "system" in a directory and uses it to build the packages. Thus the build process happens in a clean and standardized environment and does not interfere with you own system.
There are various command line arguments for build which can also be set using environment variables. (See "build --help" or "man build" for details).
The most important are:
--rpms path1:path2:...
This specifies a series of paths where build should find the RPMs for the build system. We will pass the path to the mounted openSuSe DVD for instance and thus make sure we get a package selection like a standard openSuSe install with that DVD would have.
If you add a trailing slash to the path, build is aswell going to look for RPMs in the subdirectories, otherwise it just checks the "<path>/*.rpm".
--arch arch1:arch2:...
Specifies the architecture of the RPMs to get.
--no-init
Upon first invocation build creates the seperate build system which might take a while depending on the required packages of the RPM you attempt to build. However sometimes a build might fail in the build process (after the system was setup correctly) and this argument allows you to skip the build system creation and directly start at the build process again. For instance a specific patch might fail and stop the build process. Simply fix the patch and use the same build command line with --no-init so the build process directly begins without re-checking the build system.
A typical build example might look like this:
build --arch i586 --rpms /media/SU1020.001/suse/:/home/<yourname>/build/rpm <myspec.spec>
[edit] Building an RPM
Building a package is actually a quite easy process when you can use the "build" tool and have everything setup.
What you usually need is:
- The source code of the package (usually a *.tar.gz or *.tar.bz2)
- A specification file for the build process to know how to package/compile/setup everything into an RPM
When building a package you end up with:
- A source package
- One or more packages containing the compiled binaries for the software
A source package is like an archive which contains the sources, additional patches, resources and the build specification ".spec" file.
It is common to split the range of files generated at compile time into further sub-packages. This is the reason why you see packages such as <name>-devel-..., <name>-debuginfo-..., which is all set within the corresponding .spec file.
The automatic naming of the generated packages is usually:
<name>-<version>-<revision>.<architecture>.rpm
The revision has to be changed in the .spec file whenever you do changes to it and generate new RPMs. The package manager initially compares the version, then the revision of the package.
Creating .spec files is a huge topic in itself and not suited for this quick-guide, thus the best practice in order to understand how to create packages is to take a "source" package and attempt to build real packages out of it first.
You can open included .spec file(s) and try to see if you understand what the build rules "%<rule>" mean. Then go ahead and check a RPM Specification Manual for in-depth details of the .spec file structure. You'll quickly be able to adjust small part and build updated packages based on existing ones.
[edit] Directory Setup
We use one directory where we will store all relevant build process files in your home directory.
md ~/build
Inside the directory we are going to use three further directories for storage and building.
- Storage for the final local repository of built packages:
md ~/build/repo/
- Additional required packages (some are missing from the DVD but are available online and need to be put here)
md ~/build/rpm/
- Storage of the sources and package specification files. We'll trigger the building process from here.
md ~/build/work/
Thus you end up with:
~/build/ ~/build/repo/ ~/build/rpm/ ~/build/work/
[edit] Build the package
We'll be building an example package here out of a source package.
- Change into the ~/build/work/ directory
- Extract the contents of a source RPM package into it:
file-rollor -e . <package>.src.rpm
- You should end up with some files and a .spec file
# ls ...
- Go superuser
su
- Have the openSuSe DVD inserted.
- Start the build process
build --arch i586 --rpms /media/SU1020.001/suse/:/home/<username>/build/rpm/ --jobs 4
The additional --jobs argument is useful on multiprocessor systems allowing parallel builds and speeding up the whole process.
You'll notice build checking for various packages and dependencies in the directories we supplied in the --rpms argument. If build reports that it can not find a specific package it might not be available on the DVD. Thus go online and download it from the repository and save it into the ~/build/rpm/ directory.
Then just restart the build process and it should be able to locate it now.
After the build process finished, you'll end up with your RPMS in /var/tmp/build-root/usr/src/packages/RPMS/.
[edit] Creating a custom local repository
[edit] Requirements
- createrepo script
- create_package_descr
- repo.sh
- A directory to store the repository