1#!/bin/sh 2# Set-up environment variables to run programs which are built in DESTDIR folder 3# 4# Usage example to use variables in the current shell: 5# $ export DESTDIR=$HOME/selinux-destdir 6# $ make install install-pywrap install-rubywrap 7# $ . ./scripts/env_use_destdir 8# $ make test 9# 10# Or to use variables in a subcommand, for example to run tests: 11# $ export DESTDIR=$HOME/selinux-destdir 12# $ make install install-pywrap install-rubywrap 13# $ ./scripts/env_use_destdir secilc ... 14# $ ./scripts/env_use_destdir make test 15 16if [ -z "${DESTDIR:-}" ] ; then 17 echo >&2 "Error: variable DESTDIR needs to be defined in order to use this script." 18 echo >&2 "Example:" 19 # shellcheck disable=SC2164 20 echo >&2 " DESTDIR=$(cd "$(dirname -- "$0")/.." ; pwd)/DESTDIR . $0" 21 exit 1 22fi 23 24export LD_LIBRARY_PATH="$DESTDIR/usr/lib:$DESTDIR/lib" 25if [ -n "${PREFIX:-}" ] ; then 26 LD_LIBRARY_PATH="$DESTDIR$PREFIX/lib:$LD_LIBRARY_PATH" 27fi 28if [ -n "${LIBDIR:-}" ] ; then 29 LD_LIBRARY_PATH="$DESTDIR$LIBDIR:$LD_LIBRARY_PATH" 30fi 31if [ -n "${SHLIBDIR:-}" ] ; then 32 LD_LIBRARY_PATH="$DESTDIR$SHLIBDIR:$LD_LIBRARY_PATH" 33fi 34 35export PATH="$DESTDIR/usr/sbin:$DESTDIR/usr/bin:$DESTDIR/sbin:$DESTDIR/bin:$PATH" 36if [ -n "${PREFIX:-}" ] ; then 37 PATH="$DESTDIR$PREFIX/sbin:$DESTDIR$PREFIX/bin:$LD_LIBRARY_PATH" 38fi 39if [ -n "${BINDIR:-}" ] ; then 40 PATH="$DESTDIR$BINDIR:$PATH" 41fi 42if [ -n "${SBINDIR:-}" ] ; then 43 PATH="$DESTDIR$SBINDIR:$PATH" 44fi 45 46NEW_PYTHONPATH="$DESTDIR$(${PYTHON:-python3} -c "import sysconfig; print(sysconfig.get_path('platlib', vars={'platbase': '/usr', 'base': '/usr'}))"):$DESTDIR$(${PYTHON:-python3} -c "import sysconfig; print(sysconfig.get_path('purelib', vars={'platbase': '/usr', 'base': '/usr'}))")" 47if [ -n "${PYTHONPATH:-}" ] ; then 48 # Prefix the PYTHONPATH with the new directories 49 export PYTHONPATH="$NEW_PYTHONPATH:$PYTHONPATH" 50else 51 # Define PYTHONPATH 52 export PYTHONPATH="$NEW_PYTHONPATH" 53fi 54 55# shellcheck disable=SC2155 56export RUBYLIB="$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorlibdir"]'):$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorarchdir"]')" 57 58# Run the command given on the command line 59if [ $# -gt 0 ] ; then 60 exec "$@" 61fi 62