summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-04-30 18:19:37 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-04-30 18:19:37 +0200
commit6ce739f01ff7f0c51081eb2e4598b33fafe3486b (patch)
tree95cb51848ec1af6be75ba0974359657e0670fb09
parent05b4e395a988c23f78fe7e90fa1b550fcde2112b (diff)
libwg-go: use system Go when possible
We're still maybe curlzipping and using a binary distribution of Go, but at least this is only the case on machines that don't have go. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--app/tools/libwg-go/Makefile24
1 files changed, 17 insertions, 7 deletions
diff --git a/app/tools/libwg-go/Makefile b/app/tools/libwg-go/Makefile
index 43af1439..d931c056 100644
--- a/app/tools/libwg-go/Makefile
+++ b/app/tools/libwg-go/Makefile
@@ -10,8 +10,6 @@ NDK_GO_ARCH_MAP_mips := mipsx
NDK_GO_ARCH_MAP_mips64 := mips64x
export GOPATH := $(CURDIR)/gopath
-export GOROOT := $(CURDIR)/goroot
-export PATH := $(GOROOT)/bin:$(PATH)
CLANG_FLAGS := --target=$(ANDROID_LLVM_TRIPLE) --gcc-toolchain=$(ANDROID_TOOLCHAIN_ROOT) --sysroot=$(ANDROID_SYSROOT)
export CGO_CFLAGS := $(CLANG_FLAGS) $(CFLAGS)
export CGO_LDFLAGS := $(CLANG_FLAGS) $(LDFLAGS)
@@ -20,20 +18,32 @@ export GOARCH := $(NDK_GO_ARCH_MAP_$(ANDROID_ARCH_NAME))
export GOOS := android
export CGO_ENABLED := 1
-GORELEASEVERSION := 1.10.1
-GORELEASETARBALL := https://dl.google.com/go/go$(GORELEASEVERSION).$(shell uname -s | tr '[:upper:]' '[:lower:]')-$(NDK_GO_ARCH_MAP_$(shell uname -m)).tar.gz
-
default: $(DESTDIR)/libwg-go.so
+GOBUILDARCH := $(NDK_GO_ARCH_MAP_$(shell uname -m))
+GOBUILDOS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
+GOBUILDVERSION := 1.10.1
+GOBUILDTARBALL := https://dl.google.com/go/go$(GOBUILDVERSION).$(GOBUILDOS)-$(GOBUILDARCH).tar.gz
+
+ifeq (go version go$(GOBUILDVERSION) $(GOBUILDOS)/$(GOBUILDARCH),$(shell go version 2>/dev/null))
+ensure_go_exists:
+ @echo "Using system go"
+else
+export GOROOT := $(CURDIR)/goroot
+export PATH := $(GOROOT)/bin:$(PATH)
$(GOROOT)/bin/go:
rm -rf "$(GOROOT)"
mkdir -p "$(GOROOT)"
- curl "$(GORELEASETARBALL)" | tar -C "$(GOROOT)" --strip-components=1 -xzf - || rm -rf "$(GOROOT)"
+ curl "$(GOBUILDTARBALL)" | tar -C "$(GOROOT)" --strip-components=1 -xzf - || rm -rf "$(GOROOT)"
+ensure_go_exists: $(GOROOT)/bin/go
+endif
-$(DESTDIR)/libwg-go.so: $(FILES) api-android.go jni.c $(GOROOT)/bin/go
+$(DESTDIR)/libwg-go.so: $(FILES) api-android.go jni.c ensure_go_exists
find . -name '*.go' -type l -delete
find . -type d -empty -delete
mkdir -p $(subst ../wireguard-go/,./,$(dir $(FILES)))
$(foreach FILE,$(FILES),ln -sfrt $(subst ../wireguard-go/,./,$(dir $(FILE))) $(FILE);)
go get -v -d
go build -v -o $(DESTDIR)/libwg-go.so -buildmode c-shared
+
+.PHONY: ensure_go_exists