Wednesday, 23 May 2012
 Home arrow Blog arrow HowTo Build a Package from Source the Smart Way
   
Main Menu
Home
News
Blog
Links
Search
FAQs
Spider
Articles
@intrenet
Free Softwares
Break for fun
Friends VIdeos
Techno videos
Contact Us
Disclaimer
Guest Book
Speed test
V.E.C. Calculator
IPv4 Subnet Calc
IPv6 Subnet Calc
Byte Converter
Converter
GMT/UTC Time
Bandwidth Calc
Allinone Calc
IANA Port Numbers
Country Call Codes
Pk Postal Codes
Surf Anonumously
Visitors Counter
mod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_counter
mod_vvisit_counterToday215
mod_vvisit_counterYesterday260
mod_vvisit_counterThis week475
mod_vvisit_counterThis month5024
mod_vvisit_counterAll125700
 
 
 
 


HowTo Build a Package from Source the Smart Way PDF Print E-mail
User Rating: / 0
PoorBest 
Written by Amanatullah khalil   
Monday, 25 May 2009

HowTo Build a Package from Source the Smart Way

 

HowTo Build a Package from Source the Smart Way

Postby Soul Singin' » 2009-05-10 03:26

.
This HowTo is a response to the unlimited supply of terrible advice that I have seen on GNU/Linux forums, on blogs and in various and sundry corners of the internet.

In particular, I wish people would stop advising others to use the make install routine. It's just as easy -- if not easier -- to build a DEB. Building a DEB gives you all of the advantages of package management, whereas the make install routine does not.

So this HowTo will describe several different ways that you can build a DEB package. Then -- for those of you who insist on using the make install routine -- it will explain how to use make install safely.

==================================================================

Before we begin compiling however, let's review a few compilation basics.

First, you should have a reason for compiling package. There are many valid reasons why you might want to compile a package. The most common reason is to install a more recent version in Debian Stable. If that's your reason, then take a look around to see if someone has already built a DEB package for you (e.g. Backports). You'll save yourself a lot of trouble that way.

Another reason is to compile in support for a particular feature. For example, Debian's most recent version of Gnash uses FFmpeg as its sound handler, but I compiled the same version of Gnash with GStreamer as the sound handler.

In the end, it doesn't matter what your reason is. Just make sure you have one and make sure it's a good one.

Second, if you're using Debian, then you'd be well-advised to use Debian-ized source instead of upstream source because it's very easy to build a DEB package if you're using Debianized-source.

If you build and install a DEB, then APT will be aware of the presence of the package and it will make sure that you do not overwrite the files of a previously installed package. By contrast, the make install command will overwrite anything that gets in its way.

==================================================================

Building a DEB is very easy to do and it's a shame that the members of this forum do not advocate it. If you've never built a DEB before, then try building Backintime. It only takes a minute or two, so it's a great exercise.

In general, building a DEB from Debian-ized source is a simple four-step process.
  1. First, you add a "source line" to your /etc/apt/sources.list file and install the build dependencies.
  2. Then you download the source (as normal user).
  3. Then you run dpkg-buildpackage to build the DEB.
  4. Finally, you install the DEB(s) with dpkg -i

To be more specific, add the following line to your /etc/apt/sources.list file:
Code: Select all
deb-src http://ftp.us.debian.org/debian/ sid main

Then run install the build dependencies:
Code: Select all
apt-get update
apt-get install fakeroot
apt-get build-dep <packagename>

Those are the last commands you should run as root before installing the DEB. All of the build commands should be run as normal user.

Next, create a directory for the build in your normal user's home directory, download the source into that directory and build the DEB:
Code: Select all
mkdir /home/XXXX/my_build/
cd /home/XXXX/my_build/
apt-get source <packagename>
cd <packagename>-<version>/
dpkg-buildpackage -rfakeroot -us -uc

That last command may take a minute or an hour or three hours. It all depends on the size of the package and your own hardware.

Once the dpkg-buildpackage command finishes, you'll find the DEB(s) in your /home/XXXX/my_build/ directory and you can install them (as root) with:
Code: Select all
cd /home/XXXX/my_build/
dpkg -i <packagename>_<version>_<architecture>.deb


It doesn't get much simpler than that.

Perhaps more importantly, a Debian Developer would follow a very similar procedure to create a backport from a package that's already in Testing or Unstable.

==================================================================

If you're really eager to compile and there is no Debian-ized source in Unstable or Testing, you can still build a DEB package by using dh-make.
Code: Select all
apt-get install fakeroot dh-make

In general, you begin by installing the build dependencies. If you're building a more recent version of package that's already in Debian, then the build-dependencies might be the same as the previous version. Otherwise, you'll have to figure out what they are (by reading the source package's documentation, for example).

Next, you extract the source into a directory in your home directory as normal user:
Code: Select all
mkdir /home/XXXX/my_build/
cd /home/XXXX/my_build/
tar -zxf <packagename>_<version>.tar.gz

Then enter the <packagename>_<version>/ directory and run dh_make.
Code: Select all
cd <packagename>_<version>/
dh_make --createorig

dh_make will then ask you if you want to create a: "single binary, multiple binary, library, kernel module or cdbs" and ask you to complete the package maintainer fields.

You might then have to tweak the debian/rules file (e.g. to set configuration options) or set a shell variable. It all depends on the package in question.

Once you have done that (or accepted all of the defaults), then the next step is to run (as normal user):
Code: Select all
dpkg-buildpackage

and then install the DEB package (as root) with:
Code: Select all
dpkg -i <packagename>_<version>_<architecture>.deb

For a good example of how to use dh-make, see: HowTo Compile PDFedit.

==================================================================

Debian-ized source should be your first choice when building from source. Use dh-make when Debian-ized source is unavailable because it Debian-izes the source for you.

If for some reason Debian-ized source is not available and dh-make doesn't work, then your third choice should be to use checkinstall.
Code: Select all
apt-get install checkinstall

Checkinstall is not as good as the first two options, but at least it produces a DEB, so it will prevent you from unknowingly overwriting system files and it will make APT aware of the package's presence.

In general, using checkinstall is very similar to the make install routine. The only difference is that you don't run the make install command.

First, you pick an installation directory. It's a good idea to pick a directory where no other packages are installed or will be installed. For example, /opt/ or /usr/local/ are two good choices, but because checkinstall will build a DEB, APT will make sure that you don't overwrite any files even if you choose /usr/ (or if you let the defaults choose /usr/ for you).

Suppose you pick /usr/local/. The next step is to pass that choice to the configure script. For example:
Code: Select all
./configure --prefix=/usr/local --<configuration-options>

Then you would run:
Code: Select all
make
su -c checkinstall -D make install

The trouble with checkinstall is that it does not Debian-ize the source or understand package dependencies. It simply keeps track of the files that the DEB contains.

It also annoys me that the files are installed at the same time that the package is built. (That's why you have to become root to use the checkinstall command). I wish it would just build the DEB and then let me decide when I want to install it.

Nonetheless, it does produce a DEB, so the package can be easily removed and won't overwrite other files without first obtaining your permission. Just remember to chown it back to your normal user:
Code: Select all
chown XXXX:XXXX <packagename>_<version>_<architecture>.deb

==================================================================

If an RPM is available, you might want to look into alien.
Code: Select all
apt-get install fakeroot alien

It's just as bad as checkinstall (because it doesn't understand package dependencies), but it's not much worse and -- most importantly -- it produces a DEB.

To use it, you simply download the RPM and run as normal user:
Code: Select all
fakeroot alien -d <packagename>-<version>.<architecture>.rpm

and then become root to install the DEB that alien produces.
Code: Select all
dpkg -i <packagename>_<version>_<architecture>.deb

==================================================================

Finally, there's the make install routine. make install should be your absolute last resort. You should NEVER use it unless all other options have failed and you should ONLY use it IF the package you want to build is of mission critical importance.

The make install routine is the most primitive method of building a package from source and has absolutely no concept of dependencies or package management. There's a reason why GNU/Linux distributions use package managers like APT or RPM. And that reason is to get as far away from make install as possible.

So if you're going to use make install, then at least use it intelligently. Do NOT blindly follow the lemmings running off the cliffs of the internet.

As with checkinstall, the most important thing to do is to pick an installation directory where no other packages are installed or will be installed. Once again, /opt/ and /usr/local/ are two good choices.

As with checkinstall, the next step is to pass that choice to the configure script. Suppose (again) that you pick /usr/local/. You would pass that chouce to the configure script with the --prefix flag:
Code: Select all
./configure --prefix=/usr/local --<configuration-options>

That will cause the files to be installed in your /usr/local/ directory, which Debian doesn't install to by default. This should ensure that you don't overwrite important system files when you run make install.

The next steps are to build the package and install it:
Code: Select all
make
su -c make install

But that's not the end of the story. If you want to uninstall a package that you installed with the make install routine, then you had better make sure you don't accidentally delete that package that you compiled (even if it grows to 20 GB) and you had better hope that the its make uninstall routine works just as well as its installation routine or you'll be stuck manually deleting all of the files.

That's why you should ALWAYS build a DEB package. Let APT remember where the installed files are. You've got better things to do ... like play with your newly installed package!

==================================================================

In summary:
  • It's easier to create DEBs from Debianized source than it is to use the make install routine.
  • When Debianized source is unavailable, use a helper application to build a DEB, so that you can take advantage of APT's package management features.
  • If you are unable to build a DEB package, then stop and ask yourself if you really need the package you're trying to build.
  • You should ONLY use the make install routine as a LAST RESORT for MISSION CRITICAL applications.
  • If you do use the make install routine, do it intelligently.

Good Luck and Have Fun!,

In general, it's probably better to just rename the tarball to:

package_version.orig.tar.gz

and then run dh_make, than to try to make dh_make figure it out with --create-orig.

Nice guide! The number of atrocious recommendations on installing packages is absurd.
courtesy to writer and responder and http://forums.debian.net/viewtopic.php?f=16&t=38976
 
< Prev   Next >
 
 
 
csatpk Newsflash
Statistics
OS: Linux h
PHP: 5.2.17
MySQL: 5.1.63-community-log
Time: 04:21
Caching: Disabled
GZIP: Disabled
Members: 3
News: 368
Web Links: 5
Visitors: 266084
Popular