From 4801439aae6b191d1f1b7ca36d4caa8d90227036 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. Signed-off-by: Jason A. Donenfeld --- Makefile | 43 +++++++++++++++++++++++++++++++++++++++++++ go.mod | 10 ++++++++++ 2 files changed, 53 insertions(+) create mode 100644 Makefile create mode 100644 go.mod 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 diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..7d6cf675 --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module golang.zx2c4.com/wireguard/windows + +require ( + github.com/Microsoft/go-winio v0.4.11 + golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 + golang.org/x/net v0.0.0-20190213061140-3a22650c66bd + golang.org/x/sys v0.0.0-20190220154126-629670e5acc5 + golang.zx2c4.com/winipcfg latest + golang.zx2c4.com/wireguard latest +) -- cgit v1.2.3-59-g8ed1b