wireguard-apple/wireguard-go-bridge/Makefile

60 lines
2.8 KiB
Makefile
Raw Normal View History

2018-06-09 01:14:34 +00:00
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (C) 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
2018-10-02 16:12:30 +00:00
UPSTREAM_FILES := $(filter-out %/main.go %/queueconstants.go,$(wildcard ../wireguard-go/*/*.go) $(wildcard ../wireguard-go/*.go))
DOWNSTREAM_FILES := $(wildcard src/*.go) $(wildcard src/*/*.go)
2018-06-09 01:14:34 +00:00
2018-10-02 16:12:30 +00:00
ARCHS ?= arm64 armv7 x86_64
2018-06-12 23:38:48 +00:00
GOARCH_arm64 := arm64
GOARCH_armv7 := arm
GOARCH_x86_64 := amd64
2018-10-02 16:12:30 +00:00
DEPLOYMENT_CFLAGS := $(DEPLOYMENT_TARGET_CLANG_FLAG_PREFIX)$($(DEPLOYMENT_TARGET_CLANG_ENV_NAME))
CGO_FLAGS_x86_64 := -arch x86_64 -isysroot $(shell xcrun --sdk iphonesimulator --show-sdk-path) $(DEPLOYMENT_CFLAGS)
CGO_FLAGS_arm64 := -arch arm64 -isysroot $(shell xcrun --sdk iphoneos --show-sdk-path) $(DEPLOYMENT_CFLAGS)
CGO_FLAGS_armv7 := -arch armv7 -isysroot $(shell xcrun --sdk iphoneos --show-sdk-path) $(DEPLOYMENT_CFLAGS)
2018-06-12 23:38:48 +00:00
CC_x86_64 := $(shell xcrun --sdk iphonesimulator --find clang)
CC_arm64 := $(shell xcrun --sdk iphoneos --find clang)
CC_armv7 := $(shell xcrun --sdk iphoneos --find clang)
2018-10-02 16:12:30 +00:00
CONFIGURATION_BUILD_DIR ?= $(CURDIR)/out
CONFIGURATION_TEMP_DIR ?= $(CURDIR)/.tmp
DESTDIR ?= $(CONFIGURATION_BUILD_DIR)
GOBUILDDIR ?= $(CONFIGURATION_TEMP_DIR)/wireguard-go-bridge
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-06-09 01:14:34 +00:00
2018-10-02 16:12:30 +00:00
$(GOBUILDDIR)/src/.prepared: $(UPSTREAM_FILES) $(DOWNSTREAM_FILES)
rm -rf $(GOBUILDDIR)/src
mkdir -p $(subst ../wireguard-go/,$(GOBUILDDIR)/src/git.zx2c4.com/wireguard-go/,$(dir $(UPSTREAM_FILES)))
mkdir -p $(subst src/,$(GOBUILDDIR)/src/git.zx2c4.com/wireguard-go/,$(dir $(DOWNSTREAM_FILES)))
$(foreach FILE,$(UPSTREAM_FILES),ln -sf $(abspath $(FILE)) $(subst ../wireguard-go/,$(GOBUILDDIR)/src/git.zx2c4.com/wireguard-go/,$(dir $(FILE)))$(notdir $(FILE));)
$(foreach FILE,$(DOWNSTREAM_FILES),ln -sf $(abspath $(FILE)) $(subst src/,$(GOBUILDDIR)/src/git.zx2c4.com/wireguard-go/,$(dir $(FILE)))$(notdir $(FILE));)
GOPATH=$(GOBUILDDIR) go get -v -d git.zx2c4.com/wireguard-go
2018-06-12 23:38:48 +00:00
touch $@
define libwg-go-a
2018-10-02 16:12:30 +00:00
$(GOBUILDDIR)/libwg-go-$(1).a: $(UPSTREAM_FILES) $(DOWNSTREAM_FILES) $(GOBUILDDIR)/src/.prepared
2018-06-12 23:38:48 +00:00
CC="$(CC_$(1))" \
CGO_CFLAGS="$(CGO_FLAGS_$(1))" \
CGO_LDFLAGS="$(CGO_FLAGS_$(1))" \
GOARCH=$(GOARCH_$(1)) \
2018-10-02 16:12:30 +00:00
GOPATH=$(GOBUILDDIR) \
go build -tags ios -v -o $(GOBUILDDIR)/libwg-go-$(1).a -buildmode c-archive git.zx2c4.com/wireguard-go
@rm -f $(GOBUILDDIR)/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
2018-10-02 16:12:30 +00:00
$(DESTDIR)/libwg-go.a: $(foreach ARCH,$(ARCHS),$(GOBUILDDIR)/libwg-go-$(ARCH).a)
mkdir -p $(DESTDIR)
2018-06-12 23:38:48 +00:00
xcrun --sdk iphoneos lipo -create -output $@ $^
2018-06-09 01:14:34 +00:00
2018-10-02 16:12:30 +00:00
$(DESTDIR)/example: example.c $(DESTDIR)/libwg-go.a
xcrun --sdk iphoneos clang -framework CoreFoundation -isysroot $(shell xcrun --sdk iphoneos --show-sdk-path) -arch arm64 -arch armv7 -L$(DESTDIR) -lwg-go -o $@ $<
2018-06-09 01:14:34 +00:00
clean:
2018-10-02 16:12:30 +00:00
rm -rf $(GOBUILDDIR) $(DESTDIR)/libwg-go.a $(DESTDIR)/example
2018-06-09 01:14:34 +00:00
2018-10-02 16:12:30 +00:00
.PHONY: clean build