0. 基础
先阅读GNU Autotools (autoconf, automake, libtool, etc.) 自动化编译 (1) 简单示例并成功执行、理解所说内容。
1. 先提供一个脚本。拷贝所有内容保存为文件atdir.sh并添加可执行权限,然后执行。注意,最好不要以根用户身份执行它。
#!/bin/sh
echo "Autotools for autotools multi directories (stands for atdirs)"
echo_exit()
{
echo "ERROR: $@"
exit 1
}
# 1. prepare directories and dummy files
[ ! -e "atdirs" ] || echo_exit "atdirs exists, please remove or rename it"
mkdir atdirs && cd atdirs || echo_exit "mkdir -p atdirs or cd atdirs failed"
mkdir -p doc build-aux m4 man src/{include/atdirs,lib{1,2},tests} || \
echo_exit "create subdirectory failed"
touch AUTHORS BUGS ChangeLog COPYING NEWS README || \
echo_exit "touch dummy files failed"
# 2. generates source, header files
cat > src/include/atdirs/lib1.h <<EOF
#ifndef __ATDIRS_LIB1_H_
#define __ATDIRS_LIB1_H_
void lib1_print();
#endif
EOF
cat > src/include/atdirs/lib2.h <<EOF
#ifndef __ATDIRS_LIB2_H_
#define __ATDIRS_LIB2_H_
void lib2_print();
#endif
EOF
cat > src/lib1/print.c <<EOF
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <atdirs/lib1.h>
void lib1_print()
{
printf("lib1-print: " PACKAGE_STRING " <lib-1>\n");
}
EOF
cat > src/lib2/print.c <<EOF
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#includ