首页 / 操作系统 / Linux / Linux C一个Autotools的最简单例子
1、准备:
需要工具autoscan aclocal autoheader automake autoconf make 等工具.
2、测试程序编写:
建立目录:mkdir include src
编写程序:include/str.h#include <stdio.h>
int str(char *string);编写程序:src/str.c#include "str.h"
//print string
int str(char *string){
printf("
----PRINT STRING----
"%s"
",string);
return 0;
}//interface of this program
int main(int argc , char **argv){
char str_read[1024];
printf("Please INPUT something end by [ENTER]
");
scanf("%s",str_read);
return str(str_read );
}3、生成configure.ac
configure.ac是automake的输入文件,所以必须先生成该文件。
执行命令:[root@localhost str]# ls
include src
[root@localhost str]# autoscan
autom4te: configure.ac: no such file or directory
autoscan: /usr/bin/autom4te failed with exit status: 1
[root@localhost str]# ls
autoscan.log configure.scan include src
[root@localhost str]# cp configure.scan configure.ac 修改 configure.ac# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.AC_PREREQ(2.59)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CONFIG_SRCDIR([include/str.h])
AC_CONFIG_HEADER([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_OUTPUT修改AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)为AC_INIT(str,0.0.1, [bug@sounos.org])FULL-PACKAGE-NAME 为程序名称,VERSION为当前版本, BUG-REPORT-ADDRESS为bug汇报地址
添加AM_INIT_AUTOMAKE
添加AC_CONFIG_FILES([Makefile])# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.AC_PREREQ(2.59)
#AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_INIT(str, 0.0.1, [bug@sounos.org])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([include/str.h])
AC_CONFIG_HEADER([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_OUTPUT4、执行aclocal[root@localhost str]# aclocal
/usr/share/aclocal/libfame.m4:6: warning: underquoted definition of AM_PATH_LIBFAME
run info "(automake)Extending aclocal"
or see http://sources.RedHat.com/automake/automake.html#Extending-aclocal