制作configure文件

(1) 写代码

hello.c
#include <stdio.h>
#include <sys/time.h>

int main(int argc, char *argv[]) {
    double sec;
    struct timeval tv;
    gettimeofday(&tv, NULL);
    sec = tv.tv_sec;
    sec += tv.tv_usec/1000000.0;
    printf ("hello word!\nsec = %e\n", sec);
    exit(0);
}


(2) autoscan 生成文件configure.scan

% autoscan

(3) 修改configure.scan

修改后的文件内容如下:
-- Autoconf --
Process this file with autoconf to produce a configure script.
AC_PREREQ(2.61)
AC_INIT(hello, 1.0) #修改
AM_INIT_AUTOMAKE(hello, 1.0) #添加
AC_CONFIG_SRCDIR([hello.c])
AC_CONFIG_HEADER([config.h])
Checks for programs.
AC_PROG_CC
Checks for libraries.
Checks for header files.
AC_CHECK_HEADERS([sys/time.h])
Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_TIME
Checks for library functions.
AC_CHECK_FUNCS([gettimeofday])
AC_CONFIG_FILES([Makefile]) #添加
AC_OUTPUT

(3) 3、文件改名configure.scan为configure.in

% mv configure.scan configure.in

(4) 4、运行aclocal 生成 aclocal.m4

% aclocal

(5) 运行autoconf 生成configure

% autoconf

(6) 运行autoheader 生成config.h.in,使程序可移植

% autoheader

(7) 创建空文件Makefile.am

% touch Makefile.am

写入以下内容:
bin_PROGRAMS= hello
hello_SOURCES= hello.c

(8) 生成configure.in

% automake --add-missing

(9) 编译运行

configure && make && make install