build_gcc_version.sh
2.58 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
#!/usr/bin/env bash
#===- libcxx/utils/docker/scripts/build-gcc.sh ----------------------------===//
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#===-----------------------------------------------------------------------===//
set -e
function show_usage() {
cat << EOF
Usage: build_gcc_version.sh [options]
Run autoconf with the specified arguments. Used inside docker container.
Available options:
-h|--help show this help message
--branch the branch of gcc you want to build.
--cherry-pick a commit hash to apply to the GCC sources.
--install destination directory where to install the targets.
Required options: --install and --branch
All options after '--' are passed to CMake invocation.
EOF
}
GCC_INSTALL_DIR=""
GCC_BRANCH=""
CHERRY_PICK=""
while [[ $# -gt 0 ]]; do
case "$1" in
--install)
shift
GCC_INSTALL_DIR="$1"
shift
;;
--branch)
shift
GCC_BRANCH="$1"
shift
;;
--cherry-pick)
shift
CHERRY_PICK="$1"
shift
;;
-h|--help)
show_usage
exit 0
;;
*)
echo "Unknown option: $1"
exit 1
esac
done
if [ "$GCC_INSTALL_DIR" == "" ]; then
echo "No install directory. Please specify the --install argument."
exit 1
fi
if [ "$GCC_BRANCH" == "" ]; then
echo "No branch specified. Please specify the --branch argument."
exit 1
fi
set -x
NPROC=`nproc`
TMP_ROOT="$(mktemp -d -p /tmp)"
GCC_SOURCE_DIR="$TMP_ROOT/gcc"
GCC_BUILD_DIR="$TMP_ROOT/build"
echo "Cloning source directory for branch $GCC_BRANCH"
git clone --branch "$GCC_BRANCH" --single-branch --depth=1 git://gcc.gnu.org/git/gcc.git $GCC_SOURCE_DIR
pushd "$GCC_SOURCE_DIR"
if [ "$CHERRY_PICK" != "" ]; then
git fetch origin trunk --unshallow # Urg, we have to get the entire history. This will take a while.
git cherry-pick --no-commit -X theirs "$CHERRY_PICK"
fi
./contrib/download_prerequisites
popd
mkdir "$GCC_BUILD_DIR"
pushd "$GCC_BUILD_DIR"
# Run the build as specified in the build arguments.
echo "Running configuration"
$GCC_SOURCE_DIR/configure --prefix=$GCC_INSTALL_DIR \
--disable-bootstrap --disable-libgomp --disable-libitm \
--disable-libvtv --disable-libcilkrts --disable-libmpx \
--disable-liboffloadmic --disable-libcc1 --enable-languages=c,c++
echo "Running build with $NPROC threads"
make -j$NPROC
echo "Installing to $GCC_INSTALL_DIR"
make install -j$NPROC
popd
# Cleanup.
rm -rf "$TMP_ROOT"
echo "Done"