From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 68BE159CAF for ; Sat, 2 Apr 2016 08:54:21 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id D82CDE07FC; Sat, 2 Apr 2016 08:54:20 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 6B36EE07FC for ; Sat, 2 Apr 2016 08:54:20 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6C6B934094F for ; Sat, 2 Apr 2016 08:54:19 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 3C04377 for ; Sat, 2 Apr 2016 08:54:18 +0000 (UTC) From: "Ulrich Müller" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Ulrich Müller" Message-ID: <1459584444.7977d86d8cfa8ef8b4368c338cb6933024361186.ulm@gentoo> Subject: [gentoo-commits] proj/devmanual:master commit in: / X-VCS-Repository: proj/devmanual X-VCS-Files: Makefile X-VCS-Directories: / X-VCS-Committer: ulm X-VCS-Committer-Name: Ulrich Müller X-VCS-Revision: 7977d86d8cfa8ef8b4368c338cb6933024361186 X-VCS-Branch: master Date: Sat, 2 Apr 2016 08:54:18 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 4562ebb5-443e-4dd3-988f-4e405fe7385b X-Archives-Hash: 9ed30014495abbdbcebbed01aba8b1a9 commit: 7977d86d8cfa8ef8b4368c338cb6933024361186 Author: Göktürk Yüksek binghamton edu> AuthorDate: Tue Mar 29 09:48:40 2016 +0000 Commit: Ulrich Müller gentoo org> CommitDate: Sat Apr 2 08:07:24 2016 +0000 URL: https://gitweb.gentoo.org/proj/devmanual.git/commit/?id=7977d86d Makefile: construct the full dependency tree instead of pattern matching Currently, the Makefile assumes that each document can be independently transformed and thus exposes a flat dependency hierarchy. This is incorrect because of the way table of contents (TOC) is generated. When a page is added or removed, its immediate parent and all of the parent's parents, all the way up to the root node, need to be recompiled in a bottom-up fashion to regenerate the TOC in each page. Use black magic to automatically generate build rules with proper prerequisites during runtime. The idea is to mirror the hierarchy in the document: every section has a dependency to its subsections. The rules are generated by iterating through each directory in the entire file system tree. Signed-off-by: Göktürk Yüksek binghamton.edu> Makefile | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index f22f304..d4182a8 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ -text_files := $(shell find -name "text.xml" | sed -e "s/text.xml$$/index.html/") +ALL_DIRS := $(shell find -name "text.xml" -exec dirname {} +) +text_files := $(addsuffix /index.html,$(ALL_DIRS)) image_files := $(shell find -name "*.svg" | sed -e "s/svg$$/png/") all: prereq $(text_files) $(image_files) @@ -7,13 +8,6 @@ prereq: @type -p convert &>/dev/null || { echo "media-gfx/imagemagick with corefonts, svg and truetype required" >&2; exit 1; }; \ type -p xsltproc &>/dev/null || { echo "dev-libs/libxslt is required" >&2; exit 1; } -%index.html : %text.xml devbook.xsl - xsltproc devbook.xsl $< > $@ - -# Someone should figure out a way to put this to the pattern -index.html : text.xml devbook.xsl - xsltproc devbook.xsl $< > $@ - %.png : %.svg convert $< $@ @@ -21,3 +15,26 @@ clean: @find . -name "*.png" -a \! -path "./icons/*" -exec rm -v {} + @find . -name "index.html" -exec rm -v {} + +# Given a directory with text.xml in it, return its immediate children as prerequisites +# Hypothetical example: +# INPUT: "./archs" "./archs/amd64 ./archs/x86 ./ebuild-writing ./appendices" +# OUTPUT: ./archs/amd64/index.html ./archs/amd64/index.html +define get_prerequisites = +$(addsuffix /index.html,$(foreach subdir,$(2),$(if $(subst $(1)/,,$(dir $(subdir))),,$(subdir)))) +endef + +# Given a directory with text.xml in it, genereate a complete build rule with prerequisites +# Hypothetical example: +# INPUT: "./archs" "./archs/amd64 ./archs/x86 ./ebuild-writing ./appendices" +# OUTPUT ./archs/index.html: ./archs/text.xml devbook.xsl ./archs/amd64/index.html ./archs/x86/index.html +# xsltproc devbook.xsl ./archs/text.xml > ./archs/index.html +define generate_rule = +$(1)/index.html: $(1)/text.xml devbook.xsl $(call get_prerequisites,$(1),$(2)) + xsltproc devbook.xsl $$< > $$@ +endef + +# This generates individual build rules for all the text files by +# iterating over all the directories in the file system tree +$(foreach dir,$(ALL_DIRS),$(eval $(call generate_rule,$(dir),$(filter-out $(dir),$(ALL_DIRS))))) + +.PHONY: all prereq clean