-
Notifications
You must be signed in to change notification settings - Fork 0
/
setenv
143 lines (125 loc) · 4.74 KB
/
setenv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env -S sh -c "echo >&2 \"Error: You are running this script instead of sourcing it. Make sure to use it as 'source setenv' or '. setenv', otherwise its settings won't take effect.\"; exit 1"
# first argument can be (e.g. 'source setenv -q'):
# -q : do not show banner text on configuration success
# -r : remove an already configured environment
# Get the directory where this script reside using a trick (works differently on bash and zsh)
# On bash, the current script's name is in 'BASH_SOURCE[0]'
if [ "$BASH_VERSION" != "" ]; then # for BASH
dir=$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)
elif [ "$ZSH_VERSION" != "" ]; then # on zsh the script name is in '$0'
dir=$(cd $(dirname $0) && pwd)
else # other shells are not supported, because we use variable manipulation constructs that are not part of POSIX
echo "Error: Unrecognized shell, only bash and zsh are supported."
return 1
fi
# check if dir is really pointing to an omnet++ installation dir
if [ ! -f "$dir/configure.user" -o ! -f "$dir/include/omnetpp.h" -o ! -f "$dir/Version" ]; then
echo "Error: '$dir' does not look like an OMNeT++ root directory"
return 1
fi
function _numargs() { echo $#; }
if [ $(_numargs $dir) -gt 1 ]; then
echo "Error: Directory name ($dir) must not contain spaces or special characters."
return 1
fi
# utility functions for path manipulation
opp_path_remove()
{
[[ -z $2 ]] && return 2
local value=":$1:"
value=${value//:$2:/:}
value=${value#:}
value=${value%:}
echo $value
}
opp_path_cleanup()
{
for varname in "$@"; do
local value=$(eval echo \$$varname) # note: we use eval because '${!varname}' works only in bash, and '${(P)varname}' works only in zsh
while [[ $value == *::* ]] ; do
value=${value//::/:}
done
value=${value#:}
value=${value%:}
export $varname="$value"
done
}
# remove previous environment to prevent the accumulation of path elements
if [ -n "$__omnetpp_root_dir" ]; then
if [ "$1" = "-r" ]; then
echo "Removed previous environment for '$__omnetpp_root_dir'."
dir=
else
echo "Warning: overwriting previous environment for '$__omnetpp_root_dir'."
fi
export PATH=$(opp_path_remove "$PATH" "$__omnetpp_root_dir/bin")
export PYTHONPATH=$(opp_path_remove "$PYTHONPATH" "$__omnetpp_root_dir/python")
export OMNETPP_IMAGE_PATH=$(opp_path_remove "$OMNETPP_IMAGE_PATH" "$__omnetpp_root_dir/images")
export __omnetpp_root_dir=
export OMNETPP_RELEASE=
export QT_SELECT=
export QT_LOGGING_RULES=
fi
# do not continue if removal was requested
if [ "$1" = "-r" ]; then
return 0
fi
# macOS specific settings
if [ $(uname) = "Darwin" ]; then
if [ $(uname -m) = "arm64" ]; then
if [ -d $dir/tools/macos.x86_64 ]; then
echo "NOTE: We are running on Apple Silicon, but you have downloaded the x86_64 version of the installation package!"
echo "Turning on x86_64 emulation by starting a new shell with 'arch -x86_64 /bin/zsh -i' ..."
export dir; arch -x86_64 /bin/zsh -c 'source $dir/setenv; zsh -i'
return 1
fi
if [ -d $dir/tools/macos.aarch64 ]; then
TOOLS_DIR=$dir/tools/macos.aarch64
export PATH=$TOOLS_DIR/bin:$PATH
fi
else
if [ -d $dir/tools/macos.x86_64 ]; then
TOOLS_DIR=$dir/tools/macos.x86_64
export PATH=$TOOLS_DIR/bin:$PATH
export PIP_PREFIX=$TOOLS_DIR/lib/Python.framework/Versions/Current
export PYTHONNOUSERSITE=1
export BISON_PKGDATADIR=$TOOLS_DIR/share/bison
export QT_PLUGIN_PATH=$TOOLS_DIR/plugins
TOOLS_DIR=
fi
fi
fi
# Windows/MinGW specifiy settings
if [ "$MSYSTEM" = "MINGW64" ] ; then
export PYTHONPATH=
if [ "$VCToolsInstallDir" = "" ] ; then
export PATH="/opt/mingw64/bin:$PATH"
else
export PATH="/opt/visualc/bin:$(cygpath "$VCToolsInstallDir/bin/HostX64/x64"):$PATH"
fi
fi
export PATH="$dir/bin:$PATH"
export PYTHONPATH="$dir/python:$PYTHONPATH"
export OMNETPP_IMAGE_PATH="$dir/images:$OMNETPP_IMAGE_PATH"
export HOSTNAME
export HOST
export QT_SELECT=5 # on systems with qtchooser, switch to Qt5
export QT_LOGGING_RULES='*.debug=false;qt.qpa.*=false' # disable some qt logging
export OMNETPP_RELEASE=$(cat $dir/Version)
export __omnetpp_root_dir=$dir
dir=
if [ "$1" != "-q" ]; then
echo "Environment for '$OMNETPP_RELEASE' in directory '$__omnetpp_root_dir' is ready."
if [ ! -f $__omnetpp_root_dir/Makefile.inc ]; then
cat <<__END__
Type "./configure" and "make" to build the simulation libraries.
When done, type "omnetpp" to start the IDE.
__END__
fi
fi
# source user specific script if present
if [ -f "$__omnetpp_root_dir/setenv_local" ] ; then
source $__omnetpp_root_dir/setenv_local
fi
# Mingw doesn't like extra colons in paths, so remove them using a shell function
opp_path_cleanup PATH PYTHONPATH OMNETPP_IMAGE_PATH