From fe5d8a2d58aa885fc43bb5f5bdfade5cc52cbc30 Mon Sep 17 00:00:00 2001
From: John Swinbank <swinbank@astron.nl>
Date: Sun, 15 Nov 2020 13:38:53 +0100
Subject: [PATCH] Pull metadata from git

---
 example/.gitignore  |  1 +
 example/Makefile    | 17 ++++++++++++++++-
 example/example.tex |  5 +++--
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/example/.gitignore b/example/.gitignore
index ae0b579..b464a42 100644
--- a/example/.gitignore
+++ b/example/.gitignore
@@ -2,3 +2,4 @@ example.aux
 example.log
 example.out
 example.pdf
+meta.tex
diff --git a/example/Makefile b/example/Makefile
index f5a5b2e..34a3a72 100644
--- a/example/Makefile
+++ b/example/Makefile
@@ -1,5 +1,20 @@
 export TEXMFHOME ?= ../texmf
 
-example.pdf: example.tex
+GITVERSION := $(shell git log -1 --date=short --pretty=%h)
+GITDATE := $(shell git log -1 --date=short --pretty=%ad)
+GITSTATUS := $(shell git status --porcelain)
+ifneq "$(GITSTATUS)" ""
+	GITDIRTY = -dirty
+endif
+
+example.pdf: example.tex meta.tex
 	xelatex example
 	xelatex example
+
+.FORCE:
+
+meta.tex: Makefile .FORCE
+	rm -f $@
+	echo '% GENERATED FILE -- edit this in the Makefile' >>$@
+	/bin/echo '\\newcommand{\\vcsRevision}{$(GITVERSION)$(GITDIRTY)}' >>$@
+	/bin/echo '\\newcommand{\\vcsDate}{$(GITDATE)}' >>$@
diff --git a/example/example.tex b/example/example.tex
index d4d4a11..0655315 100644
--- a/example/example.tex
+++ b/example/example.tex
@@ -1,9 +1,10 @@
 \documentclass{astron}
+\input{meta}
 
 \setDocTitle{Example Document}
 \setDocNumber{1}
-\setDocRevision{1}
-\setDocDate{\today}
+\setDocRevision{\vcsRevision}
+\setDocDate{\vcsDate}
 \setDocClass{Limited}
 \setDocProgram{SDC}
 
-- 
GitLab