diff options
| author | Joe Perches <joe@perches.com> | 2013-03-06 09:22:58 -0800 |
|---|---|---|
| committer | Christopher Li <sparse@chrisli.org> | 2013-03-06 21:11:23 -0800 |
| commit | bcdb5ee5a83fbe2779cc6e49ab1fa87c50a20805 (patch) | |
| tree | c1efb8f1e70f15dedf028cba1d39b8ac3ec25245 | |
| parent | fbc8230fa8c464e69c006659600eecfcdf6954ab (diff) | |
| download | sparse-dev-bcdb5ee5a83fbe2779cc6e49ab1fa87c50a20805.tar.gz | |
There's no current way to know the version
of sparse. Add --version to see it.
Reviewed-by: Joe Perches <joe@perches.com>
Signed-off-by: Christopher Li <sparse@chrisli.org>
| -rw-r--r-- | Makefile | 10 | ||||
| -rw-r--r-- | lib.c | 25 |
2 files changed, 34 insertions, 1 deletions
@@ -1,5 +1,13 @@ VERSION=0.4.4 +# Generating file version.h if current version has changed +SPARSE_VERSION:=$(shell git describe 2>/dev/null || echo '$(VERSION)') +VERSION_H := $(shell cat version.h 2>/dev/null) +ifneq ($(lastword $(VERSION_H)),"$(SPARSE_VERSION)") +$(info $(shell echo ' GEN 'version.h)) +$(shell echo '#define SPARSE_VERSION "$(SPARSE_VERSION)"' > version.h) +endif + OS = linux @@ -191,7 +199,7 @@ clean: clean-check rm -f *.[oa] .*.d *.so $(PROGRAMS) $(SLIB_FILE) pre-process.h sparse.pc dist: - @if test "`git describe`" != "v$(VERSION)" ; then \ + @if test "v$(SPARSE_VERSION)" != "v$(VERSION)" ; then \ echo 'Update VERSION in the Makefile before running "make dist".' ; \ exit 1 ; \ fi @@ -27,6 +27,7 @@ #include "scope.h" #include "linearize.h" #include "target.h" +#include "version.h" int verbose, optimize, optimize_size, preprocessing; int die_if_error = 0; @@ -646,11 +647,34 @@ static char **handle_base_dir(char *arg, char **next) return next; } +static char **handle_version(char *arg, char **next) +{ + printf("%s\n", SPARSE_VERSION); + exit(0); +} + struct switches { const char *name; char **(*fn)(char *, char **); }; +static char **handle_long_options(char *arg, char **next) +{ + static struct switches cmd[] = { + { "version", handle_version }, + { NULL, NULL } + }; + struct switches *s = cmd; + + while (s->name) { + if (!strcmp(s->name, arg)) + return s->fn(arg, next); + s++; + } + return next; + +} + static char **handle_switch(char *arg, char **next) { static struct switches cmd[] = { @@ -676,6 +700,7 @@ static char **handle_switch(char *arg, char **next) case 'G': return handle_switch_G(arg, next); case 'a': return handle_switch_a(arg, next); case 's': return handle_switch_s(arg, next); + case '-': return handle_long_options(arg + 1, next); default: break; } |
