blob: 68aa4c67e3ea6fb08b98c5c745fee8959cb4a2e7 [file] [log] [blame]
Eric Fiselierb0f10132019-01-19 23:36:06 +00001#!/usr/bin/env bash
2#===- libcxx/utils/docker/scripts/build-gcc.sh ----------------------------===//
3#
Chandler Carruth9d610c52019-02-11 08:39:23 +00004# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5# See https://llvm.org/LICENSE.txt for license information.
6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Eric Fiselierb0f10132019-01-19 23:36:06 +00007#
8#===-----------------------------------------------------------------------===//
9
10set -e
11
12function show_usage() {
13 cat << EOF
14Usage: build_gcc_version.sh [options]
15
16Run autoconf with the specified arguments. Used inside docker container.
17
18Available options:
19 -h|--help show this help message
20 --branch the branch of gcc you want to build.
21 --cherry-pick a commit hash to apply to the GCC sources.
22 --install destination directory where to install the targets.
23Required options: --install and --branch
24
25All options after '--' are passed to CMake invocation.
26EOF
27}
28
29GCC_INSTALL_DIR=""
30GCC_BRANCH=""
31CHERRY_PICK=""
32
33while [[ $# -gt 0 ]]; do
34 case "$1" in
35 --install)
36 shift
37 GCC_INSTALL_DIR="$1"
38 shift
39 ;;
40 --branch)
41 shift
42 GCC_BRANCH="$1"
43 shift
44 ;;
45 --cherry-pick)
46 shift
47 CHERRY_PICK="$1"
48 shift
49 ;;
50 -h|--help)
51 show_usage
52 exit 0
53 ;;
54 *)
55 echo "Unknown option: $1"
56 exit 1
57 esac
58done
59
60if [ "$GCC_INSTALL_DIR" == "" ]; then
61 echo "No install directory. Please specify the --install argument."
62 exit 1
63fi
64
65if [ "$GCC_BRANCH" == "" ]; then
66 echo "No branch specified. Please specify the --branch argument."
67 exit 1
68fi
69
70set -x
71
72NPROC=`nproc`
73TMP_ROOT="$(mktemp -d -p /tmp)"
74GCC_SOURCE_DIR="$TMP_ROOT/gcc"
75GCC_BUILD_DIR="$TMP_ROOT/build"
76
77echo "Cloning source directory for branch $GCC_BRANCH"
78git clone --branch "$GCC_BRANCH" --single-branch --depth=1 git://gcc.gnu.org/git/gcc.git $GCC_SOURCE_DIR
79
80pushd "$GCC_SOURCE_DIR"
81if [ "$CHERRY_PICK" != "" ]; then
82 git fetch origin trunk --unshallow # Urg, we have to get the entire history. This will take a while.
83 git cherry-pick --no-commit -X theirs "$CHERRY_PICK"
84fi
85./contrib/download_prerequisites
86popd
87
88
89mkdir "$GCC_BUILD_DIR"
90pushd "$GCC_BUILD_DIR"
91
92# Run the build as specified in the build arguments.
93echo "Running configuration"
94$GCC_SOURCE_DIR/configure --prefix=$GCC_INSTALL_DIR \
95 --disable-bootstrap --disable-libgomp --disable-libitm \
96 --disable-libvtv --disable-libcilkrts --disable-libmpx \
97 --disable-liboffloadmic --disable-libcc1 --enable-languages=c,c++
98
99echo "Running build with $NPROC threads"
100make -j$NPROC
101echo "Installing to $GCC_INSTALL_DIR"
102make install -j$NPROC
103popd
104
105# Cleanup.
106rm -rf "$TMP_ROOT"
107
108echo "Done"