Recently Written · git

sacc

Mirror of git://bitreich.org/sacc, the sacc gopher client from bitreich.org.

git clone https://github.com/equwal/sacc

Log | Files | Refs


commit cf707964fe31a4987713b4ae89eea96e63640c6a
Quentin Rameau <quinq@fifth.space>
2022-07-20 20:47:34 +0200

Makefile: Generate version only once

 Makefile  | 14 +++++++++++---
 config.mk |  6 ++----
 sacc.c    |  1 +
 3 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/Makefile b/Makefile
index 3440811..4c00649 100644
--- a/Makefile
+++ b/Makefile
@@ -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/
@@ -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
index fb79dd3..61ab5d2 100644
--- a/config.mk
+++ b/config.mk
@@ -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
index 096b4ce..85d40ab 100644
--- a/sacc.c
+++ b/sacc.c
@@ -18,6 +18,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
+#include "version.h"
 #include "common.h"
 #include "io.h"
 #define NEED_CONF