compress() {
for i in $P/usr/lib $P/lib ; do
  echo "compressing $i"
  if [ -d $i ]; then
    ( cd $i
      for j in *.so* ; do
	echo "j:$j"
	if [ ! -L $j ]; then
          chk=`file $j | grep "not stripped"`
          if [ ! "$chk.x" = ".x" ]; then
             echo "stripping -g $j"
             strip -g $j
          fi
        fi
      done
      for j in *.a ; do
         chk=`file $j | grep "ar archive"`
         if [ ! "$chk.x" = ".x" ]; then
           echo "ranlib and stripping -g $j"
           ranlib $j
           strip -g $j
         fi
      done
    )
  fi
done

for i in $P/usr/bin $P/usr/sbin $P/bin $P/sbin ; do
  echo "compressing $i"
  if [ -d $i ]; then
  ( cd $i 
    for j in * ; do
	echo "j:$j"
      if [ ! -L $j ]; then
        chk=`file $j | grep "not stripped"`
        if [ ! "$chk.x" = ".x" ]; then
           echo "stripping $j"
	   strip $j
        fi
      fi
    done
  )
  fi
done

for i in 1 2 3 4 5 6 7 8 ; do
  if [ -d $P/usr/share/man/man$i ]; then
     ( cd $P/usr/share/man/man$i ; 
       for j in *.$i ; do
         if [ -h $j ] ; then
           LN_TARGET=`ls -l $j | awk '{print $11}'`
           rm $j
           ln -sf $LN_TARGET.gz $j.gz
         else
           gzip $j
         fi
       done
     )
  fi
done
}

###################
# http://www.crypticide.org/users/alecm/security/cracklib,2.7.tar.gz
# http://www.cotse.com/wordlists/japanese
source=cracklib,2.7
src=cracklib,2.7
pkgbase=cracklib
vers=2.7
arch=i386
build=P3
pkg=`echo $pkgbase"-"$vers"-"$arch"-"$build".tgz"`
PLAMO_DICTPATH="/usr/share/dict"
PLAMO_DICTNAME="cracklib_dict"
###################

P=`pwd`/work
rm -rf $P
mkdir -p $P/usr

if [ -f Makefile ]; then
  make clean
fi

if [ -f config.cache -o -f config.log ]; then
  rm -f config.cache config.log
fi

make DICTPATH=$PLAMO_DICTPATH"/"$PLAMO_DICTNAME all
make DICTPATH=$PLAMO_DICTPATH"/"$PLAMO_DICTNAME install

# this will needs root permission
mkdir -p $P/usr/lib
cp cracklib/libcrack.a $P/usr/lib
ranlib $P/usr/lib/*

mkdir -p $P/usr/sbin
cp util/{mkdict,packer,unpacker} $P/usr/sbin

mkdir -p $P/$PLAMO_DICTPATH
./util/mkdict ../japanese | ./util/packer $P/$PLAMO_DICTPATH"/"$PLAMO_DICTNAME

mkdir -p $P/usr/share/doc/$src
for i in HISTORY LICENCE MANIFEST POSTER README ; do
  cp ../$src/$i $P/usr/share/doc/$src/$i
  gzip -f $P/usr/share/doc/$src/$i
done
cp ../PlamoBuild.cracklib,2.7 $P/usr/share/doc/$src

compress

cd $P
/sbin/makepkg $pkg << EOF
y
EOF
