#/bin/sh
#
# make-4-linux                                                        MM-230121
#
# Shell script for Linux to create an 'e4thcom-0.8.5' release directory and an
# archive 'e4thcom-0.8.5-ostype-hosttype.tgz'.
#
#   Required:  MinForth Plus 1.5 source at 'e4thcom-0.8.5-src/mfp1.5'
# 
# Open a terminal emulator in the  e4thcom-0.8.5-src/0.8.5  directory and
# enter  ./make-4-linux [Enter]  on the command line.
#


CWD="$PWD"
MFPDIR="./mfp1.5"
MFPBIN="$MFPDIR/mfp"
RELNR="0.8.5"
RELDIR="$PWD/../e4thcom-$RELNR"
TARGET="$OSTYPE-$HOSTTYPE"


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


SRC="e4thcom.mf"

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


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

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

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

cd $CWD

# echo $PWD

echo
echo -ne "\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 "$PWD/../e4thcom"


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

cd ../

src/$MFPBIN require e4thcom.mf  save

# echo ; mv -v e4thcom.i ../

echo $TARGET > ./__HOSTTYPE__


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


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

./e4thcom -h

exit #----------------------------------


echo -ne "\033[1mCreate/update the e4thcom-$RELNR release directory ? \033[0m"
       yes/no

echo "$RELDIR"
echo

mkdir -p "$RELDIR"

  cp -uLt "$RELDIR" "e4thcom"

  cp -ut  "$RELDIR" "e4thcom.i"

  cp -ut  "$RELDIR"  *.efc  *.efr  *.efx  README  TEST  test  ".e4thcom-$RELNR"

  # cp -urt "$RELDIR"  doc  templates  src
  cp -urt "$RELDIR"  doc  templates

#  echo $HOSTTYPE > "$RELDIR/__HOSTTYPE__"
  echo $TARGET > "$RELDIR/__HOSTTYPE__"

  echo
  echo -ne "\033[1mCreate the e4thcom-$RELNR-$TARGET.tgz archive ? \033[0m"
       yes/no

  tar czf "e4thcom-${RELNR}-$TARGET.tgz" "e4thcom-$RELNR"

  echo "$PWD/e4thcom-$RELNR-$TARGET.tgz"


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


echo "Start e4thcom -h from the release directory to show the help text ?"
echo
echo -ne "e4thcom-0.8.5/e4thcom -h " 
     yes/no
echo

e4thcom-0.8.5/e4thcom -h

exit

