2 # SPDX-FileCopyrightText: 2025 Lady <https://www.ladys.computer/about/#lady>
3 # SPDX-License-Identifier: MPL-2.0
7 # This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
8 # If a copy of the M·P·L was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
10 # This make·file should be run from the root of the source directory.
25 PROJECT_NAME
:= C·Girls
27 HEADER_FILES
= $(sort $(patsubst .
/%,%,$(shell find .
'(' -path
'.' -o
-prune
')' -a
-type f
-a
-name
'*.h')))
28 DOCUMENTATION_FILES
= $(patsubst %.h
,$(DOCDIR
)/%.xhtml
,$(HEADER_FILES
))
30 documentation
: $(DOCDIR
)/README.xhtml
$(DOCUMENTATION_FILES
) $(DOCDIR
)/index.xhtml
;
32 # (callable) Strip portions between `(*´ and `*)´ and collapse newlines in the argument.
33 # Backslash sequences in the argument are handled ⅌ `printf´.
34 # Single quotes must not appear in the argument or this will break.
35 makeunreadable
= $(shell LANG
=C LC_ALL
=C printf
'%s\n' '$(subst $(newline),$(space),$1)' |
$(SED
) 's/^ *//;s/ *$$//;s/ *([*][^*]*[*]) *//g' |
$(XARGS
) -0 $(PRINTF
) '%b\n')
38 \\@^
/[*]$$@
,\\@^
[\t]*[*]/$$@d
; (*delete multiline comments
*)
39 \\@^
/[*][^
*]*.?
[^
/]*[*]/$$@d
; (*delete singleline traditional comments
*)
40 \\@^
//@d
; (*delete singleline newstyle comments
*)
41 \\@^
/[*][*]$$@s@^.
*$$@@
; (*delete start of documentation comments
(leaving newline
)*)
42 \\@^
[*][*]//*$$@s@^.
*$$@@
; (*delete end of documentation comments
(leaving newline
)*)
43 \\@^
[*][*]$$@s@
$$@ @
; (*add trailing space to empty documentation comment lines
*)
44 \\@^
[*][*] @
!{\\@.@s@^@
\t|
`@;\\@.@s@$$@´@;}; (*format non·empty lines of code*)
45 \\@^ [*][*] @{s@^ [*][*] [ \t]*@@;s@ :—@ :—@g;s@« @« @g;s@‹ @‹ @g;s@—: @—: @g;s@ »@ »@g;s@ ›@ ›@g;s@{<\\([^>]*\\)[.]h>}@{🔗`\\1`<./\\1>}@;}; (*drop prefix from documentation lines and format*)
47 sedcmd := $(call makeunreadable,$(readablesedcmd))
49 define readablestylesheet
51 article{ Margin: Auto; Width: Min-Content; Max-Width: 100% }
52 article::after{ Display: Block; Width: 31REM; Max-Width: 100%; Min-Width: 100%; Content: "" }
53 blockquote>pre{ Margin: Auto; Width: 71CH; Max-Width: 100%; White-Space: Pre-Wrap }
54 blockquote>pre+pre{ Margin-Top: 1LH }
56 stylesheet := $(call makeunreadable,$(readablestylesheet))
58 # The first argument should be shell commands producing Les·M·L; the second should be the title of the page.
59 processlesml = { $(PRINTF) '%s\n' '<?xml version="1.0"?>' '<html xmlns="http://www.w3.org/1999/xhtml"><head><title>$2</title><style>$(stylesheet)</style></head><body>'; { $(PRINTF) '%s\n%s' '<?xml version="1.0"?>' '<script xmlns="http://www.w3.org/1999/xhtml" type="text/lesml"><![CDATA['; $1; $(PRINTF) '\n%s\n' ']]></script>'; } | xsltproc $(LESML)/parser.xslt - | $(SED) '1{/^<?xml/d;}'; $(PRINTF) '%s\n' '</body></html>' ; }
61 $(DOCUMENTATION_FILES) : $(DOCDIR)/%.xhtml : %.h $(LESML)/parser.xslt
62 @if $(TEST) '!' -d $(DOCDIR); then $(MKDIR) -p $(DOCDIR); fi
63 @$(PRINTF) '%s\n' 'Building documentation for <$<>…' >&2
64 @$(call processlesml,$(PRINTF) '%s\n\n' '#!lesml@en$$' '⁌ Documentation for `<$<>´
'; $(SED) '$(sedcmd
)' <'$<'; $(PRINTF) '\n\n%s
' '⁂
' 'A part of
{🔗
$(PROJECT_NAME
) Documentation
<.
/index.xhtml
>}.
',Documentation for <$<> | $(PROJECT_NAME) Documentation) >|'$@
'
67 $(DOCDIR)/README.xhtml : README $(LESML)/parser.xslt
68 @$(PRINTF) '%s
\n' 'Building documentation README…
' >&2
69 @$(call processlesml,$(CAT) README; $(PRINTF) '\n\n%s
' '⁂
' 'A part of
{🔗
$(PROJECT_NAME
) Documentation
<.
/index.xhtml
>}.
',$(PROJECT_NAME) Readme | $(PROJECT_NAME) Documentation) >|'$@
'
71 $(DOCDIR)/index.xhtml : FORCE $(LESML)/parser.xslt
72 @$(PRINTF) '%s
\n' 'Building documentation index…
' >&2
73 @$(call processlesml,$(PRINTF) '%s
\n\n' '#!lesml@en$$' '⁌ $(PROJECT_NAME) Documentation' '• {🔗$(PROJECT_NAME) Readme<./README.xhtml>}'$(foreach header,$(HEADER_FILES), '• {🔗Documentation for `$(header)´<./$(patsubst %.h,./%.xhtml,$(header))>}'),$(PROJECT_NAME) Documentation) >|'$@'
75 $(LESML
)/parser.xslt
: %/parser.xslt
: FORCE
76 $(GIT
) submodule update
--init
'$*'
79 .PHONY
: FORCE documentation