#!/bin/sh

fixunix()
{
echo Configuring AllegroGL to build on Unix...

find . -type f "(" \
   -name "*.c" -o -name "*.cfg" -o -name "*.cpp" -o -name "*.dep" -o \
   -name "*.h" -o -name "*.hin" -o -name "*.in" -o -name "*.inc" -o \
   -name "*.m4" -o -name "*.mft" -o -name "*.s" -o -name "*.sh" -o \
   -name "*.spec" -o -name "*.pl" -o -name "*.txt" -o -name "*._tx" -o \
   -name "makefile.*" -o -name "readme.*" \
   ")" \
   -exec sh -c "misc/dtou.sh {}" \;

mkdir -p obj/unix/debug obj/unix/release lib/unix

echo Done.
echo
echo "Run './configure' to configure ('./configure --help' for help)."
echo "Then run 'make' to build, and 'make install' to install."
echo
echo "(If this is a CVS version, you must run 'autoconf' to generate the"
echo "configure script.)"
echo
}

proc_fix()
{
echo "Configuring AllegroGL for $1..."
echo "# generated by fix.sh" > makefile
case "$1" in
	MSVC )
		echo "Notice: Because no version was specified, MSVC 6 has been chosen."
		echo ""
		echo "If you are using a newer version, you should use 'msvc7' or 'msvc8' instead."
		echo "msvc7 should be used for MSVC .NET or MSVC .NET 2003"
		echo "msvc8 should be used for MSVC .NET 2005"
		echo ""
		echo "COMPILER_MSVC6 = 1" >> makefile;;
	MSVC6) echo "COMPILER_MSVC6 = 1" >> makefile;;
	MSVC7) echo "COMPILER_MSVC7 = 1" >> makefile;;
	MSVC8) echo "COMPILER_MSVC8 = 1" >> makefile;;
esac
echo "include make/$2" >> makefile
echo ""
echo "Done!"
echo ""
}

display_help()
{
echo "Compilation target adjustment."
echo "  Usage: fix <platform> [--dtou|--utod|--quick]"
echo ""
echo "  <platform> is one of: djgpp, mingw32, msvc6, msvc7, msvc8, unix, macosx"
echo ""
echo "  --dtou converts from DOS/Win32 format to Unix"
echo "  --utod converts from Unix format to DOS/Win32"
echo "  --quick does no line ending conversion"
echo "  If no parameter is specified --dtou is assumed"
echo ""
echo "  Example: fix unix --quick"
echo ""
}

dtou()
{
	find docs include misc src -type f -exec sh misc/dtou.sh {} \;
	find examp \! -name \*.dat -type f -exec sh misc/dtou.sh {} \;
	for f in *.txt changelog config* *.sh make/makefile.unx make/makefile.gen make/makefile.lst; do
		echo $f
		sh misc/dtou.sh $f
	done
}

utod()
{
	find batch docs include src -type f -exec sh misc/utod.sh {} \;
	find examp \! -name \*.dat -type f -exec sh misc/utod.sh {} \;
	for f in *.txt changelog *.bat make/makefile.dj make/makefile.mgw make/makefile.win make/makefile.gen make/makefile.lst; do
		sh misc/utod.sh $f;
	done
}

case "$1" in
	djgpp	) proc_fix "DJGPP" "makefile.dj";;
	mingw	) proc_fix "Mingw32" "makefile.mgw";;
	mingw32	) proc_fix "Mingw32" "makefile.mgw";;
	msvc	) proc_fix "MSVC" "makefile.vc";;
	msvc6	) proc_fix "MSVC6" "makefile.vc";;
	msvc7	) proc_fix "MSVC7" "makefile.vc";;
	msvc8	) proc_fix "MSVC8" "makefile.vc";;
	unix	) fixunix;;
	macosx  ) proc_fix "MacOS X" "makefile.osx";;
	*	) display_help;;
esac

case "$2" in
	--utod	) utod;;
	--dtou	) dtou;;
	*	) ;;
esac

