1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GNU Autotoolsを使う小規模ソフトウェアパッケージ作成のためのテンプレート生成

Posted at

小規模ソフト作成のためのテンプレート生成

動機

ちょっとしたひとまとまりのソフトウェアを書く際、ある程度体裁の整ったコンパイル/インストール手順を用意するのは、ルーチンワーク的な側面が大きいがちょっとした手間である。その作業を定式化・省力化のためGNU autotools (Autoconf, Libtool, Automake)を使うのだが、configure.ac,Makefile.amの書き方やファイルの配置にはちょっと取っつきづらい/覚えづらい流儀があり、毎回調べる/昔の書いた物をコピーして書き換える手間が発生していた。もうひと手間減らすため、テンプレートから最低限のスケルトンを生成する作業をスクリプトにより自動化した。

ファイルの置き場

インストール

依存するソフトウェア

  • GNU autoconf, GNU libtool, GNU automake: (macportsでlibtoolizeがglibtoolizeという名前でインストールされているのには対応した。)
  • Bashと Sed, findなど一般的なUNIXコマンド

インストール手順

  • 上記gitレポジトリからファイルをダウンロードして展開。
  • ./configure --prefix=/somewhere/proper/directory/からのmake installで、/somewhere/proper/directory/bin/prep_develop_skelton.shが出来ているはず。

使い方

  • prep_develop_skelton.sh -hで使い方が表示される。新しいソフトウェアパッケージにつけたい名前を引数にして、ファイルを用意する場所などをオプション引数として実行する。-sオプションをつけると、subversionでのバージョン管理を想定して、branches,tags,trunkのサブディレクトリを作成。
prep_develop_skelton.sh実行例
% prep_develop_skeleton.sh -h
[Usage] % prep_develop_skeleton.sh [options] project_name
[Options]
           -p prefix      : Set destenation directory
           -d description : Set the description of the project
           -a author_name : Set author name
           -c address     : Set bug report address
           -u url         : Set reference URL
           -v version     : Set initial version number
           -s             : Use Subversion directory structure (trunk/branches/tags)
           -V             : Show verbose output
           -h             : Show Help (this message)

% prep_develop_skeleton.sh -p /somewhere/tmp/wwwwww -d 'Sample' -a 'Nanigashi_Uji' -c 'aaa@yyy.zzz' -u 'http://www.yyy.zzz/software/' -s -V sample_of_sample
Project name:                    sample_of_sample
                                 SAMPLE_OF_SAMPLE
Skeleton will be created under:  /somewhere/tmp/wwwwww
Description:                     Sample
author:                          Nanigashi_Uji
Contact address:                 aaa@yyy.zzz
URL:                             http://www.yyy.zzz/software/
version:                         0.0.1
directory structure              SVN (trunk/branches/tags)
glibtoolize: putting auxiliary files in '.'.
glibtoolize: copying file './config.guess'
glibtoolize: copying file './config.sub'
glibtoolize: copying file './install-sh'
glibtoolize: copying file './ltmain.sh'
glibtoolize: Consider adding 'AC_CONFIG_MACRO_DIRS([m4])' to configure.ac,
glibtoolize: and rerunning glibtoolize and aclocal.
glibtoolize: Consider adding '-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
glibtoolize: 'AC_PROG_RANLIB' is rendered obsolete by 'LT_INIT'
configure.ac:12: installing './compile'
configure.ac:6: installing './missing'
Makefile.am: installing './INSTALL'
Makefile.am: installing './COPYING' using GNU General Public License v3 file
Makefile.am:     Consider adding the COPYING file to the version control system
Makefile.am:     for your code, to avoid questions about which license your project uses
src/Makefile.am: installing './depcomp'
/somewhere/tmp/wwwwww/sample_of_sample

  • 上記の実行例では、-pオプションで指定したディレクトリ以下にテンプレートが生成される。おもに下記のファイルを編集していくことになる。(-sオプションなしで実行したばあい、'trunk'というサブディレクトリは省略され、一段上のディレクトリに生成される)

    • trunk/configure.ac,trunk/Makefile.am: パッケージ全体の設定。./configureのオプションの追加や、パッケージのサブディレクトリの追加/削除などはこれらを編集する。
    • trunk/src/Makefile.am,trunk/src/sample_of_sample.cc,trunk/src/libsample_of_sample.cc: C++によるmainプログラムのソースと、ライブラリ関数のソースと、そのコンパイル設定のスケルトン。
    • trunk/include/Makefile.am,trunk/include/sample_of_sample/sample_of_sample.h: ライブラリ関数のヘッダファイルのスケルトン
    • trunk/bin/Makefile.am,trunk/bin/sample_of_sample.sh.in:スクリプトファイルのスケルトン。生成されるのは単なるC++プログラムを呼び出すラッパーのシェルスクリプトだが、その他python,perlなどのスクリプトもここに作成しておいていく。
    • trunk/share/Makefile.am,trunk/share/sample_of_sample.txt: 設定ファイルやデータファイルなど、ソフトウェアから読み込んだりする各種データファイルの配置例。

configure.acの編集例

configure.acに依存するライブラリの設定を追加していく部分をテンプレートするうまい方法を模索中。とりあえず、prep_develop_skeletonをインストールした先のshare/prep_develop_skeleton/samples以下に追記するサンプル例を溜めていくことにした。とりあえず、linuxでは標準的だがmacOSには入っていないpoptライブラリを指定するサンプルconfigure.ac.libpoptだけが置いてある。他の例も追加していければいいかなと思っている。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?