Commit 3f032d56 authored by Andrew Gerrand's avatar Andrew Gerrand

build: add GOHOSTOS and GOHOSTARCH environment variables.

Auto-detect both if not set, and if GOARCH is not set use GOHOSTARCH.

GOHOSTARCH is used to set the -m32 or -m64 flags for gcc.

This is so that 64-bit can build binaries that run on 32-bit systems.

R=rsc, iant, brainman
CC=golang-dev
https://golang.org/cl/2342045
parent 5781a00e
...@@ -21,8 +21,12 @@ endif ...@@ -21,8 +21,12 @@ endif
# Set up GOROOT_FINAL, GOARCH, GOOS if needed. # Set up GOROOT_FINAL, GOARCH, GOOS if needed.
GOROOT_FINAL?=$(GOROOT) GOROOT_FINAL?=$(GOROOT)
ifeq ($(GOHOSTOS),)
GOHOSTOS:=$(shell uname | tr A-Z a-z | sed 's/mingw/windows/; s/.*windows.*/windows/')
endif
ifeq ($(GOOS),) ifeq ($(GOOS),)
GOOS:=${shell uname | tr A-Z a-z | sed 's/mingw/windows/; s/windows.*/windows/'} GOOS:=$(GOHOSTOS)
endif endif
ifeq ($(GOOS),darwin) ifeq ($(GOOS),darwin)
...@@ -35,17 +39,21 @@ else ...@@ -35,17 +39,21 @@ else
$(error Invalid $$GOOS '$(GOOS)'; must be darwin, freebsd, linux, nacl, tiny, or windows) $(error Invalid $$GOOS '$(GOOS)'; must be darwin, freebsd, linux, nacl, tiny, or windows)
endif endif
ifeq ($(GOARCH),) ifeq ($(GOHOSTARCH),)
ifeq ($(GOOS),darwin) ifeq ($(GOHOSTOS),darwin)
# Even on 64-bit platform, darwin uname -m prints i386. # Even on 64-bit platform, darwin uname -m prints i386.
# Check for amd64 with sysctl instead. # Check for amd64 with sysctl instead.
GOARCH:=${shell if sysctl machdep.cpu.extfeatures | grep EM64T >/dev/null; then echo amd64; else uname -m | sed 's/i386/386/'; fi} GOHOSTARCH:=${shell if sysctl machdep.cpu.extfeatures | grep EM64T >/dev/null; then echo amd64; else uname -m | sed 's/i386/386/'; fi}
else else
# Ask uname -m for the processor. # Ask uname -m for the processor.
GOARCH:=${shell uname -m | sed 's/^..86$$/386/; s/^.86$$/386/; s/x86_64/amd64/; s/arm.*/arm/'} GOHOSTARCH:=${shell uname -m | sed 's/^..86$$/386/; s/^.86$$/386/; s/x86_64/amd64/; s/arm.*/arm/'}
endif endif
endif endif
ifeq ($(GOARCH),)
GOARCH:=$(GOHOSTARCH)
endif
ifeq ($(GOARCH),386) ifeq ($(GOARCH),386)
O:=8 O:=8
else ifeq ($(GOARCH),amd64) else ifeq ($(GOARCH),amd64)
...@@ -63,7 +71,7 @@ $(error Invalid $$GOARCH '$(GOARCH)'; must be 386, amd64, or arm) ...@@ -63,7 +71,7 @@ $(error Invalid $$GOARCH '$(GOARCH)'; must be 386, amd64, or arm)
endif endif
# Save for recursive make to avoid recomputing. # Save for recursive make to avoid recomputing.
export GOARCH GOOS export GOARCH GOOS GOHOSTARCH GOHOSTOS
# ugly hack to deal with whitespaces in $GOROOT # ugly hack to deal with whitespaces in $GOROOT
nullstring := nullstring :=
...@@ -101,6 +109,8 @@ export LANG LC_ALL LC_CTYPE GREP_OPTIONS GREP_COLORS ...@@ -101,6 +109,8 @@ export LANG LC_ALL LC_CTYPE GREP_OPTIONS GREP_COLORS
go-env: go-env:
@echo export GOARCH=$(GOARCH) @echo export GOARCH=$(GOARCH)
@echo export GOOS=$(GOOS) @echo export GOOS=$(GOOS)
@echo export GOHOSTARCH=$(GOHOSTARCH)
@echo export GOHOSTOS=$(GOHOSTOS)
@echo export O=$O @echo export O=$O
@echo export AS="$(AS)" @echo export AS="$(AS)"
@echo export CC="$(CC)" @echo export CC="$(CC)"
......
...@@ -22,14 +22,15 @@ if test "$gcc" = "@C""C@"; then ...@@ -22,14 +22,15 @@ if test "$gcc" = "@C""C@"; then
gcc=gcc gcc=gcc
fi fi
# If this is a 64-bit machine, compile 64-bit versions of # Build 64-bit binaries on 64-bit systems, unless GOHOSTARCH=386.
# the host tools, to match the native ptrace. case "$(uname -m -p)-$GOHOSTARCH" in
case "`uname -m -p`" in *x86_64*-386 | *amd64*-386)
gcc="$gcc -m32"
;;
*x86_64* | *amd64*) *x86_64* | *amd64*)
gcc="$gcc -m64" gcc="$gcc -m64"
esac esac
# Run gcc, save error status, redisplay output without noise, exit with gcc status. # Run gcc, save error status, redisplay output without noise, exit with gcc status.
tmp=/tmp/qcc.$$.$USER.out tmp=/tmp/qcc.$$.$USER.out
$gcc -Wall -Wno-sign-compare -Wno-missing-braces \ $gcc -Wall -Wno-sign-compare -Wno-missing-braces \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment