/
compile_clang_format
executable file
·103 lines (86 loc) · 2.85 KB
/
compile_clang_format
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
#!/bin/bash
## ---------------------------------------------------------------------
##
## Copyright (C) 2018 - 2021 by the deal.II authors
##
## This file is part of the deal.II library.
##
## The deal.II library is free software; you can use it, redistribute
## it, and/or modify it under the terms of the GNU Lesser General
## Public License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
## The full text of the license can be found in the file LICENSE.md at
## the top level directory of deal.II.
##
## ---------------------------------------------------------------------
#
# This script downloads, compiles and installs the clang-format binary. The
# destination directory is
# [contrib/utilities]/programs/clang-<VERSION>/bin.
#
# Compiling clang-format and all necessary parts of LLVM/CLANG might
# require a significant amount of resources. Alternatively, you can use
# download_clang_format to install a statically-linked binary.
#
set -e
set -u
PRG="$(cd "$(dirname "$0")" && pwd)/programs"
VERSION="11"
RELEASE_DATE="2021-02-03"
LLVM_COMMIT="1fdec59bffc11ae37eb51a1b9869f0696bfd5312"
CLANG_PATH="${PRG}/clang-${VERSION}"
RELEASE_BRANCH="release/${VERSION}.x"
LLVM_REPOSITORY="https://github.com/llvm/llvm-project"
if [ ! -d "${PRG}" ]
then
echo "create folder ${PRG}"
mkdir "${PRG}"
fi
if [ -d "${CLANG_PATH}" ]
then
echo "${CLANG_PATH} exists. Exiting."
exit 1
fi
echo "Downloading and compiling clang-format-${VERSION}."
mkdir -p "${CLANG_PATH}/bin"
tmpdir="${TMPDIR:-/tmp}/dealiiclang${RANDOM}${RANDOM}"
mkdir -p "${tmpdir}"
cd "${tmpdir}"
GIT_VERSION=$(git version)
GIT_MAJOR_VERSION=$(echo "${GIT_VERSION}" | sed 's/^[^0-9]*\([0-9]*\).*$/\1/g')
GIT_MINOR_VERSION=$(echo "${GIT_VERSION}" | sed 's/^[^0-9]*[0-9]*\.\([0-9]*\).*$/\1/g')
if [ "$GIT_MAJOR_VERSION" -ge 2 ] && [ "$GIT_MINOR_VERSION" -ge 11 ]; then
GIT_SHALLOW_SINCE_AVAILABLE=true
else
GIT_SHALLOW_SINCE_AVAILABLE=false
fi
git init
git remote add origin "${LLVM_REPOSITORY}"
if [ "$GIT_SHALLOW_SINCE_AVAILABLE" = true ]; then
git fetch --shallow-since="${RELEASE_DATE}" origin "${RELEASE_BRANCH}"
else
git fetch --depth=1 origin "${RELEASE_BRANCH}"
i=1;
while ! git cat-file -e ${LLVM_COMMIT} 2> /dev/null; do
git fetch --depth=$((i+=10)) origin "${RELEASE_BRANCH}";
done
fi
git reset --hard "${LLVM_COMMIT}"
# move clang directory into right place for the build system
mv clang llvm/tools
mkdir llvm/build
cd llvm/build
case "${OSTYPE}" in
darwin*)
cmake -DCMAKE_BUILD_TYPE=MinSizeRel ..
;;
*)
cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DLLVM_BUILD_STATIC=true ..
;;
esac
make -j4 clang-format
cp bin/clang-format "${CLANG_PATH}"/bin
cp ../{CODE_OWNERS,CREDITS,LICENSE}.TXT "${CLANG_PATH}"
rm -rf "${tmpdir}"
echo "All done. clang-format successfully installed into"
echo " ${CLANG_PATH}/bin"