From f4b8c51962cddd4eed30d60dd18ce86b0aea83a0 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 25 Feb 2019 18:49:36 +0100 Subject: Makefile: initial series of horrendous makefile hacks Hopefully we'll use go modules properly and this won't be required. --- Makefile | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Makefile (limited to 'Makefile') diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..48885e5a --- /dev/null +++ b/Makefile @@ -0,0 +1,43 @@ +CFLAGS ?= -O3 +CFLAGS += -Wall -std=gnu11 +export CGO_ENABLED := 1 +export CGO_CFLAGS := $(CFLAGS) +export CC := x86_64-w64-mingw32-gcc +export GOOS := windows +export GOARCH := amd64 +export PATH := $(PATH):$(GOPATH)/bin + +all: wireguard.exe + +BUILDDIR := .tmp +rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) +DOWNSTREAM_FILES := $(filter-out %/.tmp wireguard-go/%,$(call rwildcard,,*.go *.c *.h)) go.mod +UPSTREAM_FILES := $(filter-out $(addprefix %/,$(DOWNSTREAM_FILES)) %/.tmp %/main_windows.go,$(call rwildcard,wireguard-go/,*.go)) + +define copy-src-to-build +$(BUILDDIR)/$(3)/$(patsubst $(1)%,%,$(2)): $(2) + @mkdir -vp "$$(dir $$@)" + @cp -vp "$$<" "$$@" + @$$(if $(3),sed -i 's:golang.zx2c4.com/wireguard:golang.zx2c4.com/wireguard/windows/$(3):;s:package main:package $(3):' "$$@",) +$(BUILDDIR)/.prepared: $(BUILDDIR)/$(3)/$(patsubst $(1)%,%,$(2)) +endef + +$(foreach FILE,$(UPSTREAM_FILES),$(eval $(call copy-src-to-build,wireguard-go/,$(FILE),service))) +$(foreach FILE,$(DOWNSTREAM_FILES),$(eval $(call copy-src-to-build,,$(FILE)))) + +$(BUILDDIR)/.prepared: + touch "$@" + +$(BUILDDIR)/resources.syso: ui/icon/icon.ico ui/manifest.xml + rsrc -manifest ui/manifest.xml -ico ui/icon/icon.ico -arch amd64 -o $@ + +wireguard.exe: $(BUILDDIR)/.prepared $(BUILDDIR)/resources.syso + cd "$(BUILDDIR)" && go build -ldflags="-H windowsgui" -o ../$@ -v + +run: wireguard.exe + wine wireguard.exe + +clean: + rm -rf "$(BUILDDIR)" wireguard.exe + +.PHONY: run clean all -- cgit v1.2.3-59-g8ed1b