#!/bin/sh

usage()
{
	echo "Usage: ${0} [option ...]"
	echo "Possible options are:"
	echo "  --help"
	echo "  --prefix=LIBRARY_TOP_DIRECTORY"
	echo "  --cc"
	echo "  --c++"
	echo "  --perl5"
	echo "  --make-archive"
	echo "  --cflags"
	echo "  --libs"
}


prefix=
cc_flag=false
cc_no_warning_options=false
flag=false
cxx_flag=false
cxx_no_warning_options=false
perl5_flag=false
make_archive_flag=false
cflags_flag=false
libs_flag=false

while [ ${#} -gt 0 ]
do
	case "${1}" in

	--help)
		usage 1>&2
		exit 0
		;;

	--prefix=*)
		prefix=`echo ${1} | sed 's/^--prefix=//'`
		;;

	--cc)
		cc_flag=true
		;;

	--cc-no-warning-options)
		cc_no_warning_options=true
		;;

	--c++)
		cxx_flag=true
		;;

	--c++-no-warning-options)
		cxx_no_warning_options=true
		;;

	--perl5)
		perl5_flag=true
		;;

	--make-archive)
		make_archive_flag=true
		;;

	--cflags)
		cflags_flag=true
		;;

	--libs)
		libs_flag=true
		;;

	*)
		usage 1>&2
		exit 1
		;;
	esac

	shift 1
done

if [ -z "${prefix}" ]; then
	echo "${0}: prefix must be specified." 1>&2
	usage 1>&2
	exit 1
fi


bin_dir="${prefix}/bin"

if [ ${cc_flag} = true ]; then
	echo "${bin_dir}/gccw"
fi

if [ ${cc_no_warning_options} = true ]; then
	echo "${bin_dir}/gccw --no-warning-options -W -Wall"
fi

if [ ${cxx_flag} = true ]; then
	echo "${bin_dir}/g++w"
fi

if [ ${cxx_no_warning_options} = true ]; then
	echo "${bin_dir}/g++w --no-warning-options -W -Wall"
fi

if [ ${perl5_flag} = true ]; then
	echo "${bin_dir}/Perl5"
fi

if [ ${make_archive_flag} = true ]; then
	echo "${bin_dir}/make-archive"
fi

if [ ${cflags_flag} = true ]; then
	cat << End_Of_Include_Flags | sed 's/^		//'
		-I${prefix}/src/compat_stringstream/include \
		-I${prefix}/src/comstream/include \
		-I${prefix}/src/iostream_extension/include \
		-I${prefix}/src/ip_address/include \
		-I${prefix}/src/option_analyzer/include \
		-I${prefix}/src/path/include \
		-I${prefix}/src/posix_compat/include \
		-I${prefix}/src/ref_count_ptr/include \
		-I${prefix}/src/std_compat_header_wrapper/include \
		-I${prefix}/src/stream_socket/include \
		-I${prefix}/src/string_extension/include \
		-I${prefix}/src/system_call_wrapper/include \
		-I${prefix}/src/unit_test/include
End_Of_Include_Flags
fi

if [ ${libs_flag} = true ]; then
	cat << End_Of_Library_Flags | sed 's/^		//'
		-L${prefix}/src/stream_socket -lstream_socket \
		-L${prefix}/src/ip_address -lip_address \
		-L${prefix}/src/option_analyzer -loption_analyzer \
		-L${prefix}/src/system_call_wrapper -lsystem_call_wrapper \
		-L${prefix}/src/path -lpath \
		-L${prefix}/src/string_extension -lstring_extension \
		-L${prefix}/src/posix_compat -lposix_compat
End_Of_Library_Flags
fi
