#!/bin/sh
#
# Very simple configure: only DATADIR is variable.
#
# Call:
#  ./configure
# or
#  ./configure --datadir=DATADIR
#
# Where shall we store our stuff?
#  Old default: /usr/lib/kbd
#  New default: /usr/share/kbd
#

datadir=

for arg in $*; do
	case "$arg" in
		-*=*) optarg=`echo "$arg" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
		   *) optarg= ;;
	esac

	case "$arg" in
		--d*)
			datadir=$optarg
			;;
		*)
			echo "usage: configure [--datadir=DATADIR]"
			exit 1
			;;
	esac
done

if [ x$datadir = x ]; then
	if [ -d /usr/lib/kbd ]; then
		datadir=/usr/lib/kbd
	elif [ -d /usr/share/consolefonts ]; then
		datadir=/usr/share
	elif [ -d /usr/share ]; then
		datadir=/usr/share/kbd
	else
		datadir=/usr/lib/kbd
	fi
fi

case "$datadir" in
	/*)
		echo "Configuring for DATADIR=$datadir"
		;;
	*)
		echo "DATADIR must have a leading slash"
		exit 1
		;;
esac

for i in Makefile src/Makefile man1/dumpkeys.1 man1/loadkeys.1 man8/setfont.8; do
	sed -e "
s,@datadir@,$datadir,
" $i.in > $i
done
