automake安装与使用记录
2017-05-28
Autoconf is an extensible package of M4 macros that produce shell scripts to automatically configure software source code packages. These scripts can adapt the packages to many kinds of UNIX-like systems without manual user intervention. Autoconf creates a configuration script for a package from a template file that lists the operating system features that the package can use, in the form of M4 macro calls.
Autoconf是M4 macros工具的扩展包,可以生成shell脚本来自动化配置源码,这些脚本兼容于各个版本的类UNIX系统,不需要程序员再做调整。Autoconf根据模版文件生成配置脚本,模版文件根据系统环境和代码依赖生成,以M4 macro调用的形式构成。
Automake is a tool for automatically generating Makefile.in files compliant with the GNU Coding Standards. Automake requires the use of Autoconf.
Automake是自动生成兼容于GNU编码标准的Makefile.in的工具,该工具依赖于Autoconf。
sudo apt-get install autoconf
该命令会自动安装automake的工具链(aclocal、autoscan、autoconf、autoheader、automake)
然后我们通过介绍GNU的demo来介绍这个工具链。
1、新建工程路径hello
2、新建文件src/main.c
#include <config.h>
#include <stdio.h>
int
main (void)
{
puts ("Hello World!");
puts ("This is " PACKAGE_STRING ".");
return 0;
}
3、新建README文件
This is a demonstration package for GNU Automake.
Type 'info Automake' to read the Automake manual.
4、新建src/Makefile.am
bin_PROGRAMS = hello
hello_SOURCES = main.c
5、新建Makefile.am
SUBDIRS = src
dist_doc_DATA = README
6、新建configure.ac,这个文件的配置被autoconf(创建configure)和automake(创建Makefile.in)读取使用。 ac文件的宏以AC_为前缀,具体内容参照autoconf Macro index。另外,也可以使用autoscan创建configure.ac,参照Using autoscan to Create configure.ac
AC_INIT([amhello], [1.0], [bug-automake@gnu.org])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([
Makefile
src/Makefile
])
AC_OUTPUT
7、运行Autotools来实例化构建系统,生成configure、config.h、Makefile.in、src/Makefile.in,命令如下:
autoreconf --install
8、生成Makefile、src/Makefile,config.h,运行配置命令,如下
./configure
其他参照