vpath GIT-VERSION-FILE . ..

MAN_FILTER = $(wildcard git*.txt)
HTML_FILTER = $(patsubst %.txt,%.html,$(MAN_FILTER))


ifeq ($(wildcard ../../build-docdep.perl),../../build-docdep.perl)

vpath %conf . .. ../..
vpath %in . .. ../..
vpath %xsl . .. ../..
vpath %rb  . .. ../..

ifdef mandir
tmp_mandir := $(mandir)
mandir = $(tmp_mandir)/$(lang)
else
mandir = $(prefix)/share/man/$(lang)
endif

include ../../Makefile

XMLTO_EXTRA += --searchpath ../..
ifdef USE_ASCIIDOCTOR
ASCIIDOC_EXTRA += -I../.. -I. -rasciidoctor-extensions
else
ASCIIDOC_CONF = -f ../../asciidoc.conf
endif
doc-l10n: all

install-l10n:
	$(INSTALL) -d -m 755 $(DESTDIR)$(man1dir)
	$(INSTALL) -d -m 755 $(DESTDIR)$(man5dir)
	$(INSTALL) -d -m 755 $(DESTDIR)$(man7dir)
	if [ ! -z "$(DOC_MAN1)" ]; then $(INSTALL) -m 644 $(DOC_MAN1) $(DESTDIR)$(man1dir); fi
	if [ ! -z "$(DOC_MAN5)" ]; then $(INSTALL) -m 644 $(DOC_MAN5) $(DESTDIR)$(man5dir); fi
	if [ ! -z "$(DOC_MAN7)" ]; then $(INSTALL) -m 644 $(DOC_MAN7) $(DESTDIR)$(man7dir); fi


else
ifndef V
	QUIET_PO4A      = @echo '   ' PO4A $(lang) $@;
	QUIET_ASCIIDOC	= @echo '   ' ASCIIDOC $(lang) $@;
endif

-include ../GIT-VERSION-FILE
ASCIIDOC_EXTRA = -d manpage -I.. -I. -rasciidoctor-extensions
ASCIIDOC_EXTRA += -amanmanual='Git Manual' \
                  -amansource='Git $(GIT_VERSION)' \
                  -amanversion=$(GIT_VERSION)
ASCIIDOC_EXTRA += -alitdd='\--'
ASCIIDOC_EXTRA += -acompat-mode -atabsize=8

$(HTML_FILTER): %.html: %.txt
	$(QUIET_ASCIIDOC)asciidoctor -b xhtml5 \
        $(ASCIIDOC_EXTRA) $<

MANPAGES=$(patsubst %.txt,%.1,$(MAN_FILTER))
$(MANPAGES): %.1: %.txt
	$(QUIET_ASCIIDOC)asciidoctor -b manpage -o $@ \
        $(ASCIIDOC_EXTRA) $<

man: $(MANPAGES)
html: $(HTML_FILTER)

all doc-l10n: man html

install-txt:
	install -d -m 755 $(prefix)/$(lang)
	[ -z "$$(ls *.txt 2>/dev/null)" ] || install *.txt -m 644 $(prefix)/$(lang)
	[ -z "$$(ls *.html 2>/dev/null)" ] || install *.html -m 644 $(prefix)/$(lang)

clean:
	rm -f *.1 *.html

endif


mrproper: clean
	rm -f *.txt