default: $(NVME)
-nvme: nvme.c $(NVME_HEADER) argconfig.o suffix.o
+NVME-VERSION-FILE: FORCE
+ @$(SHELL_PATH) ./NVME-VERSION-GEN
+-include NVME-VERSION-FILE
+override CFLAGS += -DNVME_VERSION='"$(NVME_VERSION)"'
+
+nvme: nvme.c $(NVME_HEADER) argconfig.o suffix.o NVME-VERSION-FILE
$(CC) $(CFLAGS) nvme.c $(LDFLAGS) -o $(NVME) argconfig.o suffix.o
argconfig.o: $(SRC)/argconfig.c $(SRC)/argconfig.h $(SRC)/suffix.h
all: doc
clean:
- rm -f $(NVME) *.o *~ a.out
+ rm -f $(NVME) *.o *~ a.out NVME-VERSION-FILE
$(MAKE) -C Documentation clean
clobber: clean
install: install-bin install-man
-.PHONY: default all doc clean clobber install install-bin install-man
+.PHONY: default all doc clean clobber install install-bin install-man FORCE
--- /dev/null
+#!/bin/sh
+
+GVF=NVME-VERSION-FILE
+DEF_VER=0.1
+
+LF='
+'
+
+# First see if there is a version file (included in release tarballs),
+# then try git-describe, then default.
+if test -f version
+then
+ VN=`cat version` || VN="$DEF_VER"
+elif test -d .git -o -f .git &&
+ VN=`git describe --match "nvme-[0-9]*" --abbrev=4 HEAD 2>/dev/null` &&
+ case "$VN" in
+ *$LF*) (exit 1) ;;
+ v[0-9]*)
+ git update-index -q --refresh
+ test -z "`git diff-index --name-only HEAD --`" ||
+ VN="$VN-dirty" ;;
+ esac
+then
+ VN=$VN
+else
+ VN="$DEF_VER"
+fi
+
+VN=`expr "$VN" : v*'\(.*\)'`
+
+if test -r $GVF
+then
+ VC=`sed -e 's/^NVME_VERSION = //' <$GVF`
+else
+ VC=unset
+fi
+test "$VN" = "$VC" || {
+ echo >&2 "NVME_VERSION = $VN"
+ echo "NVME_VERSION = $VN" >$GVF
+}
+
+
static struct stat nvme_stat;
static const char *devicename;
+static const char nvme_version_string[] = NVME_VERSION;
+
#define COMMAND_LIST \
ENTRY(LIST, "list", "List all NVMe devices and namespaces on machine", list) \
ENTRY(ID_CTRL, "id-ctrl", "Send NVMe Identify Controller", id_ctrl) \
ENTRY(READ_CMD, "read", "Submit a read command, return results", read_cmd) \
ENTRY(WRITE_CMD, "write", "Submit a write command, return results", write_cmd) \
ENTRY(REGISTERS, "show-regs", "Shows the controller registers. Requires admin character device", show_registers) \
+ ENTRY(VERSION, "version", "Shows the program version", version) \
ENTRY(HELP, "help", "Display this help", help)
#define ENTRY(i, n, h, f) \
{
unsigned i;
+ printf("%s\n", nvme_version_string);
usage("nvme");
printf("\n");
printf("'<device>' / '/dev/nvmeX' may be either an NVMe character "\
printf("See 'nvme help <command>' for more information on a specific command.\n");
}
+static int version(int argc, char **argv)
+{
+ printf("nvme version %s\n", nvme_version_string);
+ return 0;
+}
+
static int help(int argc, char **argv)
{
if (argc == 1)
{
unsigned i;
struct command *cmd;
+ char *str = argv[0];
+
+ /* translate --help and --version into commands */
+ while (*str == '-')
+ str++;
for (i = 0; i < NUM_COMMANDS; i++) {
cmd = &commands[i];
- if (strcmp(argv[0], cmd->name))
+ if (strcmp(str, cmd->name))
continue;
exit(cmd->fn(argc, argv));
}