views:

66

answers:

5

Why does every source package that uses a makefile come with a ./configure script, what does it do? As far as I can tell, it actually generates the makefile?

Is there anything that can't be done in the makefile?

+1  A: 

The configure step is a sort of meta build. It generates the makefile that will work on the specific hardware / distribution you're running. For instance it determines the name of the C or C++ compiler and embeds that in the makefile.

The configure step will also frequently take a set of parameters, the values of which may determine what libraries need to be linked against. For instance if you compile Apache HTTP with SSL enabled it needs to link against more shared libraries than if you don't. Since linking is handled by the makefile, you need an extra step to create a custom makefile (rather than requiring the make command to require dozens or hundreds of options.

Jherico
+1  A: 

Everything can be done from within the makefile but some build systems were implemented otherwise.

I don't personally use configure files for my projects but I admit I mostly export Erlang & Python based projects.

jldupont
+2  A: 

configure is usually a result of the 'autoconf' system. It can generate headers, makefiles, really anything. 'Usually,' since some are hand-crafted.

The reason for these things is to allow source code to be compiled in disparate environments. There are many variations on Unix / Linux, with slightly different system headers and libraries. configure scripts allow code to auto-adapt.

bmargulies
+1  A: 

I don't think of the makefile as a script, I think of it as an input to the make utility.

The configure script (as its name suggests) configures the makefile, including as you say resolving dependencies.

If only from the idea of avoiding self-modifying code, the things in the configure script don't really belong in the makefile.

pavium
+1  A: 

the point is that autoconf autohdr automake form an integrated system the makes cross platform building on unix relatively str8forward. THe docs are really bad and there are lots of horrible gotchas but on the other hand there are a lot of working samples

When I first came across this stuff I thought - "ha I can do that with a nice clean makefile" and proceeded to rework the source that way. Big mistake. Learn to write and edit configure.ac and makefile.am files, you will be happy in the end

To answer your question. Configure is good for

  • is function foo available on this platform and if so which include and library do I need

  • letting the builder choose if they want feature wizzbang included in a nice simple consistent way

pm100