#!/bin/sh

makefile_config="Makefile.config"
with_xml=0

# ޥɥ饤ν
for arg in "$@"
do
	name=`echo $arg | cut -d "=" -f 1`
	value=`echo $arg | cut -d "=" -f 2`

	case $name in
		--with-headers)		include_path=$value ;;
		--with-libraries)	library_path=$value ;;
		--with-xml)			with_xml=1 ;;
		--help)				echo "configure options:"
							echo "--help"
							echo "	display this information"
							echo "--with-headers=<dir>"
							echo "	specify the directory of Boost headers"
							echo "--with-libraries=<dir>"
							echo "	specify the directory of Boost libraries"
							echo "--with-xml"
							echo "  support for XML"
							exit
							;;
	esac
done

# Boost C++ LibrariesΥإåե뤬ǥ쥯ȥ򥵡
for dir in $include_path "/usr/local/include" "/opt/local/include" "/opt/include" "/usr/include" "/mingw/include"
do
	ls $dir/boost* 2> /dev/null > /dev/null
	if test $? -eq 0
	then
		boost_dir=`ls -d $dir/boost* | sort -r | head -1`
		if test $boost_dir = $dir/boost
		then
			include_path=$dir
		else
			include_path=$boost_dir
		fi
		break
	fi
done

# Boost C++ LibrariesΥ饤֥ե뤬ǥ쥯ȥ򥵡
for dir in $library_path "/usr/local/lib" "/opt/local/lib" "/opt/lib" "/usr/lib" "/lib" "/mingw/lib"
do
	ls $dir/libboost* 2> /dev/null > /dev/null
	if test $? -eq 0
	then
		library_path=$dir
		break
	fi
done

##### ʲMakefile.config #####

rm Makefile.config 2> /dev/null

# Boost C++ LibrariesΥСĴ٤
boost_version=`echo "#include <boost/version.hpp>
BOOST_VERSION" | g++ -E -I$include_path -L$library_path - | tail -1`

boost_lib_version=`echo "#include <boost/version.hpp>
BOOST_LIB_VERSION" | g++ -E -I$include_path -L$library_path - | tail -1`

# 饤֥եźĴ٤
# Ķˤäơ-gcc-mt-s, -mt-s, -gcc42-mt-sʤɡźۤʤ뤿
libboost_regex_filename=`ls $library_path/libboost_regex*-s.* 2> /dev/null | head -1`
if test -z $libboost_regex_filename
then
	libboost_regex_filename=`ls $library_path/libboost_regex*.* | head -1`
fi
libboost_suffix=`echo $libboost_regex_filename | sed -e s/.*libboost_regex//g -e s/\.[a-z]*$//g`
echo "LIBBOOST_SUFFIX=$libboost_suffix" >> $makefile_config

# Ƽѿ
echo BOOST_VERSION=$boost_lib_version >> $makefile_config
echo BOOST_DIR=$include_path >> $makefile_config
echo XERCES_DIR=$include_path >> $makefile_config
echo LIBBOOST_DIR=$library_path >> $makefile_config
echo LIBXERCES_DIR=$library_path >> $makefile_config
echo OPTIONS=$options >> $makefile_config
if test $with_xml -eq 1
then
	echo HAS_CFG_XML=1 >> $makefile_config
fi

# ̤ɽ
cat Makefile.config

# 
