From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 6B661138334 for ; Tue, 26 Nov 2019 03:06:04 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0811CE08F1; Tue, 26 Nov 2019 03:06:02 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id CA891E08F1 for ; Tue, 26 Nov 2019 03:06:01 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 489FD34D3AF for ; Tue, 26 Nov 2019 03:06:00 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id CFC8326C for ; Tue, 26 Nov 2019 03:05:57 +0000 (UTC) From: "Göktürk Yüksek" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Göktürk Yüksek" Message-ID: <1574734623.3c2491a9e3018d1fc98feaf5d3b91c4ad2e7013a.gokturk@gentoo> Subject: [gentoo-commits] proj/devmanual:master commit in: / X-VCS-Repository: proj/devmanual X-VCS-Files: Makefile X-VCS-Directories: / X-VCS-Committer: gokturk X-VCS-Committer-Name: Göktürk Yüksek X-VCS-Revision: 3c2491a9e3018d1fc98feaf5d3b91c4ad2e7013a X-VCS-Branch: master Date: Tue, 26 Nov 2019 03:05:57 +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-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: d7cf9fa0-1b44-4299-9d55-aaec3eadc793 X-Archives-Hash: 0c4c773c7c7a747fe18f1c392430030d commit: 3c2491a9e3018d1fc98feaf5d3b91c4ad2e7013a Author: Michael Orlitzky gentoo org> AuthorDate: Mon Apr 29 01:10:28 2019 +0000 Commit: Göktürk Yüksek gentoo org> CommitDate: Tue Nov 26 02:17:03 2019 +0000 URL: https://gitweb.gentoo.org/proj/devmanual.git/commit/?id=3c2491a9 Makefile: simplify generated rules. Our Makefile is GNU-specific, thanks to heavy use of call/eval to automatically generate rules. In this commit, those generated rules have been replaced by slightly less (in terms of code volume) GNU-specific magic. The new magic uses a secondary expansion rule that allows us to access the target name inside its own prerequisites. The single resulting SECONDEXPANSION rule seems to be able to replace all of the generated rules. The variables and "clean" targets were also simplified using the full power of the GNU extensions, which we are assuming anyway. Finally, two other minor improvements were made: 1. The "clean" target was moved to the end of the file. 2. The "prereq" rule was split into two separate commands, and wrapped to a reasonable line length. Closes: https://bugs.gentoo.org/684688 Signed-off-by: Michael Orlitzky gentoo.org> Signed-off-by: Göktürk Yüksek gentoo.org> Makefile | 60 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index 8742a68..3da7c99 100644 --- a/Makefile +++ b/Makefile @@ -1,40 +1,40 @@ -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/") +# These "find" commands match text.xml and *.svg files, respectively, +# but only after excluding the .git directory from the search for +# performance and overall sanity reasons. +HTMLS := $(subst text.xml,index.html,\ + $(shell find ./ -name .git -prune -o \( -type f -name 'text.xml' -print \))) +IMAGES := $(patsubst %.svg,%.png,\ + $(shell find ./ -name .git -prune -o \( -type f -name '*.svg' -print \))) -all: prereq $(text_files) $(image_files) +all: prereq $(HTMLS) $(IMAGES) prereq: - @type convert >/dev/null 2>&1 || { echo "media-gfx/imagemagick with corefonts, svg and truetype required" >&2; exit 1; }; \ - type xsltproc >/dev/null 2>&1 || { echo "dev-libs/libxslt is required" >&2; exit 1; } + @type convert >/dev/null 2>&1 || \ + { echo "media-gfx/imagemagick[corefonts,svg,truetype] required" >&2;\ + exit 1; } + @type xsltproc >/dev/null 2>&1 || \ + { echo "dev-libs/libxslt is required" >&2;\ + exit 1; } %.png : %.svg convert $< $@ -clean: - @find . -name "*.png" -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 +# Secondary expansion allows us to use the automatic variable $@ in +# the prerequisites. When it is used (and we have no idea when that +# is, so we assume always) our tag induces a +# dependency on the output of all subdirectories of the current +# directories. This wacky rule finds all of those subdirectories by +# looking for text.xml in them, and then replaces "text.xml" in the +# path with "index.html". +# +# We use the pattern %.html rather than the more-sensible %index.html +# because the latter doesn't match our top-level index.html target. +# +.SECONDEXPANSION: +%.html: $$(dir $$@)text.xml devbook.xsl xsl/*.xsl $$(subst text.xml,index.html,$$(wildcard $$(dir $$@)*/text.xml)) + xsltproc devbook.xsl $< > $@ -# 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))))) +clean: + rm -f $(HTMLS) $(IMAGES) .PHONY: all prereq clean