#!/bin/sh
###
#      \file  configure
#      \brief configure file

#      Copyright (c) 2004 Higepon
#      All rights reserved.
#      License=MIT/X Licnese

#      \author  HigePon and nanashi
#      \version $Revision: 1.8 $
#      \date   create:2003/10/07 update:$Date: 2004/10/27 11:43:37 $
###
# gcc is 3.x or 2.x
isOldVersion=`gcc --version|egrep '2\.9.*'`
isMinGW32=`uname|egrep MINGW32`
export OSTYPE="$(uname | cut -d _ -f 1 | tr [:upper:] [:lower:])"

# check MINGWPREFIX
if test -z $1 ; then
   MINGWPREFIX=${MINGWPREFIX:-"/usr/local/mingw32/bin/i386-mingw32-"}
elif test `echo $1 | grep -- --mingw-prefix= ` != "" ; then
   MINGWPREFIX=`echo $1 | sed -e "s/--mingw-prefix=//g"`
fi

echo -n "OSTYPE: "
# cygwin
if test "$OSTYPE" = "cygwin" ; then
   cp  env/cygwin.env env/Makefile.inc
   cp  tools/t5lzma/7zip/Compress/LZMA_Alone/Makefile.posix tools/t5lzma/7zip/Compress/LZMA_Alone/Makefile
   echo "cygwin"
# MinGW (MSys)
elif test $isMinGW32; then
   cp  env/mingw.env env/Makefile.inc
   cp  tools/t5lzma/7zip/Compress/LZMA_Alone/Makefile.mingw32 tools/t5lzma/7zip/Compress/LZMA_Alone/Makefile
   echo "MinGW32"
# MinGW (Unix)
elif test -x `printf "%s%s" $MINGWPREFIX "g++"` ; then
   echo "MINGWPREFIX = $MINGWPREFIX" > env/Makefile.inc
   cat env/uxmingw.env >> env/Makefile.inc
   cp  tools/t5lzma/7zip/Compress/LZMA_Alone/Makefile.posix tools/t5lzma/7zip/Compress/LZMA_Alone/Makefile
   echo "MinGW32 (Unix)"
else
   echo $OSTYPE
   echo ""
   echo "Sorry, currently your platform is not supported."
   echo "If you can support your platform, please contact with Mona PJ."
   echo "http://mona.sourceforge.jp/"
   exit 1
fi
## linux gcc2.9x
#elif test $isOldVersion ; then
#   cp  env/linux2.x.env env/Makefile.inc
#   echo "linux gcc2.x"
## linux gcc3.x
#else
#   cp  env/linux3.x.env env/Makefile.inc
#   echo "linux gcc3.x"
#fi

cp Makefile.in Makefile

echo ""
echo "[How to build]"
echo "1. make depend"
echo "2. make"
echo "3. make install"
echo "Have fun!"
