#!/bin/sh
#
# Configures to build rcdrecord
#

cxx="g++"
dir=""
host=localhost
port=12411
prefix="/usr"
prefix2=""

while [ -n "$1" ]; do
	case $1 in
	--dir=*)
		dir=`echo $1 | sed "s*--dir=**g"`
		;;
	--host=?*)
		host=`echo $1 | sed "s/--host=//g"`
		;;
	--port=?*)
		port=`echo $1 | sed "s/--port=//g"`
		;;
	--prefix=*)
		prefix=`echo $1 | sed "s*--prefix=**g"`
		;;
	--prefix2=*)
		prefix2=`echo $1 | sed "s*--prefix2=**g"`
		;;
	--server=?*)
		host=`echo $1 | sed "s/--server=//g"`
		;;
	--help)
		HELP=yes
		;;
	*)
		echo $1: unknown argument
		HELP=yes
		;;
	esac
	shift
done


if [ "$HELP" = "yes" ]; then
	cat <<EOF
Usage: $0 [options]

--server=localhost    replace localhost by your host running CDWserver

--port=12411          by this option you may change the standard port

--prefix=DIR          base directory of the installation ($prefix)

EOF
	exit 1
fi


if [ "$dir" = "" ]; then
echo
echo "Configuring rcdrecord"
echo
fi

echo "Creating ${dir}Config.h"
cat Config.h.in \
	| sed s*@host@*$host*g\
	| sed s*@port@*$port*g\
	> Config.h

echo "Creating ${dir}Makefile"
cat Makefile.in \
	| sed s*@CXX@*$cxx*g \
	| sed s*@PREFIX@*$prefix*g \
	| sed s*@PREFIX2@*$prefix2*g \
	> Makefile

if [ "$dir" = "" ]; then
echo
echo "rcdrecord is now configured for building. Just run make."
echo
fi
