msizの日記

ソフトウェア関係の覚え書きが中心になる予定

groonga 4.0.0 のSlackBuildを作ってみました

毎月29日の「肉の日」にリリースを繰り返してる、全文検索ソフトウェア「groonga」が、2月9日の、年に一度の「肉の日」に、メジャーバージョンをアップしたリリースを出しました。

新バージョンをSlackware系でも導入できるよう、SlackBuildを作ってみました。

#!/bin/sh
#
# Slackware build (SlackBuild) script for groonga
#
# Written by msizu@example.net <msiz@example.net>

#--------------------------------------------------
# variables setup

PRGNAM=groonga
VERSION=${VERSION:-4.0.0}
ARCH=${ARCH:-i486}		# this should not change
BUILD=${BUILD:-1}
TAG=${TAG:-_msiz}		# use "_SBo" for slackbuilds.org

CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}	# use "/tmp/SBo" for slackbuilds.org
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}	# Drop the package in /tmp
PKGTYPE=${PKGTYPE:-txz}

SRCTAR=${SRCTAR:- http://packages.groonga.org/source/groonga/groonga-${VERSION}.tar.gz}

if [ "$ARCH" = "i386" ]; then
  SLKCFLAGS="-O2 -march=i386 -mtune=i686"
elif [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "i586" ]; then
  SLKCFLAGS="-O2 -march=i586 -mtune=i686"
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2 -fPIC"
fi

#--------------------------------------------------
# for debug
#
set -e # Exit on most errors
# If you prefer to do selective error checking with 
#   command || exit 1
# then that's also acceptable.


#--------------------------------------------------
## check if there is source file and download if necessary

cd $CWD
if [ ! -e `basename $SRCTAR` ]; then
  curl -O $SRCTAR || \
  wget $SRCTAR || \
  ( echo "Both wget and curl were not able to download source file." && exit 1 )
fi

#--------------------------------------------------
## working directories setup

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$VERSION


#--------------------------------------------------
## extract sources

tar xzvf $CWD/$PRGNAM-$VERSION.tar.gz
cd $PRGNAM-$VERSION
chown -R root:root .
find . \
 \( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \
 -exec chmod 755 {} \; -o \
 \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \
 -exec chmod 644 {} \;


#--------------------------------------------------
## configure and compile sources

# Your application will probably need different configure flags; these
# are provided as an example only.  Be sure to build only shared
# libraries unless there's some need for static.
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure \
  --prefix=/usr \
  --sysconfdir=/etc \
  --localstatedir=/var \
  --mandir=/usr/man \
  --docdir=/usr/doc/$PRGNAM-$VERSION \
  --build=$ARCH-slackware-linux

# Compile the application and install it into the $PKG directory
make

#----------------------------------------------------------------------
make check
make install DESTDIR=$PKG


#----------------------------------------------------------------------
## some arrangement for packaging

# Strip binaries and libraries--this can be done with "make install-strip"
# in many source trees, and that's usually acceptable if so, but if not,
# use this:
( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | \
    xargs strip --strip-unneeded 2> /dev/null || true
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | \
    xargs strip --strip-unneeded 2> /dev/null || true
)

# Compress man pages.  If the man pages are installed to /usr/share/man
# instead, you'll need to either add the --mandir=/usr/man flag to
# configure or move them manually after the make install process is run.
if [ -d $PKG/usr/man ]; then
  ( cd $PKG/usr/man
    find . -type f -exec gzip -9 {} \;
    for i in $( find . -type l ) ; do ln -s $( readlink $i ).gz $i.gz ; rm $i ; done
  )
fi

# Compress info pages and remove the package's dir file.  If no info
# pages are installed by the software, don't leave this in the script.
if [ -d $PKG/usr/info ]; then
  rm -f $PKG/usr/info/dir
  gzip -9 $PKG/usr/info/*.info*
fi

# Remove perllocal.pod and other special files that don't need to be
# installed, as they will overwrite what's already on the system.  If
# this is not needed, remove it from the script.
( cd $PKG
  # Remove "special" files
  find . -name perllocal.pod \
    -o -name ".packlist" \
    -o -name "*.bs" \
    | xargs rm -f
)


#----------------------------------------------------------------------
## install documents

# Copy program documentation into the package.  The included
# documentation varies from one application to another, so be sure to
# adjust your script as needed.  Also, include the SlackBuild script in
# the documentation directory.
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a \
  AUTHORS COPYING ChangeLog INSTALL NEWS README \
  $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild


#----------------------------------------------------------------------
## package creation

## Copy the slack-desc (and a custom doinst.sh if necessary) into ./install
mkdir -p $PKG/install
#cat $CWD/slack-desc > $PKG/install/slack-desc
#cat $CWD/doinst.sh > $PKG/install/doinst.sh

cat > $PKG/install/slack-desc <<END_OF_SLACK_DESC
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description.  Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in.  You must
# make exactly 11 lines for the formatting to be correct.  It's also customary
# to leave one space after the ':'.

       |-----handy-ruler-----------------------------------------------------|
groonga: groonga (Groonga is a fast and accurate full text search engine)
groonga: 
groonga: Groonga is a fast and accurate full text search engine based on
groonga: inverted index. One of the characteristics of Groonga is that a
groonga: newly registered document instantly appears in search results. Also,
groonga: Groonga allows updates without read locks. These characteristics
groonga: result in superior performance on real-time applications.
groonga: 
groonga: http://groonga.org/
groonga: 
groonga: 
END_OF_SLACK_DESC


# Make the package; be sure to leave it in $OUTPUT.  If package symlinks
# need to be created during install *before* your custom contents of
# doinst.sh runs, then add the -p switch to the makepkg command below--
# see makepkg(8) for details.
cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE

仮に「groonga.SlackBuild」と保存したら、fakerootを使って、もしくはrootになって実行したら、開発環境が整っていれば「/tmp/groonga-4.0.0-i486-1_msiz.txz」ファイルができてると思います。

ビルドはこんな感じ。

 time fakeroot sh -x ./groonga.SlackBuild

インストールは、できあがったパッケージをslackwareのコマンドで(rootで実行)。

installpkg /tmp/groonga-4.0.0-i486-1_msiz.txz

ちなみに、環境変数VERSIONを指定すれば、別のバージョンもビルドできるはずです。
こんな感じで。

env VERSION=3.1.2 time fakeroot sh -x ./groonga.SlackBuild

試す環境ないので、64bitでもうまくいくかは未確認です。
余談ですが、groongaはclangだとビルドできない…