#!/bin/bash

package=essentia
version=-full-git

progname=$0

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

if [ "x$VIRTUAL_ENV" != "x" ] ; then
    prefix="$VIRTUAL_ENV"
elif [ "x$PYTHON3_HOME" != "x" ] ; then
    prefix="$PYTHON3_HOME"
else
    prefix="$GEXT_MARS_INSTALLED"
fi

#export CFLAGS="$CFLAGS -I$GEXT_MARS_INSTALLED/include"
##export CPPFLAGS="$CPPFLAGS -I$GEXT_MARS_INSTALLED/include"
##export CXXFLAGS="$CXXFLAGS -I$GEXT_MARS_INSTALLED/include"
#export LDFLAGS="$LDFLAGS -L$GEXT_MARS_INSTALLED/lib"
##export LD_LIBRARY_PATH="$GEXT_MARS_INSTALLED/lib"

if [ "x$PKG_CONFIG_PATH" = "x" ] ; then
    export PKG_CONFIG_PATH="$GEXT_MARS_INSTALLED/lib/pkgconfig"
else
    export PKG_CONFIG_PATH="$GEXT_MARS_INSTALLED/lib/pkgconfig:$PKG_CONFIG_PATH"

fi
    

opt_run_untar $force_untar $auto_untar $package $version

#opt_run_configure $force_config $auto_config $package $version $prefix 
# consider making a waf version for configure?
if [ $force_config = "1" ] ; then

    echo "[pushd $package$version]"
    ( cd $package$version ; \
      # Used to do full configure with testing, but have not dropped that
      # (note: needs full recursive git cloned version of repository to provide models and sample audio files)
      echo ./packaging/build_3rdparty_static_debian.sh ; \
      eval ./packaging/build_3rdparty_static_debian.sh ; \
      echo python3 ./waf configure --with-static-examples --with-python --python=$PYTHON3_HOME/bin/python3 --prefix="$prefix" $@ ; \
      eval python3 ./waf configure --with-static-examples --with-python --python=$PYTHON3_HOME/bin/python3 --prefix="$prefix" $@ ; )
    if [ $? != 0 ] ; then
        echo "      Error encountered running *configure* stage of $progname"
        exit 1
    fi
    echo "[popd]"
fi

#opt_run_make $compile $package $version
# consider making a waf version for compiling?
# (and dropping the testing part)
if [ $compile = "1" ] ; then
    echo "[pushd $package$version]"
    ( cd $package$version ; \
      # Used to do full configure with testing. If reverting back to this, note
      # that this then needs a full recursive git cloned version of repository to provide models and sample audio files
      echo "python3 ./waf" ; \
      eval python3 ./waf )
    if [ $? != 0 ] ; then
        echo "      Error encountered running *compile* stage of $progname"
        exit 1
    fi
    echo "[popd]"

    # python3 ./waf run_python_tests
fi

#opt_run_make $install $package $version "install"
# consider making a waf version for install?
if [ $install = "1" ] ; then
    echo "[pushd $package$version]"
    ( cd $package$version ; \
      echo python3 ./waf install ; \
      eval python3 ./waf install )
    if [ $? != 0 ] ; then
        echo "      Error encountered running *install* stage of $progname"
        exit 1
    fi
    echo "[popd]"
fi


opt_run_make $clean $package $version "clean"
opt_run_make $distclean $package $version "distclean"

opt_run_tarclean $tarclean $package $version
