162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci# Based on bpftool's Documentation Makefile
362306a36Sopenharmony_ci
462306a36Sopenharmony_ciINSTALL		?= install
562306a36Sopenharmony_ciRM		?= rm -f
662306a36Sopenharmony_ciRMDIR		?= rmdir --ignore-fail-on-non-empty
762306a36Sopenharmony_ci
862306a36Sopenharmony_ciPREFIX		?= /usr/share
962306a36Sopenharmony_ciMANDIR		?= $(PREFIX)/man
1062306a36Sopenharmony_ciMAN1DIR		= $(MANDIR)/man1
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ciMAN1_RST	= $(wildcard rtla*.rst)
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci_DOC_MAN1	= $(patsubst %.rst,%.1,$(MAN1_RST))
1562306a36Sopenharmony_ciDOC_MAN1	= $(addprefix $(OUTPUT),$(_DOC_MAN1))
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ciRST2MAN_DEP	:= $(shell command -v rst2man 2>/dev/null)
1862306a36Sopenharmony_ciRST2MAN_OPTS	+= --verbose
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ciTEST_RST2MAN = $(shell sh -c "rst2man --version > /dev/null 2>&1 || echo n")
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci$(OUTPUT)%.1: %.rst
2362306a36Sopenharmony_ciifndef RST2MAN_DEP
2462306a36Sopenharmony_ci	$(info ********************************************)
2562306a36Sopenharmony_ci	$(info ** NOTICE: rst2man not found)
2662306a36Sopenharmony_ci	$(info **)
2762306a36Sopenharmony_ci	$(info ** Consider installing the latest rst2man from your)
2862306a36Sopenharmony_ci	$(info ** distribution, e.g., 'dnf install python3-docutils' on Fedora,)
2962306a36Sopenharmony_ci	$(info ** or from source:)
3062306a36Sopenharmony_ci	$(info **)
3162306a36Sopenharmony_ci	$(info **  https://docutils.sourceforge.io/docs/dev/repository.html )
3262306a36Sopenharmony_ci	$(info **)
3362306a36Sopenharmony_ci	$(info ********************************************)
3462306a36Sopenharmony_ci	$(error NOTICE: rst2man required to generate man pages)
3562306a36Sopenharmony_ciendif
3662306a36Sopenharmony_ci	rst2man $(RST2MAN_OPTS) $< > $@
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ciman1: $(DOC_MAN1)
3962306a36Sopenharmony_ciman: man1
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ciclean:
4262306a36Sopenharmony_ci	$(RM) $(DOC_MAN1)
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ciinstall: man
4562306a36Sopenharmony_ci	$(INSTALL) -d -m 755 $(DESTDIR)$(MAN1DIR)
4662306a36Sopenharmony_ci	$(INSTALL) -m 644 $(DOC_MAN1) $(DESTDIR)$(MAN1DIR)
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ciuninstall:
4962306a36Sopenharmony_ci	$(RM) $(addprefix $(DESTDIR)$(MAN1DIR)/,$(_DOC_MAN1))
5062306a36Sopenharmony_ci	$(RMDIR) $(DESTDIR)$(MAN1DIR)
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci.PHONY: man man1 clean install uninstall
5362306a36Sopenharmony_ci.DEFAULT_GOAL := man
54