autoconf, automake
環境に合わせて Makefile を作る仕組み。 以下の3つのツールを組み合わせて使う。
- https://www.gnu.org/software/autoconf/
- https://www.gnu.org/software/automake/
- https://www.gnu.org/software/libtool/
CMake のほうがモダンで高速。
Commands
autoscan- 指定したディレクトリ(指定しなければカレント)のソースコードを読んで
configure.acの雛形となるconfigure.scanを作る。 既存のconfigure.acもチェックするらしいが、その内容をすべてconfigure.scanに反映してくれるわけではなさそうなので そのまま上書きしてはダメっぽい。 aclocalconfigure.acを読んでaclocal.m4を作るautomakeMakefile.amとconfigure.acからMakefile.inを作るautoconfconfigure.acとaclocal.m4からconfigureを作るautoreconf- 上記のツールをいい感じに繰り返し呼び出して各種ファイルを更新
大まかな流れ
-
configure.scanの雛形を自動生成し、configure.acに名前変更:autoscan mv configure.scan configure.ac -
configure.acを適宜編集 -
Makefile.amを作る -
その2つのファイルから、自動的にその他のファイルを生成:
autoreconf --install -
できあがった
configureファイルを試してみる:./configure --help ./configure make -
configure.acやMakefile.amを変更したらautoreconfで反映させる、を繰り返す
configure.ac
https://www.gnu.org/software/autoconf/manual/html_node/
configure.acの基本構造: https://www.gnu.org/software/autoconf/manual/html_node/Autoconf-Input-Layout.html- 標準マクロ: https://www.gnu.org/software/autoconf/manual/html_node/Autoconf-Macro-Index.html
- M4マクロ: https://www.gnu.org/software/autoconf/manual/html_node/M4-Macro-Index.html
Gitのタグをバージョン番号として取り込む:
AC_INIT([MyApp], m4_esyscmd([git describe --tags | tr -d '\n']))
Makefile.am
https://www.gnu.org/software/automake/manual/html_node/
- マクロ: https://www.gnu.org/software/automake/manual/html_node/Macro-Index.html
- 変数: https://www.gnu.org/software/automake/manual/html_node/Variable-Index.html
インストールするファイルと場所を指定する変数:
bin_PROGRAMS = beer
bin_SCRIPTS = beer.sh
lib_LIBRARIES = libbeer.a
include_HEADERS = beer.h
ビルドするのに必要な情報をターゲットごとに指定する変数。
target_ARGNAME のような形をとる:
beer_SOURCES = main.cpp
beer_CPPFLAGS = -DNDEBUG
beer_CXXFLAGS = -O3
libbeer_a_SOURCES = lib.cpp
Makefile 全体に関わる変数。
ただし上記のターゲット特異的変数に上書きされる:
AM_CPPFLAGS = -Wall -Wextra
AM_CXXFLAGS = -O2
ユーザーが指定する CPPFLAGS は
beer_CPPFLAGS や AM_CPPFLAGS を上書きせず、
後ろに並べて使用される。
https://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html