ghc.mk: don't run mkUserGuidePart more than once
authorSergei Trofimovich <siarheit@google.com>
Sat, 5 Dec 2015 00:03:05 +0000 (00:03 +0000)
committerSergei Trofimovich <siarheit@google.com>
Sat, 5 Dec 2015 10:17:08 +0000 (10:17 +0000)
When building 'html' and 'man' manuals
build system reports mkUserGuide is ran
more than once (up to 3 times in parallel).

See Note [Blessed make target file] for
more details.

Signed-off-by: Sergei Trofimovich <siarheit@google.com>
utils/mkUserGuidePart/ghc.mk

index 86492e1..3a654da 100644 (file)
@@ -39,11 +39,18 @@ utils/mkUserGuidePart_GENERATED_FLAGS_SETS := \
   verbosity                   \
   warnings
 
-utils/mkUserGuidePart_GENERATED_RST_SOURCES := \
+# See Note [Blessed make target file]
+utils/mkUserGuidePart_GENERATED_RST_SOURCES_BLESSED_FILE := \
+               docs/users_guide/what_glasgow_exts_does.gen.rst
+
+utils/mkUserGuidePart_GENERATED_RST_SOURCES_OTHER_FILES := \
                $(addprefix docs/users_guide/flags-,$(addsuffix .gen.rst,$(utils/mkUserGuidePart_GENERATED_FLAGS_SETS))) \
-               docs/users_guide/what_glasgow_exts_does.gen.rst \
                docs/man/all-flags.gen.rst
 
+utils/mkUserGuidePart_GENERATED_RST_SOURCES := \
+               $(utils/mkUserGuidePart_GENERATED_RST_SOURCES_BLESSED_FILE) \
+               $(utils/mkUserGuidePart_GENERATED_RST_SOURCES_OTHER_FILES)
+
 utils/mkUserGuidePart_USES_CABAL           = YES
 utils/mkUserGuidePart_PACKAGE              = mkUserGuidePart
 utils/mkUserGuidePart_dist_PROGNAME        = mkUserGuidePart
@@ -52,7 +59,36 @@ utils/mkUserGuidePart_dist_INSTALL_INPLACE = YES
 $(eval $(call build-prog,utils/mkUserGuidePart,dist,2))
 $(eval $(call clean-target,utils/mkUserGuidePart,gen,$(utils/mkUserGuidePart_GENERATED_RST_SOURCES)))
 
-$(utils/mkUserGuidePart_GENERATED_RST_SOURCES) : $(mkUserGuidePart_INPLACE)
+$(utils/mkUserGuidePart_GENERATED_RST_SOURCES_OTHER_FILES) :
+
+$(utils/mkUserGuidePart_GENERATED_RST_SOURCES_BLESSED_FILE) : $(utils/mkUserGuidePart_GENERATED_RST_SOURCES_OTHER_FILES) $(mkUserGuidePart_INPLACE)
        $(mkUserGuidePart_INPLACE)
+       $(TOUCH_CMD) $@
 
 all_utils/mkUserGuidePart: $(mkUserGuidePart_INPLACE)
+
+# Note [Blessed make target file]
+#
+# make cannot express nicely a single build rule
+# with multiple targets:
+#
+#   > all: a b
+#   > a b:
+#   >  touch a b
+#
+# This code will run 'touch' rule twice when parallel
+# make is used:
+#   > $ make -j
+#   > touch a b
+#   > touch a b
+#
+# But there is a workaround for it:
+# We pick a single file of a group and depend on it
+# as an ultimate target. We also need to make sure
+# that file has latest timestamp in the group:
+#
+#   > all: a b
+#   > b:
+#   > a: b
+#   >  touch a b
+#   >  touch $@