#!/bin/sh

. ./configure.tools

save_arguments "$@"

project="catalog"
ldflags=""
ccflags="-Wall -Werror -g -fPIC -fno-exceptions -D_REENTRANT"
install_dir="/usr/local"
classad_dir="/usr/local"

IFS=" ="
export IFS

while [ $# -gt 0 ]
do
	case $1 in
		--prefix)
			shift
			install_dir=$1
			;;
		--with-classad-path)
			shift
			classad_dir=$1
			;;
		--with-*-path)
			echo "ignoring unknown package $1"
			shift
			;;
		--without-*)
			echo "ignoring unknown package $1"
			shift
			;;
		-h | -help | --h | --help)
			cat <<EOF
Use: configure [options]
Where options are:
 --prefix <dir>      The directory in which to install $project
 --with-classad-path The installation path of ClassAds
 --help              Show this message         
EOF
			exit 1
			;;
		*)
			echo "Unknown argument $1"
			exit 1
			;;
	esac
	shift
done

echo "configuring $project..."

IFS=" "
export IFS

require_path "gcc"
require_path "g++"
require_gnu_make
require_library pthread

optional_library gdbm HAS_LIBGDBM
optional_library m HAS_LIBM
optional_library nsl HAS_LIBNSL
optional_library socket HAS_LIBSOCKET
optional_library pthread HAS_LIBPTHREAD

require_package classad ${classad_dir}/lib/libclassad.a ${classad_dir}

ccflags="${ccflags} -DINSTALL_DIR=\\\"${install_dir}\\\""

echo "Creating Makefile.config..."

cat <<EOF >Makefile.config
# Generated at `date` by `whoami`@`uname -n`

INSTALL_DIR = ${install_dir}

CC=gcc
CCFLAGS=${ccflags}

LD=g++
LDFLAGS=${ldflags}

AR=ar
ARFLAGS=

EOF

echo ""
echo "To build, type 'make'"
echo "To install, type 'make install'"
echo ""

exit 0
