#!/bin/bash

if [ -d "my-python3" ] ; then
    echo "This sequence of compile-make requires a venv version of Python3"
    echo "    python -mvenv my-python3"
    echo "    activate ./my-python3/bin/activate"
    echo ""
    echo "You then need to:"
    echo "    pip3 install meson ninja"
    echo ""
    sleep 10
fi

source setup.bash

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

  echo "Greenstone environment variable GSDLHOME not set."
  echo "Have you sourced the main installation's setup file, e.g. setup.bash?"
  exit -1
fi


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"

if [ -e devel-srcpack ] ; then
  dirlist="$dirlist devel-srcpack"
fi

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

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

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

