While many free software projects like to follow the mantra of ‘release often’, not all do. This can mean that you miss out on new features, especially when it comes to cutting-edge software.
The VLC or Handbrake media utilities, for example, are in such a rapid state of development that development versions almost always offer more features and stability improvements than an official release. If you’re looking for tools that support the latest hardware, you’re either left waiting for some kind soul to make an unofficial release, or faced with braving the source code of the project yourself.
But grabbing the source code and building your own version doesn’t need to be as intimidating as it might sound. For certain projects, the process is simple and straightforward, and it can give you unprecedented access to the very latest development branch. What’s even more impressive is that you can update the project to the latest code with just a couple of commands, always giving you the most recent version of any software you’re interested in.
It’s these kinds of projects – and VLC in particular – that we’re going to tackle here to help demystify the whole process. You’ll then be able to grab, compile, install and use the very latest versions, and then follow the same instructions for your favourite software. We’re going to grab the cutting-edge 1.2 version of VLC (the official version is still stuck at 1.1.8) and show you how to build and run it.
But before we dive in, here’s a brief overview of what the process entails. We need to download the latest copy of the source code for our chosen project. Most projects these days host their code on a Git or Subversion repository, both of which are used to track changes and contributors. We’ll need to use a version control client to copy the source code from the server to your local folder.
After this, we’ll need to make sure we’ve got all the dependencies the project requires, before going through the trinity of configuring, compiling and installing the software from the source code.

Dependencies
Just like packages you install through a package manager, projects you build from source code need to have their dependencies met and installed. It’s not quite the same process, but it’s for the same reasons – most projects rely on external libraries and projects for functionality.
On an Ubuntu system, the first of these is the ‘build-essential’ meta-package, which will need to be installed through your package manager or command line before you do anything else. This installs a basic development environment onto your system so that you can make executable binaries out of the source code. But it won’t install all the libraries a project may depend upon.
The project that we’re going to install also has dependencies, and satisfying those is often the most challenging part of building your own application. If you want to do this manually, you need to find which packages the application depends upon, usually from the documentation for the project, then search for and install these through your package manager.
It can often be hit and miss because there’s no standard for these package names and which versions might be included within a distribution. VLC, for example, requires dozens of libraries, from the Qt framework to all the various codecs it needs to make sense of your media files.
There is an easier solution, especially if Ubuntu includes packages for an older version of the tool you want to install. This is because the package manager already knows which other packages it needs when you install VLC, and you can ask it to install only the development versions of those packages, which in turn can be used when building your cutting edge download. This can save a lot of effort, trial (or compile) and error.
To install the packages used to build VLC, type apt-get build-dep vlc and you should see that packages like ‘qt4-dev’ are installed, along with dozens of codecs.

Get the source code
Now that the various dependencies are installed, it’s time to grab the source code. Most projects will use either a Subversion or Git repository, as these are two of the most popular version control servers used by teams of developers working together. Each tool has a different implementation and set of commands, but they do a similar job. You’ll first need to install them from your distribution’s package manager by looking for the ‘git’ and ‘subversion’ packages, after which they can both be run from the command line.
Which tool you use will depend on how your project is hosted. VLC, for example, uses Git. Which means you can download the very latest version by typing git clone git://git.videolan.org/vlc.git. All this is doing is creating a clone – a local copy – of the source tree held on the VLC server, and it’s from that copy that we’ll build the final release.
There’s no standard to the location of Git servers and the URL you need to use to access them. This is something you need to find from a project’s documentation or developer mailing list. If the project uses Subversion, rather than Git, then the command to use is svn co, followed by the URL for the project.
As with Git, the location is something you need to get from the developers themselves, because it isn’t something you can usually guess. In the command, ‘co’ represents ‘check out’, which is what Git and Subversion assume you’re doing when you download the source code. The end result from both commands is a copy of the developer source tree on your local system, and we need to enter this folder for the next step.

Prepare the code
This is the hard part, because it’s where we prepare the source code to be built on your system. It’s necessary because every setup is different, with different hardware, libraries and even operating systems.
Many free software projects are cross-platform, and it’s the configuration part that sets up the build procedure for your system. It’s difficult, because there are so many ways to do it, especially when you’ve downloaded the source code from a version control system.
If you’re uncertain, the only way to discover how to build something is to either look for a ‘README’ or ‘README.Linux’ text file in the source tree, or try the project’s online resources. There are some common methods, and the one used by most Linux projects is the trinity of build commands: ‘./configure’, ‘make’ and ‘make install’.
As you might be able to tell from the syntax of these commands, the first one, ‘./configure’, runs a script in a project’s root folder – ‘./’ means a script in the current directory, and if ‘configure’ exists, you should be able to build the project as long as your installation has all the dependencies. If not, the output from ‘configure’ should give some indication of what’s missing.
If ‘configure’ is missing, you might want to try running the automake command to generate it. If you don’t have this command available, install the ‘autoconf’ package first. If this doesn’t work, it’s likely that there’s a project-specific procedure to follow, and that’s exactly the case with VLC.
Before the ‘configure’ script is generated, you need to run a script dubbed ‘bootstrap’. It exists because VLC is a complicated beast to build. It’s cross-platform and has many more dependencies than the average project. It tries to discover what it can about your system before generating the normal ‘configure’ script.
This script can be run by typing ./bootstrap from the main source directory – you should see it highlighted in green if you type ls. The script will run for a few minutes and complain if anything important is missing. The result should be a ‘success’ message.

Configure options
You should now have the ‘configure’ script in the top directory of the VLC source code. This is another script that sets up the environment for building. The difference is that it takes user input, so the final binary version of VLC will be built to your specification. Many other projects use exactly the same process, and you’ll soon find that running the ‘configure’ script becomes second nature as you build more tools from source.
Unlike most, the VLC configure script takes dozens of options, and you have to enable many of these to build a media player that will play anything. You can see the options available by typing ./configure –help. The online developer documentation includes more information on what each addition provides.
Here’s the ‘configure’ command we used to build our version:
./configure –enable-xvideo
–enable-sdl –enable-avcodec
–enable-avformat –enable-swscale
–enable-mad –enable-a52
–enable-libmpeg2 –enable-dvdnav
–enable-faad –enable-vorbis
–enable-ogg –enable-theora
–enable-mkv –enable-freetype
–enable-flac –enable-caca
–enable-alsa –enable-qt4
As you can see, we’re going to use the Qt4-based interface, and we’ve included support for the ogg, theora and vorbis codecs, plus the ‘mkv’ and ‘avi’ containers. There are plenty of other options, but we’ve found that this set gives a flexible final binary that will play most media. Like the bootstrap script, ‘configure’ will take a few minutes and complain if you’re asking it to include a library that’s not on your system.

Building the binary
With the success of the ‘configure’ script, we can finally build the VLC application. If you run the configure script with any other project, this step will be identical. You just have to type make.
This will initiate the build process using the series of Makefile documents created by the ‘configure’ script, and these will go through the process of compiling the source code in the correct order, and linking to the components and libraries used by the project.
As a result, it can take some time. Building VLC on a dual-core 2.33GHz Intel CPU took about 25 minutes with the above configuration, with the size of the project being the biggest factor in determining how long the build process takes. A recent version of the kernel, for instance, could easily take a couple of hours.
You’ll see the ‘make’ process enter each of the VLC directories, compiling the source and moving back up the folder hierarchy. Unless you see any errors, you’ll have a new VLC binary waiting to be used. Typing ls will reveal the green ‘vlc’ executable, and as with the ‘configure’ script, you can run this from the current directory by typing ./vlc. The latest version of VLC should appear, and you’ll be able to enjoy the new features weeks or even months before the official release brings the same updates to lesser mortals.
This feature is taken from PC Plus Issue 309 – on sale now. To view the expanded feature, as well as more fantastic articles, tutorials and reviews, click here to buy the digital version of PC Plus issue 309 now. You can also subscribe to PC Plus or buy PC Plus Magazine back issues.
Leave a Reply
You must be logged in to post a comment.