autotools工具使用记录

参考 http://blog.chinaunix.net/uid-25100840-id-271131.html

   http://blog.sina.com.cn/s/blog_4c2bf01a01014fwj.html

下载与安装

下载地址 http://www.gnu.org/software/software.html

  需要下载的工具包有:autoconf-2.69  automake-1.14  m4-1.4.17 

  我下载的是最新的版本

安装顺序  m4->autoconf->automake  (参考的博文说这个顺序很重要,刚开始很纳闷,后来在安装的过程中,发现之间是有依赖关系的)

  安装方法:./configure  ->   make  ->  make install

使用方法    

autotool工具使用到的工具有:

aclocal

autoscan

autoconf

autoheader

automake

自动生成makefile的过程中需要做的有:

1 编写Makefile.am文件

1 SUBDIRS = lib #若需要编译的源文件在一个子目录下(lib为你的子目录名),需要申明,如果没有就没有必要写
2 
3 AUTOMAKE_OPTIONS = foreign #如果不添加此行,会在执行automake -a 命令时报错,找不到“NEWS”“README”“AUTHORS”“ChangeLog"等文件
4 bin_PROGRAMS = hello   #需要生成的目标文件 5 hello_SOURCES = hello.c  #源文件 6 7 hello_LDADD = ./lib/libprint.a  #依赖到库文件
1 noinst_LIBRARIES = libprint.a  #需生成的链接库 noinst_ 只想编译不安装到系统中,inst_安装到系统中
2 libprint_a_SOURCES = print.c ../include/print.h #依赖文件

注意:如果此时,print.h若又包含一个base.h头文件,以上的写法就要做修改,libprint_a_SOURCES 可用修改如下  

libprint_a_SOURCES = print.c

然后再添加一行:AM_CPPFLAGS= -I  ../include 即可,最后在项目根目录的Makefile.am中添加这一行。  

2  执行命令 autoscan 生成文件configure.scan,修改此文件,另存为configure.ac.修改或添加的内容如下:

 1 AC_PREREQ([2.69])
 2 AC_INIT(hello,0.01) #生成程序名,版本号,联系邮箱
 3 
 4 AM_INIT_AUTOMAKE #此处为添加的
 5 
 6 AC_PROG_RANLIB  #此处为添加的,没有使用到自定义的库的时候,不添加此行也不会报错
 7 
 8 AC_CONFIG_SRCDIR([hello.c])
 9 AC_CONFIG_HEADERS([config.h])
10 
11 # Checks for programs.
12 AC_PROG_CC
13 
14 # Checks for libraries.
15 
16 # Checks for header files.
17 
18 # Checks for typedefs, structures, and compiler characteristics.
19 
20 # Checks for library functions.
21 
22 AC_CONFIG_FILES([Makefile
23                  lib/Makefile])    
24 AC_OUTPUT

3  执行命令  aclocal

4  执行命令  autoconf

5  执行命令  autoheader

6  执行命令  automake  -a

7  执行命令  ./configure

8   make

原文地址:https://www.cnblogs.com/10cm/p/3420022.html