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
|
|
|
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
|
|
|
|
|
2020-03-29 10:28:41 +02:00
|
|
|
GO_VERSION := 1.14.1
|
|
|
|
GO_TARBALL := go$(GO_VERSION).$(shell uname -s | tr '[:upper:]' '[:lower:]')-$(NDK_GO_ARCH_MAP_$(shell uname -m)).tar.gz
|
2018-04-24 15:19:53 +02:00
|
|
|
|
2019-10-12 11:43:16 +02:00
|
|
|
default: $(DESTDIR)/libwg-go.so
|
2018-04-24 15:19:53 +02:00
|
|
|
|
2020-03-29 10:28:41 +02:00
|
|
|
$(GRADLE_USER_HOME)/caches/golang/$(GO_TARBALL):
|
2019-10-12 11:43:16 +02:00
|
|
|
mkdir -p "$(dir $@)"
|
2020-03-29 09:31:39 +02:00
|
|
|
flock -x "$@.lock" -c ' \
|
|
|
|
[ -f "$@" ] && exit 0; \
|
2020-03-29 10:28:41 +02:00
|
|
|
curl -o "$@.tmp" "https://dl.google.com/go/$(GO_TARBALL)" && \
|
|
|
|
mv "$@.tmp" "$@"'
|
|
|
|
|
|
|
|
$(BUILDDIR)/go-$(GO_VERSION)/.prepared: $(GRADLE_USER_HOME)/caches/golang/$(GO_TARBALL)
|
|
|
|
mkdir -p "$(dir $@)"
|
|
|
|
flock -x "$@.lock" -c ' \
|
|
|
|
[ -f "$@" ] && exit 0; \
|
|
|
|
tar -C "$(dir $@)" --strip-components=1 -xzf "$^" && \
|
2020-03-29 09:31:39 +02:00
|
|
|
patch -p1 -f -N -r- -d "$(dir $@)" < goruntime-boottime-over-monotonic.diff && \
|
|
|
|
touch "$@"'
|
2018-10-09 18:26:21 +02:00
|
|
|
|
2020-03-29 10:28:41 +02:00
|
|
|
$(DESTDIR)/libwg-go.so: export PATH := $(BUILDDIR)/go-$(GO_VERSION)/bin/:$(PATH)
|
|
|
|
$(DESTDIR)/libwg-go.so: $(BUILDDIR)/go-$(GO_VERSION)/.prepared go.mod
|
2019-10-13 10:47:44 +02:00
|
|
|
go build -tags linux -ldflags="-X golang.zx2c4.com/wireguard/ipc.socketDirectory=/data/data/$(ANDROID_PACKAGE_NAME)/cache/wireguard" -v -trimpath -o "$@" -buildmode c-shared
|
2020-03-29 10:28:41 +02:00
|
|
|
|
|
|
|
.DELETE_ON_ERROR:
|