#!/bin/bash
####################################################################
#                  mkGpatch                                        #
####################################################################

if [ -z "$1" ] || [ "$1" = "-h" ] || [ "$2" = "-h" ] ; then
   echo "---------------------------------------------------------------------"
   echo "Purpose: Generation of a GNUpatch"
   echo "Usage  : mkGpatch [ -h ] old new"
   echo " -p" use the full directory name, rather than the version-numbers.
   echo " -h" print this help text.
   echo " "
   echo "  'old' and 'new' are version-numbers, e.g 82.1 "
   echo "  Takes the differences between mctdhold and mctdhnew and "
   echo "  produces the g-zipped file GNUpatch-old-new.gz"
   echo "  Example: mkGpatch 82.0 82.1   or   mkGpatch -p mctdh.old mctdh.new"
   echo "---------------------------------------------------------------------"
   exit
fi

pwd=`pwd`

if [ "$1" = "-p" ] ; then
   dir1=$pwd/$2
   dir2=$pwd/$3
   if [ -z "${2##/*}" ] ; then dir1=$2 ; fi
   if [ -z "${3##/*}" ] ; then dir2=$3 ; fi
   file=`echo GNUpatch-$2-$3 | tr '/' '.'`
   file=$pwd/$file
else
   dir1=$pwd/mctdh$1
   dir2=$pwd/mctdh$2
   file=$pwd/GNUpatch-$1-$2
fi

if [ ! -d $dir1 ] ; then
   echo "old: $dir1 does not exist!"
   exit
fi
if [ ! -d $dir2 ] ; then
   echo "new: $dir2 does not exist!"
   echo "taking $MCTDH_DIR"
   dir2=$MCTDH_DIR
fi
if [  -f $file ] ; then
   echo "$file already exist! STOP!"
   exit
fi


LC_ALL=C TZ=UTC0 diff -Naur --exclude='.*mctdhall.*' --exclude='mctdhall*' \
 --exclude='paths.inc' --exclude='platform.cnf*' --exclude='compile.cnf' \
 --exclude='*~' --exclude='*_bk*' --exclude='*_md*' --exclude='addsurf*.*' \
 --exclude='MCTDH_client' --exclude='obsolete' --exclude='*.prcs*' \
 --exclude='doc/examples/.svn/*' --exclude='/.svn/*' --exclude='bin/binary' \
 --exclude='install/MCTDH_IFORT_*' --exclude='install/MCTDH_client' \
 --exclude='.nfs*' --exclude='*.pyc*' $dir1 $dir2 > $file

gzip  $file

exit
