#!/bin/bash

source ../cascade-make/lib/cascade-lib.bash GEXT_MARS .. $*

if [ -z "$GEXT_MARS_DEVEL" ] ; then
  cd .. && source ./devel.bash
fi

# Turns out essentia has an optional script inside it for getting and compiling
# up the necessary supporting packages.  The configure options it uses are more
# optimal than the onces developed in the CASCADE-MAKE files, and so look to be
# actively maintained, so have changed CASCADE-MAKE/ESSENTIA.sh to trigger this
# optional script as part of it's configure stage.

# *IMPORTANT*
# The route to have things statically compiled is currently followed.  Consequently:
#    packaging/build_config.sh
# has been tweaked from the git cloned file to specify --enable-static --disable-shared

# AND
#   there needs to static versions of -lm and -lc
# Not all Linux distributions ship with these.
#
# For Amazon Linux 2 AMI it was found to neeed:
#  sudo yum install glibc-static


# As things stand, the CASCADE-MAKE version of these files still had a couple of issues.
#
#  (i)  CHROMAPRINT needed -lz added to the link command for fpcalc when statically linked.
#  (ii) ESSENTIA hit a linking error at [308/408], again to do with not having the right
#       libraries for linking provided, even though they do exist


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

    ./CASCADE-MAKE/$d.sh $*

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