开发者

What does a typical ./configure do in Linux?

开发者 https://www.devze.com 2022-12-24 03:30 出处:网络
Why is it necessary e开发者_JS百科ven though everything is specified in a makefile?Typically the configure script when run will:

Why is it necessary e开发者_JS百科ven though everything is specified in a makefile?


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.


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".


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消