--- a/make/common/ProcessMarkdown.gmk Mon Nov 26 14:18:32 2018 +0100
+++ b/make/common/ProcessMarkdown.gmk Mon Nov 26 18:50:55 2018 +0100
@@ -30,11 +30,12 @@
# Helper function for SetupProcessMarkdown
# $1: The $1 from SetupProcessMarkdown
-# $2: The name of the current source file, relative to $1_SRC
+# $2: The name of the current source file, relative to the dir given in $3
+# $3: The directory of the current source file
define ProcessMarkdown
$1_$2_OUTPUT_FILE := $$($1_DEST)/$$(basename $2)$$($1_FILE_EXT)
$1_$2_TARGET_DIR := $$(dir $$($1_$2_OUTPUT_FILE))
- $1_$2_INPUT_FILE := $$($1_SRC)/$2
+ $1_$2_INPUT_FILE := $3/$2
$1_$2_MARKER := $$(subst /,_,$1_$2)
ifneq ($$($1_REPLACEMENTS), )
@@ -64,7 +65,7 @@
endif
endif
- $1_$2_OPTIONS := $$(shell $$(GREP) _pandoc-options_: $$($1_SRC)/$2 | $$(CUT) -d : -f 2-)
+ $1_$2_OPTIONS := $$(shell $$(GREP) _pandoc-options_: $3/$2 | $$(CUT) -d : -f 2-)
ifneq ($$($1_FILTER), )
$1_$2_OPTIONS += --filter $$($1_FILTER)
@@ -111,10 +112,10 @@
# and the targets generated are listed in a variable by that name.
#
# Remaining parameters are named arguments. These include:
-# SRC : Source root dir (defaults to dir of first file)
-# DEST : Dest root dir
+# DEST : Destination root dir
# FILES : List of files to copy with absolute paths, or path relative to SRC.
-# Must be in SRC.
+# SRC : Source root dir; if given keep input files hierarchy relative to
+# SRC in DEST, otherwise flatten structure into DEST.
# FORMAT : The target format (defaults to html5)
# FILE_EXT : The file extension to replace .md with (defaults to .html)
# OPTIONS : Additional options to pandoc
@@ -133,11 +134,6 @@
$$(error DEST is missing in SetupProcessMarkdown $1)
endif
- # Default SRC to the dir of the first file.
- ifeq ($$($1_SRC), )
- $1_SRC := $$(dir $$(firstword $$($1_FILES)))
- endif
-
# If no target format is specified, default to html5.
ifeq ($$($1_FORMAT), )
$1_FORMAT := html5
@@ -158,11 +154,23 @@
endif
endif
- # Remove any trailing slash from SRC and DEST
- $1_SRC := $$(patsubst %/,%,$$($1_SRC))
+ # Remove any trailing slash
$1_DEST := $$(patsubst %/,%,$$($1_DEST))
- $$(foreach f, $$(patsubst $$($1_SRC)/%,%,$$($1_FILES)), \
- $$(eval $$(call ProcessMarkdown,$1,$$f)) \
- )
+ ifeq ($$($1_SRC), )
+ # No SRC given, assume we're flattening all files into output dir.
+ $$(foreach f, $$($1_FILES), \
+ $$(eval $$(call ProcessMarkdown,$1,$$(notdir $$f),$$(patsubst %/,%,$$(dir $$f)))) \
+ )
+ else
+ # Remove any trailing slash
+ $1_SRC := $$(patsubst %/,%,$$($1_SRC))
+
+ $$(foreach f, $$(patsubst $$($1_SRC)/%,%,$$($1_FILES)), \
+ $$(eval $$(call ProcessMarkdown,$1,$$f,$$($1_SRC))) \
+ )
+ endif
+
+
+
endef