Compiling software yourself
I don’t always find all software I need in the repositories of my chosen Linux distribution. Sometimes I am lucky and find packages for my distribution on the software’s homepage which I can use immediately. Other times it helps to look in the developer areas of my distribution. Debian, for example, offers the Stable branch, which I normally use for such projects, as well as a branch called Testing and another called Unstable, which may contain the software I am looking for. I often can’t directly use this because programs from the other branches need other libraries not found in the Stable branch. Sometimes it’s sufficient to rebuild these packages on a machine running the Stable branch. Often I need library packages that I have to rebuild as well. For some software packages this has already been done. These can be found at http://backports.debian.org. The advantage here is that I can use the package management from Debian by simply including a few lines in /etc/apt/sources.list.
System or user software
If I want to install software for which there is no support at all in my distribution, I have to manage this software myself. This means that I have to compile, install, and configure it myself. And if I replace it with a newer version, I have to deinstall the old version.
Often there are files called README or INSTALL in the source archives which contain hints on compilation, required libraries and installation. I have a look here first.
Many software packages use the GNU Build System, also known as Autotools,
which facilitates porting to different UNIX environments and checks the
requirements for building it on my computer.
These are recognizable by their executable file configure in the root of the
software package.
I can call up ./configure --help to get hints about further options.
These allow me to switch certain features on or off, or preset some paths
for later installation.
In most cases I am interested in the option --prefix which determines where
the software is installed when I call up make install at the end.
Usually this is preset to /usr/local so that the software doesn’t collide with the distributions package management under that directory. I prefer the directory /usr/local/stow/softwarename-version. This enables me to use the program stow to create symbolic links to the directory under /usr/local so that I can use it with the conventional paths. If I install another version later, this is installed in a totally different directory so that I can switch between these versions within seconds. This also makes removing an older version easier because I only have to remove everything under that corresponding directory. This facilitates the management of self-compiled software tremendously.
As an example the installation of monotone a distributed revision control system, looks like this on my computers:
$ tar xjf monotone-1.0.tar.bz2
$ cd monotone-1.0
$ ./configure --prefix=/usr/local/stow/monotone-1.0
$ make
$ make check
$ sudo make install
$ sudo stow -d /usr/local/stow monotone-1.0
Afterwards I have monotone installed under /usr/local/stow/monotone-1.0 and
there are symbolic links under /usr/local/bin, /usr/local/etc and
/usr/local/share which refer to the files under the previously mentioned
directory.
I can call up mtn directly, the manual page is available using man mtn and
if I ever want to get rid of it, all I have to do is to call up stow with
option -D (and remove everything under /usr/local/stow/monotone-1.0 if I
need the storage).
Creating Debian Packages
There are at least three reasons why I would need to create a Debian software package myself:
- The software I want exists as a Debian package but I need a version or feature which is not contained in the distribution.
- I actually don’t want the software but other software packages depend on it so that the package manager always tries to install this software.
- I want to deploy the software using the Debian package management.
In the first case I can make it easy on myself.
I obtain the latest source packages with apt-get source packagename.
Then I retrieve the version of the pristine software that I need.
Now I can copy the debian directory of the source package to the extracted
pristine source directory.
I take a look at the files under debian and possibly adapt them if
necessary to unlock certain features.
Afterwards I call up debuild -us -uc in the root directory of the source.
With a little luck I obtain the software in the form I need it in.
In the second case I want to have an empty package which complies with the dependencies and manage the software myself under /usr/local as described in the previous section. I can use the tool equivs for this which was designed especially for this purpose.
In the third case I have to learn how to build Debian software packages. First I install the essential software for developing packages:
- build-essential
- This meta package contains a list of packages necessary to develop Debian packages.
- devscripts
- This contains scripts to make the life of a Debian package developer easier.
- debhelper
- This is a collection of programs which can be used in the debian/rules file to automate common tasks in package building.
- puilder or sbuild
- With this software you can build your packages in a chroot environment to avoid certain security problems with unchecked software and to recognise dependencies more easily.
For beginners I recommend the article HowToPackageForDebian in the Debian Wiki (wiki.debian.org).
Kernel and kernel modules
For Debian based systems I can refer to the Debian Linux Kernel Handbook for questions regarding the kernel.
Chapter four, Common kernel related tasks provides help in most cases. In order to compile the kernel or some extra modules myself, I need some developer packages which I can install with apt-get:
- build-essential
- Was already mentioned above.
- kernel-package
- This contains resources for Debian packages covering the Linux kernel. Among other things it contains make-kpkg, which helps build a kernel package that can be installed with dpkg.
- module-assistant
- This helps compile external kernel modules which are already prepared for Debian (like for instance openafs-modules-source).
Compiling the kernel
First I install the necessary developer packages:
$ sudo apt-get install build-essential
$ sudo apt-get install kernel-package
Next I obtain the kernel sources. I either use a suitable Debian package linux-source-$version or I take the sources from www.kernel.org and extract them under /usr/src.
Afterwards I create a symbolic link from /usr/src/linux to the extracted kernel source directory and configure the kernel. For this I can take the configuration of a running kernel as a starting point:
$ sudo ln -s linux-<version> /usr/src/linux
$ cd /usr/src/linux
$ cp /boot/config-<version> .config
$ make oldconfig
$ make menuconfig
$ make-kpkg clean
$ make-kpkg --rootcmd fakeroot kernel_image \
--revision <rev> --initrd
I can install the newly built kernel package with dpkg.
Compiling kernel modules
For some modules, which aren’t in the Debian kernel and not in the kernel from www.kernel.org, there are prepared package whose name usually ends in -source (for instance squashfs-source with Debian 5 or openswan-modules-source with Debian 6). I can install these packages and then compile the modules using module-assistant:
$ sudo apt-get install module-assistant
$ sudo apt-get install openswan-modules-source
$ sudo m-a build openswan-modules
$ sudo dpkg -i /usr/src/openswan-modules-$version.deb
$ sudo modprobe ipsec
Details can be found on the manual pages.
Software for OpenWrt
I don’t have to go out of my way to compile software for OpenWrt on ALIX devices. Because the computer works with X86 CPU I don’t need a cross compiler. I only have to take the installed libraries into account and, if necessary recompile my program with these libraries.
OpenWrt’s documentation wiki is the first place to look for answers to questions regarding self-compiled software. If I don’t find an answer there, I can search for an answer in the Forum or pose the question myself.