Environment:
OS:UBUNTU 11.04
Kernel Version:2.6.35
1. Install the software
sudo apt-get install autoconf
2. The structure of the files.
TestAutotool
----main.c
----include
--------hello.h
----hello
--------hello.c
<main.c>
#include"../include/hello.h"
int main()
{
PrintHello();
}
<hello.h>
#include<stdio.h>
extern voidPrintHello();
<hello.c>
#include"../include/hello.h"
voidPrintHello()
{
printf("Hello World\n");
}
3. Steps
autoscan
mv configure.scan configure.in
# -*-Autoconf -*-
# Process thisfile with autoconf to produce a configure script.
AC_PREREQ([2.67])
AC_INIT(main,1.0,[641959875@qq.com])
AM_INIT_AUTOMAKE(main,1.0)
AC_CONFIG_SRCDIR([main.c])
AC_CONFIG_HEADERS([config.h])
# Checks forprograms.
AC_PROG_CC
# Checks forlibraries.
AC_PROG_RANLIB
# Checks forheader files.
# Checks fortypedefs, structures, and compiler characteristics.
# Checks forlibrary functions.
AC_OUTPUT([Makefile
hello/Makefile])
vim Makefile.am
AUTOMAKE_OPTIONS=foreign
INCLUDES= -I./include
bin_PROGRAMS=main
main_SOURCES=main.c
main_LDADD=./hello/libhello.a
cd hello
# -*- Autoconf -*-
# Process thisfile with autoconf to produce a configure script.
AC_PREREQ([2.67])
AC_INIT(hello,1.0, 641959875@qq.com)
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([hello.c])
AC_CONFIG_HEADERS([config.h])
# Checks forprograms.
AC_PROG_CC
# Checks forlibraries.
AC_PROG_RANLIB
# Checks for headerfiles.
# Checks fortypedefs, structures, and compiler characteristics.
# Checks forlibrary functions.
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
noinst_LIBRARIES=libhello.a
libhello_a_SOURCES=hello.c
INCLUDE =../include/hello.h
AUTOMAKE_OPTIONS=foreign
aclocal
autoconf
autoheader
automake --add-missing
cd ..
aclocal
autoconf
autoheader
automake --add-missing
./configure
make
make install