tMakefile: Generate version only once - sacc - sacc (saccomys): simple gopher client.
Log
Files
Refs
LICENSE
---
commit cf707964fe31a4987713b4ae89eea96e63640c6a
parent 572915c3d29428773577739e54647c4dfd0daa5d
Author: Quentin Rameau 
Date:   Wed, 20 Jul 2022 20:47:34 +0200

Makefile: Generate version only once

Diffstat:
  M Makefile                            |      14 +++++++++++---
  M config.mk                           |       6 ++----
  M sacc.c                              |       1 +

3 files changed, 14 insertions(+), 7 deletions(-)
---
diff --git a/Makefile b/Makefile
t@@ -8,21 +8,28 @@ BIN = sacc
 MAN = $(BIN).1
 OBJ = $(BIN:=.o) ui_$(UI).o io_$(IO).o
 
+GETVER = $$(git rev-parse --is-inside-work-tree >/dev/null 2>&1 \
+        && git describe --tags \
+        || echo $(DEFVERSION))
+
 all: $(BIN)
 
 config.h:
         cp config.def.h config.h
 
+version.h: .git/refs/heads/
+        printf '#define VERSION "%s"\n' "$(GETVER)" > $@
+
 $(BIN): $(OBJ)
         $(CC) $(SACCLDFLAGS) -o $@ $(OBJ) $(IOLIBS) $(LIBS)
 
 $(OBJ): config.mk common.h
-sacc.o: config.h
+sacc.o: config.h version.h
 ui_ti.o: config.h
 io_$(IO).o: io.h
 
 clean:
-        rm -f $(BIN) $(OBJ)
+        rm -f $(BIN) $(OBJ) version.h
 
 install: $(BIN)
         mkdir -p $(DESTDIR)$(PREFIX)/bin/
t@@ -36,12 +43,13 @@ uninstall:
 
 # Stock FLAGS
 SACCCFLAGS = $(OSCFLAGS) \
-             -DVERSION=\"$(GETVER)\" \
              $(IOCFLAGS) \
              $(CFLAGS) \
 
 SACCLDFLAGS = $(OSLDFLAGS) \
               $(LDFLAGS) \
 
+.git/refs/heads/:
+
 .c.o:
         $(CC) $(SACCCFLAGS) -c $<
diff --git a/config.mk b/config.mk
t@@ -6,10 +6,8 @@ MANDIR = $(PREFIX)/share/man/man1
 CFLAGS = -Os
 LDFLAGS = -s
 
-# Version to put in the ident string
-VERSION = "1.06"
-GETVER = $$(git rev-parse --is-inside-work-tree >/dev/null 2>&1 && \
-            git describe --tags || echo $(VERSION))
+# Default version to put in the ident string
+DEFVERSION = "1.06"
 
 # UI type
 # txt (textual)
diff --git a/sacc.c b/sacc.c
t@@ -18,6 +18,7 @@
 #include 
 #include 
 
+#include "version.h"
 #include "common.h"
 #include "io.h"
 #define NEED_CONF