From: David Griffith Date: Sun, 17 Jul 2016 06:25:07 +0000 (-0700) Subject: Make Git hash, tag, and branch info available to Frotz. X-Git-Url: https://scope-eye.net/git/?a=commitdiff_plain;h=35b6e2b7abc5ac308480b99a770e2e364907dd94;p=liskon_frotz.git Make Git hash, tag, and branch info available to Frotz. --- diff --git a/.gitignore b/.gitignore index 3e9c5c1..b064601 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ dfrotz *.o *.a defines.h +git_hash.h diff --git a/Makefile b/Makefile index 330555f..e6d6abf 100644 --- 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 - diff --git a/src/common/frotz.h b/src/common/frotz.h index 72aba0f..549d39a 100644 --- a/src/common/frotz.h +++ b/src/common/frotz.h @@ -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 diff --git a/src/curses/ux_init.c b/src/curses/ux_init.c index 4b28aad..836c60d 100644 --- a/src/curses/ux_init.c +++ b/src/curses/ux_init.c @@ -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; +}