How do we install packages from source? This is what many of us chant everyday.
./configure make make install
Have you ever wondered how people wrote thousand of lines of configuration scripts? Actually these scripts are not written by hand in most cases, but generated by a suite called “autotools” from GNU Build System. You can read more about it here:
TL; DR: You don’t write those scripts. You generate them by using
configure.ac + Makefile.am + source code ⇶ autoconf + automake ⇶ ready-to-distribute source package
We start with the source code of an application. Let’s call it main.c
To compile this application using GCC, we do
gcc main.c -o uberapp
This will compile the application and produce a binary file called uberapp. This works for small projects but when they grow bigger, we need to look into make files, which automates the build process for us so we can just type “make” and it will do the rest.
Trouble is when we compile our applications on different platforms, we need to adjust our make files to make sure that they still work. That’s why we need “configure” scripts. They check current environment and adjust configuration to adapt the source code accordingly.
Make files and configure scripts can be very complicated, but most projects are similar. They have some source files, that need to be compiled into some binary files. In order to do that, we need to check if required build tools or some libraries are available, et cetera. GNU has developed a process to build their products so end users can just type out the command
./configure && make && make install
to install anything. The process of writing configure and make scripts can be automated too. Configure scripts can be generated using autoconf and Makefile can be generated using automake.
In general, we need configure.ac and Makefile.am to generate build script. Your uberapp project directory should look like this
With these three files main.c, configure.ac, Makefile.am in the same project directory, we call
to generate configure script and
to generate Makefile (If you see error message, when calling automake, try to use automake –add-missing instead). From here we know what to do 🙂
Bonus #1: Use –prefix with configure script to install an application some where else (e.g. your home directory).
./configure --prefix ~/tmp/local make && make install ls ~/tmp/local
That’s it. Have a nice day.