@@ -38,48 +38,53 @@ define ProcessMarkdown
3838 $1_$2_INPUT_FILE := $3/$2
3939 $1_$2_MARKER := $$(subst /,_,$1_$2)
4040
41- ifneq ($$($1_REPLACEMENTS), )
42- $1_$2_PANDOC_INPUT := $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_pre.tmp
43-
44- $$(eval $$(call SetupTextFileProcessing, $1_$2_PREPROCESSED, \
45- SOURCE_FILES := $$($1_$2_INPUT_FILE), \
46- OUTPUT_FILE := $$($1_$2_PANDOC_INPUT), \
47- REPLACEMENTS := $$($1_REPLACEMENTS), \
48- ))
49- else
50- $1_$2_PANDOC_INPUT := $$($1_$2_INPUT_FILE)
51- endif
52-
53- ifneq ($$($1_POST_PROCESS), )
54- $1_$2_PANDOC_OUTPUT := $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_post.tmp
55- else
56- $1_$2_PANDOC_OUTPUT := $$($1_$2_OUTPUT_FILE)
57- endif
41+ # Only continue if this target file hasn't been processed already. This lets
42+ # the first found source file override any other with the same name.
43+ ifeq ($$($1_$2_OUTPUT_FILE_PROCESSED), )
44+ $1_$2_OUTPUT_FILE_PROCESSED := true
45+
46+ ifneq ($$($1_REPLACEMENTS), )
47+ $1_$2_PANDOC_INPUT := $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_pre.tmp
48+
49+ $$(eval $$(call SetupTextFileProcessing, $1_$2_PREPROCESSED, \
50+ SOURCE_FILES := $$($1_$2_INPUT_FILE), \
51+ OUTPUT_FILE := $$($1_$2_PANDOC_INPUT), \
52+ REPLACEMENTS := $$($1_REPLACEMENTS), \
53+ ))
54+ else
55+ $1_$2_PANDOC_INPUT := $$($1_$2_INPUT_FILE)
56+ endif
5857
59- ifneq ($$($1_CSS), )
60- ifneq ($$(findstring https:/, $$($1_CSS)), )
61- $1_$2_CSS_OPTION := --css '$$($1_CSS)'
58+ ifneq ($$($1_POST_PROCESS), )
59+ $1_$2_PANDOC_OUTPUT := $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_post.tmp
6260 else
63- $1_$2_CSS := $$(strip $$(call RelativePath, $$($1_CSS), $$($1_$2_TARGET_DIR)))
64- $1_$2_CSS_OPTION := --css '$$($1_$2_CSS)'
61+ $1_$2_PANDOC_OUTPUT := $$($1_$2_OUTPUT_FILE)
6562 endif
66- endif
6763
68- # This does not need to be included in VARDEPS since it's from the actual
69- # source file. Only run the shell if the recipe gets executed below.
70- $1_$2_OPTIONS_FROM_SRC = \
71- $$(shell $$(GREP) _pandoc-options_: $3/$2 | $$(CUT) -d : -f 2-)
64+ ifneq ($$($1_CSS), )
65+ ifneq ($$(findstring https:/, $$($1_CSS)), )
66+ $1_$2_CSS_OPTION := --css '$$($1_CSS)'
67+ else
68+ $1_$2_CSS := $$(strip $$(call RelativePath, $$($1_CSS), $$($1_$2_TARGET_DIR)))
69+ $1_$2_CSS_OPTION := --css '$$($1_$2_CSS)'
70+ endif
71+ endif
7272
73- ifneq ($$($1_FILTER), )
74- $1_$2_OPTIONS := --filter $$($1_FILTER)
75- endif
73+ # This does not need to be included in VARDEPS since it's from the actual
74+ # source file. Only run the shell if the recipe gets executed below.
75+ $1_$2_OPTIONS_FROM_SRC = \
76+ $$(shell $$(GREP) _pandoc-options_: $3/$2 | $$(CUT) -d : -f 2-)
77+
78+ ifneq ($$($1_FILTER), )
79+ $1_$2_OPTIONS := --filter $$($1_FILTER)
80+ endif
7681
77- $1_$2_VARDEPS := $$($1_OPTIONS) $$($1_$2_OPTIONS) $$($1_CSS) \
78- $$($1_REPLACEMENTS) $$($1_POST_PROCESS)
79- $1_$2_VARDEPS_FILE := $$(call DependOnVariable, $1_$2_VARDEPS, \
80- $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER).vardeps)
82+ $1_$2_VARDEPS := $$($1_OPTIONS) $$($1_$2_OPTIONS) $$($1_CSS) \
83+ $$($1_REPLACEMENTS) $$($1_POST_PROCESS)
84+ $1_$2_VARDEPS_FILE := $$(call DependOnVariable, $1_$2_VARDEPS, \
85+ $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER).vardeps)
8186
82- $$($1_$2_PANDOC_OUTPUT): $$($1_$2_PANDOC_INPUT) $$($1_$2_VARDEPS_FILE) $$($1_EXTRA_DEPS)
87+ $$($1_$2_PANDOC_OUTPUT): $$($1_$2_PANDOC_INPUT) $$($1_$2_VARDEPS_FILE) $$($1_EXTRA_DEPS)
8388 $$(call LogInfo, Converting $2 to $$($1_FORMAT))
8489 $$(call MakeDir, $$(SUPPORT_OUTPUTDIR)/markdown $$(dir $$($1_$2_PANDOC_OUTPUT)))
8590 $$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER), \
@@ -96,17 +101,18 @@ define ProcessMarkdown
96101 fi
97102 endif
98103
99- # If we have no post processing, PANDOC_OUTPUT is set to OUTPUT_FILE. Otherwise
100- # PANDOC_OUTPUT is a temporary file, and we must now create the real OUTPUT_FILE.
101- ifneq ($$($1_POST_PROCESS), )
102- $$($1_$2_OUTPUT_FILE): $$($1_$2_PANDOC_OUTPUT)
104+ # If we have no post processing, PANDOC_OUTPUT is set to OUTPUT_FILE. Otherwise
105+ # PANDOC_OUTPUT is a temporary file, and we must now create the real OUTPUT_FILE.
106+ ifneq ($$($1_POST_PROCESS), )
107+ $$($1_$2_OUTPUT_FILE): $$($1_$2_PANDOC_OUTPUT)
103108 $$(call LogInfo, Post-processing markdown file $2)
104109 $$(call MakeDir, $$(SUPPORT_OUTPUTDIR)/markdown $$($1_$2_TARGET_DIR))
105110 $$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_post, \
106111 ( $$($1_POST_PROCESS) $$($1_$2_PANDOC_OUTPUT) > $$($1_$2_OUTPUT_FILE) ) )
107- endif
112+ endif
108113
109- $1 += $$($1_$2_OUTPUT_FILE)
114+ $1 += $$($1_$2_OUTPUT_FILE)
115+ endif
110116endef
111117
112118################################################################################
0 commit comments