xref: /aosp_15_r20/external/libcxx/utils/docker/scripts/build_gcc.sh (revision 58b9f456b02922dfdb1fad8a988d5fd8765ecb80)
1*58b9f456SAndroid Build Coastguard Worker#!/usr/bin/env bash
2*58b9f456SAndroid Build Coastguard Worker#===- libcxx/utils/docker/scripts/build-gcc.sh ----------------------------===//
3*58b9f456SAndroid Build Coastguard Worker#
4*58b9f456SAndroid Build Coastguard Worker#                     The LLVM Compiler Infrastructure
5*58b9f456SAndroid Build Coastguard Worker#
6*58b9f456SAndroid Build Coastguard Worker# This file is distributed under the University of Illinois Open Source
7*58b9f456SAndroid Build Coastguard Worker# License. See LICENSE.TXT for details.
8*58b9f456SAndroid Build Coastguard Worker#
9*58b9f456SAndroid Build Coastguard Worker#===-----------------------------------------------------------------------===//
10*58b9f456SAndroid Build Coastguard Worker
11*58b9f456SAndroid Build Coastguard Workerset -e
12*58b9f456SAndroid Build Coastguard Worker
13*58b9f456SAndroid Build Coastguard Worker
14*58b9f456SAndroid Build Coastguard Workerfunction show_usage() {
15*58b9f456SAndroid Build Coastguard Worker  cat << EOF
16*58b9f456SAndroid Build Coastguard WorkerUsage: build-gcc.sh [options]
17*58b9f456SAndroid Build Coastguard Worker
18*58b9f456SAndroid Build Coastguard WorkerRun autoconf with the specified arguments. Used inside docker container.
19*58b9f456SAndroid Build Coastguard Worker
20*58b9f456SAndroid Build Coastguard WorkerAvailable options:
21*58b9f456SAndroid Build Coastguard Worker  -h|--help           show this help message
22*58b9f456SAndroid Build Coastguard Worker  --source            the source path from which to run the configuration.
23*58b9f456SAndroid Build Coastguard Worker  --to                destination directory where to install the targets.
24*58b9f456SAndroid Build Coastguard WorkerRequired options: --to, at least one --install-target.
25*58b9f456SAndroid Build Coastguard Worker
26*58b9f456SAndroid Build Coastguard WorkerAll options after '--' are passed to CMake invocation.
27*58b9f456SAndroid Build Coastguard WorkerEOF
28*58b9f456SAndroid Build Coastguard Worker}
29*58b9f456SAndroid Build Coastguard Worker
30*58b9f456SAndroid Build Coastguard WorkerGCC_INSTALL_DIR=""
31*58b9f456SAndroid Build Coastguard WorkerGCC_SOURCE_DIR=""
32*58b9f456SAndroid Build Coastguard Worker
33*58b9f456SAndroid Build Coastguard Workerwhile [[ $# -gt 0 ]]; do
34*58b9f456SAndroid Build Coastguard Worker  case "$1" in
35*58b9f456SAndroid Build Coastguard Worker    --to)
36*58b9f456SAndroid Build Coastguard Worker      shift
37*58b9f456SAndroid Build Coastguard Worker      GCC_INSTALL_DIR="$1"
38*58b9f456SAndroid Build Coastguard Worker      shift
39*58b9f456SAndroid Build Coastguard Worker      ;;
40*58b9f456SAndroid Build Coastguard Worker    --source)
41*58b9f456SAndroid Build Coastguard Worker      shift
42*58b9f456SAndroid Build Coastguard Worker      GCC_SOURCE_DIR="$1"
43*58b9f456SAndroid Build Coastguard Worker      shift
44*58b9f456SAndroid Build Coastguard Worker      ;;
45*58b9f456SAndroid Build Coastguard Worker    -h|--help)
46*58b9f456SAndroid Build Coastguard Worker      show_usage
47*58b9f456SAndroid Build Coastguard Worker      exit 0
48*58b9f456SAndroid Build Coastguard Worker      ;;
49*58b9f456SAndroid Build Coastguard Worker    *)
50*58b9f456SAndroid Build Coastguard Worker      echo "Unknown option: $1"
51*58b9f456SAndroid Build Coastguard Worker      exit 1
52*58b9f456SAndroid Build Coastguard Worker  esac
53*58b9f456SAndroid Build Coastguard Workerdone
54*58b9f456SAndroid Build Coastguard Worker
55*58b9f456SAndroid Build Coastguard Workerif [ "$GCC_INSTALL_DIR" == "" ]; then
56*58b9f456SAndroid Build Coastguard Worker  echo "No install directory. Please specify the --to argument."
57*58b9f456SAndroid Build Coastguard Worker  exit 1
58*58b9f456SAndroid Build Coastguard Workerfi
59*58b9f456SAndroid Build Coastguard Worker
60*58b9f456SAndroid Build Coastguard Workerif [ "$GCC_SOURCE_DIR" == "" ]; then
61*58b9f456SAndroid Build Coastguard Worker  echo "No source directory. Please specify the --source argument."
62*58b9f456SAndroid Build Coastguard Worker  exit 1
63*58b9f456SAndroid Build Coastguard Workerfi
64*58b9f456SAndroid Build Coastguard Worker
65*58b9f456SAndroid Build Coastguard WorkerGCC_NAME=`basename $GCC_SOURCE_DIR`
66*58b9f456SAndroid Build Coastguard WorkerGCC_BUILD_DIR="/tmp/gcc-build-root/build-$GCC_NAME"
67*58b9f456SAndroid Build Coastguard Worker
68*58b9f456SAndroid Build Coastguard Workermkdir -p "$GCC_INSTALL_DIR"
69*58b9f456SAndroid Build Coastguard Workermkdir -p "$GCC_BUILD_DIR"
70*58b9f456SAndroid Build Coastguard Workerpushd "$GCC_BUILD_DIR"
71*58b9f456SAndroid Build Coastguard Worker
72*58b9f456SAndroid Build Coastguard Worker# Run the build as specified in the build arguments.
73*58b9f456SAndroid Build Coastguard Workerecho "Running configuration"
74*58b9f456SAndroid Build Coastguard Worker$GCC_SOURCE_DIR/configure --prefix=$GCC_INSTALL_DIR \
75*58b9f456SAndroid Build Coastguard Worker  --disable-bootstrap --disable-libgomp --disable-libitm \
76*58b9f456SAndroid Build Coastguard Worker  --disable-libvtv --disable-libcilkrts --disable-libmpx \
77*58b9f456SAndroid Build Coastguard Worker  --disable-liboffloadmic --disable-libcc1 --enable-languages=c,c++
78*58b9f456SAndroid Build Coastguard Worker
79*58b9f456SAndroid Build Coastguard WorkerNPROC=`nproc`
80*58b9f456SAndroid Build Coastguard Workerecho "Running build with $NPROC threads"
81*58b9f456SAndroid Build Coastguard Workermake -j$NPROC
82*58b9f456SAndroid Build Coastguard Worker
83*58b9f456SAndroid Build Coastguard Workerecho "Installing to $GCC_INSTALL_DIR"
84*58b9f456SAndroid Build Coastguard Workermake install -j$NPROC
85*58b9f456SAndroid Build Coastguard Worker
86*58b9f456SAndroid Build Coastguard Workerpopd
87*58b9f456SAndroid Build Coastguard Worker
88*58b9f456SAndroid Build Coastguard Worker# Cleanup.
89*58b9f456SAndroid Build Coastguard Workerrm -rf "$GCC_BUILD_DIR"
90*58b9f456SAndroid Build Coastguard Worker
91*58b9f456SAndroid Build Coastguard Workerecho "Done"