ref: 318c981c007381a5fafc76b6d0bed03653dcf036
parent: 4be92e14e622f0e8d01737e37a0e60f87a7d8a40
author: Antonio Niño Díaz <[email protected]>
date: Mon Jul 10 21:01:23 EDT 2017
Add code to determine a version string If the folder where the code is compiled is a valid git repository, the version string is generated with `git describe`. If it isn't a valid repository, a string included in the source code is used instead. This one must be updated regularly as the toolchain is developed. Signed-off-by: Antonio Niño Díaz <[email protected]>
--- a/Makefile
+++ b/Makefile
@@ -15,6 +15,8 @@
PNGLDFLAGS := `${PKG_CONFIG} --static --libs-only-L libpng`
PNGLDLIBS := `${PKG_CONFIG} --static --libs-only-l libpng`
+VERSION_STRING := `git describe --tags --dirty --always 2>/dev/null`
+
WARNFLAGS := -Wall -Werror
# Overridable CFLAGS
@@ -21,7 +23,7 @@
CFLAGS := -g
# Non-overridable CFLAGS
REALCFLAGS := ${CFLAGS} ${WARNFLAGS} -std=c99 -D_POSIX_C_SOURCE=200809L \
- -Iinclude
+ -Iinclude -DBUILD_VERSION_STRING=\"${VERSION_STRING}\"
YFLAGS :=
LFLAGS := --nounistd
@@ -49,8 +51,10 @@
src/extern/err.o \
src/extern/reallocarray.o \
src/extern/strlcpy.o \
- src/extern/strlcat.o
+ src/extern/strlcat.o \
+ src/extern/version.o
+
src/asm/asmy.h: src/asm/asmy.c
src/asm/locallex.o src/asm/globlex.o src/asm/lexer.o: src/asm/asmy.h
@@ -66,7 +70,8 @@
src/link/parser.o \
src/link/script.o \
src/link/symbol.o \
- src/extern/err.o
+ src/extern/err.o \
+ src/extern/version.o
src/link/parser.h: src/link/parser.c
src/link/lexer.o: src/link/parser.h
@@ -73,13 +78,15 @@
rgbfix_obj := \
src/fix/main.o \
- src/extern/err.o
+ src/extern/err.o \
+ src/extern/version.o
rgbgfx_obj := \
src/gfx/gb.o \
src/gfx/main.o \
src/gfx/makepng.o \
- src/extern/err.o
+ src/extern/err.o \
+ src/extern/version.o
rgbasm: ${rgbasm_obj}
$Q${CC} ${REALCFLAGS} -o $@ ${rgbasm_obj} -lm
--- /dev/null
+++ b/include/extern/version.h
@@ -1,0 +1,21 @@
+/*
+ * Copyright (C) 2017 Antonio Nino Diaz <[email protected]>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#define PACKAGE_VERSION_MAJOR (0)
+#define PACKAGE_VERSION_MINOR (3)
+#define PACKAGE_VERSION_PATCH (2)
+
+const char * get_package_version_string(void);
--- /dev/null
+++ b/src/extern/version.c
@@ -1,0 +1,34 @@
+/*
+ * Copyright (C) 2017 Antonio Nino Diaz <[email protected]>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "extern/version.h"
+
+const char * get_package_version_string(void)
+{
+ static char s[50];
+
+ /* 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;
+ } else {
+ return BUILD_VERSION_STRING;
+ }
+}