Searched a bunch, hope I didn't miss something obvious...
I have multiple book directories. Each has a single *.ditamap file (always named for the book) that references several dozen accompanying *.dita topic files:
makefile
book1/
book1.ditamap intro.dita topic1.dita topic2.dita glossary.dita
book2/
book2.ditamap about.dita topicA.dita topicB.dita appendix.dita
book3/
book3.ditamap cmd1.dita cmd2.dita cmd3.dita
The XHTML output (target) for a book depends on its single .ditamap file plus all the *.dita files in that book directory (prerequisites). The makefile is placed alongside the book directories.
Building XHTML for a book creates an output XHTML directory inside that book directory, with an index.html file that I use as the target:
book1/
book1.ditamap intro.dita topic1.dita topic2.dita glossary.dita
book1/book1_xhtml/
index.html ...more html and CSS files...
The following static pattern rule will rebuild the XHTML directory inside any book directory where the *.ditamap file has changed:
ditamap_files := $(wildcard */*.ditamap)
xhtml_files := $(patsubst %.ditamap,%_xhtml/index.html,${ditamap_files})
all: dita xhtml
dita: ${ditamap_files}
xhtml: ${xhtml_files}
${xhtml_files}: %_xhtml/index.html: %.ditamap
dita -i "${<}" -f xhtml -o "${*}_xhtml"
(Side note: make
nicely handles building the path to the index.html target thanks to its clever directory-handling rules!)
However, I haven't found a way to extend this rule to be sensitive to the *.dita files too. Whenever .ditamap or .dita has changed inside the book directory, the book XHTML file must be rebuilt.
I tried stuff like
${xhtml_files}: %_xhtml/index.html: %.ditamap $(wildcard $(dir %)/*.dita)
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^
dita -i "${<}" -f xhtml -o "${*}_xhtml" 2>&1 | tee "${*}_xhtml.out"
but this completely fails to work because wildcards aren't supported in static pattern rules. Somehow I need to collect wildcarded files within the directory of the stem of each target, then make them prerequisites for that book.