version=5.32.1
package_name="Greenstone-friendly Perl5 with CPAN modules"
perl_dir=gsperl5-with-cpan-linux64



OS_ALLCAPS=`uname -s | sed 's/_.*$//' | tr 'a-z' 'A-Z'`

if [ "x$OS_ALLCAPS" = "xDARWIN" ] ; then
    perl_dir=gsperl5-with-cpan-darwin
fi
full_perl_dir="$PWD/$perl_dir"

if test ! -d "$full_perl_dir" ; then
    echo "" >&2
    echo "In setting up $package_name, did not find directory:" >&2
    echo "  $full_perl_dir" >&2    
    echo "" >&2
    echo "Have you run ./PREPARE-${OS_ALLCAPS}.sh?" >&2    
    echo "Exiting..." >&2    
    echo "" >&2
    return
fi

# have we already run the setup for this?
if [ ! -z "$GSPERL_WITH_CPAN_HOME" ] ; then 
    if [ "$GSPERL_WITH_CPAN_HOME" = "$full_perl_dir" ] ; then
      echo + "GSPERL_WITH_CPAN_HOME was already set"
      return 1
    fi
fi

echo " - OS is $OS_ALLCAPS"

GSPERL_WITH_CPAN_HOME="$full_perl_dir"  ; export GSPERL_WITH_CPAN_HOME
PATH="$GSPERL_WITH_CPAN_HOME/bin:$PATH" ; export PATH

# The perl Greenstone compiles up on Linux Standard Base (LSB) is statically
# linked to libperl, however the LSB buildenv is configured to dynamically
# link to libssp (stack smashing protection), and so we do need to set
# LD_LIBRARY_PATH to point to the version of that, which we include within
# the perl tarball
#

#if test $OS_ALLCAPS = "LINUX" ; then
#    LD_LIBRARY_PATH="$full_perl_dir/lib/$version/x86_64-linux-thread-multi/CORE:$LD_LIBRARY_PATH" ;      export LD_LIBRARY_PATH
#    echo + "Set GSPERL_WITH_CPAN_HOME and updated PATH and LD_LIBRARY_PATH"
#elif test $OS_ALLCAPS = "DARWIN" ; then
#    DYLD_LIBRARY_PATH="$full_perl_dir/lib/$version/darwin-thread-multi-2level/CORE:$DYLD_LIBRARY_PATH" ; export DYLD_LIBRARY_PATH
#    echo + "Set GSPERL_WITH_CPAN_HOME and updated PATH and DYLD_LIBRARY_PATH"
#else
#    echo "Error: Currently unsupported OS platform: $OS_ALLCAPS." >&2
#    echo "Failed to update library path to specify location of 'libperl.so'" >&2   
#fi

if test $OS_ALLCAPS = "LINUX" ; then
    LD_LIBRARY_PATH="$full_perl_dir/lib/:$LD_LIBRARY_PATH" ;      export LD_LIBRARY_PATH
    echo + "Set GSPERL_WITH_CPAN_HOME and updated PATH and LD_LIBRARY_PATH"
elif test $OS_ALLCAPS = "DARWIN" ; then
    echo + "Set GSPERL_WITH_CPAN_HOME and updated PATH"    
    echo "+ *** At this stage of development, assumed that we do not need to set/update DYLD_LIBRARY_PATH"
    #DYLD_LIBRARY_PATH="$full_perl_dir/lib:$DYLD_LIBRARY_PATH" ; export DYLD_LIBRARY_PATH
    #echo + "Set GSPERL_WITH_CPAN_HOME and updated PATH and DYLD_LIBRARY_PATH"
else
    echo "Error: Currently unsupported OS platform: $OS_ALLCAPS." >&2
    echo "Failed to update library path to specify location of 'libperl.so'" >&2   
fi
