-
Notifications
You must be signed in to change notification settings - Fork 3
/
patmos-chrpath
executable file
·163 lines (136 loc) · 3.51 KB
/
patmos-chrpath
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
#!/bin/bash
###############################################################################
#
# rpath update script for the Patmos compiler tool chain build scripts.
#
# Authors:
# Stefan Hepp <[email protected]>
#
###############################################################################
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"
}
OS_NAME=$(uname -s)
# physical location of this script, and the config
self=$(abspath $0)
CFGFILE=$(dirname $self)/build.cfg
########################################################################
# Root directory for all repositories
ROOT_DIR=$(pwd)
# Set to 'short' for llvm/clang/... directory names, 'long' for
# patmos-llvm/patmos-clang/.. or 'prefix' to use $(REPO_PREFIX)llvm/..
REPO_NAMES=short
REPO_PREFIX=
# Installation directory prefix
INSTALL_DIR="$ROOT_DIR/local"
########################################################################
VERBOSE=false
WARN=false
DELETE=false
PACKAGE=
BINARY=
# user config
if [ -f $CFGFILE ]; then
source $CFGFILE
fi
function usage() {
cat <<EOT
Usage: $0 [<options>] [-p <reponame> | -b <binary>] [-i <installdir>] [<new_rpath>]
Update the rpath of the installed Patmos binaries.
-h Show this help.
-d Delete the rpath instead of updating it.
-v Be verbose.
-w Warn only if chrpath is not found.
-p Update binaries from the given Patmos package ('llvm','patmos')
-b Update the given binary only.
The default installdir will be taken from build.cfg if not given.
The new rpath will be <installdir>/lib if not set.
EOT
exit 0
}
function update_binary() {
local binary=$1
if [ "$DELETE" == "true" ]; then
if [ "$VERBOSE" == "true" ]; then
echo "$CHRPATH -d $binary"
fi
$CHRPATH -d $binary >/dev/null
else
if [ "$VERBOSE" == "true" ]; then
echo "$CHRPATH -r $RPATH $binary"
fi
$CHRPATH -r $RPATH $binary >/dev/null
fi
}
function update_llvm() {
bindir=$INSTALL_DIR/bin
for file in $bindir/patmos-*; do
case $file in
*patmos*-llvm-lit|*patmos*-ld|*patmos*-ar|*patmos*-ld.gold|*patmos*-clang-wcet) ;;
*patmos*-difftest|*patmos*-sorttimes) ;;
*)
update_binary $file
;;
esac
done
}
# one-shot config
while getopts ":hi:dvp:b:wx" opt; do
case $opt in
h) usage; exit 0 ;;
i) INSTALL_DIR="$(abspath $OPTARG)" ;;
d) DELETE=true ;;
v) VERBOSE=true ;;
p) PACKAGE=$OPTARG ;;
b) BINARY=$OPTARG ;;
w) WARN=true ;;
x) set -x ;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage >&2
exit 1
;;
esac
done
shift $((OPTIND-1))
RPATH=$1
if [ -z $RPATH ]; then
RPATH="$INSTALL_DIR/lib"
fi
CHRPATH=$(which chrpath)
if [ $? != 0 -o ! -x "$CHRPATH" ]; then
if [ "$WARN" == "true" ]; then
echo "** Warning: chrpath not found, skipping."
exit 0
else
echo "** Error: chrpath not found, exiting."
exit 2
fi
fi
if [ ! -z $BINARY ]; then
update_binary $BINARY
elif [ -z $PACKAGE ]; then
update_llvm
elif [ "$PACKAGE" == "llvm" ]; then
update_llvm
else
echo "Unsupported package name: $PACKAGE."
exit 2
fi