0. 操作平台: Linux
1. 软件包安装(Debian)
yes | sudo apt-get install gcc make autoconf automake libtool
2. 从一个例子谈起。
2.0 完整拷贝如下代码直接在终端执行或者保存为auto-example.sh,添加执行权限执行。或者参考2.1~2.5逐步执行。
echo "create directory ..."
echo_exit()
{
echo "ERROR: $@"
exit 1
}
# 1.
mkdir hello && cd hello || echo_exit "mkdir hello or cd hello failed"
cat > hello.c <<EOF || echo_exit "generates hello.c failed"
#include <stdio.h>
int main()
{
printf("hello auto-tools!\n");
return 0;
}
EOF
# 2.
cat > Makefile.am << EOF || echo_exit "generates Makefile.am failed"
bin_PROGRAMS = hello
hello_SOURCES = hello.c
EOF
# 3.
cat > configure.ac << EOF || echo_exit "generates configure.ac failed"
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.67])
AC_INIT([hello], [1.0], [yygcode@gmail.com])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
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
EOF
# 4.
autoreconf --install || echo_exit "autoreconf --install failed"
# 5.
./configure && make || echo_exit "configure or make failed"
# 6.
make dist && make distcheck || echo_exit "make dist && make distcheck failed"
echo "All Do Over Success"
2.1 创建hello目录和源代码hello.c:
~$ mkdir hello && cd hello
~$ cat > hello.c <<EOF
#include <stdio.h>
int main()
{
printf("hello auto-tools!\n");
return 0;
}
EOF
2.2 创建 Makefile.am
~$ cat > Makefile.am << EOF
bin_PROGRAMS = hello
hello_SOURCES = hello.c
EOF
2.3 用 autoscan 生成configure.ac的模板configure.scan
~$ autoscan
~$ cat configure.scan
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.67])
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
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
需要修改configure.scan的不问内容并保存为configure.ac。为了方便,直接用如下指令生成configure.ac:
~$ cat > configure.ac << EOF
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.67])
AC_INIT([hello]