#/bin/sh
#
# e4thcom-x.y.z/src/make-e4thcom                                      MM-230130
# -----------------------------------------------------------------------------
#   Script to build e4thcom and the required MinForth Plus for Linux or OSX.
# -----------------------------------------------------------------------------
#
#       WARNING  Do not use this script for e4thcom-0.9.0 with OSX !
#
# -----------------------------------------------------------------------------
# Open a terminal emulator in the 'e4thcom-x.y.z/src' directory and enter 
# ./make-e4thcom [Enter]  on the command line.
#
# Creates the binary and image files for Minforth Plus and e4thcom from the
# sources. The files for e4thcom are then placed in the e4thcom application
# directory 'e4thcom-x.y.z'.
# -----------------------------------------------------------------------------

MFPDIR="$PWD/mfp1.5w4.0.2/mfp1.5"
MFPBIN="$MFPDIR/mfp"
SRCDIR="$PWD"
APPDIR="$SRCDIR/.."
APPSRC="e4thcom.mf"
TARGET="$OSTYPE-$HOSTTYPE"


if [ ! -d $MFPDIR ] ; then
   echo -e "\033[1m\033[33m* Error: MinForth $MFPDIR not found\033[0m"
   exit 1
fi


if [ ! -f "./$APPSRC" ] ; then
echo -e "\033[1m\033[33m* Error: File ./$APPSRC not found\033[0m"
   exit 1
fi


yes/no () {
     read -n 1 -p " [Y/n]" REPLY ; echo
     if [ "$REPLY" = "n" ] || [ "$REPLY" = "N" ]
     then
        echo -e "\033[1m\033[33m* stopped\033[0m"
        exit
     fi
}


echo -ne "\n\033[1mCreate MINFORTH Plus 1.5 for $TARGET ? \033[0m"
     yes/no

cd $MFPDIR ; ./make-mfp || exit 1

cd $SRCDIR


echo -ne "\n\033[1mCreate the e4thcom executable for $TARGET ? \033[0m"
     yes/no

if [ ! -f "$MFPBIN" ] ; then
echo -e "\033[1m\033[33m* Error: File $MFPBIN not found\033[0m"
   exit 1
fi

cp -v $MFPBIN "$APPDIR/e4thcom"


echo -ne "\n\033[1mCreate the e4thcom image file for $TARGET ? \033[0m"
     yes/no

$MFPBIN require e4thcom.mf  save

# Fehlerbehandlung wenn kein image file erzeugt wurde

echo ; mv -v e4thcom.i "$APPDIR"

echo $TARGET > ./__HOSTTYPE__


echo -e "\n\033[1m\033[33m* done\033[0m\n"


echo -ne "\033[1mExecute e4thcom -h to show the help text ? \033[0m"
     yes/no
echo

# ./e4thcom -h
$APPDIR/e4thcom -h

# EOF MM-230208

