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://kddlabs.co.jp....fedora/1/...
src=pmake-1.45-16
pkgbase=pmake
vers=1.45-16
arch=i386
build=P1
pkg=`echo $pkgbase"-"$vers"-"$arch"-"$build".tgz"`

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

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

patch -p1 < ../pmake-1.45-mktemp.patch
patch -p1 < ../pmake-1.45-zeroinit.patch
patch -p1 < ../pmake-1.45-dotdirs.patch

make -f Makefile.boot clean
rm -rf config.cache config.log
#./configure --prefix=/usr 
make -f Makefile.boot CFLAGS="${RPM_OPT_FLAGS} -D__COPYRIGHT\(x\)= -D__RCSID\(x\)= \
    -I. -DMACHINE=\\\"plamo\\\" -DMACHINE_ARCH=\\\"i386\\\"" CC=gcc
# make -f Makefile.boot -DMACHINE=\"plamo\" -DMACHINE_ARCH=\"`arch`\"" CC=gcc
#make -f Makefile.boot
# make install prefix=$P/usr

compress

mkdir -p $P/usr/bin
 strip bmake
 cp bmake $P/usr/bin/pmake
mkdir -p $P/usr/share/man/man1
 cp make.1 $P/usr/share/man/man1/pmake.1
mkdir -p $P/usr/share/doc/$src
for i in ../PlamoBuild.pmake-1.45-16 mk/* ; do
  cp $i $P/usr/share/doc/$src
  gzip -f $P/usr/share/doc/$src/$i
done
mkdir -p $P/usr/share/doc/$src/mk
  cp mk/* $P/usr/share/doc/$src/mk

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

