#!/bin/bash

if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
  echo "Configuration Options:"
  echo "  -h, --help        Display this help and exit"
  echo "  --allegro         Use Allegro 5 as the platform API"
  echo "  --glfw            Use GLFW 3 as the platform API"
# echo "  --sdl             Use SDL 1.2 as the platform API"
  echo "  --gpu             Use GPU for rendering (experimental)"
  echo "  --prefix <dir>    Set install directory root"
  exit
fi

PLATFORM=glv
PREFIX=/usr/local
GPU=scale

while [ "$1" != "" ]; do
  case $1 in
    --allegro)
      PLATFORM=allegro ;;
    --glfw)
      PLATFORM=glfw ;;
#   --sdl)
#     PLATFORM=sdl ;;
    --gpu)
      GPU=all ;;
    --prefix)
      shift
      PREFIX=$1 ;;
    *)
      echo "Invalid option $1"
      exit 1
      ;;
  esac
  shift
done

leq() {
  [[ $1 = $2 ]] && echo true || echo false
}
lne() {
  [[ $1 != $2 ]] && echo true || echo false
}

echo "Generating make.config & project.config"
printf "os_api: \'${PLATFORM}\ngpu_render: $(leq ${GPU} all)\n" >project.config
printf "PREFIX=${PREFIX}\nUI=${PLATFORM}\nGPU=${GPU}\n" >make.config
echo "Now type make (or copr) to build."
