]> Lady’s Gitweb - Caudex/blob - GNUmakefile
Enable manual ordering
[Caudex] / GNUmakefile
1 # SPDX-FileCopyrightText: 2024, 2025 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 ╔╡ ⁌ 🪾📰 Caudex ∷ GNUmakefile ╞═══════════════════════════════╗
10 ║╰──────────────────────────────╯ ║
11 ╟┬ ¶ Prerequisites ───────────────────────────────────────────┬╢
12 ║│ │║
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 :— │║
16 ║│ │║
17 ║│ • awk │║
18 ║│ • mkdir │║
19 ║│ • od │║
20 ║│ • printf │║
21 ║│ • sed │║
22 ║│ • test │║
23 ║│ • tr │║
24 ║│ • xargs │║
25 ║│ │║
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 ───────────────────────────────────────────────────┬╢
31 ║│ │║
32 ║│ • `make help (default)´: Print this message. │║
33 ║│ │║
34 ║│ • `make wrmg´: Output a random unused identifier. │║
35 ║│ │║
36 ║│ • `make +⟨CATEGORY⟩´: Create a new entry in ⟨CATEGORY⟩ and │║
37 ║│ output its path. │║
38 ║│ │║
39 ║│ Set `VERBOSE=1´ to see the text of commands as they are │║
40 ║│ executed. │║
41 ║│ │║
42 ║│ See `README.markdown´ for a more involved description of │║
43 ║│ the capabilities and configuration of this program. │║
44 ║╰────────────────────────────────────────────────────────────╯║
45 ╟┬ ¶ Copyright & License ─────────────────────────────────────┬╢
46 ║│ │║
47 ║│ Copyright © 2024–2025 Lady [@ Ladys Computer]. │║
48 ║│ │║
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 ╚══════════════════════════════════════════════════════════════╝
55 endef
56
57 # ━ § MAKE·FILE SETUP ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
58
59 # Programs needed to run this make·file.
60 #
61 # If these are not installed on your computer, or you need to use a different implementation, you can override the appropriate variable.
62 AWK := awk
63 MKDIR := mkdir
64 OD := od
65 PRINTF := printf
66 SED := sed
67 TEST := test
68 TR := tr
69 XARGS := xargs
70
71 # The directory which contains the codex entries and related metadata.
72 SRCDIR := data/codex
73
74 # The default language for new entries.
75 DOCLANG := en
76
77 # Set to a non·empty value to print all commands as they run.
78 VERBOSE :=
79
80 # The default target for this makefile.
81 .DEFAULT_GOAL := help
82
83 # ━ § BEGIN MAKE·FILE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
84
85 # ─ ¶ Non‐Recipe Variable Definitions ─────────────────────────────────
86
87 # A variable which contains a newline, to allow the generation of multiline strings in function calls.
88 override define newline
89
90
91 endef
92
93 # (callable) Quote the given string for use within shell calls.
94 override quote = '$(subst ','"'"',$1)'
95
96 # Outputs an `@´ to silence rules, unless `VERBOSE´ is nonempty.
97 override silent := $(if $(VERBOSE),,@)
98
99 # A random W·R·M·G(·like) base⹀32 identifier.
100 #
101 # This variable returns a different value each time it is referenced.
102 # Use `foreach´ to save the value for repeated usage.
103 #
104 # This variable recursively calls itself to ensure there is no existing entry with the resulting identifier.
105 #
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)))
108
109 # ─ ¶ Recipe Variable Definitions ─────────────────────────────────────
110
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
113
114 # ─ ¶ Phony Targets ───────────────────────────────────────────────────
115
116 # Provide help.
117 help :
118 @$(PRINTF) '%b' $(call quote,$(subst $(newline),\n,$(makefileinfo)))
119
120 # Output a random unused identifier.
121 wrmg :
122 @$(PRINTF) '%s\n' $(wrmg)
123
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)))
129
130 # ─ ¶ Special Targets ─────────────────────────────────────────────────
131
132 # Don’t use any implicit rules.
133 .SUFFIXES : ;
134
135 # Treat targets with this as a prerequisite as though they were phony.
136 #
137 # Mainly useful in pattern rules.
138 FORCE : ;
139
140 # Phony rules; always consider these out·of·date.
141 .PHONY : FORCE help wrmg ;
142
143 # ─ ¶ Build Targets ───────────────────────────────────────────────────
144
145 # Create an empty codex metadata file if none exists.
146 $(SRCDIR)/~ :
147 $(silent)$(PRINTF) '%b@%s$$ profile=urn:fdc:ladys.computer:20240204:Caudex:pf:codex\n%s\n' '\0043!lesml' '$(DOCLANG)' '%%' >|$(call quote,$@)
This page took 0.06064 seconds and 5 git commands to generate.