# SPDX-FileCopyrightText: 2024 Lady <https://www.ladys.computer/about/#lady>
# SPDX-License-Identifier: MPL-2.0

SHELL = sh

# Copyright � 2024 Lady [@ Ladys Computer].
#
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# 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/>.

xmls := $(wildcard data/*/bibl) $(wildcard data/*/info) $(wildcard data/*/fortunes/*)

lint : $(foreach xml,$(xmls),lint][$(xml)) ;

$(foreach xml,$(xmls),lint][$(xml)) : lint][% :
	@xmllint --valid --noout '$*'
	@$(if $(findstring /fortunes/,$*),if ! xmllint --xpath '//*[local-name()="seg" and namespace-uri()="http://www.tei-c.org/ns/1.0" and @type="callout"]' '$*' >/dev/null 2>/dev/null; then printf '%s\n' 'No callout in file <$*>'; false; fi; if xmllint --xpath '//*[local-name()="seg" and namespace-uri()="http://www.tei-c.org/ns/1.0" and @type="callout"][2]' '$*' >/dev/null 2>/dev/null; then printf '%s\n' 'Multiple callouts in file <$*>'; false; fi,:)

.IGNORE : $(foreach xml,$(xmls),lint][$(xml)) ;

.PHONY : lint $(foreach xml,$(xmls),lint][$(xml)) ;