1#!/bin/sh 2 3set -u 4set -e 5trap onexit INT 6trap onexit TERM 7trap onexit EXIT 8 9TMPDIR= 10SUDO= 11 12onexit() 13{ 14 if [ ! "$TMPDIR" = "" ]; then 15 $SUDO rm -rf $TMPDIR 16 fi 17} 18 19uid() 20{ 21 id | cut -f2 -d = | cut -f1 -d \(; 22} 23 24safedirmove () 25{ 26 if [ "$1" = "$2" ]; then 27 return 0 28 fi 29 if [ "$1" = "" -o ! -d "$1" ]; then 30 echo safedirmove: source dir $1 is not valid 31 return 1 32 fi 33 if [ "$2" = "" -o -e "$2" ]; then 34 echo safedirmove: dest dir $2 is not valid 35 return 1 36 fi 37 if [ "$3" = "" -o -e "$3" ]; then 38 echo safedirmove: tmp dir $3 is not valid 39 return 1 40 fi 41 mkdir -p $3 42 mv $1/* $3/ 43 rmdir $1 44 mkdir -p $2 45 mv $3/* $2/ 46 rmdir $3 47 return 0 48} 49 50makedeb() 51{ 52 SUPPLEMENT=$1 53 DIRNAME=$PKGNAME 54 55 if [ $SUPPLEMENT = 1 ]; then 56 PKGNAME=$PKGNAME\32 57 DEBARCH=amd64 58 fi 59 60 umask 022 61 rm -f $PKGNAME\_$VERSION\_$DEBARCH.deb 62 TMPDIR=`mktemp -d /tmp/$PKGNAME-build.XXXXXX` 63 mkdir $TMPDIR/DEBIAN 64 65 if [ $SUPPLEMENT = 1 ]; then 66 make install DESTDIR=$TMPDIR 67 rm -rf $TMPDIR$BINDIR 68 if [ "$DATAROOTDIR" != "$PREFIX" ]; then 69 rm -rf $TMPDIR$DATAROOTDIR 70 fi 71 if [ "$JAVADIR" != "" ]; then 72 rm -rf $TMPDIR$JAVADIR 73 fi 74 rm -rf $TMPDIR$DOCDIR 75 rm -rf $TMPDIR$INCLUDEDIR 76 rm -rf $TMPDIR$MANDIR 77 else 78 make install DESTDIR=$TMPDIR 79 if [ "$PREFIX" = "@CMAKE_INSTALL_DEFAULT_PREFIX@" -a "$DOCDIR" = "@CMAKE_INSTALL_DEFAULT_PREFIX@/doc" ]; then 80 safedirmove $TMPDIR/$DOCDIR $TMPDIR/usr/share/doc/$PKGNAME-$VERSION $TMPDIR/__tmpdoc 81 ln -fs /usr/share/doc/$DIRNAME-$VERSION $TMPDIR$DOCDIR 82 fi 83 fi 84 85 SIZE=`du -s $TMPDIR | cut -f1` 86 (cat pkgscripts/deb-control | sed s/{__PKGNAME}/$PKGNAME/g \ 87 | sed s/{__ARCH}/$DEBARCH/g | sed s/{__SIZE}/$SIZE/g \ 88 > $TMPDIR/DEBIAN/control) 89 90 /sbin/ldconfig -n $TMPDIR$LIBDIR 91 92 $SUDO chown -Rh root:root $TMPDIR/* 93 dpkg -b $TMPDIR $PKGNAME\_$VERSION\_$DEBARCH.deb 94} 95 96PKGNAME=@PKGNAME@ 97VERSION=@VERSION@ 98DEBARCH=@DEBARCH@ 99PREFIX=@CMAKE_INSTALL_PREFIX@ 100BINDIR=@CMAKE_INSTALL_FULL_BINDIR@ 101DATAROOTDIR=@CMAKE_INSTALL_FULL_DATAROOTDIR@ 102DOCDIR=@CMAKE_INSTALL_FULL_DOCDIR@ 103INCLUDEDIR=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 104JAVADIR=@CMAKE_INSTALL_FULL_JAVADIR@ 105LIBDIR=@CMAKE_INSTALL_FULL_LIBDIR@ 106MANDIR=@CMAKE_INSTALL_FULL_MANDIR@ 107 108if [ ! `uid` -eq 0 ]; then 109 SUDO=sudo 110fi 111 112makedeb 0 113if [ "$DEBARCH" = "i386" ]; then makedeb 1; fi 114 115exit 116