diff --git a/configure.in b/configure.in index ec843ebb11..b7e98da6c6 100644 --- a/configure.in +++ b/configure.in @@ -813,6 +813,18 @@ AC_CHECK_HEADER(pcap.h,,[AC_ERROR(pcap.h not found ...)]) fi fi +# get revision + if test -f ./revision; then + REVISION=`cat ./revision` + CFLAGS="${CFLAGS} -DREVISION=\"${REVISION}\"" + else + GIT=`which git` + if test "$GIT" != ""; then + REVISION=`git describe --always` + CFLAGS="${CFLAGS} -DREVISION=\"${REVISION}\"" + fi + fi + AC_SUBST(CFLAGS) AC_SUBST(LDFLAGS) AC_SUBST(CPPFLAGS) diff --git a/src/suricata-common.h b/src/suricata-common.h index 7c7c9f08a0..5ebe1827b6 100644 --- a/src/suricata-common.h +++ b/src/suricata-common.h @@ -127,6 +127,11 @@ #include #define BUG_ON(x) assert(!(x)) +/* we need this to stringify the defines which are supplied at compiletime see: + http://gcc.gnu.org/onlinedocs/gcc-3.4.1/cpp/Stringification.html#Stringification */ +#define xstr(s) str(s) +#define str(s) #s + /** type for the internal signature id. Since it's used in the matching engine * extensively keeping this as small as possible reduces the overall memory * footprint of the engine. Set to uint32_t if the engine needs to support diff --git a/src/suricata.c b/src/suricata.c index 3306561bb3..561655c05e 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -313,7 +313,11 @@ static void SetBpfString(int optind, char *argv[]) { void usage(const char *progname) { +#ifdef REVISION + printf("%s %s (rev %s)\n", PROG_NAME, PROG_VER, xstr(REVISION)); +#else printf("%s %s\n", PROG_NAME, PROG_VER); +#endif printf("USAGE: %s\n\n", progname); printf("\t-c : path to configuration file\n"); printf("\t-i : run in pcap live mode\n"); @@ -437,7 +441,11 @@ int main(int argc, char **argv) } #endif /* OS_WIN32 */ +#ifdef REVISION + SCLogInfo("This is %s version %s (rev %s)", PROG_NAME, PROG_VER, xstr(REVISION)); +#else SCLogInfo("This is %s version %s", PROG_NAME, PROG_VER); +#endif /* Initialize the configuration module. */ ConfInit(); @@ -726,7 +734,11 @@ int main(int argc, char **argv) #endif break; case 'V': +#ifdef REVISION + printf("\nThis is %s version %s (rev %s)\n\n", PROG_NAME, PROG_VER, xstr(REVISION)); +#else printf("\nThis is %s version %s\n\n", PROG_NAME, PROG_VER); +#endif exit(EXIT_SUCCESS); default: usage(argv[0]);