Wednesday, February 2, 2011

How To Create .DEB Package

To create a .deb package, firstly make sure you have all the dependencies required for compiling the package. Basically, try to compile it first and if once you can do that, it means everything is installed properly and you can create the .deb package.

1. Install all the packages needed for creating a .deb package:


sudo apt-get install build-essential autoconf automake autotools-dev dh-make debhelper devscripts fakeroot xutils lintian pbuilder


2. Folder and source preparations:

Extract the archive for the application you want to create the .deb file and name the folder

like this : packagename-packageversion
NOTE 1:

The folder name must be lowercase.

. NOTE 2 :

You should start packaging with a completely clean source directory, or simply with freshly unpacked sources.
NOTE 3 :

Then, place the source package .tar.gz file one directory up fromwhere the source files have been extracte


If you don't have the source files .tar.gz archive, simply create an archive from your source files (if for instance you downloaded the packages using Git)


3. Begin the “Debianization”:

I will use the ABC.01 files in my example, for easier explanations. To begin the "debianization", run the following commands:

root@boss[~]#cd ABC.01

root@boss[~]# dh_make -e youremail@address -f . ./ABC.01.tar.gz


Where ABC.01 is the source files folder of the application you want to create the .deb package of, ABC.01.tar.gz is the tar.gz archive of the original source files and youremail@address is your email address.



This should be displayed after running the above command:

Type of package: single binary, indep binary, multiple binary, library,kernel module, kernel patch or cdbs?
[s/i/m/l/k/n/b]


We'll not get into complicated things right now, so select "s" (single binary). Then hit "Enter" to confirm.


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.


4.The "control" file:

Probably the most important step is how you edit the control file. This file contains various values which dpkg, dselect and other package management tools will use to manage the package.

This file will be created after completing step 3, and you can find it in the "debian" folder in the directory containing your source files. It initially looks like this:


1 Source: x264
2 Section: unknown
3 Priority: extra
4 Maintainer: andrei
5 Build-Depends: debhelper (>= 7), autotools-dev
6 Standards-Version: 3.8.1
7 Homepage:
8
9 Package: x264
10 Architecture: any
11 Depends: ${shlibs:Depends}, ${misc:Depends}
12 Description:



For now, enter a hompage (line 7) and a description (line 12) for your package and also a section, such as "X11", on line 2.


Now, a very important step: we must enter the build dependencies on line 5, To find out which files our package needs, run the following command:


root@boss[~]# dpkg-depcheck -d ./configure

At the bottom, the output of this command should be something like this:

Packages needed:
libc6-i686
libldap-2.4-2
libsasl2-2
libtasn1-3
yasm
libgpg-error0
libgcrypt11
libkeyutils1
libidn11
libgnutls26
libk5crypto3
locales
libcurl3-gnutls
libkrb5support0
libkrb5-3
libgssapi-krb5-2
gawk


Enter all these packages on the line 5 of your control file, separated by a comma and a space. Don't remove the already existing packages on line 5!

Here is how my control file now looks like:

Source: ABC.01
Section: X11
Priority: extra
Maintainer: sai
Build-Depends: debhelper (>= 7), autotools-dev, libc6-i686, libldap-2.4-2, libsasl2-2, libtasn1-3, yasm, libgpg-error0, libgcrypt11, libkeyutils1, 1libidn11, libgnutls26, libk5crypto3, locales, libcurl3-gnutls, libkrb5support0, libkrb5-3, libgssapi-krb5-2, gawk
Standards-Version: 3.8.1
Homepage: http://www.videolan.org/developers/x264.html

Package: ABC.01
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: ABC.01 is a free library for encoding H264/AVC video streams.

5.The "copyright" file:

In the same "debian" folder, you will also find a "copyright" file which you need to edit. The important things to add to this file are the place you got the package from and the actual copyright notice and license.

You must include the complete license, unless it's one of the common free software licenses such as GNU GPL or LGPL, BSD or the Artistic license, when you can just refer to the appropriate file in /usr/share/common-licenses/ directory that exists on every Debian system.

6.The "changelog" file:

Also in the same "debian" folder, this file is very important, especially for signing your .deb file with your GPG key


NOTE : The name of the maintainer in the changelog file must be exactly the same as the one entered for the GPG key, so edit it and enter your name. Here is how mine looks like:

ABC.01 unstable; urgency=low * Initial release (Closes: #nnnn) -- sai Thu, 09 Dec 2010 22:40:24 +0200


If you enter the wrong name, you will see something like this:

dpkg-deb: building package `ABC.01 in `../ABC.01.deb'. signfile x264-0.1+svn20100107-1.dsc gpg: skipped "sai ": secret key not available gpg: [stdin]: clearsign failed: secret key not available

7. Building the actual .deb package:

Run the following command:

root@boss[~]# dpkg-buildpackage -rfakeroot
dpkg-depcheck -d ./configure

If you successfully completed step 6, you should be asked for your GPG passkey. Enter it and proceed. The .deb file should be now created in your home file, along with the .dsc, .changes, .diff.gz and .orig.tar.gz files.


8. Optional: Check your new .deb package using lintian:

Run the following command:

root@boss[~]# lintian -Ivi ../yourpackage.changes

No comments:

Post a Comment