blob: 21707173f019580525e022f6ec74ffc62d5d2118 [file] [log] [blame]
#!/usr/bin/env bash
# Copyright 2018 The Fuchsia Authors
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT
function HELP {
echo "help:"
echo "-a <arch> : build just one architecture (default: both)"
echo "-A : build asan variant"
echo "-C : build clang variant"
echo "-l : build thinlto variant"
echo "-L : build lto variant"
echo "-X : build xray variant"
echo "-P : build profile variant"
echo "-o <dir> : build in <dir> (default build-VARIANT)"
echo "-j N : passed on to Ninja"
echo "-q : build quietly (pass -q to gn)"
echo "-v : build verbosely (pass -v to ninja)"
echo "-r : build release build"
echo "-d : build unoptimized, with full debug symbols"
echo "-t : build with tests disabled (for targets with small boot partitions)"
echo "-h for help"
echo "all arguments after -- become GN build arguments"
exit 1
}
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
GN_SWITCHES=(--export-compile-commands)
GN_ARGS=()
NINJA_ARGS=()
VARIANT=gcc
BUILDDIR=
BUILDDIR_SUFFIX=
while getopts a:ACdhj:lLo:PqrtvX FLAG; do
case $FLAG in
a) NINJA_ARGS+=("$OPTARG") ;;
A) VARIANT=asan ;;
C) VARIANT=clang ;;
d) VARIANT=noopt ;;
j) NINJA_ARGS+=(-j "$OPTARG") ;;
l) VARIANT=thinlto ;;
L) VARIANT=lto ;;
o) BUILDDIR="$OPTARG" ;;
P) VARIANT=profile ;;
q) GN_SWITCHES+=(-q) ;;
r) BUILDDIR_SUFFIX=-release GN_ARGS+=(assert_level=0) ;;
t) GN_ARGS+=(tests_in_image=false) ;;
v) NINJA_ARGS+=(-v) ;;
X) VARIANT=xray ;;
h) HELP ;;
\?)
echo unrecognized option
HELP
esac
done
shift $((OPTIND-1))
set -e
if [[ -z "$BUILDDIR" ]]; then
BUILDDIR="build-$VARIANT$BUILDDIR_SUFFIX"
fi
# Generate args.gn, but only touch it if the contents have changed to avoid
# unnecessarily regenerating on no-op builds.
mkdir -p $BUILDDIR
echo "variants = [ \"$VARIANT\" ] $GN_ARGS $*" | "$DIR/gn" format --stdin > "$BUILDDIR/args.gn.tmp"
if cmp -s "$BUILDDIR/args.gn" "$BUILDDIR/args.gn.tmp"; then
rm -f "$BUILDDIR/args.gn.tmp"
else
mv -f "$BUILDDIR/args.gn.tmp" "$BUILDDIR/args.gn"
"$DIR/gn" gen "${GN_SWITCHES[@]}" "$BUILDDIR"
fi
exec "$DIR/ninja" -C "$BUILDDIR" "${NINJA_ARGS[@]}"