From 31e88f06af7ab787d8fe0c1ca625193e1799e167 Mon Sep 17 00:00:00 2001
From: Matt Madison <matt@madison.systems>
Date: Wed, 13 Sep 2017 08:12:04 -0700
Subject: [PATCH 3/7] make.bash: better separate host and target builds

Fore OE cross-builds, the simple checks in make.bash are
insufficient for distinguishing host and target build
environments, so add some options for telling the
script which parts are being built.

Upstream-Status: Pending

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Matt Madison <matt@madison.systems>
---
 src/make.bash | 51 ++++++++++++++++++++++++++++-----------------------
 1 file changed, 28 insertions(+), 23 deletions(-)

diff --git a/src/make.bash b/src/make.bash
index dcf3256..9553623 100755
--- a/src/make.bash
+++ b/src/make.bash
@@ -156,13 +156,22 @@ if [ "$1" = "--no-clean" ]; then
 	buildall=""
 	shift
 fi
-./cmd/dist/dist bootstrap $buildall $GO_DISTFLAGS -v # builds go_bootstrap
+do_host_build="yes"
+do_target_build="yes"
+if [ "$1" = "--target-only" ]; then
+	do_host_build="no"
+	shift
+elif [ "$1" = "--host-only" ]; then
+	do_target_build="no"
+	shift
+fi
 
-# Delay move of dist tool to now, because bootstrap may clear tool directory.
-mv cmd/dist/dist "$GOTOOLDIR"/dist
-echo
+if [ "$do_host_build" = "yes" ]; then
+	./cmd/dist/dist bootstrap $buildall $GO_DISTFLAGS -v # builds go_bootstrap
+	# Delay move of dist tool to now, because bootstrap may clear tool directory.
+	mv cmd/dist/dist "$GOTOOLDIR"/dist
+	echo
 
-if [ "$GOHOSTARCH" != "$GOARCH" -o "$GOHOSTOS" != "$GOOS" ]; then
 	echo "##### Building packages and commands for host, $GOHOSTOS/$GOHOSTARCH."
 	# CC_FOR_TARGET is recorded as the default compiler for the go tool. When building for the host, however,
 	# use the host compiler, CC, from `cmd/dist/dist env` instead.
@@ -171,24 +180,20 @@ if [ "$GOHOSTARCH" != "$GOARCH" -o "$GOHOSTOS" != "$GOOS" ]; then
 	echo
 fi
 
-echo "##### Building packages and commands for $GOOS/$GOARCH."
-
-old_bin_files=$(cd $GOROOT/bin && echo *)
-
-CC="$CC_FOR_TARGET" "$GOTOOLDIR"/go_bootstrap install $GO_FLAGS -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std cmd
-
-# Check that there are no new files in $GOROOT/bin other than go and gofmt
-# and $GOOS_$GOARCH (a directory used when cross-compiling).
-(cd $GOROOT/bin && for f in *; do
-	if ! expr " $old_bin_files go gofmt ${GOOS}_${GOARCH} " : ".* $f " >/dev/null 2>/dev/null; then
-		echo 1>&2 "ERROR: unexpected new file in $GOROOT/bin: $f"
-		exit 1
-	fi
-done)
-
-echo
-
-rm -f "$GOTOOLDIR"/go_bootstrap
+if [ "$do_target_build" = "yes" ]; then
+    GO_INSTALL="${GO_TARGET_INSTALL:-std cmd}"
+    echo "##### Building packages and commands for $GOOS/$GOARCH."
+    if [ "$GOHOSTOS" = "$GOOS" -a "$GOHOSTARCH" = "$GOARCH" -a "$do_host_build" = "yes" ]; then
+	rm -rf ./host-tools
+	mkdir ./host-tools
+	mv "$GOTOOLDIR"/* ./host-tools
+	GOTOOLDIR="$PWD/host-tools"
+    fi
+    GOTOOLDIR="$GOTOOLDIR" CC="$CC_FOR_TARGET" "$GOTOOLDIR"/go_bootstrap install $GO_FLAGS -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v ${GO_INSTALL}
+    echo
+
+    rm -f "$GOTOOLDIR"/go_bootstrap
+fi
 
 if [ "$1" != "--no-banner" ]; then
 	"$GOTOOLDIR"/dist banner
-- 
2.7.4

