From a6640058ffdea63f25708c5f241c86ce2b052650 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Fri, 19 Aug 2016 19:53:32 -0300 Subject: [PATCH] eeshow/: eeshow -V prints the commit from which eeshow was built --- eeshow/Makefile | 8 +++++++- eeshow/main.c | 10 ++++++++-- eeshow/version.c | 16 ++++++++++++++++ eeshow/version.h | 18 ++++++++++++++++++ 4 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 eeshow/version.c create mode 100644 eeshow/version.h diff --git a/eeshow/Makefile b/eeshow/Makefile index ece7f79..f1b9e7c 100644 --- a/eeshow/Makefile +++ b/eeshow/Makefile @@ -11,7 +11,7 @@ # NAME = eeshow -OBJS = main.o \ +OBJS = main.o version.o \ kicad/sch-parse.o kicad/sch-render.o kicad/lib-parse.o \ kicad/lib-render.o kicad/dwg.o kicad/delta.o \ gui/gui.o gui/over.o gui/style.o gui/aoi.o gui/fmt-pango.o gui/input.o \ @@ -33,6 +33,10 @@ LDLIBS = -lm \ `pkg-config --libs libgit2` \ `pkg-config --libs gtk+-3.0` +GIT_VERSION = $(shell git log -1 --format='%h' -s .) +GIT_STATUS = $(shell [ -z "`git status -s -uno`" ] || echo +) +CFLAGS += -DVERSION='"$(GIT_VERSION)$(GIT_STATUS)"' + ifneq ($(USE_WEBKIT),) CFLAGS += -DUSE_WEBKIT `pkg-config --cflags webkit2gtk-4.0` LDLIBS += `pkg-config --libs webkit2gtk-4.0` @@ -44,10 +48,12 @@ endif include ../common/Makefile.c-common .PHONY: test neo900 sch test testref png pngref pdf diff view newref +.PHONY: version.c all:: $(NAME) $(NAME): $(OBJS) + $(MAKE) version.o $(CC) -o $(NAME) $(OBJS) $(LDLIBS) help.inc: $(HELP_TEXT) Makefile diff --git a/eeshow/main.c b/eeshow/main.c index 15fa8e7..7f2256e 100644 --- a/eeshow/main.c +++ b/eeshow/main.c @@ -31,6 +31,7 @@ #include "gui/fmt-pango.h" #include "file/git-hist.h" #include "gui/gui.h" +#include "version.h" #include "main.h" @@ -50,6 +51,7 @@ void usage(const char *name) " %*s[-- driver_spec]\n" " %s [-v ...] -C [rev:]file\n" " %s [-v ...] -H path_into_repo\n" +" %s -V\n" " %s gdb ...\n" "\n" " rev git revision\n" @@ -58,6 +60,7 @@ void usage(const char *name) " -C 'cat' the file to standard output\n" " -H show history of repository on standard output\n" " -N n limit history to n revisions (unlimited if omitted or 0)\n" +" -V print revision (version) number and exit\n" " gdb run eeshow under gdb\n" "\n" "No driver spec: enter GUI\n" @@ -83,7 +86,7 @@ void usage(const char *name) " diff [-o output.pdf] [-s scale] [file.lib ...] file.sch\n" "\n" " see PNG\n" - , name, name, (int) strlen(name) + 1, "", name, name, name); + , name, name, (int) strlen(name) + 1, "", name, name, name, name); exit(1); } @@ -127,7 +130,7 @@ int main(int argc, char **argv) if (!have_dashdash) gtk_init(&argc, &argv); - while ((c = getopt(dashdash, argv, "rvC:F:H:N:")) != EOF) + while ((c = getopt(dashdash, argv, "rvC:F:H:N:V")) != EOF) switch (c) { case 'r': recurse = 1; @@ -147,6 +150,9 @@ int main(int argc, char **argv) case 'N': limit = atoi(optarg); break; + case 'V': + fprintf(stderr, "%s\n", version); + return 1; default: usage(*argv); } diff --git a/eeshow/version.c b/eeshow/version.c new file mode 100644 index 0000000..a8b276f --- /dev/null +++ b/eeshow/version.c @@ -0,0 +1,16 @@ +/* + * version.c - GIT version + * + * Written 2016 by Werner Almesberger + * Copyright 2016 by Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include "version.h" + + +const char *version = VERSION; diff --git a/eeshow/version.h b/eeshow/version.h new file mode 100644 index 0000000..deb101f --- /dev/null +++ b/eeshow/version.h @@ -0,0 +1,18 @@ +/* + * version.h - GIT version + * + * Written 2016 by Werner Almesberger + * Copyright 2016 by Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#ifndef VERSION_H +#define VERSION_H + +extern const char *version; + +#endif /* !VERSION_H */