#!/bin/bash

# We have a run-time dependency on maven collection, enable it first if not already
if ! scl_enabled rh-maven35 ; then
  if [ -z "$RPM_BUILD_ROOT" ] ; then
    . scl_source enable rh-maven35
  fi
fi

# The IDE has optional deps on other collections, so enable them if present
if test -e /opt/rh/devtoolset-6/enable ; then
  . scl_source enable devtoolset-6
fi
if test -e /opt/rh/devtoolset-7/enable ; then
  . scl_source enable devtoolset-7
fi
if test -e /opt/rh/devtoolset-8/enable ; then
  . scl_source enable devtoolset-8
fi
if test -e /opt/rh/python27/enable ; then
  . scl_source enable python27
fi
if test -e /opt/rh/rh-python35/enable ; then
  . scl_source enable rh-python35
fi
if test -e /opt/rh/rh-python36/enable ; then
  . scl_source enable rh-python36
fi

# General environment variables
export PATH=/opt/rh/rh-eclipse48/root/usr/bin:/opt/rh/rh-eclipse48/root/usr/lib/jvm/java/bin${PATH:+:${PATH}}
export MANPATH=/opt/rh/rh-eclipse48/root/usr/share/man:${MANPATH}

# Needed by Java Packages Tools to locate java.conf
export JAVACONFDIRS="/opt/rh/rh-eclipse48/root/etc/java:${JAVACONFDIRS:-/etc/java}"

# Required by XMvn to locate its configuration files
export XDG_CONFIG_DIRS="/opt/rh/rh-eclipse48/root/etc/xdg:${XDG_CONFIG_DIRS:-/etc/xdg}"
export XDG_DATA_DIRS="/opt/rh/rh-eclipse48/root/usr/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"

# Some perl Ext::MakeMaker versions install things under /usr/lib/perl5
# even though the system otherwise would go to /usr/lib64/perl5.
export PERL5LIB=/opt/rh/rh-eclipse48/root//usr/lib64/perl5/vendor_perl:/opt/rh/rh-eclipse48/root/usr/lib/perl5:/opt/rh/rh-eclipse48/root//usr/share/perl5/vendor_perl${PERL5LIB:+:${PERL5LIB}}
# bz847911 workaround:
# we need to evaluate rpm's installed run-time % { _libdir }, not rpmbuild time
# or else /etc/ld.so.conf.d files?
rpmlibdir=$(rpm --eval "%{_libdir}")
# bz1017604: On 64-bit hosts, we should include also the 32-bit library path.
if [ "$rpmlibdir" != "${rpmlibdir/lib64/}" ]; then
  rpmlibdir32=":/opt/rh/rh-eclipse48/root${rpmlibdir/lib64/lib}"
fi
export LD_LIBRARY_PATH=/opt/rh/rh-eclipse48/root$rpmlibdir$rpmlibdir32${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
