#!/bin/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

if [ -z $APACHE_HTTPD_HOME ] ; then
  export APACHE_HTTPD_HOME=$GSDLHOME/apache-httpd/$GSDLOS
fi

if [ ! -d "$APACHE_HTTPD_HOME" ] ; then
  # ... and it also needs to have been configured with --enable-apache-httpd
  # This is because the entension needs to add mod_flvx to the web server

  if [ -z $GSDL3SRCHOME  ] ; then
    # Greenstone 2
    echo "Warning: Did not find the directory \"$APACHE_HTTPD_HOME\""
    echo "         Has the main Greenstone been configured for this? "
    echo "         e.g. ./configure --enable-apache-httpd [... other options]"
    echo ""
    echo "=> Only the build-time code for the extension will be compiled"
  else 
    # Greenstone 3
    echo "  Compiling build-time video extension for Greenstone3 use"
  fi
  export APACHE_HTTPD_HOME=
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 [ ! -z $APACHE_HTTPD_HOME ] ; then
  dirlist="$dirlist runtime-srcpack"
fi

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

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

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

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



if [ $install = "1" ] ; then
  cat NOTES.txt
fi
