views:

682

answers:

5

Recently, I switched my development environment to LINUX from Windows. I have only used Visual Studio so far for C++ development. So many concepts like make, autotools are new to me. I have read GNU makefile documentation and got almost an idea about it. But I am kinda confused about autotools.

AFAIK, makefiles are used to make the build process easier. Here are my questions.

  1. Why we need tools like autotools just for creating the makefiles? Since all knows the how to create a makefile, I am not getting the real use of autotools.
  2. What is the standard? Do we need to use tools like this or just handwritten makefiles would do?

Any help would be great!

+1  A: 

Do you know what unix your users will be using? Or even which distribution of Linux? Do you know where they want software installed? Do you know what tools they have, what architecture they want to compile on, how many CPUs they have, how much RAM and disk might be available to them?

The *nix world is a cross-platform landscape, and your build and install tools need to deal with that.


Mind you, the auto* tools date from an earlier epoch, and there are many valid complaints about them, but the several projects to replace them with more modern alternatives are having trouble developing a lot of momentum.

Lots of things are like that in the *nix world.

dmckee
+2  A: 

Autotools are needed because Makefiles are not guaranteed to work the same across different platforms. If you handwrite a Makefile, and it works on your machine, there is a good chance that it won't on mine.

Zifre
+1  A: 

For small projects or even for large projects that only run on one platform, handwritten makefiles are the way to go.

Where autotools really shine is when you are compiling for different platforms that require different options. Autotools is frequently the brains behind the typical

./configure

make

make install

compilation and install steps for Linux libraries and applications.

That said, I find autotools to be a pain and I've been looking for a better system. Lately I've been using bjam, but that also has its drawbacks. Good luck finding what works for you.

Dan Hook
+25  A: 

You are talking about two separate, but intertwined things here:

  • Autotools
  • GNU coding standards

Within autotools, you have several projects:

  • Autoconf
  • Automake
  • Libtool

Lets look at each one individually.

Autoconf

Easily scan an existing tree to find its dependencies and create a configure script that will run under almost any kind of shell. The configure script allows the user to control the build behavior (i.e. --with-foo / --without-foo / --prefix / --sysconfdir / etc ..), as well as does checks to ensure that the system can compile the program.

Configure generates a config.h (from a template) which programs can include to work around portability issues. I.e., if HAVE_LIBPTHREAD is not defined, use forks instead.

I personally use autoconf on many projects. It usually takes people some time to get used to m4, however it does save time.

You can have makefiles inherit some of the values that configure finds without using automake.

Automake

By providing a short template that describes what programs will be built and what objects need to be linked to build them, Makefiles that adhere to GNU coding standards can automatically be created. This includes dependency handling and all of the required GNU targets.

Some people find this easier, I prefer to write my own makefiles.

Libtool

Libtool is a very cool tool for simplifying the building and installation of shared libraries on any Unix like system. Sometimes I use it, other times (especially when just building static link objects) I do it by hand.

There are other options too, see this question.

In short, you really should use some kind of portable build configuration system if you release your code to the masses. What you use is up to you. GNU software is known to build and run on almost anything, however you might not need to adhere to such (and sometimes extremely pedantic) standards.

If anything, I'd recommend giving autoconf a try if you're writing software for POSIX systems. If you need documentation and how-to links, update your question.

Edit

Don't fear m4 :) There is always the autoconf macro archive. Plenty of examples, or drop in checks .. write your own or use what's tested. Autoconf is far too often confused with Automake, they are two separate things.

Tim Post
+1: well reasoned and very detailled
David Schmitt
+1, though libtools is the spawn of the devil. Personally, I'm starting to use cmake for some of my projects, but it's hard to beat the flexibility of autotools.
janneb
@janneb: Yes, but with flexibility comes complexity. I just wish there was an easier starting point for the newbie.
Martin York
+1, nice clear summary. I've been too scared to use autotools thus far but that may change in time.
j_random_hacker
@j_random_hacker, don't fear m4 .. once you get used to it, its far easier than writing your own scripts. Yeah, I know, stuff that looks like LISP makes people shudder, but its not LISP.To help you, here are your father's parenthesis:(((((((((((((((((()))))))))))))))))
Tim Post
There is also the http://autoconf-archive.cryp.to/ autoconf macro archive :)
Tim Post
Thanks tinkertim, I will use the parentheses wisely :)
j_random_hacker
@janneb libtool is the way it is because building shared libraries on some systems is REALLY perverse, and without libtool it gets almost impossible to support those systems since they require lots of extra hoop jumping that Linux does not... and Windows can require you to do some extra hoop jumping to get working shared libs, especially if you care about people using VC++ rather than mingw. So yes libtool exists for a good reason. The other thing it handles is things like position independent code, and shared vs static (sometimes you need to build with different options)
Spudd86
+15  A: 

First of all, the AutoTools are not an opaque build system but a loosely coupled tool-chain, as tinkertim already pointed out. Let me just add some thoughts on Autoconf and Automake:

Autoconf is the configuration system that creates the configure script based on feature checks that are supposed to work on all kinds of platforms. A lot of system knowledge has gone into its M4 macro database during the 15 years of its existence. On the one hand, I think the latter is the main reason AutoTools have not been replaced by something else yet. On the other hand, Autoconf used to be far more important when the target platforms were more heterogeneous and Linux, AIX, HPUX, Sun OS, ..., and a large variety of different processor architecture had to be supported. I don't really see its point if you only want to support recent Linux distributions and Intel-compatible processors.

Automake is an abstraction layer for GNU Make and acts as a Makefile generator from simpler templates. A number of projects eventually got rid of the Automake abstraction and reverted to writing Makefiles manually because you lose control over your Makefiles and you might not need all the canned build targets that obfuscate your Makefile.

Now to the alternatives (and I strongly suggest an alternative to Autotools based on your requirements):

CMake's most notable achievement is replacing AutoTools in KDE. It's probably the closest you can get if you want to have Autoconf-like functionality without M4 idiosyncrasies. It brings Windows support to the table and has proven to be applicable in large projects. My beef with CMake is that it is still a Makefile-generator (at least on Linux) with all its immanent problems (e.g. Makefile debugging, timestamp signatures, implicit dependency order).

SCons is a Make replacement written in Python. It uses Python scripts as build control files allowing very sophisticated techniques. Unfortunately, its configuration system is not on par with Autoconf. SCons is often used for in-house development when adaptation to specific requirements is more important than following conventions.

If you really want to stick with AutoTools, I strongly suggest to read Recursive Make Considered Harmful and write your own GNU Makefile configured through Autoconf.

Pankrat
Autoconf has many more uses than just trivial checks, for instance, quickly find out if struct foo in foo/foo.h has a member named 'bar', the version of libfoo, etc. Plus, the build time options really help when making .deb / .rpm packages. But, yeah, its a matter of preference I suppose.
Tim Post
+1 for useful info. I'd give you another +1 for mentioning "Recursive Make Considered Harmful" if I could -- this has to be one of the most underappreciated documents in IT.
j_random_hacker
@tinkertim: You're right, but that doesn't set Autoconf apart in contrast to other build systems. The examples you've given can be easily implemented in SConf (SCons' configuration sub-system). However, all the sanity checks and things I would not even think of checking come for free in Autoconf.
Pankrat