1 # SPDX-FileCopyrightText: 2023-2024 Lady <https://www.ladys.computer/about/#lady>
2 # SPDX-License-Identifier: MPL-2.0
6 # Copyright © 2023–2024 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/>.
25 DATABUILDDIR := build/data
26 RDFBUILDDIR := build/rdf
27 SITEBUILDDIR := build/site
31 THISDIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
34 MAKEOPTS := CP='$(CP)' FIND='$(FIND)' GIT='$(GIT)' MKDIR='$(MKDIR)' PRINTF='$(PRINTF)' RM='$(RM)' SED='$(SED)' TEST='$(TEST)' TOUCH='$(TOUCH)' XARGS='$(XARGS)'
36 # Stage 1: Build R·D·F files to build/rdf
37 SHUSHEDATAOPTS := $(MAKEOPTS) SRCDIR='$(DATASRCDIR)' INCLUDEDIR='$(DATASRCDIR)' BUILDDIR='$(DATABUILDDIR)' DESTDIR='$(RDFBUILDDIR)' EXTRAPARSERS='$(wildcard $(THISDIR)/parsers/data/*.xslt)' EXTRAPARSERLIBS='$(DATASRCDIR)/ontologies/¦' EXTRAFINDINCLUDERULES='-not '"'"'('"'"' '"'"'('"'"' -name ontologies -o -name profiles '"'"')'"'"' -a -type d -a -prune '"'"')'"'"'' EXTRATRANSFORMS='$(wildcard $(THISDIR)/transforms/data/*.xslt)'
39 # Stage 2: Build the actual site
40 SHUSHESITEOPTS := $(MAKEOPTS) SRCDIR='$(SITESRCDIR)' INCLUDEDIR='$(RDFBUILDDIR)' BUILDDIR='$(SITEBUILDDIR)' DESTDIR='$(DESTDIR)' EXTRAPARSERS='$(wildcard $(THISDIR)/parsers/site/*.xslt)' EXTRATRANSFORMS='$(wildcard $(THISDIR)/transforms/site/*.xslt)'
43 YSEMEOPTS := $(MAKEOPTS) BUILDTARGET='.grass' DESTDIR='$(DESTDIR)' SERVERPATH='lady/vocab'
45 xmls := $(wildcard $(DATASRCDIR)/*/*)
47 # ━ § Call out to ⛩📰 书社 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
49 install : $(SHUSHE)/GNUmakefile build
50 @for publicfile in $(patsubst %,"%",$(wildcard $(DESTDIR)/*)); do if $(GIT) check-ignore -q "$$publicfile"; then $(RM) -rf "$$publicfile"; fi; done
51 @for target in $$($(MAKE) -s -f '$<' listout QUIET=1 $(SHUSHEDATAOPTS)); do $(PRINTF) '%s\n' "$$target" | $(SED) 's/¦/:/g' | $(XARGS) $(PRINTF) 'Copying </%s>…\n' >&2; $(PRINTF) '%s\n' "$$target" | $(SED) 's:^:$(DESTDIR)/:;s/¦/:/g' | $(XARGS) $(CP) '$(RDFBUILDDIR)/'"$$target"; done
52 @for target in $$($(MAKE) -s -f '$<' listout QUIET=1 $(SHUSHESITEOPTS)); do for dir in $$($(FIND) "$(SITEBUILDDIR)/public/$$target" -not -name '.*' -and -type d); do if $(TEST) '!' -d "$(DESTDIR)/$$dir"; then $(PRINTF) '%s\n' "$$dir" | $(SED) 's:$(SITEBUILDDIR)/public/:$(DESTDIR)/:' | $(XARGS) $(MKDIR) -p; fi; done; for file in $$($(FIND) "$(SITEBUILDDIR)/public/$$target" -not '(' -name '.*' -or -type d ')'); do $(PRINTF) '%s\n' "$$file" | $(SED) 's:$(SITEBUILDDIR)/public/:/:;s:/_\(.*\)_\(\..*\)$$:/(\1)\2:g;s/¦/:/g' | $(XARGS) $(PRINTF) 'Copying <%s>…\n' >&2; $(PRINTF) '%s\n' "$$file" | $(SED) 's:$(SITEBUILDDIR)/public/:$(DESTDIR)/:;s:/_\(.*\)_\(\..*\)$$:/(\1)\2:g;s/¦/:/g' | $(XARGS) $(CP) "$$file"; done; done
53 $(TOUCH) '$(BUILDTARGET)'
55 build : $(SHUSHE)/GNUmakefile
56 @$(RM) -rf '$(RDFBUILDDIR)/profiles'
57 @$(MAKE) -f '$<' install $(SHUSHEDATAOPTS)
58 @$(MAKE) -f '$<' $(SHUSHESITEOPTS)
60 clean : $(SHUSHE)/GNUmakefile
61 @$(MAKE) -f '$<' $@ $(SHUSHEDATAOPTS)
62 @$(RM) -rf '$(RDFBUILDDIR)'
63 @$(MAKE) -f '$<' $@ $(SHUSHESITEOPTS)
65 list listout : $(SHUSHE)/GNUmakefile
66 @$(RM) -rf '$(RDFBUILDDIR)/profiles'
67 @$(MAKE) -f '$<' install $(SHUSHEDATAOPTS)
68 @$(MAKE) -f '$<' $@ $(SHUSHESITEOPTS)
70 $(BUILDDIR)/data/% : $(SHUSHE)/GNUmakefile FORCE
71 @$(MAKE) -f '$<' $@ $(SHUSHEDATAOPTS)
73 $(BUILDDIR)/rdf/% : $(SHUSHE)/GNUmakefile FORCE
74 @$(MAKE) -f '$<' $@ $(SHUSHEDATAOPTS)
76 $(BUILDDIR)/site/% : $(SHUSHE)/GNUmakefile FORCE
77 @$(RM) -rf '$(RDFBUILDDIR)/profiles'
78 @$(MAKE) -f '$<' install $(SHUSHEDATAOPTS)
79 @$(MAKE) -f '$<' $@ $(SHUSHESITEOPTS)
81 $(DESTDIR)/% : $(SHUSHE)/GNUmakefile FORCE
82 @$(RM) -rf '$(RDFBUILDDIR)/profiles'
83 @$(MAKE) -f '$<' install $(SHUSHEDATAOPTS)
84 @$(MAKE) -f '$<' $@ $(SHUSHESITEOPTS)
86 # ━ § Call out to 👥📤 Yseme ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
88 dry-sync sync : $(YSEME)/GNUmakefile
89 @$(MAKE) -f '$<' $@ $(YSEMEOPTS)
91 # ━ § Build xmllint ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
93 # This is temporarily required as DTD resolving requires a very new
94 # version of `xmllint´ when a filename contains non‐Ascii characters.
95 # Once `libxml2` ≥ 2.13.2 is more widely available, this subrepo and
96 # build step can probably be dropped.
98 .libxml2/xmllint : .libxml2/autogen.sh
99 $(CD) .libxml2 && ./autogen.sh && ./configure
102 # ━ § Linting ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
104 lint : $(foreach xml,$(xmls),lint][$(xml)) ;
106 $(foreach xml,$(xmls),lint][$(xml)) : lint][% : .libxml2/xmllint
107 @.libxml2/xmllint --valid --noout '$*'
109 # ━ § Special targets ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
111 .IGNORE : $(foreach xml,$(xmls),lint][$(xml)) ;
113 .PHONY : FORCE build clean dry-sync gone lint $(foreach xml,$(xmls),lint][$(xml)) list prebuild sync uninstall ;
115 gone : clean uninstall ;
118 @for publicfile in $(patsubst %,"%",$(wildcard $(DESTDIR)/*)); do if $(GIT) check-ignore -q "$$publicfile"; then $(RM) -rf "$$publicfile"; fi; done
122 # ━ § Make·file targets ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
124 $(SHUSHE)/GNUmakefile $(YSEME)/GNUmakefile : %/GNUmakefile : FORCE
125 $(GIT) submodule update --init '$*'
127 .libxml2/autogen.sh : %/autogen.sh : FORCE
128 $(GIT) submodule update --init '$*'