#!/bin/sh
#******************************************************************************#
#                                                                              #
#   configure                                                                  #
#   | Project : libfx                                                          #
#                                                                              #
#   By: thomas <thomas@touhey.fr>                                              #
#   Last updated: 2016/05/23 01:04:53                                          #
#                                                                              #
#******************************************************************************#
# Help
usage() {
cat <<EOF
Usage: $0 [OPTION]

Defaults for the options are specified in brackets.

Installation directories:
  --prefix=PREFIX         main installation prefix [/opt/sh3eb-elf]

Fine tuning of the installation directories:
  --libdir=DIR            library directory of the linker [PREFIX/sh3eb-elf/lib]
  --includedir=DIR        include directory for the compiler [PREFIX/sh3eb-elf/include]

EOF
exit 0
}

# Defaults
prefix=/opt/sh3eb-elf
libdir='$(IPREFIX)/sh3eb-elf/lib'
includedir='$(IPREFIX)/sh3eb-elf/include'

# Args parsing
for arg ; do
case "$arg" in
--help|-h) usage ;;
--prefix=*) prefix=${arg#*=} ;;
--libdir=*) libdir=${arg#*=} ;;
--includedir=*) includedir=${arg#*=} ;;
-*) echo "$0: unknown option $arg" ;;
*) echo "$0: are you drunk ?" ;;
esac
done

# Create Makefile configuration
exec 3>&1 1>Makefile.cfg

cat <<EOF
#!/usr/bin/make -f
# Makefile configuration generated by ./configure
IPREFIX = $prefix
ILIBDIR = $libdir
IINCDIR = $includedir
EOF

exec 1>&3 3>&-
chmod +x Makefile.cfg

# We're done
echo "Configuration loaded, you can make now."
