#!/bin/bash

# call this script from inside your game's project folder
# this script creates a Makefile inside your project's "gameSource" directory


#
# Modification History
#
# 2010-April-2    Andy Sommerville
# Allow menu choice from argv.
# "exit 1" when user chooses 'q'; terminate build.
#
# 2006-June-27    Jason Rohrer
# Copied/modified from Transcend project.  Dropped a platforms that were only
# nominally supported.
#

if [[ "$1" < "4" ]] ; then
  if [[ "$1" > "0" ]] ; then
    platformSelection="$1"
  fi
fi
while [ -z "$platformSelection" ]
do

    echo "select platform:"

    echo "  1 --  GNU/Linux"
    echo "  2 --  MacOSX"
    echo "  3 --  Win32 using MinGW"
    echo "  q --  quit"

    echo ""
    echo -n "> "

    read platformSelection

	
	if [ "$platformSelection" = "q" ]
    then
        exit 1
    fi


    # use ASCII comparison.

	if [[ "$platformSelection" > "3" ]]
    then
        platformSelection=""
    fi

    if [[ "$platformSelection" < "1" ]]
    then
        platformSelection=""
    fi

done


# use partial makefiles from minorGems project
makefileMinorGems="../minorGems/build/Makefile.minorGems"
makefileMinorGemsTargets="../minorGems/build/Makefile.minorGems_targets"



platformName="Generic"
platformMakefile="generic"


makefilePath="../minorGems/game/platforms/SDL"
commonMakefile="$makefilePath/Makefile.common"

makefileAll="$makefilePath/Makefile.all"



case "$platformSelection" in


    "1" )
        platformName="GNU/Linux"
        platformMakefile="$makefilePath/Makefile.GnuLinux"
    ;;


    "2" )
        platformName="MacOSX"
        platformMakefile="$makefilePath/Makefile.MacOSX"
    ;;


    "3" )
        platformName="Win32 MinGW"
        platformMakefile="$makefilePath/Makefile.MinGW"
    ;;


esac



rm -f Makefile.temp
echo "# Auto-generated by game9/configure for the $platformName platform.  Do not edit manually." > Makefile.temp

rm -f gameSource/Makefile
cat Makefile.temp $platformMakefile $commonMakefile $makefileMinorGems $makefileAll $makefileMinorGemsTargets > gameSource/Makefile


rm Makefile.temp



exit
