#!/bin/bash

if [ "x$PYTHON3_HOME" = "x"  ] ; then
    echo "Compilation of this extension requires a version of Python3 where"
    echo "additional packages can be installed"
    echo ""
    echo "This can be accomplished by using Greenstone3's:"
    echo "    ext-cli/get-selfcontained-python3.sh"
    echo "And then source the top-level CLI setup file:"
    echo "    . ./gs3-setup-cli.sh"
    echo ""
    echo "You then need to:"
    echo "    pip3 install meson ninja"
    echo ""
    sleep 10
fi

source setup.bash

if [ "x$GSDLHOME" = "x" ] && [ "x$GSDL3SRCHOME" = "x" ]  ; then
  # This extension needs to have the main GSDL setup.bash sourced

  echo "Have you sourced the top-level Greenstone setup file, e.g. gs3-setup.sh (GS3) or setup.bash (GS2)?"
  exit -1
fi


# Now done in the setup.bash file
#source cascade-make/bin/script/test-setup.bash
#source cascade-make/lib/cascade-lib.bash

# Guaranteed that GSDLOS has now been set

if [ ! -e $GEXTVIDEO_INSTALLED ] ; then
  echo "Creating $GEXTVIDEO_INSTALLED"
  mkdir $GEXTVIDEO_INSTALLED
fi

dirlist="build-srcpack"

echo "**** No longer checking for devel-srcpack"
sleep 5
#if [ -e devel-srcpack ] ; then
#  dirlist="$dirlist devel-srcpack"
#fi

for d in $dirlist ; do
  echo "Running $d/CASCADE-MAKE3.sh $*"

  (cd $d ; ./CASCADE-MAKE3.sh $*)

  if [ $? != 0 ] ; then
    echo "Error encountered running $d/CASCADE-MAKE3.sh"
    exit 1
  fi
done

