]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - Makefile
Added 'version' command to print when the bcachefs tool was built
[bcachefs-tools-debian] / Makefile
index 267d48510084bee064a29571f538d4171041a62a..57ed873e884118d4a0d67616c5a5b809ce20bc59 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -13,9 +13,12 @@ CFLAGS+=-std=gnu89 -O2 -g -MMD -Wall                         \
        -DNO_BCACHEFS_CHARDEV                                   \
        -DNO_BCACHEFS_FS                                        \
        -DNO_BCACHEFS_SYSFS                                     \
+       -DVERSION_STRING='"$(VERSION)"'                         \
        $(EXTRA_CFLAGS)
 LDFLAGS+=$(CFLAGS)
 
+VERSION?=$(shell git describe --long --dirty 2>/dev/null || echo 0.1-nogit)
+
 CC_VERSION=$(shell $(CC) -v 2>&1|grep -E '(gcc|clang) version')
 
 ifneq (,$(findstring gcc,$(CC_VERSION)))
@@ -56,6 +59,16 @@ DEPS=$(SRCS:.c=.d)
 OBJS=$(SRCS:.c=.o)
 bcachefs: $(OBJS)
 
+# If the version string differs from the last build, update the last version
+ifneq ($(VERSION),$(shell cat .version 2>/dev/null))
+.PHONY: .version
+endif
+.version:
+       echo '$(VERSION)' > $@
+
+# Rebuild the 'version' command any time the version string changes
+cmd_version.o : .version
+
 .PHONY: install
 install: bcachefs
        mkdir -p $(DESTDIR)$(ROOT_SBINDIR)