1#!/bin/bash
2
3set -e
4
5ORIG_SRCDIR=$(dirname "${BASH_SOURCE[0]}")
6if [[ "$ORIG_SRCDIR" != "." ]]; then
7  if [[ ! -z "$BUILDDIR" ]]; then
8    echo "error: To use BUILDDIR, run from the source directory"
9    exit 1
10  fi
11  export BUILDDIR=$("${ORIG_SRCDIR}/build/soong/scripts/reverse_path.py" "$ORIG_SRCDIR")
12  cd $ORIG_SRCDIR
13fi
14if [[ -z "$BUILDDIR" ]]; then
15  echo "error: Run ${BASH_SOURCE[0]} from the build output directory"
16  exit 1
17fi
18export SRCDIR="."
19export BOOTSTRAP="${SRCDIR}/bootstrap.bash"
20
21export TOPNAME="Android.bp"
22export BOOTSTRAP_MANIFEST="${SRCDIR}/build/soong/build.ninja.in"
23export RUN_TESTS="-t"
24
25case $(uname) in
26    Linux)
27	export GOOS="linux"
28	export PREBUILTOS="linux-x86"
29	;;
30    Darwin)
31	export GOOS="darwin"
32	export PREBUILTOS="darwin-x86"
33	;;
34    *) echo "unknown OS:" $(uname) && exit 1;;
35esac
36export GOROOT="${SRCDIR}/prebuilts/go/$PREBUILTOS/"
37export GOARCH="amd64"
38export GOCHAR="6"
39
40if [[ $# -eq 0 ]]; then
41    mkdir -p $BUILDDIR
42
43    if [[ $(find $BUILDDIR -maxdepth 1 -name Android.bp) ]]; then
44      echo "FAILED: The build directory must not be a source directory"
45      exit 1
46    fi
47
48    export SRCDIR_FROM_BUILDDIR=$(build/soong/scripts/reverse_path.py "$BUILDDIR")
49
50    sed -e "s|@@BuildDir@@|${BUILDDIR}|" \
51        -e "s|@@SrcDirFromBuildDir@@|${SRCDIR_FROM_BUILDDIR}|" \
52        -e "s|@@PrebuiltOS@@|${PREBUILTOS}|" \
53        "$SRCDIR/build/soong/soong.bootstrap.in" > $BUILDDIR/.soong.bootstrap
54    ln -sf "${SRCDIR_FROM_BUILDDIR}/build/soong/soong.bash" $BUILDDIR/soong
55fi
56
57"$SRCDIR/build/blueprint/bootstrap.bash" "$@"
58