#!/bin/sh

makefile_config="Makefile.config"

# ޥɥ饤ν
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=$include_path $value ;;
		--with-libraries)	library_path=$library_path $value ;;
		--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"
							;;
	esac
done

# Boost C++ LibrariesΥإåե뤬ǥ쥯ȥ򥵡
for dir in $include_path "/usr/local/include" "/opt/local/include" "/opt/include" "/usr/include"
do
	ls $dir/boost* 2> /dev/null > /dev/null
	if test $? -eq 0
	then
		boost_dir=`ls -d $dir/boost* | sort -r | tr "\n" "\t" | cut -f 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"
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>
echo BOOST_VERSION" | g++ -E -I$include_path -L$library_path - | sh`

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

# 饤֥եźĴ٤
# Ķˤäơ-gcc-mt-s, -mt-s, -gcc42-mt-sʤɡźۤʤ뤿
libboost_regex_filename=`ls $library_path/libboost_regex*-s.* | tr "\n" "\t" | cut -f 1`
if test -z $libboost_regex_filename
then
	libboost_regex_filename=`ls $library_path/libboost_regex*.* | tr "\n" "\t" | cut -f 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

# Boost C+ Libraries 1.34ʾʤ顢libboost_system*󥯤ɬפ
if test $boost_version -ge 103400
then
	echo "BOOST_LIBFILES = -lboost_system\$(LIBBOOST_SUFFIX)" >> $makefile_config
fi

# Ƽѿ
echo BOOST_VERSION=$boost_lib_version >> $makefile_config
echo BOOST_DIR=$include_path >> $makefile_config
echo LIBBOOST_DIR=$library_path >> $makefile_config

# ̤ɽ
cat Makefile.config

# 
