2018-06-09 01:14:34 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
#
|
2019-01-02 00:56:33 +00:00
|
|
|
# Copyright (C) 2018-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
2018-06-09 01:14:34 +00:00
|
|
|
|
2018-12-16 02:47:05 +00:00
|
|
|
# These are generally passed to us by xcode, but we set working defaults for standalone compilation too.
|
|
|
|
ARCHS ?= arm64 armv7
|
|
|
|
SDK_NAME ?= iphoneos
|
2018-12-20 19:47:42 +00:00
|
|
|
SDKROOT ?= $(shell xcrun --sdk $(SDK_NAME) --show-sdk-path)
|
2018-12-16 02:47:05 +00:00
|
|
|
CONFIGURATION_BUILD_DIR ?= $(CURDIR)/out
|
|
|
|
CONFIGURATION_TEMP_DIR ?= $(CURDIR)/.tmp
|
|
|
|
|
|
|
|
export CC ?= clang
|
|
|
|
LIPO ?= lipo
|
|
|
|
DESTDIR ?= $(CONFIGURATION_BUILD_DIR)
|
|
|
|
BUILDDIR ?= $(CONFIGURATION_TEMP_DIR)/wireguard-go-bridge
|
|
|
|
|
2018-10-09 17:41:12 +00:00
|
|
|
UPSTREAM_FILES := $(filter-out %/main.go %/queueconstants.go,$(wildcard ../wireguard-go/*/*.go) $(wildcard ../wireguard-go/*.go)) ../wireguard-go/go.mod ../wireguard-go/go.sum
|
2018-10-02 16:12:30 +00:00
|
|
|
DOWNSTREAM_FILES := $(wildcard src/*.go) $(wildcard src/*/*.go)
|
2019-02-08 15:42:25 +00:00
|
|
|
CFLAGS_PREFIX := $(if $(DEPLOYMENT_TARGET_CLANG_FLAG_NAME),-$(DEPLOYMENT_TARGET_CLANG_FLAG_NAME)=$($(DEPLOYMENT_TARGET_CLANG_ENV_NAME)),) -Wno-unused-command-line-argument -isysroot $(SDKROOT) -arch
|
2018-06-12 23:38:48 +00:00
|
|
|
GOARCH_arm64 := arm64
|
|
|
|
GOARCH_armv7 := arm
|
|
|
|
GOARCH_x86_64 := amd64
|
2018-06-09 01:14:34 +00:00
|
|
|
export GOOS := darwin
|
|
|
|
export CGO_ENABLED := 1
|
|
|
|
|
2018-10-02 16:12:30 +00:00
|
|
|
build: $(DESTDIR)/libwg-go.a
|
2018-10-31 03:02:36 +00:00
|
|
|
version-header: $(DESTDIR)/wireguard-go-version.h
|
2018-06-09 01:14:34 +00:00
|
|
|
|
2018-11-01 22:39:06 +00:00
|
|
|
GOBUILDARCH := $(GOARCH_$(shell uname -m))
|
|
|
|
GOBUILDOS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
|
2019-02-27 05:24:56 +00:00
|
|
|
GOBUILDVERSION := 1.12
|
2019-02-08 15:23:40 +00:00
|
|
|
GOBUILDTARBALL := go$(GOBUILDVERSION).$(GOBUILDOS)-$(GOBUILDARCH).tar.gz
|
|
|
|
GOBUILDTARBALLURL := https://dl.google.com/go/$(GOBUILDTARBALL)
|
2018-11-01 22:39:06 +00:00
|
|
|
GOBUILDVERSION_NEEDED := go version go$(GOBUILDVERSION) $(GOBUILDOS)/$(GOBUILDARCH)
|
|
|
|
export GOROOT := $(BUILDDIR)/goroot
|
|
|
|
export GOPATH := $(BUILDDIR)/gopath
|
|
|
|
export PATH := $(GOROOT)/bin:$(PATH)
|
|
|
|
GOBUILDVERSION_CURRENT := $(shell $(GOROOT)/bin/go version 2>/dev/null)
|
|
|
|
ifneq ($(GOBUILDVERSION_NEEDED),$(GOBUILDVERSION_CURRENT))
|
|
|
|
$(shell rm -f $(GOROOT)/bin/go)
|
|
|
|
endif
|
2019-02-08 15:23:40 +00:00
|
|
|
.cache/$(GOBUILDTARBALL):
|
|
|
|
mkdir -p $(dir $@)
|
|
|
|
curl -o $@ $(GOBUILDTARBALLURL) || { rm -f $@; exit 1; }
|
|
|
|
|
|
|
|
$(GOROOT)/bin/go: .cache/$(GOBUILDTARBALL)
|
2018-11-01 22:39:06 +00:00
|
|
|
rm -rf "$(GOROOT)"
|
|
|
|
mkdir -p "$(GOROOT)"
|
2019-02-08 15:23:40 +00:00
|
|
|
tar -C "$(GOROOT)" --strip-components=1 -xzf - < .cache/$(GOBUILDTARBALL) || { rm -rf "$(GOROOT)"; exit 1; }
|
2018-11-01 22:39:06 +00:00
|
|
|
patch -p1 -f -N -r- -d "$(GOROOT)" < goruntime-boottime-over-monotonic.diff || { rm -rf "$(GOROOT)"; exit 1; }
|
2019-03-03 05:12:09 +00:00
|
|
|
touch $@
|
2018-11-01 22:39:06 +00:00
|
|
|
|
|
|
|
$(shell test "$$(cat "$(BUILDDIR)/.gobuildversion" 2>/dev/null)" = "$(GOBUILDVERSION_CURRENT)" || rm -f "$(DESTDIR)/libwg-go.a")
|
|
|
|
|
2018-06-12 23:38:48 +00:00
|
|
|
define libwg-go-a
|
2019-03-03 05:12:09 +00:00
|
|
|
$(BUILDDIR)/libwg-go-$(1).a: $(GOROOT)/bin/go
|
2018-12-16 02:47:05 +00:00
|
|
|
CGO_CFLAGS="$(CFLAGS_PREFIX) $(ARCH)" \
|
|
|
|
CGO_LDFLAGS="$(CFLAGS_PREFIX) $(ARCH)" \
|
2018-10-09 17:41:12 +00:00
|
|
|
GOARCH="$(GOARCH_$(1))" \
|
2018-11-05 03:30:32 +00:00
|
|
|
go build -tags ios -ldflags=-w -v -o "$(BUILDDIR)/libwg-go-$(1).a" -buildmode c-archive && go version > "$(BUILDDIR)/.gobuildversion"; \
|
2019-03-03 05:12:09 +00:00
|
|
|
chmod -fR +w "$(GOPATH)/pkg/mod"; \
|
2018-10-31 01:49:59 +00:00
|
|
|
ret=$$$$?; \
|
|
|
|
rm -f "$(BUILDDIR)/libwg-go-$(1).h"; \
|
|
|
|
exit $$$$ret
|
2018-06-12 23:38:48 +00:00
|
|
|
endef
|
2018-10-02 16:12:30 +00:00
|
|
|
$(foreach ARCH,$(ARCHS),$(eval $(call libwg-go-a,$(ARCH))))
|
2018-06-12 23:38:48 +00:00
|
|
|
|
2019-03-03 05:12:09 +00:00
|
|
|
$(DESTDIR)/wireguard-go-version.h: go.mod $(GOROOT)/bin/go
|
|
|
|
go get -d -tags ios; chmod -fR +w "$(GOPATH)/pkg/mod"
|
|
|
|
wggo="$(GOPATH)/pkg/mod/$$(sed -n 's/.*\(golang\.zx2c4\.com\/wireguard\) \(.*\)$$/\1@\2/p' go.mod)"; \
|
|
|
|
sed -n 's/.*WireGuardGoVersion = "\(.*\)"/#define WIREGUARD_GO_VERSION "\1"/p' "$$wggo/device/version.go" > "$@"
|
2018-10-31 03:02:36 +00:00
|
|
|
|
2018-10-09 17:41:12 +00:00
|
|
|
$(DESTDIR)/libwg-go.a: $(foreach ARCH,$(ARCHS),$(BUILDDIR)/libwg-go-$(ARCH).a)
|
|
|
|
@mkdir -vp "$(DESTDIR)"
|
2018-12-16 02:47:05 +00:00
|
|
|
$(LIPO) -create -output "$@" $^
|
2018-10-31 03:02:36 +00:00
|
|
|
|
2018-06-09 01:14:34 +00:00
|
|
|
clean:
|
2018-12-16 02:47:05 +00:00
|
|
|
rm -rf "$(BUILDDIR)" "$(DESTDIR)/libwg-go.a" "$(DESTDIR)/wireguard-go-version.h"
|
2018-06-09 01:14:34 +00:00
|
|
|
|
2019-02-08 15:23:40 +00:00
|
|
|
distclean: clean
|
|
|
|
rm -rf .cache
|
|
|
|
|
2018-11-04 02:55:14 +00:00
|
|
|
install: build
|
|
|
|
|
2019-02-08 15:23:40 +00:00
|
|
|
.PHONY: distclean clean build version-header install
|