首页 > 代码库 > Configure,Makefile.am, Makefile.in, Makefile文件之间关系

Configure,Makefile.am, Makefile.in, Makefile文件之间关系

技术分享

 

1.autoscan (autoconf): 扫描源代码以搜寻普通的可移植性问题,比如检查编译器,库,头文件等,生成文件configure.scan,它是configure.ac的一个雏形。

    your source files --> [autoscan*] --> [configure.scan] --> configure.ac

2.aclocal (automake):根据已经安装的宏,用户定义宏和acinclude.m4文件中的宏将configure.ac文件所需要的宏集中定义到文件 aclocal.m4中。aclocal是一个perl 脚本程序,它的定义是:“aclocal - create aclocal.m4 by scanning configure.ac”
user input files   optional input     process          output files
================ ============== ======= ============

acinclude.m4 - - - - -.
V
.-------,
configure.ac ------------------------>|aclocal|
{user macro files} ->| |------> aclocal.m4
`-------‘
3.autoheader(autoconf): 根据configure.ac中的某些宏,比如cpp宏定义,运行m4,声称config.h.in

user input files optional input process output files
================ ============== ======= ============

aclocal.m4 - - - - - - - .
|
V
.----------,
configure.ac ----------------------->|autoheader|----> autoconfig.h.in
`----------‘

4.automake: automake将Makefile.am中定义的结构建立Makefile.in,然后configure脚本将生成的Makefile.in文件转换 为Makefile。如果在configure.ac中定义了一些特殊的宏,比如AC_PROG_LIBTOOL,它会调用libtoolize,否则它 会自己产生config.guess和config.sub

user input files   optional input   processes          output files
================ ============== ========= ============

.--------,
| | - - -> COPYING
| | - - -> INSTALL
| |------> install-sh
| |------> missing
|automake|------> mkinstalldirs
configure.ac ----------------------->| |
Makefile.am ----------------------->| |------> Makefile.in
| |------> stamp-h.in
.---+ | - - -> config.guess
| | | - - -> config.sub
| `------+-‘
| | - - - -> config.guess
|libtoolize| - - - -> config.sub
| |--------> ltmain.sh
| |--------> ltconfig
`----------‘

5.autoconf:将configure.ac中的宏展开,生成configure脚本。这个过程可能要用到aclocal.m4中定义的宏。

user input files   optional input   processes          output files
================ ============== ========= ============

aclocal.m4 ,autoconfig.h.in - - - - - - -.
V
.--------,
configure.ac ----------------------->|autoconf|------> configure
 
6. ./configure的过程

.-------------> [config.cache]
configure* --------------------------+-------------> config.log
|
[config.h.in] -. v .--> [autoconfig.h]
+-------> config.status* -+
Makefile.in ---‘ `--> Makefile
 
7. make过程
 
[autoconfig.h] -.
+--> make* ---> 程序
Makefile ---‘
 
.---------,
config.site - - ->| |
config.cache - - ->|configure| - - -> config.cache
| +-,
`-+-------‘ |
| |----> config.status
config.h.in ------->|config- |----> config.h
Makefile.in ------->| .status|----> Makefile
| |----> stamp-h
| +--,
.-+ | |
| `------+--‘ |
ltmain.sh ------->|ltconfig|-------> libtool
| | |
`-+------‘ |
|config.guess|
| config.sub |
`------------‘

 

.--------,
Makefile ------>| |
config.h ------>| make |
{project sources} ---------------->| |--------> {project targets}
.-+ +--,
| `--------‘ |
| libtool |
| missing |
| install-sh |
|mkinstalldirs|
`-------------‘

实例:
在/hello/目录下创建一个hello.c文件,并编译运行它:

#cd /hello/

(1) 编写源文件hello.c:

#include<stdio.h> 
int main(int argc, char** argv)
{
printf("Hello, GNU!n");
return 0;
}

[wss@localhost hello]$ls
hello.c

 

[wss@localhost hello]$autoscan
[wss@localhost hello]$ls
autoscan.log configure.scan hello.c

已经生成了configure.scan,autoscan.log文件

将configure.scan 修改为 configure.ac,最后修改的内容如下:

# -*- Autoconf -*-
2 # Process this file with autoconf to produce a configure script.
3
4 AC_PREREQ(2.69)
5 AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
6 AC_CONFIG_SRCDIR([hello.c])
7 #AC_CONFIG_HEADERS(config.h)
8 AM_INIT_AUTOMAKE(hello, 1.0)
9 # Checks for programs.
10 AC_PROG_CC
11
12
13 # Checks for libraries.
14
15 # Checks for header files.
16
17 # Checks for typedefs, structures, and compiler characteristics.
18
19 # Checks for library functions.
20
21 AC_OUTPUT(Makefile)

 

[wss@localhost hello]$aclocal
[wss@localhost hello]$ls
aclocal.m4 autom4te.cache autoscan.log configure.ac hello.c

生成 aclocal.m4 和 autom4te.cache (生成aclocal.m4的过程中涉及到configure.in)

 

[wss@localhost hello]$autoconf
[wss@localhost hello]$ls
aclocal.m4 autom4te.cache autoscan.log configure configure.ac hello.c

生成 configure (根据 configure.in, 和 aclocal.m4)

 

编写Makefile.am:

AUTOMAKE_OPTIONS= foreign
bin_PROGRAMS= hello
hello_SOURCES= hello.c

 

[wss@localhost hello]$ automake --add-missing
configure.ac:7: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated. For more info, see:
configure.ac:7: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
Makefile.am: installing ‘./depcomp‘
[wss@localhost hello]$ls
aclocal.m4 autoscan.log configure depcomp install-sh Makefile.in
autom4te.cache compile configure.ac hello.c Makefile.am missing

automake生成 Makefile.in, depcomp, install-sh, 和 missing (根据 Makefile.am, 和 aclocal.m4)

 

[wss@localhost hello]$./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands
[wss@localhost hello]$

[wss@localhost hello]$ls
aclocal.m4 autoscan.log config.log configure depcomp install-sh Makefile.am missing
autom4te.cache compile config.status configure.ac hello.c Makefile Makefile.in
[wss@localhost hello]$

 

[wss@localhost hello]$make
gcc -DPACKAGE_NAME=\"FULL-PACKAGE-NAME\" -DPACKAGE_TARNAME=\"full-package-name\" -DPACKAGE_VERSION=\"VERSION\" -DPACKAGE_STRING=\"FULL-PACKAGE-NAME\ VERSION\" -DPACKAGE_BUGREPORT=\"BUG-REPORT-ADDRESS\" -DPACKAGE_URL=\"\" -DPACKAGE=\"hello\" -DVERSION=\"1.0\" -I. -g -O2 -MT hello.o -MD -MP -MF .deps/hello.Tpo -c -o hello.o hello.c
mv -f .deps/hello.Tpo .deps/hello.Po
gcc -g -O2 -o hello hello.o
[wss@localhost hello]$ls
aclocal.m4 autoscan.log config.log configure depcomp hello.c install-sh Makefile.am missing
autom4te.cache compile config.status configure.ac hello hello.o Makefile Makefile.in

 

http://123.59.135.138/projects/user-admin

Configure,Makefile.am, Makefile.in, Makefile文件之间关系