views:

350

answers:

3

Why is it necessary though everything is specified in a makefile?

+12  A: 

Typically the configure script when run will:

  • Check some details about the machine on which the software is going to be installed. This script checks for lots of dependencies on your system. For the particular software to work properly, it may be requiring a lot of things to be existing on your machine already. If any of the major requirements are missing on your system, the configure script would exit and you cannot proceed with the installation, until you get those required things.

  • Create the Makefile to be used in the next step.

codaddict
Never know makefile was created by configure before:)
Mask
It also provides an interface to configure (aptly) compilation options. `./configure --help` will (usually?) give a list of available options.
intuited
+2  A: 

A configure script builds the Makefile from a template, substituting in things like where you want to install the code and what definitions are needed for the (C, C++, Fortran, ...) compiler that is used to build the program. Theoretically it could all be done in one step, except that there's that many different configurations possible that it's easier to do in stages. (For example, if building a large program with a multi-core machine available, you might want to specify that a certain number of parallel compilations happen, which is not the concern of how things are configured.)

Donal Fellows
+4  A: 

It runs a script which typically produces makefiles and "configure.h".

The script is written in the lanugage "m4" which is a macro language. The top level macros are found in autoconf.ac or (in older systems) autoconf.in. These expand containing lower level macros which in turn expand into actual tests which create small programs or tasks to check what kind of system you have.

For example AC_CHECK_HEADER([myheader.h], ...) might generate a tiny C program like:

#include "myheader.h"
int main(int argc, char** argv) {
  return 0;
}

If the program compiles, the check is considered "passing" otherwise it "fails". The status of such checks often gets reflected in the config.h file. On a passing check, you might find a line in config.h that looks like:

#define HAVE_MYHEADER_H 1

while on a test that fails, it might look like

#define HAVE_MYHEADER_H 0

When configured to work with autoconf in AM_INIT_AUTOMAKE macro, the Makefile can also reference the results of the tests if the variable containing the test result is exported. So if a needed library is located a few different typical locations, or the syntax of "what works" with one of your standard tools (like tar, ar, etc) is different, or the preferred tool is not available. The Makefile will be able to still build the project properly using the different library locations, the different tool syntax, or a different set of tools.

So when dealing with an Autotools project (configure / make / make install) the Makefile really doesn't contain everything necessary to build the project, it's generated from the Makefile.in template to specifically match your system when you type "configure".

Edwin Buck
I noticed these `configure` files are extremely huge,are they written manually?
Mask
No, the configure script is an expansion (also using the m4 language) of directives which are put in the configure.ac (or in older systems configure.in) file. Running autoconf will generate the configure script from configure.ac, but sometimes you need to patch up the macro libraries. When you need to do that, run aclocal and it will try to verify that all the macros are properly defined (and useable for the next autoconf execution).
Edwin Buck
@Edwin Buck: excellent answer!
Lazer
very nice answer
ravi