2018-07-06 04:09:48 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2018-05-02 21:40:01 +02:00
|
|
|
#
|
2019-01-02 01:57:15 +01:00
|
|
|
# Copyright © 2017-2019 WireGuard LLC. All Rights Reserved.
|
2018-05-02 21:40:01 +02:00
|
|
|
|
2018-10-09 18:26:21 +02:00
|
|
|
UPSTREAM_FILES := $(filter-out %/main.go %/queueconstants.go,$(wildcard ../wireguard-go/*/*.go) $(wildcard ../wireguard-go/*.go)) ../wireguard-go/go.mod ../wireguard-go/go.sum
|
2018-11-03 20:15:05 +01:00
|
|
|
DOWNSTREAM_FILES := $(wildcard src/*.go) $(wildcard src/*.c) $(wildcard src/*/*.go)
|
2018-10-09 18:26:21 +02:00
|
|
|
|
|
|
|
BUILDDIR ?= $(CURDIR)/build
|
|
|
|
DESTDIR ?= $(CURDIR)/out
|
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-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-24 15:19:53 +02:00
|
|
|
default: $(DESTDIR)/libwg-go.so
|
|
|
|
|
2018-04-30 18:19:37 +02:00
|
|
|
GOBUILDARCH := $(NDK_GO_ARCH_MAP_$(shell uname -m))
|
|
|
|
GOBUILDOS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
|
2019-02-27 05:13:37 +01:00
|
|
|
GOBUILDVERSION := 1.12
|
2018-04-30 18:19:37 +02:00
|
|
|
GOBUILDTARBALL := https://dl.google.com/go/go$(GOBUILDVERSION).$(GOBUILDOS)-$(GOBUILDARCH).tar.gz
|
2018-05-02 03:55:18 +02:00
|
|
|
GOBUILDVERSION_NEEDED := go version go$(GOBUILDVERSION) $(GOBUILDOS)/$(GOBUILDARCH)
|
2018-10-09 18:26:21 +02:00
|
|
|
export GOROOT := $(BUILDDIR)/goroot
|
2018-10-11 00:23:17 +02:00
|
|
|
export GOPATH := $(BUILDDIR)/gopath
|
2018-04-30 18:19:37 +02:00
|
|
|
export PATH := $(GOROOT)/bin:$(PATH)
|
2018-05-02 03:55:18 +02:00
|
|
|
GOBUILDVERSION_CURRENT := $(shell $(GOROOT)/bin/go version 2>/dev/null)
|
|
|
|
ifneq ($(GOBUILDVERSION_NEEDED),$(GOBUILDVERSION_CURRENT))
|
|
|
|
$(shell rm -f $(GOROOT)/bin/go)
|
|
|
|
endif
|
2018-04-24 15:19:53 +02:00
|
|
|
$(GOROOT)/bin/go:
|
|
|
|
rm -rf "$(GOROOT)"
|
|
|
|
mkdir -p "$(GOROOT)"
|
2018-05-02 03:55:18 +02:00
|
|
|
curl "$(GOBUILDTARBALL)" | tar -C "$(GOROOT)" --strip-components=1 -xzf - || { rm -rf "$(GOROOT)"; exit 1; }
|
2019-02-27 05:13:37 +01:00
|
|
|
patch -p1 -f -N -r- -d "$(GOROOT)" < goruntime-boottime-over-monotonic.diff || { rm -rf "$(GOROOT)"; exit 1; }
|
2018-04-24 15:19:53 +02:00
|
|
|
|
2018-05-02 03:55:18 +02:00
|
|
|
$(shell test "$$(cat .gobuildversion 2>/dev/null)" = "$(GOBUILDVERSION_CURRENT)" || rm -f "$(DESTDIR)/libwg-go.so")
|
|
|
|
|
2018-10-09 18:26:21 +02:00
|
|
|
define copy-src-to-build
|
|
|
|
$(subst $(1),$(BUILDDIR)/,$(2)): $(2)
|
|
|
|
@mkdir -vp "$$(dir $$@)"
|
|
|
|
@cp -vp "$$<" "$$@"
|
|
|
|
$(BUILDDIR)/.prepared: $(subst $(1),$(BUILDDIR)/,$(2))
|
|
|
|
endef
|
|
|
|
|
|
|
|
$(foreach FILE,$(UPSTREAM_FILES),$(eval $(call copy-src-to-build,../wireguard-go/,$(FILE))))
|
|
|
|
$(foreach FILE,$(DOWNSTREAM_FILES),$(eval $(call copy-src-to-build,src/,$(FILE))))
|
|
|
|
|
2018-10-11 00:23:17 +02:00
|
|
|
$(BUILDDIR)/.prepared: $(GOROOT)/bin/go
|
|
|
|
cd "$(BUILDDIR)" && go get || { chmod -fR +w "$(GOPATH)/pkg/mod"; rm -rf "$(GOPATH)/pkg/mod"; exit 1; }
|
|
|
|
chmod -fR +w "$(GOPATH)/pkg/mod"
|
2018-10-09 18:26:21 +02:00
|
|
|
touch "$@"
|
|
|
|
|
|
|
|
$(DESTDIR)/libwg-go.so: $(BUILDDIR)/.prepared
|
2018-10-11 00:23:17 +02:00
|
|
|
cd "$(BUILDDIR)" && go build -ldflags="-X main.socketDirectory=/data/data/$(ANDROID_PACKAGE_NAME)/cache/wireguard" -v -o "$@" -buildmode c-shared
|
2018-05-02 03:55:18 +02:00
|
|
|
go version > .gobuildversion
|