Make fio include the git version in the version output
authorJens Axboe <axboe@kernel.dk>
Wed, 21 Mar 2012 21:25:22 +0000 (22:25 +0100)
committerJens Axboe <axboe@kernel.dk>
Wed, 21 Mar 2012 21:25:22 +0000 (22:25 +0100)
Makes it easier in bug reporting, don't have to ask people what
they are running...

Here's to you, Kep.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
FIO-VERSION-GEN [new file with mode: 0755]
Makefile
init.c

diff --git a/FIO-VERSION-GEN b/FIO-VERSION-GEN
new file mode 100755 (executable)
index 0000000..d812255
--- /dev/null
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+GVF=FIO-VERSION-FILE
+DEF_VER=v2.0.5.GIT
+
+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 "fio-[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/^FIO_VERSION = //' <$GVF)
+else
+       VC=unset
+fi
+test "$VN" = "$VC" || {
+       echo >&2 "FIO_VERSION = $VN"
+       echo "FIO_VERSION = $VN" >$GVF
+}
+
+
index ddf257f3e6b145967774a70f7519e7bb43d23579..50b827b8347a0bef96f4998511d3b6407983cb15 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -100,9 +100,18 @@ else
 mandir = $(prefix)/man
 endif
 
-all: .depend $(PROGS) $(SCRIPTS)
+all: .depend $(PROGS) $(SCRIPTS) FORCE
 
-.c.o: .depend
+.PHONY: all install clean
+.PHONY: FORCE cscope
+
+FIO-VERSION-FILE: FORCE
+       @$(SHELL_PATH) ./FIO-VERSION-GEN
+-include FIO-VERSION-FILE
+
+CFLAGS += -DFIO_VERSION='"$(FIO_VERSION)"'
+
+.c.o: .depend FORCE
        $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $(CPPFLAGS) $<
 
 goptions.o: goptions.c goptions.h
@@ -129,7 +138,7 @@ t/stest: $(T_SMALLOC_OBJS)
 t/ieee754: $(T_IEEE_OBJS)
        $(QUIET_CC)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(T_IEEE_OBJS) $(LIBS) $(LDFLAGS)
 
-fio: $(FIO_OBJS)
+fio: $(FIO_OBJS) FORCE
        $(QUIET_CC)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(FIO_OBJS) $(LIBS) $(LDFLAGS)
 
 gfio: $(GFIO_OBJS)
@@ -138,15 +147,15 @@ gfio: $(GFIO_OBJS)
 .depend: $(SOURCE)
        $(QUIET_DEP)$(CC) -MM $(CFLAGS) $(CPPFLAGS) $(SOURCE) 1> .depend
 
-$(PROGS): .depend
+$(PROGS): .depend FORCE
 
-clean:
-       -rm -f .depend $(GFIO_OBJS) $(FIO_OBJS) $(T_OBJS) $(PROGS) $(T_PROGS) core.* core gfio
+clean: FORCE
+       -rm -f .depend $(GFIO_OBJS) $(FIO_OBJS) $(T_OBJS) $(PROGS) $(T_PROGS) core.* core gfio FIO-VERSION-FILE
 
 cscope:
        @cscope -b -R
 
-install: $(PROGS) $(SCRIPTS)
+install: $(PROGS) $(SCRIPTS) FORCE
        $(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
        $(INSTALL) $(PROGS) $(SCRIPTS) $(DESTDIR)$(bindir)
        $(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man1
diff --git a/init.c b/init.c
index 261e02e1fb673ee8db30e0b7eff34843dda03a67..a04198f3e08c77a02a3d2286c350091106e9b086 100644 (file)
--- a/init.c
+++ b/init.c
 
 #include "fio_version.h"
 
-#if FIO_PATCH > 0
-const char fio_version_string[] =      __fio_stringify(FIO_MAJOR) "."  \
-                                       __fio_stringify(FIO_MINOR) "."  \
-                                       __fio_stringify(FIO_PATCH);
-#else
-const char fio_version_string[] =      __fio_stringify(FIO_MAJOR) "."  \
-                                       __fio_stringify(FIO_MINOR);
-#endif
+const char fio_version_string[] = FIO_VERSION;
 
 #define FIO_RANDSEED           (0xb1899bedUL)
 
@@ -1182,7 +1175,7 @@ static int fill_def_thread(void)
 
 static void usage(const char *name)
 {
-       printf("fio %s\n", fio_version_string);
+       printf("%s\n", fio_version_string);
        printf("%s [options] [job options] <job file(s)>\n", name);
        printf("  --debug=options\tEnable debug logging. May be one/more of:\n"
                "\t\t\tprocess,file,io,mem,blktrace,verify,random,parse,\n"
@@ -1455,7 +1448,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                        break;
                case 'v':
                        if (!cur_client) {
-                               log_info("fio %s\n", fio_version_string);
+                               log_info("%s\n", fio_version_string);
                                do_exit++;
                        }
                        break;
@@ -1694,7 +1687,7 @@ int parse_options(int argc, char *argv[])
        }
 
        if (!terse_output)
-               log_info("fio %s\n", fio_version_string);
+               log_info("%s\n", fio_version_string);
 
        return 0;
 }