1#!/bin/sh
2
3set -u
4set -e
5trap onexit INT
6trap onexit TERM
7trap onexit EXIT
8
9TMPDIR=
10
11onexit()
12{
13	if [ ! "$TMPDIR" = "" ]; then
14		rm -rf $TMPDIR
15	fi
16}
17
18safedirmove ()
19{
20	if [ "$1" = "$2" ]; then
21		return 0
22	fi
23	if [ "$1" = "" -o ! -d "$1" ]; then
24		echo safedirmove: source dir $1 is not valid
25		return 1
26	fi
27	if [ "$2" = "" -o -e "$2" ]; then
28		echo safedirmove: dest dir $2 is not valid
29		return 1
30	fi
31	if [ "$3" = "" -o -e "$3" ]; then
32		echo safedirmove: tmp dir $3 is not valid
33		return 1
34	fi
35	mkdir -p $3
36	mv $1/* $3/
37	rmdir $1
38	mkdir -p $2
39	mv $3/* $2/
40	rmdir $3
41	return 0
42}
43
44PKGNAME=@PKGNAME@
45VERSION=@VERSION@
46BUILD=@BUILD@
47
48PREFIX=@CMAKE_INSTALL_PREFIX@
49DOCDIR=@CMAKE_INSTALL_FULL_DOCDIR@
50LIBDIR=@CMAKE_INSTALL_FULL_LIBDIR@
51
52umask 022
53rm -f $PKGNAME-$VERSION-$BUILD.tar.bz2
54TMPDIR=`mktemp -d /tmp/ljtbuild.XXXXXX`
55__PWD=`pwd`
56make install DESTDIR=$TMPDIR/pkg
57if [ "$PREFIX" = "@CMAKE_INSTALL_DEFAULT_PREFIX@" -a "$DOCDIR" = "@CMAKE_INSTALL_DEFAULT_PREFIX@/doc" ]; then
58	safedirmove $TMPDIR/pkg$DOCDIR $TMPDIR/pkg/usr/share/doc/$PKGNAME-$VERSION $TMPDIR/__tmpdoc
59	ln -fs /usr/share/doc/$PKGNAME-$VERSION $TMPDIR/pkg$DOCDIR
60fi
61cd $TMPDIR/pkg
62tar cfj ../$PKGNAME-$VERSION-$BUILD.tar.bz2 *
63cd $__PWD
64mv $TMPDIR/*.tar.bz2 .
65
66exit 0
67