]> Lady’s Gitweb - Shushe/blob - GNUmakefile
75045a96fb4db52b580849004c38e641b0809550
[Shushe] / GNUmakefile
1 # SPDX-FileCopyrightText: 2023, 2024 Lady <https://www.ladys.computer/about/#lady>
2 # SPDX-License-Identifier: MPL-2.0
3
4 SHELL = /bin/sh
5
6 # ━ § BASIC INFORMATION ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
7 override define makefileinfo
8 ╭────────────────────────────╮
9 ╔╡ ⁌ ⛩️📰 书社 ∷ GNUmakefile ╞═════════════════════════════════╗
10 ║╰────────────────────────────╯ ║
11 ╟┬ ¶ Prerequisites ───────────────────────────────────────────┬╢
12 ║│ │║
13 ║│ Requires G·N·U Make, at least version 3.81, a version of │║
14 ║│ uuencode with base64 support, and the various programs │║
15 ║│ offered by libxml2 and libxslt. Beyond this, only programs │║
16 ║│ required by Posix are required, altho there is a chance of │║
17 ║│ version incompatibilities. The full list of program │║
18 ║│ requirements is as follows :— │║
19 ║│ │║
20 ║│ • awk │║
21 ║│ • cat │║
22 ║│ • cksum │║
23 ║│ • cp │║
24 ║│ • date │║
25 ║│ • echo │║
26 ║│ • file │║
27 ║│ • find │║
28 ║│ • git (optional) │║
29 ║│ • ln │║
30 ║│ • mkdir (requires support for `-p´) │║
31 ║│ • mv │║
32 ║│ • od (requires support for `-t x1´) │║
33 ║│ • printf │║
34 ║│ • rm │║
35 ║│ • sed │║
36 ║│ • sleep │║
37 ║│ • stat │║
38 ║│ • test │║
39 ║│ • touch │║
40 ║│ • tr (requires support for `-d´) │║
41 ║│ • uuencode (requires support for `-m´ and `-r´) │║
42 ║│ • xargs (requires support for `-0´) │║
43 ║│ • xmlcatalog (provided by libxml2) │║
44 ║│ • xmllint (provided by libxml2) │║
45 ║│ • xsltproc (provided by libxslt) │║
46 ║│ │║
47 ║│ In all cases, you can supply your own version of any │║
48 ║│ program `program´ by overriding the corresponding variable │║
49 ║│ `PROGRAM´ when calling Make. │║
50 ║╰────────────────────────────────────────────────────────────╯║
51 ╟┬ ¶ Usage ───────────────────────────────────────────────────┬╢
52 ║│ │║
53 ║│ • `make all´ (default): Compile, but do not install, all │║
54 ║│ files. │║
55 ║│ │║
56 ║│ • `make clean´: Remove `BUILDDIR´. │║
57 ║│ │║
58 ║│ • `make gone´: Remove `BUILDDIR´ and installed files. │║
59 ║│ │║
60 ║│ • `make help´: Print this message. │║
61 ║│ │║
62 ║│ • `make install´: Compile all files and install in │║
63 ║│ `DESTDIR´. │║
64 ║│ │║
65 ║│ • `make list´: List all recognized source files and their │║
66 ║│ classification (including media type and dependencies). │║
67 ║│ │║
68 ║│ • `make uninstall´: Remove installed files, but not │║
69 ║│ `BUILDDIR´. │║
70 ║│ │║
71 ║│ Set `VERBOSE=1´ to see the text of commands as they are │║
72 ║│ executed. │║
73 ║│ │║
74 ║│ See `README.markdown´ for a more involved description of │║
75 ║│ the capabilities and configuration of this program. │║
76 ║╰────────────────────────────────────────────────────────────╯║
77 ╟┬ ¶ Copyright & License ─────────────────────────────────────┬╢
78 ║│ │║
79 ║│ Copyright © 2023–2024 Lady [@ Lady’s Computer]. │║
80 ║│ │║
81 ║│ This Source Code Form is subject to the terms of the │║
82 ║│ Mozilla Public License, v 2.0. If a copy of the M·P·L was │║
83 ║│ not distributed with this file, You can obtain one at │║
84 ║│ <http://mozilla.org/MPL/2.0/>. │║
85 ║╰────────────────────────────────────────────────────────────╯║
86 ╚══════════════════════════════════════════════════════════════╝
87 endef
88
89 # ━ § MAKE·FILE SETUP ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
90
91 # Programs needed to run this make·file.
92 #
93 # If these are not installed on your computer, or you need to use a different implementation, you can override the appropriate variable.
94 AWK := awk
95 CAT := cat
96 CKSUM := cksum
97 CP := cp
98 DATE := date
99 ECHO := echo
100 FILE := file
101 FIND := find
102 GIT := git
103 LN := ln
104 MKDIR := mkdir
105 MV := mv
106 OD := od
107 PRINTF := printf
108 RM := rm
109 SED := sed
110 SLEEP := sleep
111 STAT := stat
112 TEST := test
113 TOUCH := touch
114 TR := tr
115 UUENCODE := uuencode
116 XARGS := xargs
117 XMLCATALOG := xmlcatalog
118 XMLLINT := xmllint
119 XSLTPROC := xsltproc
120
121 # The directory which contains the source files.
122 #
123 # Multiple directories can be given so long as files with the same name do not exist in each.
124 SRCDIR := sources
125
126 # The directory which contains “includes”:
127 # Files which may be included in other files but for which no final output will be generated.
128 #
129 # Multiple directories can be given so long as files with the same name do not exist in each.
130 #
131 # These can be inside of `SRCDIR´ directories if desired.
132 INCLUDEDIR := sources/includes
133
134 # The directory in which to generate temporary buildfiles.
135 BUILDDIR := build
136
137 # The directory into which to output files on `make install´.
138 DESTDIR := public
139
140 # The location of this Makefile (and related ⛩️📰 书社 files), relative to the current working directory.
141 #
142 # By default, this is inferred from the variable `MAKEFILE_LIST´.
143 THISDIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
144
145 # Configuration of `find´.
146 #
147 # By default, `find´ will ignore files which begin with a period and those which are likely to cause problems for `make´.
148 EXTRAFINDRULES :=
149 EXTRAFINDINCLUDERULES :=
150 FINDRULES := ! '(' '(' -name '[.-]*' -o -name '*[][*?:|$$%\#\\; ]*' -o -name '*[)]' ')' -a -prune ')'$(if $(EXTRAFINDRULES), -a $(EXTRAFINDRULES),)
151 FINDINCLUDERULES := $(FINDRULES)$(if $(EXTRAFINDINCLUDERULES), -a $(EXTRAFINDINCLUDERULES),)
152
153 # The list of magic files to use when determining media types.
154 #
155 # Some are provided as part of this repository, but you can add more if you need different media type detection.
156 #
157 # Your computer probably has several already installed at `/usr/share/file/magic´.
158 EXTRAMAGIC :=
159 MAGIC := $(sort $(patsubst ./%,%,$(wildcard $(THISDIR)/magic/*)) $(EXTRAMAGIC))
160
161 # The list of parsers for plaintext file types.
162 #
163 # Which parsers are provided will influence which kinds of files are recognized as plaintext.
164 EXTRAPARSERS :=
165 PARSERS := $(sort $(patsubst ./%,%,$(wildcard $(THISDIR)/parsers/*.xslt)) $(EXTRAPARSERS))
166
167 # The list of transforms.
168 EXTRATRANSFORMS :=
169 TRANSFORMS := $(sort $(patsubst ./%,%,$(wildcard $(THISDIR)/transforms/*.xslt)) $(EXTRATRANSFORMS))
170
171 # List of types which should be treated as X·M·L.
172 XMLTYPES := application/xml text/xml
173
174 ifdef GIT
175 ifneq ($(wildcard $(THISDIR)/.git),)
176 # A description of the current git revision of ⛩️📰 书社.
177 THISREV := $(shell cd $(THISDIR); $(GIT) describe 2> /dev/null || $(GIT) rev-parse HEAD 2> /dev/null || true)
178 endif
179
180 ifneq ($(wildcard .git),)
181 # A description of the current git revision of the working directory.
182 SRCREV := $(shell $(GIT) describe 2> /dev/null || $(GIT) rev-parse HEAD 2> /dev/null || true)
183 endif
184 endif
185
186 # Set to a non·empty value to print all commands as they run.
187 VERBOSE :=
188
189 # The default target for this makefile.
190 .DEFAULT_GOAL := all
191
192 # ━ § BEGIN MAKE·FILE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
193
194 # ─ ¶ Non‐Recipe Variable Definitions ─────────────────────────────────
195
196 # A variable with no value, usable when assigning values which contain whitespace.
197 override empty :=
198
199 # A variable which contains a newline, to allow the generation of multiline strings in function calls.
200 override define newline
201
202
203 endef
204
205 # A variable which contains a single space.
206 override space := $(empty) $(empty)
207
208 # A variable which contains a single comma.
209 override comma := ,
210
211 # (callable) Quote the given string for use within shell calls.
212 override quote = '$(subst ','"'"',$1)'
213
214 # Outputs an `@´ to silence rules, unless `VERBOSE´ is nonempty.
215 override silent := $(if $(VERBOSE),,@)
216
217 # (callable) Test to see if the prerequisites provided by the second argument matches the value in the file corresponding to the first argument in `$(BUILDDIR)/lastprereqs´.
218 # If not, save the new value and then add FORCE.
219 # Return them regardless.
220 #
221 # Calling this variable is useful when a given target should be updated whenever its list of prerequisites changes in addition to whenever there is a change to one of its prerequisites.
222 #
223 # ☡ This variable creates at least one subshell every time it is computed.
224 override diffprereqs = $(if $(subst $(shell $(CAT) $(call quote,$(BUILDDIR)/lastprereqs/$1) 2> /dev/null || true),,$2),$2 FORCE$(and $(shell $(call ensuredirectory,$(BUILDDIR)/lastprereqs) && $(PRINTF) '%s\n' $(call quote,$2) > $(BUILDDIR)/lastprereqs/$1),),$2)
225
226 # (callable) Escape special characters for use in sed regular expressions.
227 override sedesc = $(subst /,[/],$(subst $$,\$$,$(subst *,\*,$(subst .,\.,$(subst [,\[,$(subst ^,\^,$(subst \,\\,$1)))))))
228
229 # The command to use for percent‐decoding.
230 override perdeccmd := $(SED) 's/|/%7C/g;s/[\]/%5C/g;s/%[0-9A-Fa-f]\{2\}/|&|/g' | $(TR) '|' '\n' | $(SED) '/^%[0-9A-Fa-f]\{2\}$$/!s/%/|%25|/' | $(TR) '|' '\n' | $(AWK) '$$0!~/%/{printf "%s",$$0}/%/{d="0123456789ABCDEF";v=substr(toupper($$0),2,2);printf "\\%04o",(index(d,substr(v,1,1))-1)*16+index(d,substr(v,2,1))-1}' | $(XARGS) -0 $(PRINTF) '%b'
231
232 # (callable) Percent‐decode the given strings.
233 #
234 # ☡ This variable creates a subshell every time it is computed.
235 override perdec = $(shell $(PRINTF) '%s\0450A' $(foreach encoded,$1,$(call quote,$(encoded))) | $(perdeccmd))
236
237 # (callable) Percent‐encode the given strings.
238 #
239 # This singly‐encodes u·r·i characters and doubly‐encodes other characters, then calls `perdec´ to decode back to a single encoding.
240 # The encoding assumes the input is a “u·r·i component”; e·g that the resulting string should only contain `pchar´ (but can contain any `sub-delim´).
241 #
242 # It is assumed that the given strings do not contain newlines.
243 #
244 # ☡ This variable creates a subshell every time it is computed.
245 override perenc = $(shell $(PRINTF) '%s\n' $(foreach unencoded,$1,$(call quote,$(unencoded))) | $(OD) -t x1 | $(SED) 's/^[0-9]*//;s/0[Aa]/%&/g;s/2[146-9A-Ea-e]/%&/g;s/3[0-9AaBbDd]/%&/g;s/40/%&/g;s/[46][1-9A-Fa-f]/%&/g;s/[57][0-9Aa]/%&/g;s/5[Ff]/%&/g;s/7[Ee]/%&/g;s/[ ][0-9A-Fa-f]\{2\}/%25&/g' | $(TR) -d ' \n' | $(TR) 'abcdef' 'ABCDEF' | $(perdeccmd))
246
247 # (callable) Percent‐encode each component in the given paths.
248 #
249 # ☡ This variable creates a subshell every time it is computed.
250 override pathenc = $(subst %2F,/,$(call perenc,$1))
251
252 # (overridable) Collect all of the applicable includes from the includes directory.
253 sourceincludes := $(shell $(FIND) $(foreach dir,$(INCLUDEDIR),$(call quote,$(dir))) '(' $(FINDRULES) ')' -a -type f)
254
255 # (overridable) Collect all of the applicable source files from the source directory, removing any which are also includes.
256 sourcefiles := $(filter-out $(sourceincludes),$(shell $(FIND) $(foreach dir,$(SRCDIR),$(call quote,$(dir))) '(' $(FINDRULES) ')' -a -type f))
257
258 # Figure out the file type of each source file and source include.
259 ifneq ($(wildcard $(BUILDDIR)/magic.mgc),)
260 override types := $(shell $(SED) 's/^ *//;s/ *$$//;s/ {2,}/ /g' <<< $(call quote,$(sourcefiles) $(sourceincludes)) | $(TR) ' ' '\n' | $(FILE) -m $(call quote,$(BUILDDIR)/magic.mgc) --mime-type --separator '|' --files-from - | $(SED) 's/| */|/g')
261 endif
262
263 # Get the list of supported plaintext file types from the parser.
264 ifneq ($(wildcard $(BUILDDIR)/parser.xslt),)
265 override plaintexttypes := $(filter-out $(XMLTYPES),$(shell $(XMLLINT) --xpath '/*/*[@name="书社:parsers"]//*[namespace-uri()="http://www.w3.org/1999/xhtml" and local-name()="dd"]/text()' $(call quote,$(BUILDDIR)/parser.xslt)))
266 endif
267
268 # (callable) Get all of the files (source and includes) which have the given types.
269 override filesoftype = $(foreach type,$1,$(patsubst %|$(type),%,$(filter %|$(type),$(types))))
270
271 # Build up collections of various file types.
272 override xmlfiles := $(call filesoftype,$(XMLTYPES))
273 override plaintextfiles := $(filter-out $(xmlfiles),$(call filesoftype,$(plaintexttypes)))
274 override assetfiles := $(filter-out $(xmlfiles) $(plaintextfiles),$(sourcefiles) $(sourceincludes))
275
276 # (callable) Get the types of the given files.
277 override typeoffile = $(patsubst $(foreach file,$1,$(file)|%),%,$(filter $(foreach file,$1,$(file)|%),$(types)))
278
279 # Pair each source magic file with its location in the build directory.
280 override magicpair := $(foreach magicfile,$(MAGIC),$(magicfile)|$(BUILDDIR)/magic/$(notdir $(magicfile)))
281
282 # (callable) Get the source file for the given magic files.
283 override magicsource = $(foreach magicpath,$1,$(patsubst %|$(magicpath),%,$(firstword $(filter %|$(magicpath),$(magicpair)))))
284
285 # (callable) Get the build file for the given magic files.
286 override magicfile = $(foreach file,$1,$(patsubst $(file)|%,%,$(filter $(file)|%,$(magicpair))))
287
288 # (callable) Get the local path for the given source file.
289 override sourcepath = $(firstword $(foreach directory,$(SRCDIR),$(if $(filter $(directory)/%,$1),$(patsubst $(directory)/%,%,$1),)))
290
291 # (callable) Get the local path for the given include.
292 override includepath = $(firstword $(foreach directory,$(INCLUDEDIR),$(if $(filter $(directory)/%,$1),$(patsubst $(directory)/%,%,$1),)))
293
294 # (callable) Get base64 data u·r·i’s for the given files.
295 #
296 # ☡ This variable creates a subshell every time it is computed.
297 override datauri = $(foreach file,$1,data:$(call typeoffile,$(file));base64,$(shell $(UUENCODE) -m -r $(call quote,$(file)) _ | tr -d ' \n'))
298
299 # Pair each source file and include with its local u·r·i.
300 override sourcelocalpair := $(foreach file,$(sourcefiles) $(sourceincludes),$(file)|about:shushe?$(if $(filter $(file),$(sourceincludes)),include=$(call pathenc,$(call includepath,$(file))),source=$(call pathenc,$(call sourcepath,$(file)))))
301
302 # (callable) Get local uris for the given files.
303 override localuri = $(foreach file,$1,$(patsubst $(file)|%,%,$(filter $(file)|%,$(sourcelocalpair))))
304
305 # (callable) Get the source files for the given local uris.
306 override sourcefile = $(foreach local,$1,$(patsubst %|$(local),%,$(filter %|$(local),$(sourcelocalpair))))
307
308 # Adds a requirement on `$(BUILDDIR)/.update-types´ if the file is present.
309 #
310 # This file is created after a reload due to type changes, and is removed after.
311 # Requiring it ensures that file classifications are up·to·date immediately after the reload.
312 override typeupdates := $(wildcard $(BUILDDIR)/.update-types)
313
314 # Pair each source file and include with its parsed location.
315 override sourceparsedpair := $(foreach file,$(sourcefiles) $(sourceincludes),$(file)|$(BUILDDIR)/$(if $(filter $(file),$(sourceincludes)),includes/$(call includepath,$(file)),sources/$(call sourcepath,$(file))))
316
317 # (callable) Get the location of the transformed X·M·L files for the given source files.
318 override parsed = $(foreach file,$1,$(patsubst $(file)|%,%,$(filter $(file)|%,$(sourceparsedpair))))
319
320 # (callable) Get the source files for the given parsed file.
321 override unparsed = $(foreach file,$1,$(patsubst %|$(file),%,$(filter %|$(file),$(sourceparsedpair))))
322
323 # Pair each parser, transform, or parsed file with its file u·r·i.
324 override fileuripairs := $(join $(patsubst %,%|,$(PARSERS) $(TRANSFORMS) $(call parsed,$(sourcefiles) $(sourceincludes))),$(call pathenc,$(foreach uriable,$(PARSERS) $(TRANSFORMS) $(call parsed,$(sourcefiles) $(sourceincludes)),file://$(abspath $(uriable)))))
325
326 # (callable) Get the file u·r·is for the given parsers, transforms, or parsed files.
327 override fileuri = $(foreach file,$1,$(patsubst $(file)|%,%,$(filter $(file)|%,$(fileuripairs))))
328
329 ifneq ($(wildcard $(BUILDDIR)/dependencies),)
330 # Pair each file with a list of dependencies for it.
331 override dependenciesforfile := $(foreach file,$(filter-out $(assetfiles),$(sourcefiles) $(sourceincludes)),$(file)|$(subst $(space),|,$(shell $(CAT) $(call quote,$(BUILDDIR)/dependencies) | $(SED) $(call quote,/^$(call sedesc,$(call localuri,$(file)))$$/$(comma)/^[^ ]/!d;/^ /!d;s/^ //))))
332
333 # (callable) Get the list of dependency leiris for the given source files.
334 #
335 # Recursive dependencies are marked with a leading `-´.
336 override dependencyuris = $(foreach file,$1,$(subst |, ,$(patsubst $(file)|%,%,$(filter $(file)|%,$(dependenciesforfile)))))
337
338 # (callable) Get the list of recursive dependencies for the given source files.
339 override recursives = $(foreach uri,$(filter -%,$(call dependencyuris,$1)),$(call sourcefile,$(patsubst -%,%,$(uri))))
340
341 # (callable) Get the list of (nonrecursive) dependencies for the given source files.
342 override dependencies = $(foreach uri,$(filter-out -%,$(call dependencyuris,$1)),$(call sourcefile,$(uri)))
343 endif
344
345 # Collect all files with recursive dependencies.
346 override recursivefiles := $(foreach file,$(filter-out $(assetfiles),$(sourcefiles)),$(if $(call recursives,$(file)),$(file),))
347
348 # Collect all files which should be compiled.
349 #
350 # This is all of the non·asset, nonrecursive files.
351 override compilablefiles := $(filter-out $(assetfiles) $(recursivefiles),$(sourcefiles))
352
353 # Collect all files which can be installed.
354 #
355 # This is all of the comilable files and all asset sources.
356 override installablefiles := $(compilablefiles) $(filter $(assetfiles),$(sourcefiles))
357
358 ifneq ($(wildcard $(BUILDDIR)/destinations),)
359 # Get the output of the destination transform.
360 override destinations := $(shell $(CAT) $(BUILDDIR)/destinations)
361
362 # Pair source files and their destinations.
363 override sourcedestinationpair := $(foreach destination,$(destinations),$(call sourcefile,$(firstword $(subst |, ,$(destination))))|$(call perdec,$(subst $(space),|,$(wordlist 2,$(words $(subst |, ,$(destination))),$(subst |, ,$(destination))))))
364
365 # (callable) Get the destination for the given source files.
366 override destination = $(foreach file,$1,$(patsubst $(file)|%,%,$(filter $(file)|%,$(sourcedestinationpair))))
367
368 # Pair each source file with its compiled location.
369 override sourcecompiledpair := $(foreach file,$(sourcefiles),$(file)|$(BUILDDIR)/public/$(call destination,$(file)))
370
371 # (callable) Get the location of the transformed X·M·L files for the given source files.
372 override compiled = $(foreach file,$1,$(patsubst $(file)|%,%,$(filter $(file)|%,$(sourcecompiledpair))))
373
374 # (callable) Get the source files for the given compiled file.
375 override uncompiled = $(foreach file,$1,$(patsubst %|$(file),%,$(filter %|$(file),$(sourcecompiledpair))))
376
377 # (callable) Get the installed locations for the given source files.
378 override installed = $(foreach file,$1,$(DESTDIR)/$(call destination,$(file)))
379 endif
380
381 # ─ ¶ Recipe Variable Definitions ─────────────────────────────────────
382
383 # (callable) Check to see if the given directory exists and create it if not.
384 override ensuredirectory = if $(TEST) ! -d $(call quote,$1); then $(MKDIR) -p $(call quote,$1); fi
385
386 # (callable) Get the identifier for the given parser or transform.
387 override id = $(XMLLINT) --xpath '/*/*[local-name()="id" and namespace-uri()="urn:fdc:ladys.computer:20231231:Shu1She4"]/text()[1]' $(call quote,$1) 2> /dev/null || $(PRINTF) '%s\n' $(call quote,about:shushe?$(or $2,unknown)=$(call pathenc,$(basename $(notdir $1))))
388
389 # (callable) Sanitize and wrap the provided plaintext file in X·M·L, printing to `stdout´.
390 override wrapplaintext = $(TR) '\000\013\014' '\032\011\012' < $(call quote,$1) | $(SED) "$$($(PRINTF) '%b' 's/]]>/]]]]><!\\[CDATA\\[>/g\ns/\0357\0277\0276/�/g\ns/\0357\0277\0277/�/g\n$$!s/\\r$$//g\ns/\\r/\\n/g\n$$!s/\0302\0205$$//g\ns/\0302\0205/\\n/g;s/\0342\0200\0250/\\n/g;s/[\0001-\0010]/�/g;s/[\0016-\0037]/�/g')" | $(XARGS) -0 -J %% $(PRINTF) '%b%s%s\n' '<?xml version=\042\061.0\042?>\n<script xmlns=\042http://www.w3.org/1999/xhtml\042 type=\042$(call typeoffile,$1)\042><![CDATA[' %% ']]></script>'
391
392 # (callable) Check if the provided X·M·L file is X·M·L 1.1, and if so, coerce to X·M·L 1.0 as best as possible, printing the result (or the original file contents) to `stdout´.
393 #
394 # The X·M·L declaration will be dropped and character escapes for C0 control codes will be replaced with a literal `U+0091 PRIVATE USE ONE´, which is invalid in X·M·L 1.1, but valid X·M·L 1.0 (making the replacement obvious).
395 #
396 # This isn’t a perfect substitution (it makes some assumptions about the format of the underlying X·M·L), but it should be workable for most sensible, welformed files.
397 override serializexml = $(SED) "$$($(PRINTF) '%b' '/<?xml[ \t]\\{1,\\}version=[\0042\0047]1.1/,$${ s/<?xml[^>]*?>/<!--<?xml version=\00421.1\0042?>-->/\n s/&\0043x0*[1-8BCEFbcef];/\0302\0221/g\n s/&\0043x0*1[0-9A-Fa-f];/\0302\0221/g\n s/&\00430*[1-8];/\0302\0221/g\n s/&\00430*1[124-9];/\0302\0221/g\n s/&\00430*2[0-9];/\0302\0221/g\n s/&\00430*3[01];/\0302\0221/g\n}')" < $(call quote,$1) | $(SED) "$$(PRINTF '%b' ':a\n/^\\n*$$/{ $$d\n N\n ba\n}')"
398
399 # ─ ¶ Phony Targets ───────────────────────────────────────────────────
400
401 # Compile all files, or error if any are recursive.
402 all : $(call compiled,$(recursivefiles) $(compilablefiles)) ;
403
404 # Destroy buildfiles.
405 clean :
406 $(if $(BUILDDIR),$(silent)$(RM) -rf $(call quote,$(BUILDDIR)/),)
407
408 # Destroy build directory and installed files.
409 gone : clean uninstall ;
410
411 # Provide help.
412 help :
413 @$(PRINTF) '%b' '$(subst $(newline),\n,$(makefileinfo))'
414
415 # Install the compiled files into `DESTDIR´, or error if any are recursive.
416 install : $(call installed,$(recursivefiles) $(installablefiles)) ;
417
418 # List all source files and includes and their computed types.
419 list :
420 @$(PRINTF) '%b' $(call quote,$(foreach file,$(sort $(sourcefiles)) $(sort $(sourceincludes)),\0033[1m$(file)\0033[22m|$(call typeoffile,$(file))|[\0033[3m$(if $(filter $(file),$(xmlfiles)),xml,$(if $(filter $(file),$(plaintextfiles)),text,asset))$(if $(filter $(file),$(sourceincludes)),|include,)\0033[23m]$(if $(call dependencies,$(file))$(call recursives,$(file)), $(strip $(foreach recursive,$(call recursives,$(file)),\0033[93;41m•|Recursive|Dependency|\0033[39;49m|$(recursive)) $(foreach dependency,$(call dependencies,$(file)),\0033[2m•|Dependency|\0033[22m|$(dependency))))$(if $(filter $(file),$(sourcefiles)), →|<\0033[4m/$(call destination,$(file))\0033[24m>,) )) | $(TR) ' |' '\n '
421
422 # Destroy installed files.
423 uninstall :
424 $(foreach file,$(installablefiles),$(if $(wildcard $(call installed,$(file))),$(silent)$(PRINTF) '%s\n' $(call quote,Removing </$(patsubst $(DESTDIR)/%,%,$(call installed,$(file)))>…)$(newline)$(silent)$(RM) -f $(call quote,$(call installed,$(file)))$(newline),))
425
426 # Raise an error when attempting to build any files with recursive dependencies.
427 $(call compiled,$(recursivefiles)) :
428 @$(PRINTF) '%b\n' $(call quote,\0033[93;41mError:\0033[39;49m `$(call uncompiled,$@)´ has recursive dependencies:\n$(subst |, ,$(subst $(space),$(newline),$(foreach recursive,$(call recursives,$(call uncompiled,$@)),•|$(recursive))))) && false
429
430 # Add as a prerequisite to treat the target as tho it were phony.
431 FORCE : ;
432
433 # ─ ¶ Special Targets ─────────────────────────────────────────────────
434
435 # Perform secondary expansion; this enables pattern rules to determine their prerequisites based on the matched pattern.
436 .SECONDEXPANSION : ;
437
438 # Don’t use any implicit rules.
439 .SUFFIXES : ;
440
441 # Phony rules; always consider these out·of·date.
442 .PHONY : FORCE all default clean gone info install list uninstall $(call compiled,$(recursivefiles)) ;
443
444 ifneq ($(typeupdates)$(wildcard $(BUILDDIR)/dependencies)$(wildcard $(BUILDDIR)/destinations),)
445 # Reload this make·file if the dependency graph or output destinations have changed.
446 #
447 # The dependency graph and output destinations are used to set the values of variables in this make·file, so it’s important to ensure that they are actually up·to·date prior to executing any later rules.
448 #
449 # This recipe only exists after types have been updated or when the dependency graph or destinations file already exists.
450 #
451 # ※ There is a chance that generating the dependencies will also update the parsers.
452 $(THISDIR)/GNUmakefile :: $(BUILDDIR)/dependencies $(BUILDDIR)/destinations
453 $(silent)$(TOUCH) $(THISDIR)/GNUmakefile
454 ifeq ($(typeupdates),)
455 @if $(TEST) ! -f $(call quote,$(BUILDDIR)/.update-types); then $(PRINTF) '%b\n' '\0033[1mDependency graph and output destinations updated. Restarting…\0033[22m'; fi
456 else
457 $(silent)$(RM) $(BUILDDIR)/.update-types
458 @$(PRINTF) '%b\n' '\0033[1mDependency graph and output destinations updated. Restarting…\0033[22m'
459 endif
460 endif
461
462 ifeq ($(typeupdates),)
463 # Reload this make·file if any of the magic files or parsers have changed.
464 #
465 # These are used to classify source files, so if they have changed then the make·file must be reloaded.
466 #
467 # This recipe sleeps for one second to ensure that files built after the restart have a more current time·stamp.
468 $(THISDIR)/GNUmakefile :: $(BUILDDIR)/magic.mgc $(BUILDDIR)/parser.xslt
469 $(silent)$(TOUCH) $(THISDIR)/GNUmakefile
470 $(silent)$(RM) -f $(call quote,$(BUILDDIR)/dependencies) $(call quote,$(BUILDDIR)/destinations)
471 @$(PRINTF) '%b\n' '\0033[1mMagic file or parsers have updated. Restarting…\0033[22m'
472 $(silent)$(SLEEP) 1
473 $(silent)$(TOUCH) $(call quote,$(BUILDDIR)/.update-types)
474 endif
475
476 # ─ ¶ Build Targets ───────────────────────────────────────────────────
477
478 # Create symbolic links from the build directory’s store of magic files to their corresponding sources.
479 $(call magicfile,$(MAGIC)) : $(BUILDDIR)/magic/% : $$(call magicsource,$$@)
480 $(silent)$(call ensuredirectory,$(dir $@))
481 $(silent)$(LN) -sf $(call quote,$(realpath $<)) $(call quote,$@)
482
483 # Generate the compiled magic file from its sources.
484 #
485 # It must be updated if any of the files in the magic directory change.
486 $(BUILDDIR)/magic.mgc : $(call diffprereqs,magic,$(sort $(call magicfile,$(MAGIC))))
487 $(foreach outdated,$(filter-out $^,$(wildcard $(BUILDDIR)/magic/*)),$(silent)$(RM) $(call quote,$(outdated))$(newline))
488 @$(ECHO) "Compiling new magic…"
489 $(silent)$(call ensuredirectory,$(dir $@))
490 $(silent)cd $(call quote,$(BUILDDIR)) && $(FILE) -C -m $(call quote,$(realpath $(BUILDDIR)/magic))
491 $(silent)$(TOUCH) $(call quote,$(BUILDDIR)/.update-types)
492
493 # Generate the main parser.
494 $(BUILDDIR)/parser.catalog : $(call diffprereqs,parsers,$(sort $(PARSERS)))
495 @$(ECHO) "Generating catalog of parsers…"
496 $(silent)$(XMLCATALOG) --create --noout $(call quote,$@)
497 $(foreach parser,$(PARSERS),$(silent)( $(call id,$(parser)) ) | $(XARGS) -I %% $(XMLCATALOG) --add uri %% $(call quote,$(call fileuri,$(parser))) --noout $(call quote,$@)$(newline))
498 $(BUILDDIR)/parser.xslt : $(BUILDDIR)/parser.catalog $(THISDIR)/lib/catalog2parser.xslt
499 @$(ECHO) "Generating main parser…"
500 $(silent)$(XSLTPROC) -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2parser.xslt) $(call quote,$<)
501 $(silent)$(TOUCH) $(call quote,$(BUILDDIR)/.update-types)
502
503 # Parse the files.
504 #
505 # Even plain X·M·L files are parsed, because they may contain X·H·T·M·L `<script>´ elements which contain other kinds of data.
506 # Asset files are turned into H·T·M·L embeds pointing to `data:´ U·R·I’s.
507 $(call parsed,$(sourcefiles) $(sourceincludes)) : % : $$(call unparsed,$$@) $(BUILDDIR)/parser.xslt $(typeupdates)
508 @$(PRINTF) '%s\n' $(call quote,Processing `$<´…)
509 $(silent)$(call ensuredirectory,$(dir $@))
510 $(silent)$(if $(filter $<,$(assetfiles)),$(PRINTF) '%s\n' $(call quote,<object xmlns="http://www.w3.org/1999/xhtml" type="$(call typeoffile,$<)" data="$(call datauri,$<)"/>) > $(call quote,$@),$(if $(filter $<,$(plaintextfiles)),$(call wrapplaintext,$<),$(call serializexml,$<)) | $(XSLTPROC) -o $(call quote,$@) --stringparam BUILDTIME $$(TZ= $(DATE) '+%Y-%m-%dT%H:%M:%SZ') --stringparam IDENTIFIER $(call quote,$(call localuri,$<)) --stringparam SRCTIME $$(TZ= $(STAT) -f '%Sm' -t '%Y-%m-%dT%H:%M:%SZ' $(call quote,$<)) --stringparam CKSUM $$($(CKSUM) $(call quote,$<) | $(SED) 's/[ ].*//')$(if $(THISREV), --stringparam THISREV $(call quote,$(THISREV)),)$(if $(SRCREV), --stringparam SRCREV $(call quote,$(SRCREV)),) $(call quote,$(BUILDDIR)/parser.xslt) -)
511
512 # Generate a catalog of all parsed files, for use when processing includes.
513 #
514 # This does not depend on actually transforming the files.
515 $(BUILDDIR)/catalog : $(call diffprereqs,sources,$(sort $(sourcefiles) $(sourceincludes))) $(typeupdates)
516 @$(ECHO) "Generating catalog of parsed files…"
517 $(silent)$(XMLCATALOG) --create --noout $(call quote,$@)
518 $(foreach source,$(sourcefiles) $(sourceincludes),$(silent)$(XMLCATALOG) --add uri $(call quote,$(call localuri,$(source))) $(call quote,$(call fileuri,$(call parsed,$(source)))#$(if $(filter $(source),$(assetfiles)),asset,xml)) --noout $(call quote,$@)$(newline))
519
520 # Build a list of dependencies for each parsed file.
521 $(BUILDDIR)/dependencies : $(BUILDDIR)/catalog $(call parsed,$(plaintextfiles) $(xmlfiles)) $(THISDIR)/lib/catalog2dependencies.xslt
522 @$(ECHO) "Identifying dependencies…"
523 $(silent)$(XSLTPROC) -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2dependencies.xslt) $(call quote,$<)
524
525 # Generate a catalog of destinations for files.
526 #
527 # This depends on parsing non·asset source files, but not assets or includes.
528 # It does not require knowing the dependencies.
529 $(BUILDDIR)/destinations : $(BUILDDIR)/catalog $(call parsed,$(filter-out $(assetfiles),$(sourcefiles))) $(THISDIR)/lib/catalog2destinations.xslt
530 @$(ECHO) "Identifying output destinations…"
531 $(silent)$(XSLTPROC) -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2destinations.xslt) $(call quote,$<)
532
533 # Generate the main transform.
534 $(BUILDDIR)/transform.catalog : $(call diffprereqs,transforms,$(sort $(TRANSFORMS)))
535 @$(ECHO) "Generating catalog of transforms…"
536 $(silent)$(XMLCATALOG) --create --noout $(call quote,$@)
537 $(foreach transform,$(TRANSFORMS),$(silent)( $(call id,$(transform)) ) | $(XARGS) -I %% $(XMLCATALOG) --add uri %% $(call quote,$(call fileuri,$(transform))) --noout $(call quote,$@)$(newline))
538 $(BUILDDIR)/transform.xslt : $(BUILDDIR)/transform.catalog $(THISDIR)/lib/catalog2transform.xslt
539 @$(ECHO) "Generating main transform…"
540 $(silent)$(XSLTPROC) -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2transform.xslt) $(call quote,$<)
541
542 # Generate the output files using the dependencies as necessary.
543 $(call compiled,$(compilablefiles)) : $(BUILDDIR)/public/% : $$(call parsed,$$(call uncompiled,$$@)) $(BUILDDIR)/transform.xslt $$(call parsed,$$(call dependencies,$$(call uncompiled,$$@)))
544 $(silent)$(call ensuredirectory,$(dir $@))
545 @$(PRINTF) '%s\n' $(call quote,Compiling </$*>…)
546 $(silent)$(XSLTPROC) -o $(call quote,$@) --stringparam CATALOG 'catalog' --stringparam BUILDTIME $$(TZ= $(DATE) '+%Y-%m-%dT%H:%M:%SZ') --stringparam SRCTIME $$(TZ= $(STAT) -f '%Sm' -t '%Y-%m-%dT%H:%M:%SZ' $(call quote,$(call uncompiled,$@))) --stringparam IDENTIFIER $(call quote,$(call localuri,$(call uncompiled,$@))) --stringparam PATH $(call quote,/$*) --stringparam CKSUM $$($(CKSUM) $(call quote,$(call uncompiled,$@)) | $(SED) 's/[ ].*//')$(if $(THISREV), --stringparam THISREV $(call quote,$(THISREV)),)$(if $(SRCREV), --stringparam SRCREV $(call quote,$(SRCREV)),) $(call quote,$(BUILDDIR)/transform.xslt) $(call quote,$<)
547 $(call compiled,$(filter $(assetfiles),$(sourcefiles))) : $(BUILDDIR)/public/% : $$(call uncompiled,$$@)
548 @$(PRINTF) '%s\n' $(call quote,Compiling </$*>…)
549 $(silent)$(call ensuredirectory,$(dir $@))
550 $(silent)$(CP) $(call quote,$<) $(call quote,$@)
551
552 # Install compiled files (or error in the case of recursive ones).
553 $(call installed,$(filter $(assetfiles),$(sourcefiles)) $(recursivefiles) $(compilablefiles)) : $(DESTDIR)/% : $(BUILDDIR)/public/%
554 @$(PRINTF) '%s\n' $(call quote,Installing </$*>…)
555 $(silent)$(call ensuredirectory,$(dir $@))
556 $(silent)$(CP) $(call quote,$<) $(call quote,$@)
This page took 0.113561 seconds and 3 git commands to generate.