.POSIX:
.SUFFIXES:
HARE=hare
HAREFLAGS=
HAREDOC=haredoc

DESTDIR=
PREFIX=/usr/local
SRCDIR=$(PREFIX)/src
HARESRCDIR=$(SRCDIR)/hare
THIRDPARTYDIR=$(HARESRCDIR)/third-party

all:
	@true # no-op

check:
	$(HARE) test

clean:
	rm -rf docs

docs:
	mkdir -p docs/libtui/layout/vlayout
	mkdir -p docs/libtui/widget/list
	mkdir -p docs/libtui/widget/ed
	$(HAREDOC) -Fhtml libtui > docs/libtui/index.html
	$(HAREDOC) -Fhtml libtui::layout > docs/libtui/layout/index.html
	$(HAREDOC) -Fhtml libtui::layout::vlayout > docs/libtui/layout/vlayout/index.html
	$(HAREDOC) -Fhtml libtui::widget > docs/libtui/widget/index.html
	$(HAREDOC) -Fhtml libtui::widget::list > docs/libtui/widget/list/index.html
	$(HAREDOC) -Fhtml libtui::widget::ed > docs/libtui/widget/ed/index.html

install:
	mkdir -p "$(DESTDIR)$(THIRDPARTYDIR)"
	cp -r libtui "$(DESTDIR)$(THIRDPARTYDIR)"/libtui
	chmod -R 644 "$(DESTDIR)$(THIRDPARTYDIR)"/libtui/*
	chmod 755 "$(DESTDIR)$(THIRDPARTYDIR)"/libtui
	chmod 755 "$(DESTDIR)$(THIRDPARTYDIR)"/libtui/layout
	chmod 755 "$(DESTDIR)$(THIRDPARTYDIR)"/libtui/layout/vlayout
	chmod 755 "$(DESTDIR)$(THIRDPARTYDIR)"/libtui/widget
	chmod 755 "$(DESTDIR)$(THIRDPARTYDIR)"/libtui/widget/list
	chmod 755 "$(DESTDIR)$(THIRDPARTYDIR)"/libtui/widget/ed

uninstall:
	rm -rf $(DESTDIR)$(THIRDPARTYDIR)/libtui

.PHONY: all clean check docs install uninstall
