2022-11-17 00:17:52 +00:00
|
|
|
# SPDX-License-Identifier: MIT
|
2018-06-09 01:14:34 +00:00
|
|
|
#
|
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.
|
2021-03-08 19:29:12 +00:00
|
|
|
ARCHS ?= x86_64 arm64
|
|
|
|
PLATFORM_NAME ?= macosx
|
|
|
|
SDKROOT ?= $(shell xcrun --sdk $(PLATFORM_NAME) --show-sdk-path)
|
2018-12-16 02:47:05 +00:00
|
|
|
CONFIGURATION_BUILD_DIR ?= $(CURDIR)/out
|
|
|
|
CONFIGURATION_TEMP_DIR ?= $(CURDIR)/.tmp
|
|
|
|
|
2021-09-22 03:06:10 +00:00
|
|
|
export PATH := $(PATH):/usr/local/bin:/opt/homebrew/bin
|
2018-12-16 02:47:05 +00:00
|
|
|
export CC ?= clang
|
|
|
|
LIPO ?= lipo
|
|
|
|
DESTDIR ?= $(CONFIGURATION_BUILD_DIR)
|
|
|
|
BUILDDIR ?= $(CONFIGURATION_TEMP_DIR)/wireguard-go-bridge
|
|
|
|
|
2020-12-09 13:25:22 +00:00
|
|
|
CFLAGS_PREFIX := $(if $(DEPLOYMENT_TARGET_CLANG_FLAG_NAME),-$(DEPLOYMENT_TARGET_CLANG_FLAG_NAME)=$($(DEPLOYMENT_TARGET_CLANG_ENV_NAME)),) -isysroot $(SDKROOT) -arch
|
2018-06-12 23:38:48 +00:00
|
|
|
GOARCH_arm64 := arm64
|
|
|
|
GOARCH_x86_64 := amd64
|
2021-03-08 19:29:12 +00:00
|
|
|
GOOS_macosx := darwin
|
|
|
|
GOOS_iphoneos := ios
|
2018-06-09 01:14:34 +00:00
|
|
|
|
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
|
|
|
|
2019-10-08 14:40:21 +00:00
|
|
|
REAL_GOROOT := $(shell go env GOROOT 2>/dev/null)
|
2018-11-01 22:39:06 +00:00
|
|
|
export GOROOT := $(BUILDDIR)/goroot
|
2019-03-08 04:56:00 +00:00
|
|
|
$(GOROOT)/.prepared:
|
|
|
|
[ -n "$(REAL_GOROOT)" ]
|
2018-11-01 22:39:06 +00:00
|
|
|
mkdir -p "$(GOROOT)"
|
2019-03-08 04:56:00 +00:00
|
|
|
rsync -a --delete --exclude=pkg/obj/go-build "$(REAL_GOROOT)/" "$(GOROOT)/"
|
2019-10-23 11:20:36 +00:00
|
|
|
cat goruntime-*.diff | patch -p1 -f -N -r- -d "$(GOROOT)"
|
2019-03-08 04:56:00 +00:00
|
|
|
touch "$@"
|
2018-11-01 22:39:06 +00:00
|
|
|
|
2018-06-12 23:38:48 +00:00
|
|
|
define libwg-go-a
|
2019-10-08 14:40:21 +00:00
|
|
|
$(BUILDDIR)/libwg-go-$(1).a: export CGO_ENABLED := 1
|
|
|
|
$(BUILDDIR)/libwg-go-$(1).a: export CGO_CFLAGS := $(CFLAGS_PREFIX) $(ARCH)
|
|
|
|
$(BUILDDIR)/libwg-go-$(1).a: export CGO_LDFLAGS := $(CFLAGS_PREFIX) $(ARCH)
|
2021-03-08 19:29:12 +00:00
|
|
|
$(BUILDDIR)/libwg-go-$(1).a: export GOOS := $(GOOS_$(PLATFORM_NAME))
|
2019-10-08 14:40:21 +00:00
|
|
|
$(BUILDDIR)/libwg-go-$(1).a: export GOARCH := $(GOARCH_$(1))
|
|
|
|
$(BUILDDIR)/libwg-go-$(1).a: $(GOROOT)/.prepared go.mod
|
2021-03-08 19:29:12 +00:00
|
|
|
go build -ldflags=-w -trimpath -v -o "$(BUILDDIR)/libwg-go-$(1).a" -buildmode c-archive
|
2019-10-08 14:40:21 +00:00
|
|
|
rm -f "$(BUILDDIR)/libwg-go-$(1).h"
|
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
|
|
|
|
2021-03-08 19:29:12 +00:00
|
|
|
$(DESTDIR)/wireguard-go-version.h: go.mod $(GOROOT)/.prepared
|
|
|
|
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' "$<" > "$@"
|
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
|
|
|
|
2018-11-04 02:55:14 +00:00
|
|
|
install: build
|
|
|
|
|
2019-03-08 04:56:00 +00:00
|
|
|
.PHONY: clean build version-header install
|