From 3bfe9c41ab9e93646a51e64d53661153d5429817 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 27 Dec 2019 18:17:00 +0100 Subject: [PATCH] Makefile: rework automatic version.h mangling Signed-off-by: Jason A. Donenfeld Reported-by: Joe Doss --- src/Makefile | 14 +++++--------- src/version.h | 2 ++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Makefile b/src/Makefile index e5b2230..049d555 100644 --- a/src/Makefile +++ b/src/Makefile @@ -46,6 +46,10 @@ CFLAGS += -DRUNSTATEDIR="\"$(RUNSTATEDIR)\"" ifeq ($(DEBUG),yes) CFLAGS += -g endif +GIT_VERSION := $(shell GIT_CEILING_DIRECTORIES="$(PWD)/../.." git describe --dirty 2>/dev/null) +ifneq ($(GIT_VERSION),) +CFLAGS += -D'WIREGUARD_TOOLS_VERSION="$(GIT_VERSION:v%=%)"' +endif ifeq ($(PLATFORM),linux) LIBMNL_CFLAGS := $(shell $(PKG_CONFIG) --cflags libmnl 2>/dev/null) LIBMNL_LDLIBS := $(shell $(PKG_CONFIG) --libs libmnl 2>/dev/null || echo -lmnl) @@ -96,17 +100,9 @@ install: wg @[ "$(WITH_WGQUICK)" = "yes" -a "$(WITH_SYSTEMDUNITS)" = "yes" ] || exit 0; \ install -v -d "$(DESTDIR)$(SYSTEMDUNITDIR)" && install -v -m 0644 systemd/wg-quick@.service "$(DESTDIR)$(SYSTEMDUNITDIR)/wg-quick@.service" -wg.o: version.h -version.h: - @export GIT_CEILING_DIRECTORIES="$(PWD)/../.." && \ - ver="#define WIREGUARD_TOOLS_VERSION \"$$(git describe --dirty 2>/dev/null)\"" && \ - [ "$$(cat version.h 2>/dev/null)" != "$$ver" ] && \ - echo "$$ver" > version.h && \ - git update-index --assume-unchanged version.h || true - check: clean scan-build --html-title=wireguard-tools -maxloop 100 --view --keep-going $(MAKE) wg -.PHONY: clean install version.h check +.PHONY: clean install check -include *.d diff --git a/src/version.h b/src/version.h index c382f86..92406d5 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1,3 @@ +#ifndef WIREGUARD_TOOLS_VERSION #define WIREGUARD_TOOLS_VERSION "1.0.20191226" +#endif