From 6ce739f01ff7f0c51081eb2e4598b33fafe3486b Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 30 Apr 2018 18:19:37 +0200 Subject: 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 --- app/tools/libwg-go/Makefile | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'app') 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 -- cgit v1.2.3