Making Software

Compiling Simple Programs

In the open source world, it is easy to compile software from source code. We are going to download the source code for the GNU ed program.

wget http://mirror.us-midwest-1.nexcess.net/gnu/ed/ed-1.16.tar.lz

The download comes in what is called a "tarball". This is the open source world equivalent to a zip file. Decompressing and opening the archive can be a bit tricky on GNU/Linux; the tar command has pretty nasty syntax. We will need an extra utility to decompress this .lz file.

$ sudo apt install lzip
$ lzip -d ed-1.16.tar.lz
$ tar -xfv ed-1.16.tar
$ ls

Now we have a folder with the ed source code inside. Let's change to that directory and see how easy it can be to compile open source software.

$ cd ed-1.16
$ ./configure
$ make
$ ./ed

Notice that we are using a slightly different notation to invoke a couple programs, ./. Since the shell will only look in folders listed in the $PATH variable, if we want to execute a program within the current directory we have to specify that we want to search in the current directory (./).

Dependency Hell

Let's try a more difficult example. This time, we are going to try to compile the git version control system. Unfortunately, we do not have all the necessary dependencies and this will cause the compilation to fail. The repeated failure to build software due to dependencies is affectionately known as dependency hell.

$ cd ~/
$ wget https://www.kernel.org/pub/software/scm/git/git-2.27.0.tar.xz
$ tar xfv git-2.27.0.tar.xz
$ cd git-2.27.0 $ ./configure $ make

Uh oh, hit a snag. The make process says he cannot find a C header file, zlib.h. Let's download and create the zlib library real quick.

$ cd ~/
$ wget https://zlib.net/zlib-1.2.11.tar.xz
$ tar xf zlib-1.2.11.tar.xz
$ cd zlib-1.2.11
$ ./configure
$ make
$ sudo make install

Now we go back to the git source code folder and attempt to build again. One interesting feature of the make build process is that it will only recompile files that have changed since the last compile. We will again hit some snags, but this time we will just use the package manager to install the missing dependencies.

$ cd ~/git-2.27.0
$ make
$ sudo apt install tclsh gettext
$ make
$ ls -l git

We have successfully built the git version control system. Much of open source software has it's source code controlled using git these days. This was just a demonstration of how open source software is packaged and built. Hopefully you also can recognize the usefulness of a package manager! If you want to get your hands dirty building lots of source code, there is a GNU/Linux distro where you can build everything directly from source code: Linux From Scratch.

Last modified: Tuesday, 16 June 2020, 1:47 PM