Skip to contentSkip to conversation

build: add git revision to --version output if build from git repository

PATCH In review Alon Bar-Lev 3 participants 17 messages Apr 28, 2012 – Jun 13, 2012 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 build: add git revision to --version output if build from git repository

If configure is located at git repository, acquire branch and revision of head to be printed at --version output.

---
 configure.ac          |   11 +++++++++++
 src/openvpn/options.c |    3 +++
 2 files changed, 14 insertions(+), 0 deletions(-)
configure.ac +11 -0
index 399b4e7..812d336 100644
@@ -307,11 +307,13 @@ AC_ARG_VAR([ROUTE], [full path to route utility])
 AC_ARG_VAR([IPROUTE], [full path to ip utility])
 AC_ARG_VAR([NETSTAT], [path to netstat utility]) # tests
 AC_ARG_VAR([MAN2HTML], [path to man2html utility])
+AC_ARG_VAR([GIT], [path to git utility])
 AC_PATH_PROGS([IFCONFIG], [ifconfig],, [$PATH:/usr/local/sbin:/usr/sbin:/sbin])
 AC_PATH_PROGS([ROUTE], [route],, [$PATH:/usr/local/sbin:/usr/sbin:/sbin])
 AC_PATH_PROGS([IPROUTE], [ip],, [$PATH:/usr/local/sbin:/usr/sbin:/sbin])
 AC_CHECK_PROGS([NETSTAT], [netstat], [netstat], [$PATH:/usr/local/sbin:/usr/sbin:/sbin:/etc]) # tests
 AC_CHECK_PROGS([MAN2HTML], [man2html])
+AC_CHECK_PROGS([GIT], [git]) # optional
 AC_DEFINE_UNQUOTED([IFCONFIG_PATH], ["$IFCONFIG"], [Path to ifconfig tool])
 AC_DEFINE_UNQUOTED([IPROUTE_PATH], ["$IPROUTE"], [Path to iproute tool])
 AC_DEFINE_UNQUOTED([ROUTE_PATH], ["$ROUTE"], [Path to route tool])
@@ -781,6 +783,15 @@ PKG_CHECK_MODULES(
 	[]
 )
 
+AC_MSG_CHECKING([git checkout])
+if test -n "${GIT}" -a -d "${srcdir}/.git"; then
+	PACKAGE_VERSION_EXTRA_GIT_REVISION="`GIT_DIR=\"${srcdir}/.git\" git rev-parse --symbolic-full-name HEAD`/`GIT_DIR=\"${srcdir}/.git\" git rev-parse --short HEAD`"
+	AC_MSG_RESULT([${PACKAGE_VERSION_EXTRA_GIT_REVISION}])
+	AC_DEFINE_UNQUOTED([PACKAGE_VERSION_EXTRA_GIT_REVISION], ["${PACKAGE_VERSION_EXTRA_GIT_REVISION}"], [Git checkout revision])
+else
+	AC_MSG_RESULT([no])
+fi
+
 if test -n "${SP_PLATFORM_WINDOWS}"; then
 	AC_DEFINE_UNQUOTED([PATH_SEPARATOR], ['\\\\'], [Path separator]) #"
 	AC_DEFINE_UNQUOTED([PATH_SEPARATOR_STR], ["\\\\"], [Path separator]) #"
src/openvpn/options.c +3 -0
index 019be57..c1aedfb 100644
@@ -3430,6 +3430,9 @@ usage_version (void)
 #ifdef CONFIGURE_DEFINES
   msg (M_INFO|M_NOPREFIX, "Compile time defines: %s", CONFIGURE_DEFINES);
 #endif
+#ifdef PACKAGE_VERSION_EXTRA_GIT_REVISION
+  msg (M_INFO|M_NOPREFIX, "git revision: %s", PACKAGE_VERSION_EXTRA_GIT_REVISION);
+#endif
 #endif
   openvpn_exit (OPENVPN_EXIT_STATUS_USAGE); /* exit point */
 }
Signature · 1 line
1.7.3.4
#1 lore raw
Quoted 8 lines · Alon Bar-Lev

If configure is located at git repository, acquire branch and revision of head to be printed at --version output.

---
 configure.ac          |   11 +++++++++++
 src/openvpn/options.c |    3 +++

 2 files changed, 14 insertions(+), 0 deletions(-)

David,

Check if this meets your requirement.
It won't survive make dist, but if compiled directly from repository the HEAD will be visible.
Surviving make dist is doable if some file is generated, but this file will stay the same even if there are local modifications... So I don't think it worth both the effort and the confusion.

Alon.

#2 lore raw
In reply to Alon Bar-Lev

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 6 lines · Alon Bar-Lev

If configure is located at git repository, acquire branch and revision of head to be printed at --version output.

configure.ac | 11 +++++++++++ src/openvpn/options.c |
3 +++ 2 files changed, 14 insertions(+), 0 deletions(-)

This is definitely a step in the right direction. However, it depends on ./configure being run to get the updated git revision set. When developing and testing out changes, you don't always need to run ./configure for each build. Thus this may provide a false reference.

Let me explain more carefully:

  $ ./configure
  $ make
  (test src/openvpn/openvpn)
  (hack more on source files in src/openvpn)
  $ make
  (test src/openvpn/openvpn)
  $ src/openvpn/openvpn src/openvpn/openvpn-test1
  (hack more on source files in src/openvpn)
  $ make
  (test src/openvpn/openvpn and compare against openvpn-test1)

If doing such an iteration over a day or two or maybe weeks (which is not uncommon for me, as I don't have time to dig into OpenVPN every day), the git revision reference provided with your patch will not help me much. And as I also work across several branches, testing different approaches for the same issue, I would need far better overview over what's git HEAD of 'make' and not the 'configure' run.

What I would like to see is something more like what's found in TOR projects' obfsproxy, where the Makefile generates a micro-version.i, which is included. As this file is forced to be (re-)created each time, it will always be accurate.

I don't say that obfsproxy have done the implementation correct, but it can at least be a seed for inspiration:

Makefile.am part:
<https://gitweb.torproject.org/obfsproxy.git/blob/94ebc4c3edf1e3e5f313444e59981ac557578df5:/Makefile.am#l106>

main.c parts:
<https://gitweb.torproject.org/obfsproxy.git/blob/94ebc4c3edf1e3e5f313444e59981ac557578df5:/src/main.c#l38>
<https://gitweb.torproject.org/obfsproxy.git/blob/94ebc4c3edf1e3e5f313444e59981ac557578df5:/src/main.c#l57>

Otherwise, that this git revision is not available when doing 'make dist' is no problem. In fact, that's fairly reasonable, as an official release is far easier to track back to a concrete commit.

kind regards,

David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk+iOakACgkQDC186MBRfrp1ZQCfZwJ740HBH2wGOEK5lAEt2681 W/gAoKHlGzxG124aj+CrK6uqsjCEcqvc
=lCZv
-----END PGP SIGNATURE-----

#3 lore raw

Hi,

2012/5/3 David Sommerseth <[email protected]...>:

Quoted 7 lines

What I would like to see is something more like what's found in TOR projects' obfsproxy, where the Makefile generates a micro-version.i, which is included.  As this file is forced to be (re-)created each time, it will always be accurate.

I don't say that obfsproxy have done the implementation correct, but it can at least be a seed for inspiration:

I agree that the Makefile-based approach is more useful. Regarding the
implementation: Depending on compile vs link time it might be faster to move the re-compiled part into a dedicated version.c which only contains a

  const char *get_ovpn_version()
  {
    return PACKAGE_VERSION_EXTRA_GIT_REVISION;
  }

Cheers
Fabian

#4 lore raw

PATCH 1/1 build: add git revision to --version output if build from git repository

In reply to David Sommerseth

If source is located at git repository, acquire branch and revision of head to be printed at --version output.

---
 Makefile.am           |   25 ++++++++++++++++++++++++-
 configure.ac          |   11 +++++++++++
 src/openvpn/options.c |    6 ++++++
 3 files changed, 41 insertions(+), 1 deletions(-)
Makefile.am +24 -1
index ab3e3d2..d6dc2c5 100644
@@ -40,11 +40,18 @@ MAINTAINERCLEANFILES = \
 	$(srcdir)/depcomp $(srcdir)/aclocal.m4 \
 	$(srcdir)/config.guess $(srcdir)/config.sub
 
+CLEANFILES = \
+	config-version.h
+
 EXTRA_DIST = \
 	contrib \
 	debug
 
-SUBDIRS = build distro include src sample doc tests
+if GIT_CHECKOUT
+.PHONY: config-version.h
+endif
+
+SUBDIRS = . build distro include src sample doc tests
 
 dist_doc_DATA = \
 	COPYRIGHT.GPL \
@@ -53,6 +60,7 @@ dist_doc_DATA = \
 dist_noinst_DATA = \
 	.gitignore \
 	.gitattributes \
+	config-version.h.in \
 	PORTS \
 	README.IPv6 TODO.IPv6 \
 	README.polarssl \
@@ -75,3 +83,18 @@ if WIN32
 rootdir=$(prefix)
 root_DATA = version.sh
 endif
+
+if GIT_CHECKOUT
+nodist_noinst_HEADERS = \
+	config-version.h
+config-version.h:
+	@PACKAGE_VERSION_EXTRA_GIT_REVISION="`GIT_DIR=\"$(top_srcdir)/.git\" $(GIT) rev-parse --symbolic-full-name HEAD`/`GIT_DIR=\"$(top_srcdir)/.git\" $(GIT) rev-parse --short=16 HEAD`"; \
+		sed "s#@PACKAGE_VERSION_EXTRA_GIT_REVISION[@]#$${PACKAGE_VERSION_EXTRA_GIT_REVISION}#g" "$(srcdir)/config-version.h.in" > config-version.h.tmp
+	@if ! [ -f config-version.h ] || ! cmp -s config-version.h.tmp config-version.h; then \
+		echo "replacing config-version.h"; \
+		mv config-version.h.tmp config-version.h; \
+	else \
+		rm config-version.h.tmp; \
+	fi
+endif
+
configure.ac +11 -0
index 399b4e7..dd94522 100644
@@ -307,11 +307,13 @@ AC_ARG_VAR([ROUTE], [full path to route utility])
 AC_ARG_VAR([IPROUTE], [full path to ip utility])
 AC_ARG_VAR([NETSTAT], [path to netstat utility]) # tests
 AC_ARG_VAR([MAN2HTML], [path to man2html utility])
+AC_ARG_VAR([GIT], [path to git utility])
 AC_PATH_PROGS([IFCONFIG], [ifconfig],, [$PATH:/usr/local/sbin:/usr/sbin:/sbin])
 AC_PATH_PROGS([ROUTE], [route],, [$PATH:/usr/local/sbin:/usr/sbin:/sbin])
 AC_PATH_PROGS([IPROUTE], [ip],, [$PATH:/usr/local/sbin:/usr/sbin:/sbin])
 AC_CHECK_PROGS([NETSTAT], [netstat], [netstat], [$PATH:/usr/local/sbin:/usr/sbin:/sbin:/etc]) # tests
 AC_CHECK_PROGS([MAN2HTML], [man2html])
+AC_CHECK_PROGS([GIT], [git]) # optional
 AC_DEFINE_UNQUOTED([IFCONFIG_PATH], ["$IFCONFIG"], [Path to ifconfig tool])
 AC_DEFINE_UNQUOTED([IPROUTE_PATH], ["$IPROUTE"], [Path to iproute tool])
 AC_DEFINE_UNQUOTED([ROUTE_PATH], ["$ROUTE"], [Path to route tool])
@@ -781,6 +783,14 @@ PKG_CHECK_MODULES(
 	[]
 )
 
+AC_MSG_CHECKING([git checkout])
+GIT_CHECKOUT="no"
+if test -n "${GIT}" -a -d "${srcdir}/.git"; then
+	AC_DEFINE([HAVE_CONFIG_VERSION_H], [1], [extra version available in config-version.h])
+	GIT_CHECKOUT="yes"
+fi
+AC_MSG_RESULT([${GIT_CHECKOUT}])
+
 if test -n "${SP_PLATFORM_WINDOWS}"; then
 	AC_DEFINE_UNQUOTED([PATH_SEPARATOR], ['\\\\'], [Path separator]) #"
 	AC_DEFINE_UNQUOTED([PATH_SEPARATOR_STR], ["\\\\"], [Path separator]) #"
@@ -928,6 +938,7 @@ AC_SUBST([OPTIONAL_PKCS11_HELPER_CFLAGS])
 AC_SUBST([OPTIONAL_PKCS11_HELPER_LIBS])
 
 AM_CONDITIONAL([WIN32], [test "${WIN32}" = "yes"])
+AM_CONDITIONAL([GIT_CHECKOUT], [test "${GIT_CHECKOUT}" = "yes"])
 
 sampledir="\$(docdir)/sample"
 AC_SUBST([sampledir])
src/openvpn/options.c +6 -0
index 019be57..3717137 100644
@@ -35,6 +35,9 @@
 #elif defined(_MSC_VER)
 #include "config-msvc.h"
 #endif
+#ifdef HAVE_CONFIG_VERSION_H
+#include "config-version.h"
+#endif
 
 #include "syshead.h"
 
@@ -3430,6 +3433,9 @@ usage_version (void)
 #ifdef CONFIGURE_DEFINES
   msg (M_INFO|M_NOPREFIX, "Compile time defines: %s", CONFIGURE_DEFINES);
 #endif
+#ifdef PACKAGE_VERSION_EXTRA_GIT_REVISION
+  msg (M_INFO|M_NOPREFIX, "git revision: %s", PACKAGE_VERSION_EXTRA_GIT_REVISION);
+#endif
 #endif
   openvpn_exit (OPENVPN_EXIT_STATUS_USAGE); /* exit point */
 }
Signature · 1 line
1.7.3.4
#5 lore raw
Quoted 4 lines · Alon Bar-Lev

If source is located at git repository, acquire branch and revision of head to be printed at --version output.

Slowly I get what you need.
How is this one?

Alon.

#6 lore raw

PATCH 1/1 build: add git revision to --version output if build from git repository

In reply to David Sommerseth

If source is located at git repository, acquire branch and revision of head to be printed at --version output.

---
 Makefile.am           |   25 ++++++++++++++++++++++++-
 configure.ac          |   11 +++++++++++
 src/openvpn/options.c |    6 ++++++
 3 files changed, 41 insertions(+), 1 deletions(-)
Makefile.am +24 -1
index ab3e3d2..d6dc2c5 100644
@@ -40,11 +40,18 @@ MAINTAINERCLEANFILES = \
 	$(srcdir)/depcomp $(srcdir)/aclocal.m4 \
 	$(srcdir)/config.guess $(srcdir)/config.sub
 
+CLEANFILES = \
+	config-version.h
+
 EXTRA_DIST = \
 	contrib \
 	debug
 
-SUBDIRS = build distro include src sample doc tests
+if GIT_CHECKOUT
+.PHONY: config-version.h
+endif
+
+SUBDIRS = . build distro include src sample doc tests
 
 dist_doc_DATA = \
 	COPYRIGHT.GPL \
@@ -53,6 +60,7 @@ dist_doc_DATA = \
 dist_noinst_DATA = \
 	.gitignore \
 	.gitattributes \
+	config-version.h.in \
 	PORTS \
 	README.IPv6 TODO.IPv6 \
 	README.polarssl \
@@ -75,3 +83,18 @@ if WIN32
 rootdir=$(prefix)
 root_DATA = version.sh
 endif
+
+if GIT_CHECKOUT
+nodist_noinst_HEADERS = \
+	config-version.h
+config-version.h:
+	@PACKAGE_VERSION_EXTRA_GIT_REVISION="`GIT_DIR=\"$(top_srcdir)/.git\" $(GIT) rev-parse --symbolic-full-name HEAD`/`GIT_DIR=\"$(top_srcdir)/.git\" $(GIT) rev-parse --short=16 HEAD`"; \
+		sed "s#@PACKAGE_VERSION_EXTRA_GIT_REVISION[@]#$${PACKAGE_VERSION_EXTRA_GIT_REVISION}#g" "$(srcdir)/config-version.h.in" > config-version.h.tmp
+	@if ! [ -f config-version.h ] || ! cmp -s config-version.h.tmp config-version.h; then \
+		echo "replacing config-version.h"; \
+		mv config-version.h.tmp config-version.h; \
+	else \
+		rm config-version.h.tmp; \
+	fi
+endif
+
configure.ac +11 -0
index 399b4e7..dd94522 100644
@@ -307,11 +307,13 @@ AC_ARG_VAR([ROUTE], [full path to route utility])
 AC_ARG_VAR([IPROUTE], [full path to ip utility])
 AC_ARG_VAR([NETSTAT], [path to netstat utility]) # tests
 AC_ARG_VAR([MAN2HTML], [path to man2html utility])
+AC_ARG_VAR([GIT], [path to git utility])
 AC_PATH_PROGS([IFCONFIG], [ifconfig],, [$PATH:/usr/local/sbin:/usr/sbin:/sbin])
 AC_PATH_PROGS([ROUTE], [route],, [$PATH:/usr/local/sbin:/usr/sbin:/sbin])
 AC_PATH_PROGS([IPROUTE], [ip],, [$PATH:/usr/local/sbin:/usr/sbin:/sbin])
 AC_CHECK_PROGS([NETSTAT], [netstat], [netstat], [$PATH:/usr/local/sbin:/usr/sbin:/sbin:/etc]) # tests
 AC_CHECK_PROGS([MAN2HTML], [man2html])
+AC_CHECK_PROGS([GIT], [git]) # optional
 AC_DEFINE_UNQUOTED([IFCONFIG_PATH], ["$IFCONFIG"], [Path to ifconfig tool])
 AC_DEFINE_UNQUOTED([IPROUTE_PATH], ["$IPROUTE"], [Path to iproute tool])
 AC_DEFINE_UNQUOTED([ROUTE_PATH], ["$ROUTE"], [Path to route tool])
@@ -781,6 +783,14 @@ PKG_CHECK_MODULES(
 	[]
 )
 
+AC_MSG_CHECKING([git checkout])
+GIT_CHECKOUT="no"
+if test -n "${GIT}" -a -d "${srcdir}/.git"; then
+	AC_DEFINE([HAVE_CONFIG_VERSION_H], [1], [extra version available in config-version.h])
+	GIT_CHECKOUT="yes"
+fi
+AC_MSG_RESULT([${GIT_CHECKOUT}])
+
 if test -n "${SP_PLATFORM_WINDOWS}"; then
 	AC_DEFINE_UNQUOTED([PATH_SEPARATOR], ['\\\\'], [Path separator]) #"
 	AC_DEFINE_UNQUOTED([PATH_SEPARATOR_STR], ["\\\\"], [Path separator]) #"
@@ -928,6 +938,7 @@ AC_SUBST([OPTIONAL_PKCS11_HELPER_CFLAGS])
 AC_SUBST([OPTIONAL_PKCS11_HELPER_LIBS])
 
 AM_CONDITIONAL([WIN32], [test "${WIN32}" = "yes"])
+AM_CONDITIONAL([GIT_CHECKOUT], [test "${GIT_CHECKOUT}" = "yes"])
 
 sampledir="\$(docdir)/sample"
 AC_SUBST([sampledir])
src/openvpn/options.c +6 -0
index 019be57..3717137 100644
@@ -35,6 +35,9 @@
 #elif defined(_MSC_VER)
 #include "config-msvc.h"
 #endif
+#ifdef HAVE_CONFIG_VERSION_H
+#include "config-version.h"
+#endif
 
 #include "syshead.h"
 
@@ -3430,6 +3433,9 @@ usage_version (void)
 #ifdef CONFIGURE_DEFINES
   msg (M_INFO|M_NOPREFIX, "Compile time defines: %s", CONFIGURE_DEFINES);
 #endif
+#ifdef PACKAGE_VERSION_EXTRA_GIT_REVISION
+  msg (M_INFO|M_NOPREFIX, "git revision: %s", PACKAGE_VERSION_EXTRA_GIT_REVISION);
+#endif
 #endif
   openvpn_exit (OPENVPN_EXIT_STATUS_USAGE); /* exit point */
 }
Signature · 1 line
1.7.3.4
#7 lore raw
Quoted 7 lines · Alon Bar-Lev

If source is located at git repository, acquire branch and revision of head to be printed at --version output.

|   25 ++++++++++++++++++++++++- configure.ac          |   11
+++++++++++ src/openvpn/options.c |    6 ++++++ 3 files changed, 41

insertions(+), 1 deletions(-)

Just a detail ... but isn't config-version.h.in lacking? Haven't tested it yet, just read through the patch - so I might have overlooked something.

But this looks far closer to what I'd like from such a feature. Thanks for poking into this!

kind regards,

David Sommerseth

#8 lore raw
Quoted 13 lines · David Sommerseth
Quoted 7 lines · Alon Bar-Lev

If source is located at git repository, acquire branch and revision of head to be printed at --version output.

|   25 ++++++++++++++++++++++++- configure.ac          |   11
+++++++++++ src/openvpn/options.c |    6 ++++++ 3 files changed, 41

insertions(+), 1 deletions(-)

Just a detail ... but isn't config-version.h.in lacking?  Haven't tested it yet, just read through the patch - so I might have overlooked something.

Quoted 7 lines

But this looks far closer to what I'd like from such a feature. Thanks for poking into this!

kind regards,

David Sommerseth

Right!
I was way too tired!
Sorry.

Alon.

#9 lore raw

PATCH 1/1 build: add git revision to --version output if build from git repository

If source is located at git repository, acquire branch and revision of head to be printed at --version output.

---
 .gitignore            |    1 +
 Makefile.am           |   21 +++++++++++++++++++++
 compat.m4             |    5 +++++
 config-version.h.in   |    1 +
 configure.ac          |   12 ++++++++++++
 src/openvpn/options.c |    6 ++++++
 6 files changed, 46 insertions(+), 0 deletions(-)
 create mode 100644 config-version.h.in
.gitignore +1 -0
index 60b9433..9f546a3 100644
@@ -49,3 +49,4 @@ doc/openvpn.8.html
 distro/rpm/openvpn.spec
 tests/t_client.sh
 src/openvpn/openvpn
+config-version.h
Makefile.am +21 -0
index ab3e3d2..f3567f6 100644
@@ -40,10 +40,20 @@ MAINTAINERCLEANFILES = \
 	$(srcdir)/depcomp $(srcdir)/aclocal.m4 \
 	$(srcdir)/config.guess $(srcdir)/config.sub
 
+CLEANFILES = \
+	config-version.h
+
 EXTRA_DIST = \
 	contrib \
 	debug
 
+.PHONY: config-version.h
+
+if GIT_CHECKOUT
+BUILT_SOURCES = \
+	config-version.h
+endif
+
 SUBDIRS = build distro include src sample doc tests
 
 dist_doc_DATA = \
@@ -53,6 +63,7 @@ dist_doc_DATA = \
 dist_noinst_DATA = \
 	.gitignore \
 	.gitattributes \
+	config-version.h.in \
 	PORTS \
 	README.IPv6 TODO.IPv6 \
 	README.polarssl \
@@ -75,3 +86,13 @@ if WIN32
 rootdir=$(prefix)
 root_DATA = version.sh
 endif
+
+config-version.h:
+	@PACKAGE_VERSION_EXTRA_GIT_REVISION="`GIT_DIR=\"$(top_srcdir)/.git\" $(GIT) rev-parse --symbolic-full-name HEAD`/`GIT_DIR=\"$(top_srcdir)/.git\" $(GIT) rev-parse --short=16 HEAD`"; \
+		$(SED) "s#@PACKAGE_VERSION_EXTRA_GIT_REVISION[@]#$${PACKAGE_VERSION_EXTRA_GIT_REVISION}#g" "$(srcdir)/config-version.h.in" > config-version.h.tmp
+	@if ! [ -f config-version.h ] || ! cmp -s config-version.h.tmp config-version.h; then \
+		echo "replacing config-version.h"; \
+		mv config-version.h.tmp config-version.h; \
+	else \
+		rm -f config-version.h.tmp; \
+	fi
compat.m4 +5 -0
index d5c01f7..4c13254 100644
@@ -43,6 +43,11 @@ ifdef(
 	[AC_DEFUN([AC_USE_SYSTEM_EXTENSIONS], [GNU_SOURCE])]
 )
 ifdef(
+	[AC_PROG_SED],
+	,
+	[AC_DEFUN([AC_PROG_SED], [AC_CHECK_PROGS([SED], [sed])])]
+)
+ifdef(
 	[AC_TYPE_INT8_T],
 	,
 	[
config-version.h.in new file +1 -0
new file mode 100644
index 0000000..dd68c18
@@ -0,0 +1 @@
+#define PACKAGE_VERSION_EXTRA_GIT_REVISION "@PACKAGE_VERSION_EXTRA_GIT_REVISION@"
configure.ac +12 -0
index 399b4e7..d2851f6 100644
@@ -300,6 +300,7 @@ PKG_PROG_PKG_CONFIG
 AC_PROG_CPP
 AC_PROG_INSTALL
 AC_PROG_LN_S
+AC_PROG_SED
 AC_PROG_MAKE_SET
 
 AC_ARG_VAR([IFCONFIG], [full path to ipconfig utility])
@@ -307,11 +308,13 @@ AC_ARG_VAR([ROUTE], [full path to route utility])
 AC_ARG_VAR([IPROUTE], [full path to ip utility])
 AC_ARG_VAR([NETSTAT], [path to netstat utility]) # tests
 AC_ARG_VAR([MAN2HTML], [path to man2html utility])
+AC_ARG_VAR([GIT], [path to git utility])
 AC_PATH_PROGS([IFCONFIG], [ifconfig],, [$PATH:/usr/local/sbin:/usr/sbin:/sbin])
 AC_PATH_PROGS([ROUTE], [route],, [$PATH:/usr/local/sbin:/usr/sbin:/sbin])
 AC_PATH_PROGS([IPROUTE], [ip],, [$PATH:/usr/local/sbin:/usr/sbin:/sbin])
 AC_CHECK_PROGS([NETSTAT], [netstat], [netstat], [$PATH:/usr/local/sbin:/usr/sbin:/sbin:/etc]) # tests
 AC_CHECK_PROGS([MAN2HTML], [man2html])
+AC_CHECK_PROGS([GIT], [git]) # optional
 AC_DEFINE_UNQUOTED([IFCONFIG_PATH], ["$IFCONFIG"], [Path to ifconfig tool])
 AC_DEFINE_UNQUOTED([IPROUTE_PATH], ["$IPROUTE"], [Path to iproute tool])
 AC_DEFINE_UNQUOTED([ROUTE_PATH], ["$ROUTE"], [Path to route tool])
@@ -781,6 +784,14 @@ PKG_CHECK_MODULES(
 	[]
 )
 
+AC_MSG_CHECKING([git checkout])
+GIT_CHECKOUT="no"
+if test -n "${GIT}" -a -d "${srcdir}/.git"; then
+	AC_DEFINE([HAVE_CONFIG_VERSION_H], [1], [extra version available in config-version.h])
+	GIT_CHECKOUT="yes"
+fi
+AC_MSG_RESULT([${GIT_CHECKOUT}])
+
 if test -n "${SP_PLATFORM_WINDOWS}"; then
 	AC_DEFINE_UNQUOTED([PATH_SEPARATOR], ['\\\\'], [Path separator]) #"
 	AC_DEFINE_UNQUOTED([PATH_SEPARATOR_STR], ["\\\\"], [Path separator]) #"
@@ -928,6 +939,7 @@ AC_SUBST([OPTIONAL_PKCS11_HELPER_CFLAGS])
 AC_SUBST([OPTIONAL_PKCS11_HELPER_LIBS])
 
 AM_CONDITIONAL([WIN32], [test "${WIN32}" = "yes"])
+AM_CONDITIONAL([GIT_CHECKOUT], [test "${GIT_CHECKOUT}" = "yes"])
 
 sampledir="\$(docdir)/sample"
 AC_SUBST([sampledir])
src/openvpn/options.c +6 -0
index 019be57..3717137 100644
@@ -35,6 +35,9 @@
 #elif defined(_MSC_VER)
 #include "config-msvc.h"
 #endif
+#ifdef HAVE_CONFIG_VERSION_H
+#include "config-version.h"
+#endif
 
 #include "syshead.h"
 
@@ -3430,6 +3433,9 @@ usage_version (void)
 #ifdef CONFIGURE_DEFINES
   msg (M_INFO|M_NOPREFIX, "Compile time defines: %s", CONFIGURE_DEFINES);
 #endif
+#ifdef PACKAGE_VERSION_EXTRA_GIT_REVISION
+  msg (M_INFO|M_NOPREFIX, "git revision: %s", PACKAGE_VERSION_EXTRA_GIT_REVISION);
+#endif
 #endif
   openvpn_exit (OPENVPN_EXIT_STATUS_USAGE); /* exit point */
 }
Signature · 1 line
1.7.3.4
#10 lore raw
Quoted 11 lines · Alon Bar-Lev

If source is located at git repository, acquire branch and revision of head to be printed at --version output.

---
 .gitignore            |    1 +
 Makefile.am           |   21 +++++++++++++++++++++ compat.m4             |    5 +++++ config-version.h.in   |    1 + configure.ac          |   12 ++++++++++++ src/openvpn/options.c |    6 ++++++

Quoted 2 lines
 6 files changed, 46 insertions(+), 0 deletions(-)

 create mode 100644 config-version.h.in

David,
This should be complete, even simpler than the original. Alon.

#11 lore raw

PATCH 1/2 build: add git revision to --version output if build from git repository

If source is located at git repository, acquire branch and revision of head to be printed at --version output.

---
 .gitignore            |    1 +
 Makefile.am           |   21 +++++++++++++++++++++
 compat.m4             |    5 +++++
 config-version.h.in   |    1 +
 configure.ac          |   12 ++++++++++++
 src/openvpn/options.c |    6 ++++++
 6 files changed, 46 insertions(+), 0 deletions(-)
 create mode 100644 config-version.h.in
.gitignore +1 -0
index 60b9433..9f546a3 100644
@@ -49,3 +49,4 @@ doc/openvpn.8.html
 distro/rpm/openvpn.spec
 tests/t_client.sh
 src/openvpn/openvpn
+config-version.h
Makefile.am +21 -0
index ab3e3d2..33dfcd6 100644
@@ -40,10 +40,20 @@ MAINTAINERCLEANFILES = \
 	$(srcdir)/depcomp $(srcdir)/aclocal.m4 \
 	$(srcdir)/config.guess $(srcdir)/config.sub
 
+CLEANFILES = \
+	config-version.h
+
 EXTRA_DIST = \
 	contrib \
 	debug
 
+.PHONY: config-version.h
+
+if GIT_CHECKOUT
+BUILT_SOURCES = \
+	config-version.h
+endif
+
 SUBDIRS = build distro include src sample doc tests
 
 dist_doc_DATA = \
@@ -53,6 +63,7 @@ dist_doc_DATA = \
 dist_noinst_DATA = \
 	.gitignore \
 	.gitattributes \
+	config-version.h.in \
 	PORTS \
 	README.IPv6 TODO.IPv6 \
 	README.polarssl \
@@ -75,3 +86,13 @@ if WIN32
 rootdir=$(prefix)
 root_DATA = version.sh
 endif
+
+config-version.h:
+	@CONFIGURE_GIT_REVISION="`GIT_DIR=\"$(top_srcdir)/.git\" $(GIT) rev-parse --symbolic-full-name HEAD`/`GIT_DIR=\"$(top_srcdir)/.git\" $(GIT) rev-parse --short=16 HEAD`"; \
+		$(SED) "s#@CONFIGURE_GIT_REVISION[@]#$${CONFIGURE_GIT_REVISION}#g" "$(srcdir)/config-version.h.in" > config-version.h.tmp
+	@if ! [ -f config-version.h ] || ! cmp -s config-version.h.tmp config-version.h; then \
+		echo "replacing config-version.h"; \
+		mv config-version.h.tmp config-version.h; \
+	else \
+		rm -f config-version.h.tmp; \
+	fi
compat.m4 +5 -0
index d5c01f7..4c13254 100644
@@ -43,6 +43,11 @@ ifdef(
 	[AC_DEFUN([AC_USE_SYSTEM_EXTENSIONS], [GNU_SOURCE])]
 )
 ifdef(
+	[AC_PROG_SED],
+	,
+	[AC_DEFUN([AC_PROG_SED], [AC_CHECK_PROGS([SED], [sed])])]
+)
+ifdef(
 	[AC_TYPE_INT8_T],
 	,
 	[
config-version.h.in new file +1 -0
new file mode 100644
index 0000000..27ee36a
@@ -0,0 +1 @@
+#define CONFIGURE_GIT_REVISION "@CONFIGURE_GIT_REVISION@"
configure.ac +12 -0
index 399b4e7..d2851f6 100644
@@ -300,6 +300,7 @@ PKG_PROG_PKG_CONFIG
 AC_PROG_CPP
 AC_PROG_INSTALL
 AC_PROG_LN_S
+AC_PROG_SED
 AC_PROG_MAKE_SET
 
 AC_ARG_VAR([IFCONFIG], [full path to ipconfig utility])
@@ -307,11 +308,13 @@ AC_ARG_VAR([ROUTE], [full path to route utility])
 AC_ARG_VAR([IPROUTE], [full path to ip utility])
 AC_ARG_VAR([NETSTAT], [path to netstat utility]) # tests
 AC_ARG_VAR([MAN2HTML], [path to man2html utility])
+AC_ARG_VAR([GIT], [path to git utility])
 AC_PATH_PROGS([IFCONFIG], [ifconfig],, [$PATH:/usr/local/sbin:/usr/sbin:/sbin])
 AC_PATH_PROGS([ROUTE], [route],, [$PATH:/usr/local/sbin:/usr/sbin:/sbin])
 AC_PATH_PROGS([IPROUTE], [ip],, [$PATH:/usr/local/sbin:/usr/sbin:/sbin])
 AC_CHECK_PROGS([NETSTAT], [netstat], [netstat], [$PATH:/usr/local/sbin:/usr/sbin:/sbin:/etc]) # tests
 AC_CHECK_PROGS([MAN2HTML], [man2html])
+AC_CHECK_PROGS([GIT], [git]) # optional
 AC_DEFINE_UNQUOTED([IFCONFIG_PATH], ["$IFCONFIG"], [Path to ifconfig tool])
 AC_DEFINE_UNQUOTED([IPROUTE_PATH], ["$IPROUTE"], [Path to iproute tool])
 AC_DEFINE_UNQUOTED([ROUTE_PATH], ["$ROUTE"], [Path to route tool])
@@ -781,6 +784,14 @@ PKG_CHECK_MODULES(
 	[]
 )
 
+AC_MSG_CHECKING([git checkout])
+GIT_CHECKOUT="no"
+if test -n "${GIT}" -a -d "${srcdir}/.git"; then
+	AC_DEFINE([HAVE_CONFIG_VERSION_H], [1], [extra version available in config-version.h])
+	GIT_CHECKOUT="yes"
+fi
+AC_MSG_RESULT([${GIT_CHECKOUT}])
+
 if test -n "${SP_PLATFORM_WINDOWS}"; then
 	AC_DEFINE_UNQUOTED([PATH_SEPARATOR], ['\\\\'], [Path separator]) #"
 	AC_DEFINE_UNQUOTED([PATH_SEPARATOR_STR], ["\\\\"], [Path separator]) #"
@@ -928,6 +939,7 @@ AC_SUBST([OPTIONAL_PKCS11_HELPER_CFLAGS])
 AC_SUBST([OPTIONAL_PKCS11_HELPER_LIBS])
 
 AM_CONDITIONAL([WIN32], [test "${WIN32}" = "yes"])
+AM_CONDITIONAL([GIT_CHECKOUT], [test "${GIT_CHECKOUT}" = "yes"])
 
 sampledir="\$(docdir)/sample"
 AC_SUBST([sampledir])
src/openvpn/options.c +6 -0
index 7769625..4ee2f31 100644
@@ -35,6 +35,9 @@
 #elif defined(_MSC_VER)
 #include "config-msvc.h"
 #endif
+#ifdef HAVE_CONFIG_VERSION_H
+#include "config-version.h"
+#endif
 
 #include "syshead.h"
 
@@ -3481,6 +3484,9 @@ usage_version (void)
 #ifdef CONFIGURE_DEFINES
   msg (M_INFO|M_NOPREFIX, "Compile time defines: %s", CONFIGURE_DEFINES);
 #endif
+#ifdef CONFIGURE_GIT_REVISION
+  msg (M_INFO|M_NOPREFIX, "git revision: %s", CONFIGURE_GIT_REVISION);
+#endif
 #endif
   openvpn_exit (OPENVPN_EXIT_STATUS_USAGE); /* exit point */
 }
Signature · 1 line
1.7.3.4
#12 lore raw
Quoted 4 lines · Alon Bar-Lev

If source is located at git repository, acquire branch and revision of head to be printed at --version output.

Exactly the same patch, just renamed the variable CONFIGURE_GIT_REVISION to be consistent with next patch and previous configure defs constant name.

Alon.

#13 lore raw
In reply to Alon Bar-Lev
Quoted 4 lines · Alon Bar-Lev

If source is located at git repository, acquire branch and revision of head to be printed at --version output.

Quoted 9 lines
---
 .gitignore            |    1 +
 Makefile.am           |   21 +++++++++++++++++++++
 compat.m4             |    5 +++++
 config-version.h.in   |    1 +
 configure.ac          |   12 ++++++++++++
 src/openvpn/options.c |    6 ++++++
 6 files changed, 46 insertions(+), 0 deletions(-)
 create mode 100644 config-version.h.in

ACK. Applied to master branch.

commit 7046ff20f93eca1d850df43fe716922e6d105c1c

Author: Alon Bar-Lev <[email protected]...>
Date:   Sat May 5 09:39:42 2012 +0300
    build: add git revision to --version output if build from git repository
    
    If source is located at git repository, acquire branch and revision
    of head to be printed at --version output.
    
    Signed-off-by: Alon Bar-Lev <[email protected]...>
    Acked-by: David Sommerseth <[email protected]...>
    Message-Id: [email protected]...
    URL: http://article.gmane.org/gmane.network.openvpn.devel/6431
    Signed-off-by: David Sommerseth <[email protected]...>

kind regards,

David Sommerseth

#14 lore raw

PATCH 2/2 build: add --with-special-build to provide special build string

In reply to Alon Bar-Lev

Special build string is printed when --version is specified.

This is handy when building a snapshot or if not git repository.

---
 configure.ac          |    6 ++++++
 src/openvpn/options.c |    3 +++
 2 files changed, 9 insertions(+), 0 deletions(-)
configure.ac +6 -0
index d2851f6..926a270 100644
@@ -229,6 +229,12 @@ AC_ARG_ENABLE(
 )
 
 AC_ARG_WITH(
+	[special-build],
+	[AS_HELP_STRING([--with-special-build=STRING], [specify special build string])],
+	[AC_DEFINE_UNQUOTED([CONFIGURE_SPECIAL_BUILD], ["${withval}"], [special build string])]
+)
+
+AC_ARG_WITH(
 	[mem-check],
 	[AS_HELP_STRING([--with-mem-check=TYPE], [build with debug memory checking, TYPE=no|dmalloc|valgrind|ssl @<:@default=no@:>@])],
 	[
src/openvpn/options.c +3 -0
index 4ee2f31..9e77463 100644
@@ -3484,6 +3484,9 @@ usage_version (void)
 #ifdef CONFIGURE_DEFINES
   msg (M_INFO|M_NOPREFIX, "Compile time defines: %s", CONFIGURE_DEFINES);
 #endif
+#ifdef CONFIGURE_SPECIAL_BUILD
+  msg (M_INFO|M_NOPREFIX, "special build: %s", CONFIGURE_SPECIAL_BUILD);
+#endif
 #ifdef CONFIGURE_GIT_REVISION
   msg (M_INFO|M_NOPREFIX, "git revision: %s", CONFIGURE_GIT_REVISION);
 #endif
Signature · 1 line
1.7.3.4
#15 lore raw

PATCH 1/1 build: add --with-special-build to provide special build string

Special build string is printed when --version is specified.

Empty = no special build.

This is handy when building a snapshot or if not git repository.

---
 configure.ac          |    6 ++++++
 src/openvpn/options.c |    3 +++
 2 files changed, 9 insertions(+), 0 deletions(-)
configure.ac +6 -0
index d2851f6..e086dd7 100644
@@ -229,6 +229,12 @@ AC_ARG_ENABLE(
 )
 
 AC_ARG_WITH(
+	[special-build],
+	[AS_HELP_STRING([--with-special-build=STRING], [specify special build string])],
+	[test -n "${withval}" && AC_DEFINE_UNQUOTED([CONFIGURE_SPECIAL_BUILD], ["${withval}"], [special build string])]
+)
+
+AC_ARG_WITH(
 	[mem-check],
 	[AS_HELP_STRING([--with-mem-check=TYPE], [build with debug memory checking, TYPE=no|dmalloc|valgrind|ssl @<:@default=no@:>@])],
 	[
src/openvpn/options.c +3 -0
index 4ee2f31..9e77463 100644
@@ -3484,6 +3484,9 @@ usage_version (void)
 #ifdef CONFIGURE_DEFINES
   msg (M_INFO|M_NOPREFIX, "Compile time defines: %s", CONFIGURE_DEFINES);
 #endif
+#ifdef CONFIGURE_SPECIAL_BUILD
+  msg (M_INFO|M_NOPREFIX, "special build: %s", CONFIGURE_SPECIAL_BUILD);
+#endif
 #ifdef CONFIGURE_GIT_REVISION
   msg (M_INFO|M_NOPREFIX, "git revision: %s", CONFIGURE_GIT_REVISION);
 #endif
Signature · 1 line
1.7.3.4
Acked-by on v1 1/1
#16 lore raw

Re: [Openvpn-devel] [PATCH] build: add --with-special-build to provide special build string

Quoted 4 lines · Alon Bar-Lev

Special build string is printed when --version is specified.

Empty = no special build.

Quoted 8 lines

This is handy when building a snapshot or if not git repository.

---
 configure.ac          |    6 ++++++
 src/openvpn/options.c |    3 +++
 2 files changed, 9 insertions(+), 0 deletions(-)

ACK. Applied to master.

commit 10b4b65e0318ce305e05cdec4b44b8f6bcd3915f

Author: Alon Bar-Lev <[email protected]...>
Date:   Sat May 5 11:01:17 2012 +0300

build: add --with-special-build to provide special build string

Special build string is printed when --version is specified.

Empty = no special build.

This is handy when building a snapshot or if not git repository.

Message-Id: [email protected]...
URL: http://article.gmane.org/gmane.network.openvpn.devel/6435

kind regards,

David Sommerseth