1.hello.c
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include "config.h"
double get_epoch()
{
double sec;
#ifdef HAVE_GETTIMEOFDAY
struct timeval tv;
gettimeofday(&tv, NULL);
sec = tv.tv_sec;
sec += tv.tv_usec / 1000000.0;
#else
sec = time(NULL);
#endif
return sec;
}
int main(int argc, char* argv[])
{
printf("%f\n", get_epoch());
return 0;
}
2.编写Makefile.am
AUTOMAKE_OPTIONS = foreign
INCLUDES=
bin_PROGRAMS = hello
hello_SOURCES=gettime.c
hello_CFLAGS=-Wall -g
hello_LDADD=
3. autoscan之后生成configre.scan重命名为configure.in伙configure.ac,之后修改文件加上AM_INIT_AUTOMAKE(hello,1.1)。
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.66])
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AC_CONFIG_SRCDIR([gettime.c])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE(hello,1.1)
# 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.
# Checks for library functions.
AC_CHECK_FUNCS([gettimeofday])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
4.acloacl
5.autoconf
6.autoheader
7.automake --add-missing
8.../configure
9.make
10.运行hellio