#!/bin/sh
#
# source: http://ftp.gnu.org/gnu/libtasn1/libtasn1-2.10.tar.gz
#
# maintainer: (package seek maintainer)
#

#------------------Set Some Variables

soft='libtasn1'
softversion='2.10'
packageversion='72.1'

arch='i486'
cpu='i686'

buildir=$(pwd)
srcpkg="$buildir/$soft-$softversion.tar.gz"
src="$buildir/$soft-$softversion"
package="$soft-$softversion-$arch-$packageversion"
dest="$buildir/$package"

cd $buildir
rm -rf $src
tar -xvzf $srcpkg
rm -f $dest.tgz
rm -rf $dest

#------------------Set correct permissions

cd $src
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 {} \;

#------------------Start Configure

export CFLAGS="-O2 -march=$arch -mtune=$cpu"
export CFXXLAGS="-O2 -march=$arch -mtune=$cpu"

./configure \
  --prefix=/usr \
  --sysconfdir=/etc \
  --localstatedir=/var \
  --mandir=/usr/man \
  --infodir=/usr/info \
  --disable-static

make -j4
make install DESTDIR=$dest

find $dest | xargs file | grep -e "executable" -e "shared object" | grep ELF \
  | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null

( cd $dest/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
)

gzip -9 $dest/usr/info/*

#-------------------Prepare the documentation

mkdir -p $dest/usr/doc/$soft-$softversion
cp -a AUTHORS ChangeLog COPYING* INSTALL NEWS README THANKS $dest/usr/doc/$soft-$softversion
#( cd $dest/usr/doc/$soft-$softversion
#  ln -s ../../share/gtk-doc/html/pygtk/ html
#)

#-----------------Make the slack-desc files

mkdir -p $dest/install
cat << EODESC > $dest/install/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-----------------------------------------------------|
libtasn1: libtasn1 - Library for ASN.1 and DER manipulation
libtasn1:
libtasn1: Libtasn is a library written in C for manipulating ASN.1 objects
libtasn1: including DER/BER encoding and DER/BER decoding. Libtasn is used by
libtasn1: GnuTLS to manipulate X.509 objects and by GNU Shishi to handle
libtasn1: Kerberos V5 packets
libtasn1:
libtasn1:
libtasn1:
libtasn1:
libtasn1:
EODESC


mkdir -p $dest/usr/src/$soft-$softversion
cp -a $buildir/build-$soft.sh $dest/usr/src/$soft-$softversion

#-------------------Make the packages and the md5sum

cd $dest
makepkg -l y -c n $dest.txz

cd $buildir
md5sum $package.txz > $package.md5