Novell Home

Using Build.rpm to Package an OpenSource Project

From Developer Community

by Cory Aitchison

In a continuation of Paul MacKay's excellent article Beginner's Guide to Using Novell SUSE Linux's Build Utility and an article I wrote earlier Building Packages for Novell's Linux Products this tutorial outlines how to create an rpm from a random open source project using build.rpm. Okay to be honest the selection may not have been totally random, I selected to use gaim for reasons outlined below. However, the model I use and the spec file provided should be easily modifiable to build any project that is contained in CVS or Subversion and makes use of the gnu autotools.

In my other build.rpm article I go through the anatomy of a spec file so I will skip that part here. What I will cover is the steps in the process of packaging an open source project from beginning to end.

Contents

Determine where and how project you want to build is stored

I guess step one would be to decide what project you want to build but that seemed too trivial. As I mentioned above, I decided to build gaim. I selected this project because 1) I knew it was stored in cvs, and 2) I have packaged it before and I know it would be fairly straight forward.

Now, because gaim is stored in CVS I decided to make things a little harder on myself and use the build process to check it out from cvs instead of downloading it and creating a tarball first. This shows some of the flexibility that you get by using RPM. You have total shell control in your spec file so you can do interesting things like this. If the sources were not located in CVS or you didn't want to take this step, you could just as easily download the source and perform a normal build.

Create your spec file

Header Information

Once we have our sources we can then begin the process of making the spec file. The first part to do is take care of all the mandatory tags located at the start of the spec file.

# This sample has been tested on a SUSE Professional 9.3 workstation using
# packages for Suse Pro 9.3.  If you want to build to other platforms you may need
# to make some changes to the BuildRequires line.

summary:	A GTK Hello World example program.
name:		gaim
version:	1.5.0
release:	0
source:		%{name}-%{version}.tar.gz
vendor: 	Novell, Inc.
packager: 	DevNet Team <ndk@novell.com>
group:		Applications/Internet
copyright:	gpl
prefix:		/opt/gaim
URL:		http://gaim.sourceforge.net/
buildroot: %{_tmppath}/%{name}

BuildRequires: <This is covered and given below>

%description
A test build of gaim

I took most of this information from gaim.

BuildRequires

I have found no easy way to do this. It is very time consuming, especially if you are building something with a GUI front end. The way I fill in my build requires is as follows:

  1. Take a stab at what libraries and packages I think I'll need.
  2. Try building
  3. If we make it past the initial ./configure do a happy dance and exit the loop
  4. See why the build fails
  5. GOTO 1

It always brings me great relief when I make it past the 'make' step as I can usually figure out all the rest of the errors. TIP: You can make this step a little easier on yourself by chrooting into /var/tmp/buildroot (the temporary build area for build.rpm) and doing running the configure and make parts of your spec file at this point. That way as you find package dependencies you can install the RPMs into your build area and try again. It saves the overhead of running build.rpm each time.

BuildRequires: 	pkgconfig cvs pam-modules gettext make libtool automake\
                perl autoconf gzip gnome-filesystem gcc glibc-devel\
                libzio info binutils xorg-x11-libs less gettext gtk2\
                gtk2-devel glib2 glib2-devel atk atk-devel pango pango-devel\
                cairo cairo-devel expat fontconfig fontconfig-devel freetype2\
                freetype2-devel libpixman libpng xorg-x11-devel\
                xorg-x11 cabextract resmgr fonts-config xf86tools libjpeg\
                libstdc++ libusb xorg-x11 xorg-x11-Mesa xorg-x11-devel\ 
                xorg-x11-fonts-scalable xorg-x11-fonts-cyrillic xorg-x11-fonts-75dpi

It took me about 4 hours to get the above libraries right.

Fill in the rest of the spec file

From here on out you are just doing basic RPM stuff. This can also take some time and there are invariably weird errors that come up as you put the finishing touches on your spec file. However this is all fairly easy stuff. We are setting up the %prep, %build, %install, and %files areas.

%description
A test build of gaim

%prep
SOURCE_DIR=%{_topdir}/SOURCES/
cd $SOURCE_DIR
cvs -d:pserver:anonymous@66.35.250.207:/cvsroot/gaim export -r v1_5_0 gaim

%build
SOURCE_DIR=%{_topdir}/SOURCES/
cd $SOURCE_DIR/gaim
./autogen.sh --prefix=%{buildroot}/%{prefix}
make
make install

%install
DESTDIR=%{buildroot}
#mkdir -p $DESTDIR%{prefix}
touch /usr/src/packages/SOURCES/gaim-1.5.0.tar.gz

%files
%{prefix}/*

Do take notice of the line 'cvs -d:pserver:anonymous@66.35.250.207:/cvsroot/gaim export -r v1_5_0 gaim'. This is where I get the sources from sourceforge to build gaim (a rather ingenious step if I do say so myself). Also note the line touch /usr/src/packages/SOURCES/gaim-1.5.0.tar.gz. I am not sure why this is necessary but it is (see the article discussion for more information). RPM looks for this tar.gz and I couldn't see a way around it. If anyone out there does know why and how to avoid it please drop me an email and I'll update this article.

Run build.rpm and watch the magic happen

Now that the spec file is set up all we have to do is run build.rpm and the packages should be properly made.

build --rpms /suseISOs/9.3/cd1:/suseISOs/9.3/cd2:/suseISOs/9.3/cd3:/suseISOs/9.3/cd4:/suseISOs/9.3/cd5 gaim.spec

Build.rpm will now get all the packages listed on the BuildRequires line from the locations listed in the --rpms directive. If you follow this example, you may run into a problem that I encountered. The packaging process hangs twice when I run it and I have to do a ^c to continue on. The line that is displayed when the process hangs is something like this:

/usr/X11R6/bin/xfs notice: ignoring font path element /usr/X11R6/lib/X11/fonts/hellas/Type1 (unreadable)

And again it happens twice. If anyone knows how to get around this, again, please let me know.

Conclusion

So if you have an understanding of how to write spec files this article should let you put all the pieces together to create any package you want from source using build.rpm.

If you have any correction please feel free to make them directly in this wiki page -OR- email them to me and I'll be happy to add them.

Complete Spec File

# This sample has been tested on a SUSE Professional 9.3 workstation using
# packages for Suse Pro 9.3.  If you want to build to other platforms you may need
# to make some changes to the BuildRequires line.

summary:	A GTK Hello World example program.
name:		gaim
version:	1.5.0
release:	0
source:		%{name}-%{version}.tar.gz
vendor: 	Novell, Inc.
packager: 	DevNet Team <ndk@novell.com>
group:		Applications/Internet
copyright:	gpl
prefix:		/opt/gaim
URL:		http://gaim.sourceforge.net/
buildroot: %{_tmppath}/%{name}

BuildRequires: 	pkgconfig cvs pam-modules gettext make libtool automake perl\
                autoconf gzip gnome-filesystem gcc glibc-devel libzio info\
		binutils xorg-x11-libs less gettext gtk2 gtk2-devel glib2\
		glib2-devel atk atk-devel pango pango-devel cairo cairo-devel\
		expat fontconfig fontconfig-devel freetype2 freetype2-devel\
		libpixman libpng xorg-x11-devel xorg-x11 cabextract resmgr\
		fonts-config xf86tools libjpeg libstdc++ libusb xorg-x11\
		xorg-x11-Mesa xorg-x11-devel xorg-x11-fonts-scalable\
		xorg-x11-fonts-cyrillic xorg-x11-fonts-75dpi
%description
A test build of gaim

%prep
SOURCE_DIR=%{_topdir}/SOURCES/
cd $SOURCE_DIR
cvs -d:pserver:anonymous@66.35.250.207:/cvsroot/gaim export -r v1_5_0 gaim

%build
SOURCE_DIR=%{_topdir}/SOURCES/
cd $SOURCE_DIR/gaim
./autogen.sh --prefix=%{buildroot}/%{prefix}
make
make install

%install
DESTDIR=%{buildroot}
#mkdir -p $DESTDIR%{prefix}
#cp -a * $DESTDIR%{prefix}/
touch /usr/src/packages/SOURCES/gaim-1.5.0.tar.gz

%files
%{prefix}/*

Novell® Making IT Work As One

© 2009 Novell, Inc. All Rights Reserved.