#!/usr/bin/make -f # SPDX-FileCopyrightText: 2024, 2025, 2026 Lady # SPDX-License-Identifier: MPL-2.0 ## ⋯ 🧮🖍 Codemark ∷ make ∷ documentation.make ## ## ⁌ Documentation makefile ## ## ] Copyright © 2024–2026 Lady [@ Ladys Computer]. ## ] ## ] This Source Code Form is subject to the terms of the Mozilla ## ] Public License, version 2.0. ## ] If a copy of the M·P·L was not distributed with this file, You can ## ] obtain one at {🔗}. SHELL = /bin/sh ## This makefile is used to generate documentation from source files. ## It is an example usage of 🧮🖍 Codemark you may want to use or ## extend for your own projects. # This makefile should be run from the root of the source directory. AWK := awk BASENAME := basename CAT := cat CKSUM := cksum CP := cp DATE := date DIRNAME := dirname FIND := find GIT := git MKDIR := mkdir MV := mv OD := od PRINTF := printf REALPATH := realpath RM := rm SED := sed SORT := sort TEST := test TR := tr XARGS := xargs XSLTPROC := xsltproc CODEMARK := $(or $(patsubst %/make/,%,$(filter %/make/,$(dir $(realpath $(lastword $(MAKEFILE_LIST)))))),.) LESML := @modules.tmp/💄📝 DEFAULTLANG := en DEFAULTPROFILE := urn:fdc:ladys.computer:20260226:codemark:pf:out PROJECTNAME := 🧮🖍 Codemark BUILDDIR := @build.tmp DOCDIR := @documentation.tmp FINDRULES := '!' '(' -name '.*' -o -name '*.test.*' ')' export LANG := C export LC_ALL := C export cmd_BASENAME := $(BASENAME) export cmd_CAT := $(CAT) export cmd_CKSUM := $(CKSUM) export cmd_CP := $(CP) export cmd_DATE := $(DATE) export cmd_DIRNAME := $(DIRNAME) export cmd_MKDIR := $(MKDIR) export cmd_MV := $(MV) export cmd_PRINTF := $(PRINTF) export cmd_REALPATH := $(REALPATH) export cmd_RM := $(RM) export cmd_SED := $(SED) export cmd_SORT := $(SORT) export cmd_TEST := $(TEST) export cmd_TR := $(TR) export cmd_XARGS := $(XARGS) export path_BUILDDIR := $(abspath $(BUILDDIR)) export path_CODEMARK := $(abspath $(CODEMARK)) export lesml_LANG := $(DEFAULTLANG) export lesml_PROFILE := $(DEFAULTPROFILE) SOURCES := $(shell $(FIND) . '(' -type f -a '!' -name '*.license' -o -type d -a '!' '(' '(' -name "@*" -o -name LICENSES ')' -a -prune ')' -o -type d ')'$(if $(FIND_RULES), -a '(' $(FINDRULES) ')',)) override syntaxprograms := $(wildcard $(CODEMARK)/sed/SYNTAXES/*.sed) override sedprograms := $(syntaxprograms) $(CODEMARK)/sed/syntax-comment.sed override syntaxes := lesml $(basename $(notdir $(syntaxprograms))) override docforsource = $(patsubst %,$(DOCDIR)/%.xhtml,$(basename $1)) override sources := $(patsubst ./%,%,$(foreach syntax,$(syntaxes),$(filter %.$(syntax),$(SOURCES)))) override sourcedocs := $(foreach source,$(sources),$(source):$(call docforsource,$(source))) override duplicates := $(strip $(foreach source,$(sources),$(filter-out $(source):%,$(filter %:$(call docforsource,$(source)),$(sourcedocs))))) $(if $(duplicates),$(error Multiple source files map to destination: {$(duplicates)}),) override docs := $(foreach source,$(sources),$(call docforsource,$(source))) override doclesmls := $(patsubst $(DOCDIR)/%.xhtml,$(BUILDDIR)/documentation/%.lesml,$(docs)) override sourcefordoc = $(patsubst %:$1,%,$(filter %:$1,$(sourcedocs))) override define newline endef override empty := override space := $(empty) $(empty) override quote = '$(subst ','"'"',$1)' override perdeccmd := $(SED) 's/|/%7C/g;s/[\]/%5C/g;s/%[0123456789ABCDEFabcdef]\{2\}/|&|/g' | $(TR) '|' '\n' | $(SED) '/^%[0123456789ABCDEFabcdef]\{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}' | $(SED) $(call quote,s/'/'"'"'/g;s/^/'/;s/$$/'/;$$!s/$$/\\/) | $(XARGS) -E '' $(PRINTF) '%b' override perenc = $(shell $(PRINTF) '%s\n' $(foreach unencoded,$1,$(call quote,$(unencoded))) | $(OD) -t x1 | $(SED) 's/^[0123456789]*//;s/0[Aa]/%&/g;s/2[146789ABCDEabcde]/%&/g;s/3[0123456789AaBbDd]/%&/g;s/40/%&/g;s/[46][123456789ABCDEFabcdef]/%&/g;s/[57][0123456789Aa]/%&/g;s/5[Ff]/%&/g;s/7[Ee]/%&/g;s/[ ][0123456789ABCDEFabcdef]\{2\}/%25&/g' | $(TR) -d ' \n' | $(TR) 'abcdef' 'ABCDEF' | $(perdeccmd)) override pathenc = $(subst %2F,/,$(call perenc,$1)) documentation : $(DOCDIR)/index.xhtml $(docs) ; .SECONDEXPANSION: ; processlesml = { $(PRINTF) '%s\n%s' '' ''; } | $(XSLTPROC) --stringparam PROJECT_NAME $(call quote,$(PROJECTNAME)) --stringparam DOCDIR $(call quote,$(call pathenc,$(realpath $(DOCDIR)))) $(CODEMARK)/xslt/documentation.xslt - $(doclesmls) : $(BUILDDIR)/documentation/%.lesml : $$(call sourcefordoc,$(DOCDIR)/$$*.xhtml) $(sedprograms) $(CODEMARK)/sh/codemark.sh @if $(TEST) '!' -d $(call quote,$(dir $@)); then $(MKDIR) -p $(call quote,$(dir $@)); fi @$(PRINTF) '%s\n' $(call quote,Generating documentation for <$<>…) >&2 @$(CODEMARK)/sh/codemark.sh -- $(call quote,$<) >|$(call quote,$@) $(BUILDDIR)/documentation/index.lesml : $(docs) $(sedprograms) $(CODEMARK)/sh/codemark.sh @if $(TEST) '!' -d $(call quote,$(dir $@)); then $(MKDIR) -p $(call quote,$(dir $@)); fi @$(PRINTF) '%s\n' 'Generating documentation index…' >&2 @$(PRINTF) '%s\n\n' '#!lesml@en$$ profile=urn:fdc:ladys.computer:20260226:Codemark:pf:index' $(call quote,⁌ $(PROJECT_NAME) Documentation) $(foreach doc,$(docs), $(call quote,• {🔗./$(patsubst $(DOCDIR)/%,%,$(doc))<$(call pathenc,./$(patsubst $(DOCDIR)/%,%,$(doc)))>})) | $(CODEMARK)/sh/codemark.sh - >|$(call quote,$@) $(docs) $(DOCDIR)/index.xhtml : $(DOCDIR)/%.xhtml : $(BUILDDIR)/documentation/%.lesml $(LESML)/parser.xslt $(CODEMARK)/xslt/documentation.xslt @if $(TEST) '!' -d $(call quote,$(dir $@)); then $(MKDIR) -p $(call quote,$(dir $@)); fi @$(call processlesml,$<) >|$(call quote,$@) $(LESML)/parser.xslt : %/parser.xslt : FORCE $(GIT) submodule update --init $(call quote,$*) FORCE : ; .PHONY : FORCE documentation