dwarf-assembly/env/apply

118 lines
2.6 KiB
Bash
Executable file

#!/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
# ==== 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
}
# ==== 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"
elif [ -z "$1" ] ; then
echo "$2"
else
echo "$1:$2"
fi
}
function ifpath {
if [ -e "$1" ] ; then
echo "$1"
fi
}
export CPATH_EHELFSAVE="$CPATH"
export LIBRARY_PATH_EHELFSAVE="$LIBRARY_PATH"
export LD_LIBRARY_PATH_EHELFSAVE="$LD_LIBRARY_PATH"
export PATH_EHELFSAVE="$PATH"
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")"
export PATH="$(colon_prepend \
"$(colon_prepend \
"$(ifpath "$LIBUNWIND_PREFIX/bin")" \
"$(ifpath "$PERF_PREFIX/bin")")" \
"$PATH")"
export PS1="($flavour $dbg) $PS1"
unset ifpath
unset colon_prepend