From 9be6bbf0e88fadcb8e7031965391ec16a8f9b477 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Thu, 6 Feb 2014 09:11:00 -0800 Subject: cmd/go, cmd/cgo, make.bash: cross compiling with cgo enabled Introduce two new environment variables, CC_FOR_TARGET and CXX_FOR_TARGET. CC_FOR_TARGET defaults to CC and is used when compiling for GOARCH, while CC remains for compiling for GOHOSTARCH. CXX_FOR_TARGET defaults to CXX and is used when compiling C++ code for GOARCH. CGO_ENABLED defaults to disabled when cross compiling and has to be explicitly enabled. Update issue 4714 LGTM=minux.ma, iant R=golang-codereviews, minux.ma, iant, rsc, dominik.honnef CC=golang-codereviews https://codereview.appspot.com/57100043 Committer: Ian Lance Taylor --- src/make.bash | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/make.bash') diff --git a/src/make.bash b/src/make.bash index 877d1e5eb..bfcb5d58e 100755 --- a/src/make.bash +++ b/src/make.bash @@ -35,10 +35,15 @@ # controls the default behavior of the linker's -linkmode option. The # default value depends on the system. # -# CC: Command line to run to get at host C compiler. +# CC: Command line to run to compile C code for GOHOSTARCH. # Default is "gcc". Also supported: "clang". -# CXX: Command line to run to get at host C++ compiler, only recorded -# for cgo use. Default is "g++". Also supported: "clang++". +# +# CC_FOR_TARGET: Command line to run to compile C code for GOARCH. +# This is used by cgo. Default is CC. +# +# CXX_FOR_TARGET: Command line to run to compile C++ code for GOARCH. +# This is used by cgo. Default is CXX, or, if that is not set, +# "g++" or "clang++". # # GO_DISTFLAGS: extra flags to provide to "dist bootstrap". Use "-s" # to build a statically linked toolchain. @@ -153,13 +158,15 @@ echo if [ "$GOHOSTARCH" != "$GOARCH" -o "$GOHOSTOS" != "$GOOS" ]; then echo "# Building packages and commands for host, $GOHOSTOS/$GOHOSTARCH." - GOOS=$GOHOSTOS GOARCH=$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. + CC=$CC GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH \ "$GOTOOLDIR"/go_bootstrap install -ccflags "$GO_CCFLAGS" -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std echo fi echo "# Building packages and commands for $GOOS/$GOARCH." -"$GOTOOLDIR"/go_bootstrap install $GO_FLAGS -ccflags "$GO_CCFLAGS" -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std +CC=$CC_FOR_TARGET "$GOTOOLDIR"/go_bootstrap install $GO_FLAGS -ccflags "$GO_CCFLAGS" -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std echo rm -f "$GOTOOLDIR"/go_bootstrap -- cgit v1.2.1