GNU Autotools (autoconf, automake, libtool, etc.) 自动化编译 (1) 简单示例

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

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]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值