# $Progeny$

doc_files=		${srcdir}/guide.html \
			${srcdir}/guide.txt \
			${srcdir}/api-reference \
			${srcdir}/discover.1 \
			${srcdir}/discover-config.1 \
			${srcdir}/discover.conf.5 \
			${srcdir}/discover-modprobe.conf.5 \
			${srcdir}/discover-modprobe.8

refentries=		discover-config.refentry \
			discover-modprobe.conf.refentry \
			discover-modprobe.refentry \
			discover.conf.refentry \
			discover.refentry

sed_regexp = -e " s|/.*/discover.conf|${sysconfdir}/discover.conf|g " \
			-e " s|/.*/list.xml|@DISCOVER_DEFAULT_URL@|g " \
			-e " s|/.*/discover-modprobe.conf|${sysconfdir}/discover-modprobe.conf|g "

all: ${doc_files}

###############################################################################
# Clean

clean_FILES=		#none
distclean_FILES=	Makefile
maintainer_clean_FILES=	${doc_files} discover-config.refentry

clean:

distclean:
	rm -rf ${clean_FILES} ${distclean_FILES}

maintainer-clean:
	rm -rf ${clean_FILES} ${distclean_FILES} ${maintainer_clean_FILES}

###############################################################################
# Installation

install: ${doc_files}
	${INSTALL_DIR} ${DESTDIR}${datadir}/doc/discover
	${INSTALL_DIR} ${DESTDIR}${mandir}/man1
	${INSTALL_DIR} ${DESTDIR}${mandir}/man5
	${INSTALL_DIR} ${DESTDIR}${mandir}/man8
	@${MAKE} __sed_install FROM=${srcdir}/guide.html \
		TO=${DESTDIR}${datadir}/doc/discover/guide.html
	@${MAKE} __sed_install FROM=${srcdir}/guide.txt \
		TO=${DESTDIR}${datadir}/doc/discover/guide.txt

# XXX: If you have these, you're smarter than the
#      average bear
	cp -r ${srcdir}/api-reference/html \
		${DESTDIR}${datadir}/doc/discover/api-reference

	@${MAKE} __sed_install FROM=${srcdir}/discover.1 \
		TO=${DESTDIR}${mandir}/man1/discover.1
	@${MAKE} __sed_install FROM=${srcdir}/discover-config.1 \
		TO=${DESTDIR}${mandir}/man1/discover-config.1
	@${MAKE} __sed_install FROM=${srcdir}/discover.conf.5 \
		TO=${DESTDIR}${mandir}/man5/discover.conf.5
	@${MAKE} __sed_install FROM=${srcdir}/discover-modprobe.conf.5 \
		TO=${DESTDIR}${mandir}/man5/discover-modprobe.conf.5
	@${MAKE} __sed_install FROM=${srcdir}/discover-modprobe.8 \
		TO=${DESTDIR}${mandir}/man8/discover-modprobe.8

uninstall:
	rm -f ${DESTDIR}${datadir}/doc/discover/guide.html
	rm -f ${DESTDIR}${datadir}/doc/discover/guide.txt
	rm -rf ${DESTDIR}${datadir}/doc/discover/api-reference
	rm -f ${DESTDIR}${mandir}/man1/discover-config.1
	rm -f ${DESTDIR}${mandir}/man8/discover-modprobe.8
	rm -f ${DESTDIR}${mandir}/man5/discover-modprobe.conf.5

###############################################################################
# Distribution

DISTFILES=		Doxyfile GNUmakefile Makefile.in \
			discover.refentry \
			bus-classes.xml \
			crash-snippet.xml \
			device-types.xml \
			guide.xml \
			range.fig \
			${doc_files} \
			${refentries}

distdir: ${DISTFILES}
	${top_srcdir}/buildtools/distdir ${distdir}/${_THISDIR_} ${DISTFILES}
	cp -r api-reference ${distdir}/${_THISDIR_}

# This rule exists because the documentation is generated as
# part of the distribution archive, in an environment where the
# directory layout may differ from that to be used on the
# installed system, and passed to the configure script.
#
# It's this, or force people to use all sorts of XML-based build
# tools installed and configured to just write.
__sed_install:
	sed ${sed_regexp} ${FROM} > ${FROM}.sed
	${INSTALL_DATA} ${FROM}.sed ${TO}
	rm ${FROM}.sed
