forked from trailblazing/llvm-bit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynamic-switch-llvm-ykt.sh
194 lines (175 loc) · 4.73 KB
/
dynamic-switch-llvm-ykt.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
#!/bin/sh
if ! [ "$WORKING_PATH" = "" ] ; then
ORIGINAL_SRC_ROOT=$WORKING_PATH/llvm
ORIGINAL_BUILD_ROOT=$WORKING_PATH/build-llvm
ORIGINAL_OBJ_ROOT=$WORKING_PATH/install-llvm
SRC_ROOT=$WORKING_PATH/llvm-ykt
BUILD_ROOT=$WORKING_PATH/build-llvm-ykt
OBJ_ROOT=$WORKING_PATH/install-llvm-ykt
export SRC_ROOT
export OBJ_ROOT
original_build_root="$ORIGINAL_BUILD_ROOT"
original_obj_root="$ORIGINAL_OBJ_ROOT"
build_root="$BUILD_ROOT"
obj_root="$OBJ_ROOT"
# http://stackoverflow.com/questions/918886/how-do-i-split-a-string-on-a-delimiter-in-bash
# deal with CPATH
ADDR=""
IFS=':' read -ra ADDR <<< "$CPATH"
#while IFS=':' read -ra ADDR; do
for i in "${ADDR[@]}"; do
if [[ ! ( "${i/$original_obj_root}" = "$i" ) ]]; then
CPATH=${CPATH/$i};
fi;
if [[ ! ( "${i/$obj_root}" = "$i" ) ]]; then
CPATH=${CPATH/$i};
fi;
if [[ ! ( "${i/$original_build_root}" = "$i" ) ]]; then
CPATH=${CPATH/$i};
fi;
if [[ ! ( "${i/$build_root}" = "$i" ) ]]; then
CPATH=${CPATH/$i};
fi;
done;
#done <<< "$CPATH";
ADDR=""
tmp=""
IFS=':' read -ra ADDR <<< "$CPATH"
#while IFS=':' read -ra ADDR; do
for i in "${ADDR[@]}"; do
if [[ ! ( "$i" = "" ) ]] ; then
if [ "$tmp" = "" ] ; then
tmp=$i
else
tmp=$tmp:$i
fi;
fi;
done
#done <<< "$CPATH";
if [ "$tmp" = "" ] ; then
CPATH=$OBJ_ROOT/include:$OBJ_ROOT/lib:$OBJ_ROOT/bin:$ORIGINAL_OBJ_ROOT/include:$ORIGINAL_OBJ_ROOT/lib:$ORIGINAL_OBJ_ROOT/bin
# CPATH=$OBJ_ROOT/include:$tmp
else
CPATH=$OBJ_ROOT/include:$OBJ_ROOT/lib:$OBJ_ROOT/bin:$ORIGINAL_OBJ_ROOT/include:$ORIGINAL_OBJ_ROOT/lib:$ORIGINAL_OBJ_ROOT/bin:$tmp
# CPATH=$OBJ_ROOT/include:$tmp
fi;
export CPATH
# deal with PATH
ADDR=""
IFS=':' read -ra ADDR <<< "$PATH"
for i in "${ADDR[@]}"; do
if [[ ! ( "${i/$original_obj_root}" = "$i" ) ]]; then
PATH=${PATH/$i};
fi;
if [[ ! ( "${i/$obj_root}" = "$i" ) ]]; then
PATH=${PATH/$i};
fi;
if [[ ! ( "${i/$original_build_root}" = "$i" ) ]]; then
PATH=${PATH/$i};
fi;
if [[ ! ( "${i/$build_root}" = "$i" ) ]]; then
PATH=${PATH/$i};
fi;
done;
ADDR=""
tmp=""
IFS=':' read -ra ADDR <<< "$PATH"
for i in "${ADDR[@]}"; do
if [[ ! ( "$i" = "" ) ]] ; then
if [ "$tmp" = "" ] ; then
tmp=$i
else
tmp=$tmp:$i
fi;
fi;
done
if [ "$tmp" = "" ] ; then
PATH=$OBJ_ROOT/include:$OBJ_ROOT/lib:$OBJ_ROOT/bin:$ORIGINAL_OBJ_ROOT/include:$ORIGINAL_OBJ_ROOT/lib:$ORIGINAL_OBJ_ROOT/bin
else
PATH=$OBJ_ROOT/include:$OBJ_ROOT/lib:$OBJ_ROOT/bin:$ORIGINAL_OBJ_ROOT/include:$ORIGINAL_OBJ_ROOT/lib:$ORIGINAL_OBJ_ROOT/bin:$tmp
fi;
export PATH
if ! [ "$1" = "" ]; then
cuda_device="$1" #"/usr/lib/nvidia-cuda-toolkit/libdevice"
# deal with LD_LIBRARY_PATH
ADDR=""
IFS=':' read -ra ADDR <<< "$LD_LIBRARY_PATH"
for i in "${ADDR[@]}"; do
if [[ ! ( "${i/$original_obj_root}" = "$i" ) ]]; then
LD_LIBRARY_PATH=${LD_LIBRARY_PATH/$i};
fi;
if [[ ! ( "${i/$obj_root}" = "$i" ) ]]; then
LD_LIBRARY_PATH=${LD_LIBRARY_PATH/$i};
fi;
if [[ ! ( "${i/$original_build_root}" = "$i" ) ]]; then
LD_LIBRARY_PATH=${LD_LIBRARY_PATH/$i};
fi;
if [[ ! ( "${i/$build_root}" = "$i" ) ]]; then
LD_LIBRARY_PATH=${LD_LIBRARY_PATH/$i};
fi;
if [[ ! ( "${i/$cuda_device}" = "$i" ) ]]; then
LD_LIBRARY_PATH=${LD_LIBRARY_PATH/$i};
fi;
done;
ADDR=""
tmp=""
IFS=':' read -ra ADDR <<< "$LD_LIBRARY_PATH"
for i in "${ADDR[@]}"; do
if [[ ! ( "$i" = "" ) ]] ; then
if [ "$tmp" = "" ] ; then
tmp=$i
else
tmp=$tmp:$i
fi;
fi;
done
if [ "$tmp" = "" ] ; then
LD_LIBRARY_PATH=$OBJ_ROOT/lib:$ORIGINAL_OBJ_ROOT/lib:$cuda_device
else
LD_LIBRARY_PATH=$OBJ_ROOT/lib:$ORIGINAL_OBJ_ROOT/lib:$cuda_device:$tmp
fi;
export LD_LIBRARY_PATH
# deal with LIBRARY_PATH
ADDR=""
IFS=':' read -ra ADDR <<< "$LIBRARY_PATH"
for i in "${ADDR[@]}"; do
if ! [ "${i/$original_obj_root}" = "$i" ]; then
LIBRARY_PATH=${LIBRARY_PATH/$i};
fi;
if ! [ "${i/$obj_root}" = "$i" ]; then
LIBRARY_PATH=${LIBRARY_PATH/$i};
fi;
if ! [ "${i/$original_build_root}" = "$i" ]; then
LIBRARY_PATH=${LIBRARY_PATH/$i};
fi;
if ! [ "${i/$build_root}" = "$i" ]; then
LIBRARY_PATH=${LIBRARY_PATH/$i};
fi;
if ! [ "${i##$cuda_device}" = "$i" ]; then
LIBRARY_PATH=${LIBRARY_PATH/$i};
fi;
done;
ADDR=""
tmp=""
IFS=':' read -ra ADDR <<< "$LIBRARY_PATH"
for i in "${ADDR[@]}"; do
if ! [ "$i" = "" ] ; then
if [ "$tmp" = "" ] ; then
tmp=$i
else
tmp=$tmp:$i
fi;
fi;
done
if [ "$tmp" = "" ] ; then
LIBRARY_PATH=$OBJ_ROOT/lib:$ORIGINAL_OBJ_ROOT/lib:$cuda_device
else
LIBRARY_PATH=$OBJ_ROOT/lib:$ORIGINAL_OBJ_ROOT/lib:$cuda_device:$tmp
fi;
export LIBRARY_PATH
else
echo "cuda libdevice path has not provided."
fi;
else
echo "export WORKING_PATH first."
fi;