run_sparc.sh
7.48 KB
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/bin/bash
LLVM_NAME=llvm
LLVM_VERSION=13.0.0
LLVM_SERVER="https://github.com/llvm/llvm-project.git"
#LLVM_GIT_BRANCH="release/10.x"
#LLVM_GIT_COMMIT="ef32c611aa214dea855364efd7ba451ec5ec3f74"
#LLVM_GIT_COMMIT="3186b18b998124a6b577f8274a10b7ee8b634c18"
# release/13.x (2021/09/06)
LLVM_GIT_BRANCH="release/13.x"
LLVM_GIT_COMMIT="181739213aa00de40a5bc6fbb1c578ce25b78d39"
DAITEQ_BRANCH="daiteq"
TGT_TRIPLE=sparc-daiteq-none-elf
HOST_TRIPLE=x86_64-linux-gnu
CURDIR="$(pwd)"
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# number of cores used for make
MAKE_CORES=$(nproc --all)
DIR_SRCS=${CURDIR}/source
DIR_BLD=${CURDIR}/build-sparc
DIR_INST=${CURDIR}/install-sparc
DIR_PTCH=${SCRIPTDIR}/patches
DIR_DEBUG=${CURDIR}/debug-sparc
GENDIRS="${DIR_SRCS} ${DIR_BLD} ${DIR_INST}"
#DN_BUUNP=${DIR_UPCK}/${BU_NAME}-${BU_VERSION}
CCMAKE_ARGS="-D CMAKE_BUILD_TYPE=Release \
-D BUILD_SHARED_LIBS=ON \
-D LLVM_ENABLE_Z3_SOLVER=OFF \
-D CMAKE_INSTALL_PREFIX=${DIR_INST} \
-D LLVM_DEFAULT_TARGET_TRIPLE=${TGT_TRIPLE} \
-D LLVM_EXTERNAL_CLANG_SOURCE_DIR=${DIR_SRCS}/clang \
-D LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR=${DIR_SRCS}/clang-tools-extra \
-D LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR=${DIR_SRCS}/compiler-rt \
-D LLVM_INCLUDE_DOCS=OFF \
-D LLVM_ENABLE_OCAMLDOC=OFF \
-D LLVM_INSTALL_BINUTILS_SYMLINKS=ON \
-D LLVM_TARGETS_TO_BUILD=Sparc \
-D LLVM_TARGET_ARCH=sparc \
-D LLVM_TOOL_CLANG_BUILD=ON \
-D LLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=ON \
-D CLANG_INCLUDE_TESTS=ON \
-D CLANG_VENDOR=daiteq-esa \
-D LLVM_TOOL_COMPILER_RT_BUILD=OFF"
# -D COMPILER_RT_USE_BUILTINS_LIBRARY=ON
CCMAKE_DEBUG_ARGS="-D CMAKE_BUILD_TYPE:STRING=Debug \
-D LLVM_ENABLE_ASSERTIONS:BOOL=ON \
-D BUILD_SHARED_LIBS=ON \
-D LLVM_ENABLE_Z3_SOLVER=OFF \
-D CMAKE_INSTALL_PREFIX=${DIR_INST} \
-D LLVM_DEFAULT_TARGET_TRIPLE=${TGT_TRIPLE} \
-D LLVM_EXTERNAL_CLANG_SOURCE_DIR=${DIR_SRCS}/clang \
-D LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR=${DIR_SRCS}/clang-tools-extra \
-D LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR=${DIR_SRCS}/compiler-rt \
-D LLVM_INCLUDE_DOCS=OFF \
-D LLVM_ENABLE_OCAMLDOC=OFF \
-D LLVM_INSTALL_BINUTILS_SYMLINKS=ON \
-D LLVM_TARGETS_TO_BUILD=Sparc \
-D LLVM_TARGET_ARCH=sparc \
-D LLVM_TOOL_CLANG_BUILD=ON \
-D LLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=ON \
-D CLANG_INCLUDE_TESTS=ON \
-D CLANG_VENDOR=daiteq-esa \
-D LLVM_TOOL_COMPILER_RT_BUILD=OFF"
prepare_dirs() {
for d in ${GENDIRS}
do
echo "Create directory ${d}"
mkdir -p ${d}
done
}
download_source() {
mkdir -p ${DIR_SRCS}
if [ "$(ls -A ${DIR_SRCS})" ]
then
echo "Repository is already cloned ... check consistency"
else
git clone --progress -n --branch ${LLVM_GIT_BRANCH} ${LLVM_SERVER} ${DIR_SRCS}
fi
cd ${DIR_SRCS}
# is there already working branch
if [ $(git branch --list ${DAITEQ_BRANCH}) ]
then
# already exists
git checkout ${DAITEQ_BRANCH}
else
# no work branch
git reset --hard ${LLVM_GIT_COMMIT}
git branch ${DAITEQ_BRANCH}
git checkout ${DAITEQ_BRANCH}
fi
cd ${CURDIR}
}
apply_patches() {
if [ ! -e ${DIR_PTCH} ]
then
echo "There is not a directory with patches"
exit 1
fi
cd ${DIR_SRCS}
# change branch to ours
git checkout ${DAITEQ_BRANCH}
# reset to the source LLVM commit
git reset --hard ${LLVM_GIT_COMMIT}
# check applying patches
for p in `ls ${DIR_PTCH}/*.txt | sort -V`
do
echo "Use patch ${p}"
git apply --check --whitespace=fix ${p}
echo vysledek = $?
if [[ $? != 0 ]]; then
echo " Patch cannot be applied."
cd ${CURDIR}
break
fi
git am --whitespace=fix ${p}
done
cd ${CURDIR}
}
do_configure() {
if [ ! -e ${DIR_SRCS} ]
then
echo "There is no unpacked files with source codes"
exit 1
fi
mkdir -p ${DIR_BLD}
cd ${DIR_BLD}
CONF=1
if [ -f CMakeCache.txt ]
then
echo "Compilation is already configured - try it again."
#CONF=0
fi
if [ ${CONF} -eq 1 ]
then
cmake ${CCMAKE_ARGS} ${DIR_SRCS}/llvm
if [ $? -ne 0 ]
then
echo "E: configure failed"
exit 1
fi
fi
}
build_source() {
mkdir -p ${DIR_BLD}
cd ${DIR_BLD}
if [ ! -f Makefile ]
then
echo "Compilation is not configured - run configuration."
do_configure
fi
make -j ${MAKE_CORES}
if [ $? -ne 0 ]
then
echo "E: make failed"
exit 1
fi
cd ${CURDIR}
}
build_debug() {
if [ ! -e ${DIR_SRCS} ]
then
echo "There is no unpacked files with source codes"
exit 1
fi
mkdir -p ${DIR_DEBUG}
cd ${DIR_DEBUG}
if [ -f CMakeCache.txt ]
then
echo "Compilation is already configured - try it again."
#CONF=0
else
cmake ${CCMAKE_DEBUG_ARGS} ${DIR_SRCS}/llvm
if [ $? -ne 0 ]
then
echo "E: configure failed"
exit 1
fi
fi
make -j ${MAKE_CORES}
if [ $? -ne 0 ]
then
echo "E: make debug failed"
exit 1
fi
cd ${CURDIR}
}
install_pkg() {
mkdir -p ${DIR_INST}
cd ${DIR_BLD}
make install
cd ${CURDIR}
}
clean_build() {
echo "Removing build and install directories."
rm -rf ${DIR_BLD} ${DIR_INST}
}
clean_unpacked() {
echo "Removing patches from the repository."
cd ${DIR_SRCS}
# change branch to ours
git checkout ${DAITEQ_BRANCH}
# reset to the source LLVM commit
git reset --hard ${LLVM_GIT_COMMIT}
# check applying patches
cd ${CURDIR}
}
distclean_all() {
echo "Removing all download and generated files and directories."
rm -rf ${GENDIRS}
}
# ##############################################################################
print_help() {
echo "The script needs one argument - required operation:"
echo " all - do all steps (get,patch,config,build,install)"
echo " get - download source package if it doesn't exist"
echo " patch - patch original package"
echo " config - perform configuration in build directory (cmake)"
echo " build - build LLVM package (make)"
echo " install - install LLVM to the output directory"
echo " clean - remove generated files (build and install dirs.)"
echo " packclean - remove unpacked files (unpack dir.)"
echo " distclean - remove all generated files and directories"
echo " debug - build debug version of LLVM package"
}
# ##############################################################################
# main ...
echo "Script for preparing patched LLVM for LEON IP core extensions."
if [ "$#" -ne 1 ]
then
print_help
exit 0
fi
case $1 in
"all" )
#echo "do all"
download_source
apply_patches
do_configure
build_source
install_pkg
;;
"get" )
#echo "do clone LLVM"
download_source
;;
"patch" )
#echo "do patch"
apply_patches
;;
"config" )
#echo "do configure"
do_configure
;;
"build" )
#echo "do build"
build_source
;;
"install" )
#echo "do install"
install_pkg
;;
"clean" )
#echo "do clean"
clean_build
;;
"packclean" )
#echo "do packclean"
clean_unpacked
;;
"distclean" )
#echo "do distclean"
distclean_all
;;
"debug" )
#echo "do debug"
build_debug
;;
* )
echo "E: Unsupported operation"
print_help
exit 1
;;
esac