操作代码如下:
root@NanoPi2:~/Test/hello# autoscan
root@NanoPi2:~/Test/hello# ls
autoscan.log configure.scan hello.c
root@NanoPi2:~/Test/hello# vi configure.scan
root@NanoPi2:~/Test/hello# mv configure.scan configure.ac
root@NanoPi2:~/Test/hello# ls
autoscan.log configure.ac hello.c
root@NanoPi2:~/Test/hello# aclocal
root@NanoPi2:~/Test/hello# ls
aclocal.m4 autom4te.cache autoscan.log configure.ac hello.c
root@NanoPi2:~/Test/hello# autoconf
root@NanoPi2:~/Test/hello# ls
aclocal.m4 autom4te.cache autoscan.log configure configure.ac hello.c
root@NanoPi2:~/Test/hello# autoheader
root@NanoPi2:~/Test/hello# ls
aclocal.m4 autom4te.cache autoscan.log config.h.in configure configure.ac hello.c
root@NanoPi2:~/Test/hello# vi Makefile.am
root@NanoPi2:~/Test/hello# automake --add-missing
configure.ac:6: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated. For more info, see:
configure.ac:6: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
configure.ac:11: installing './compile'
configure.ac:6: installing './install-sh'
configure.ac:6: installing './missing'
Makefile.am: installing './depcomp'
root@NanoPi2:~/Test/hello# ls
aclocal.m4 autoscan.log config.h.in configure.ac hello.c Makefile.am missing
autom4te.cache compile configure depcomp install-sh Makefile.in
root@NanoPi2:~/Test/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... no
checking for mawk... mawk
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: creating config.h
config.status: executing depfiles commands
root@NanoPi2:~/Test/hello# ls
aclocal.m4 autoscan.log config.h config.log configure depcomp install-sh Makefile.am missing
autom4te.cache compile config.h.in config.status configure.ac hello.c Makefile Makefile.in stamp-h1
root@NanoPi2:~/Test/hello# make
make all-am
make[1]: Entering directory '/root/Test/hello'
gcc -DHAVE_CONFIG_H -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
make[1]: Leaving directory '/root/Test/hello'
root@NanoPi2:~/Test/hello# ./hello
Hello! This is our embedded world!
root@NanoPi2:~/Test/hello#
其中configure.scan注释如下:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT(hello, 1.0, lx2018fc@qq.com)
AM_INIT_AUTOMAKE(hello,1.0)
AC_CONFIG_SRCDIR([hello.c])
AC_CONFIG_HEADERS([config.h])
# 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_CONFIG_FILES([Makefile])
AC_OUTPUT
• AC_PREREQ 宏声明本文件要求的 autoconf 版本,如本例使用的版本 2.69。
• AC_INIT宏用来定义软件的名称和版本等信息,在本例中省略了BUG-REPORT-ADDRESS,
一般为作者的 E-mail。
• AM_INIT_AUTOMAKE 是笔者另加的,它是 automake 所必备的宏,也同前面一样,
PACKAGE 是所要产生软件套件的名称,VERSION 是版本编号。
• AC_CONFIG_SRCDIR 宏用来侦测所指定的源码文件是否存在,来确定源码目录的有
效性。在此处为当前目录下的 hello.c。
• AC_CONFIG_HEADER 宏用于生成 config.h 文件,以便 autoheader 使用。
• AC_CONFIG_FILES 宏用于生成相应的 Makefile 文件。
• 中间的注释间可以添加分别用户测试程序、测试函数库、测试头文件等宏定义。
Makefile.am文件注释如下:
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello
hello_SOURCES= hello.c
• 其中的 AUTOMAKE_OPTIONS 为设置 automake 的选项。由于 GNU(在第 1 章中已
经有所介绍)对自己发布的软件有严格的规范,比如必须附带许可证声明文件 COPYING 等,
否则 automake 执行时会报错。automake 提供了 3 种软件等级:foreign、gnu 和 gnits,让用户
选择采用,默认等级为 gnu。在本例使用 foreign 等级,它只检测必须的文件。
• bin_PROGRAMS 定义要产生的执行文件名。如果要产生多个执行文件,每个文件名
用空格隔开。
• hello_SOURCES 定义“hello”这个执行程序所需要的原始文件。如果“hello”这个
程序是由多个原始文件所产生的,则必须把它所用到的所有原始文件都列出来,并用空格隔
开。例如:若目标体“hello”需要“hello.c”、“sunq.c”、“hello.h”三个依赖文件,则定义
hello_SOURCES=hello.c sunq.c hello.h。要注意的是,如果要定义多个执行文件,则对每个执
行程序都要定义相应的 file_SOURCES。