Eric Fiselier | b0f1013 | 2019-01-19 23:36:06 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | #===- libcxx/utils/docker/scripts/build-gcc.sh ----------------------------===// |
| 3 | # |
Chandler Carruth | 9d610c5 | 2019-02-11 08:39:23 +0000 | [diff] [blame] | 4 | # 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 Fiselier | b0f1013 | 2019-01-19 23:36:06 +0000 | [diff] [blame] | 7 | # |
| 8 | #===-----------------------------------------------------------------------===// |
| 9 | |
| 10 | set -e |
| 11 | |
| 12 | function show_usage() { |
| 13 | cat << EOF |
| 14 | Usage: build_gcc_version.sh [options] |
| 15 | |
| 16 | Run autoconf with the specified arguments. Used inside docker container. |
| 17 | |
| 18 | Available 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. |
| 23 | Required options: --install and --branch |
| 24 | |
| 25 | All options after '--' are passed to CMake invocation. |
| 26 | EOF |
| 27 | } |
| 28 | |
| 29 | GCC_INSTALL_DIR="" |
| 30 | GCC_BRANCH="" |
| 31 | CHERRY_PICK="" |
| 32 | |
| 33 | while [[ $# -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 |
| 58 | done |
| 59 | |
| 60 | if [ "$GCC_INSTALL_DIR" == "" ]; then |
| 61 | echo "No install directory. Please specify the --install argument." |
| 62 | exit 1 |
| 63 | fi |
| 64 | |
| 65 | if [ "$GCC_BRANCH" == "" ]; then |
| 66 | echo "No branch specified. Please specify the --branch argument." |
| 67 | exit 1 |
| 68 | fi |
| 69 | |
| 70 | set -x |
| 71 | |
| 72 | NPROC=`nproc` |
| 73 | TMP_ROOT="$(mktemp -d -p /tmp)" |
| 74 | GCC_SOURCE_DIR="$TMP_ROOT/gcc" |
| 75 | GCC_BUILD_DIR="$TMP_ROOT/build" |
| 76 | |
| 77 | echo "Cloning source directory for branch $GCC_BRANCH" |
| 78 | git clone --branch "$GCC_BRANCH" --single-branch --depth=1 git://gcc.gnu.org/git/gcc.git $GCC_SOURCE_DIR |
| 79 | |
| 80 | pushd "$GCC_SOURCE_DIR" |
| 81 | if [ "$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" |
| 84 | fi |
| 85 | ./contrib/download_prerequisites |
| 86 | popd |
| 87 | |
| 88 | |
| 89 | mkdir "$GCC_BUILD_DIR" |
| 90 | pushd "$GCC_BUILD_DIR" |
| 91 | |
| 92 | # Run the build as specified in the build arguments. |
| 93 | echo "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 | |
| 99 | echo "Running build with $NPROC threads" |
| 100 | make -j$NPROC |
| 101 | echo "Installing to $GCC_INSTALL_DIR" |
| 102 | make install -j$NPROC |
| 103 | popd |
| 104 | |
| 105 | # Cleanup. |
| 106 | rm -rf "$TMP_ROOT" |
| 107 | |
| 108 | echo "Done" |