# SPDX-License-Identifier: Apache-2.0 # # Copyright © 2017-2021 WireGuard LLC. All Rights Reserved. BUILDDIR ?= $(CURDIR)/build DESTDIR ?= $(CURDIR)/out 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 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) -Wl,-soname=libwg-go.so export CC := $(ANDROID_C_COMPILER) export GOARCH := $(NDK_GO_ARCH_MAP_$(ANDROID_ARCH_NAME)) export GOOS := android export CGO_ENABLED := 1 export GOPATH ?= $(HOME)/go GO_VERSION := 1.19.5 GO_PLATFORM := $(shell uname -s | tr '[:upper:]' '[:lower:]')-$(NDK_GO_ARCH_MAP_$(shell uname -m)) GO_TARBALL := go$(GO_VERSION).$(GO_PLATFORM).tar.gz GO_HASH_darwin-amd64 := 03e8323f63043d13c309a4ebbfc0b0e6c65b835ad4384b445f1a0c39d2c335d7 GO_HASH_darwin-arm64 := 4fbbf81242a1c6cdd7e505684c12422570b9c628108d021d4354fed07d79d443 GO_HASH_linux-amd64 := 36519702ae2fd573c9869461990ae550c8c0d955cd28d2827a6b159fda81ff95 PROTOC_VERSION := 3.20.1 PROTOC_GEN_GO := $(GOPATH)/bin/protoc-gen-go PROTOC := $(GRADLE_USER_HOME)/caches/protoc-$(PROTOC_VERSION)/protoc PROTODIR = $(CURDIR)/../../src/main/proto PROTO_INCLUDEDIR = $(CURDIR)/../../build/extracted-include-protos/debug PBDIR = $(GOPATH)/pkg/mod default: $(DESTDIR)/libwg-go.so $(GRADLE_USER_HOME)/caches/golang/$(GO_TARBALL): mkdir -p "$(dir $@)" flock "$@.lock" -c ' \ [ -f "$@" ] && exit 0; \ curl -o "$@.tmp" "https://dl.google.com/go/$(GO_TARBALL)" && \ echo "$(GO_HASH_$(GO_PLATFORM)) $@.tmp" | sha256sum -c && \ mv "$@.tmp" "$@"' $(BUILDDIR)/go-$(GO_VERSION)/.prepared: $(GRADLE_USER_HOME)/caches/golang/$(GO_TARBALL) mkdir -p "$(dir $@)" flock "$@.lock" -c ' \ [ -f "$@" ] && exit 0; \ tar -C "$(dir $@)" --strip-components=1 -xzf "$^" && \ patch -p1 -f -N -r- -d "$(dir $@)" < goruntime-boottime-over-monotonic.diff && \ touch "$@"' $(PROTOC_GEN_GO): export GOARCH := $(PROTOC_GEN_GO): export GOOS := $(PROTOC_GEN_GO): export PATH := $(BUILDDIR)/go-$(GO_VERSION)/bin/:$(PATH) $(PROTOC_GEN_GO): $(BUILDDIR)/go-$(GO_VERSION)/.prepared Makefile go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28 go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2 gen/%.pb.go: export PATH := $(GOPATH)/bin:$(PATH) gen/%.pb.go: $(PROTODIR)/%.proto $(BUILDDIR)/go-$(GO_VERSION)/.prepared $(PROTOC_GEN_GO) test -d gen || mkdir gen $(PROTOC) -I $(PROTODIR) -I $(PROTO_INCLUDEDIR) --go_out=paths=source_relative:./gen $< gen/%_grpc.pb.go: export PATH := $(GOPATH)/bin:$(PATH) gen/%_grpc.pb.go: $(PROTODIR)/%.proto $(BUILDDIR)/go-$(GO_VERSION)/.prepared $(PROTOC_GEN_GO) test -d gen || mkdir gen $(PROTOC) -I $(PROTODIR) -I $(PROTO_INCLUDEDIR) --go-grpc_out=./gen --go-grpc_opt=paths=source_relative $< $(DESTDIR)/libwg-go.so: export PATH := $(BUILDDIR)/go-$(GO_VERSION)/bin/:$(PATH) $(DESTDIR)/libwg-go.so: $(BUILDDIR)/go-$(GO_VERSION)/.prepared go.mod api-android.go http-proxy.go service.go gen/libwg.pb.go gen/libwg_grpc.pb.go jni.c 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 .DELETE_ON_ERROR: