#!/bin/sh
#
# fix
#
case `uname` in
	*Linux* )
		echo "Fixing Teddy from Win32 to Linux"

		echo "Fix file names"
        if test -f authors ; then
            mv authors AUTHORS
        fi
		if test -f bugs ; then
			mv bugs BUGS
		fi
		if test -f readme ; then
			mv readme README
		fi
		if test -f TeddyTests/readme ; then
			mv TeddyTests/readme TeddyTests/README
		fi

		echo "Fix permissions"
		dirs=`find . -type d`
        chmod -R u+rwx *
		chmod -R a-x `find . -type f`
		for dir in ${dirs}; do
        	chmod u+x ${dir}
		done
		chmod u+x fix

		echo "Fix source and script line endings"
		source_files=`find . -name '*.cpp' -o -name '*.c' -o -name '*.h'`
		shell_files=`find . -name 'bootstrap' -o -name 'mkinstalldirs' -o -name 'install-sh' -o -name 'missing' -o -name 'conf'`
		config_files=`find . -name '*.in' -o -name 'config*' -o -name '*.m4'`
		for file in ${source_files} ${shell_files} ${config_files}; do
        	perl -i -pe 's/\r\n?/\n/' ${file}
		done
        chmod u+x ${shell_files}

		echo "Running bootstrap script"
		sh bootstrap
		;;


	*cygwin*)
		echo "Cygwin system - fix needs not known"
		;;
	*)
		echo "Unknown system - fix needs not known"
		;;
esac

