Tuesday, April 13, 2010

RPM creation

Introduction to Packages

First, read this online document: http://www.rpm.org/max-rpm/

All Linux systems use some kind of packaging system to install and remove programs. A package is a collection of files combined into a single package file. These files can include commands, configuration files, libraries, man pages, etc... When a package is installed, the package system extracts all the component files and places them in the correct locations on your operating system. Likewise, when you want to remove a package, the package system knows which files to delete.

A package usually contains a compiled program that only works on a particular CPU architecture. Because some program depends on other programs to operate, packages can have dependencies as well. Certain packages may fail to install unless you have installed other packages firrst, and some packages may not be removed unless no other programs depend upon them. This protects the user from installing software that will fail due to a missing component.

If your system uses RPM packages, you can search the RPM database at rpmfind.net/.

How to build an RPM:

To build an RPM, you must first setup a directory hierarchy per the rpmbuild specifications. Once that is done, you can place your source code and associated files in the proper locations in the hierarchy, create your spec file, then build the RPM.

The RPM directory hierarchy specifies five directories:

- BUILD: a scratch space to compile your software.
- RPMS: contains the binary RPM that rpmbuild builds.
- SOURCES: a place for you source code.
- SPECS: contains your spec file for the RPM you want to build.
- SRPMS: contains the source RPM build during the process.

Begin by copying your source into the SOURCES directory. The source should be bundled as a tarball with the naming convention: package-version.tar.gz.

Next, create your spec file. Here is a sample of a spec file:

  # This is a sample spec file for wget  %define _topdir   /home/strike/mywget %define name   wget  %define release  1 %define version  1.12 %define buildroot %{_topdir}/%{name}-%{version}-root  BuildRoot: %{buildroot} Summary:   GNU wget License:   GPL Name:    %{name} Version:   %{version} Release:   %{release} Source:   %{name}-%{version}.tar.gz Prefix:   /usr Group:    Development/Tools  %description The GNU wget program downloads files from the Internet using the command-line.  %prep %setup -q  %build ./configure make  %install make install prefix=$RPM_BUILD_ROOT/usr  %files %defattr(-,root,root) /usr/local/bin/wget  %doc %attr(0444,root,root) /usr/local/share/man/man1/wget.1 


Note that there are five sections in a typical spec file.

The first section is the %description section. This description is shown whenever a user runs rpm -qi to query the RPM database.

The %prep, %build, and %install each contains a shell script. The %prep readies the source code such as unpacking it. The %build section configures and launch the build manually. The %install section installs the application. The %files lists the files that should be bundled into the RPM and sets permissions and other information.

To get a complete example, read the following http://www.ibm.com/developerworks/library/l-rpm1/

No comments:

Post a Comment