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-04-04 14:20:02 +02:00
|
|
|
comma := ,
|
2023-03-21 16:51:18 +01:00
|
|
|
CLANG_FLAGS := --target=$(TARGET) --sysroot=$(SYSROOT)
|
|
|
|
export CGO_CFLAGS := $(CLANG_FLAGS) $(subst -mthumb,-marm,$(CFLAGS))
|
2023-04-04 14:20:02 +02:00
|
|
|
export CGO_LDFLAGS := $(CLANG_FLAGS) $(patsubst -Wl$(comma)--build-id=%,-Wl$(comma)--build-id=none,$(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-10-18 14:04:00 +02:00
|
|
|
GO_VERSION := 1.21.3
|
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-10-18 14:04:00 +02:00
|
|
|
GO_HASH_darwin-amd64 := 27014fc69e301d7588a169ca239b3cc609f0aa1abf38528bf0d20d3b259211eb
|
|
|
|
GO_HASH_darwin-arm64 := 65302a7a9f7a4834932b3a7a14cb8be51beddda757b567a2f9e0cbd0d7b5a6ab
|
|
|
|
GO_HASH_linux-amd64 := 1241381b2843fae5a9707eec1f8fb2ef94d827990582c7c7c32f5bdfbfd420c8
|
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
|
2024-01-07 18:07:11 +01:00
|
|
|
#go mod tidy
|
|
|
|
go build -tags linux -ldflags="-X gitea.hbanafa.com/hesham/wireguard-go/wireguard/ipc.socketDirectory=/data/data/$(ANDROID_PACKAGE_NAME)/cache/wireguard -buildid=" -v -trimpath -buildvcs=false -o "$@" -buildmode c-shared
|
2020-03-29 10:28:41 +02:00
|
|
|
|
|
|
|
.DELETE_ON_ERROR:
|