Download programs as sources and build them using the Terminal

Nov 9, 2009 17:01 GMT  ·  By

People usually end up running applications on their Mac that do not need any more fiddling than double clicking on their executable. However, sometimes you encounter a so-called source package that will give any newcomer nightmares for a very long time. Once you open the program’s source code folder and you see those meaninglessly named files that you do not seem to find any use for, your life will definitely change.

For some of us, that meant that we just had to learn what to do with those kinds of packages. If you have downloaded a program source package and you did not know what to do with it (and you still do not), then this article will allow you to go through building your first program from the ground up with the help of the Terminal.

This article will not try to improve on your skills or show you how to use any advanced tools for building a redistributable binary. All it tries to do is give a start point to people that have no other experience in building programs and I think this article could be as better as any other place.

First of all, you will have to make sure you have on your Mac the tools necessary to go through each step. On a Mac, you can find all those tools in the Apple Xcode toolkit that you can get from HERE.

After downloading the archive containing the source for your program and unpacking it, you will have to open a Terminal window (you can find the Terminal app in the /Applications/Utilities/ folder). Afterwards, you will have to go to the folder containing your program’s unpacked source code.

If you use the desktop to download things, then the unpacked source code should also be right there and you can go there in the Terminal by running the following commands (we now assume that your program is named “foobar” and its version is xyz):

cd ~/Desktop/foobar-xxx

When you are inside the source code directory, you almost near the end of the process because now you will run three commands in the Terminal and, if everything is OK with the program’s source and it finds all the needed libraries on your system, you are done. The three magic commands are (you must use them in this exact order):

./configure make make install

The first command will automatically run a number of diagnostic tests on your Mac, to make sure that your machine has everything the software needs to install. When the configuration process has ended, the make tool will compile the software. The last command will put all the files you need to run the compiled program in the exact places they belong on your Mac.

You have built your first program using its source code and the dreaded Terminal. To be able to run it, you just have to write its name at the command prompt, in this case Foobar2000, and hit ENTER.

Now, let us go over a few special cases. These are not the usual type of source code distributable programs mainly because they do not respect the building steps I presented you above. For each of these three cases (the most important ones you may find) there is a specific building process, similar to the default one but with a twist or even using different commands to achieve the same purpose through the same process.

Python

Python-based programs are perhaps some of the easiest to build out there. They can be easily spotted because you will always find, while looking through the files in their source code, a setup.py file. Once you know what they are, you will need to run only one command in the program’s source code folder:

python setup.py install

That’s all there is to it and, after this one easy step, you can start using the program.

Ruby

Ruby programs are another type of program that can easily be built, also with a single command. The Ruby programs are distributed as gem files and, if you encounter such a file, open a Terminal, go to the gem’s folder and run the following command:

gem install foobar

Perl

You can recognize Perl programs distributed as source code after the signature files that have a “pl” extension. Perl programs, contrary to usual source code programs, can be used without compiling. All you need to do if you encounter such a program is to open a Terminal window and run the following command from the command prompt (in the source code folder):

perl foobar.pl

Conclusion

Once you have successfully built your first program, you may try to also improve your newly acquired knowledge and try your skills on other source code distributed tools. While trying to build them, you may encounter all kinds of errors or the above steps will not work the right away.

All you have to remember is that you should always read the README and INSTALL files you can find in the source code folder right before beginning the building process. This should be done because, most of the time, those two files come with important instructions and additions to the building process specific to that program.

Also, if you don’t seem to manage building it without getting into the same errors as before, even after trying out all the developer wrote in the README and INSTALL files, you should copy the error message and search for it on the internet. This might help you find other people that had the same problems and, maybe, a solution to solve them.

If you have questions and/or pieces of advice for people that may want to build programs from source and do not know (yet) how, use the comments section below.