From c83c1562320bd914574c4fb7c6138d37a184f30f Mon Sep 17 00:00:00 2001
From: "Peter W. Draper" <p.w.draper@durham.ac.uk>
Date: Tue, 23 Jun 2015 17:09:35 +0100
Subject: [PATCH] Generate the version.h file when git is not available and it
 is still required

This can happen if a zip/tar of the source code is download directly from gitlab


Former-commit-id: 87b39ab3cf4d53a625511937b8bdda5c9b3a9cf1
---
 examples/test.c        | 3 ++-
 examples/test_single.c | 3 +++
 src/Makefile.am        | 7 +++++++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/examples/test.c b/examples/test.c
index 427b761680..2ffeda6e34 100644
--- a/examples/test.c
+++ b/examples/test.c
@@ -573,7 +573,8 @@ int main ( int argc , char *argv[] ) {
 #endif
 
     /* Greeting message */
-    message( "This is %s\n", package_description() );
+    if ( myrank == 0 )
+        message( "This is %s\n", package_description() );
     
     /* Init the space. */
     bzero( &s , sizeof(struct space) );
diff --git a/examples/test_single.c b/examples/test_single.c
index 9387f826ac..76d475a215 100644
--- a/examples/test_single.c
+++ b/examples/test_single.c
@@ -63,6 +63,9 @@ int main ( int argc , char *argv[] ) {
     struct part p1, p2;
     float x, w, dwdx, r2, dx[3] = { 0.0f , 0.0f , 0.0f }, gradw[3];
     
+    /* Greeting message */
+    printf( "This is %s\n", package_description() );
+
     /* Init the particles. */
     for ( k = 0 ; k < 3 ; k++ ) {
         p1.a[k] = 0.0f; p1.v[k] = 0.0f; p1.x[k] = 0.0;
diff --git a/src/Makefile.am b/src/Makefile.am
index f9aa25995a..49ef5e7055 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -58,11 +58,18 @@ libswiftsim_mpi_la_SHORTNAME = mpi
 
 # Versioning. If any sources change then update the version.h file with
 # the current git revision and package version.
+# May have a checkout without a version.h file and no git command (tar/zip
+# download), allow that, but make sure we know it.
 version.h: version.h.in $(AM_SOURCES) $(include_HEADERS) $(noinst_HEADERS)
 	if test "X$(GIT_CMD)" != "X"; then \
 	    GIT_REVISION=`git describe --abbrev=8  --always --tags --dirty`; \
 	    sed -e "s,@PACKAGE_VERSION\@,$(PACKAGE_VERSION)," \
 	        -e "s,@GIT_REVISION\@,$${GIT_REVISION}," version.h.in > version.h; \
+	else \
+	    if test ! -f version.h; then \
+	        sed -e "s,@PACKAGE_VERSION\@,$(PACKAGE_VERSION)," \
+	            -e "s,@GIT_REVISION\@,unknown," version.h.in > version.h; \
+	    fi; \
 	fi
 
 #  Make sure version.h is built first.
-- 
GitLab