From 80b20b17ebb48d12c285a47e2f6f3ed1130c97fd Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Mon, 6 Jul 2015 21:43:03 +0200 Subject: [PATCH] Add some info about git commit when printing the version. Also modify dependency generation to be a side-effect of compilation. It's still not quite perfect in picking up some changes (in particular just after a commit, no files have changed but the git identification is now different). --- Makefile | 14 ++++++++++---- macro11.c | 2 +- macro11.h | 10 +++++++++- make-git-info | 21 +++++++++++++++++++++ 4 files changed, 41 insertions(+), 6 deletions(-) create mode 100755 make-git-info diff --git a/Makefile b/Makefile index b2fe715..99e1b5b 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ all: macro11 dumpobj tags: macro11 dumpobj ctags *.c *.h -macro11: $(MACRO11_OBJS) Makefile +macro11: git-info.h $(MACRO11_OBJS) Makefile $(CC) $(CFLAGS) -o macro11 $(MACRO11_OBJS) -lm dumpobj: $(DUMPOBJ_OBJS) Makefile @@ -33,9 +33,13 @@ dumpobj: $(DUMPOBJ_OBJS) Makefile $(MACRO11_OBJS): Makefile $(DUMPOBJ_OBJS): Makefile +git-info.h: + ./make-git-info + clean: -rm -f $(MACRO11_OBJS) $(DUMPOBJ_OBJS) macro11 dumpobj -rm -f *.d + -rm -f git-info.h # Since the only tests we have so far are for crashes, # just try to assemble. Later, we will need expected/actual tests. @@ -63,8 +67,10 @@ tests: macro11 argtests -include $(ALL_SRCS:.c=.d) -%.d: %.c - @set -e; rm -f $@; \ +# Make .d files as side effect of compiling .c to .o +%.d %.o: %.c + $(CC) $(CFLAGS) -c -o $*.o $< + @set -e; rm -f $*.d; \ $(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \ - sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ + sed 's,\($*\)\.o[ :]*,\1.o \1.d : ,g' < $@.$$$$ > $*.d; \ rm -f $@.$$$$ diff --git a/macro11.c b/macro11.c index 8e10d6b..ef50f88 100644 --- a/macro11.c +++ b/macro11.c @@ -82,7 +82,7 @@ static void print_version( fprintf(strm, "macro11 - portable MACRO11 assembler for DEC PDP-11\n"); fprintf(strm, " Version %s\n", VERSIONSTR); fprintf(strm, " Copyright 2001 Richard Krehbiel,\n"); - fprintf(strm, " modified 2009 by Joerg Hoppe.\n"); + fprintf(strm, " modified 2009 by Joerg Hoppe,\n"); fprintf(strm, " modified 2015 by Olaf 'Rhialto' Seibert.\n"); } diff --git a/macro11.h b/macro11.h index 40a5621..12ac3bf 100644 --- a/macro11.h +++ b/macro11.h @@ -1,9 +1,17 @@ #ifndef MACRO11_H #define MACRO11_H -#define VERSIONSTR "0.4wip (22 May 2015)" +#include "git-info.h" + +#define BASE_VERSION "0.4wip" + +#if defined(GIT_VERSION) +#define VERSIONSTR BASE_VERSION" ("GIT_VERSION"\n\t"GIT_AUTHOR_DATE")" +#else +#define VERSIONSTR BASE_VERSION" (21 June 2015)" /*#define VERSIONSTR "0.3 (April 21, 2009)" */ /*#define VERSIONSTR "0.2 July 15, 2001" */ +#endif /* diff --git a/make-git-info b/make-git-info new file mode 100755 index 0000000..31f9d38 --- /dev/null +++ b/make-git-info @@ -0,0 +1,21 @@ +#!/bin/sh + +desc=$(git describe --tags) + +if [ "$desc" = "" ] +then + echo "#undef GIT_VERSION" > new-git-info.h +else + auth=$(git log -n 1 "--pretty=format:%an <%ae> %aD") + + echo "#define GIT_VERSION "'"'"$desc"'"' >new-git-info.h + echo "#define GIT_AUTHOR_DATE "'"'"$auth"'"' >>new-git-info.h +fi + +# move-if-different +if diff new-git-info.h git-info.h >/dev/null 2>&1 +then + rm new-git-info.h +else + mv new-git-info.h git-info.h +fi