autotools + 使い方

autotools + 使い方

autotools の基本的な使い方をざっくばらんにメモ。

テスト用のディレクトリを作成する

$ mkdir autotool  
$ cd autotool  

適当にソースコードを記述する

$ vi main.cpp
#include  
int main()  
{  
       puts("hello autotool.");  
       return0;  
}  

autoscan を実行する

$ autoscan  

出来た configure.scan をconfigure.ac に名称変更

$ mv configure.scan configure.ac  

configure.ac を編集する。

$ vi configure.ac  

AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS) を編集。
automake を使うので AM_INIT_AUTOMAKE を追加。
AC_CONFIG_FILES([Makefile]) を追加。

# -*- Autoconf -*-  
# Process this file with autoconf to produce a configure script.  
AC_PREREQ(2.61)  
AC_INIT( hoge-pkg,0.1, hoge@mail.com)  
AC_CONFIG_SRCDIR([main.cpp])  
AC_CONFIG_HEADER([config.h])  
AM_INIT_AUTOMAKE # automakeを使うので追加  
# Checks for programs.  
AC_PROG_CXX  
# Checks for libraries.  
# Checks for header files.  
# Checks for typedefs, structures, and compiler characteristics.  
# Checks for library functions.  
AC_CONFIG_FILES([Makefile])  
AC_OUTPUT  

Makefile.am を作成する

$ vi Makefile.am  
bin_PROGRAMS = hello  
hello_SOURCES = main.cpp  

aclocal を実行する

$ aclocal  

autoheader を実行する

$ autoheader  

automake を実行する

$ automake -a -c  

-a は、足りないファイルを追加してくれるオプション
-c は、上のファイルをコピーしてくれるオプション。

もし足りないファイルがあると言われたら
昔の automake を使うと./ChangeLog' not found などと言われる事がある。
そんなときは、空で良いので同名のファイルを作ってあげる。

$ touch README AUTHORS ChangeLog NEWS  

autoconf を実行する

$ autoconf  

configure する

$ ./configure  

make する

$ make  

出来たバイナリを実行してみる

$ ./hello  
hello autotool.  

配布したい場合

$ make dist  

おしまい

以上、簡単な導入でした。

明日以降、–with オプションの付け方をメモする。