man_MANS =
CLEANFILES =
EXTRA_DIST =

XSLTPROC = xsltproc

XSLTPROC_FLAGS = --xinclude --nonet

XSLTPROC_MAN_FLAGS = \
	$(XSLTPROC_FLAGS) \
	--stringparam man.output.quietly 1 \
	--stringparam funcsynopsis.style ansi \
	--stringparam man.th.extra1.suppress 1 \
	--stringparam man.authors.section.enabled 0 \
	--stringparam man.copyright.section.enabled 0 \
	http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl

if ENABLE_GTK_DOC

%.1: %.xml common.ent
	$(AM_V_GEN) xsltproc $(XSLTPROC_MAN_FLAGS) $<

%.5: %.xml common.ent
	$(AM_V_GEN) xsltproc $(XSLTPROC_MAN_FLAGS) $<

%.7: %.xml common.ent
	$(AM_V_GEN) xsltproc $(XSLTPROC_MAN_FLAGS) $<

%.8: %.xml common.ent
	$(AM_V_GEN) xsltproc $(XSLTPROC_MAN_FLAGS) $<

endif

if BUILD_SETTING_DOCS

nm-settings.xml: nm-settings.xsl $(top_builddir)/libnm/nm-setting-docs.xml
	$(AM_V_GEN) xsltproc --output $@ $^

nm-settings-keyfile.xml: nm-settings-keyfile.xsl $(top_builddir)/libnm/nm-keyfile-docs.xml
	$(AM_V_GEN) xsltproc --output $@ $^

nm-settings-ifcfg-rh.xml: nm-settings-ifcfg-rh.xsl $(top_builddir)/libnm/nm-ifcfg-rh-docs.xml
	$(AM_V_GEN) xsltproc --output $@ $^

CLEANFILES +=				\
	nm-settings.xml			\
	nm-settings-keyfile.xml		\
	nm-settings-ifcfg-rh.xml

endif

man_pages =			\
	nmcli.1			\
	nmtui.1			\
	nm-online.1		\
	NetworkManager.conf.5	\
	nmcli-examples.7	\
	NetworkManager.8

autogenerated_man_pages =	\
	nm-settings.5		\
	nm-settings-keyfile.5

if CONFIG_PLUGIN_IFCFG_RH
autogenerated_man_pages += nm-settings-ifcfg-rh.5
else
EXTRA_DIST += nm-settings-ifcfg-rh.5
endif

EXTRA_DIST +=						\
	nm-settings.xml					\
	nm-settings.xsl					\
	nm-settings-keyfile.xml				\
	nm-settings-keyfile.xsl				\
	nm-settings-ifcfg-rh.xml			\
	nm-settings-ifcfg-rh.xsl			\
	$(addsuffix .xml,$(basename $(man_pages)))	\
	$(man_pages)					\
	$(autogenerated_man_pages)

nmtui_links = nmtui-edit nmtui-connect nmtui-hostname
NetworkManager_conf_links = nm-system-settings.conf

# Implement a || condition
if INSTALL_PREGEN_MANPAGES
install_manpages = true
else
if ENABLE_GTK_DOC
install_manpages = true
endif
endif

install-data-hook:
	if test -n "$(install_manpages)"; then \
		for link in $(nmtui_links); do \
			ln -f $(DESTDIR)$(mandir)/man1/nmtui.1 $(DESTDIR)$(mandir)/man1/$$link.1; \
		done; \
		for link in $(NetworkManager_conf_links); do \
			ln -f $(DESTDIR)$(mandir)/man5/NetworkManager.conf.5 $(DESTDIR)$(mandir)/man5/$$link.5; \
		done; \
	fi

uninstall-hook:
	if test -n "$(install_manpages)"; then \
		for link in $(nmtui_links); do \
			rm -f $(DESTDIR)$(mandir)/man1/$$link.1; \
		done; \
		for link in $(NetworkManager_conf_links); do \
			rm -f $(DESTDIR)$(mandir)/man5/$$link.5; \
		done; \
	fi

if ENABLE_GTK_DOC
man_MANS += $(man_pages)
CLEANFILES += $(man_pages)
if SETTING_DOCS_AVAILABLE
man_MANS += $(autogenerated_man_pages)
CLEANFILES += $(autogenerated_man_pages)
endif
else
if INSTALL_PREGEN_MANPAGES
man_MANS +=					\
	$(man_pages)		\
	$(autogenerated_man_pages)
endif
endif
