#!/bin/sh

if test $# != 2 -o $0 != "./install_gnupoc_uiq_30"; then
  echo "Usage: ./install_gnupoc_uiq_30 <path-to-sdk-zip> <target-dir>"
  echo " e.g.: ./install_gnupoc_uiq_30 UIQ3.0SDK.exe ~/symbian-sdks/uiq_30"
  exit 1
fi

SRC=$1
DEST=`echo $2 | sed s:/\$::`

mkdir -p $DEST

export PATH=7z:$PATH
# 7z must find the path to 7z.so
P7ZIP=`which 7z`

while read a
do
  echo "$a"
  sh -c "$a"
  if test $? != 0; then
    echo "Unexpected error: aborting."
    exit 1
  fi
done << __END


### Unzip
$P7ZIP x -y -o$DEST $SRC
rm -rf $DEST/\\\\\$*


### Fixing
./lowercase $DEST/epoc32/tools
./lowercase $DEST/epoc32/INCLUDE
./lowercase $DEST/epoc32/include
./lowercase $DEST/epoc32/release
./lowercase $DEST/epoc32/data
./fixinclude $DEST/epoc32/include
./lowercase $DEST/Examples
./fixinclude $DEST/examples
./fixexamples $DEST/examples
for i in \`find $DEST/epoc32/tools -name \\\*.pl -or -name \\\*.pm\`; do ./dos2unix \$i; done
cp -pR $DEST/epoc32/tools $DEST/epoc32/tools_orig
cat gnupoc-uiq_30-patch | (cd $DEST/epoc32; patch -p0 )
find $DEST/epoc32/tools -name \\\*.orig -exec rm {} \\\\;
cd $DEST/epoc32/tools; chmod a+x \*.pl bldmake abld makmake bmconv rcomp makesis epoc eshell petran pfsdump elf2e32 makekeys signsis extmake

__END

exit 0
