In a recent post thomaswy asked about maintaining makefiles for larger projects. It is certainly true that manually updating lists of dependencies for many (hundreds… thousands even, the Linux kernel is comprised of some 22,000 source files) can become tedious. Luckily there are tools that will generate Makefiles for you, though really their motivation is to automate the build process on a wide variety of machines and platforms. If you’ve used Qt for development you have probably been using the ‘qmake’ command. This is generate a ‘Makefile’ that is then read with a subsequent call to ‘make’. For more general projects GNU provides Autoconf and Automake. Along with a couple other programs these are referred to as the GNU Autotools. If you ever need to install a piece of GNU software from source (if a package isn’t available for your distribution, for instance) chances are it will use Autotools and you will build it with two commands:
$ ./configure $ make
The first command will generate the Makefile that is then used when you run `make`. In the process of generating the Makefile, `configure` will check your system for necessary libraries and tools and notify you if something needed is missing. This is also where you would specify optional build parameters. To get a list of options run
$ ./configure --help
If you decide you do want to make your project available to the open source community, it’s a good idea to set up the build process using GNU Autotools since folks will be expecting it.
Another option is cmake, which provides similar functionality to GNU Autotools and in addition has the capability to generate project files for a number of IDEs. A quick google search will turn up several commentaries on the merits of the two build systems (and probably several others).
If you do find yourself writing several Makefiles for larger projects (and even if you don’t), be sure to familiarize yourself with the issues raised in the now well-known paper Recursive Make Considered Harmful by Peter Miller.