##
## This makefile is not used during regular build. It has to be called
## separately
##

STATIC_FILES = $(srcdir)/man-bugs.adoc $(srcdir)/attributes.adoc	\
$(srcdir)/man-authors.adoc

GENERATED_FILES = $(srcdir)/csv2yapet.adoc $(srcdir)/yapet2csv.adoc	\
$(srcdir)/yapet.adoc $(srcdir)/yapet_colors.adoc			\
$(srcdir)/yapet_config.adoc $(srcdir)/README.adoc			\
$(srcdir)/INSTALL.adoc $(srcdir)/NEWS.adoc

TARGETS_TEXT = INSTALL README NEWS

TARGETS = $(srcdir)/Doxyfile $(srcdir)/INSTALL.html			\
$(srcdir)/NEWS.html $(srcdir)/README.html		\
$(srcdir)/yapet.html $(srcdir)/yapet.1 $(srcdir)/csv2yapet.html		\
$(srcdir)/csv2yapet.1 $(srcdir)/yapet2csv.html $(srcdir)/yapet2csv.1	\
$(srcdir)/yapet_colors.5 $(srcdir)/yapet_colors.html			\
$(srcdir)/yapet_config.5 $(srcdir)/yapet_config.html $(TARGETS_TEXT)

editfile = $(SED) -e 's|@PACKAGE_STRING[@]|$(PACKAGE_STRING)|g' \
	-e 's|@PACKAGE_VERSION[@]|$(PACKAGE_VERSION)|g' \
	-e 's|@PACKAGE_NAME[@]|$(PACKAGE_NAME)|g' \
	-e 's|@PACKAGE[@]|$(PACKAGE)|g' \
	-e 's|@PACKAGE_TARNAME[@]|$(PACKAGE_TARNAME)|g' \
	-e 's|@srcdir[@]|$(srcdir)|g' \
	-e 's|@top_srcdir[@]|$(top_srcdir)|g' \
	-e 's|@top_builddir[@]|$(top_builddir)|g' \
	-e 's|@builddir[@]|$(builddir)|g'

all: $(TARGETS)

.adoc.in.adoc: Makefile.doc
	$(editfile) $< > $@

.adoc.html: $(GENERATED_FILES) $(STATIC_FILES)
	asciidoctor -b html5 -o $@ $<

$(TARGETS_TEXT): $(GENERATED_FILES)
	cp $(srcdir)/$@.adoc $(top_srcdir)/$@

.adoc.1: $(GENERATED_FILES) $(STATIC_FILES)
	asciidoctor -b manpage -o $@ $<

.adoc.5: $(GENERATED_FILES) $(STATIC_FILES)
	asciidoctor -b manpage -o $@ $<

$(srcdir)/Doxyfile: $(srcdir)/Doxyfile.in
	$(editfile) $< > $@

clean:
	rm -rf source-doc
	rm -f  $(GENERATED_FILES) $(TARGETS)

SUFFIXES = .html .1 .5 .adoc .adoc.in
