#!/bin/csh
# Make a port GNU-Darwin-like
if ( -f pkg-plist.old ) then
	goto statickize
endif
echo Darwinizing...
echo 'removing shared libraries from packing list'
grep -v 'lib\/lib' pkg-plist>dplist1
grep 'lib\/lib' pkg-plist |\
grep -v '\.so' > dplist2
echo 'adding any dynamic libraries to packing list'
grep 'lib\/lib' pkg-plist |\
sed s/'\.a'/'.*'/ |\
grep -v '\.so' |\
awk '{ print "/bin/ls -1 /usr/X11R6/"$1"|/usr/bin/sed s/'.usr.X11R6.'//| grep dylib >>dplist2" }' > getlibs
source getlibs
grep 'lib\/lib' pkg-plist |\
sed s/'\.a'/'.*'/ |\
grep -v '\.so' |\
awk '{ print "/bin/ls -1 /usr/local/"$1"|/usr/bin/sed s/'.usr.local.'//| grep dylib >>dplist2" }' > getlibs
source getlibs 
grep -v '\.so' dplist2  >>dplist1
#grep  '\.so' dplist2 |\
#grep -v "\.so.." |\
#sed s/'\.so'/'.a'/ >>dplist1
cp pkg-plist pkg-plist.old
sed s/'%%RUBY_SITELIBDIR%%'/'lib\/ruby\/site_ruby\/1.6'/ dplist1 |\
sed s/'%%RUBY_DOCDIR%%'/'share\/doc\/ruby'/ |\
sed s/'%%RUBY_ARCHLIBDIR%%'/'lib\/ruby\/1.6\/powerpc-darwin1.4.1'/ |\
sed s/'%%RUBY_LIBDIR%%'/'lib\/ruby\/1.6'/ |\
sed s/'%%_RUBY_SUFFIX%%'/'16'/ |\
sed s/'%%RUBY_NAME%%'/'ruby'/ |\
sed s/'%%GNOME:%%'/''/ |\
sed s/'%%DOC%%'/''/ |\
sed s/'%%X11%%'/''/ |\
sed s/'%%LOCALBASE%%'/''/ |\
sed s/'%%X11BASE%%'/''/ |\
sed s/'%%INFODIR%%'/'info'/ |\
sed s/'%%DATADIR%%'/'share'/ |\
sed s/'%%RUBY_EXAMPLESDIR%%'/'share\/examples\/ruby\/gdk_pixbuf'/ |\
sed s/'%%RUBY_SITEARCHLIBDIR%%'/'lib\/ruby\/site_ruby\/1.6\/powerpc-darwin1.4.1'/ |\
sed s/'%%PYTHON_VERSION%%'/'python2.0'/ |\
sed s/'%%PYTHON_SITELIBDIR%%'/'lib\/python2.2\/site-packages'/ |\
sed s/'%%PORTDOCS%%'// > dplist3
grep -v 'lib\/ruby' dplist3 |grep -v 'ruby\/gdk_pixbuf' > pkg-plist 
grep 'lib\/ruby' dplist3| sed s/'\.so'/'.bundle'/>> pkg-plist 
rm dplist1 dplist2 getlibs dplist3
rm -f work/.PLIST.mktmp

statickize:
if ( -f Makefile.old ) then
	exit
endif
echo "Darwininzing Makefile..."
cp Makefile Makefile.old
grep -v INSTALLS_SHLIB Makefile.old> Makefile
#echo "removing WRKSRC..."
#rm -rf work
