-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·207 lines (186 loc) · 5.5 KB
/
install.sh
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash
#
# platin installation script
#
function abspath() {
local path=$1
local pwd_restore="$(pwd)"
# readlink -f does not work on OSX, so we do this manually
cd $(dirname "$path")
path=$(basename "$path")
# follow chain of symlinks
while [ -L "$path" ]; do
path=$(readlink "$path")
cd $(dirname "$path")
path=$(basename "$path")
done
echo "$(pwd -P)/$path"
cd "$pwd_restore"
}
self=$(abspath "${0}")
SRC_DIR=$(dirname "$self")
# find ruby,gem,rdoc commands
source "${SRC_DIR}/ext/detect_ruby_commands"
detect_ruby
detect_gem_command
function usage() {
echo "usage: ${0} -i INSTALL_DIR [-b BUILD_DIR] [-d]" >&2
echo >&2
echo "Install the platin toolchain relative to the given prefix" >&2
echo "Installed Files: " >&2
echo " <prefix>/bin/platin ... Binary" >&2
echo " <prefix>/lib/platin/ ... Library Directory" >&2
echo " <prefix>/lib/platin/gems ... Ruby Libraries (if necessary)" >&2
echo "OPTIONS" >&2
echo " -d dry run" >&2
echo " -v verbose" >&2
exit 1
}
BUILD_DIR="$SRC_DIR/build"
while getopts "hi:b:dvx" opt; do
case $opt in
h) usage; exit 0 ;;
i) INSTALL_DIR="${OPTARG}" ;;
b) BUILD_DIR="${OPTARG}" ;;
d) DRYRUN=true; VERBOSE=true ;;
v) VERBOSE=true ;;
x) set -x ;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage >&2
exit 1
;;
esac
done
if [ -z "${INSTALL_DIR}" ] ; then
usage
fi
BINARY="${INSTALL_DIR}/bin/platin"
COMPILER="${INSTALL_DIR}/bin/patmos-clang-wcet"
LIB_DIR="${INSTALL_DIR}/lib/platin"
GEM_DIR="${LIB_DIR}/gems"
function info() {
if [ ! -z "${VERBOSE}" ] ; then
echo 'INFO' "${@}"
else
echo "${@}"
fi
}
function install() {
DST="${1}"
SRC="${2}"
info "Installing ${SRC} -> ${DST}"
run mkdir -p "$(dirname "${DST}")"
run cp "${SRC}" "${DST}"
}
function verbose() {
if [ ! -z "${VERBOSE}" ] ; then
echo "${@}"
fi
}
function run() {
CMD="${1}"
shift
verbose "${CMD}" "${@}"
if [ -z "${DRYRUN}" ] ; then
"${CMD}" "${@}"
fi
}
# A note on GEM_PATH (as of ruby 1.9.3 / gem 1.8.11):
# * GEM_PATH should be a colon separated list of directories
# caveat: if there is a *trailing* colon, the GEM_PATH environment
# variable is *ignored*
# * if GEM_PATH is set, the lookup path for gems is global repo and
# all directories listed in GEM_PATH
# * if GEM_PATH is not set, the lookup path for gems is global repo
# *and* the user local repository
#
# Therefore, if we need gems from the user local repository and from
# the platin-specific gem repository, we need to include the
# user local repositories in GEM_PATH. As we do not know about them
# we simply read 'gem env gempath' and add all directories to
# GEM_PATH.
function ruby_wrapper_header() {
echo '#!/bin/bash'
cat "${SRC_DIR}/ext/detect_ruby_commands"
cat <<EOF
detect_ruby
detect_gem_command
if [ -z "\${GEM}" ] ; then
export GEM_PATH="${GEM_DIR}"
else
CURRENT_GEM_PATH=\$(\${GEM} env gempath)
export GEM_PATH="${GEM_DIR}:\${CURRENT_GEM_PATH}"
fi
EOF
}
function install_binary() {
install "${BINARY}" "${SRC_DIR}/platin"
run chmod uga+x "${BINARY}"
if [ -z "${DRYRUN}" ] ; then
ruby_wrapper_header >"${BINARY}"
echo 'RELATIVE_LIBDIR="../lib/platin"' >>"${BINARY}"
cat "${SRC_DIR}/platin" >> "${BINARY}"
fi
}
function install_wcet_compiler() {
install "${COMPILER}" "${SRC_DIR}/platin"
run chmod uga+x "${BINARY}"
if [ -z "${DRYRUN}" ] ; then
ruby_wrapper_header > "${COMPILER}"
cat <<EOF >>"${COMPILER}"
LIBDIR=\$(dirname \${0})/../lib/platin
COMPILER_SCRIPT="\${LIBDIR}"/ext/patmos-clang-wcet.rb
exec \${RUBY} -I "\${LIBDIR}" "\${COMPILER_SCRIPT}" "\${@}"
EOF
fi
}
function install_late_bypass() {
local dir="${SRC_DIR}/ext/patch_loads"
local builddir="${BUILD_DIR}/ext/patch_loads"
mkdir -p $builddir
if (cd $builddir && cmake $dir && make ) 2>&1 > /dev/null ; then
DST="${INSTALL_DIR}/lib/platin/ext/patch_loads"
install "${DST}" "${builddir}/patch_loads"
else
info "Warning: could not build patch_loads tool." \
"platin late-bypass will not work."
fi
}
install_binary
install_wcet_compiler
install_late_bypass
for libfile in $(cd "${SRC_DIR}/lib" ; find "." -name '*.rb' -o -name '*.yml') ; do
SRC="${SRC_DIR}/lib/${libfile}"
DST="${INSTALL_DIR}/lib/platin/${libfile}"
install "${DST}" "${SRC}"
done
if [ ! -z "${GEM}" ] ; then
if [ -z "${GEM_PATH}" ] ; then
export GEM_PATH="${GEM_DIR}"
else
export GEM_PATH="${GEM_DIR}:${GEM_PATH}"
fi
for gemqname in rsec:0.4 ruby-graphviz:1.0.8 kwalify:0.7.2 lpsolve:5.5.10.j ; do
gemname=$(echo "${gemqname}" | cut -d':' -f1)
gemversion=$(echo "${gemqname}" | cut -d':' -f2)
verbose "INFO checking for gem ${gemqname}"
if [ "$(${GEM} list ${gemname} --version ${gemversion} -i)" != "true" ] ; then
info "Installing gem ${gemname} --version ${gemversion} (missing)"
local_gemfile="${SRC_DIR}/ext/${gemname}-${gemversion}.gem"
if [ -z "${DRYRUN}" ] ; then
if [ -e "${local_gemfile}" ] ; then
gem_args="${local_gemfile}"
else
gem_args="${gemname} --version ${gemversion}"
fi
"${GEM}" install --install-dir "${GEM_DIR}" ${gem_args} -q 2>&1 | sed 's/^/[GEM] /'
if [ "${PIPESTATUS[0]}" -ne 0 ] ; then
echo "WARNING: failed to install gem ${gem_args}. platin will not work." >&2
fi
fi
fi
done
else
echo "WARNING: did not find 'gem' command; skipping ruby library checks" >&2
fi