« Installing Fedora Core is more work than Gentoo | Main | Tufts hires Amy Rich, Unix guru and Sysadmin Author »

December 20, 2004

Building a Simple RPM is . . . Simple

Over the last month or so I've been helping folks at some other schools update or install new versions of the TUSK code. Every installation is Linux; Reh Hat 7.x, Fedora Core 2, Red Hat Enterprise 3. I'm not crazy about RPMs, but they have a purpose and I'm just glad that when they are appropriate they are simple to build.

Part of our install requires making a static build of Apache, compiling in mod_ssl and mod_perl, and tacking Embperl onto the build. Getting all the steps and options just right is a trick, using a script is the only sane way to go. While it's possible to have the script make install, my preference is to build a package. This helps if there is a need to upgrade or an undetected problem with the build, you can confidently uninstall and then reinstall the new package.

I've built close to a zillion packages on Solaris, using the Sun pkg programs, and had installed an RPM or two, but had never built one.

The process is simple, easier than all the manual work required with Sun's packaging.

1 - create an rpm home dir (~/rpm)
2 - inside the rpm home create 5 directories; BUILD, RPMS, SOURCES, SPECS and SRPMS
3 - create ~/.rpmmacros with two lines

%_topdir /home/mkruck01/rpm
%_tmppath /tmp
4 - Download the tarfile you want to install (apache in our case) and put it in SOURCES.
5 - Emacs SPECS/apache.spec (Emacs knows a spec file and creates a nice template)
6 - Add info to template to look like:

Summary: apache web server
Name: apache
Version: 2.0.54
Release: 1
License: Apache
Group: application
Source0: %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
%description
Apache is a great webserver

%prep
%setup -q

%build
./configure --prefix=/usr/local
make
make test

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

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root,-)
%doc
/usr/*

7 - Build the software and RPM with: rpmbuild -bb ~/rpm/SPECS/apache.spec

The RPM will be in RPMS/i386 (or whatever your processor identifier happens to be).

The cool thing is that for many different software build processes the build and install steps are the same, so you can copy the spec file and change the first few items, drop your tarfile into the SOURCES dir and have an RPM faster than it would take to untar and compile manually.

Posted by mike at December 20, 2004 5:55 PM