about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--Makefile.am67
-rw-r--r--src/main.c2
-rw-r--r--src/profanity.c2
-rw-r--r--src/ui/console.c2
-rw-r--r--src/ui/core.c2
-rw-r--r--src/xmpp/capabilities.c2
-rw-r--r--src/xmpp/iq.c2
8 files changed, 41 insertions, 41 deletions
diff --git a/.gitignore b/.gitignore
index e34cfbfb..763f3903 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,7 +32,8 @@ TODO
 plugins/
 *_key.txt
 *_fingerprints.txt
-src/gitversion.c
+src/gitversion.h
+src/gitversion.h.in
 *_key.txt
 *_fingerprints.txt
 TAGS
diff --git a/Makefile.am b/Makefile.am
index 31280b0c..2be22252 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,17 +1,3 @@
-if INCLUDE_GIT_VERSION
-src/gitversion.c: .git/HEAD .git/index
-	rm -f src/gitversion.c src/gitversion.o
-	echo "#ifndef PROF_GIT_BRANCH" >> $@
-	echo "#define PROF_GIT_BRANCH \"$(shell git rev-parse --symbolic-full-name --abbrev-ref HEAD)\"" >> $@
-	echo "#endif" >> $@
-	echo "#ifndef PROF_GIT_REVISION" >> $@
-	echo "#define PROF_GIT_REVISION \"$(shell git log --pretty=format:'%h' -n 1)\"" >> $@
-	echo "#endif" >> $@
-
-clean-local:
-	rm -f src/gitversion.c src/gitversion.o
-endif
-
 core_sources = \
 	src/contact.c src/contact.h src/log.c src/common.c \
 	src/log.h src/profanity.c src/common.h \
@@ -42,7 +28,7 @@ core_sources = \
 	src/config/preferences.c src/config/preferences.h \
 	src/config/theme.c src/config/theme.h
 
-test_sources = \
+tests_sources = \
 	src/contact.c src/contact.h src/common.c \
 	src/log.h src/profanity.c src/common.h \
 	src/profanity.h src/chat_session.c \
@@ -93,8 +79,7 @@ test_sources = \
 
 main_source = src/main.c
 
-git_sources = \
-	src/gitversion.c
+git_include = src/gitversion.h
 
 otr3_sources = \
 	src/otr/otrlib.h src/otr/otrlibv3.c src/otr/otr.h src/otr/otr.c
@@ -102,34 +87,48 @@ otr3_sources = \
 otr4_sources = \
 	src/otr/otrlib.h src/otr/otrlibv4.c src/otr/otr.h src/otr/otr.c
 
-if INCLUDE_GIT_VERSION
-with_git_sources = $(git_sources) $(core_sources)
-tests_with_git_sources = $(git_sources) $(test_sources)
-else
-with_git_sources = $(core_sources)
-tests_with_git_sources = $(test_sources)
-endif
-
 if BUILD_OTR
 if BUILD_OTR3
-with_otr_sources = $(with_git_sources) $(otr3_sources)
-tests_with_otr_sources = $(tests_with_git_sources) $(otr3_sources)
+core_sources += $(otr3_sources)
+tests_sources += $(otr3_sources)
 endif
 if BUILD_OTR4
-with_otr_sources = $(with_git_sources) $(otr4_sources)
-tests_with_otr_sources = $(tests_with_git_sources) $(otr4_sources)
+core_sources += $(otr4_sources)
+tests_sources += $(otr4_sources)
 endif
-else
-with_otr_sources = $(with_git_sources)
-tests_with_otr_sources = $(tests_with_git_sources)
 endif
 
 bin_PROGRAMS = profanity
-profanity_SOURCES = $(with_otr_sources) $(main_source)
+profanity_SOURCES = $(core_sources) $(main_source)
+if INCLUDE_GIT_VERSION
+BUILT_SOURCES = $(git_include)
+endif
 
 TESTS = tests/testsuite
 check_PROGRAMS = tests/testsuite
-tests_testsuite_SOURCES = $(tests_with_otr_sources)
+tests_testsuite_SOURCES = $(tests_sources)
 tests_testsuite_LDADD = -lcmocka
 
 man_MANS = docs/profanity.1
+
+if INCLUDE_GIT_VERSION
+$(git_include).in: .git/HEAD .git/index
+	rm -f $@
+	echo "#ifndef PROF_GIT_BRANCH" >> $@
+	echo "#define PROF_GIT_BRANCH \"$(shell git rev-parse --symbolic-full-name --abbrev-ref HEAD)\"" >> $@
+	echo "#endif" >> $@
+	echo "#ifndef PROF_GIT_REVISION" >> $@
+	echo "#define PROF_GIT_REVISION \"$(shell git log --pretty=format:'%h' -n 1)\"" >> $@
+	echo "#endif" >> $@
+
+#
+# Create $(git_include) atomically to catch possible race. The race can occur
+# when $(git_include) is generated in parallel with building of src/profanity.c.
+# So this hack allows to find and fix the problem earlier.
+#
+$(git_include): $(git_include).in
+	cp $< $@
+
+clean-local:
+	rm -f $(git_include) $(git_include).in
+endif
diff --git a/src/main.c b/src/main.c
index 7796ed96..1c9e7926 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,7 +24,7 @@
 
 #include "config.h"
 #ifdef HAVE_GIT_VERSION
-#include "gitversion.c"
+#include "gitversion.h"
 #endif
 
 #include "profanity.h"
diff --git a/src/profanity.c b/src/profanity.c
index c1a9aa9d..e68cec1a 100644
--- a/src/profanity.c
+++ b/src/profanity.c
@@ -22,7 +22,7 @@
 #include "config.h"
 
 #ifdef HAVE_GIT_VERSION
-#include "gitversion.c"
+#include "gitversion.h"
 #endif
 
 #include <locale.h>
diff --git a/src/ui/console.c b/src/ui/console.c
index e37516aa..64f0e990 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -41,7 +41,7 @@
 #include "xmpp/bookmark.h"
 
 #ifdef HAVE_GIT_VERSION
-#include "gitversion.c"
+#include "gitversion.h"
 #endif
 
 static void _cons_splash_logo(void);
diff --git a/src/ui/core.c b/src/ui/core.c
index d0451346..740e5f6f 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -23,7 +23,7 @@
 #include "config.h"
 
 #ifdef HAVE_GIT_VERSION
-#include "gitversion.c"
+#include "gitversion.h"
 #endif
 
 #include <stdlib.h>
diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c
index fc71ae54..3c286ac8 100644
--- a/src/xmpp/capabilities.c
+++ b/src/xmpp/capabilities.c
@@ -23,7 +23,7 @@
 #include "config.h"
 
 #ifdef HAVE_GIT_VERSION
-#include "gitversion.c"
+#include "gitversion.h"
 #endif
 
 #include <stdlib.h>
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index 3766d2c4..7c8a61c4 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -23,7 +23,7 @@
 #include "config.h"
 
 #ifdef HAVE_GIT_VERSION
-#include "gitversion.c"
+#include "gitversion.h"
 #endif
 
 #include <stdlib.h>