2018-02-07 19:19:20 +01:00
|
|
|
containing = $(foreach v,$2,$(if $(findstring $1,$v),$v))
|
|
|
|
FILES := $(wildcard ../wireguard-go/*/*.go) $(wildcard ../wireguard-go/*.go)
|
2018-04-23 16:42:44 +02:00
|
|
|
FILES := $(filter-out %/main.go $(filter-out %_linux.go,$(call containing,_,$(FILES))),$(FILES))
|
2018-02-07 19:19:20 +01:00
|
|
|
|
2018-04-25 14:36:33 +02:00
|
|
|
NDK_GO_ARCH_MAP_x86 := 386
|
|
|
|
NDK_GO_ARCH_MAP_x86_64 := amd64
|
|
|
|
NDK_GO_ARCH_MAP_arm := arm
|
|
|
|
NDK_GO_ARCH_MAP_arm64 := arm64
|
|
|
|
NDK_GO_ARCH_MAP_mips := mipsx
|
|
|
|
NDK_GO_ARCH_MAP_mips64 := mips64x
|
|
|
|
|
2018-04-24 15:19:53 +02:00
|
|
|
export GOPATH := $(CURDIR)/gopath
|
|
|
|
export GOROOT := $(CURDIR)/goroot
|
|
|
|
export PATH := $(GOROOT)/bin:$(PATH)
|
2018-02-07 19:19:20 +01:00
|
|
|
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)
|
|
|
|
export CC := $(ANDROID_C_COMPILER)
|
2018-04-25 14:36:33 +02:00
|
|
|
export GOARCH := $(NDK_GO_ARCH_MAP_$(ANDROID_ARCH_NAME))
|
2018-02-07 19:19:20 +01:00
|
|
|
export GOOS := android
|
|
|
|
export CGO_ENABLED := 1
|
|
|
|
|
2018-04-25 14:36:33 +02:00
|
|
|
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
|
2018-04-24 15:19:53 +02:00
|
|
|
|
|
|
|
default: $(DESTDIR)/libwg-go.so
|
|
|
|
|
|
|
|
$(GOROOT)/bin/go:
|
|
|
|
rm -rf "$(GOROOT)"
|
|
|
|
mkdir -p "$(GOROOT)"
|
|
|
|
curl "$(GORELEASETARBALL)" | tar -C "$(GOROOT)" --strip-components=1 -xzf - || rm -rf "$(GOROOT)"
|
|
|
|
|
|
|
|
$(DESTDIR)/libwg-go.so: $(FILES) api-android.go jni.c $(GOROOT)/bin/go
|
2018-02-07 19:19:20 +01:00
|
|
|
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
|