compress() {

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

for i in usr/bin usr/sbin bin sbin; do
  if [ -d $P/$i ]; then
  ( cd $P/$i 
    for j in * ; do
      chk=`file $j | grep "not stripped"`
      if [ ! "$chk.x" = ".x" ]; then
         echo "strip $j"
	 strip $j
      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

}

##################
# ftp://ftp.kddlabs.co.jp fedora 4 
src=mailx-8.1.1-44
pkgbase=mailx
vers=8.1.1_44
arch=i386
build=P1
pkg=`echo $pkgbase"-"$vers"-"$arch"-"$build".tgz"`

###################

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

cp ../flock.c .
patch -p1 < ../mailx-8.1.1.debian.patch
patch -p1 < ../mailx-8.1.1.security.patch
patch -p1 < ../mailx-8.1.1.nolock.patch
patch -p1 < ../mailx-8.1.1.debian2.patch
patch -p1 < ../mailx-noroot.patch
patch -p1 < ../mailx-nopanic.patch
patch -p1 < ../mailx-nullchar.patch
patch -p1 < ../mailx-8.1.1-fhs.patch
patch -p1 < ../mailx-8.1.1-environ.patch
patch -p1 < ../mailx-8.1.1-siglj.patch
patch -p1 < ../mailx-8.1.1-bug15728.patch
patch -p1 < ../mailx-8.1.1-bug10074.patch
patch -p1 < ../mailx-8.1.1-uidcheck.patch
patch -p1 < ../mailx-8.1.1-flock.patch
patch -p1 < ../mailx-8.1.1-nostrip.patch
patch -p1 < ../mailx-8.1.1-ctime.patch
patch -p1 < ../mailx-8.1.1-bug134837.patch
patch -p1 < ../mailx-8.1.1-manpage-fix.patch
patch -p1 < ../mailx-8.1.1-manfix.patch
patch -p1 < ../mailx-8.1.1-display.patch
patch -p1 < ../mailx-8.1.1-bug44798.patch
patch -p1 < ../mailx-8.1.1-bug58672.patch
patch -p1 < ../mailx-8.1.1-reproblem.patch
patch -p1 < ../mailx-8.1.1-mbproblem.patch
patch -p1 < ../mailx-8.1.1-unread.patch

make clean
rm -rf config.cache config.log
#./configure --prefix=/usr 
make

cd USD.doc
make
cd ..

compress

pwd
mkdir -p $P/etc
  cp misc/mail.rc $P/etc
mkdir -p $P/usr/share/man/man1
  cp *.1 $P/usr/share/man/man1
mkdir -p $P/usr/lib
  cp misc/mail.tildehelp $P/usr/lib
  cp misc/mail.help $P/usr/lib
mkdir -p $P/bin
mkdir -p $P/usr/bin
  strip mail
  cp mail $P/usr/bin/Mail
cd $P
  ln -sf $P/usr/bin/Mail $P/bin/Mail
  ln -sf $P/usr/bin/Mail $P/bin/mail
  ln -sf $P/usr/bin/Mail $P/bin/mailx
cd ..
mkdir -p $P/usr/share/doc/$src
for i in ../PlamoBuild.mailx-8.1.1-44 USD.doc/manual.ps ; do
  cp $i $P/usr/share/doc/$src
  gzip -f $P/usr/share/doc/$src/$i
done
  
cd $P
/sbin/makepkg $pkg << EOF
y
EOF

