English - Español - Deutsch - Français - Português
Home > English > BuildingWithoutHelper
BuildingWithoutHelper

How to make a Debian package without using a helper

 by Miriam Ruiz
 Version 0.3, 09-Jan-2005

0. INDEX

   1. Introduction
   2. Downloading and unpacking the source
   3. Testing the upstream building system
   4. Fixing some upstream bugs
   5. Creating Debian specific files
      5.1. Control file
      5.2. Copyright file
      5.3. Changelog file
      5.4. Rules file
   6. Understanding the rules file
      6.1. Initial definitions
      6.2. Rules
      6.3. Explanation
      6.4. Adding a menu
   7. Building the package
   8. Final words
   9. Full files
      9.1. debian/control
      9.2. debian/copyright
      9.3. debian/changelog
      9.4. debian/rules

1. INTRODUCTION

This document is written for people who want to understand the insides of debian packaging. It is no assumed that the reader knows how to package a program, but it would be much better if she/he already did.

This is not supposed to be the best document to learn to make packages from zero. If that is your case, I suggest you to read "Debian New Maintainers' Guide" at http://www.debian.org/doc/maint-guide/

Thanks to Helen Faulkner and Dafydd Harries for their help, their support and for helping me with this document, and Manoj Srivastava for his interest in helping me to learn and for his code, which was an important reference for me.

Special thanks go to Debian-Women and ChicasLinux? for their support.

NOTE: This document shall not be understood as "here's an easy/good way to maintain your packages", but as "here is how the insides of debian package building works". I don't know if it can be useful for anyone, in case it is, I'd be glad.

2. DOWNLOADING AND UNPACKING THE SOURCE

We're going to build a Debian package from scratch without using debhelper, yada or anything like that, just with the help of "dpkg" and "dpkg-dev" packages.

The program I've selected for this task is called "roaddemo", is available at http://www.newimage.com/~rhk/roaddemo/ and is distributed under a GNU GPL License. It depends on OpenGL? and SDL and is built using the standard "./configure && make && make install" procedure (with a minor trick, as "make install" doesn't seem to work properly as it is, but it will do anyway for the tutorial).

The first step is to make a new directory in which we will work, and to download the program:

   $ mkdir roaddemo
   $ cd roaddemo
   $ wget -t 0 -c http://www.newimage.com/~rhk/roaddemo/roaddemo-1.0.1.tar.gz

We'll expand the tar.gz archive and rename it to the proper .orig.tar.gz file name it will need in Debian's building system ( <package>_<version>.orig.tar.gz ):

   $ tar xvfz roaddemo-1.0.1.tar.gz
   $ mv roaddemo-1.0.1.tar.gz roaddemo_1.0.1.orig.tar.gz
   $ cd roaddemo_1.0.1

The code expands itself in a directory called roaddemo-1.0.1, which is consistent with the <package>-<version> nomenclature. Otherwise we'd have to rename it properly using "mv" command.

3. TESTING THE UPSTREAM BUILDING SYSTEM

We'll see if it compiles properly before attempting to package it:

   $ ./configure --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info

We'll use those switches for a start. It might depend on how the autoconf stuff is done whether they might need some tweaking or not. If it is well done, typing "./configure --help" should show the available options.

Then we'll try to build the program using "make":

   $ make

As that seems to work, let's try to install it using "make install".

We don't really want the program to be installed in our main directory tree, so we'll add the parameter "DESTDIR" to tell make where the program should be installed. We'll make a temporary directory for that:

   $ mkdir tmp

We'll use the "`pwd`/tmp" trick to give the program the absolute directory instead of a relative one.

   $ make install DESTDIR=`pwd`/tmp

This command seems to give an error, but normally it should work perfectly, so don't worry about this. In this case, the problem is solved by adding a new parameter telling "make" what "LIBTOOL" is, which should be defined inside it anyway. This is a bug in the upstream source.

   $ make install DESTDIR=`pwd`/tmp LIBTOOL=libtool

Now we have the program we wanted to install inside "tmp/".

It is important that you have a look at the files the building system has installed. If you are working from the console, there is a command called "tree" which is very useful for this sort of thing. The Debian package is called "tree".

It is not uncommon to have some kind of problem in the building process. Sometimes "autoconf" or "automake" files are not done as they should, sometimes the parameters to "./configure" are not standard and you'll have to find them out. Sometimes only a conventional "Makefile" is available and you have no "./configure" stuff. In the latter case, you might need to fix it so that the "DESTDIR" parameter works. There is no global solution for every problem, so that's the creative part of it.

Let's clean everything we have created so far:

   $ make distclean
   $ rm -rf tmp

4. FIXING SOME UPSTREAM BUGS

Now, if the program was well done, you shouldn't need to do what I'm doing now, but as it is quite a common mistake, I'll solve it here just in case. The program seems to open a file called "road.bmp", which is not installed by "make install", so we'll need to install it by hand.

Inside the code, "road.bmp" is open without an absolute address, so when the program is run, it'll try to load it from the current working directory, whatever that is. According to Debian Policy, the file should go somewhere under "/usr/share/<package name>", so we'll put it right in "/usr/share/roaddemo/road.bmp".

We'll have to modify the code. First we try to find where in the source code that file is used:

   $ grep road.bmp *.h *.c *.cpp *.cc *.hpp

That command gives us the following result:

   roaddemo.cc:    if (load_texture("road.bmp", &road_tex_id) < 0)

Great, that's what we need to modify. Change "road.bmp" in that file to "/usr/share/roaddemo/road.bmp" and don't touch anything else.

This sort of thing is best fixed by sending a patch upstream that lets you define paths at compile time, or at least notifying the upstream author.

You usually need to modify something in the upstream code when developing a package, so be aware of it. What is uncommon is the program that goes smoothly as is. You will likely have to encounter and fix similar problems yourself.

Even though you can modify anything you need, don't change the files more than neccesary. That means, don't change the indentation, carriage return styles or whatever is not absolutely needed. When the developing of the package ends, you are going to get a .diff.gz file with the changes between the original files and yours, and modifying those kind of things makes it unnecessarily big, and increases the chances that you will not be able to apply them to newer releases of the upstreamer.

5. CREATING DEBIAN SPECIFIC FILES

Now let's go to the package building part. We'll have to create "./debian" directory and, at least, the following files: "debian/control", "debian/copyright", "debian/changelog" and "debian/rules".

   $ mkdir debian

According to Debian's Policy, man pages are required for every binary in your package. It would also be nice to add an icon and a "debian/menu" file with the data needed to add the program to the menu, but that are not strictly needed. As this is not a tutorial about man pages, I'll not cover that issue here.

5.1. CONTROL FILE

"debian/control" should have an structure similar to this:

 Source: <package name>
 Section: <section>
 Priority: optional
 Maintainer: <maintainer>
 Build-Depends: <build dependencies>
 Standards-Version: 3.6.1

 Package: <package name>
 Architecture: any
 Depends: ${shlibs:Depends}
 Description: <insert up to 60 chars description>
  <insert long description, indented with spaces>

5.2. COPYRIGHT FILE

Our "debian/copyright" file, as it is a program distributed under the GNU GPL License:

 This package was debianized by <maintainer> on
 <date and time>.

 It was downloaded from <upstream URI>

 Upstream Author: <upstream author>

 License:

    This package is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; version 2 dated June, 1991.

    This package is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this package; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    02111-1307, USA.  

 On Debian GNU/Linux systems, the complete text of the GNU General
 Public License can be found in `/usr/share/common-licenses/GPL'.

5.3. CHANGELOG FILE

Now for "debian/changelog":

 <package name> (<package version>-<release>) unstable; urgency=low

   * Initial Release.

  -- <maintainer>  <date and time>

I'm not going to explain here how this files are done. Have a look at the "Debian New Maintainers' Guide" ( http://www.debian.org/doc/maint-guide/ ).

5.4. RULES FILE

Now for the "debian/rules" part, where the rules to build the package are defined.

"debian/rules" is in fact a "Makefile", and is run by "/usr/bin/make". You can go do "info make", "man make" or have a look at http://www.gnu.org/software/make/manual/make.html if you need more information on "make" building system.

"debian/rules" can be called with diferent parameters: "build", "clean", "binary", so we'll have to implement all of them.

6. UNDERSTANDING THE RULES FILE

6.1. INITIAL DEFINITIONS

First of all, we'll add a line so that the shell knows it is a "make" file in case it is directly executed:

   #!/usr/bin/make -f

Now a useful definition of the package's name for simplifying "debian/rules" management:

   # Name of the package
   package=roaddemo

At some point of the execution, we'll need to make sure we're in the appropriate directory, and that we're running the script as "root" (or with the command "fakeroot"), so we'll define a couple of functions:

   # Function to check if we're in the correct dir
   define checkdir
   	@test -f debian/rules -a -f roaddemo.cc ||     	(echo Not in correct source directory; exit 1)
   endef

   # Function to check if we're root
   define checkroot
   	@test $$(id -u) = 0 || (echo need root priviledges; exit 1)
   endef

"checkdir" checks that a "debian/rules" file exists, and also a file called "roaddemo.cc" in the current directory. "checkroot" checks that we're "root". This functions were taken 'as is' from Manoj Srivastava's building system and can be used under the GNU GPL License.

We'll then define our working directories:

   # Top directory of the source code (thanks Manoj)
   SRCTOP    := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
   # Destination directory where files will be installed
   DESTDIR    = $(SRCTOP)/debian/$(package)

"SRCTOP" is the top directory of our source code, and "DESTDIR" is where the package will be temporarily installed, that is, "debian/roaddemo/" directory.

We'll define more directories to make our life simpler later:

   # Definition of directories
   BIN_DIR = $(DESTDIR)/usr/bin
   GAMES_DIR = $(DESTDIR)/usr/games
   SHARE_DIR = $(DESTDIR)/usr/share/roaddemo
   DOCS_DIR = $(DESTDIR)/usr/share/doc/roaddemo
   MAN_DIR = $(DESTDIR)/usr/share/man/man1
   MAN_GAMES_DIR = $(DESTDIR)/usr/share/man/man6
   MENU_DIR = $(DESTDIR)/usr/lib/menu
   PIXMAPS_DIR = $(DESTDIR)/usr/share/pixmaps

"BIN_DIR" and "GAMES_DIR" is where binary files for conventional programs and games should respectively go. "SHARE_DIR" is where the platform independent files for the package should be installed. "DOCS_DIR" is for documentation, "MAN_DIR" and "MAN_GAMES_DIR" are for man pages, "MENU_DIR" is where we would put the menu management files and "PIXMAPS_DIR" where icons should go.

6.2. RULES

Now for the implementation of the commands. You can look at http://www.debian.org/doc/debian-policy/ch-source.html#s-debianrules to see what rules need to be implemented:

 # Stamp Rules

 configure-stamp:
 	$(checkdir)
 	./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info
 	touch configure-stamp

 build-stamp: configure-stamp
 	$(checkdir)
 	-rm -f build-stamp
 	$(MAKE)
 	touch build-stamp

 # Debian rules

 build: build-stamp

 clean: stamp-configure
 	$(checkdir)
 	-rm -f *-stamp
 	$(MAKE) distclean
 	-rm -rf debian/$(package)
 	-rm -f debian/files
 	-rm -f debian/substvars

 binary-indep: build

 # Definitions for install
 INST_OWN = -o root -g root
 MAKE_DIR  = install -p -d $(INST_OWN) -m 755
 INST_FILE = install -c    $(INST_OWN) -m 644
 INST_PROG = install -c    $(INST_OWN) -m 755 -s
 INST_SCRIPT = install -c  $(INST_OWN) -m 755

 binary-arch: build
 	$(checkdir)
 	$(checkroot)

 	# Install Program
 	$(MAKE) install DESTDIR=$(DESTDIR) LIBTOOL=libtool

 	# Install Program Resources
 	$(MAKE_DIR) $(SHARE_DIR)
 	$(INST_FILE) road.bmp $(SHARE_DIR)

 	$(MAKE_DIR) $(DESTDIR)/DEBIAN

 	# Install Docs
 	$(MAKE_DIR) $(DOCS_DIR)
 	$(INST_FILE) debian/copyright $(DOCS_DIR)/copyright
 	$(INST_FILE) debian/changelog $(DOCS_DIR)/changelog.Debian
 	$(INST_FILE) README $(DOCS_DIR)/README

 	# Install Manpages
 	#$(MAKE_DIR) $(MAN_GAMES_DIR)
 	#$(INST_FILE) roaddemo.6 $(MAN_GAMES_DIR)

 	# Install Menu and Icon
 	#$(MAKE_DIR) $(MENU_DIR)
 	#$(INST_FILE) debian/menu $(MENU_DIR)/roaddemo
 	#$(MAKE_DIR) $(PIXMAPS_DIR)
 	#$(INST_FILE) debian/roaddemo.xpm $(PIXMAPS_DIR)

 	# Install Package Management Scripts
 	#$(INST_SCRIPT) debian/postinst $(DESTDIR)/DEBIAN
 	#$(INST_SCRIPT) debian/postrm $(DESTDIR)/DEBIAN

 	# Compress Docs (thanks Helen)
 	gzip -9 $(DOCS_DIR)/changelog.Debian
 	#gzip -9 $(MAN_GAMES_DIR)/roaddemo.6

 	# Strip the symbols from the executable (thanks Helen)
 	strip -R .comment $(BIN_DIR)/roaddemo

 	# Work out the shared library dependancies (thanks Helen)	
 	dpkg-shlibdeps $(package)

 	# Generate the control file (thanks Helen)
 	dpkg-gencontrol	-isp -P$(DESTDIR)

 	# Make DEBIAN/md5sums (thanks Helen)
 	cd $(DESTDIR) && find . -type f ! -regex '.*DEBIAN/.*' -printf '%P\0' | xargs -r0 md5sum > DEBIAN/md5sums

 	# Create the .deb package (thanks Helen)
 	dpkg-deb -b $(DESTDIR) ../

Finally, we end with a fairly generic part:

 # Below here is fairly generic really

 binary: binary-indep binary-arch

 .PHONY: binary binary-arch binary-indep clean build

Phony rules are any rules which don't produce a file with the same name as the rule -- i.e. if you type "make foo", and it doesn't create a file/directory "foo", then it's a phony rule (thanks, daf).

6.3. EXPLANATION

Now for the explanation of each part:

"stamp-configure" checks that we're in the correct directory and does the configuration stuff of the package.

The purpose of the *-stamp files is to avoid repeating things. When "make" is deciding what to do, it looks at the timestamps of the files in question. It is obvious that this doesn't work when the rules in question don't produce files. If you run "./debian/rules build", and "./debian/rules binary" afterwards, "make" doesn't know the second time that you already did the first one. If, instead, you create a "build-stamp" rule, and make "build" depend on that, and "touch" the "build-stamp" when you are finished building, then "make" has a way of knowing that the build is finished (thanks again, daf).

"build" depends on "stamp-configure" being executed first. If it wasn't, it is automatically called before starting to build ("info make" for more information). After that, the building part is done.

"clean" cleans the directories from previous builds. As it uses "make distclean" for that, it depends on "stamp-configure" being called before it. After making "make distclean", we still have to clean some of the files the package creation systems temporarily makes inside "./debian" directory, that is, the whole "debian/roaddemo/" temporary installation tree, and the files "debian/files" and "debian/substvars".

"binary" makes, installs and builds all the packages. It depends on "binary-indep" and "binary-arch".

"binary-indep" makes, installs and builds the platform independent packages, such as perl or python scripts, which do not need to be compiled for every platform. We do not need it for anything in this case.

"binary-arch" makes, installs and builds the platform dependent packages, such as the compiled programs, as ours. In first place, we check that we're in the appropriate directory and that we are "root" (or using "fakeroot"). Then we call "make install" for installing the program. As the installation script doesn't handle the file "road.bmp", we move it by hand into its destination directory: "/usr/share/roaddemo/". Remember that we modified the source code to get it from there.

The control part of the package needs to go inside a "debian/roaddemo/DEBIAN" directory, so we make it, then we copy the doc files into "/usr/share/doc/roaddemo", including "debian/copyright" and "debian/changelog" (the latter renamed to "changelog.Debian", just in case there's a "changelog" file from upstream author).

In case we have man pages, we install them. We also install menu scripts and icons if we have them. A note on icons: there's no problem in adding a new .xpm icon file, as it is just a text format. Debian packaging system does not support adding new binary files, such as .bmp, .png or .ico for example. If you needed to do so, you'd have to use "uuencode" and "uudecode" accordingly.

Then we add installation/removal scripts. In case we are adding a menu script, we need at least the neccesary commands in "postinst" and "postrm" to update the menus afterwards. In our program, if you are not adding menu items, you do not need them.

Now the final part. We compress "changelog.Debian" as well as the man pages (if we had any), strip the debugging symbols from binary executables (with "strip"), work out the shared library dependencies (with "dpkg-shlibdeps") and generate the control file (with "dpkg-gencontrol"). After that we create a file "debian/roaddemo/DEBIAN/md5sums" with the "md5sum" of every file in the package (for checking afterwards), and finally we create the .deb package in "../" directory.

Don't forget that "debian/rules" is an executable, so remember to do:

   $ chmod +x debian/rules

6.4. ADDING A MENU

If you want your program to be automatically added to te Debian menu system, you'll need to add a "debian/menu" file, which should be something like:

 ?package(roaddemo):needs="x11" section="Games/Toy"   	title="Road Demo" command="roaddemo"   	icon="/usr/share/pixmaps/roaddemo.xpm"

Or, if you don't have an icon:

 ?package(roaddemo):needs="x11" section="Games/Toy"   	title="Road Demo" command="roaddemo"

If you add a menu, take into account that you also have to add the neccesary commmand lines to update the menu system in the package's management scrips "debian/postinst" and "debian/postrm":

If you add a menu, be careful to also add a "debian/postinst" and a "debian/postrm" files:

"debian/postinst" file:

 #!/bin/sh
 set -e
 if [ "$1" = "configure" ] && [ -x /usr/bin/update-menus ]; then update-menus ; fi

"debian/postrm" file:

 #!/bin/sh
 set -e
 if [ "$1" = "configure" ] && [ -x /usr/bin/update-menus ]; then update-menus ; fi

You can read additional info about menu system in "/usr/share/doc/menu/html/index.html" inside your Debian system. You also can find there the list of possible sections you can use.

7. BUILDING THE PACKAGE

Now we're done, lets check it:

We clean the files resulting from previous tries:

   $ debian/rules clean

And we make the package:

   $ debuild

If everything goes OK, we should have new files in "../" directory:

   $ ls ..
   roaddemo-1.0.1               roaddemo_1.0.1-1_i386.changes
   roaddemo_1.0.1-1.diff.gz     roaddemo_1.0.1-1_i386.deb
   roaddemo_1.0.1-1.dsc         roaddemo_1.0.1.orig.tar.gz
   roaddemo_1.0.1-1_i386.build

Now you should check if there's something strange in the package using "lintian" and "linda":

   $ lintian ../roaddemo_1.0.1-1_i386.deb
   $ linda ../roaddemo_1.0.1-1_i386.deb

8. FINAL WORDS

Even though this started as a personal exercise to learn the insights of the Debian packaging building system, it has become a full tutorial that might be useful for other people. I couldn't have done that without the help of Debian-Women and Debian-Mentors. The same goes to Helen and Dafydd, I wouldn't have done this without your help. I don't mean just writing this document, but, most important for me, learning and understanding it. Thanks.

9. FULL FILES

9.1. debian/control

-- CUT HERE --
 Source: roaddemo
 Section: games
 Priority: optional
 Maintainer: Miriam Ruiz <little_miry@yahoo.es>
 Build-Depends: libsdl1.2-dev, libgl-dev
 Standards-Version: 3.6.1

 Package: roaddemo
 Architecture: any
 Depends: ${shlibs:Depends}
 Description: Simple demo using opengl and SDL
  Bezier-road demo ported from glut to SDL.
  .
  Use the right mouse button to select one of the
  endpoints or control points, then click and drag
  with the left mouse button to move the point.

-- CUT HERE --

9.2. debian/copyright

-- CUT HERE --
 This package was debianized by Miriam Ruiz <little_miry@yahoo.es> on
 Sat,  8 Jan 2005 20:09:28 +0000.

 It was downloaded from http://www.newimage.com/~rhk/roaddemo/

 Upstream Author: Ray Kelm <rhk@newimage.com>

 License:

    This package is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; version 2 dated June, 1991.

    This package is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this package; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    02111-1307, USA.  

 On Debian GNU/Linux systems, the complete text of the GNU General
 Public License can be found in `/usr/share/common-licenses/GPL'.

-- CUT HERE --

9.3. debian/changelog

-- CUT HERE --
 roaddemo (1.0.1-1) unstable; urgency=low

   * Initial Release.

  -- Miriam Ruiz <little_miry@yahoo.es>  Sat,  8 Jan 2005 20:09:28 +0000

-- CUT HERE --

9.4. debian/rules

-- CUT HERE --
 #!/usr/bin/make -f

 # Debian Rules by Miriam Ruiz <little_miry@yahoo.es>
 #    January 2005
 #
 # Thanks for their help and for some of their code go to:
 #    * Manoj Srivastava
 #    * Helen Faulkner
 #    * Dafydd Harries
 #    * Gregory Pomerantz

 ###############################################################################
 ##
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
 ## the Free Software Foundation; either version 2 of the License, or
 ## (at your option) any later version.
 ##
 ## This program is distributed in the hope that it will be useful,
 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ## GNU General Public License for more details.
 ##
 ## You should have received a copy of the GNU General Public License
 ## along with this program; if not, write to the Free Software
 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ##
 ###############################################################################

 # Name of the package
 package=roaddemo

 # Function to check if we're in the correct dir (thanks Manoj)
 define checkdir
 	@test -f debian/rules -a -f roaddemo.cc ||   	(echo Not in correct source directory; exit 1)
 endef

 # Function to check if we're root (thanks Manoj)
 define checkroot
 	@test $$(id -u) = 0 || (echo need root priviledges; exit 1)
 endef

 # Top directory of the source code (thanks Manoj)
 SRCTOP    := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
 # Destination directory where files will be installed
 DESTDIR    = $(SRCTOP)/debian/$(package)

 # Definition of directories
 BIN_DIR = $(DESTDIR)/usr/bin
 GAMES_DIR = $(DESTDIR)/usr/games
 SHARE_DIR = $(DESTDIR)/usr/share/roaddemo
 DOCS_DIR = $(DESTDIR)/usr/share/doc/roaddemo
 MAN_DIR = $(DESTDIR)/usr/share/man/man1
 MAN_GAMES_DIR = $(DESTDIR)/usr/share/man/man6
 MENU_DIR = $(DESTDIR)/usr/lib/menu
 PIXMAPS_DIR = $(DESTDIR)/usr/share/pixmaps

 # Stamp Rules

 configure-stamp:
 	$(checkdir)
 	./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info
 	touch configure-stamp

 build-stamp: configure-stamp
 	$(checkdir)
 	-rm -f build-stamp
 	$(MAKE)
 	touch build-stamp

 # Debian rules

 build: build-stamp

 clean: stamp-configure
 	$(checkdir)
 	-rm -f *-stamp
 	$(MAKE) distclean
 	-rm -rf debian/$(package)
 	-rm -f debian/files
 	-rm -f debian/substvars

 binary-indep: build

 # Definitions for install
 INST_OWN = -o root -g root
 MAKE_DIR  = install -p -d $(INST_OWN) -m 755
 INST_FILE = install -c    $(INST_OWN) -m 644
 INST_PROG = install -c    $(INST_OWN) -m 755 -s
 INST_SCRIPT = install -c  $(INST_OWN) -m 755

 binary-arch: build
 	$(checkdir)
 	$(checkroot)

 	# Install Program
 	$(MAKE) install DESTDIR=$(DESTDIR) LIBTOOL=libtool

 	# Install Program Resources
 	$(MAKE_DIR) $(SHARE_DIR)
 	$(INST_FILE) road.bmp $(SHARE_DIR)

 	$(MAKE_DIR) $(DESTDIR)/DEBIAN

 	# Install Docs
 	$(MAKE_DIR) $(DOCS_DIR)
 	$(INST_FILE) debian/copyright $(DOCS_DIR)/copyright
 	$(INST_FILE) debian/changelog $(DOCS_DIR)/changelog.Debian
 	$(INST_FILE) README $(DOCS_DIR)/README

 	# Install Manpages
 	#$(MAKE_DIR) $(MAN_GAMES_DIR)
 	#$(INST_FILE) roaddemo.6 $(MAN_GAMES_DIR)

 	# Install Menu and Icon
 	#$(MAKE_DIR) $(MENU_DIR)
 	#$(INST_FILE) debian/menu $(MENU_DIR)/roaddemo
 	#$(MAKE_DIR) $(PIXMAPS_DIR)
 	#$(INST_FILE) debian/roaddemo.xpm $(PIXMAPS_DIR)

 	# Install Package Scripts
 	#$(INST_SCRIPT) debian/postinst $(DESTDIR)/DEBIAN
 	#$(INST_SCRIPT) debian/postrm $(DESTDIR)/DEBIAN

 	# Compress Docs (thanks Helen)
 	gzip -9 $(DOCS_DIR)/changelog.Debian
 	#gzip -9 $(MAN_GAMES_DIR)/roaddemo.6

 	# Strip the symbols from the executable (thanks Helen)
 	# TODO: the stripping part in binary-arch should honor the DEB_BUILD_OPTIONS environment variable and not strip stuff when it includes 'nostrip'
 	strip -R .comment $(BIN_DIR)/roaddemo

 	# Work out the shared library dependancies (thanks Helen)	
 	dpkg-shlibdeps $(package)

 	# Generate the control file (thanks Helen)
 	dpkg-gencontrol	-isp -P$(DESTDIR)

 	# Make DEBIAN/md5sums (thanks Helen)
 	cd $(DESTDIR) && find . -type f ! -regex '.*DEBIAN/.*' -printf '%P\0' | xargs -r0 md5sum > DEBIAN/md5sums

 	# Create the .deb package (thanks Helen)
 	dpkg-deb -b $(DESTDIR) ../

 # Below here is fairly generic really

 binary: binary-indep binary-arch

 .PHONY: binary binary-arch binary-indep clean build

-- CUT HERE --