# SPDX-FileCopyrightText: 2024, 2025 Lady # SPDX-License-Identifier: MPL-2.0 SHELL = /bin/sh # ━ § BASIC INFORMATION ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ override define makefileinfo ╭──────────────────────────────╮ ╔╡ ⁌ 🪾📰 Caudex ∷ GNUmakefile ╞═══════════════════════════════╗ ║╰──────────────────────────────╯ ║ ╟┬ ¶ Prerequisites ───────────────────────────────────────────┬╢ ║│ │║ ║│ Requires G·N·U Make, at least version 3.81. Otherwise, │║ ║│ only programs specified by Posix are required. The full │║ ║│ list of program requirements is as follows :— │║ ║│ │║ ║│ • awk │║ ║│ • mkdir │║ ║│ • od │║ ║│ • printf │║ ║│ • sed │║ ║│ • test │║ ║│ • tr │║ ║│ • xargs │║ ║│ │║ ║│ In all cases, you can supply your own version of any │║ ║│ program `program´ by overriding the corresponding variable │║ ║│ `PROGRAM´ when calling Make. │║ ║╰────────────────────────────────────────────────────────────╯║ ╟┬ ¶ Usage ───────────────────────────────────────────────────┬╢ ║│ │║ ║│ • `make help (default)´: Print this message. │║ ║│ │║ ║│ • `make wrmg´: Output a random unused identifier. │║ ║│ │║ ║│ • `make +⟨CATEGORY⟩´: Create a new entry in ⟨CATEGORY⟩ and │║ ║│ output its path. │║ ║│ │║ ║│ Set `VERBOSE=1´ to see the text of commands as they are │║ ║│ executed. │║ ║│ │║ ║│ See `README.markdown´ for a more involved description of │║ ║│ the capabilities and configuration of this program. │║ ║╰────────────────────────────────────────────────────────────╯║ ╟┬ ¶ Copyright & License ─────────────────────────────────────┬╢ ║│ │║ ║│ Copyright © 2024–2025 Lady [@ Ladys Computer]. │║ ║│ │║ ║│ This Source Code Form is subject to the terms of the │║ ║│ Mozilla Public License, v 2.0. If a copy of the M·P·L was │║ ║│ not distributed with this file, You can obtain one at │║ ║│ . │║ ║╰────────────────────────────────────────────────────────────╯║ ╚══════════════════════════════════════════════════════════════╝ endef # ━ § MAKE·FILE SETUP ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ # Programs needed to run this make·file. # # If these are not installed on your computer, or you need to use a different implementation, you can override the appropriate variable. AWK := awk MKDIR := mkdir OD := od PRINTF := printf SED := sed TEST := test TR := tr XARGS := xargs # The directory which contains the codex entries and related metadata. SRCDIR := data/codex # The default language for new entries. DOCLANG := en # Set to a non·empty value to print all commands as they run. VERBOSE := # The default target for this makefile. .DEFAULT_GOAL := help # ━ § BEGIN MAKE·FILE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ # ─ ¶ Non‐Recipe Variable Definitions ───────────────────────────────── # A variable which contains a newline, to allow the generation of multiline strings in function calls. override define newline endef # (callable) Quote the given string for use within shell calls. override quote = '$(subst ','"'"',$1)' # Outputs an `@´ to silence rules, unless `VERBOSE´ is nonempty. override silent := $(if $(VERBOSE),,@) # A random W·R·M·G(·like) base⹀32 identifier. # # This variable returns a different value each time it is referenced. # Use `foreach´ to save the value for repeated usage. # # This variable recursively calls itself to ensure there is no existing entry with the resulting identifier. # # 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. 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))) # ─ ¶ Recipe Variable Definitions ───────────────────────────────────── # (callable) Check to see if the given directory exists and create it if not. override ensuredirectory = if $(TEST) ! -d $(call quote,$1); then $(MKDIR) -p $(call quote,$1); fi # ─ ¶ Phony Targets ─────────────────────────────────────────────────── # Provide help. help : @$(PRINTF) '%b' $(call quote,$(subst $(newline),\n,$(makefileinfo))) # Output a random unused identifier. wrmg : @$(PRINTF) '%s\n' $(wrmg) # Create a new entry in the provided category and output its path. +% : $(SRCDIR)/~ FORCE $(silent)$(call ensuredirectory,$(SRCDIR)/$*) $(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)/$*/~)) $(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))) # ─ ¶ Special Targets ───────────────────────────────────────────────── # Don’t use any implicit rules. .SUFFIXES : ; # Treat targets with this as a prerequisite as though they were phony. # # Mainly useful in pattern rules. FORCE : ; # Phony rules; always consider these out·of·date. .PHONY : FORCE help wrmg ; # ─ ¶ Build Targets ─────────────────────────────────────────────────── # Create an empty codex metadata file if none exists. $(SRCDIR)/~ : $(silent)$(PRINTF) '%b@%s$$ profile=urn:fdc:ladys.computer:20240204:Caudex:pf:codex\n%s\n' '\0043!lesml' '$(DOCLANG)' '%%' >|$(call quote,$@)