I was trying to achieve something similar as the OP; I wanted to embed Git commit-id in Postgres version string. The code in Postgres' configure.in, in the same line that I intended to modify, already had an example.
The gist of it is that you can embed shell snippet in string literals in configure.in
, and the resulting configure
file (the shell executing the shell script, actually) will always execute that shell snippet to build the resultant string.
Please see the patch. Following are the patches to configure.in
and relevant section from resulting configure
file.
AC_DEFINE_UNQUOTED(PG_VERSION_STR,
- ["PostgreSQL $PACKAGE_VERSION on $host, compiled by $cc_string, `expr $ac_cv_sizeof_void_p \* 8`-bit"],
+ ["PostgreSQL $PACKAGE_VERSION (commit `cd $srcdir && git log -1 --format=format:%h`) on $host, compiled by $cc_string, `expr $ac_cv_sizeof_void_p \* 8`-bit"],
[A string containing the version number, platform, and C compiler])
Resulting configure
code:
cat >>confdefs.h <<_ACEOF
-#define PG_VERSION_STR "PostgreSQL $PACKAGE_VERSION on $host, compiled by $cc_string, `expr $ac_cv_sizeof_void_p \* 8`-bit"
+#define PG_VERSION_STR "PostgreSQL $PACKAGE_VERSION (commit `cd $srcdir && git log -1 --format=format:%h`) on $host, compiled by $cc_string, `expr $ac_cv_sizeof_void_p \* 8`-bit"
_ACEOF
Postgres version string before and after the patch:
PostgreSQL 9.3.0 on x86_64-unknown-linux-gnu, compiled by ...
PostgreSQL 9.3.0 (commit 2cf9dac) on x86_64-unknown-linux-gnu, compiled by ...