目录结构图示

shallow - 图1

手动编写2个文件:

configure.ac

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

AC_PREREQ([2.69])
AC_INIT([main], [1.1], [www.softool.cn])
#只填写入口主文件名即可:
AC_CONFIG_SRCDIR([main.c])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE
# Checks for programs.
AC_PROG_CC

# Checks for libraries.
# 正常情况下,各个目录生成.o目标文件,然后链接在一块。
# 但是 Automake的宏应该是不支持各个.o目标文件的链接的,
# 而 Automake支持库文件的链接,所以我们采用依赖库的思想
# 来解决。
# 我们这里使用静态库:
AC_PROG_RANLIB
# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.
#各个目录下面都需要一个 Makefile
AC_OUTPUT(Makefile
            hello/Makefile
)

每个目录的 Makefile.am

根目录:
AUTOMAKE_OPTIONS = foreign
## 我们要使用递归目录变量 SUBDIRS
SUBDIRS = hello
## 指定要生成的可执行文件的名:
bin_PROGRAMS = main
## 指定上面要生成可执行文件名依赖的主入口源文件:
main_SOURCES = main.c
## 需要链接各子目录生成的库:
main_LDADD = hello/libhello.a
子目录:
AUTOMAKE_OPTIONS = foreign
## 指定要生成的静态库
## 由于不需要安装到指定的目录中,所以这里使用的前缀为 noinst
noinst_LIBRARIES = libhello.a
## 指定上面的静态库依赖的源文件,多个源文件可以使用空格来隔开:
libhello_a_SOURCES = hello.c

执行演示

整个命令的执行过程

autoscan
mv configure.scan configure.ac

#编辑 configure.ac

aclocal
autoconf
autoheader

#编辑各目录的 Makefile.am

automake -a
./configure
make

效果

shallow - 图2
shallow - 图3