#!/bin/bash

#
# Copyleft 2004-06-28 
# Thomas (at the host) kuehne.cn
#
# setup DMD v0.94 (digitalmars.com) on a linux box and
# patch the included phobos linux.mak files
#

if(echo $@ | grep -i "dmd" | grep -i "\\.zip$") then
    echo "dummy" > /dev/null
else
    echo "require argument: \"/path/to/dmd.zip\""
    exit -1
fi

unzip -o "$@"

PWD=`pwd`

patch -p0 << EOF
diff -ur dmd/bin/dmd.conf ../dmd/bin/dmd.conf
--- dmd/bin/dmd.conf	2003-05-12 02:07:40.000000000 +0200
+++ ../dmd/bin/dmd.conf	2004-06-10 10:57:27.764007296 +0200
@@ -1,4 +1,4 @@
 
 [Environment]
 
-DFLAGS=-I/home/wgb/yourname/dmd/src/phobos
+DFLAGS=-I$PWD/dmd/src/phobos
EOF

chmod -v guo-w+rx dmd/bin/dmd dmd/bin/obj2asm dmd/bin/dumpobj

rm -f dmd_sys_install.sh
cat << EOF > dmd_sys_install.sh
rm -vf /usr/local/bin/dmd /usr/local/bin/dumpobj /usr/local/bin/obj2asm
ln -vs $PWD/dmd/bin/dmd /usr/local/bin/dmd
ln -vs $PWD/dmd/bin/dumpobj /usr/local/bin/dumpobj
ln -vs $PWD/dmd/bin/obj2asm /usr/local/bin/obj2asm
rm -vf /usr/local/lib/libphobos.a 
ln -vs $PWD/dmd/lib/libphobos.a /usr/local/lib/libphobos.a
rm -vf /etc/dmd.conf
ln -vs $PWD/dmd/bin/dmd.conf /etc/dmd.conf
EOF

chmod +x ./dmd_sys_install.sh

echo ""
echo "as superuser do in the current dir:"
echo "   ./dmd_sys_install.sh"
