参考:http://www.gnu.org/software/automake/#documentation
环境:win7 cygwin64
1、在空目录中创建以下文件。
- src / main.c是hello程序的源文件
$ cat src/main.c
#include <config.h>
#include <stdio.h>
int
main (void)
{
puts ("Hello World!");
puts ("This is " PACKAGE_STRING ".");
return 0;
}
- README
$ cat README
This is a demonstration package for GNU Automake.
Type 'info Automake' to read the Automake manual.
- Makefile.am和src / Makefile.am包含这两个目录的Automake指令。
$ cat src/Makefile.am
bin_PROGRAMS = hello
hello_SOURCES = main.c
$ cat Makefile.am
SUBDIRS = src
dist_doc_DATA = README
- 最后,configure.ac包含用于创建配置脚本的Autoconf指令。
$ cat 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
- 一但拥有这五个文件,现在是运行Autotools来实例化构建系统的时候了。 使用autoreconf命令执行以下操作:
$ autoreconf --install
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/\${ <-- HERE ([^ \t=:+{}]+)}/ at /usr/bin/automake-1.14 line 3930.
configure.ac:3: installing './compile'
configure.ac:2: installing './install-sh'
configure.ac:2: installing './missing'
src/Makefile.am: installing './depcomp'
此时构建系统完成。
除了输出中提到的三个脚本之外,您还可以看到autoreconf创建了四个其他文件:configure,config.h.in,Makefile.in和src / Makefile.in。 后三个文件是通过配置config.h,Makefile和src / Makefile来配置的模板。 我们开工吧:
Administrator@USERCHI-CKFB921 /cygdrive/g/cygwin64/TestProjects/AutoMake
$ ./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... /usr/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.exe
checking for suffix of executables... .exe
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: creating src/Makefile
config.status: creating config.h
config.status: executing depfiles commands
在配置文件探测到系统后,可以看到Makefile,src / Makefile和config.h在最后创建。 现在可以运行我们希望的所有目标。 例如:
$ make
make all-recursive
make[1]: 进入目录“/cygdrive/g/cygwin64/TestProjects/AutoMake”
Making all in src
make[2]: 进入目录“/cygdrive/g/cygwin64/TestProjects/AutoMake/src”
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
mv -f .deps/main.Tpo .deps/main.Po
gcc -g -O2 -o hello.exe main.o
make[2]: 离开目录“/cygdrive/g/cygwin64/TestProjects/AutoMake/src”
make[2]: 进入目录“/cygdrive/g/cygwin64/TestProjects/AutoMake”
make[2]: 离开目录“/cygdrive/g/cygwin64/TestProjects/AutoMake”
make[1]: 离开目录“/cygdrive/g/cygwin64/TestProjects/AutoMake”
$ ./src/hello.exe
Hello World!
This is amhello 1.0.
- 生成发布软件包
$ make distcheck
...
=============================================
amhello-1.0 archives ready for distribution:
amhello-1.0.tar.gz
=============================================
请注意,仅当GNU构建系统不存在时,才需要运行autoreconf。 当您稍后更改Makefile.am或configure.ac中的某些指令时,在执行时,系统的相关部分将自动重新生成。
autoreconf是一个脚本,以正确的顺序调用autoconf,automake和一堆其他命令。 如果你开始使用这些工具,找出所有这些工具应该按哪个顺序被调用并且为什么是不重要的。 然而,因为Autoconf和Automake有单独的手册,重要的一点是要明白autoconf是从configure.ac负责创建configure,而automake负责从Makefile.ams和configure.ac创建Makefile.ins。 在寻求答案时,至少应该指导您使用正确的手册。