aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosty <gabriel@bwaaa.monster>2026-09-20 12:08:39 -0400
committerfrosty <gabriel@bwaaa.monster>2026-09-20 12:08:39 -0400
commit31d32c9349a2fcdafb00a43b1dea35885133b49b (patch)
tree6dc9aa7e6921f954e1ddcda807cc425b4c9e97e9
parent4e5b81c1688080ea770184f54c66ebe82482b692 (diff)
fix: fix version handling in Makefile
-rw-r--r--Makefile37
1 files changed, 23 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index 910cd50..4bfc1d8 100644
--- a/Makefile
+++ b/Makefile
@@ -4,17 +4,11 @@ PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
DESTDIR ?=
-GIT_HASH := $(shell git rev-parse --short HEAD)
-GIT_DATE := $(shell git log -1 --format='%ad' --date='format:%y.%m.%d')
-GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
-GIT_REMOTE := $(shell git remote get-url origin)
-GIT_TAG := $(shell git describe --tags --exact-match HEAD 2>/dev/null)
-
-VERSION := $(if $(GIT_TAG),$(GIT_TAG),$(GIT_DATE)+$(GIT_HASH)_$(GIT_BRANCH))
-
TARGET := bin/yapssg
SOURCES := src/Main.c $(wildcard src/*/*.c)
OBJECTS := $(patsubst src/%.c,obj/%.o,$(SOURCES))
+VERSION_O := obj/Version/Version.o
+VERSION_H := obj/Version/version.h
CPPFLAGS += -Isrc $(shell $(PKG_CONFIG) --cflags libxml-2.0 luajit)
CFLAGS ?= -O2 -Wall -Wextra -Werror -std=c99
@@ -27,15 +21,30 @@ all: $(TARGET)
$(TARGET): $(OBJECTS) | bin
$(CC) $(LDFLAGS) $(OBJECTS) $(LDLIBS) -o $@
+$(VERSION_O): CPPFLAGS += -Iobj
+
+$(VERSION_O): $(VERSION_H)
+
+$(VERSION_H): FORCE
+ @mkdir -p $(@D)
+ @if v="$$(git describe --tags --exact-match HEAD 2>/dev/null)" && [ -n "$$v" ]; then \
+ :; \
+ elif h="$$(git rev-parse --short HEAD 2>/dev/null)" && [ -n "$$h" ]; then \
+ d="$$(git log -1 --format='%ad' --date='format:%y.%m.%d' 2>/dev/null)"; \
+ b="$$(git rev-parse --abbrev-ref HEAD 2>/dev/null)"; \
+ v="$${d}+$${h}_$${b}"; \
+ else \
+ if [ -f $@ ]; then exit 0; fi; \
+ v="$$(date +%y.%m.%d)+unknown"; \
+ fi; \
+ printf '#define YAPSSG_VERSION "%s"\n' "$$v" > $@.tmp; \
+ cmp -s $@ $@.tmp || mv -f $@.tmp $@; \
+ rm -f $@.tmp
+
obj/%.o: src/%.c
mkdir -p $(@D)
$(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -c $< -o $@
-obj/Version/Version.o: CPPFLAGS += -DYAPSSG_VERSION=\"$(VERSION)\"
-obj/Version/Version.o: FORCE
-
-FORCE:
-
bin:
mkdir -p $@
@@ -45,4 +54,4 @@ clean:
install: $(TARGET)
install -Dm755 $(TARGET) $(DESTDIR)$(BINDIR)/yapssg
--include $(OBJECTS:.o=.d)
+-include $(OBJECTS:.o=.d) \ No newline at end of file