How To Make RPM Packages

When working with RedHat Linux systems the best way to ensure that you have the right software installed is by using RPM’s

RPM is a package management system like Solaris packages.

To create packages from source code some or all of the following steps would be needed.

To set it up a build environment and number of configuration files are needed.

First the build environment.

cd /home/asbjorn
mkdir myrpm
cd rpm
mkdir -p BUILD RPMS/i386 SOURCES SPECS SRPMS

In earlier releases of RedHat a file .rpmrc was used.

Now rpmbuild uses the .rpmmacros for default values.

In the first two lines, information about the package creator is provided.

The _topdir line is included, so the package can be build as a user rather than as root.
Do not build packages as root if you can avoid it.

The following lines provide references to the build environment.

cd /home/asbjorn

vi .rpmmacros

%packager      Asbjorn Riedel <asbjorn@SOMEWEBSITE.com>
%vendor        The name of the project

%_topdir       /home/asbjorn/myrpm

%{_topdir}/BUILD
%{_topdir}/RPMS
%{_topdir}/RPMS/i386
%{_topdir}/SOURCES
%{_topdir}/SPECS
%{_topdir}/SRPMS

By defining the .spec file we can set up all the parameters needed for building packages of software delivered as tar files.

The %{_prefix} definition can be changed depending on the location where you want your package to be installed, example /opt, /usr or /usr/local. Just change the line with Prefix:  in it.

 vi myrpm/SPECS/testpackage.spec

%define name testpackage
%define version 0.0.1
%define release 1

Summary: A test package for RedHat Linux
Name: %{name}
Version: %{version}
Release: %{release}
Source:
http://www.picourl.com/testpackage/%{name}-%{version}.tar.gz
Vendor: Guess It Must Be Me
URL:
http://www.picourl.com/
License: None
Group: System
Prefix: %{_prefix}

%description
This is a testpackage , specially made for testing

%package devel
Summary: package with stuff to develop %{name}.
Group: System
Requires: %{name} = %{version}

%description devel
The %{name}-devel testpackage contains stuff for building %{name}.

%prep
%setup -q

%build
make

%install
rm -rf $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT install

%clean
rm -rf $RPM_BUILD_ROOT

%post -p /sbin/ldconfig

%postun -p /sbin/ldconfig

%files
%defattr(-,root,root)
%doc ReadMe
%{_prefix}/lib/lib*.so.*

%files devel
%defattr(-,root,root)
%doc ReadMe
%{_prefix}/bin/*
%{_prefix}/include/*

%changelog
* Thu Mar 27 2008 Asbjorn Riedel <
asbjorn@localhost>
– Initial spec file

The %install part contains the actual commands to build the software and it may need to be changed in your case.

 

How to finally do the build …

rpmbuild -ba SPECS/testpackage.specs