一つのソースファイルからなるパッケージの作成
一つのソースファイルに対してAutomakeを適用する,おそらくもっとも簡単な例である.
まず最初に全体の流れを示す.
- ソースの準備
- configure.inの作成
- autoconf
- Makefile.amの作成
- autoheader
- automake -a
今回はAutomakeを使用するもっとも簡単な例を示すために,hello.cというソースを容易した.
$ ls -a
. .. hello.c
$ cat hello.c
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
fprintf(stdout,"hello \n");
exit(EXIT_SUCCESS);
}
次に,Autoconf,Automakeのためにconfigure.inを作成する.まず,autoscanを実行してconfigure.inのもとになるconfigure.scanを生成する.
$ autoscan Use of uninitialized value in concatenation (.) or string at /usr/bin/autoscan line 195. $ ls -a . .. autoscan.log configure.scan hello.c $ mv configure.scan configure.inなんかautoscanが怒ってるような気がするが気にしない.で,configure.scanをもとにconfigure.inを作成する.こんな感じ.
# Process this file with autoconf to produce a configure script. AC_INIT(hello.c) AM_INIT_AUTOMAKE(hello,1.00,hoge@fuga) AM_CONFIG_HEADER(config.h) # Checks for programs. AC_PROG_CC AC_PROG_INSTALL # Checks for libraries. # Checks for header files. AC_HEADER_STDC AC_CHECK_HEADERS(stdlib.h stdio.h) # Checks for typedefs, structures, and compiler characteristics. # Checks for library functions. AC_OUTPUT(Makefile)上のconfigure.inにはAM_で始まるAutomake用のマクロが含まれているのでAutoconfには理解できない.そこで,aclocalでAutoconfにも理解できるようにしておく.
ls -a . .. autoscan.log configure.in hello.c $ aclocal $ ls -a . .. aclocal.m4 autoscan.log configure.in hello.c生成されるaclocal.m4についてはaclocalの節で説明する.aclocalはうまくいっている時は無言である.
Autoconfを実行してconfigureスクリプトを作成する.
$ autoconf $ ls -a . .. aclocal.m4 autoscan.log configure configure.in hello.c
次にAutomakeのためにMakefile.amを作成する.こんな感じ.
bin_PROGRAMS = hello hello_SOURCES = hello.c
先のconfigure.inでは,config.h.inをチェックするように設定したので,config.hを生成する必要がある.そこでautoheaderでconfig.h.inを生成する.
$ ls -a . .. Makefile.am aclocal.m4 autoscan.log configure configure.in hello.c $ autoheader $ ls -a . .. Makefile.am aclocal.m4 autoscan.log config.h.in configure configure.in hello.c
いよいよautomakeを実行してみる.その前にGNU標準に従うために,いくつかのファイルを作成する.
$ touch NEWS README AUTHORS ChangeLog $ ls -a . .. AUTHORS ChangeLog Makefile.am NEWS README aclocal.m4 autoscan.log config.h.in configure configure.in hello.c $ automake -a automake: configure.in: installing `./install-sh' automake: configure.in: installing `./mkinstalldirs' automake: configure.in: installing `./missing' automake: Makefile.am: installing `./INSTALL' automake: Makefile.am: installing `./COPYING' $ ls -a . AUTHORS ChangeLog Makefile.am NEWS aclocal.m4 config.h.in configure.in install-sh mkinstalldirs .. COPYING INSTALL Makefile.in README autoscan.log configure hello.c missing stamp-h.in
ここまでで準備完了である.あとはいつものように
$ ./configure $ makeなどとするだけである.
$ ./configure
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
...(省略)...
creating Makefile
creating config.h
$ make
gcc -DHAVE_CONFIG_H -I. -I. -I. -Wall -pedantic -ansi -c hello.c
gcc -Wall -pedantic -ansi -o hello hello.o
$ ./hello
hello
できた.

