@@ -8,6 +8,7 @@ PLATFORM_NAME ?= macosx
88SDKROOT ?= $(shell xcrun --sdk $(PLATFORM_NAME ) --show-sdk-path)
99CONFIGURATION_BUILD_DIR ?= $(CURDIR ) /out
1010CONFIGURATION_TEMP_DIR ?= $(CURDIR ) /.tmp
11+ CACHE_ROOT ?= $(CURDIR ) /.cache
1112
1213export PATH := $(PATH ) :/usr/local/bin:/opt/homebrew/bin
1314export CC ?= clang
@@ -21,29 +22,36 @@ GOARCH_x86_64 := amd64
2122GOOS_macosx := darwin
2223GOOS_iphoneos := ios
2324
24- GO_VERSION := 1.20.2
25+ GO_VERSION := 1.20.3
2526GO_PLATFORM := $(shell uname -s | tr '[:upper:]' '[:lower:]') -$(GOARCH_$(shell uname -m) )
2627GO_TARBALL := go$(GO_VERSION ) .$(GO_PLATFORM ) .tar.gz
27- GO_HASH_darwin-amd64 := c93b8ced9517d07e1cd4c362c6e2d5242cb139e29b417a328fbf19aded08764c
28- GO_HASH_darwin-arm64 := 7343c87f19e79c0063532e82e1c4d6f42175a32d99f7a4d15e658e88bf97f885
28+ GO_HASH_darwin-amd64 := c1e1161d6d859deb576e6cfabeb40e3d042ceb1c6f444f617c3c9d76269c3565
29+ GO_HASH_darwin-arm64 := 86b0ed0f2b2df50fa8036eea875d1cf2d76cefdacf247c44639a1464b7e36b95
30+ GO_ROOT := $(BUILDDIR ) /go-$(GO_VERSION )
31+
32+
33+ UNAME := $(shell uname -m)
34+ ifeq ($(UNAME ) , $(GOARCH_arm64 ) )
35+ GOOS_iphonesimulator := ios
36+ endif
2937
3038build : $(DESTDIR ) /libwg-go.a
3139version-header : $(DESTDIR ) /wireguard-go-version.h
3240
33- $(BUILDDIR ) /$(GO_TARBALL ) :
34- mkdir -p " $( @D ) "
41+ $(CACHE_ROOT ) /$(GO_TARBALL ) :
42+ mkdir -p " $( dir $@ ) "
3543 flock " $@ .lock" -c ' \
3644 [ -f " $@ " ] && exit 0; \
37- curl -o " $@ .tmp" " https://dl.google.com/go /$( GO_TARBALL) " && \
38- echo " $( GO_HASH_$( GO_PLATFORM) ) $@ .tmp" | sha256sum -c && \
45+ wget -O " $@ .tmp" " https://go.dev/dl /$( GO_TARBALL) " && \
46+ echo " $( GO_HASH_$( GO_PLATFORM) ) $@ .tmp" | sha256sum -c && \
3947 mv " $@ .tmp" " $@ " '
4048
41- $( BUILDDIR ) /go- $( GO_VERSION ) / .prepared : $(BUILDDIR ) /$(GO_TARBALL )
42- mkdir -p " $( @D ) "
49+ $( GO_ROOT ) / .prepared : $(CACHE_ROOT ) /$(GO_TARBALL )
50+ mkdir -p " $( dir $@ ) "
4351 flock " $@ .lock" -c ' \
4452 [ -f " $@ " ] && exit 0; \
45- tar -C " $( @D ) " --strip-components=1 -xzf " $^" && \
46- patch -p1 -f -N -r- -d " $( @D ) " < goruntime-boottime-over-monotonic.diff && \
53+ tar -C " $( dir $@ ) " --strip-components=1 -xzf " $^" && \
54+ patch -p1 -f -N -r- -d " $( dir $@ ) " < goruntime-boottime-over-monotonic.diff && \
4755 touch " $@ " '
4856
4957define libwg-go-a
@@ -52,16 +60,16 @@ $(BUILDDIR)/libwg-go-$(1).a: export CGO_CFLAGS := $(CFLAGS_PREFIX) $(ARCH)
5260$(BUILDDIR ) /libwg-go-$(1 ) .a: export CGO_LDFLAGS := $(CFLAGS_PREFIX ) $(ARCH )
5361$(BUILDDIR ) /libwg-go-$(1 ) .a: export GOOS := $(GOOS_$(PLATFORM_NAME ) )
5462$(BUILDDIR ) /libwg-go-$(1 ) .a: export GOARCH := $(GOARCH_$(1 ) )
55- $(BUILDDIR ) /libwg-go-$(1 ) .a: $(BUILDDIR ) /go- $( GO_VERSION ) /.prepared go.mod
63+ $(BUILDDIR ) /libwg-go-$(1 ) .a: $(GO_ROOT ) /.prepared go.mod
5664 go build -ldflags=-w -trimpath -v -o "$(BUILDDIR ) /libwg-go-$(1 ) .a" -buildmode c-archive
5765 $(RM ) "$(BUILDDIR ) /libwg-go-$(1 ) .h"
5866endef
5967$(foreach ARCH,$(ARCHS),$(eval $(call libwg-go-a,$(ARCH))))
6068
61- $(DESTDIR ) /wireguard-go-version.h : $( BUILDDIR ) /go- $( GO_VERSION ) /.prepared go.mod
69+ $(DESTDIR ) /wireguard-go-version.h : go.mod $( GO_ROOT ) /.prepared
6270 sed -E -n ' s/.*golang\.zx2c4\.com\/wireguard +v[0-9.]+-[0-9]+-([0-9a-f]{8})[0-9a-f]{4}.*/#define WIREGUARD_GO_VERSION "\1"/p' " $<" > " $@ "
6371
64- $(DESTDIR ) /llibwg -go.a : export PATH := $(BUILDDIR ) /go- $( GO_VERSION ) /bin/:$(PATH )
72+ $(DESTDIR ) /libwg -go.so : export PATH := $(GO_ROOT ) /bin/:$(PATH )
6573$(DESTDIR ) /libwg-go.a : $(foreach ARCH,$(ARCHS ) ,$(BUILDDIR ) /libwg-go-$(ARCH ) .a)
6674 @mkdir -vp " $( DESTDIR) "
6775 $(LIPO ) -create -output " $@ " $^
0 commit comments