Tuesday, April 26, 2016

[Quick tips: UBUNTU 16.04]: Create a .deb file from Source in Ubuntu 16.04

Create a .deb file from Source in Ubuntu 16.04

Create a deb file from Source 

 

Create a .deb file from Source

Ubuntu has tens of thousands of .deb files in the official and unofficial repositories. But, all packages will not be available in DEB format. Some times, packages might be available only for RPM based distros, or Arch based distros. In such cases, it’s important to know how to create a .deb file from source file.
In this brief tutorial, let us see how to create a .deb file from Source file in Ubuntu 16.04 LTS. This guide should work on all DEB based systems such as Debian, Linux Mint, and Elementary OS etc.
First, we need to install the required dependencies to compile and create DEB file from source file.
To do so, run:
sudo apt-get install checkinstall build-essential automake autoconf libtool pkg-config libcurl4-openssl-dev intltool libxml2-dev libgtk2.0-dev libnotify-dev libglib2.0-dev libevent-dev
Sample output:
 Reading package lists... Done
 Building dependency tree
 Reading state information... Done
 build-essential is already the newest version (12.1ubuntu2).
 build-essential set to manually installed.
 pkg-config is already the newest version (0.29-2ubuntu2).
 pkg-config set to manually installed.
 The following additional packages will be installed:
 autotools-dev debhelper dh-strip-nondeterminism gir1.2-gtk-2.0 icu-devtools libatk1.0-dev libcairo-script-interpreter2 libcairo2-dev libevent-core-2.0-5
 libevent-extra-2.0-5 libevent-openssl-2.0-5 libevent-pthreads-2.0-5 libexpat1-dev libfile-stripnondeterminism-perl libfontconfig1-dev libfreetype6-dev
 libgdk-pixbuf2.0-dev libharfbuzz-dev libharfbuzz-gobject0 libice-dev libicu-dev libltdl-dev libmail-sendmail-perl libpango1.0-dev libpcre3-dev libpcre32-3
 libpcrecpp0v5 libpixman-1-dev libpng12-dev libpthread-stubs0-dev libsigsegv2 libsm-dev libsys-hostname-long-perl libx11-dev libx11-doc libxau-dev libxcb-render0-dev
 libxcb-shm0-dev libxcb1-dev libxcomposite-dev libxcursor-dev libxdamage-dev libxdmcp-dev libxext-dev libxfixes-dev libxft-dev libxi-dev libxinerama-dev
 libxml2-utils libxrandr-dev libxrender-dev m4 po-debconf x11proto-composite-dev x11proto-core-dev x11proto-damage-dev x11proto-fixes-dev x11proto-input-dev
 x11proto-kb-dev x11proto-randr-dev x11proto-render-dev x11proto-xext-dev x11proto-xinerama-dev xorg-sgml-doctools xtrans-dev zlib1g-dev
 Suggested packages:
 autoconf-archive gnu-standards autoconf-doc dh-make libcairo2-doc libcurl4-doc libcurl3-dbg libidn11-dev libkrb5-dev libldap2-dev librtmp-dev libssl-dev
 libglib2.0-doc libgtk2.0-doc libice-doc icu-doc libtool-doc libpango1.0-doc libsm-doc gfortran | fortran95-compiler gcj-jdk libxcb-doc libxext-doc libmail-box-perl
 The following NEW packages will be installed:
 autoconf automake autotools-dev checkinstall debhelper dh-strip-nondeterminism gir1.2-gtk-2.0 icu-devtools intltool libatk1.0-dev libcairo-script-interpreter2
 libcairo2-dev libcurl4-openssl-dev libevent-core-2.0-5 libevent-dev libevent-extra-2.0-5 libevent-openssl-2.0-5 libevent-pthreads-2.0-5 libexpat1-dev
 libfile-stripnondeterminism-perl libfontconfig1-dev libfreetype6-dev libgdk-pixbuf2.0-dev libglib2.0-dev libgtk2.0-dev libharfbuzz-dev libharfbuzz-gobject0
 libice-dev libicu-dev libltdl-dev libmail-sendmail-perl libnotify-dev libpango1.0-dev libpcre3-dev libpcre32-3 libpcrecpp0v5 libpixman-1-dev libpng12-dev
 libpthread-stubs0-dev libsigsegv2 libsm-dev libsys-hostname-long-perl libtool libx11-dev libx11-doc libxau-dev libxcb-render0-dev libxcb-shm0-dev libxcb1-dev
 libxcomposite-dev libxcursor-dev libxdamage-dev libxdmcp-dev libxext-dev libxfixes-dev libxft-dev libxi-dev libxinerama-dev libxml2-dev libxml2-utils libxrandr-dev
 libxrender-dev m4 po-debconf x11proto-composite-dev x11proto-core-dev x11proto-damage-dev x11proto-fixes-dev x11proto-input-dev x11proto-kb-dev x11proto-randr-dev
 x11proto-render-dev x11proto-xext-dev x11proto-xinerama-dev xorg-sgml-doctools xtrans-dev zlib1g-dev
 0 upgraded, 77 newly installed, 0 to remove and 0 not upgraded.
 Need to get 24.8 MB of archives.
 After this operation, 128 MB of additional disk space will be used.
 Do you want to continue? [Y/n] y
ostechnix@ostechnix: ~_002
We have installed the required dependencies. Let us go ahead and download the source file of a package.

Downloading source tarballs

For the purpose of this tutorial, let us create .deb file for Leafpad source file. As you know already, Leafpad is the simple, graphical text editor.
Go to the Leafpad home page and download the tar file.
wget http://tarot.freeshell.org/leafpad/leafpad-0.8.17le2.tar.bz2
Then, extract the downloaded tar file as shown below.
tar xvjf leafpad-0.8.17le2.tar.bz2
Then, go to the extracted folder, and run the following commands one by one to compile the source code:
cd leafpad-0.8.17le2/
./configure
Note: In case ./configure command is not found, skip it and continue with next command.
make
Finally, run the following commands to create .deb file from source code.
sudo checkinstall
Sample output:
Type Y when asked to create the description for the Deb file.
 checkinstall 1.6.2, Copyright 2009 Felipe Eduardo Sanchez Diaz Duran
 This software is released under the GNU GPL.
 The package documentation directory ./doc-pak does not exist.
 Should I create a default set of package docs? [y]: y
ostechnix@ostechnix: ~-leafpad-0.8.17_003
Next type the description for the DEB file, and press ENTER double time to continue.
 Preparing package documentation...OK

 Please write a description for the package.
 End your description with an empty line or EOF.
 >> This Leafpad DEB file has been created from source code
 >> EOF
ostechnix@ostechnix: ~-leafpad-0.8.17_004
In the next screen, you will see the details of source file that you are going to create a DEB file from it. The DEB package will be built according to these details.
Review the details, and change them as your wish.
 *****************************************
 **** Debian package creation selected ***
 *****************************************

This package will be built according to these values:

 0 - Maintainer: [ root@ostechnix ]
 1 - Summary: [ This Leafpad DEB file has been created from source code ]
 2 - Name: [ leafpad ]
 3 - Version: [ 0.8.17 ]
 4 - Release: [ 1 ]
 5 - License: [ GPL ]
 6 - Group: [ checkinstall ]
 7 - Architecture: [ amd64 ]
 8 - Source location: [ leafpad-0.8.17 ]
 9 - Alternate source location: [ ]
 10 - Requires: [ ]
 11 - Provides: [ leafpad ]
 12 - Conflicts: [ ]
 13 - Replaces: [ ]
ostechnix@ostechnix: ~-leafpad-0.8.17_006
For example, I want to change the maintainer Email id. To do so, press number “0”. Type the maintainer email, and press ENTER key.
ostechnix@ostechnix: ~-leafpad-0.8.17_007
 Enter a number to change any of them or press ENTER to continue: 0
 Enter the maintainer's name and e-mail address:
 >> sk@ostechnix.com
Finally, press Enter if you ok with details.
The .deb Package has been built successfully, and installed automatically.
**********************************************************************

Done. The new package has been installed and saved to 
/home/ostechnix/leafpad-0.8.17/leafpad_0.8.17-1_amd64.deb

You can remove it from your system anytime using:

dpkg -r leafpad

**********************************************************************
ostechnix@ostechnix: ~-leafpad-0.8.17_008
The .deb will be saved in the directory where you extracted the source file.
Let us view the contents of the source directory:
ls
Sample output:
ABOUT-NLS config.sub intltool-extract missing
aclocal.m4 configure intltool-extract.in mkinstalldirs
AUTHORS configure.ac intltool-merge NEWS
ChangeLog COPYING intltool-merge.in po
compile data intltool-update README
config.guess depcomp intltool-update.in src
config.h description-pak leafpad_0.8.17-1_amd64.deb stamp-h1
config.h.in doc-pak Makefile
config.log INSTALL Makefile.am
config.status install-sh Makefile.in
ostechnix@ostechnix:~/leafpad-0.8.17$
As you can see in the above output, the deb file has been successfully created and saved in the source directory itself.
You can also remove the installed deb package as shown below.
sudo dpkg -r leafpad
I have tested these guide with Leafpad and 7zip source files. It worked like a charm as I described above.

No comments: