==================================================================
changelog
2009 September 11
- append "~bpo50+1" to the DEB's version number, to preserve the upgrade path.
- (Thanks to julian67 for the debchange suggestion).
- when using dh-make, rename the tarball to: <package>_<version>.orig.tar.gz
- (Thanks to infinitycircuit for this suggestion).
- added some checkinstall tips.
- (Thanks to acimmarusti for this suggestion).
- original post
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.
- First, you add a "source line" to your /etc/apt/sources.list file and install the build dependencies.
- Then you download the source (as normal user).
- Then you run dpkg-buildpackage to build the DEB.
- Finally, you install the DEB(s) with dpkg -i
Code: Select all
deb-src http://ftp.us.debian.org/debian/ sid main
Code: Select all
apt-get update
apt-get install fakeroot
apt-get build-dep <packagename>
Next, create a directory for the build in your normal user's home directory and download the source into that directory:
Code: Select all
mkdir /home/XXXX/my_build/
cd /home/XXXX/my_build/
apt-get source <packagename>
cd <packagename>-<version>/
For example, I recently backported version 0.8.3a-1 of wxMaxima to Debian Lenny, so at this point, I ran:
Code: Select all
debchange -b -v 0.8.3a-1~bpo50+1
Code: Select all
debchange warning: new version (0.8.3a-1~bpo50+1) is less than
the current version number (0.8.3a-1).
Next, build the DEB:
Code: Select all
dpkg-buildpackage -rfakeroot -us -uc
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
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
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
Code: Select all
mv wxMaxima-0.8.3a/ wxmaxima-0.8.3a/
mv wxMaxima-0.8.3a.tar.gz wxmaxima_0.8.3a.orig.tar.gz
Code: Select all
cd <packagename>_<version>/
dh_make
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
Code: Select all
dpkg -i <packagename>_<version>_<architecture>.deb
==================================================================
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
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>
Code: Select all
make
su -c checkinstall -D make install
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
Code: Select all
su -c 'checkinstall -D --install=no'
While updating this HowTo, I tried his suggestion (with wxMaxima 0.8.3a) by running:
Code: Select all
./configure --prefix=/opt
make
su -c 'checkinstall -D --install=no'
Specifically, checkinstall installed the /opt/ directory's files, but did not install the /usr/share/doc/wxmaxima/ directory's files.
==================================================================
If an RPM is available, you might want to look into alien.
Code: Select all
apt-get install fakeroot alien
To use it, you simply download the RPM and run as normal user:
Code: Select all
fakeroot alien -d <packagename>-<version>.<architecture>.rpm
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>
The next steps are to build the package and install it:
Code: Select all
make
su -c make install
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.
Soul Singin'
.