小規模ソフト作成のためのテンプレート生成
動機
ちょっとしたひとまとまりのソフトウェアを書く際、ある程度体裁の整ったコンパイル/インストール手順を用意するのは、ルーチンワーク的な側面が大きいがちょっとした手間である。その作業を定式化・省力化のためGNU autotools (Autoconf, Libtool, Automake)を使うのだが、configure.ac,Makefile.amの書き方やファイルの配置にはちょっと取っつきづらい/覚えづらい流儀があり、毎回調べる/昔の書いた物をコピーして書き換える手間が発生していた。もうひと手間減らすため、テンプレートから最低限のスケルトンを生成する作業をスクリプトにより自動化した。
ファイルの置き場
- https://github.com/nanigashi-uji/prep_develop_skeleton
- https://gitlab.com/nanigashi_uji/bash_script_skeleton
インストール
依存するソフトウェア
- 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_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
だけが置いてある。他の例も追加していければいいかなと思っている。