1 # SPDX-FileCopyrightText: 2024, 2025 Lady <https://www.ladys.computer/about/#lady>
2 # SPDX-License-Identifier: MPL-2.0
6 # ━ § BASIC INFORMATION ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
7 override define makefileinfo
8 ╭──────────────────────────────╮
9 ╔╡ ⁌ 📰 Caudex ∷ GNUmakefile ╞═══════════════════════════════╗
10 ║╰──────────────────────────────╯ ║
11 ╟┬ ¶ Prerequisites ───────────────────────────────────────────┬╢
13 ║│ Requires G·N·U Make, at least version 3.81. Otherwise, │║
14 ║│ only programs specified by Posix are required. The full │║
15 ║│ list of program requirements is as follows :— │║
26 ║│ In all cases, you can supply your own version of any │║
27 ║│ program `program´ by overriding the corresponding variable │║
28 ║│ `PROGRAM´ when calling Make. │║
29 ║╰────────────────────────────────────────────────────────────╯║
30 ╟┬ ¶ Usage ───────────────────────────────────────────────────┬╢
32 ║│ • `make help (default)´: Print this message. │║
34 ║│ • `make wrmg´: Output a random unused identifier. │║
36 ║│ • `make +⟨CATEGORY⟩´: Create a new entry in ⟨CATEGORY⟩ and │║
37 ║│ output its path. │║
39 ║│ Set `VERBOSE=1´ to see the text of commands as they are │║
42 ║│ See `README.markdown´ for a more involved description of │║
43 ║│ the capabilities and configuration of this program. │║
44 ║╰────────────────────────────────────────────────────────────╯║
45 ╟┬ ¶ Copyright & License ─────────────────────────────────────┬╢
47 ║│ Copyright © 2024–2025 Lady [@ Ladys Computer]. │║
49 ║│ This Source Code Form is subject to the terms of the │║
50 ║│ Mozilla Public License, v 2.0. If a copy of the M·P·L was │║
51 ║│ not distributed with this file, You can obtain one at │║
52 ║│ <http://mozilla.org/MPL/2.0/>. │║
53 ║╰────────────────────────────────────────────────────────────╯║
54 ╚══════════════════════════════════════════════════════════════╝
57 # ━ § MAKE·FILE SETUP ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
59 # Programs needed to run this make·file.
61 # If these are not installed on your computer, or you need to use a different implementation, you can override the appropriate variable.
71 # The directory which contains the codex entries and related metadata.
74 # The default language for new entries.
77 # Set to a non·empty value to print all commands as they run.
80 # The default target for this makefile.
83 # ━ § BEGIN MAKE·FILE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
85 # ─ ¶ Non‐Recipe Variable Definitions ─────────────────────────────────
87 # A variable which contains a newline, to allow the generation of multiline strings in function calls.
88 override define newline
93 # (callable) Quote the given string for use within shell calls.
94 override quote = '$(subst ','"'"',$1)'
96 # Outputs an `@´ to silence rules, unless `VERBOSE´ is nonempty.
97 override silent := $(if $(VERBOSE),,@)
99 # A random W·R·M·G(·like) base⹀32 identifier.
101 # This variable returns a different value each time it is referenced.
102 # Use `foreach´ to save the value for repeated usage.
104 # This variable recursively calls itself to ensure there is no existing entry with the resulting identifier.
106 # The checksum digits differ from W·R·M·G to get around limitations in Make and to enable usage with·in a U·R·N.
107 override wrmg = $(foreach attempt,$(shell $(OD) -t u4 -N 4 /dev/random | $(SED) 's/^[0-9]* *//' | $(TR) -d ' \n' | $(AWK) 'BEGIN{chars="0123456789ABCDEFGHJKMNPQRSTVWXYZ+!@=U"}{d=32^5;r=$$0%(32^6);printf("%s",substr(chars,r%37,1));while(d>0){printf("%s", substr(chars,int(r/d),1));if(d==32^4)printf("%s", "-");r%=d;d=int(d/32)}}'),$(if $(wildcard $(SRCDIR)/*/$(attempt)*),$(call wrmg),$(attempt)))
109 # ─ ¶ Recipe Variable Definitions ─────────────────────────────────────
111 # (callable) Check to see if the given directory exists and create it if not.
112 override ensuredirectory = if $(TEST) ! -d $(call quote,$1); then $(MKDIR) -p $(call quote,$1); fi
114 # ─ ¶ Phony Targets ───────────────────────────────────────────────────
118 @$(PRINTF) '%b' $(call quote,$(subst $(newline),\n,$(makefileinfo)))
120 # Output a random unused identifier.
122 @$(PRINTF) '%s\n' $(wrmg)
124 # Create a new entry in the provided category and output its path.
125 +% : $(SRCDIR)/~ FORCE
126 $(silent)$(call ensuredirectory,$(SRCDIR)/$*)
127 $(if $(wildcard $(SRCDIR)/$*/~),,$(silent)$(PRINTF) '%b@%s$$ profile=urn:fdc:ladys.computer:20240204:Caudex:pf:category\n%s\n' '\0043!lesml' '$(DOCLANG)' '%%' >|$(call quote,$(SRCDIR)/$*/~))
128 $(foreach identifier,$(wrmg),$(silent)$(PRINTF) '%b@%s$$ profile=urn:fdc:ladys.computer:20240204:Caudex:pf:entry\n%s\n' '\0043!lesml' '$(DOCLANG)' '%%' >|$(call quote,$(SRCDIR)/$*/$(identifier))$(newline)$(silent)$(PRINTF) '%s\n' $(call quote,$(SRCDIR)/$*/$(identifier)))
130 # ─ ¶ Special Targets ─────────────────────────────────────────────────
132 # Don’t use any implicit rules.
135 # Treat targets with this as a prerequisite as though they were phony.
137 # Mainly useful in pattern rules.
140 # Phony rules; always consider these out·of·date.
141 .PHONY : FORCE help wrmg ;
143 # ─ ¶ Build Targets ───────────────────────────────────────────────────
145 # Create an empty codex metadata file if none exists.
147 $(silent)$(PRINTF) '%b@%s$$ profile=urn:fdc:ladys.computer:20240204:Caudex:pf:codex\n%s\n' '\0043!lesml' '$(DOCLANG)' '%%' >|$(call quote,$@)