`
love19820823
  • 浏览: 931429 次
文章分类
社区版块
存档分类
最新评论

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

 
阅读更多

自己:最近搞一个ntpdsim,一直没能生成libntpsim.a,所以一直没有成功生成ntpdsim。

原因是对makefile的理解一直不太深,尤其是对automake之类的应用,没有理解他们之间的相对关系,还一直想自己动手写一个完整的Makefile,但是相对于庞大的工程真是无能为力。偶然看到这篇文章讲解了整个体系,大体是autoscan 、aclocal、autoconf、automake、configure、make的流程。

在我的真是项目中,因为实际在根目录中已经自带了configure, 执行这个configure后,会在各个子目录中生成Makefile,然后到相应子目录中make,先在libntp 中生成libntpsim.a,然后在 ntpd中生成ntpdsim,这样会找到libntpsim.a。

原文章地址:http://hi.baidu.com/litaosmile/blog/item/0c5562139fe5ced9f6039ee3.html


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;
}

[litao@vm0000131 hello]$ ll
total 4
-rw-rw-r-- 1 litao litao 68 Aug 12 12:02 hello.c

一、autoscan

[litao@vm0000131 hello]$ autoscan
autom4te: configure.ac: no such file or directory
autoscan: /usr/bin/autom4te failed with exit status: 1
[litao@vm0000131 hello]$ ll
total 8
-rw-rw-r-- 1 litao litao 0 Aug 12 12:03 autoscan.log
-rw-rw-r-- 1 litao litao 457 Aug 12 12:03 configure.scan
-rw-rw-r-- 1 litao litao 68 Aug 12 12:02 hello.c

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

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

[litao@vm0000131 hello]$ mv configure.scan configure.in
[litao@vm0000131 hello]$ vim configure.in

# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CONFIG_SRCDIR([hello.c])
#AC_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE(hello, 1.0)
# Checks for programs.
AC_PROG_CC

# Checks for libraries.

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.
AC_OUTPUT(Makefile)

二、acloacl

[litao@vm0000131 hello]$ aclocal

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

[litao@vm0000131 hello]$ ll
total 44
-rw-rw-r-- 1 litao litao 31120 Aug 12 12:08 aclocal.m4
drwxr-xr-x 2 litao litao 4096 Aug 12 12:08 autom4te.cache
-rw-rw-r-- 1 litao litao 0 Aug 12 12:03 autoscan.log
-rw-rw-r-- 1 litao litao 496 Aug 12 12:08 configure.in
-rw-rw-r-- 1 litao litao 68 Aug 12 12:02 hello.c

三、antoconf

[litao@vm0000131 hello]$ autoconf
生成 configure (根据 configure.in, 和 aclocal.m4)

[litao@vm0000131 hello]$ ll
total 168
-rw-rw-r-- 1 litao litao 31120 Aug 12 12:08 aclocal.m4
drwxr-xr-x 2 litao litao 4096 Aug 12 12:11 autom4te.cache
-rw-rw-r-- 1 litao litao 0 Aug 12 12:03 autoscan.log
-rwxrwxr-x 1 litao litao 122297 Aug 12 12:11 configure
-rw-rw-r-- 1 litao litao 496 Aug 12 12:08 configure.in
-rw-rw-r-- 1 litao litao 68 Aug 12 12:02 hello.c

四、编写Makefile.am:

AUTOMAKE_OPTIONS= foreign
bin_PROGRAMS= hello
hello_SOURCES= hello.c

五、automake

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

[litao@vm0000131 hello]$ automake
configure.in: required file `./install-sh' not found
configure.in: required file `./missing' not found
Makefile.am: required file `./depcomp' not found
[litao@vm0000131 hello]$ automake --add-missing
configure.in: installing `./install-sh'
configure.in: installing `./missing'
Makefile.am: installing `./depcomp'
[litao@vm0000131 hello]$ ll
total 192
-rw-rw-r-- 1 litao litao 31120 Aug 12 12:08 aclocal.m4
drwxr-xr-x 2 litao litao 4096 Aug 12 12:14 autom4te.cache
-rw-rw-r-- 1 litao litao 0 Aug 12 12:03 autoscan.log
-rwxrwxr-x 1 litao litao 122297 Aug 12 12:11 configure
-rw-rw-r-- 1 litao litao 496 Aug 12 12:08 configure.in
lrwxrwxrwx 1 litao litao 31 Aug 12 12:16 depcomp -> /usr/share/automake-1.9/depcomp
-rw-rw-r-- 1 litao litao 68 Aug 12 12:02 hello.c
lrwxrwxrwx 1 litao litao 34 Aug 12 12:16 install-sh -> /usr/share/automake-1.9/install-sh
-rw-rw-r-- 1 litao litao 69 Aug 12 12:15 Makefile.am
-rw-rw-r-- 1 litao litao 16561 Aug 12 12:16 Makefile.in
lrwxrwxrwx 1 litao litao 31 Aug 12 12:16 missing -> /usr/share/automake-1.9/missing

六、configure
生成 Makefile, config.log, 和 config.status



分享到:
评论

相关推荐

    configure.和Makefile.之间的关系

    configure.和Makefile.之间的关系

    使用 Automake,Autoconf生成 Makefile

    最全的Automake Autoconf生成Makefile资料。 解析Configure,Makefile.am, Makefile.in, Makefile文件之间关系。

    notify-simple.tar

    解压方式:tar -xvf notify-simple.tar Makefile.am文件的编写 configure.ac文件的编写 Makefile.am与Makefile.in、configure.ac文件的关系 autotools实例讲解 libnotify.so库实例应用

    关于configure配置开源makefile得详细介绍

    详细介绍了configure得各个选项得意思,和使用得方法。同时在config.log里面可以详细看到configure得错误,做对应得修改

    Twitter API Client(gridtwit) oauth demo C++源代码

    Makefile.am ---- Modified, please cover the original file Makefile.in ---- Modified, please cover the original file oauthbodyhash.c oauthdatapost.c oauthexample.c oauthsign.c oauthtest.c ...

    arm linux mp3 player

    .........\.................\......\makefile.am .........\.................\......\makefile.in .........\.................\parse.c .........\.................\parse.h .........\.................\...

    automake-1.14.tar.gz

    Automake是从Makefile.am(定义一系列make变量的文件)自动生成Makefile.in文件的工具。生成的Makefile.in符合GNU Makefile 标准。 因为不同的平台需要修改Makefile,所以编写configure脚本自动修改Makefile,再执行./...

    利用autoconf,automake生成makefile全攻略

    网上给的例子,都是针对一个文件来生成makefile. 但在实际工程中不可能只有一个文件,所以我给出一个3个文件的例子.Myfirst.cpp 主程序,Hello.h,Hello.cpp类的实现. 功能:利用现有工具,生成makefile,生成执行...

    top2.tar.gz

    Makefile.am Makefile.in missing sched_policy.c sched_policy.h top.c #./top -h Usage: ./top [ -m max_procs ] [ -n iterations ] [ -d delay ] [ -s sort_column ] [ -t ] [ -h ] -m num Maximum number of ...

    top3.tar.gz

    Makefile.am Makefile.in missing sched_policy.c sched_policy.h top.c #./top -h Usage: ./top [ -m max_procs ] [ -n iterations ] [ -d delay ] [ -s sort_column ] [ -t ] [ -h ] -m num Maximum number of ...

    ecos-3.0.i386linux.tar.bz2

    实时操作系统ecos的源码包。...acinclude.m4 buildid.txt configure.in examples packages tools aclocal.m4 ChangeLog COPYING Makefile.am README.host acsupport configure doc Makefile.in README.txt

    autoconf-图文详解-附带详细解释

    还觉得写Makefile是难事吗?autoconf-图文详解-附带详细解释 作者亲自写的例子: MyFirst.cpp Hello.h Hello.cpp configure.in Makefile.am autoconf总结.docx 手把手教你玩转 autoconf automake

    libX11源码

    libx11纯源码;根据configure.ac 和makefile.am 生成configure和makefile,文件为源码,未做处理;

    libX11-1.8.tar.gz

    libX11的源码,支持交叉编译,支持嵌入式平台上使用;根据configure.ac 和makefile.am 生成configure和makefile,文件为库源码未做任何改动;

    跟我一起学写makefile

    Makefile 在 Unix 上写程式的人大概都碰过 Makefile,... 後会产生一个可供 Autoconf 使用的 Makefile.in 档。再配合利用 Autoconf 产生的自动设定档 configure 即可产生一份符合 GNU Makefile 惯例的 Makeifle 了。

    cryptopp-autotools:用于Crypto ++项目的Autotools文件

    它提供configure.ac , makefile.am和libcryptopp.pc.in 。 官方上不支持自动工具,因此使用此工具的风险自负。 Crypto ++ Autotools的目的有三方面: 更好地支持Linux发行版,例如Debain,Fedora和openSUSE 通过对...

    IMBE解码库

    文件列表: 文件夹:IMBE decoding library mbelib-1.2.3\ambe3600x2250.c ............\ambe3600x2250_const.h ............\CHANGELOG ............\config.h ............\configure ............\...

    自动生成MakeFile文件的几大工具

    通常编译的./configure文件,大多通过由autotools构建的,最终生成Makefile和config.h文件 CMake: CMake是一个跨平台的安装(编译)工具 CMake类似make工具功能,用来读取并执行CMakeLists.txt文件的语句,最终...

    嵌入式Linux系统移植步步通

    目 录 第一部分 前言...................................................................................................................................8 1 硬件环境.........................................

    easy-rsa-old-master.zip

    │ ├── Makefile.am │ └── rpm │ ├── easy-rsa.spec.in │ └── Makefile.am ├── doc │ ├── Makefile.am │ ├── README-1.0 │ └── README-2.0 ├── easy-rsa │ ├── 1.0 │...

Global site tag (gtag.js) - Google Analytics