Packaging From Scratch
[Important]
Requirements: build-essential, automake, gnupg, lintian, fakeroot and pbuilder.
In this example we will be using the GNU hello program as our example. You can download the source tarball from ftp.gnu.org. For the purposes of this example, we will be using the ~/hello/ directory.
mkdir ~/hello cd ~/hello wget http://ftp.gnu.org/gnu/hello/hello-2.1.1.tar.gz
We will also compare our package to one that is already packaged in the Ubuntu repository. For now, we will place it in the ubuntu directory so we can look at it later. To get the source package, make sure you have a "deb-src" line in your /etc/apt/sources.list file for the Main repository. Then, simply execute:
mkdir ubuntu cd ubuntu apt-get source hello cd ..
[Note]
Unlike most apt-get commands, you do not need to have root privileges to get the source package, because it is downloaded to the current directory. In fact, it is recommended that you only use apt-get source as a regular user, because then you can edit files in the source package without needing root privileges.
What the apt-get source command does is:
-
Download the source package. A source package commonly contains a .dsc file describing the package and giving md5sums for the source package, an .orig.tar.gz file containing the source code from the author(s), and a .diff.gz file containing patches applied against the source code with the packaging information.
-
Untar the .orig.tar.gz file into the current directory.
-
Apply the gunzipped .diff.gz to the unpacked source directory.
If you manually download the source package (.dsc, .orig.tar.gz, and .diff.gz files), you can unpack them in the same way apt-get source does by using dpkg-source as follows:
dpkg-source -x *.dsc
The first thing you will need to do is make a copy of the original (sometimes called "upstream") tarball in the following format: <packagename>_<version>.orig.tar.gz. This step does two things. First, it creates two copies of the source code. If you accidentally change or delete the working copy you can use the one you downloaded. Second, it is considered poor packaging practice to change the original source tarball unless absolutely necessary. See the section called "Common Mistakes" for reasons.
cp hello-2.1.1.tar.gz hello_2.1.1.orig.tar.gz tar -xzvf hello_2.1.1.orig.tar.gz
[Warning]
The underscore, "_", between the package name (hello) and the version (2.1.1), as opposed to a hyphen, "-", is very important. Your source package will incorrectly be built as a Debian native package.
We now have a hello-2.1.1 directory containing the source files. Now we need to create the customary debian directory
* License

