From ba936df6f8d6e988dee9f0be392c4157709c70bb Mon Sep 17 00:00:00 2001 From: nirenjan Date: Wed, 22 Sep 2021 01:37:57 -0700 Subject: [PATCH] Add Version file and associated scripts When building from source, it is desired that we embed the version string into the resulting binaries so that we can determine exactly what version of the sources were used. This change adds a Version file, which always holds the latest release version, and a configure.version script, which tries to get the version information from Git, before falling back to using the version embedded in the above file. The generated configure script will then have the version embedded within it, which will then create the BUILD_VERSION definition in config.h. Applications can then use this definition as needed. --- Makefile.am | 2 ++ Version | 1 + configure.ac | 4 +++- configure.version | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 Version create mode 100755 configure.version diff --git a/Makefile.am b/Makefile.am index d286c4b..005e5f1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -83,6 +83,8 @@ EXTRA_DIST += \ LICENSE \ README.md \ config.rpath \ + configure.version \ + Version \ gettext.h \ usb-ids.h \ po/README.md diff --git a/Version b/Version new file mode 100644 index 0000000..7179039 --- /dev/null +++ b/Version @@ -0,0 +1 @@ +0.2.3 diff --git a/configure.ac b/configure.ac index 0f22393..6ab79cc 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ # # SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 -AC_INIT([x52pro-linux], [0.2.3], [nirenjan@gmail.com]) +AC_INIT([x52pro-linux], [m4_esyscmd_s([cat ./Version])], [nirenjan@gmail.com]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([-Wall foreign subdir-objects]) AC_REQUIRE_AUX_FILE([tap-driver.sh]) @@ -26,6 +26,8 @@ AX_GCC_FUNC_ATTRIBUTE([format]) AX_GCC_FUNC_ATTRIBUTE([noreturn]) AC_C_TYPEOF +AC_DEFINE([BUILD_VERSION], ["m4_esyscmd([./configure.version])"], [Build version]) + AC_MSG_NOTICE([Detected host OS is ${host_os}]) build_linux=no # Detect target system diff --git a/configure.version b/configure.version new file mode 100755 index 0000000..ff6c3e7 --- /dev/null +++ b/configure.version @@ -0,0 +1,34 @@ +#!/bin/sh +# Use the Git version if Git is available, otherwise fallback to Version + +top_srcdir="${1-.}" +test -d "${top_srcdir}" || { \ + echo "FATAL: Could not change to top_srcdir '$1'" >&2 ; \ + exit 1 ; \ +} + +version="${top_srcdir}/Version" + +# Use GIT_DIR if set +if ! test -n "${GIT_DIR}" +then + GIT_DIR="${top_srcdir}/.git" + export GIT_DIR +fi + +if test -d "${GIT_DIR}" +then + # Change tags like vX.Y.Z to X.Y.Z + DESCRIBE=$(git describe --dirty 2>/dev/null) +fi + +if test ! -n "${DESCRIBE}" +then + DESCRIBE="unknown-version" + if test -f "${version}" + then + DESCRIBE="v$(cat "${version}")" + fi +fi + +printf "%s" "${DESCRIBE}"