From 464d8eee86d806dadd54a3af04abc0a9bd5dbe5c Mon Sep 17 00:00:00 2001
From: astian <astian@eclipso.at>
Date: Wed, 2 Aug 2017 10:46:43 +0000
Subject: [PATCH] build: Fix gresource.xml dependencies generation

shell/Makefile.am was supposed to automatically generate a set of
dependencies for the sources produced from evince.gresource.xml (by way
of "glib-compile-resources --generate-dependencies").  However, the
current implementation was broken (on GNU Make, at least).  It tried to
do this:

  prereq1: $(other_stuff_here)
          ...
  target: prereq1 $(shell filter prereq1)
          ...

Where "filter" is a program that takes "prereq1" and produces a list of
additional prerequisites for "target".

Apparently the intention was for "prereq1" to be updated first, and
then, once "prereq1" has been generated or updated, for "filter" to read
it.  But this doesn't work: first, because the expansion for $(shell
...) happens at the time the rule is parsed; second, because even if the
expansion did occur after the previous prerequisites were updated, it
would still be broken when using parallel recipe execution (-j X).

The implementation in this patch uses a common make pattern instead:
include an auto-generated makefile snippet.

Another problem with the code was that it placed the generated files in
the source directory instead of the build directory.  This was also
fixed.
---
 shell/Makefile.am | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/shell/Makefile.am b/shell/Makefile.am
index 757c8136..092e9d4b 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -75,6 +75,8 @@ evince_SOURCES=				\
 
 nodist_evince_SOURCES = \
 	ev-resources.c \
+	ev-resources.dep \
+	evince.gresource.xml \
 	$(NULL)
 
 if ENABLE_DBUS
@@ -131,7 +133,9 @@ evince-icon.o: $(srcdir)/evince-icon.rc $(top_srcdir)/data/evince.ico
 endif
 
 BUILT_SOURCES = \
-	ev-resources.c
+	ev-resources.c \
+	ev-resources.dep \
+	evince.gresource.xml
 
 if ENABLE_DBUS
 BUILT_SOURCES += \
@@ -176,19 +180,21 @@ EXTRA_DIST = \
 	ev-gdbus.xml \
 	ev-daemon-gdbus.xml
 
-GRESOURCE_XML_IN_FILES = evince.gresource.xml.in
-GRESOURCE_XML_FILE = $(GRESOURCE_XML_IN_FILES:.xml.in=.xml)
-
 if HAVE_GTK_320
 EVINCE_CSS=evince.css
 else
 EVINCE_CSS=evince-3-18.css
 endif
 
-$(GRESOURCE_XML_FILE): $(GRESOURCE_XML_IN_FILES) Makefile
+evince.gresource.xml: evince.gresource.xml.in Makefile
 	$(AM_V_GEN) $(SED) -e "s|\@EVINCE_CSS\@|$(EVINCE_CSS)|" $< > $@
 
-ev-resources.c: $(GRESOURCE_XML_FILE) Makefile $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies --sourcedir=$(srcdir) --sourcedir=$(top_srcdir)/data $(srcdir)/evince.gresource.xml)
+# Generate and include a makefile snippet with additional prerequisites.
+-include ev-resources.dep
+ev-resources.dep: evince.gresource.xml Makefile
+	@echo ev-resources.c: $$($(GLIB_COMPILE_RESOURCES) --generate-dependencies --sourcedir=$(srcdir) --sourcedir=$(top_srcdir)/data $<) > $@
+
+ev-resources.c: evince.gresource.xml Makefile
 	$(AM_V_GEN) XMLLINT=$(XMLLINT) $(GLIB_COMPILE_RESOURCES) --target $@ --sourcedir=$(srcdir) --sourcedir=$(top_srcdir)/data --generate-source --c-name ev $<
 
 ev-gdbus-generated.c ev-gdbus-generated.h: ev-gdbus.xml Makefile
@@ -207,6 +213,6 @@ ev-daemon-gdbus-generated.c ev-daemon-gdbus-generated.h: ev-daemon-gdbus.xml Mak
 			--generate-c-code ev-daemon-gdbus-generated \
 			$<
 
-DISTCLEANFILES = $(BUILT_SOURCES) $(GRESOURCE_XML_FILE)
+DISTCLEANFILES = $(BUILT_SOURCES)
 
 -include $(top_srcdir)/git.mk
-- 
2.13.3

