Always generate version from git if possible #532.
authorDaniel Carl <danielcarl@gmx.de>
Thu, 10 Jan 2019 09:26:37 +0000 (10:26 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Thu, 10 Jan 2019 09:26:37 +0000 (10:26 +0100)
.gitignore
Makefile
config.mk
src/main.c
src/setting.c

index 711ddb0..b511ac4 100644 (file)
@@ -3,3 +3,4 @@
 *.so
 *.tar.gz
 sandbox
+version.h
index 8566abe..ce2f2ef 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,12 @@
+version = 3.3.0
 include config.mk
 
-all: src.subdir-all
+all: version.h src.subdir-all
+
+version.h: Makefile .git/index
+       @echo "create $@"
+       $(Q)v="$$(git describe --tags 2>/dev/null)"; \
+       echo "#define VERSION \"$${v:-$(version)}\"" > $@
 
 options:
        @echo "vimb build options:"
@@ -10,7 +16,7 @@ options:
        @echo "EXTCFLAGS = $(EXTCFLAGS)"
        @echo "CC        = $(CC)"
 
-install: src.subdir-all
+install: all
        @# binary
        install -d $(BINPREFIX)
        install -m 755 src/vimb $(BINPREFIX)/vimb
@@ -19,7 +25,7 @@ install: src.subdir-all
        install -m 644 src/webextension/$(EXTTARGET) $(LIBDIR)/$(EXTTARGET)
        @# man page
        install -d $(MANPREFIX)/man1
-       @sed -e "s!VERSION!$(VERSION)!g" \
+       @sed -e "s!VERSION!$(version)!g" \
                -e "s!PREFIX!$(PREFIX)!g" \
                -e "s!DATE!`date +'%m %Y'`!g" $(DOCDIR)/vimb.1 > $(MANPREFIX)/man1/vimb.1
        @# .desktop file
index 8c8c51a..5691aae 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -1,5 +1,3 @@
-VERSION = 3.3.0
-
 ifneq ($(V),1)
 Q := @
 endif
@@ -20,11 +18,9 @@ DOCDIR  = doc
 # used libs
 LIBS = gtk+-3.0 'webkit2gtk-4.0 >= 2.20.0'
 
-COMMIT := $(shell git describe --tags --always 2> /dev/null || echo "unknown")
-
 # setup general used CFLAGS
 CFLAGS   += -std=c99 -pipe -Wall -fPIC
-CPPFLAGS += -DVERSION=\"${VERSION}\" -DEXTENSIONDIR=\"${EXTENSIONDIR}\" -DCOMMIT=\"$(COMMIT)\"
+CPPFLAGS += -DEXTENSIONDIR=\"${EXTENSIONDIR}\"
 CPPFLAGS += -DPROJECT=\"vimb\" -DPROJECT_UCFIRST=\"Vimb\"
 CPPFLAGS += -D_XOPEN_SOURCE=500
 CPPFLAGS += -D__BSD_VISIBLE
index 58b5f24..057cf39 100644 (file)
@@ -28,6 +28,7 @@
 #include <unistd.h>
 #include <webkit2/webkit2.h>
 
+#include "../version.h"
 #include "ascii.h"
 #include "command.h"
 #include "completion.h"
@@ -1923,12 +1924,12 @@ int main(int argc, char* argv[])
     }
 
     if (ver) {
-        printf("%s, version %s\n\n", PROJECT, VERSION);
+        printf("%s, version %s\n", PROJECT, VERSION);
         return EXIT_SUCCESS;
     }
 
     if (buginfo) {
-        printf("Commit:          %s\n", COMMIT);
+        printf("Version:         %s\n", VERSION);
         printf("WebKit compile:  %d.%d.%d\n",
                 WEBKIT_MAJOR_VERSION,
                 WEBKIT_MINOR_VERSION,
index db57702..ea58fc2 100644 (file)
@@ -20,6 +20,7 @@
 #include <glib.h>
 #include <string.h>
 
+#include "../version.h"
 #include "completion.h"
 #include "config.h"
 #include "ext-proxy.h"