#!/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/adjust_sleep/include \
		-I${prefix}/src/angle/include \
		-I${prefix}/src/auto_select_stream/include \
		-I${prefix}/src/base64_converter \
		-I${prefix}/src/binary_io/include \
		-I${prefix}/src/bidirectional_caster/include \
		-I${prefix}/src/compat_stringstream/include \
		-I${prefix}/src/comstream/include \
		-I${prefix}/src/d2_region/include \
		-I${prefix}/src/d2_vector/include \
		-I${prefix}/src/debugstream/include \
		-I${prefix}/src/fdstream/include \
		-I${prefix}/src/file_mutex/include \
		-I${prefix}/src/float_traits/include \
		-I${prefix}/src/general_server/include \
		-I${prefix}/src/input_line_buffer/include \
		-I${prefix}/src/iostream_extension/include \
		-I${prefix}/src/ip_address/include \
		-I${prefix}/src/lisp_lex/include \
		-I${prefix}/src/load_average/include \
		-I${prefix}/src/math_extension/include \
		-I${prefix}/src/memorystream/include \
		-I${prefix}/src/mmap_file/include \
		-I${prefix}/src/mmap_fstream/include \
		-I${prefix}/src/option_analyzer/include \
		-I${prefix}/src/path/include \
		-I${prefix}/src/prof_stopwatch/include \
		-I${prefix}/src/posix_compat/include \
		-I${prefix}/src/random_generator/include \
		-I${prefix}/src/range/include \
		-I${prefix}/src/ref_count_ptr/include \
		-I${prefix}/src/sigmoid/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/time_stamp/include \
		-I${prefix}/src/unit_test/include \
		-I${prefix}/src/udp_pseudo_connection/include
End_Of_Include_Flags
fi

if [ ${libs_flag} = true ]; then
	cat << End_Of_Library_Flags | sed 's/^		//'
		-L${prefix}/src/udp_pseudo_connection -ludp_pseudo_connection \
		-L${prefix}/src/general_server -lgeneral_server \
		-L${prefix}/src/stream_socket -lstream_socket \
		-L${prefix}/src/lisp_lex -llisp_lex \
		-L${prefix}/src/load_average -lload_average \
		-L${prefix}/src/ip_address -lip_address \
		-L${prefix}/src/d2_region -ld2_region \
		-L${prefix}/src/d2_vector -ld2_vector \
		-L${prefix}/src/base64_converter -lbase64_converter \
		-L${prefix}/src/prof_stopwatch -lprof_stopwatch \
		-L${prefix}/src/time_stamp -ltime_stamp \
		-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/input_line_buffer -linput_line_buffer \
		-L${prefix}/src/debugstream -ldebugstream \
		-L${prefix}/src/posix_compat -lposix_compat
End_Of_Library_Flags
fi
