autoconf automake libtoolをインストール

ずっとconfigureの書き方について検索していたらautoconfとツールに辿り着いた。あれは手書きじゃなかったのか?とりあえず入れておくと後々便利そうなのでインストールすることに、

因みに、私の環境ではgnu m4を別途インストールする必要があった、makeの時と同じで最小構成で入っているm4ではautoconfのインストールが出来なかった。libtoolの必要性は不明だが多くのサイトで3つを一緒に扱っているので念のためインストール

コマンドと順序は次の通り
# tar zxvf m4-1.4.4.tar.gz
# cd m4-1.4.4
# ./configure
# make
# make install

何も設定せずインストールされたのでシステムの/usr/bin/m4は上書きされず/usr/local/bin/m4としてインストールされたので/usr/bin/m4はリネームした。

# tar zxvf libtool-1.5.20.tar.gz
# cd libtool-1.5.20
# ./configure
# make
# make install

# tar zxvf autoconf-2.59.tar.gz
# cd autoconf-2.59
# ./configure
# make
# make install

# tar zxvf automake-1.9.tar.gz
# cd automake-1.9
# ./configure
# make
# make install

インストールできたので早速使ってみる。

ソースファイルがあるディレクトリで
> autoscan
autom4te: configure.ac: no such file or directory
autoscan: /usr/local/bin/autom4te failed with exit status: 1

これでconfigure.scanが作られるのでこれを参考にconfigure.acを作る。
> cat configure.scan

# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CONFIG_SRCDIR([bench.c])
AC_CONFIG_HEADER([config.h])

# Checks for programs.
AC_PROG_CC

# Checks for libraries.

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.
AC_OUTPUT

作ったconfigure.acは以下の内容
AC_PREREQ(2.59)
AC_INIT(bench, 1.0.0, no-define)
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([bench.c])
AC_PROG_CC
AC_OUTPUT(Makefile)

configure.acの作成が終わったら、Makefile.amの作成に入る。
> vi Makefile.am

bin_PROGRAMS = hello
hello_SOURCES = hello.c

ソース1個ならこれだけでOK
次に必要なファイルを準備するため(?)aclocalを使う。

> aclocal

これで*.m4ファイルなど自動生成。
そしてautomakeする。
> automake -a -c
configure.ac: installing `./install-sh’
configure.ac: installing `./missing’
Makefile.am: installing `./INSTALL’
Makefile.am: required file `./NEWS’ not found
Makefile.am: required file `./README’ not found
Makefile.am: required file `./AUTHORS’ not found
Makefile.am: required file `./ChangeLog’ not found
Makefile.am: installing `./COPYING’
Makefile.am: installing `./depcomp’

これでも4つ準備しなければいけないファイルがあるが唯のテキストなのでダミーで誤魔化す。

> touch NEWS
> touch README
> touch AUTHORS
> touch ChangeLog

> automake -a -c
これでautomakeが成功してMakefile.inが生成されたので最後にautoconfで仕上げる。
> autoconf
configureの出来上がり。

実際に使ってみた。
> ./configure
checking for a BSD-compatible install… /usr/bin/install -c
checking whether build environment is sane… yes
checking for gawk… no
checking for mawk… no
checking for nawk… nawk
checking whether make sets $(MAKE)… yes
checking for gcc… gcc
checking for C compiler default output file name… a.out
checking whether the C compiler works… yes
checking whether we are cross compiling… no
checking for suffix of executables…
checking for suffix of object files… o
checking whether we are using the GNU C compiler… yes
checking whether gcc accepts -g… yes
checking for gcc option to accept ANSI C… none needed
checking for style of include used by make… GNU
checking dependency style of gcc… gcc3
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands

> make
if gcc -DPACKAGE_NAME=”bench” -DPACKAGE_TARNAME=”bench” -DPACKAGE_VERSION=”1.0.0″ -DPACKAGE_STRING=”bench 1.0.0″ -DPACKAGE_BUGREPORT=”no-define” -DPACKAGE=”bench” -DVERSION=”1.0.0″ -I. -I. -g -O2 -MT hello.o -MD -MP -MF “.deps/hello.Tpo” -c -o hello.o hello.c; then mv -f “.deps/hello.Tpo” “.deps/hello.Po”; else rm -f “.deps/hello.Tpo”; exit 1; fi
gcc -g -O2 -o hello hello.o

試しに使ってみたし生成されたconfigureやMakefile.inをみてみたが大きすぎてカスタマイズの方法が探れなかった。1ソースなのに生成されるテキストでか過ぎ…。

Makefile書くのは今のところ困ってないので変数変換のカラクリを解析してautoconfのみするかconfigure直書きを目指してみよう。

Crontabを編集

昨日のntpの件があるので今日はcrontabを編集。
普通は使用するユーザーでcrontab -eで編集。ちなみに現在登録されている内容を見るのはcrontab -l

# crontab -e

下記のように追加して
0 * * * * /usr/sbin/ntpdate ntp.nict.jp

# crontab -l

# DO NOT EDIT THIS FILE – edit the master and reinstall.
# (/tmp/crontab installed on Tue Nov 29 21:14:30 2005)
# (Cron version — $FreeBSD: src/usr.sbin/cron/crontab/crontab.c,v 1.22 2004/09/14 19:01:19 dds Exp $)
0 * * * * /usr/sbin/ntpdate ntp.nict.jp

こんな風にファイルができます。
出来たファイルは/var/cron/tabs/rootです。rootの部分は作成したユーザーです。
これはFreeBSDの場合ですが、Redhatだと/var/spool/cron/rootという風に保存されるディレクトリが違います。

また、システムで使用するcrontabは/etc/crontabです。
とりあえず出力

# /etc/crontab – root’s crontab for FreeBSD
#
# $FreeBSD: src/etc/crontab,v 1.32 2002/11/22 16:13:39 tom Exp $
#
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
HOME=/var/log
#
#minute hour mday month wday who command
#
*/5 * * * * root /usr/libexec/atrun
#
# Save some entropy so that /dev/random can re-seed on boot.
*/11 * * * * operator /usr/libexec/save-entropy
#
# Rotate log files every hour, if necessary.
0 * * * * root newsyslog
#
# Perform daily/weekly/monthly maintenance.
1 3 * * * root periodic daily
15 4 * * 6 root periodic weekly
30 5 1 * * root periodic monthly
#
# Adjust the time zone if the CMOS clock keeps local time, as opposed to
# UTC time. See adjkerntz(8) for details.
1,31 0-5 * * * root adjkerntz -a

見たかぎりlinuxと同じような構成の部分がありますね。daily,weekly,monthlyの部分がBSDではperiodicを使い、/etc/periodic/以下にdaily,weekly,monthlyのディレクトリがあってその中にスクリプトを置いています。redhat linuxの場合は/etc/の下にcron.daily, cron.weekly, cron.monthlyとディレクトリがあってその中にスクリプトが入っています。

2013-03-14追記:
NTPサーバを福岡大学からNICTに変更しました。

時計あわせを忘れてた

今気づいたのがサーバーの時計が3分遅れていること、サーバーの時計が狂っているのは致命傷なのですぐに対策します。
運よくntpdateは入っていたのでこれを利用。

# ntpdate ntp.nict.jp

…とおもったらうまく行かない。ファイヤーウォールだな。

# vi /etc/ipf.rules
#ipf -Fa -Z -f /etc/ipf.rules

ちなみに使用しているのは123番ポートです。
あとはcrontabかな

2013-03-14追記:
当時の記事ではntpdateの指定先に福岡大学を指定してましたので、NICTに変更しました。

昔の話ですが福岡大学のNTPサーバが早くから公開されていて知名度もあったためか市販されているルータ機器の時刻合わせ先に福岡大学を指定している物がありアクセス集中による問題が発生していました。

今時はNICTですが、NICT内で負荷分散しているとは言え無闇に設定してアクセス集中させるのはよろしくないので、検証用のVPS等はリブートによる時刻修正か手動によるntpdateコマンド発行等にしましょう。VPSが時計のズレを起こしやすいのはしょうがないですが。。。