Make Git hash, tag, and branch info available to Frotz.
authorDavid Griffith <dave@661.org>
Sun, 17 Jul 2016 06:25:07 +0000 (23:25 -0700)
committerDavid Griffith <dave@661.org>
Sun, 17 Jul 2016 06:25:07 +0000 (23:25 -0700)
.gitignore
Makefile
src/common/frotz.h
src/curses/ux_init.c

index 3e9c5c147ab21cfb59755a108de789cf691255e9..b064601de5ea03d229d37628b0d69bd49d2a1938 100644 (file)
@@ -3,3 +3,4 @@ dfrotz
 *.o
 *.a
 defines.h
+git_hash.h
index 330555fd737582a2dfe4b50face9730092732d83..e6d6abf62de47b7de557e3b01f68ddfafe9d7745 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -148,9 +148,9 @@ SOUND_LIB = -lao -ldl -lpthread -lm -lsndfile -lvorbisfile -lmodplug -lsamplerat
 # Targets
 #
 
-.PHONY: all help dist clean distclean install install_dumb uninstall uninstall_dumb
+.PHONY: all help dist clean distclean install install_dumb uninstall uninstall_dumb hash
 
-$(NAME): $(CURSES_DIR)/defines.h $(COMMON_TARGET) $(CURSES_TARGET) $(BLORB_TARGET)
+$(NAME): hash $(COMMON_DIR)/defines.h $(CURSES_DIR)/curses_defines.h $(COMMON_TARGET) $(CURSES_TARGET) $(BLORB_TARGET)
 ifeq ($(SOUND), ao)
        $(CC) -o $(BINNAME)$(EXTENSION) $(TARGETS) $(LIB) $(CURSES) $(SOUND_LIB)
 else ifeq ($(SOUND), none)
@@ -187,9 +187,12 @@ $(CURSES_OBJECT): %.o: %.c
 ####################################
 # Get the defines set up just right
 #
-$(CURSES_DIR)/defines.h:
+$(COMMON_DIR)/defines.h:
        @echo "Generating $@"
        @echo "#define VERSION \"$(VERSION)\"" > $@
+
+$(CURSES_DIR)/curses_defines.h:
+       @echo "Generating $@"
        @echo "#define CONFIG_DIR \"$(CONFIG_DIR)\"" >> $@
        @echo "#define SOUND \"$(SOUND)\"" >> $@
        @echo "#define SAMPLERATE $(SAMPLERATE)" >> $@
@@ -271,7 +274,7 @@ uninstall_dumb:
        rm -f $(PREFIX)/bin/d$(NAME)
        rm -f $(MAN_PREFIX)/man/man6/d$(NAME).6
 
-dist: distclean
+dist: distclean hash
        mkdir $(distdir)
        @for file in `ls`; do \
                if test $$file != $(distdir); then \
@@ -288,7 +291,8 @@ dist: distclean
 
 clean:
        rm -f $(SRCDIR)/*.h $(SRCDIR)/*.a
-       rm -f $(CURSES_DIR)/defines.h
+       rm -f $(COMMON_DIR)/defines.h
+       rm -f $(CURSES_DIR)/curses_defines.h
        find . -name *.o -exec rm -f {} \;
        find . -name *.O -exec rm -f {} \;
 
@@ -300,6 +304,24 @@ distclean: clean
        -rm -rf $(distdir)
        -rm -f $(distdir).tar $(distdir).tar.gz
 
+# If we're building from a Git repository, fetch the commit tag and put 
+#   it into $(COMMON_DIR)/git_hash.h.
+# If not, that should mean that we're building from a tarball.  In that 
+#  case, $(COMMON_DIR)/git_hash.h should already be there.
+hash:
+ifneq ($(and $(wildcard .git),$(shell which git)),)
+       @echo "Creating $(COMMON_DIR)/git_hash.h"
+       @echo "#define GIT_HASH \"$$(git rev-parse HEAD)\"" > $(COMMON_DIR)/git_hash.h
+       @echo "#define GIT_TAG \"$$(git describe --tags)\"" >> $(COMMON_DIR)/git_hash.h
+       @echo "#define GIT_BRANCH \"$$(git rev-parse --abbrev-ref HEAD)\"" >> $(COMMON_DIR)/git_hash.h
+else
+  ifneq ($(wildcard $(COMMON_DIR)/git_hash.h),)
+       @echo "Found $(COMMON_DIR)/git_hash.h"
+  else
+       $(error $(COMMON_DIR)/git_hash.h is missing!.)
+  endif
+endif
+
 help:
        @echo
        @echo "Targets:"
@@ -313,4 +335,3 @@ help:
        @echo "    distclean"
        @echo "    dist"
        @echo
-
index 72aba0fbb420945a0a67272f4e382ae469bf6ca7..549d39a1a4a1adefe859db8dcbda9175fe1b5cf4 100644 (file)
@@ -9,9 +9,8 @@
    But since no os_* function uses it, it's safe to let the frotz core see
    this definition, but have the unix port see the curses version. */
 
-#ifndef VERSION
-#define VERSION "2.44pre"
-#endif
+#include "defines.h"
+#include "git_hash.h"
 
 #ifndef __UNIX_PORT_FILE
 #include <signal.h>
index 4b28aad1b7bd599522e78f0589b1f759a5684ec9..836c60dfaaa3e56fc547be84ab0ea1fc1e1bd541 100644 (file)
@@ -61,9 +61,9 @@ Syntax: frotz [options] story-file\n\
   -f # foreground color         \t -S # transcript width\n\
   -F   Force color mode         \t -t   set Tandy bit\n\
   -h # screen height            \t -u # slots for multiple undo\n\
-  -i   ignore fatal errors      \t -w # screen width\n\
-  -l # left margin              \t -x   expand abbreviations g/x/z\n\
-  -o   watch object movement"
+  -i   ignore fatal errors      \t -v   print version information\n\
+  -l # left margin              \t -w # screen width\n\
+  -o   watch object movement    \t -x   expand abbreviations g/x/z"
 
 /*
 char stripped_story_name[FILENAME_MAX+1];
@@ -75,6 +75,7 @@ static int zoptind = 1;
 static int zoptopt = 0;
 static char *zoptarg = NULL;
 
+static void    print_version(void);
 static int     getconfig(char *);
 static int     getbool(char *);
 static int     getcolor(char *);
@@ -230,7 +231,7 @@ void os_process_arguments (int argc, char *argv[])
 
     /* Parse the options */
     do {
-       c = zgetopt(argc, argv, "aAb:c:def:Fh:il:oOpPqr:s:S:tu:w:xZ:");
+       c = zgetopt(argc, argv, "aAb:c:def:Fh:il:oOpPqr:s:S:tu:vw:xZ:");
        switch(c) {
          case 'a': f_setup.attribute_assignment = 1; break;
          case 'A': f_setup.attribute_testing = 1; break;
@@ -268,6 +269,7 @@ void os_process_arguments (int argc, char *argv[])
          case 'S': f_setup.script_cols = atoi(zoptarg); break;
          case 't': u_setup.tandy_bit = 1; break;
          case 'u': f_setup.undo_slots = atoi(zoptarg); break;
+         case 'v': print_version(); exit(2); break;
          case 'w': u_setup.screen_width = atoi(zoptarg); break;
          case 'x': f_setup.expand_abbreviations = 1; break;
          case 'Z': f_setup.err_report_mode = atoi(zoptarg);
@@ -280,10 +282,12 @@ void os_process_arguments (int argc, char *argv[])
     } while (c != EOF);
 
     if (zoptind != argc - 1) {
-       printf("FROTZ V%s\t", VERSION);
+       printf("FROTZ V%s\t", GIT_TAG);
 
 #ifndef NO_SOUND
        printf("Audio output enabled.");
+#else
+       printf("Audio output disabled.");
 #endif
        putchar('\n');
 
@@ -1036,3 +1040,22 @@ error:
     fputc ('\n', stderr);
     return '?';
 }/* zgetopt */
+
+
+static void print_version(void)
+{
+    printf("FROTZ V%s\t", VERSION);
+#ifndef NO_SOUND
+        printf("Audio output enabled.");
+#else
+       printf("Audio output disabled.");
+#endif
+    printf("\nGit commit:\t%s\n", GIT_HASH);
+    printf("Git tag:\t%s\n", GIT_TAG);
+    printf("Git branch:\t%s\n", GIT_BRANCH);
+    printf("  Frotz was originally written by Stefan Jokisch\n");
+    printf("  It was ported to Unix by Galen Hazelwood.\n");
+    printf("  The core and Unix port are currently maintained by David Griffith.\n");
+    printf("  See https://github.com/DavidGriffith/frotz for Frotz's homepage\n\n");
+    return;
+}