]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
--version switch
authorJohannes Berg <johannes@sipsolutions.net>
Tue, 16 Sep 2008 19:56:25 +0000 (21:56 +0200)
committerJohannes Berg <johannes@sipsolutions.net>
Tue, 16 Sep 2008 19:56:25 +0000 (21:56 +0200)
.gitignore
Makefile
git-version.sh [new file with mode: 0755]
iw.c
iw.h

index 5d26771f5b377c4c8d5919d1b432fca944a4886f..a2358b43653e030ed06c3a962fd9c5241719db7e 100644 (file)
@@ -2,3 +2,4 @@ iw
 *~
 *.o
 .config
+version.h
index 74cb1e1892f3fa7872afef911f572fb8a3a9ac81..a5d529d4c08c61eb3baab60d1b0087d98eb8bf04 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -23,7 +23,11 @@ endif
 
 all: $(ALL)
 
-%.o: %.c iw.h
+version.h: git-version.sh
+       @$(NQ) ' GEN  version.h'
+       $(Q)./git-version.sh
+
+%.o: %.c iw.h version.h
        @$(NQ) ' CC  ' $@
        $(Q)$(CC) $(CFLAGS) -c -o $@ $<
 
diff --git a/git-version.sh b/git-version.sh
new file mode 100755 (executable)
index 0000000..31e0241
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+(
+if head=`git rev-parse --verify HEAD 2>/dev/null`; then
+       git update-index --refresh --unmerged > /dev/null
+       printf "#define IW_GIT_VERSION \"-g%.8s" "$head"
+       if git diff-index --name-only HEAD | read dummy ; then
+               printf -- "-dirty"
+       fi
+       echo '"'
+else
+       echo '#define IW_GIT_VERSION ""'
+fi
+) > version.h
diff --git a/iw.c b/iw.c
index d872025a61f8eaa64041ff9fa0b76978a34475b4..58d58f008283624873a11098a4e68d50c9d79093 100644 (file)
--- a/iw.c
+++ b/iw.c
@@ -21,6 +21,7 @@
 #include <linux/nl80211.h>
 
 #include "iw.h"
+#include "version.h"
 
 int debug = 0;
 
@@ -76,7 +77,8 @@ static void usage(const char *argv0)
 
        fprintf(stderr, "Usage:\t%s [options] command\n", argv0);
        fprintf(stderr, "Options:\n");
-       fprintf(stderr, "\t--debug\tenable netlink debugging\n");
+       fprintf(stderr, "\t--debug\t\tenable netlink debugging\n");
+       fprintf(stderr, "\t--version\tshow version\n");
        fprintf(stderr, "Commands:\n");
        for (cmd = &__start___cmd; cmd < &__stop___cmd; cmd++) {
                switch (cmd->idby) {
@@ -101,6 +103,11 @@ static void usage(const char *argv0)
        }
 }
 
+static void version(void)
+{
+       printf("iw version " VERSION IW_GIT_VERSION "\n");
+}
+
 static int phy_lookup(char *name)
 {
        char buf[200];
@@ -265,6 +272,11 @@ int main(int argc, char **argv)
                argv++;
        }
 
+       if (argc > 0 && strcmp(*argv, "--version") == 0) {
+               version();
+               return 0;
+       }
+
        if (argc == 0 || strcmp(*argv, "help") == 0) {
                usage(argv0);
                goto out;
diff --git a/iw.h b/iw.h
index c9d905215dade5d8f2bb967a8041f1c9c11dc168..45655cb85d865bc531d80d9902f3a019ab37b67a 100644 (file)
--- a/iw.h
+++ b/iw.h
@@ -6,6 +6,8 @@
 #include <netlink/genl/family.h>
 #include <netlink/genl/ctrl.h>
 
+#define VERSION "1.0"
+
 #define ETH_ALEN 6
 
 struct nl80211_state {