SHELL = /bin/sh

# © 2023–2024 Lady [@ Lady’s Computer].
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

SHUSHE := .shushe
SHUSHE_OPTIONS := INCLUDEDIR='sources/INCLUDE' TRANSFORMS='$(wildcard transforms/*.xslt) $(wildcard $(SHUSHE)/transforms/*.xslt)'

YSEME := .yseme
YSEME_OPTIONS := DESTDIR=public SERVERPATH=lady/www

build: $(SHUSHE)/GNUmakefile
	rm -rf ./public
	@$(MAKE) -f $< install $(SHUSHE_OPTIONS)
	touch .grass

list: $(SHUSHE)/GNUmakefile
	@$(MAKE) -f $< $@ $(SHUSHE_OPTIONS)

$(SHUSHE)/GNUmakefile $(YSEME)/GNUmakefile: %/GNUmakefile:
	git submodule update --init $*

GNUmakefile: $(SHUSHE)/GNUmakefile $(YSEME)/GNUmakefile
	touch GNUmakefile

ifneq ($(wildcard $(YSEME)/GNUmakefile),)
YSEME_TARGETS := $(shell sed '/^\.PHONY[ :]/!d;/^\.PHONY[ :]/s/ *;.*//;/^\.PHONY[ :]/s/\.PHONY.*: *//' < $(YSEME)/GNUmakefile)

$(YSEME_TARGETS): $(YSEME)/GNUmakefile
	@$(MAKE) -f $< $@ $(YSEME_OPTIONS)
endif

.PHONY: build list $(YSEME_TARGETS);