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。为了方便,直接用如下指令生成confi

本文档提供了一个简单的GNU Autotools(autoconf, automake, libtool等)使用示例,适用于Linux平台。首先介绍了在Debian系统中安装相关软件包的步骤,然后通过创建名为'hello'的目录和编写hello.c源代码,逐步指导如何使用autoreconf生成configure文件,并执行编译过程。"
78155051,5853771,学生信息系统优化实践,"['前端开发', 'Windows应用开发', '用户界面', '数据库管理']
最低0.47元/天 解锁文章
559

被折叠的 条评论
为什么被折叠?



