This article wants to be an introduction to creating .deb packages, meaning I will not get into more advanced procedures like creating a menu entry, custom configuration, explaining the rules file and so on because this how-to would have ~20 pages or so. Instead, I will make a small how-to with the default steps you need to complete and for any customization, simply consult the links at the end of this post. Also, this how-to presumes the package you are trying to create a .deb file has a "Makefile".
Why other methods of creating a .deb package fail:
Please note that in some parts of this how-to, an example is required and I have chosen to create a x264 .deb package and will use it as an example in some of the steps provided below.
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.
Let's get started!
Why other methods of creating a .deb package fail:
checkinstall will not link to the dependencies, meaning the .deb package will only work on the computer it was created on!
Ubucompilator does not add the necessary Build-Depends to the Debian control file so yes, the .deb package can be created with Ubucompilator, but you cannot use the source code to say Launchpad so it can be build for different architectures, etc. Also, the packages are not signed and so on, so that's not the proper way of creating a .deb file
Please note that in some parts of this how-to, an example is required and I have chosen to create a x264 .deb package and will use it as an example in some of the steps provided below.
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.
Let's get started!
1. Install all the packages needed for creating a .deb package
2. Folder and source preparations
Extract the archive for the application you want to create the .deb file and name the folder like this:
Important: the folder name must be lowercase!
For instance, if compiling x264 from SVN, name the folder like this:
(I've also added the date when I've downloaded the package from SVN - 2 days ago)
Important: You should start packaging with a completely clean (pristine) source directory, or simply with freshly unpacked sources.
Then, place the source package .tar.gz file one directory up from where the source files have been extracted.
Example: if you want to compile X264, you can place the "x264-0.1+svn20100107" folder containing the source files in your home folder (/home/yourusername/x264-0.1+svn20100107) and the .tar.gz file also in your home folder, meaning it shouldn't be in the x264_0.1+svn20100107 folder. Hope you understood what I'm trying to say =)
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 x264 files in my example, for easier explanations. To begin the "debianization", run the following commands:
Where x264-0.1+svn20100107 is the source files folder of the application you want to create the .deb package of, x264-0.1+svn20100107.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:
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:
I have numbered the lines for easier explanations. I won't explain what's already obvious though.
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:
At the bottom, the output of this command should be something like this:
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:
Then, save the file.
You can of course further modify this file, and enter what packages it replaces, suggests and so on, but I'll post a link at the end of this post for all that because, like I said, my guide will be a very basic one.
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. If you do not have a GPG key, see THIS HOW-TO.
Very important: 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:
If you enter the wrong name, you will see something like this:
7. Building the actual .deb package
Run the following command:
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:
In the case of my x264 example:
In case you want to see a step-by-step screencast, here it is:
(some steps are missing, but you should get an idea on what you need to do; also I misspelled my name so I get a signing error at the end, but I was too lazy to re-record the screencast)
For further customizing your .deb packages, see:
The Debian New Maintainers' Guide - the .deb packages creation Bible
Creating a .deb package from a python setup.py - some further explanations of the files in the debian folder, as well as instructions for creating a .deb package for a setup.py file.
Debian Policy Manual
Debian Developer's Reference
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
Important: the folder name must be lowercase!
For instance, if compiling x264 from SVN, name the folder like this:
x264-0.1+svn20100107
(I've also added the date when I've downloaded the package from SVN - 2 days ago)
Important: You should start packaging with a completely clean (pristine) source directory, or simply with freshly unpacked sources.
Then, place the source package .tar.gz file one directory up from where the source files have been extracted.
Example: if you want to compile X264, you can place the "x264-0.1+svn20100107" folder containing the source files in your home folder (/home/yourusername/x264-0.1+svn20100107) and the .tar.gz file also in your home folder, meaning it shouldn't be in the x264_0.1+svn20100107 folder. Hope you understood what I'm trying to say =)
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 x264 files in my example, for easier explanations. To begin the "debianization", run the following commands:
cd x264-0.1+svn20100107
dh_make -e youremail@address -f ../x264-0.1+svn20100107.tar.gz
Where x264-0.1+svn20100107 is the source files folder of the application you want to create the .deb package of, x264-0.1+svn20100107.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 <webupd8@gmail.com>
5 Build-Depends: debhelper (>= 7), autotools-dev
6 Standards-Version: 3.8.1
7 Homepage: <insert the upstream URL, if relevant>
8
9 Package: x264
10 Architecture: any
11 Depends: ${shlibs:Depends}, ${misc:Depends}
12 Description: <insert up to 60 chars description>
<insert long description, indented with spaces>
I have numbered the lines for easier explanations. I won't explain what's already obvious though.
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:
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: x264
Section: X11
Priority: extra
Maintainer: Andrew <webupd8@gmail.com>
Build-Depends: debhelper (>= 7), autotools-dev, 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
Standards-Version: 3.8.1
Homepage: http://www.videolan.org/developers/x264.html
Package: x264
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: x264 is a free library for encoding H264/AVC video streams.
Then, save the file.
You can of course further modify this file, and enter what packages it replaces, suggests and so on, but I'll post a link at the end of this post for all that because, like I said, my guide will be a very basic one.
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. If you do not have a GPG key, see THIS HOW-TO.
Very important: 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:
x264 (0.1+svn20100107-1) unstable; urgency=low
* Initial release (Closes: #nnnn) <nnnn is the bug number of your ITP>
-- andrei <webupd8@gmail.com> Sat, 09 Jan 2010 22:40:24 +0200
If you enter the wrong name, you will see something like this:
dpkg-deb: building package `x264' in `../x264-0.1+svn20100107-1_i386.deb'.
signfile x264-0.1+svn20100107-1.dsc
gpg: skipped "Andrew <webupd8@gmail.com>": secret key not available
gpg: [stdin]: clearsign failed: secret key not available
7. Building the actual .deb package
Run the following command:
dpkg-buildpackage -rfakeroot
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:
lintian -Ivi ../yourpackage.changes
In the case of my x264 example:
lintian -Ivi ../x264_0.1+svn20100107-1_i386.changes
In case you want to see a step-by-step screencast, here it is:
(some steps are missing, but you should get an idea on what you need to do; also I misspelled my name so I get a signing error at the end, but I was too lazy to re-record the screencast)
For further customizing your .deb packages, see:
The Debian New Maintainers' Guide - the .deb packages creation Bible
Creating a .deb package from a python setup.py - some further explanations of the files in the debian folder, as well as instructions for creating a .deb package for a setup.py file.
Debian Policy Manual
Debian Developer's Reference
Tidak ada komentar:
Posting Komentar