2018-07-06 04:09:48 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2018-05-02 21:40:01 +02:00
|
|
|
#
|
2023-03-21 15:41:11 +01:00
|
|
|
# Copyright © 2017-2023 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
|
|
|
|
|
2023-03-21 16:51:18 +01:00
|
|
|
CLANG_FLAGS := --target=$(TARGET) --sysroot=$(SYSROOT)
|
|
|
|
export CGO_CFLAGS := $(CLANG_FLAGS) $(subst -mthumb,-marm,$(CFLAGS))
|
2020-04-04 01:25:38 +02:00
|
|
|
export CGO_LDFLAGS := $(CLANG_FLAGS) $(LDFLAGS) -Wl,-soname=libwg-go.so
|
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
|
|
|
|
|
2023-03-21 15:22:43 +01:00
|
|
|
GO_VERSION := 1.20.2
|
2020-03-29 10:36:29 +02:00
|
|
|
GO_PLATFORM := $(shell uname -s | tr '[:upper:]' '[:lower:]')-$(NDK_GO_ARCH_MAP_$(shell uname -m))
|
|
|
|
GO_TARBALL := go$(GO_VERSION).$(GO_PLATFORM).tar.gz
|
2023-03-21 15:22:43 +01:00
|
|
|
GO_HASH_darwin-amd64 := c93b8ced9517d07e1cd4c362c6e2d5242cb139e29b417a328fbf19aded08764c
|
|
|
|
GO_HASH_darwin-arm64 := 7343c87f19e79c0063532e82e1c4d6f42175a32d99f7a4d15e658e88bf97f885
|
|
|
|
GO_HASH_linux-amd64 := 4eaea32f59cde4dc635fbc42161031d13e1c780b87097f4b4234cfce671f1768
|
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-04-02 01:48:04 +02:00
|
|
|
flock "$@.lock" -c ' \
|
2020-03-29 09:31:39 +02:00
|
|
|
[ -f "$@" ] && exit 0; \
|
2020-03-29 10:28:41 +02:00
|
|
|
curl -o "$@.tmp" "https://dl.google.com/go/$(GO_TARBALL)" && \
|
2020-03-29 10:36:29 +02:00
|
|
|
echo "$(GO_HASH_$(GO_PLATFORM)) $@.tmp" | sha256sum -c && \
|
2020-03-29 10:28:41 +02:00
|
|
|
mv "$@.tmp" "$@"'
|
|
|
|
|
|
|
|
$(BUILDDIR)/go-$(GO_VERSION)/.prepared: $(GRADLE_USER_HOME)/caches/golang/$(GO_TARBALL)
|
|
|
|
mkdir -p "$(dir $@)"
|
2020-04-02 01:48:04 +02:00
|
|
|
flock "$@.lock" -c ' \
|
2020-03-29 10:28:41 +02:00
|
|
|
[ -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:
|