#!/bin/sh

# This is hand-written configuration script.
# It writes configuration options into Makefile.config

# TODO: rewrite this using autoconf
# https://www.gnu.org/software/autoconf/manual/index.html

ac_default_prefix=/usr/local

PREFIX=$ac_default_prefix

for ac_option
do
  case $ac_option in
  *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
  *=)   ac_optarg= ;;
  *)    ac_optarg=yes ;;
  esac

  case $ac_option in

  -help | --help | -h)
    show_help=yes ;;

  --prefix=*)
    PREFIX=$ac_optarg ;;

  esac
done

if test -n "$show_help"; then
  cat <<EOF
Usage: $0 [OPTION]... [VAR=VALUE]...

Configuration:
  -h, --help              display this help and exit

Installation directories:
  --prefix=PREFIX         install directory prefix
                          [$ac_default_prefix]

EOF
  exit 0
fi

# writing Makefile.config
echo "# configuration options"                                  >Makefile.config
echo "BINARY_DIR               := $PREFIX/bin"                  >>Makefile.config
echo "SHARED_DIR               := $PREFIX/share"                >>Makefile.config
echo "MANPAGE_DIR              := $PREFIX/share/man/man6"       >>Makefile.config
echo "FULL_PATH_EXTRA_DATA_DIR := $PREFIX/share/ja2"            >>Makefile.config
echo "INSTALLABLE              := yes"                          >>Makefile.config

# writing ja2config.h
echo "/* configuration options */"                              >ja2config.h
echo "#define EXTRA_DATA_DIR \"$PREFIX/share/ja2\""		>>ja2config.h
