This is a quick HOWTO on how to build up an RPM from a source tarball. Information here was extracted from the book "Maximum RPM", the "RPM HOWTO" from www.rpm.org and personal experience. I am by no means an RPM expert, but I have used this technique to build a few RPM's on the Linux Intel and PPC platforms.

Tools:

Of course you will need of version of RPM on the system you plan to do the building on. If you are running RedHat or any of the derivatives (Mandrake, LinuxPPC, YellowDog, etc.), then you should already have it installed. If you are running Slackware or some of the other distributions, you will need to obtain and install RPM from www.rpm.org in order to proceed.

Directories:

Installing RPM should have created the following directory structure under /usr/src:


/usr/src/redhat/BUILD
/usr/src/redhat/RPMS
/usr/src/redhat/SOURCES
/usr/src/redhat/SPECS
/usr/src/redhat/SRPMS

This is where you will be creating and testing your RPM. Final testing really needs to be done on a virgin system, where the package you are creating has not already been installed. If you don't have access to a clean system, then you'll need to rely on feedback from the user community as to whether your RPM works or not.

Procedure:

To illustrate the building of an RPM from a tarball, I'm going to use rxvt: "ouR eXtended Virtual Terminal". This is a nice version that adds pseudo tranparent backgrounds and a "Next" style scrollbar, that goes well with WindowMaker, my current favorite window manager.

Start out by placing the tarball in the /usr/src/redhat/SOURCES directory. The assumption at this point is that the tarball is fully patched and your system has all the tools/libraries required to successfully compile and install the program. If the program needs to be patched or modified in any way, you will need to either expand the tarball and make the changes, then retar it, or include the patches as part of your RPM .spec script. I this particular instance, I found the man page did not install, so I'm going to manually add a command to my sepc file to get it installed, rather than modify the source.

Now you need to compose your .spec file. This file is a script that rpm uses to build up the source and binary RPM's from the tarball. Once you've mastered one, it's pretty much routine to make more. The hardest part of the whole routine is creating the list of files that get installed by the binary RPM. This has to be derived by examining the Makefile and/or README's of the source tarball.

I'm going to list the rxvt2.6.0.sperc-.spec file and discuss each section:

  • Summary: Just a one-line description of the package.
  • Name: The application's name.
  • Version: The application's version, generally extracted from the tar file name.
  • Release: The RPM release, this is independent of the program version. It's purpose is to indicate how many times the program has been packaged.
  • Copyright: Usually extracted from the README's in the tarball. If it's not GPL/Open Source, you better get the author's permission to create an RPM.
  • Group: This is somewhat arbitrary. It's just a way of categorizing what type of application the program is.
  • Source: This should be a URL pointing to the original program source.
  • Distribution: This would be name of the distribution. For the example, I'm using the as-of-yet fictional iEspresso distribution for Apple's iMac.
  • Vendor: Again, distribution related. The name of the distribution's vendor. For th example fictional distribution, I used TBD.
  • Packager: You opportunity for fame and fortune, or lots of email. Put a contact address where people can reach you, should they have trouble using your RPM.


Summary: rxvt - ouR eXtended Virtual Terminal
Name: rxvt
Version: 2.6.0
Release: 1
Copyright: GPL
Group: Applications/Terminal
Source: ftp://ftp.rxvt.org/pub/rxvt/rxvt-2.6.0.tar.gz
Distribution: iExpresso
Vendor: TBD
Packager: Stew Benedict

%description - This can be several lines of text giving a more thorough description of the application. In this case, I just composed a short blurb.

%description rxvt X11 terminal, compiled with psuedo transparency and Next style scrollbars, also includes an analog clock

The %prep section does the preliminary work of placing the tar file in the temporary build directory and expanding it. If you have a proper RPM install, the %setup -q macro will probably suffice. If not, you can put whatever commands you need here to get things ready to go. For instance, on my Slackware based notebook, the setup program is something entirely different, so I used the following lines:


cp ../SOURCES/FSViewer.app-0.2.1.tar.gz .
tar -xzf FSViewer.app-0.2.1.tar.gz


%prep
%setup -q

The %build section contains whatever steps you take manually when compiling the source tarball. In this case, I'm moving to the build directory, running ./configure with the features I want and make. An additioanl make builds the analog clock app.


%build
./configure --enable-transparency --enable-next-scroll --disable-backspace-key --disable-delete-key
make
make clock

The %install section covers the steps required to install the final application. I could be as simple as "make install", or if the source Makefile does not have an install option, you will need to recreate whatever steps are necessary to move the binary, man-files etc., to the right place and set the permissions properly. For this particular example, the make install did not place the man page for rxvt, so I'm doing it manually.


%install
make install
cp doc/rxvt.1 /usr/local/man/man1

The %files section can be the gruelling part of creating an RPM. You need to explicitly list the full path to every file the RPM is going to install. No matter how well you do the first steps, if you omit files from this section, they will not be included in the binary RPM, nor will they get installed on the users' system(s). This can be a bit of detective job to track down all the files needed. Again, the author's Makefile and README's can be good sources of information. This one was easy, just 4 files.


%files
/usr/local/bin/rxvt
/usr/local/bin/rclock
/usr/local/man/man1/rxvt.1
/usr/local/man/man1/rclock.1

The %clean section is just to cleanup things after you build your RPM's. Again, this can be most anything you could run from the command line. In this case I'm deleting the directory from the BUILD directory.


%clean
cd ..
rm -rf rxvt-2.6.0

The %changelog is just to track the changes in the RPM as it gets revised once it's out in the community at large. It does expect the format to be as listed below.


%changelog
* Sun Aug 1 1999 Stew Benedict
- packaged for soon-to-be iEspresso distribution

OK, now you've composed your spec file, and it's time to try it out. Move to the /usr/src/redhat/SPECS directory and run the command:


rpm -ba rxvt-2.6.0.spec

If you're successful, you should end up with two files:


/usr/src/redhat/SRPMS/rxvt-2.6.0-1.src.rpm
/usr/src/redhat/RPMS/ppc/rxvt-2.6.0-1.ppc.rpm

If you get errors, then you'll need to review the errors and see at which step you had a problem and address it.

To review the contents of your new RPM's you can use the commands:


rpm -q -l -p /usr/src/redhat/SRPMS/rxvt-2.6.0-1.src.rpm
rpm -q -l -p /usr/src/redhat/RPMS/ppc/rxvt-2.6.0-1.ppc.rpm

And you should see the tarball and the spec file in the src rpm, and a list of the files you specified in the binary rpm. If you don't see anything in the binary rpm, then review your spec file again.

Well, that's it. Hopefully this will give you some insight on how to build up RPM's. Lets see you all go wild and start building lots of apps for LinuxPPC.