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).
This commit is contained in:
Olaf Seibert
2015-07-06 21:43:03 +02:00
parent ce2d526291
commit 80b20b17eb
4 changed files with 41 additions and 6 deletions

View File

@@ -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 $@.$$$$

View File

@@ -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");
}

View File

@@ -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
/*

21
make-git-info Executable file
View File

@@ -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