@@ -1,5 +1,12 @@
VERSION=0.4.4
+HAVE_GIT:=$(shell git describe >/dev/null 2>&1 && echo 'yes')
+ifeq ($(HAVE_GIT),yes)
+SPARSE_VERSION=$(shell git describe)
+else
+SPARSE_VERSION=$(VERSION)
+endif
+
OS = linux
@@ -27,7 +34,8 @@ HAVE_LLVM_VERSION:=$(shell llvm-config --version | grep "^[3-9].*" >/dev/null 2>
LLVM_VERSION=$(shell llvm-config --version)
GCC_BASE = $(shell $(CC) --print-file-name=)
-BASIC_CFLAGS = -DGCC_BASE=\"$(GCC_BASE)\"
+BASIC_CFLAGS = -DGCC_BASE=\"$(GCC_BASE)\" \
+ -DSPARSE_VERSION=\"$(SPARSE_VERSION)\"
ifeq ($(HAVE_GCC_DEP),yes)
BASIC_CFLAGS += -Wp,-MD,$(@D)/.$(@F).d
@@ -646,11 +646,39 @@ static char **handle_base_dir(char *arg, char **next)
return next;
}
+static char **handle_version(char *arg, char **next)
+{
+ printf("%s\n", SPARSE_VERSION);
+ return next;
+}
+
struct switches {
const char *name;
char **(*fn)(char *, char **);
};
+static char **handle_options(char *arg, char **next)
+{
+ static struct switches cmd[] = {
+ { "version", handle_version },
+ { NULL, NULL }
+ };
+ struct switches *s;
+
+ s = cmd;
+ while (s->name) {
+ if (!strcmp(s->name, arg))
+ return s->fn(arg, next);
+ s++;
+ }
+
+ /*
+ * Ignore unknown command line options:
+ * they're probably gcc switches
+ */
+ return next;
+}
+
static char **handle_switch(char *arg, char **next)
{
static struct switches cmd[] = {
@@ -952,6 +980,10 @@ struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list
if (!arg)
break;
+ if (arg[0] == '-' && arg[1] == '-' && arg[2]) {
+ args = handle_options(arg+2, args);
+ continue;
+ }
if (arg[0] == '-' && arg[1]) {
args = handle_switch(arg+1, args);
continue;