1 # SPDX-FileCopyrightText: 2023, 2024, 2025 Lady <https://www.ladys.computer/about/#lady>
2 # SPDX-License-Identifier: MPL-2.0
6 # Copyright © 2023–2025 Lady [@ Ladys Computer].
8 # This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
9 # 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/>.
28 THISDIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
31 MAKEOPTS := CP='$(CP)' FIND='$(FIND)' GIT='$(GIT)' MKDIR='$(MKDIR)' PRINTF='$(PRINTF)' RM='$(RM)' SED='$(SED)' TEST='$(TEST)' TOUCH='$(TOUCH)' XARGS='$(XARGS)'
32 SHUSHEOPTS := $(MAKEOPTS) SRCDIR='$(SRCDIR)' DATADIR='$(DATADIR)' BUILDDIR='$(BUILDDIR)' DESTDIR='$(BUILDDIR)/public' EXTRAPARSERS='$(wildcard $(THISDIR)/parsers/*.xslt)' EXTRAPARSERLIBS='$(DATADIR)/ontologies/¦' EXTRATRANSFORMS='$(wildcard $(THISDIR)/transforms/*.xslt)'
35 YSEMEOPTS := $(MAKEOPTS) BUILDTARGET='$(BUILDTARGET)' DESTDIR='$(DESTDIR)' SERVERPATH='lady/vocab'
39 xmls := $(wildcard $(DATADIR)/*/[0-9A-Za-z_]*) $(wildcard $(DATADIR)/*/¦*)
41 # ━ § Call out to ⛩📰 书社 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
43 install : $(SHUSHE)/GNUmakefile build
44 @for publicfile in $(patsubst %,"%",$(shell $(FIND) '$(DESTDIR)'/*)); do if $(GIT) check-ignore -q "$$publicfile"; then $(RM) -R -f "$$publicfile"; fi; done
45 @for dir in $$($(FIND) '$(BUILDDIR)/public' -type d | $(SED) 's:$(BUILDDIR)/public/::'); do if $(TEST) '!' -d "$(DESTDIR)/$$dir"; then $(MKDIR) -p "$(DESTDIR)/$$dir"; fi; done
46 @for file in $$($(FIND) '$(BUILDDIR)/public' -type f | $(SED) 's:$(BUILDDIR)/public/::'); do $(PRINTF) '%s\n' "$$file" | $(SED) 's:/_\(.*\)_\(\..*\)$$:/(\1)\2:g;s/¦/:/g' | $(XARGS) $(PRINTF) 'Copying <%s>…\n' >&2; $(PRINTF) '%s\n' "$$file" | $(SED) 's:^:$(DESTDIR)/:;s:/_\(.*\)_\(\..*\)$$:/(\1)\2:g;s/¦/:/g' | $(XARGS) $(CP) "$(BUILDDIR)/public/$$file"; done
47 $(TOUCH) '$(BUILDTARGET)'
49 build : $(SHUSHE)/GNUmakefile
50 @$(RM) -R -f '$(BUILDDIR)/public'
51 @$(MAKE) -f '$<' install $(SHUSHEOPTS)
53 clean list listout : $(SHUSHE)/GNUmakefile
54 @$(MAKE) -f '$<' $@ $(SHUSHEOPTS)
56 $(BUILDDIR)/% : $(SHUSHE)/GNUmakefile FORCE
57 @$(MAKE) -f '$<' $@ $(SHUSHEOPTS)
59 # ━ § Call out to 👥📤 Yseme ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
61 dry-sync sync : $(YSEME)/GNUmakefile
62 @$(MAKE) -f '$<' $@ $(YSEMEOPTS)
64 # ━ § Build xmllint ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
66 # This is temporarily required as DTD resolving requires a very new
67 # version of `xmllint´ when a filename contains non‐Ascii characters.
68 # Once `libxml2` ≥ 2.13.2 is more widely available, this subrepo and
69 # build step can probably be dropped.
71 .libxml2/xmllint : .libxml2/autogen.sh
72 cd .libxml2 && ./autogen.sh
75 # ━ § Linting ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
77 lint : $(foreach xml,$(xmls),lint][$(xml)) ;
79 $(foreach xml,$(xmls),lint][$(xml)) : lint][% : .libxml2/xmllint
80 @.libxml2/xmllint --valid --noout '$*'
82 # ━ § Special targets ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
84 .IGNORE : $(foreach xml,$(xmls),lint][$(xml)) ;
86 .PHONY : FORCE build clean dry-sync gone lint $(foreach xml,$(xmls),lint][$(xml)) list prebuild serve sync uninstall ;
88 gone : clean uninstall ;
91 @printf '%b\n' '\0033[1m\n\0033[7m NOTE: \0033[27m Visit <http://localhost:$(PORT)/> to view the site.\n\0033[7m \0033[27m \n\0033[7m \0033[27m Press control + C to exit.\n\0033[22m' >&2
92 @ruby ./scripts/serve.rb $(PORT) >&2
95 @for publicfile in $(patsubst %,"%",$(wildcard $(DESTDIR)/*)); do if $(GIT) check-ignore -q "$$publicfile"; then $(RM) -rf "$$publicfile"; fi; done
99 # ━ § Make·file targets ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
101 $(SHUSHE)/GNUmakefile $(YSEME)/GNUmakefile : %/GNUmakefile : FORCE
102 $(GIT) submodule update --init '$*'
104 .libxml2/autogen.sh : %/autogen.sh : FORCE
105 $(GIT) submodule update --init '$*'