From a8b5e887446eac4b1dd60fe6e43f93bded4cb75e Mon Sep 17 00:00:00 2001 From: nhkeni Date: Wed, 19 Jun 2024 12:28:13 -0400 Subject: [PATCH] add the git prefix to the long version output Tested on MacOS, written and not tested for Linux, not attempted for Windows --- include/global.h | 1 + src/date.c | 9 +++++++++ src/version.c | 4 ++++ sys/unix/Makefile.src | 2 +- sys/unix/hints/linux.370 | 4 ++++ sys/unix/hints/macOS.370 | 4 ++++ 6 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/global.h b/include/global.h index 4c9692aca..0643ca13d 100644 --- a/include/global.h +++ b/include/global.h @@ -386,6 +386,7 @@ struct nomakedefs_s { const char *copyright_banner_c; const char *git_sha; const char *git_branch; + const char *git_prefix; const char *version_string; const char *version_id; unsigned long version_number; diff --git a/src/date.c b/src/date.c index 8764a89be..aef985e75 100644 --- a/src/date.c +++ b/src/date.c @@ -29,6 +29,7 @@ struct nomakedefs_s nomakedefs = { "Version 1.0, built Jul 28 13:18:57 1987.", (const char *) 0, /* git_sha */ (const char *) 0, /* git_branch */ + (const char *) 0, /* git_prefix */ "1.0.0-0", "NetHack Version 1.0.0-0 - last build Tue Jul 28 13:18:57 1987.", 0x01010000UL, @@ -125,6 +126,9 @@ populate_nomakedefs(struct version_info *version) #ifdef NETHACK_GIT_BRANCH nomakedefs.git_branch = dupstr(NETHACK_GIT_BRANCH); #endif +#ifdef NETHACK_GIT_PREFIX + nomakedefs.git_prefix = dupstr(NETHACK_GIT_PREFIX); +#endif nomakedefs_populated = 1; return; @@ -161,6 +165,11 @@ free_nomakedefs(void) free((genericptr_t) nomakedefs.git_branch), nomakedefs.git_branch = 0; #endif +#ifdef NETHACK_GIT_PREFIX + if (nomakedefs.git_prefix) + free((genericptr_t) nomakedefs.git_prefix), + nomakedefs.git_prefix = 0; +#endif /* values are Null now; dynamic vs static doesn't really matter anymore */ nomakedefs_populated = 0; diff --git a/src/version.c b/src/version.c index 33eb254bf..2d6467bc5 100644 --- a/src/version.c +++ b/src/version.c @@ -58,6 +58,10 @@ getversionstring(char *buf, size_t bufsz) "%sbranch:%s", c++ ? "," : "", nomakedefs.git_branch); #endif + if (nomakedefs.git_prefix) + Snprintf(eos(buf), (bufsz - strlen(buf)) - 1, + "%sprefix:%s", + c++ ? "," : "", nomakedefs.git_prefix); if (c) Snprintf(eos(buf), (bufsz - strlen(buf)) - 1, "%s", ")"); diff --git a/sys/unix/Makefile.src b/sys/unix/Makefile.src index b7b1b03d9..f21982f66 100644 --- a/sys/unix/Makefile.src +++ b/sys/unix/Makefile.src @@ -765,7 +765,7 @@ $(TARGETPFX)sfstruct.o: sfstruct.c $(HACK_H) # date.c should be recompiled any time any of the source or include code # is modified. $(TARGETPFX)date.o: date.c $(HACK_H) $(HACKCSRC) $(HOBJ) $(TARGET_HACKLIB) - $(TARGET_CC) $(TARGET_CFLAGS) $(GITHASH) $(GITBRANCH) -c -o $@ date.c + $(TARGET_CC) $(TARGET_CFLAGS) $(GITHASH) $(GITBRANCH) $(GITPREFIX) -c -o $@ date.c # date.h should be remade any time any of the source or include code # is modified. Unfortunately, this would make the contents of this diff --git a/sys/unix/hints/linux.370 b/sys/unix/hints/linux.370 index c17706de2..ce12472c7 100755 --- a/sys/unix/hints/linux.370 +++ b/sys/unix/hints/linux.370 @@ -288,6 +288,7 @@ VARDATND += $(sort $(VARDATND0)) GIT_HASH := $(shell echo `git rev-parse --verify HEAD` 2>&1) GIT_BRANCH := $(shell echo `git rev-parse --abbrev-ref HEAD` 2>&1) +GIT_PREFIX := $(shell echo `git config nethack.substprefix` 2>&1) ifdef GIT_HASH GITHASH = -DNETHACK_GIT_SHA=\"$(GIT_HASH)\" @@ -295,6 +296,9 @@ endif ifdef GIT_BRANCH GITBRANCH = -DNETHACK_GIT_BRANCH=\"$(GIT_BRANCH)\" endif +ifdef GIT_PREFIX +GITPREFIX = -DNETHACK_GIT_PREFIX=\"$(GIT_PREFIX)\" +endif ifdef WANT_LIBNH CFLAGS += -DSHIM_GRAPHICS -DNOTTYGRAPHICS -DNOSHELL -DLIBNH -fpic diff --git a/sys/unix/hints/macOS.370 b/sys/unix/hints/macOS.370 index 4a5d59816..b77ea94f1 100755 --- a/sys/unix/hints/macOS.370 +++ b/sys/unix/hints/macOS.370 @@ -285,6 +285,7 @@ VARDATND += $(sort $(VARDATND0)) GIT_HASH := $(shell echo `git rev-parse --verify HEAD` 2>&1) GIT_BRANCH := $(shell echo `git rev-parse --abbrev-ref HEAD` 2>&1) +GIT_PREFIX := $(shell echo `git config nethack.substprefix` 2>&1) ifdef GIT_HASH GITHASH = -DNETHACK_GIT_SHA=\"$(GIT_HASH)\" @@ -292,6 +293,9 @@ endif ifdef GIT_BRANCH GITBRANCH = -DNETHACK_GIT_BRANCH=\"$(GIT_BRANCH)\" endif +ifdef GIT_PREFIX +GITPREFIX = -DNETHACK_GIT_PREFIX=\"$(GIT_PREFIX)\" +endif ifdef WANT_LIBNH CFLAGS += -DSHIM_GRAPHICS -DNOTTYGRAPHICS -DNOSHELL -DLIBNH