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

$(HTML_FILTER): %.html: %.txt
	$(QUIET_ASCIIDOC)asciidoctor -b xhtml5 -d manpage -d manpage -I.. -I. -rasciidoctor-extensions \
        -amanversion=$(GIT_VERSION) -amanmanual='Git Manual' -amansource='Git  $(GIT_VERSION)' $<

MANPAGES=$(patsubst %.txt,%.1,$(MAN_FILTER))
$(MANPAGES): %.1: %.txt
	$(QUIET_ASCIIDOC)asciidoctor -b manpage -d manpage -o $@ \
        -I. -I.. -rasciidoctor-extensions \
        -amanmanual='Git Manual' -amansource='Git $(GIT_VERSION)' $<

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

all doc-l10n: man html

install-txt:
	install -d -m 755 $(prefix)/$(lang)
	install *.txt -m 644 $(prefix)/$(lang)

clean:
	rm -f *.1 *.html

endif


mrproper: clean
	rm -f *.txt