shithub: rgbds

Download patch

ref: e141da1d9456ecb57357d4881045ec5728ea6ec0
parent: 35367282e44167afd63ccc271b39ac3446022d06
author: ISSOtm <eldredhabert0@gmail.com>
date: Tue Mar 9 18:59:34 EST 2021

Compute fallback version string at compile time

--- 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);
 
--- a/src/version.c
+++ b/src/version.c
@@ -9,17 +9,17 @@
 #include <stdio.h>
 #include <string.h>
 
+#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;
 	}