Add the environment activation script

This commit is contained in:
Sameer Rahmani 2023-02-03 00:47:26 +00:00
parent 889248aa68
commit b3cc33d9c8
Signed by: lxsameer
GPG Key ID: B0A4AF28AB9FD90B
2 changed files with 103 additions and 2 deletions

103
activate Normal file
View File

@ -0,0 +1,103 @@
# Serene Programming Language
#
# Copyright (c) 2019-2022 Sameer Rahmani <lxsameer@gnu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
# Commentary
# -----------------------------------------------------------------------------
# This file must be used with "source activate" *from bash* you cannot run it
# directly.
#
# It will activate the development environment by making the dependencies
# visible to the build system.
#
# Use the `deactiavate` function to go back to your normal shell
if [ "${BASH_SOURCE-}" = "$0" ]; then
echo "You must source this script: \$ source $0" >&2
exit 33
fi
deactivate () {
# reset old environment variables
# ! [ -z ${VAR+_} ] returns true if VAR is declared at all
if ! [ -z "${_OLD_PATH:+_}" ] ; then
PATH="$_OLD_PATH"
export PATH
unset _OLD_PATH
fi
# The hash command must be called to get it to forget past
# commands. Without forgetting past commands the $PATH changes
# we made may not be respected
hash -r 2>/dev/null
if ! [ -z "${_OLD_PS1+_}" ] ; then
PS1="$_OLD_PS1"
export PS1
unset _OLD_PS1
fi
unset BUILD_DIR
unset TARGET_ARCHS
unset DEV_HEROES
unset BUILD_DIR_NAME
unset ME
unset LLVM_DIR_NAME
unset LLVM_DIR
unset LLVM_SOURCE_DIR
unset LLVM_BUILD_DIR
unset LLVM_INSTALL_DIR
unset BDWGC_DIR_NAME
unset BDWGC_DIR
unset BDWGC_BUILD_DIR
unset BDWGC_INSTALL_DIR
unset BDWgc_DIR
if [ ! "${1-}" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
}
# unset irrelevant variables
deactivate nondestructive
ME=$(cd "$(dirname "$0")/." >/dev/null 2>&1 ; pwd -P)
source "$ME/config"
info "Activating LLVM version '$(get_version $LLVM_DIR)'"
info "Activating BDWGC version '$(get_version $BDWGC_SOURCE_DIR)'"
_OLD_PATH="$PATH"
PATH="$LLVM_INSTALL_DIR/bin:$PATH"
export PATH
if [ -z "${BUILD_DIR_DISABLE_PROMPT-}" ] ; then
_OLD_PS1="${PS1-}"
if [ "x" != x ] ; then
PS1="() ${PS1-}"
else
PS1="(World) ${PS1-}"
fi
export PS1
fi
# The hash command must be called to get it to forget past
# commands. Without forgetting past commands the $PATH changes
# we made may not be respected
hash -r 2>/dev/null

View File

@ -34,8 +34,6 @@ function build_toolchain() { ## Build LLVM and the toolchain
if [[ -d "$LLVM_BUILD_DIR.$version" ]]; then
warn "A build dir for 'llvm' already exists at '$LLVM_BUILD_DIR.$version'"
warn "Skipping..."
return
fi
mkdir -p "$LLVM_BUILD_DIR.$version"