Compdigitec Labs

« | Home | »

Creating Debian packages (properly) using debhelper

By admin | April 28, 2012

# change these to fit your name/e-mail address
export DEBEMAIL="john.smith@fanboys.example.com"
export DEBFULLNAME="John Smith"

wget http://www.example.com/pub/example-2.0.1.tar.gz
tar zxvf example-2.0.1.tar.gz
cd example-2.0.1
dh_make -f ../example-2.0.1.tar.gz

Now, open up debian/control and modify the section field to fit one of the valid Debian sections. Then, the Build-Depends field should have whatever packages you need - minimally it should have debhelper (>= 7.0.50~), dh-buildinfo, dh-autoreconf (if you need it), along with any libraries your application will need. Set the Homepage field to be the URL of your software’s homepage on the Internet.

Once you are happy with that you can modify your package’s fields, right below the source section. Set the Architechture (i386, amd64, or etc), add Depends (Depends: ${shlibs:Depends}, ${misc:Depends} should work in most cases, because dh_shlibdeps is called). Finally, modify the package description.

A sample debian/control file:

Source: example
Section: misc
Priority: optional
Maintainer: John Smith
Build-Depends: debhelper (>= 7.0.50~),
               dh-buildinfo,
               dh-autoreconf,
               libogg-dev
Standards-Version: 3.8.4
Homepage: http://www.example.org/
Vcs-Git: git://git.example.org/example.git
Vcs-Browser: http://git.example.org/?p=example.git;a=summary

Package: example
Architecture: i386
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: Awesome example application
 Example is an awesome example application. It provides examples to do many things.
 .
 Example can also be used as an excuse to not learn how to make examples.

A sample debian/rules file:

#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

build:
	./configure --prefix=/usr --sysconfdir=/etc --enable-ogg --enable-the-force --disable-stuff --blah-blah=blah
	make

binary:
	dh_testroot
	dh_auto_install
	dh_shlibdeps
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

%:
	dh $@

To build the package (assuming everything compiles correctly):

dpkg-buildpackage -nc -us -uc -ivolatile_build_folder/

Explanation:
-nc means don’t clean (saves you time in case an error occurs)
-us and -uc mean unsigned source and unsigned changes recently, not useful if you are not official maintainer
-i means don’t consider this folder when making diff archive (to avoid dpkg-source: error: unrepresentable changes to source)

After this process is complete, the built .deb file can be found in the folder above the source folder.

Useful links:

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles!

Topics: Linux | No Comments »

Comments