Skip to content

Commit 89b2d5b

Browse files
authored
Merge pull request #4361 from grandixximo/docs-asciideps-targets
docs(build): name the real target in the generated dependencies
2 parents ae2d0a7 + 5c31ef1 commit 89b2d5b

2 files changed

Lines changed: 71 additions & 18 deletions

File tree

docs/src/Submakefile

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,21 +1088,29 @@ $(DOC_OUT_HTML)/en/pdf/LinuxCNC_Manual_Pages_en.pdf: objects/LinuxCNC_Manual_Pag
10881088
|| (X=$$?; rm -f $@ $@.raw; exit $$X)
10891089
@test -f $@
10901090

1091+
# Target a page's include:: and image: prerequisites hang off. A page is
1092+
# consumed by its .html; a Master document has no HTML, only the PDF that
1093+
# pulls its chapters in, and the English ones render into objects/. Not
1094+
# derivable from the source path, so asciideps is told.
1095+
EN_DEP_TARGET = $(if $(filter Master_%,$*),objects/$*.pdf,$(DOC_OUT_ADOC)/en/$*.html)
1096+
10911097
depends/%.d: $(DOC_OUT_ADOC)/en/%.adoc $(DOC_SRCDIR)/asciideps .include-stamp | stage-en
10921098
$(ECHO) Depending $<
10931099
@mkdir -p $(dir $@)
1094-
$(Q)$(DOC_SRCDIR)/asciideps $< > $@.tmp
1100+
$(Q)$(DOC_SRCDIR)/asciideps $< $(EN_DEP_TARGET) > $@.tmp
10951101
@mv $@.tmp $@
10961102

10971103
# Translated .adoc lives in $(DOC_OUT_ADOC)/<lang>/; same recipe, just a
10981104
# different source dir so the per-language depends/<lang>/X.d targets
10991105
# resolve. The pattern only matches paths starting with a known language
11001106
# tag, so the English depends/%.d above wins for non-translated entries.
1107+
# Translated Master PDFs render beside their source, so unlike English the
1108+
# target is the sibling .pdf.
11011109
define TRANSLATED_DEP_RULE
11021110
depends/$(1)/%.d: $(DOC_OUT_ADOC)/$(1)/%.adoc $(DOC_SRCDIR)/asciideps .include-stamp | stage-en
11031111
$$(ECHO) Depending $$<
11041112
@mkdir -p $$(dir $$@)
1105-
$$(Q)$$(DOC_SRCDIR)/asciideps $$< > $$@.tmp
1113+
$$(Q)$$(DOC_SRCDIR)/asciideps $$< $$(if $$(filter Master_%,$$*),$(DOC_OUT_ADOC)/$(1)/$$*.pdf,$(DOC_OUT_ADOC)/$(1)/$$*.html) > $$@.tmp
11061114
@mv $$@.tmp $$@
11071115
endef
11081116
$(foreach L,$(LANGUAGES),$(eval $(call TRANSLATED_DEP_RULE,$(L))))
@@ -1191,14 +1199,19 @@ $(foreach L,$(LANGUAGES),$(eval $(call HTML_COPY_RULE,$(L))))
11911199
# has no work to do (filter-out yields empty) so we skip the dep too. HTML
11921200
# image placement is no longer done here: the image_resolver rewrites HTML src
11931201
# to the shared pool and .html-images-stamp materialises it.
1202+
#
1203+
# Matched anywhere on the line, like asciideps, so both see the same set.
1204+
# Anchored at the start it missed the 39 inline refs, leaving those images
1205+
# out of the translated PDFs that embed them from here. Keyed on the macro
1206+
# shape, or prose mentioning image:: is taken for a path and the copy fails.
11941207
ifeq ($(BUILD_DOCS_TRANSLATED),yes)
11951208
ADOC_IMAGES_STAMP_DEPS := $(DOC_DIR)/.translateddocs-stamp
11961209
endif
11971210
.adoc-images-stamp: $(ADOC_IMAGES_STAMP_DEPS) $(addprefix $(DOC_OUT_ADOC)/, $(filter-out $(DOC_SRCS_EN), $(DOC_SRCS)))
11981211
set -e; for ADOC_FILE in $(addprefix $(DOC_OUT_ADOC)/, $(filter-out $(DOC_SRCS_EN), $(DOC_SRCS))); do \
11991212
ADOC_DIR=$$(echo $$(dirname $$ADOC_FILE) | sed s%$(DOC_OUT_ADOC)/%% ); \
12001213
echo Processing $$ADOC_FILE, dir $$ADOC_DIR; \
1201-
for IMAGE_FILE in $$(grep -E ^image:[^[:space:]] $$ADOC_FILE | sed -E "s/image:+([^[]+)\[/\nimage:\1\n/g" | grep image: | cut -d: -f2-); do \
1214+
for IMAGE_FILE in $$(grep -v '^[[:space:]]*//' $$ADOC_FILE | grep -oE 'image::?[^[:space:][]+\[' | sed -E 's/^image::?//; s/\[$$//'); do \
12021215
IMAGE_DIR=$$(dirname $$IMAGE_FILE); \
12031216
IMAGE_PATH=$$(echo $(DOC_SRCDIR)/$$ADOC_DIR/$$IMAGE_FILE | sed -E 's%/src/($(LANGUAGES_MATCH))/%/src/%'); \
12041217
if [ ! -e $$IMAGE_PATH ] ; then \
@@ -1214,6 +1227,24 @@ endif
12141227
done; \
12151228
done > $@.new && mv $@.new $@
12161229

1230+
# Same staging, one file at a time. The dependency files name these images,
1231+
# so a clean -j build reaches one before the bulk pass has written it and
1232+
# falls through to the "Required image file" error at the end of this file.
1233+
# Source lookup as above: the English original, else the English build tree
1234+
# for images generated there, such as the .dot-rendered SVGs.
1235+
ifeq ($(BUILD_DOCS_TRANSLATED),yes)
1236+
define TRANSLATED_IMAGE_RULE
1237+
$(DOC_OUT_ADOC)/$(1)/%.$(2): | $(DOC_DIR)/.translateddocs-stamp
1238+
@mkdir -p $$(@D)
1239+
$$(Q)S=$(DOC_SRCDIR)/$$*.$(2); \
1240+
[ -e "$$$$S" ] || S=$(DOC_OUT_ADOC)/en/$$*.$(2); \
1241+
cp -f "$$$$S" $$@
1242+
endef
1243+
$(foreach L,$(LANGUAGES), \
1244+
$(foreach E,png jpg jpeg gif svg, \
1245+
$(eval $(call TRANSLATED_IMAGE_RULE,$(L),$(E)))))
1246+
endif
1247+
12171248
# Relative path from this html target back to $(DOC_OUT_HTML)/, used to
12181249
# point the lcnc-overrides.css <link> in docinfo.html at the right place.
12191250
# Every output now lives under a $(DOC_OUT_HTML)/<lang>/ subtree, so depth
@@ -1282,24 +1313,32 @@ endef
12821313
# components_gen.adoc generates straight into build/adoc/en/hal; svgs_made_from_dots
12831314
# runs first.
12841315
#
1285-
# One rule per staged file, not a bulk find|tar behind a stamp with the staged copies hanging off it order-only.
1286-
# make stats a prerequisite once per run and re-stats it only if it decided to remake it, and an order-only edge never triggers a remake.
1287-
# A bulk copy that rewrote the staged .adoc mid-run was therefore invisible to the renderer, which had already compared the .html against the pre-copy mtime, so editing a page took two `make` runs to reach the HTML: the first re-staged, the second rendered.
1288-
# With a real recipe per file make knows the staged copy changed and the render fires in the same run.
1316+
# One rule per staged file, not a bulk copy behind a stamp with the staged
1317+
# copies hanging off it order-only. make stats a prerequisite once per run
1318+
# and re-stats it only if it decided to remake it, which an order-only edge
1319+
# never triggers, so a bulk copy rewriting the staged .adoc mid-run stayed
1320+
# invisible and editing a page took two `make` runs to reach the HTML.
12891321
EN_STAGE_TYPES := -name '*.adoc' -o -name '*.png' -o -name '*.jpg' -o -name '*.jpeg' -o -name '*.gif' -o -name '*.svg' -o -name '*.py'
12901322
EN_STAGE_SRCS := $(shell find $(DOC_SRCDIR) \( $(EN_STAGE_TYPES) \))
12911323
EN_STAGED := $(patsubst $(DOC_SRCDIR)/%,$(DOC_OUT_ADOC)/en/%,$(EN_STAGE_SRCS))
12921324

1293-
# cp -p keeps the source mtime to the nanosecond; tar rounded it down to the whole second, which could leave a staged copy a fraction older than a .html rendered from it in the same second and lose that edit entirely.
1325+
# cp -p keeps the source mtime to the nanosecond. tar rounded down to the
1326+
# whole second, which could leave a staged copy a shade older than a .html
1327+
# rendered from it in that same second and lose the edit.
12941328
$(EN_STAGED): $(DOC_OUT_ADOC)/en/%: $(DOC_SRCDIR)/% | svgs_made_from_dots
12951329
@mkdir -p $(@D)
12961330
$(Q)cp -p $< $@
12971331

1298-
# Stage the whole set before anything reads it, the way the bulk copy did. On-demand staging is not enough: asciidoctor resolves include:: and image: against the staged tree at render time, and asciideps recurses into included files there, but only a fraction of those are make prerequisites. Leave it to demand and a partial like hal/halshow.adoc never lands, so the page that includes it renders an "Unresolved directive" placeholder instead of its content.
1332+
# Stage the whole set up front, as the bulk copy did. On demand is not
1333+
# enough: asciidoctor resolves include:: and image: against this tree at
1334+
# render time and asciideps recurses into it, yet few of those files are make
1335+
# prerequisites. Left to demand, a partial like hal/halshow.adoc never lands
1336+
# and the page including it renders an "Unresolved directive" placeholder.
12991337
.PHONY: stage-en
13001338
stage-en: $(EN_STAGED)
13011339

1302-
# Staged files are used only as prerequisites: mark .SECONDARY so make does not delete them as intermediates mid -j build (like the .SECONDARY above).
1340+
# Staged files are used only as prerequisites: mark .SECONDARY so make does
1341+
# not delete them as intermediates mid -j build (like the .SECONDARY above).
13031342
.SECONDARY: $(EN_STAGED)
13041343

13051344
# English now renders from build/adoc/en, the same model as the translations.

docs/src/asciideps

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@
22

33
set -e
44

5-
test -z "$1" && exit 0
6-
test -f "$1" || exit 1
5+
# usage: asciideps SOURCE.adoc [TARGET...]
6+
#
7+
# Emit a make rule hanging SOURCE's include:: and image: prerequisites off
8+
# TARGET. The caller names the target because it is not derivable from the
9+
# source path: a Master document has no .html and its English PDF lands in
10+
# objects/. Defaults to the source stem, for a standalone run.
11+
SRC=$1
12+
[ -z "$SRC" ] && exit 0
13+
[ -f "$SRC" ] || { echo "asciideps: '$SRC' not a file" >&2; exit 1; }
14+
shift
15+
TARGETS="$*"
16+
[ -n "$TARGETS" ] || TARGETS="${SRC%.adoc}.html"
717

818
includestack=( )
919

@@ -31,15 +41,19 @@ includes () {
3141

3242
images() {
3343
DIR=$(dirname "$1")
34-
sed -ne "s|^.*image:\{1,2\}\([^[]*\)\[.*\].*$|$DIR/\1|p" "$1" | tr '\n' ' '
44+
# Drop line comments first: the macro is matched anywhere on the line to
45+
# catch inline refs, which otherwise also matches a commented-out one.
46+
# That is no dependency, and requiring it breaks the build once the file
47+
# it names is removed.
48+
grep -v '^[[:space:]]*//' "$1" \
49+
| sed -ne "s|^.*image:\{1,2\}\([^[]*\)\[.*\].*$|$DIR/\1|p" \
50+
| tr '\n' ' '
3551
}
3652

37-
INCLUDES=$(includes "$1" | tr '\n' ' ')
38-
IMAGES=$(images "$1")
53+
INCLUDES=$(includes "$SRC" | tr '\n' ' ')
54+
IMAGES=$(images "$SRC")
3955
for f in $INCLUDES; do
4056
IMAGES="$IMAGES $(images "$f")"
4157
done
4258

43-
echo "${1%%.txt}.dep: $INCLUDES"
44-
echo "${1%%.txt}.html: $INCLUDES $IMAGES"
45-
echo "${1%%.txt}.pdf: $INCLUDES $IMAGES"
59+
echo "$TARGETS: $INCLUDES $IMAGES"

0 commit comments

Comments
 (0)