From: Johannes Berg Date: Tue, 16 Sep 2008 19:56:25 +0000 (+0200) Subject: --version switch X-Git-Tag: v0.9~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d711f013374ec07bd85c426b7b7106101da6b9e8;p=thirdparty%2Fiw.git --version switch --- diff --git a/.gitignore b/.gitignore index 5d26771..a2358b4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ iw *~ *.o .config +version.h diff --git a/Makefile b/Makefile index 74cb1e1..a5d529d 100644 --- 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 index 0000000..31e0241 --- /dev/null +++ b/git-version.sh @@ -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 d872025..58d58f0 100644 --- a/iw.c +++ b/iw.c @@ -21,6 +21,7 @@ #include #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 c9d9052..45655cb 100644 --- a/iw.h +++ b/iw.h @@ -6,6 +6,8 @@ #include #include +#define VERSION "1.0" + #define ETH_ALEN 6 struct nl80211_state {