Automake 所產生的 Makefile 除了可以做到程式的編譯和連結,也已經把如何產生程式文件 (如 manual page, info 檔及 dvi 檔) 的動作,還有把原始程式包裝起來以供散佈的動作都考慮進去了,所以原始程式所存放的目錄架構最好符合 GNU 的標準慣例,接下來我拿 hello.c 來做為例子。
在工作目錄下建立一個新的子目錄 ``devel'',再在 devel 下建立一個 ``hello'' 的子目錄,這個目錄將作為我們存放 hello 這個程式及其相關檔案的地方:
% cd devel
% mkdir hello
% cd hello
int main(int argc, char** argv)
{
printf(``Hello, GNU!\n'');
return 0;
}
% ls
configure.scan hello.c
AC_INIT(hello.c)
AM_INIT_AUTOMAKE(hello, 1.0)
dnl Checks for programs.
AC_PROG_CC
dnl Checks for libraries.
dnl Checks for header files.
dnl Checks for typedefs, structures, and compiler characteristics.
dnl Checks for library functions.
AC_OUTPUT(Makefile)
% autoconf
% ls
aclocal.m4 configure configure.in hello.c
bin_PROGRAMS= hello
hello_SOURCES= hello.c
automake: configure.in: installing `./install-sh'
automake: configure.in: installing `./mkinstalldirs'
automake: configure.in: installing `./missing'
creating cache ./config.cache
checking for a BSD compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking whether make sets ${MAKE}... yes
checking for working aclocal... found
checking for working autoconf... found
checking for working automake... found
checking for working autoheader... found
checking for working makeinfo... found
checking for gcc... gcc
checking whether the C compiler (gcc ) works... yes
checking whether the C compiler (gcc ) is a cross-compiler... no
checking whether we are using GNU C... yes
checking whether gcc accepts -g... yes
updating cache ./config.cache
creating ./config.status
creating Makefile
gcc -DPACKAGE=\"hello\" -DVERSION=\"1.0\" -I. -I. -g -O2 -c hello.c
gcc -g -O2 -o hello hello.o
% ./hello
Hello! GNU!