Debian New Maintainers' Guide Josip Rodin version 0.97, 27. September 1999. Copyright © 1998, 1999 Josip Rodin.

This document may used under the terms of any fully DFSG compliant license, preferably GNU General Public License version 2+.

With permission of their authors, I have used and modified portions of these two documents:

Making a Debian Package (AKA the Debmake Manual), copyright © 1997 Jaldhar Vyas The New-Maintainer's Debian Packaging Howto, copyright © 1997 Will Lowe Getting started "The Right Way"

This document will try to describe building of a Debian GNU/Linux package to the common Debian user (and wannabe developer) in common language, and well covered with working examples. There is an old Roman saying, Longum iter est per preaecepta, breve et efficax per exempla! (It's a long way by the rules, but short and efficient with examples!).

One of the things that makes Debian such a top-notch Linux distribution is its package system. While there is a vast quantity of software already in the Debian format, sometimes you need to install software that isn't. You may be wondering how you can make your own packages and perhaps you think it is a very difficult task. Well, if you are a real novice on Linux, it is hard, but if you were rookie, you wouldn't be reading this doc now. :-) You do need to know a little about Unix programming but you certainly don't need to be a wizard. Programs you need for development

Before you start anything, you should make sure that you properly install some packages with (ie. `dpkg -i package`, or through some of the front-ends like dselect or apt). This document has been written while the 2.1 'slink' distribution was the officially stable release of Debian, and the 2.2 'potato' was being created, thus the packages named here are mostly those from 'potato'.

Following packages come with standard installation of Debian 2.1, so you probably have them (and additional packages they depend on) already. Still, you should check it with `dpkg -s package`. binutils - these programs used to assemble and link object files - the stuff programs are made of. (see `info binutils`) cpp - the C preprocessor. (see ) cpio - this is an archiver like tar or zip. (see ) dpkg-dev - this package contains the tools needed to unpack, build and upload Debian source packages. It also contains the packaging and dpkg-internals manual. (see ) file - this handy program can determine what type a file is. (see ) fileutils - the essential Linux utilities, like ls, chmod, rm and others. (see `info --file /usr/info/fileutils.info.gz`) gcc - the GNU C compiler. Most Linux programs are written in C. However, if your program is written in some other programming language, like C++, Fortran, Pascal, you should get g++, g77, or gpc, respectively. (see , , , ) libc6-dev - the C libraries and header files gcc needs to link with to create object files. Although some programs still recommend and/or use libc5, you are encouraged to use the newer version (libc6). (see `info libc`) make - usually creation of a program takes several steps. Rather than having to type out the same commands over and over again, you can use this program to automate the process, creating 'Makefile's. Some programs also use imake and xmkmf, programs used to generate Makefiles from sets of macro functions. Many newer programs use configure scripts and Makefiles with help of programs like autoconf and automake, so you might need these, too. (see `info make`, , , , ) patch - this very useful utility will take file containing a difference listing (produced by the diff program) and apply it to the original file, producing a patched version. (see ) perl5 - Perl is one of the most used interpreted scripting languages on today's un*x systems, often referred to as "Unix's Swiss Army Chainsaw". (see )

From the devel section of the distribution you'll probably need to install these yourself: dh-make and debhelper - dh-make is necessary to create the skeleton of our example package, and it will use some the debhelper tools for creating packages. They are not essential for creation of packages, but it is highly recommended for new maintainers. It makes the whole process very much easier to start, and control afterwards. (see , , /usr/share/doc/debhelper/README) devscripts - this package contain some nice and useful scripts that can be helpful to the maintainers, but they are also not necessary for building packages. (see /usr/share/doc/devscripts/README.gz) fakeroot - this utility lets you emulate being root which is necessary for some parts of the build process. (see ) lintian - this is a package checker, that can let you know of any common mistakes after you build the package, and explain the errors found. (see , /usr/share/doc/lintian/lintian.html/index.html)

Finally, these very important packages are in the doc section of the distribution: debian-policy - includes the structure and contents of the archive, several OS design issues, the Filesystem Hierarchy Standard, and the most important thing (for you) is that it describes requirements that each package must satisfy to be included in the distribution. (see /usr/share/doc/debian-policy/policy.html/index.html) developers-reference - for all matters not specifically about the technical details of packaging, like the structure of the archive, how to rename, orphan, pick up packages, how to do NMUs, how to manage bugs, when and where to upload etc. (see /usr/share/doc/developers-reference/developers-reference.html/index.html) packaging-manual - describes the technical aspects of creating Debian binary and source packages. (see /usr/share/doc/packaging-manual/packaging.html/index.html)

You will also need the encryption package, either PGP (the pgp-* packages) or GPG (the gnupg package), to digitally sign your package. This is especially important if you want to distribute it to other people (and you will certainly be doing that when your work gets included in the Debian distribution). However, due to a rather wacky U.S. export law, you cannot simply download this from your nearest Debian FTP site. But Debian does provide these packages through a site that is not physically located in the US, called non-US.debian.org (ftp://non-us.debian.org/debian-non-US/). Your FTP site will have a file called README.non-US, which will tell you how to find a closer mirror of that site.

The short descriptions that are given above only serve to introduce you to what each package does. Before continuing please thoroughly read how to the documentation of each program, at least the standard usage. It may seem like heavy going now, but later on you'll be very glad you read it. Note: debmake is a package that contains some programs that function similar to dh-make, but it's specific use is not covered in this document. Refer to for more information. Other information

There are two types of packages you can make, source and binary. A source package contains code which you can compile into a program. A binary package contains just the finished program. Don't mix terms like source of the program and the source package of the program! Please read the other manuals if you need more details on terminology.

Debian uses the term 'maintainer' for person that makes packages, 'author' for the person that made the program, and 'upstream maintainer' for the person who currently maintains that program. Usually author and the upstream maintainer are the same person - and sometimes even the maintainer is the same person. If you made a program, and want it to get in Debian, feel free to submit your application to become a maintainer.

After you build your package (or while doing that), you will have to become an official Debian maintainer if you wish your program to get into the next distribution (if the program is useful, why not?). That process is explained in Developer's Reference. Please read it. First steps

While the documentation at the is not so clear about where and how should new maintainers start their work, this document will explain every little (at first maybe irrelevant) step, and help you create that first package, and to gain some experience in building next releases of that and maybe other packages later on. Choose your program.

You have probably chosen the package you want to build, but here are some pointers for you as the uninitiated: check if the package is in the distribution already. If you use the 'stable' distribution, maybe it's best that you go to the . If you use current 'unstable' distribution, check it out with these commands: dpkg -s program dpkg -l '*program*' consult the and debian-devel mailing list archives to see if anyone else is building that same package. If so, contact the current maintainer if you feel you need to. If not - find another interesting program that nobody maintains. program must have a license, if possible free as according to the . If it doesn't conform to some of these rules, it still can be included in 'contrib' or 'non-free' sections of Debian. If you are unsure about where should it go, ask on program certainly should not run setuid root, or even better - it shouldn't need to be setuid or setgid to anything. program should not be a daemon, or something that goes in */sbin directories. program should result in binary executable form, don't try libraries yet. it should be well documented, or at least understandable (to anyone). you should contact program's author(s) to check if they agree with packaging it. It is important to be able to consult with author(s) about the program in case of any program specific problems, so don't try to package unmaintained pieces of software. and last but not the least, you must know that it works, and have it tried for some time.

Of course, these things are just safety measures, and intended to save you from rageous users if you do something wrong in some setuid ftp daemon... When you gain some more experience in packaging, you'll be able to do such packages, but even the most experienced developers consult debian-devel mailing list when they are in doubt. And people there will gladly help.

For more help about these, check in Developer's Reference. Get the program, and try it out.

So the first thing to do is to find and download the original package. I presume that you already have the source file that you picked up at the author's homepage. Linux sources usually come in tar/gzip format, with extension .tar.gz or .tgz, and usually contain the subdirectory called program-version and all the sources in it. If your program's source comes as some other sort of archive (for instance, the filename ends in .Z or .zip), unpack it with appropriate tools, or ask on debian-mentors if you're not sure how to unpack it correctly (hint: issue `file archive.extension`).

As an example, I'll use program named 'gentoo', an X11 GTK+ file manager. Note that the program is already packaged, and has changed substantially from the version while this text was first written.

Create subdirectory under /usr/local/src named as your program's name (/usr/local/src/gentoo in this case). Place the downloaded archive in it, and uncompress it with `tar -xzf gentoo-0.9.12.tar.gz`. That (somewhat lengthy) process will make no output (except if there are any errors - then you must download it again or check if it is really a tar/gzip archive), but you will get the sources unpacked in a subdirectory called 'gentoo-0.9.12' in /usr/local/src/gentoo.

Change to that directory and thoroughly read the provided documentation. It is usually in files named README*, INSTALL*, *.lsm or *.html. In there you will find instructions on how to correctly compile and install the program (most probably to /usr/local/bin directory).

The process varies from program to program, but a lot of modern programs come with a `configure' script that configures the source under your system and makes sure that your system is in condition to compile it. After configuring (with `./configure`), programs are usually compiled with `make`, and get installed in destination directories by typing `make install`.

So, do compile, install and try that program, to make sure it works okay and doesn't break something else while it's installing or running. Stuff prior to `dh_make'

For the correct building of the program, you should move the source directory to <packagename>-<version>. As you can see, the example program gentoo doesn't need that, but maybe your program will. So, make the program's original name lowercase, if it already is not. If it consists of more than one word, contract them to one word or make an abbreviation. For example, program "John's little editor for X" package would be named johnledx or jle4x, or whatever you decide, as long as it's under some reasonable limit, like 15 characters.

Also check for the exact version of the program (to be included in the package version). If that piece of software is not numbered with versions like X.Y.Z, but with some kind of date, feel free to use that date as the version number, prepended with a "0.0." (just in case upstream people one day decide to release a nice version like 1.0). So, if the release or snapshot date was 19th of December, 1998, you can use the version string of 0.0.19981219. Some programs won't be numbered at all, in which case you should contact the upstream maintainer to see if they've got some other revision-tracking method. Running `dh_make'

Make sure you're in the program source directory, and issue this:

dh_make -e your.maintainer@address

Of course, replace the string "your.maintainer@address" with your e-mail address for inclusion in the changelog entry and other files.

Some information will come up. It will ask you what sort of package you want to create. Gentoo is a single binary package - it creates only one binary, and thus one .deb file - so we will select the first option, with the 's' key, check the information on the screen and confirm with pressing <enter>. As a new maintainer you are discouraged to create multi-binary packages, or the libraries, as explained earlier.

Please note that you should run dh_make only once, and that it won't behave correctly if you run it again in the same, already "debianized", directory. That also means that you will use a different method to release a new revision or a new version of your package in the future. Read more about that later in the text. Modifying the source

When dh_make is finished, and you adjusted the program's own Makefile, you can `cd ..` to see a new directory that has been created, and it is called 'gentoo-0.9.12.orig'. It contains the original source code which will hereafter remain untouched. The 'gentoo-0.9.12' directory still exists, and there you will make changes.

Normally, programs install themselves in the /usr/local subdirectories. But, Debian packages must not use that directory, since it is reserved for system administrator's (or user's) private use. This means that you have to take a look at gentoo's Makefile. This is the script will use to automate building this program. For more details on Makefiles, look in .

Note that there isn't space here to go into all the details of fixing but here are a few problems you often run across. Installation in a subdirectory

Most of the programs have some way of installing themselves in the existing directory structure of your system, so that their binaries get included in your $PATH, and that you find their documentation and manual pages in common places. You have to make sure that they do it correctly, but you have to make them install themselves in a temporary subdirectory that will be created under your debian/ directory, usually called debian/tmp, from which the maintainer tools will build a working .deb package. Everything that is contained in this directory will be installed on user's system when he installs your package, the only difference is that dpkg will be installing the files in the root directory.

Basically, you need to make the program install in debian/tmp, but behave correctly when placed in the root directory, i.e. when installed from the .deb package. With programs using GNU autoconf, this will be quite easy, because dh_make will set up commands for doing that automatically, so you might as well skip reading this section. But with other programs, you will most probably have to examine and edit the Makefiles.

Here's the relevant part of gentoo's Makefile:

# Where to put binary on 'make install'? BIN = /usr/local/bin # Where to put icons on 'make install'? Note: if you change this, # gentoo will not find the icons as it starts up. You're going to # have to alter gentoo's icon path (in the config window, "Paths" # tab) to get it work. ICONS = /usr/local/lib/gentoo/

Before all that, you should insert a new two lines that say:

# Edited for Debian GNU/Linux. DESTDIR = because the build process requires it (will be explained later).

Then the Makefile mentions the location of the final binary. Just change that to this:

# Where to put binary on 'make install'? BIN = $(DESTDIR)/usr/X11R6/bin

But why in that directory, and not some other? Because Debian has defined some rules on where programs are to be installed. That is specified in the Filesystem Hierarchy Standard (see /usr/share/doc/debian-policy/fhs/). So, we should install the binary in /usr/X11R6/bin instead of /usr/local/bin, and the man page (it doesn't exist here, but almost every program has one, so we'll make one later) in /usr/share/man/man1 instead of /usr/local/man/man1.

After that we have a bit harder situation. If you change one line to:

ICONS = $(DESTDIR)/usr/share/gentoo/ which conforms to the policy, you will have to edit some real C sources. But where and what to search? You can find this out by issuing:

grep -n usr/local/lib *.[ch] (in every subdirectory that contains .c and .h files). Grep will tell you the name of the file and the line in it, when he finds an occurrence. Now edit those files and in those lines replace usr/local/lib with usr/share - and that is it. Just replace usr/local/lib with your location, and be very careful that you don't mess up the rest of the code, if you don't know much about programming in C. :-)

After that you should find the install target (search for line that starts with 'install:') and rename all references to directories other than ones defined at the top of the Makefile. In this case, it does that and polishes things up a bit. Previously, install target said:

# ----------------------------------------- Installation # You're going to have to be root to do this! install: gentoo install ./gentoo $(BIN) install icons $(ICONS) install gentoorc-example $(HOME)/.gentoorc

After our change it says: # ----------------------------------------- Installation # You're going to have to be root to do this! install: gentoo-target install -d $(BIN) $(ICONS) $(DESTDIR)/etc install ./gentoo $(BIN) install -m644 icons/* $(ICONS) install -m644 gentoorc-example $(DESTDIR)/etc/gentoorc install -d $(DESTDIR)/usr/share/doc/gentoo/html cp -a docs/* $(DESTDIR)/usr/share/doc/gentoo/html

A careful reader will notice that I changed 'gentoo' to 'gentoo-target' in the 'install:' line. That is called bug fix :-)

Whenever you make changes that are not specifically related to Debian package, be sure to send them to the upstream maintainer so they can be included in the next program revision. Note that you don't have to send the debian/* files upstream, but you should do so with any other patches. And try to be nice to upstream, by making your fixes not specific to Debian or Linux (or even Unix!) prior to sending them. Differing libraries

There is one other common problem: libraries are often different from platform to platform. For example, Makefile can contain a reference to a library which doesn't exist on Debian. In that case, we need to change it to a library which does exist in Debian, and serves the same purpose. The best way is to comment out (not to delete!) those lines because there may be others that will try to compile on different platforms so that they can have some hints about what could be the problem.

So, if there is a line in your program's Makefile that says something like this (and your program doesn't compile):

LIBS = -lcurses -lsomething -lsomethingelse

Change it to this, and it will most probably work:

LIBS = -lncurses -lsomething -lsomethingelse #LIBS = -lcurses -lsomething -lsomethingelse The debian/control and debian/rules file

There is a new subdirectory in gentoo-0.9.12, it is called 'debian'. There are a number of files in this directory. We will be editing these in order to customize the behavior of the package. The most important of them are 'control' and 'rules'. the `control' file

This file contains various values which dpkg and dselect will use to manage the package. Here is the control file dh_make creates for us.

1 Source: gentoo 2 Section: unknown 3 Priority: optional 4 Maintainer: Josip Rodin <jrodin@jagor.srce.hr> 5 Standards-Version: 3.0.1 6 7 Package: gentoo 8 Architecture: any 9 Depends: ${shlibs:Depends} 10 Description: <insert up to 60 chars description> 11 <insert long description, indented with spaces> (I've added the line numbers.)

Lines 1-5 are the control information for the source package. Line 1 is the name of the source package.

Line 2 is the section of the distribution this package goes into. As you may have noticed, Debian is divided in sections: main (the free software), non-free (the not really free software) and contrib (free software that depends on non-free software). Under those, there are logical subsections that describe in short what packages are in. So we have 'admin' for administrator-only programs, 'base' for the basic tools, 'devel' for programmer tools, 'doc' for documentation, 'libs' for libraries, 'mail' for e-mail readers and daemons, 'net' for network apps and daemons, 'x11' for X11 specific programs, and many more.

Let's change it then to x11.

Line 3 describes how important it is that the user install this package. Section and priority are actually only used by dselect when it sorts packages and selects defaults, and they can (and most probably will be) overridden by our FTP maintainers. See the Policy manual for guidance on what to set these fields to.

As it is a normal priority package, we'll leave it as optional.

Line 4 is the name and email address of the maintainer.

Line 5 is the version of the Debian Policy standards this package follows (two major versions of the installed debian-policy package).

Line 7 is the name of the binary package.

Line 8 describes the CPU architecture the binary package was compiled for. We can leave this as "any" because will fill in the appropriate value for any machine this package gets compiled on (see the Developer's Reference for explanation on what porting packages is).

Line 9 shows one of the most powerful features of the Debian packaging system. Packages can relate to each other in various ways. Apart from Depends:, other relationship fields are Recommends:, Suggests:, Pre-Depends:, Conflicts:, Provides:, and Replaces: .

The package management tools such as dpkg, dselect or APT (and its front-ends) usually behave the same way when dealing with these relations; if not, it will be explained. (see , , , , )

This is what they usually mean:

Depends:

The package will not be installed unless the packages it depends on are installed. Use this if your program absolutely will not run (or will cause severe breakage) unless a particular package is present. Recommends:

Dselect will not install your package unless the packages it recommends are installed. Dpkg and APT should let you do it, though. Use this for packages that are not strictly necessary but are typically used with your program. Suggests:

When a user installs your program, dselect will prompt him to install any package it suggests. Dpkg and APT shouldn't care much. Use this for packages which will work nicely with your program but are not at all necessary. Pre-Depends:

This is stronger than Depends:. The package will not be installed unless the packages it pre-depends on are installed and correctly configured. Use this very sparingly and only after discussing it on the debian-devel mailing list. Read: don't use it at all. :-) Conflicts:

The package will not be installed until all the packages it conflicts with have been removed. Provides:

For some types of packages where there are multiple alternatives virtual names have been defined. You can get the full list in /usr/share/doc/debian-policy/virtual-package-names-list.text.gz file. Use this if your program provides a function of an existing virtual package. Replaces:

Use this when your program replaces files from another package, or replaces whole of another package (used in conjunction with Conflicts:). Files from the named packages will be removed before installing yours.

All these fields have uniform syntax. They are a list of package names separated by commas. These package names may also be lists of alternative package names, separated by vertical bar symbols | (pipe symbols). The fields may restrict their applicability to particular versions of each named package. These versions are listed in parentheses after each individual package name, and they should contain a relation from the list below followed by the version number. The relations allowed are: <<, <=, =, >= and >> for strictly earlier, earlier or equal, exactly equal, later or equal and strictly later, respectively.

The last feature I want to show you is $(shlibs:Depends). This will be automatically filled in by (see later) with the names of any shared libraries, such as libc6 or xlib6g, your program uses, so you don't have to specify them yourself. Having said all that, we can leave line 9 exactly as it is now.

Line 10 is where the list of suggestions go. Here it's only 'file', because can use some features provided by that program/package.

Line 11 is the short description. Most people screens are 80 columns wide so this shouldn't be longer than about 60 characters. I'll change it to "A fully GUI configurable GTK+ file manager".

Line 12 is where the long description goes. This should be a paragraph which gives more detail about the package. Column 1 of each line should be empty. There must be no blank lines, but you can put a . (dot) in a column to simulate that. Also, there must be no more that one blank line after the long description.

Here is the updated control file:

1 Source: gentoo 2 Section: x11 3 Priority: optional 4 Maintainer: Josip Rodin <jrodin@jagor.srce.hr> 5 Standards-Version: 3.0.1 6 7 Package: gentoo 8 Architecture: any 9 Depends: ${shlibs:Depends} 10 Suggests: file 11 Description: A fully GUI configurable GTK+ file manager 12 gentoo is a file manager for Linux written from scratch in pure C. It 13 uses the GTK+ toolkit for all of its interface needs. gentoo provides 14 100% GUI configurability; no need to edit config files by hand and re- 15 start the program. gentoo supports identifying the type of various 16 files (using extension, regular expressions, or the 'file' command), 17 and can display files of different types with different colors and icons. 18 . 19 gentoo borrows some of its look and feel from the classic Amiga file 20 manager "Directory OPUS" (written by Jonathan Potter). (I've added the line numbers.) the `rules' file

Now we go back to the 'debian' directory to take a look at rules which will use to actually create the package. This file is actually another Makefile, since it is executed with 'make -f', but different than the one in the upstream source.

Every 'rules' file, as any other Makefile, consists of several rules of how to build the source. Rules consist of targets, filenames or names of actions that should be carried out (for example, 'build:' or 'install:'). Rules that you want to execute you should call as the command line arguments (for example, 'rules build' or 'rules install'). After the target name, you can name the dependency, program or file that that rule depends on. After that there can be any number of commands (starting with <tab>!), until an empty line is found. There begins another rule. Comments begin with hashes ('#'), and end with end of the line. You can invoke rules either from other rules or from command line (ie. `debian/rules clean`).

You are probably confused now, but it will all be clear upon examination of the 'rules' file that dh_make gives us as a default. You should also read the 'make' entry in info for more information.

1 #!/usr/bin/make -f 2 # Made with the aid of dh_make, by Craig Small 3 # Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess. 4 # Some lines taken from debmake, by Christoph Lameter. 5 6 # Uncomment this to turn on verbose mode. 7 #export DH_VERBOSE=1 8 9 build: build-stamp 10 build-stamp: 11 dh_testdir 12 13 14 # Add here commands to compile the package. 15 $(MAKE) 16 17 touch build-stamp 18 19 clean: 20 dh_testdir 21 dh_testroot 22 rm -f build-stamp install-stamp 23 24 # Add here commands to clean up after the build process. 25 -$(MAKE) clean 26 27 dh_clean 28 29 install: install-stamp 30 install-stamp: build-stamp 31 dh_testdir 32 dh_testroot 33 dh_clean -k 34 dh_installdirs 35 36 # Add here commands to install the package into debian/tmp. 37 $(MAKE) install DESTDIR=`pwd`/debian/tmp 38 39 touch install-stamp 40 41 # Build architecture-independent files here. 42 binary-indep: build install 43 # We have nothing to do by default. 44 45 # Build architecture-dependent files here. 46 binary-arch: build install 47 # dh_testversion 48 dh_testdir 49 dh_testroot 50 dh_installdocs 51 dh_installexamples 52 dh_installmenu 53 # dh_installemacsen 54 # dh_installinit 55 dh_installcron 56 dh_installmanpages 57 # dh_undocumented 58 dh_installchangelogs 59 dh_strip 60 dh_compress 61 dh_fixperms 62 dh_suidregister 63 dh_installdeb 64 dh_shlibdeps 65 dh_gencontrol 66 # dh_makeshlibs 67 dh_md5sums 68 dh_builddeb 69 70 source diff: 71 @echo >&2 'source and diff are obsolete - use dpkg-source -b'; false 72 73 binary: binary-indep binary-arch 74 .PHONY: build clean binary-indep binary-arch binary (I've added the line numbers.)

You are probably familiar with lines like line 1 from shell and perl scripts. It means this file is to be run through make. Empty lines are ignored. Lines beginning with '#' (hash) are treated as comments and also ignored.

Lines 9 through 17 describe the 'build' (and its child build-stamp) rule which runs the applications own Makefile to compile the program.

Things rarely work perfectly the first time so the 'clean' rule specified in lines 18-26 clean up any unneeded junk left over from previous failed attempts.

The installation process, the 'install' rule, starts with line 29. On line 34, all necessary directories are created in the 'debian' directory. Line 37 runs the install target from gentoo's Makefile - and installs in the debian/tmp directory - this is why we specified $(DESTDIR) as the root installation directory in gentoo's Makefile.

As the comments suggest, 'binary-indep' rule on lines 41-43 is used to build architecture independent packages, but we don't have any.

Next is 'binary-arch' rule, on lines 46 through 68, in which we run several small utilities from the debhelper package that do various operations on your package to make it conform to Debian policy.

The names start with dh_ and after that you can see what every little utility really does: check that you are in the right directory (/usr/local/src/gentoo/gentoo-0.9.12/), checks that you have root permissions, creates directories mentioned in 'dirs' file [doesn't exist here], copies documentation to debian/tmp/usr/share/doc/gentoo directory, copies menu file to debian/tmp/usr/lib/menu/gentoo, copies manpages and links them correctly, copies changelogs to debian/tmp/usr/share/doc/gentoo directory, copies init.d script [doesn't exist here], copies crontab script to debian/tmp/etc/cron.* [doesn't exist here], copies example files to debian/tmp/usr/share/doc/gentoo/examples [doesn't exist here], strips debugging headers from executable files to make them smaller, gzips man pages and documentation larger than 4 kb, checks and fixes invalid permissions in debian/tmp directory, sets up files to register setuid executables with [doesn't exist here], copies package related files under debian/tmp directory, calculates dependencies of the executables, generates and installs the control file, generates shared libs dependencies file [doesn't exist here], generates MD5 checksums, and finally, finally builds the package.

Every one of these dh_* scripts has its own man page, for more information please read it. There are other dh_* scripts not mentioned here, and if you might need them, read the debhelper documentation.

Lines 70-74 are just some necessities on which you can read in the make manual. For now, they're not important to know about.

The important part to know about the rules file created by dh_make is that it is just a suggestion. It will work for simple packages but for more complicated ones, don't be afraid to add and subtract from it to fit your needs. This especially applies to the binary-arch sections, where you should comment out lines that call features you don't need, in this case I'll comment out lines 47, 53, 54, 57 and 66 because gentoo doesn't need them. Only thing that you must not change are the names of the rules, because they are needed to be named this way because all the tools use these names, mandated by our Packaging manual.

Of course, some tuning is required here: on the line 58 I'll add 'FIXES' because that is the name of the changelog file. For any other option, please read the man page of dh_* program involved. Other files in debian/ dir copyright

This file contains the package's copyright information. It's format is not dictated by the Policy, but the contents is (section 6.5). Dh_make created a default one, this is what it looks like:

1 This package was debianized by Josip Rodin <jrodin@jagor.srce.hr> on 2 Wed, 11 Nov 1998 21:02:14 +0100. 3 4 It was downloaded from <fill in ftp site> 5 6 Upstream Author(s): <put author(s) name and email here> 7 8 Copyright: 9 10 <Must follow here> (I've added the line numbers.)

The important things to add to this file are the place you got the package from and the actual copyright notice (include it whole). If the copyright is one of the popular free software licenses such as GNU GPL or LGPL, BSD or the Artistic license, you can just refer to the appropriate file in /usr/share/common-licenses/ directory that exists on every Debian system. Gentoo is licensed under the GNU General Public License, so we'll change the file to this:

1 This package was debianized by Josip Rodin <jrodin@jagor.srce.hr> on 2 Wed, 11 Nov 1998 21:02:14 +0100. 3 4 It was downloaded from: ftp://ftp.obsession.se/gentoo/ 5 6 Upstream author: Emil Brink <emil@obsession.se> 7 8 This software is copyright (c) 1998-99 by Emil Brink, Obsession 9 Development. 10 11 You are free to distribute this software under the terms of 12 the GNU General Public License. 13 On Debian systems, the complete text of the GNU General Public 14 License can be found in /usr/share/common-licenses/GPL file. (I've added the line numbers.) README.Debian

Any extra details or discrepancies between the original package and your debianized version should be documented here. Dh_make created a default one, this is what it looks like: gentoo for Debian ---------------------- <possible notes regarding this package - if none, delete this file> Josip Rodin <jrodin@jagor.srce.hr>, Wed, 11 Nov 1998 21:02:14 +0100

Since we don't have anything to put there - it is allowed to delete the file. changelog

This is a required file, which has a special format described in the Packaging Manual (section 3.2.3). This format is used by dpkg and other programs to obtain the version number, revision, distribution and urgency of your package.

For you, it is also important, since it is good to have documented all changes you have done. It will help people downloading your package to see are there any unresolved issues with the package that they should know instantly about. It will be saved as /usr/share/doc/gentoo/changelog.Debian.gz in the binary package.

Dh_make creates a default one, this is what it looks like:

1 gentoo (0.9.12-1) unstable; urgency=low 2 3 * Initial Release. 4 5 -- Josip Rodin <jrodin@jagor.srce.hr> Wed, 11 Nov 1998 21:02:14 +0100 6 7 Local variables: 8 mode: debian-changelog 9 End: (I've added the line numbers.)

Line 1 is the package name, version, distribution, and urgency. Name must match the source package name, for now, distribution should be unstable or experimental, and urgency shouldn't be changed to anything higher than 'low'. :-)

Lines 3-5 are a log entry, where you document changes made in this package revision (not the upstream changes - there is special file for that purpose, created by upstream authors, installed as /usr/share/doc/gentoo/changelog.gz). New lines must be inserted just before the uppermost line that begins with asterisk ('*'). You can do it with dch, emacs (lines 7-9 contain mode information for the Emacs editorx), or just some text editor. You will end up with something like this:

1 gentoo (0.9.12-1) unstable; urgency=low 2 3 * Initial Release. 4 * This is my first Debian package. 5 * Adjusted the Makefile to fix $DESTDIR problems. 6 7 -- Josip Rodin <jrodin@jagor.srce.hr> Wed, 11 Nov 1998 21:02:14 +0100 8 9 Local variables: 10 mode: debian-changelog 11 End: (I've added the line numbers.)

When you release a new version, you must increment the version number. You can do that with `dch -v <version>-<revision>` and then insert the comments using your preferred editor. Tip: how to easily get the date in required format? Use the `822-date` command, or `date -R`.

New version information is added at the top of the changelog file. This is what the changelog looks like afterwards:

1 gentoo (0.9.12-2) unstable; urgency=low 2 3 * Fixed a glitch in the menu file. 4 5 -- Josip Rodin <jrodin@jagor.srce.hr> Wed, 11 Nov 1998 22:15:39 +0100 6 7 gentoo (0.9.12-1) unstable; urgency=low 8 9 * Initial Release. 10 * This is my first Debian package. 11 * Adjusted the Makefile to fix $DESTDIR problems. 12 13 -- Josip Rodin <jrodin@jagor.srce.hr> Wed, 11 Nov 1998 21:02:14 +0100 14 15 Local variables: 16 mode: debian-changelog 17 End: (I've added the line numbers.) conffiles

One of the most annoying things about software is when you spend a great deal of time and effort customizing a program only to have an upgrade stomp all over your changes. Debian solves this problem by marking configuration files so that when you upgrade a package you will be prompted whether you want to keep your old configuration or not. You do this by entering the full path to each configuration file (they are usually in /etc,) one per line, in a file called conffiles.

Gentoo has one conffile, /etc/gentoorc, and we'll enter that in the `conffiles' file. It is not actually neccessary to have that file, if your program has no configuration files. dirs

This file specifies the directories which we need but normal installation procedure (make install) somehow doesn't create. By default, it looks like this:

usr/bin usr/sbin

Note that the preceding slash is not included. We would have normally changed it to look like this:

usr/X11R6/bin usr/X11R6/man/man1 but those directories are already created in the Makefile, so we won't need this file, and we may delete it. manpage.1.ex

The files ending in *.ex are examples of how to add that kind of support into the package. To use one of them, edit it and remove the .ex extension. If you don't want to use it, just delete it.

Your program should have a man page. If it doesn't, this is a skeleton you can fill out. See the man pages for for a brief description of how to create a man page. Be sure to rename this file to the name of the program and make the extension the manual section it should go into. Here's a short list:

Section | Description | Notes 1 User commands Executable commands or scripts. 2 System calls Functions provided by the kernel. 3 Library calls Functions within system libraries. 4 Special files Usually found in /dev 5 File formats E.g. /etc/passwd's format 6 Games Or other frivolous programs 7 Macro packages Such as man macros. 8 System administration Programs typically only run by root. 9 Kernel routines Non-standard calls and internals.

So gentoo's manpage should be called gentoo.1, or gentoo.1x because it is an X11 program. There was no gentoo.1 man page in the original source so I wrote it using information from the example and from upstream docs. menu.ex

X Window System users usually have a window manager with a menu that can be customized to launch programs. If they have installed the Debian "menu" package, a set of menus for every program on the system will be created for them. It isn't required by the Debian Policy, but users will surely appreciate it. We can add Gentoo to the menus by editing this file. Here's the default that dh_make creates:

?package(gentoo):needs=X11|text|vc|wm section=Apps/see-menu-manual\ title="gentoo" command="/usr/bin/gentoo"

The first field specifies what kind of interface the program needs (e.g. text or X11). The next is the menu and submenu the entry should appear in. The current list of sections is at: /usr/share/doc/debian-policy/menu-policy.html/ch2.html#s2.1 The third field is the name of the program. The fourth is the icon for the program or none if there isn't one. The fifth is the actual text which will appear in the menu. Finnally, the sixth field is the command that runs the program.

Now we'll change the menu entry to this:

?package(gentoo):needs=X11 section=Apps/Misc \ title="Gentoo" command="/usr/X11R6/bin/gentoo"

See , and /usr/share/doc/debian-policy/menu-policy.html/ for more information. watch.ex

You can use this file in addition to the and programs (in the devscripts package) to watch the site you got the original source from. Here's what I put in it:

# watch control file for uscan # Site Directory Pattern Version Script ftp.obsession.se /gentoo gentoo-(.*)\.tar\.gz debian uupdate

Hint: connect to the Internet, and try running "uscan" in the program directory once you create the file. And read the manual pages. postinst.ex, preinst.ex, postrm.ex, prerm.ex

These files are called maintainer scripts, and you should try to avoid maintainer scripts if you possibly can because they tend to get too complex. For more information look in the Packaging Manual, and examine these example files provided by dh_make.

We should now be ready to build the package. Final steps Building the package

Enter the program's main directory (/usr/local/src/gentoo/gentoo-0.9.12/) and then issue this command:

dpkg-buildpackage -rfakeroot

This will do everything for you, you'll just have to enter your PGP secret key, twice. After it's done, you will see four new files in /usr/local/src/gentoo directory:

gentoo_0.9.12-1_i386.deb

This is the completed binary package. You can use dpkg or dselect to install and remove this just like any other package. gentoo_0.9.12.orig.tar.gz

This is the original source code gathered up so that if someone else wants to recreate your package from scratch they can. Or if they aren't using Debian packaging system, but need to download the source and compile. gentoo_0.9.12-1.dsc

This is a summary of the contents of the source code. The file is generated from the gentoo-0.9.12/debian/control file, and is used when unpacking the source with . This file is PGP signed, so that people can be sure that it's really yours. gentoo_0.9.12-1.diff.gz

This compressed file contains each and every addition you made to the original source code, in the form known as "unified diff". It is made and used by . gentoo_0.9.12-1_i386.changes

This file describes all the changes made in the current package revision, and it is used by the Debian FTP archive maintenance programs to install the binary and source packages in it. It is partly generated from the gentoo-0.9.12/debian/changelog file and the .dsc file.

As you keep working on the package, behavior will change and new features will be added. People downloading your package can look at this file and quickly see what has changed. The long strings of numbers are MD5 checksums for the files mentioned. Person downloading your files can test them with and if the numbers don't match, they'll know the file is corrupt or has been hacked. This file is PGP signed, so that people can be even more sure that it's really yours. Checking the package for errors

Run on your .changes file; this program will check for many common packaging errors. The command is:

lintian -i gentoo_0.9.12-1_i386.changes

If it appears that there are some errors (lines beginning with E:), read the explanation (the N: lines), correct mistakes, and rebuild with dpkg-buildpackage. If there are lines that begin with W:, those are only warnings, so you can be pretty much sure that your package is okay (but it sure needs some fine tuning).

Look inside the package using a file manager like , or unpack it in a temporary place using .

Install the package to test it yourself. Try to install it on machines other than your own and watch closely for any warnings or errors on installation and running the program.

Later, when you build a new version, you should do the following to ensure basic upgradability of the package: upgrade from the previous version (and from the version in last Debian release), downgrade back again, install the package as a new package (i.e., with no previous version installed), uninstall it, reinstall it again, and then purge it. Uploading your package

Now that you have tested your new package throughly, you'll need to upload these files to master.debian.org, using . First you have to set up dupload's config file, ~/.dupload.conf . Put something like this in it: package config; $default_host = "master"; $cfg{master}{"method"} = "scpb"; $cfg{master}{"login"} = "joy"; $cfg{master}{"visibleuser"} = "jrodin"; $cfg{master}{"visiblename"} = "jagor.srce.hr"; $cfg{master}{"fullname"} = "Josip Rodin"; $cfg{non-us}{"method"} = "scpb"; $cfg{non-us}{"login"} = "joy"; $cfg{non-us}{"visibleuser"} = "jrodin"; $cfg{non-us}{"visiblename"} = "jagor.srce.hr"; $cfg{non-us}{"fullname"} = "Josip Rodin"; 1;

Of course, change my personal settings to yours, and read the manual page to understand what does each of these options mean.

Then connect to your Internet provider, make sure once again that you are in /usr/local/src/gentoo directory, and issue this command:

dupload --to master gentoo_0.9.12-1_i386.changes

Dupload will ask for your password on master.debian.org, upload the packages, and give a short announcement about your upload on If you live in Europe, you can use some other upload queues instead of master. For details look in , and the Developer's Reference. Where to ask for help

Before you decide to ask your question in some public place, please just RTFM. That includes documentation in /usr/share/doc/dpkg, /usr/share/doc/debian, /usr/share/doc/package/* files and the man/info pages for all the programs mentioned in this article. When you receive a bug report (yes, actual bug reports!), you will know that it is time that you dig in the and read the documentation there, to be able to deal with the reports efficiently.

By joining the Debian Mentors' mailing list at If you still have questions, ask on the Debian Developers' mailing list at Even if it all worked well, it's time to start praying. Why? Because in just a few hours (or days) users from all around the world will start to use your package, and if you made some critical error you'll get mailbombed by numerous angry Debian users... Just kidding. :-)

Relax and be ready for bug reports, because there is a lot more work to be done before it will be fully in line with Debian policies (once again, read the real documentation for details). Good luck!