Creating .deb and RPM packages

Since I’ve managed to get it to work for GSSMP, I thought I might share how I am generating .deb and RPM packages using a Makefile. These make it much easier for Ubuntu and Fedora Linux users (respectively) to install the program. It should also be helpful for people using Debian, who can try the .deb, and other RPM-based distros, who can try the RPM.

This project is all autotooled-up, so this may not be very helpful if you don’t use autotools.

(Side tip: I don’t understand autotools at all, but since I created the project with glade, it did all the hard work for me.)

I created these files for the Ubuntu .deb package:

changelog:

gssmp (0.8-0ubuntu1) edgy; urgency=low

  * First release packaged for ubuntu

 -- Andy Balaam <myemailaddress>  Thu, 15 Feb 2007 12:33:11 +0000

copyright:

This package was debianized by Andy Balaam <myemailaddress> on
Thu, 15 Feb 2007 12:33:11 +0000.

It was downloaded from

http://sourceforge.net/project/showfiles.php?group_id=187144&package_id=219138

Copyright Holder: Andy Balaam <myemailaddress>

License:
   This package is free software; you can redistribute it and/or modify
   blah blah blah GPL boilerplate

control:

Source: gssmp
Section: sound
Priority: optional
Maintainer: Andy Balaam <myemailaddress>
Build-Depends: debhelper (>= 4.0.0), autotools-dev, libgstreamer0.10-dev, libgnomeui-dev
Standards-Version: 3.6.2

Package: gssmp
Architecture: any
Depends: libgstreamer0.10-0, libgnomeui-0
Description: Gnome Simple Stateful Music Player
 GSSMP is a music player designed to work with Gnome.  It does not store a
 database of all your music, but is designed to work with music files organised
 into directories.  It is small, unobtrusive, and tries to do what you would
 expect, instead of asking you questions.
 .
 It remembers which file was playing on exit, and continues that file from the
 same place when you start again.  It remembers tracks you have been listening
 to recently and displays them in the "Recent" menu.

I put those three files in my source tree under install/deb/.

For the RPM, I just needed one file, gssmp.spec:

###
### RPM spec file for Gnome Simple Stateful Music Player
###
### Adapted from jEdit's spec file http://www.jedit.org
###
Summary: A music player that doesn't interfere.
Name: gssmp
Provides: gssmp
Version: 0.8
Release: 1
License: GPL
Group: Applications/Multimedia/
Source0: %{name}-%{version}.tar.bz2
URL: http://gssmp.sourceforge.net/
Vendor: Andy Balaam <myemailaddress>
Packager: Andy Balaam <myemailaddress>
BuildArch: i386
BuildRoot: %{_builddir}/%{name}-root
Requires: libgnomeui, gstreamer
BuildRequires: libgnomeui-devel, gstreamer-devel

%description
GSSMP is a music player designed to work with Gnome.  It does not store a
database of all your music, but is designed to work with music files organised
into directories.  It is small, unobtrusive, and tries to do what you would
expect, instead of asking you questions.

It remembers which file was playing on exit, and continues that file from the
same place when you start again.  It remembers tracks you have been listening
to recently and displays them in the "Recent" menu.

%prep
%setup -n %{name}-%{version}

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

%install
make DESTDIR=%{buildroot} install

%clean
rm -rf %{buildroot}

%files
/usr/bin/gssmp
/usr/share/doc/gssmp/AUTHORS
/usr/share/doc/gssmp/COPYING
/usr/share/doc/gssmp/INSTALL
/usr/share/doc/gssmp/NEWS
/usr/share/doc/gssmp/README
/usr/share/doc/gssmp/TODO

which I put in install/rpm

Then I modified my Makefile.am to build the deb and RPM when I told it to:

APP_NAME=gssmp

# Create a deb package
pkg-deb: pkg-src
        - rm -r $(TMP_DIR)
        mkdir -p $(TMP_DIR)
        cp pkg/$(APP_NAME)-$(VERSION).tar.bz2 $(TMP_DIR)/
        tar --directory $(TMP_DIR)/ \
                -xjf $(TMP_DIR)/$(APP_NAME)-$(VERSION).tar.bz2
        cd $(TMP_DIR)/$(APP_NAME)-$(VERSION)/; \
                echo | dh_make --single --copyright gpl -e myemailaddress -f \
                        ../$(APP_NAME)-$(VERSION).tar.bz2
        cp install/deb/changelog install/deb/control \
                install/deb/copyright $(TMP_DIR)/$(APP_NAME)-$(VERSION)/debian/
        cd $(TMP_DIR)/$(APP_NAME)-$(VERSION)/; \
                rm debian/README.Debian debian/*.ex debian/*.EX; \
                ./configure; \
                dpkg-buildpackage -rfakeroot; \
                mv ../*.deb $(PWD)/pkg/
        rm -r $(TMP_DIR);

# Create an RPM package
pkg-rpm: pkg-src
        mkdir -p $(HOME)/.rpm/RPMS/i386
        mkdir -p $(HOME)/.rpm/SRPMS
        mkdir -p $(HOME)/.rpm/BUILD
        mkdir -p $(HOME)/.rpm/SOURCES
        mkdir -p $(HOME)/.rpm/tmp
        - rm -r $(HOME)/.rpm/BUILD/$(APP_NAME)-root
        - rm -r $(HOME)/.rpm/RPMS/$(APP_NAME)-*
        - rm -r $(HOME)/.rpm/SRPMS/$(APP_NAME)-*
        - rm -r $(HOME)/.rpm/SOURCES/$(APP_NAME)-*
        cp pkg/$(APP_NAME)-$(VERSION).tar.bz2 $(HOME)/.rpm/SOURCES/
        rpmbuild --quiet --nodeps --define="_topdir $(HOME)/.rpm" \
            -ba install/rpm/gssmp.spec
        mv $(HOME)/.rpm/RPMS/i386/$(APP_NAME)-$(VERSION)-*.i386.rpm pkg/

Now I just needed to run ./autogen.sh to regenerate my Makefile, and then make pkg-deb or make pkg-rpm and the deb or RPM appears magically in the pkg/ directory.

Autotools, for all its faults, does make this stuff relatively easy. All the code for installing in different places (installing at all) and general flexibility is done for you. Of course, it’s at the expense of ever understanding what’s going on, but you can’t have everything.

Now I just need to make a man page … and fix all the bugs … oh, and make an icon … and make it accept a filename on the command line … and sort out MIME types … etc … so it should be finished really soon.

One Response to “Creating .deb and RPM packages”

  1. myITcorner: Tomasz Gebarowski programming blog » Blog Archive » Making Debian library package with dh_make Says:

    [...] Debian New Maintainers’ Guide Andy Balaam’s Blog Tags: debian, gnu, library, [...]

Leave a Reply