Hey Raphaël, This does not seems to work... I've applied your patch and recompile my git tree but version are still showing "2.1.0" ... ?
Another thing, we really do prefer having #ifdef statement in one call site per binaries this means that you might want to use like "lttng-sessiond.h", put the ifdef there and do an inline function to print the correct version. Last thing, don't use spaces please! You can use extras/checkpatch.pl to make sure you are ok with the std we have. Thanks! David Raphaël Beamonte: > Signed-off-by: Raphaël Beamonte <[email protected]> > --- > include/Makefile.am | 20 +++++++++++++++++++- > include/lttng/version.h | 25 +++++++++++++++++++++++++ > src/bin/lttng-sessiond/main.c | 5 +++++ > src/bin/lttng/commands/version.c | 4 ++++ > src/bin/lttng/lttng.c | 7 ++++++- > 5 files changed, 59 insertions(+), 2 deletions(-) > create mode 100644 include/lttng/version.h > > diff --git a/include/Makefile.am b/include/Makefile.am > index 0bcb6f9..6664813 100644 > --- a/include/Makefile.am > +++ b/include/Makefile.am > @@ -1 +1,19 @@ > -lttnginclude_HEADERS = lttng/lttng.h lttng/lttng-error.h > +all-local: > + (git_version=$$(git describe --long --all 2>/dev/null); \ > + version_h=$(top_builddir)/include/lttng/version.h; \ > + if [ -z "$${git_version}" ]; then \ > + if [ $$(grep -c "^#define GIT_VERSION" "$${version_h}") -gt 0 > ]; then \ > + sed -i "/^#define GIT_VERSION/d" "$${version_h}"; \ > + fi; \ > + else \ > + if [ $$(grep -cE "^#define GIT_VERSION \"?$${git_version}\"?$$" > "$${version_h}") -eq 0 ]; then \ > + if [ $$(grep -c "^#define GIT_VERSION" "$${version_h}") > -gt 0 ]; then \ > + sed -i "s'^#define GIT_VERSION.*$$'#define > GIT_VERSION \"$${git_version}\"'" "$${version_h}"; \ > + else \ > + sed -i "s'^\(#define > VERSION_H.*\)$$'\1\n\n#define GIT_VERSION \"$${git_version}\"'" > "$${version_h}"; \ > + fi; \ > + fi; \ > + fi) > + > + > +lttnginclude_HEADERS = lttng/lttng.h lttng/lttng-error.h lttng/version.h > diff --git a/include/lttng/version.h b/include/lttng/version.h > new file mode 100644 > index 0000000..42a509d > --- /dev/null > +++ b/include/lttng/version.h > @@ -0,0 +1,25 @@ > +/* > + * version.h > + * > + * Linux Trace Toolkit version header file > + * > + * Copyright (C) 2013 - Raphaël Beamonte <[email protected]> > + * > + * This library is free software; you can redistribute it and/or modify it > + * under the terms of the GNU Lesser General Public License, version 2.1 > only, > + * as published by the Free Software Foundation. > + * > + * This library is distributed in the hope that it will be useful, but > WITHOUT > + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or > + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public > License > + * for more details. > + * > + * You should have received a copy of the GNU Lesser General Public License > + * along with this library; if not, write to the Free Software Foundation, > + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA > + */ > + > +#ifndef VERSION_H > +#define VERSION_H > + > +#endif /* VERSION_H */ > diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c > index f7bb53e..f0d5895 100644 > --- a/src/bin/lttng-sessiond/main.c > +++ b/src/bin/lttng-sessiond/main.c > @@ -35,6 +35,7 @@ > #include <urcu/uatomic.h> > #include <unistd.h> > #include <config.h> > +#include <lttng/version.h> > > #include <common/common.h> > #include <common/compat/socket.h> > @@ -3547,7 +3548,11 @@ static int parse_args(int argc, char **argv) > usage(); > exit(EXIT_FAILURE); > case 'V': > +#ifdef GIT_VERSION > + fprintf(stdout, "%s (Git: %s)\n", VERSION, GIT_VERSION); > +#else /* GIT_VERSION */ > fprintf(stdout, "%s\n", VERSION); > +#endif /* GIT_VERSION */ > exit(EXIT_SUCCESS); > case 'S': > opt_sig_parent = 1; > diff --git a/src/bin/lttng/commands/version.c > b/src/bin/lttng/commands/version.c > index 7f69de3..c6e9e10 100644 > --- a/src/bin/lttng/commands/version.c > +++ b/src/bin/lttng/commands/version.c > @@ -24,6 +24,7 @@ > #include <sys/types.h> > #include <unistd.h> > #include <config.h> > +#include <lttng/version.h> > > #include "../command.h" > > @@ -79,6 +80,9 @@ int cmd_version(int argc, const char **argv) > } > > MSG("lttng version " VERSION " - " VERSION_NAME); > +#ifdef GIT_VERSION > + MSG("Git version: " GIT_VERSION); > +#endif > MSG("\n" VERSION_DESCRIPTION "\n"); > MSG("Web site: http://lttng.org"); > MSG("\nlttng is free software and under the GPL license and part LGPL"); > diff --git a/src/bin/lttng/lttng.c b/src/bin/lttng/lttng.c > index 8562144..e30a7c6 100644 > --- a/src/bin/lttng/lttng.c > +++ b/src/bin/lttng/lttng.c > @@ -25,6 +25,7 @@ > #include <sys/wait.h> > #include <unistd.h> > #include <config.h> > +#include <lttng/version.h> > #include <ctype.h> > > #include <lttng/lttng.h> > @@ -81,7 +82,11 @@ static struct cmd_struct commands[] = { > > static void usage(FILE *ofp) > { > - fprintf(ofp, "LTTng Trace Control " VERSION" - " VERSION_NAME"\n\n"); > + fprintf(ofp, "LTTng Trace Control " VERSION" - " VERSION_NAME"\n"); > +#ifdef GIT_VERSION > + fprintf(ofp, "Git version: " GIT_VERSION"\n"); > +#endif > + fprintf(ofp, "\n"); > fprintf(ofp, "usage: lttng [OPTIONS] <COMMAND> [<ARGS>]\n"); > fprintf(ofp, "\n"); > fprintf(ofp, "Options:\n"); _______________________________________________ lttng-dev mailing list [email protected] http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
