2009-09-12 Sat
autoconf 学び直し その1
autoconfの学び直し。
以前いじくった時は特に難しいことを必要としなかったので、キチンとメモを残しておかなかったので、ちゃんと残す。
環境によって挙動を変えるように設定したい。
参考文献
- Automakeでmakeする
-- http://www.02.246.ne.jp/~torutk/cxx/automake/automake.html
- Autotoolsの入力ファイルと出力ファイル
-- http://www.fireproject.jp/feature/automake/
- automake
-- http://www.geocities.jp/fut_nis/html/automake-ja/Public-macros.html
- MODULE.JP - SpiderMonkeyをGNU Autotools対応する
-- http://module.jp/blog/autotoolize_spidermonkey.html
- COPYING(GPLの規約が書いてある)が勝手に作られる
-- http://d.hatena.ne.jp/ultraist/20070707
- autoconf & automake
-- http://www.jaist.ac.jp/~kiyoshiy/memo/autoconf.html
メモ(いろいろ試しながらやったので作業が前後してるかも
- ソースコードの設置
-- 適当になんかファイルを作ったら、
-- srcディレクトリ以下に置く
/-- src
|-- practice.c
|-- practice.c
- Makefile.amを書く
-- ビルドするソースが無いディレクトリのMakefile.amはディレクトリの列挙
-- 今回の例だと、「$ echo 'SUBDIRS = src' > Makefile.am」かな
-- ビルドするソースが有るディレクトリのMakefile.amはソースの記述
bin_PROGRAMS = example1 example2
example1_SOURCES = example1.c
example2_SOURCES = example2.c
example1_SOURCES = example1.c
example2_SOURCES = example2.c
- autoscanする。
-- configure.acのひな形を作りたい
-- バグが無いコードを実行すると「autoscan.log」と「configure.scan」ができる。
- すべての、configure.scanをconfigure.acに変更する
-- これはautoconfで使われる。
-- 古いバージョンのAutoconfではconfigure.inを使用していましたが、Autoconf 2.50とそれ以降では,configure.inではなくconfigure.acを推奨
- configure.acの「FULL-PACKAGE-NAME」、「VERSION」を変更する。
-- 例えばハフマン符号のコードなら、「FULL-PACKAGE-NAME」を「huffman」とかにすれば良い。
-- VERSIONは、最初だから0.0.1_01とかで良い。
-- BUG-REPORT-ADDRESSは、自分のアドレスを書いたりした。
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
- AC_INIT_AUTOMAKE(FULL-PACKAGE-NAME, VERSION)を足す
-- automake
--- http://www.geocities.jp/fut_nis/html/automake-ja/Public-macros.html
- AM_INIT_AUTOMAKEを足す
-- automakeを使うことをautoconfに伝えるマクロ
-- GNU projectとして作るわけではないので、foreignという引数を与える
--- foreignを与えないと「COPYING(GPLの規約が書いてある)が勝手に作られる」
$ automake --version
automake (GNU automake) 1.4-p6
Copyright (C) 1999, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Tom Tromey <tromey@redhat.com>
automake (GNU automake) 1.4-p6
Copyright (C) 1999, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Tom Tromey <tromey@redhat.com>
-- ということで「AM_INIT_AUTOMAKE([foreign 1.4-p6])」とか書く。
-- AC_CONFIG_HEADER() を AM_CONFIG_HEADER() に変更
-- AC_INIT_AUTOMAKE()もなんか駄目だなぁ。。。
そうすると以下のようになる。
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
FULL-PACKAGE-NAME=huffman
VERSION=0.0.1_01
BUG-REPORT-ADDRESS=overlasting<at>gmail<dot>com
AUTOMAKE_VERSION=1.4-p6
AC_PREREQ(2.61)
AC_INIT(huffman, 0.0.1_01, overlasting<at>gmail<dot>com)
# AC_INIT_AUTOMAKE(huffman, 0.0.1_01)
AM_INIT_AUTOMAKE([foreign 1.4-p6])
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_SRCDIR([src/practice.c])
AM_CONFIG_HEADER(config.h)
# Checks for programs.
AC_PROG_CC
# Process this file with autoconf to produce a configure script.
FULL-PACKAGE-NAME=huffman
VERSION=0.0.1_01
BUG-REPORT-ADDRESS=overlasting<at>gmail<dot>com
AUTOMAKE_VERSION=1.4-p6
AC_PREREQ(2.61)
AC_INIT(huffman, 0.0.1_01, overlasting<at>gmail<dot>com)
# AC_INIT_AUTOMAKE(huffman, 0.0.1_01)
AM_INIT_AUTOMAKE([foreign 1.4-p6])
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_SRCDIR([src/practice.c])
AM_CONFIG_HEADER(config.h)
# Checks for programs.
AC_PROG_CC
- aclocalする
-- $ aclocalする
- Automakeのためのマクロ
- Autoconfのためのマクロ
- ユーザ定義のマクロ
などを参照し,configure.inに記述されている全てのマクロを解決し,aclocal.m4を生成する.
入力ファイル
* configure.ac (configure.in)
* acinclude.m4(オプション.なくてもよい)
* ユーザ定義マクロファイル(オプション.なくてもよい)
出力ファイル
* aclocal.m4
- Autoconfのためのマクロ
- ユーザ定義のマクロ
などを参照し,configure.inに記述されている全てのマクロを解決し,aclocal.m4を生成する.
入力ファイル
* configure.ac (configure.in)
* acinclude.m4(オプション.なくてもよい)
* ユーザ定義マクロファイル(オプション.なくてもよい)
出力ファイル
* aclocal.m4
たしかにactocal.m4ができてた。
- 無いよと怒られたファイルは追加する
-- $ touch NEWS AUTHORS ChangeLog README
- Autoheaderを実行しよう
-- $ autoheaderする
Autoheaderはm4にconfigure.inを与えてconfig.h.inを生成する.
入力ファイル
* configure.in
* aclocal.m4
出力ファイル
* configure.h.in
入力ファイル
* configure.in
* aclocal.m4
出力ファイル
* configure.h.in
-- 確かに、config.h.inできた!!
- 次はautomake --add-missingする
-- 意味は?
automake accepts the following options:
-a
--add-missing
Automake requires certain common files to exist in certain situations; for instance config.guess is required if config‐
ure.in runs AC_CANONICAL_HOST. Automake is distributed with several of these files; this option will cause the missing
ones to be automatically added to the package, whenever possible. In general if Automake tells you a file is missing,
try using this option.
--amdir=DIR
Look for Automake data files in directory DIR instead of in the installation directory. This is typically used for
debugging.
--build-dir=DIR
Tell Automake where the build directory is. This option is used when including dependencies into a Makefile.in gener‐
ated by make dist; it should not be used otherwise.
-a
--add-missing
Automake requires certain common files to exist in certain situations; for instance config.guess is required if config‐
ure.in runs AC_CANONICAL_HOST. Automake is distributed with several of these files; this option will cause the missing
ones to be automatically added to the package, whenever possible. In general if Automake tells you a file is missing,
try using this option.
--amdir=DIR
Look for Automake data files in directory DIR instead of in the installation directory. This is typically used for
debugging.
--build-dir=DIR
Tell Automake where the build directory is. This option is used when including dependencies into a Makefile.in gener‐
ated by make dist; it should not be used otherwise.
Autoconf
Autoconfはconfigure.inに記述されたm4マクロをaclocal.m4参照しつつ展開し,configureスクリプトを生成する.
入力ファイル
* configure.in
* aclocal.m4
出力ファイル
* configure
入力ファイル
* configure.in
* aclocal.m4
出力ファイル
* configure
Configure
$ ./configure
configureはAutoconfにより生成されるスクリプトで,各プラットフォームの環境をチェックし,その環境にあわせてパッケージをビルドするためのMakefileを生成する.
入力ファイル
* Makefile.in
* config.h.in
* ltmain.sh(Libtool使用時)
出力ファイル
* Makefile
* config.h
* libtool(Libtool使用時)
この他にも多くの入出力ファイルを使用している.
入力ファイル
* Makefile.in
* config.h.in
* ltmain.sh(Libtool使用時)
出力ファイル
* Makefile
* config.h
* libtool(Libtool使用時)
この他にも多くの入出力ファイルを使用している.
ここから先は他のアプリの cnfigure.in を見てみよう。
@takesako さんからはm4マクロ周りを調べると良いよ、とご教授いただいた。
また、次に暇な日に続く。




