This simple tutorial would show how to compile source tarballs (*.tar.gz, *.tar.bz2) and create a *.deb installer in Ubuntu.
Pre-requisite
Make sure you have dh_make
and build-essentials
installed in your system. To install those in Ubuntu, run below commands:
sudo apt-get install dh-make sudo apt-get install build-essential
How to create deb file from source packages (e.g tar.gz files)
Follow below steps to compile and create deb file from source package in Ubuntu.
- Create a folder which can be used to keep the source files and other files. You can have it named anything you want. For this tutorial I have named it as “testbox” and kept it in Desktop. Also I will use the source of a software called “qgifer-0.2.1”, this software is used to create gif files from video files. I have downloaded the qgifer-0.2.1-source source files from SF.
- Keep your source file (i.e. the compressed tar file) inside testbox folder. Extract the compressed source files.
- You can keep the extracted folder name as it is OR you can change it. For this tutorial I will change the folder name from
qgifer-0.2.1-source
toqgifer-0.2.1
. While renaming the source directory make sure to follow rules: only use lower case letters, numbers, plus, dot and minus characters. - Delete the source tar file. We don’t need it anymore.
- At this stage, your test directory should look like this.
- Change any path to destination in source files or in the *.desktop file. E.g. for below desktop file, possible changes you may want to is the “Categories” and “Icons”.
- After all change is done, compress the entire source folder to a tar.gz file type. Then copy the tar.gz file inside the source folder. Then delete the tar.gz file outside of the source folder.
- Open terminal and go inside the source folder and run below command to create the basic “debian” directory structure with default values.
Setup test directory
Creation of a deb file requires “debian” directory and all the necessary minimum contents of it inside the source directory. Also the source directory should contain the launcher i.e. *.desktop file to make entries in menu and including icon. Typically all the source tarballs comes with these files and sometimes the debian directory and its contents as well.
Configure debian directory
dh_make -e hello@mail.com -c gpl3 -f qgifer-0.2.1.tar.gz
Note: You can put down your actual valid email address.
The above command will ask for certain values:
Type of package: Choose s for single binary
Now we need to edit the contents of the created ‘debian’ directory just been created. While compiling a source package, everything depends on the contents of this directory. So it is very important to update the contents as per your needs. Debian packaging is a complex process and has many options to customize a compilation based on user needs. This tutorial would try to keep is as simple as possible to have the concept in place.
Before change
qgifer (0.2.1-1) unstable; urgency=low * Initial release (Closes: #nnnn)-- arindam Thu, 11 Feb 2016 22:37:44 +0530
After change
qgifer (0.2.1-1) vivid; urgency=low * Initial release (Closes: #1234) <1234 is the bug number of your ITP> -- arindamThu, 11 Feb 2016 22:37:44 +0530
Source: qgifer Section: Graphics Priority: optional Maintainer: arindamBuild-Depends: debhelper (>= 9), libopencv-dev (>= 2.3), libgif-dev (>=4.1), libqt4-dev (>= 4.8.0), cmake (>= 2.6) Standards-Version: 3.9.4 Homepage: #Vcs-Git: git://git.debian.org/collab-maint/qgifer.git #Vcs-Browser: http://git.debian.org/?p=collab-maint/qgifer.git;a=summary Package: qgifer Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Description: A video-based animated GIF creator Creates GIF from a video file.
Note: Check the readme files of the source package for dependencies needed for the package. Make sure to install all the dependencies in the your system where you are compiling the source before you proceed further.
#!/usr/bin/make -f # -*- makefile -*- # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 %: dh $@
Note: For sample rule files, go to /usr/share/doc/debhelper/examples
.
dpkg-source: info: using source format `3.0 (quilt)' dpkg-source: info: building qgifer using existing ./qgifer_0.2.1.orig.tar.gz dpkg-source: error: cannot represent change to qgifer-0.2.1.tar.gz: binary file contents changed dpkg-source: error: add qgifer-0.2.1.tar.gz in debian/source/include-binaries if you want to store the modified binary in the debian tarball dpkg-source: error: unrepresentable changes to source dpkg-buildpackage: error: dpkg-source -b qgifer-0.2.1 gave error exit status 2
Compile
fakeroot dpkg-buildpackage -F
dpkg-buildpackage
command will take some time to compile the source depending on how big your project is. Once the command is complete, go one level up from the source folder where you can see bunch of files have been created including the *.deb file for your package. You can now double-click to install the deb file in your system.We bring the latest tech, software news and stuff that matters. Stay in touch via Telegram, Twitter, YouTube, and Facebook and never miss an update!
