From e141da1d9456ecb57357d4881045ec5728ea6ec0 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Tue, 9 Mar 2021 23:59:34 +0100 Subject: [PATCH] Compute fallback version string at compile time --- include/version.h | 6 +++--- src/version.c | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/version.h b/include/version.h index 15a9de15..8359f239 100644 --- a/include/version.h +++ b/include/version.h @@ -9,9 +9,9 @@ #ifndef EXTERN_VERSION_H #define EXTERN_VERSION_H -#define PACKAGE_VERSION_MAJOR (0) -#define PACKAGE_VERSION_MINOR (4) -#define PACKAGE_VERSION_PATCH (2) +#define PACKAGE_VERSION_MAJOR 0 +#define PACKAGE_VERSION_MINOR 4 +#define PACKAGE_VERSION_PATCH 2 const char *get_package_version_string(void); diff --git a/src/version.c b/src/version.c index 77868e99..0f716e01 100644 --- a/src/version.c +++ b/src/version.c @@ -9,17 +9,17 @@ #include #include +#include "helpers.h" #include "version.h" const char *get_package_version_string(void) { - static char s[50]; - - /* The following conditional should be simplified by the compiler. */ + // The following conditional should be simplified by the compiler. if (strlen(BUILD_VERSION_STRING) == 0) { - snprintf(s, sizeof(s), "v%d.%d.%d", PACKAGE_VERSION_MAJOR, - PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCH); - return s; + // Fallback if version string can't be obtained from Git + return "v" EXPAND_AND_STR(PACKAGE_VERSION_MAJOR) + "." EXPAND_AND_STR(PACKAGE_VERSION_MINOR) + "." EXPAND_AND_STR(PACKAGE_VERSION_PATCH); } else { return BUILD_VERSION_STRING; }