2018-07-02 12:33:33 +02:00
|
|
|
#!/bin/bash
|
|
|
|
## Source this file.
|
|
|
|
## Usage: apply [vanilla | vanilla-nocache | *eh_elf] [dbg | *release]
|
|
|
|
|
|
|
|
# ==== INPUT ACQUISITION ====
|
|
|
|
flavour="eh_elf"
|
|
|
|
dbg="release"
|
|
|
|
while [ "$#" -gt 0 ] ; do
|
|
|
|
case "$1" in
|
|
|
|
"vanilla" | "vanilla-nocache" | "eh_elf")
|
|
|
|
flavour="$1"
|
|
|
|
;;
|
|
|
|
"dbg" | "release")
|
|
|
|
dbg="$1"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
>&2 echo "Unknown argument: $1"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2018-07-04 18:13:19 +02:00
|
|
|
# ==== UNSET PREVIOUS ENVIRONMENT ====
|
|
|
|
|
|
|
|
type -t deactivate
|
|
|
|
[ -n "$(type -t deactivate)" ] && deactivate
|
|
|
|
|
|
|
|
# ==== DEFINE DEACTIVATE ====
|
|
|
|
|
|
|
|
function deactivate {
|
|
|
|
export CPATH="$CPATH_EHELFSAVE"
|
|
|
|
export LIBRARY_PATH="$LIBRARY_PATH_EHELFSAVE"
|
|
|
|
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH_EHELFSAVE"
|
|
|
|
export PS1="$PS1_EHELFSAVE"
|
|
|
|
export PATH="$PATH_EHELFSAVE"
|
|
|
|
|
|
|
|
unset CPATH_EHELFSAVE
|
|
|
|
unset LIBRARY_PATH_EHELFSAVE
|
|
|
|
unset LD_LIBRARY_PATH_EHELFSAVE
|
|
|
|
unset PS1_EHELFSAVE
|
|
|
|
unset PATH_EHELFSAVE
|
|
|
|
|
|
|
|
unset deactivate
|
|
|
|
}
|
|
|
|
|
2018-07-02 12:33:33 +02:00
|
|
|
# ==== PREFIX ====
|
|
|
|
export PERF_PREFIX="$HOME/local/perf-$flavour"
|
|
|
|
|
|
|
|
LIBUNWIND_PREFIX="$HOME/local/libunwind"
|
|
|
|
case "$flavour" in
|
|
|
|
"vanilla" | "vanilla-nocache" )
|
|
|
|
LIBUNWIND_PREFIX="${LIBUNWIND_PREFIX}-vanilla"
|
|
|
|
;;
|
|
|
|
"eh_elf" )
|
|
|
|
LIBUNWIND_PREFIX="${LIBUNWIND_PREFIX}-eh_elf"
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
>&2 echo "$flavour: unknown flavour"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
case "$dbg" in
|
|
|
|
"dbg" )
|
|
|
|
LIBUNWIND_PREFIX="${LIBUNWIND_PREFIX}-dbg"
|
|
|
|
;;
|
|
|
|
"release" )
|
|
|
|
LIBUNWIND_PREFIX="${LIBUNWIND_PREFIX}-release"
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
>&2 echo "$dbg: unknown debug mode (release | dbg)"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
export LIBUNWIND_PREFIX
|
|
|
|
|
|
|
|
|
|
|
|
# ==== EXPORTING ENV VARS ====
|
|
|
|
|
|
|
|
function colon_prepend {
|
|
|
|
if [ -z "$2" ]; then
|
|
|
|
echo "$1"
|
2018-07-04 18:13:19 +02:00
|
|
|
elif [ -z "$1" ] ; then
|
|
|
|
echo "$2"
|
2018-07-02 12:33:33 +02:00
|
|
|
else
|
|
|
|
echo "$1:$2"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-07-04 18:13:19 +02:00
|
|
|
function ifpath {
|
|
|
|
if [ -e "$1" ] ; then
|
|
|
|
echo "$1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-07-02 12:33:33 +02:00
|
|
|
export CPATH_EHELFSAVE="$CPATH"
|
|
|
|
export LIBRARY_PATH_EHELFSAVE="$LIBRARY_PATH"
|
|
|
|
export LD_LIBRARY_PATH_EHELFSAVE="$LD_LIBRARY_PATH"
|
2018-07-04 18:13:19 +02:00
|
|
|
export PATH_EHELFSAVE="$PATH"
|
2018-07-02 12:33:33 +02:00
|
|
|
export PS1_EHELFSAVE="$PS1"
|
|
|
|
|
|
|
|
export CPATH="$(colon_prepend \
|
|
|
|
"$LIBUNWIND_PREFIX/include/:$PERF_PREFIX/include" "$CPATH")"
|
|
|
|
export LIBRARY_PATH="$(colon_prepend \
|
|
|
|
"$LIBUNWIND_PREFIX/lib/:$PERF_PREFIX/lib" "$LIBRARY_PATH")"
|
|
|
|
export LD_LIBRARY_PATH="$(colon_prepend \
|
|
|
|
"$LIBUNWIND_PREFIX/lib/:$PERF_PREFIX/lib" "$LD_LIBRARY_PATH")"
|
2018-07-04 18:13:19 +02:00
|
|
|
export PATH="$(colon_prepend \
|
|
|
|
"$(colon_prepend \
|
|
|
|
"$(ifpath "$LIBUNWIND_PREFIX/bin")" \
|
|
|
|
"$(ifpath "$PERF_PREFIX/bin")")" \
|
|
|
|
"$PATH")"
|
2018-07-02 12:33:33 +02:00
|
|
|
|
|
|
|
export PS1="($flavour $dbg) $PS1"
|
2018-07-04 18:13:19 +02:00
|
|
|
|
|
|
|
unset ifpath
|
|
|
|
unset colon_prepend
|