summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Roethlisberger <[email protected]>2018-03-10 19:52:21 +0100
committerDaniel Roethlisberger <[email protected]>2018-03-10 19:52:21 +0100
commitfa9c2a1dfca5b54f8705ae01ee2aa174ea0f4d93 (patch)
tree5e38853a5bd6f46b3f9a0c6b89fe9da64a931196
parentba7a3200445fdfd026d300752747ffd95a4b7e78 (diff)
Refactor version handling into Mk/buildinfo.mk
-rw-r--r--GNUmakefile33
-rwxr-xr-xMk/bin/copyright.py (renamed from extra/dev/copyright.py)0
-rw-r--r--Mk/buildinfo.mk47
-rw-r--r--build.c (renamed from version.c)10
-rw-r--r--build.h (renamed from version.h)10
-rw-r--r--main.c10
-rw-r--r--main.t.c2
7 files changed, 72 insertions, 40 deletions
diff --git a/GNUmakefile b/GNUmakefile
index 17aa1df..f2ed0f4 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -208,26 +208,9 @@ TSRCS:= $(wildcard *.t.c)
TOBJS:= $(TSRCS:.t.c=.t.o)
TOBJS+= $(filter-out main.o,$(OBJS))
-VFILE:= $(wildcard VERSION)
-GITDIR:= $(wildcard .git)
-ifdef VFILE
-VERSION:= $(shell $(CAT) VERSION)
-BUILD_INFO+= V:FILE
-else
-ifndef GITDIR
-VERSION:= $(shell $(BASENAME) $(PWD)|\
- $(GREP) $(TARGET)-|\
- $(SED) 's/.*$(TARGET)-\(.*\)/\1/g')
-NEWSSHA:= $(shell $(OPENSSL) dgst -sha1 -r NEWS.md |\
- $(CUT) -c -7)
-BUILD_INFO+= V:DIR N:$(NEWSSHA)
-else
-VERSION:= $(shell $(GIT) describe --tags --dirty --always)
-BUILD_INFO+= V:GIT
-endif
-CFLAGS+= $(DEBUG_CFLAGS)
-endif
-BUILD_DATE:= $(shell date +%Y-%m-%d)
+PKGNAME:= $(TARGET)
+include Mk/buildinfo.mk
+VERSION:= $(BUILD_VERSION)
# Autodetect dependencies known to pkg-config
PKGS:=
@@ -340,8 +323,10 @@ endif
CPPDEFS+= -D_GNU_SOURCE \
-D"BNAME=\"$(TARGET)\"" -D"PNAME=\"$(PNAME)\"" \
- -D"VERSION=\"$(VERSION)\"" -D"BUILD_DATE=\"$(BUILD_DATE)\"" \
- -D"FEATURES=\"$(FEATURES)\"" -D"BUILD_INFO=\"$(BUILD_INFO)\""
+ -D"BUILD_VERSION=\"$(BUILD_VERSION)\"" \
+ -D"BUILD_DATE=\"$(BUILD_DATE)\"" \
+ -D"BUILD_INFO=\"$(BUILD_INFO)\"" \
+ -D"BUILD_FEATURES=\"$(FEATURES)\""
CPPCHECKFLAGS+= $(CPPDEFS)
FEATURES:= $(sort $(FEATURES))
@@ -406,7 +391,7 @@ all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
-version.o: version.c version.h GNUmakefile $(VFILE) FORCE
+build.o: build.c FORCE
%.t.o: %.t.c $(HDRS) GNUmakefile
ifdef CHECK_MISSING
@@ -462,7 +447,7 @@ mantest: $(TARGET).1
$(RM) man1
copyright: *.c *.h *.1
- extra/dev/copyright.py $^
+ Mk/bin/copyright.py $^
$(TARGET)-$(VERSION).1.txt: $(TARGET).1
$(RM) -f man1
diff --git a/extra/dev/copyright.py b/Mk/bin/copyright.py
index ab51290..ab51290 100755
--- a/extra/dev/copyright.py
+++ b/Mk/bin/copyright.py
diff --git a/Mk/buildinfo.mk b/Mk/buildinfo.mk
new file mode 100644
index 0000000..962baef
--- /dev/null
+++ b/Mk/buildinfo.mk
@@ -0,0 +1,47 @@
+# in: PKGNAME
+# in: BUILD_INFO (optional)
+
+ifndef PKGNAME
+$(error PKGNAME not defined)
+endif
+
+BASENAME?= basename
+CUT?= cut
+GIT?= git
+GREP?= grep
+OPENSSL?= openssl
+SED?= sed
+
+GITDIR:= $(wildcard .git)
+VERSION_FILE:= $(wildcard VERSION)
+NEWS_FILE:= $(firstword $(wildcard NEWS*))
+
+ifdef GITDIR
+BUILD_VERSION:= $(shell $(GIT) describe --tags --dirty --always)
+BUILD_INFO+= V:GIT
+GITDIR:=
+else
+ifdef VERSION_FILE
+BUILD_VERSION:= $(shell $(CAT) VERSION)
+BUILD_INFO+= V:FILE
+else
+BUILD_VERSION:= $(shell $(BASENAME) $(PWD)|\
+ $(GREP) $(PKGNAME)-|\
+ $(SED) 's/.*$(PKGNAME)-\(.*\)/\1/g')
+BUILD_INFO+= V:DIR
+endif
+ifdef NEWS_FILE
+NEWSSHA:= $(shell $(OPENSSL) dgst -sha1 -r $(NEWS_FILE) |\
+ $(CUT) -c -7)
+BUILD_INFO+= N:$(NEWSSHA)
+NEWSSHA:=
+endif
+endif # GITDIR
+
+BUILD_DATE:= $(shell date +%Y-%m-%d)
+
+# out: NEWS_FILE
+# out: VERSION_FILE
+# out: BUILD_DATE
+# out: BUILD_VERSION
+# out: BUILD_INFO
diff --git a/version.c b/build.c
index e9e0eee..9d4d2fd 100644
--- a/version.c
+++ b/build.c
@@ -26,15 +26,15 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include "version.h"
+#include "build.h"
/*
* Volatile build-time information which can change between make runs.
*/
-const char *version = VERSION;
-const char *build_date = BUILD_DATE;
-const char *build_info = BUILD_INFO;
-const char *features = FEATURES;
+const char *build_version = BUILD_VERSION;
+const char *build_date = BUILD_DATE;
+const char *build_info = BUILD_INFO;
+const char *build_features = BUILD_FEATURES;
/* vim: set noet ft=c: */
diff --git a/version.h b/build.h
index d2779c3..25c17d2 100644
--- a/version.h
+++ b/build.h
@@ -26,14 +26,14 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef VERSION_H
-#define VERSION_H
+#ifndef BUILD_H
+#define BUILD_H
-extern const char *version;
+extern const char *build_version;
extern const char *build_date;
extern const char *build_info;
-extern const char *features;
+extern const char *build_features;
-#endif /* !VERSION_H */
+#endif /* !BUILD_H */
/* vim: set noet ft=c: */
diff --git a/main.c b/main.c
index 294c537..b4c359c 100644
--- a/main.c
+++ b/main.c
@@ -40,7 +40,7 @@
#include "cachemgr.h"
#include "sys.h"
#include "log.h"
-#include "version.h"
+#include "build.h"
#include "defaults.h"
#include <stdlib.h>
@@ -70,8 +70,8 @@ extern int daemon(int, int);
static void
main_version(void)
{
- fprintf(stderr, "%s %s (built %s)\n", PNAME, version, build_date);
- if (strlen(version) < 5) {
+ fprintf(stderr, "%s %s (built %s)\n", PNAME, build_version, build_date);
+ if (strlen(build_version) < 5) {
/*
* Note to package maintainers: If you break the version
* string in your build, it will be impossible to provide
@@ -100,8 +100,8 @@ main_version(void)
if (build_info[0]) {
fprintf(stderr, "Build info: %s\n", build_info);
}
- if (features[0]) {
- fprintf(stderr, "Features: %s\n", features);
+ if (build_features[0]) {
+ fprintf(stderr, "Features: %s\n", build_features);
}
nat_version();
fprintf(stderr, "Local process info support: ");
diff --git a/main.t.c b/main.t.c
index 7aab9f5..48d6700 100644
--- a/main.t.c
+++ b/main.t.c
@@ -28,7 +28,7 @@
#include "attrib.h"
#include "opts.h"
-#include "version.h"
+#include "build.h"
#include <stdlib.h>
#include <string.h>