Makefile: Abstract out "identify the pkgversion" code
authorPeter Maydell <peter.maydell@linaro.org>
Thu, 7 Mar 2019 14:26:47 +0000 (14:26 +0000)
committerPeter Maydell <peter.maydell@linaro.org>
Thu, 7 Mar 2019 14:26:47 +0000 (14:26 +0000)
Abstract out the "identify the pkgversion" code from the
rule for creating qemu-version.h, so it sets makefile
variables for QEMU_PKGVERSION and QEMU_FULL_VERSION.
(We will want to use these when building the Sphinx docs.)

NB: As we abstract this out, we use -e to check for .git
rather than -d, since in some situations .git may be a file
rather than a directory.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Acked-by: Aleksandar Markovic <amarkovic@wavecomp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20190305172139.32662-11-peter.maydell@linaro.org
Message-id: 20190228145624.24885-11-peter.maydell@linaro.org

Makefile

index add22cf294735e66e7289321cda6327f6c8a3404..b746d112a7f17ec97b04d4fb7d74ed1a97c016b8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -87,6 +87,20 @@ endif
 
 include $(SRC_PATH)/rules.mak
 
+# Create QEMU_PKGVERSION and FULL_VERSION strings
+# If PKGVERSION is set, use that; otherwise get version and -dirty status from git
+QEMU_PKGVERSION := $(if $(PKGVERSION),$(PKGVERSION),$(shell \
+  cd $(SRC_PATH); \
+  if test -e .git; then \
+    git describe --match 'v*' 2>/dev/null | tr -d '\n'; \
+    if ! git diff-index --quiet HEAD &>/dev/null; then \
+      echo "-dirty"; \
+    fi; \
+  fi))
+
+# Either "version (pkgversion)", or just "version" if pkgversion not set
+FULL_VERSION := $(if $(QEMU_PKGVERSION),$(VERSION) ($(QEMU_PKGVERSION)),$(VERSION))
+
 GENERATED_FILES = qemu-version.h config-host.h qemu-options.def
 
 GENERATED_QAPI_FILES = qapi/qapi-builtin-types.h qapi/qapi-builtin-types.c
@@ -392,23 +406,8 @@ all: $(DOCS) $(if $(BUILD_DOCS),sphinxdocs) $(TOOLS) $(HELPERS-y) recurse-all mo
 
 qemu-version.h: FORCE
        $(call quiet-command, \
-               (cd $(SRC_PATH); \
-               if test -n "$(PKGVERSION)"; then \
-                       pkgvers="$(PKGVERSION)"; \
-               else \
-                       if test -d .git; then \
-                               pkgvers=$$(git describe --match 'v*' 2>/dev/null | tr -d '\n');\
-                               if ! git diff-index --quiet HEAD &>/dev/null; then \
-                                       pkgvers="$${pkgvers}-dirty"; \
-                               fi; \
-                       fi; \
-               fi; \
-               printf "#define QEMU_PKGVERSION \"$${pkgvers}\"\n"; \
-               if test -n "$${pkgvers}"; then \
-                       printf '#define QEMU_FULL_VERSION QEMU_VERSION " (" QEMU_PKGVERSION ")"\n'; \
-               else \
-                       printf '#define QEMU_FULL_VERSION QEMU_VERSION\n'; \
-               fi; \
+                (printf '#define QEMU_PKGVERSION "$(QEMU_PKGVERSION)"\n'; \
+               printf '#define QEMU_FULL_VERSION "$(FULL_VERSION)"\n'; \
                ) > $@.tmp)
        $(call quiet-command, if ! cmp -s $@ $@.tmp; then \
          mv $@.tmp $@; \