]> Lady’s Gitweb - Codemark/blob - make/documentation.make
Initial commit
[Codemark] / make / documentation.make
1 #!/usr/bin/make -f
2 # SPDX-FileCopyrightText: 2024, 2025, 2026 Lady <https://www.ladys.computer/about/#lady>
3 # SPDX-License-Identifier: MPL-2.0
4
5 ## ⋯ 🧮🖍 Codemark ∷ make ∷ documentation.make
6 ##
7 ## ⁌ Documentation makefile
8 ##
9 ## ] Copyright © 2024–2026 Lady [@ Ladys Computer].
10 ## ]
11 ## ] This Source Code Form is subject to the terms of the Mozilla
12 ## ] Public License, version 2.0.
13 ## ] If a copy of the M·P·L was not distributed with this file, You can
14 ## ] obtain one at {🔗<https://mozilla.org/MPL/2.0/>}.
15
16 SHELL = /bin/sh
17
18 ## This makefile is used to generate documentation from source files.
19 ## It is an example usage of 🧮🖍 Codemark you may want to use or
20 ## extend for your own projects.
21
22 # This makefile should be run from the root of the source directory.
23
24 AWK := awk
25 BASENAME := basename
26 CAT := cat
27 CKSUM := cksum
28 CP := cp
29 DATE := date
30 DIRNAME := dirname
31 FIND := find
32 GIT := git
33 MKDIR := mkdir
34 MV := mv
35 OD := od
36 PRINTF := printf
37 REALPATH := realpath
38 RM := rm
39 SED := sed
40 SORT := sort
41 TEST := test
42 TR := tr
43 XARGS := xargs
44 XSLTPROC := xsltproc
45
46 CODEMARK := $(or $(patsubst %/make/,%,$(filter %/make/,$(dir $(realpath $(lastword $(MAKEFILE_LIST)))))),.)
47 LESML := @modules.tmp/💄📝
48
49 DEFAULTLANG := en
50 DEFAULTPROFILE := urn:fdc:ladys.computer:20260226:codemark:pf:out
51
52 PROJECTNAME := 🧮🖍 Codemark
53
54 BUILDDIR := @build.tmp
55 DOCDIR := @documentation.tmp
56
57 FINDRULES := '!' '(' -name '.*' -o -name '*.test.*' ')'
58
59 export LANG := C
60 export LC_ALL := C
61
62 export cmd_BASENAME := $(BASENAME)
63 export cmd_CAT := $(CAT)
64 export cmd_CKSUM := $(CKSUM)
65 export cmd_CP := $(CP)
66 export cmd_DATE := $(DATE)
67 export cmd_DIRNAME := $(DIRNAME)
68 export cmd_MKDIR := $(MKDIR)
69 export cmd_MV := $(MV)
70 export cmd_PRINTF := $(PRINTF)
71 export cmd_REALPATH := $(REALPATH)
72 export cmd_RM := $(RM)
73 export cmd_SED := $(SED)
74 export cmd_SORT := $(SORT)
75 export cmd_TEST := $(TEST)
76 export cmd_TR := $(TR)
77 export cmd_XARGS := $(XARGS)
78
79 export path_BUILDDIR := $(abspath $(BUILDDIR))
80 export path_CODEMARK := $(abspath $(CODEMARK))
81
82 export lesml_LANG := $(DEFAULTLANG)
83 export lesml_PROFILE := $(DEFAULTPROFILE)
84
85 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) ')',))
86
87 override syntaxprograms := $(wildcard $(CODEMARK)/sed/SYNTAXES/*.sed)
88
89 override sedprograms := $(syntaxprograms) $(CODEMARK)/sed/syntax-comment.sed
90
91 override syntaxes := lesml $(basename $(notdir $(syntaxprograms)))
92
93 override docforsource = $(patsubst %,$(DOCDIR)/%.xhtml,$(basename $1))
94
95 override sources := $(patsubst ./%,%,$(foreach syntax,$(syntaxes),$(filter %.$(syntax),$(SOURCES))))
96
97 override sourcedocs := $(foreach source,$(sources),$(source):$(call docforsource,$(source)))
98
99 override duplicates := $(strip $(foreach source,$(sources),$(filter-out $(source):%,$(filter %:$(call docforsource,$(source)),$(sourcedocs)))))
100 $(if $(duplicates),$(error Multiple source files map to destination: {$(duplicates)}),)
101
102 override docs := $(foreach source,$(sources),$(call docforsource,$(source)))
103
104 override doclesmls := $(patsubst $(DOCDIR)/%.xhtml,$(BUILDDIR)/documentation/%.lesml,$(docs))
105
106 override sourcefordoc = $(patsubst %:$1,%,$(filter %:$1,$(sourcedocs)))
107
108 override define newline
109
110
111 endef
112 override empty :=
113 override space := $(empty) $(empty)
114
115 override quote = '$(subst ','"'"',$1)'
116
117 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'
118 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))
119 override pathenc = $(subst %2F,/,$(call perenc,$1))
120
121 documentation : $(DOCDIR)/index.xhtml $(docs) ;
122
123 .SECONDEXPANSION: ;
124
125 processlesml = { $(PRINTF) '%s\n%s' '<?xml version="1.0"?>' '<script xmlns="http://www.w3.org/1999/xhtml" type="text/lesml"><![CDATA['; $(CAT) -- $(call quote,$1); $(PRINTF) '\n%s\n' ']]></script>'; } | $(XSLTPROC) --stringparam PROJECT_NAME $(call quote,$(PROJECTNAME)) --stringparam DOCDIR $(call quote,$(call pathenc,$(realpath $(DOCDIR)))) $(CODEMARK)/xslt/documentation.xslt -
126
127 $(doclesmls) : $(BUILDDIR)/documentation/%.lesml : $$(call sourcefordoc,$(DOCDIR)/$$*.xhtml) $(sedprograms) $(CODEMARK)/sh/codemark.sh
128 @if $(TEST) '!' -d $(call quote,$(dir $@)); then $(MKDIR) -p $(call quote,$(dir $@)); fi
129 @$(PRINTF) '%s\n' $(call quote,Generating documentation for <$<>…) >&2
130 @$(CODEMARK)/sh/codemark.sh -- $(call quote,$<) >|$(call quote,$@)
131
132 $(BUILDDIR)/documentation/index.lesml : $(docs) $(sedprograms) $(CODEMARK)/sh/codemark.sh
133 @if $(TEST) '!' -d $(call quote,$(dir $@)); then $(MKDIR) -p $(call quote,$(dir $@)); fi
134 @$(PRINTF) '%s\n' 'Generating documentation index…' >&2
135 @$(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,$@)
136
137 $(docs) $(DOCDIR)/index.xhtml : $(DOCDIR)/%.xhtml : $(BUILDDIR)/documentation/%.lesml $(LESML)/parser.xslt $(CODEMARK)/xslt/documentation.xslt
138 @if $(TEST) '!' -d $(call quote,$(dir $@)); then $(MKDIR) -p $(call quote,$(dir $@)); fi
139 @$(call processlesml,$<) >|$(call quote,$@)
140
141 $(LESML)/parser.xslt : %/parser.xslt : FORCE
142 $(GIT) submodule update --init $(call quote,$*)
143
144 FORCE : ;
145 .PHONY : FORCE documentation
This page took 0.054947 seconds and 5 git commands to generate.