# Makefile - for remstats documentation

.SUFFIXES:
.SUFFIXES: .pod .html .txt $(SUFFIXES)
HTML = \
	alerter.html alert-cgi.html alert-email.html alert-monitor.html \
	alert-winpopup.html availability-report.html availability-report-cgi.html \
	check-config.html cgis.html cleanup.html \
	collectors.html config-tools.html cookies.html configuration.html \
	configfile-alert-destination-map.html configfile-alert-template-map.html \
	configfile-alert-templates.html configfile-availability.html \
	configfile-customgraphs.html \
	configfile-html.html configfile-links.html configfile-remotepings.html \
	configfile-general.html configfile-groups.html configfile-host-templates.html \
	configfile-times.html configfile-colors.html configfile-archives.html \
	configfile-tools.html configfile-scripts.html configfile-alerts.html \
	configfile-oids.html configfile-rrds.html configfile-hosts.html \
	configfile-views.html configfile-view-templates.html \
	conventions.html \
	convert-config-links.html dataimage-cgi.html datapage-cgi.html \
	datapage-alert-writer.html \
	datapage-interfaces.html datapage-inventory.html datapage-status.html \
	do-traceroutes.html genindex.html genmenu.html graph-paths.html \
	graph-cgi.html \
	graph-writer.html htmlpod.html index.html install.html \
	install-servers.html install-webserver.html install-user.html \
	log-collector.html log-event-cgi.html log-server.html misc.html \
	monitors.html multiping.html new-config.html new-ping-hosts.html \
	new-port-hosts.html new-snmp-hosts.html new-unix-hosts.html \
	nt-discover.html nt-status-collector.html nt-status-server.html pagemakers.html \
	ping-cgi.html ping-collector.html ping-monitor.html podhtml.html \
	podlatex.html podpdf.html port-collector.html private.html \
	remoteping-collector.html remoteping-server.html remstats-monitor.html \
	required.html rrd-report.html run-remstats.html servers.html \
	showlog-cgi.html snmp-collector.html snmp-route-collector.html \
	snmp-showif.html snmpif-description-updater.html snmpif-setspeed.html \
	split-config.html thanks.html topology-monitor.html tools.html \
	topics.html traceroute.html traceroute-cgi.html \
	unix-status-collector.html unix-status-server.html updater.html \
	view-writer.html whois-cgi.html \
	bugs.html done.html todo.html releasenotes.html faq.html 
TEXT = \
	alerter.txt alert-cgi.txt alert-email.txt alert-monitor.txt alert-winpopup.txt \
	availability-report.txt availability-report-cgi.txt \
	check-config.txt cgis.txt cleanup.txt collectors.txt config-tools.txt \
	cookies.txt configuration.txt configfile-alert-template-map.txt \
	configfile-alert-destination-map.txt configfile-alert-templates.txt \
	configfile-availability.txt \
	configfile-customgraphs.txt configfile-html.txt configfile-links.txt \
	configfile-remotepings.txt configfile-host-templates.txt \
	configfile-general.txt configfile-groups.txt configfile-times.txt \
	configfile-colors.txt \
	configfile-archives.txt configfile-tools.txt configfile-scripts.txt \
	configfile-alerts.txt configfile-oids.txt configfile-rrds.txt \
	configfile-hosts.txt configfile-views.txt configfile-view-templates.txt \
	conventions.txt \
	convert-config-links.txt dataimage-cgi.txt datapage-cgi.txt datapage-alert-writer.txt \
	datapage-interfaces.txt datapage-inventory.txt datapage-status.txt \
	do-traceroutes.txt genindex.txt \
	genmenu.txt graph-paths.txt graph-cgi.txt graph-writer.txt \
	htmlpod.txtindex.txt install.txt install-servers.txt \
	install-webserver.txt install-user.txt log-collector.txt \
	log-event-cgi.txt log-server.txt \
	misc.txt monitors.txt multiping.txt new-config.txt new-ping-hosts.txt \
	new-port-hosts.txt new-snmp-hosts.txt new-unix-hosts.txt \
	nt-discover.txt nt-status-collector.txt nt-status-server.txt \
	pagemakers.txt ping-cgi.txt ping-collector.txt ping-monitor.txt \
	podhtml.txt podlatex.txt podpdf.txt port-collector.txt private.txt \
	remoteping-collector.txt \
	remoteping-server.txt remstats-monitor.txt required.txt \
	rrd-report.txt run-remstats.txt servers.txt showlog-cgi.txt \
	snmp-collector.txt snmp-route-collector.txt snmp-showif.txt \
	snmpif-description-updater.txt snmpif-setspeed.txt split-config.txt \
	thanks.txt topology-monitor.txt tools.txt topics.txt \
	traceroute.txt traceroute-cgi.txt \
	unix-status-collector.txt \
	unix-status-server.txt updater.txt view-writer.txt whois-cgi.txt \
	bugs.txt install.txt todo.txt releasenotes.txt faq.txt
SPECIALHTML = bugs.html install.html todo.html releasenotes.html faq.html
SPECIALTEXT = ../BUGS ../CHANGES.old ../INSTALL ../TODO ../RELEASENOTES ../FAQ
EXTRA = topindex.html
TARGETS = $(HTML) $(SPECIALTEXT) $(EXTRA)

EVERYTHING_NEEDS = Makefile HEADER.pod HEADER2.pod FOOTER.pod fixup.config ../fixup \
	../htmlfixup ../podhtml

.pod.html: Makefile HEADER.pod HEADER2.pod FOOTER.pod fixup.config ../fixup ../htmlfixup ../podhtml ../genmenu MENU
	@echo ""
	../genmenu $* MENU >$*.tmpmenu
	cat HEADER.pod $*.tmpmenu HEADER2.pod $*.pod FOOTER.pod >$*.tmp1
	../fixup $*.tmp1 >$*.tmp2
	../htmlfixup $*.pod $*.tmp2 >$*.tmp3
	../podhtml $*.tmp3 >$@
	@-rm -f $*.tmp*

.pod.txt: Makefile HEADER.pod HEADER2.pod FOOTER.pod fixup.config ../fixup ../htmlfixup ../podhtml
	@echo ""
	cat HEADER.pod $*.pod FOOTER.pod >$*.tmp1
	../fixup $*.tmp1 >$*.tmp2
	pod2text $*.tmp2 >$@
	@-rm -f $*.tmp*

#--------------------------------------------------------------------- main ---
default: all

all: all-begin VERSION BESTAVAILABLEVERSION $(TARGETS)

all-begin:
	@echo ""
	@echo "=== making docs ==="

book: book.tex book.dvi book.ps book.pdf
	echo >book "placeholder for make"

install: all
	@echo ""
	@echo "=== installing html ==="
	[ -d /home/remstats/html ] || ../makeadir remstats remstats 755 /home/remstats/html
	[ -d /home/remstats/html/release ] || ../makeadir remstats remstats 755 /home/remstats/html/release
	[ -d /home/remstats/html/release/src ] || ../makeadir remstats remstats 755 /home/remstats/html/release/src
	cp $(HTML) $(EXTRA) /home/remstats/html/release
	cp $(SPECIALTEXT) $(SPECIALHTML) /home/remstats/html/release/src

#--------------------------------------------------------------------- misc ---
../BUGS: $(EVERYTHING_NEEDS) bugs.txt
	@echo ""
	cp bugs.txt ../BUGS

../CHANGES.old: changes.old
	@echo ""
	cp changes.old ../CHANGES.old

../FAQ: $(EVERYTHING_NEEDS) faq.txt
	@echo ""
	cp faq.txt ../FAQ

../INSTALL: $(EVERYTHING_NEEDS) install.txt
	@echo ""
	cp install.txt ../INSTALL

../RELEASENOTES: $(EVERYTHING_NEEDS) releasenotes.txt
	@echo ""
	cp releasenotes.txt ../RELEASENOTES

../TODO: $(EVERYTHING_NEEDS) todo.txt
	@echo ""
	cp todo.txt ../TODO

topindex.html: $(EVERYTHING_NEEDS) topindex.html.in
	@echo ""
	../fixup topindex.html.in >topindex.html

topics.html: $(EVERYTHING_NEEDS) topics.pod podhtml--rawindex ../podhtml ../genindex
	@echo ""
	../genindex -f pod podhtml--rawindex >$*.tmp1
	../genmenu $* MENU >$*.tmp2
	cat HEADER.pod $*.tmp2 HEADER2.pod $*.pod $*.tmp1 FOOTER.pod >$*.tmp3
	../fixup $*.tmp3 >$*.tmp4
	../htmlfixup $*.pod $*.tmp4 >$*.tmp5
	../podhtml $*.tmp5 >$@
	@-rm -f $*.tmp*

topics.txt: $(EVERYTHING_NEEDS) topics.pod podhtml--rawindex ../genindex
	@echo ""
	../genindex -f pod podhtml--rawindex >$*.tmp1
	cat $*.pod FOOTER.pod >$*.tmp2
	../fixup $*.tmp2 > $*.tmp3
	pod2text $*.tmp3 >$@
	@-rm -f $*.tmp*

book-header.tex: book-header.tex.in
	../fixup book-header.tex.in > book-header.tex

book-footer.tex: book-footer.tex.in
	../fixup book-footer.tex.in > book-footer.tex

book.pod: MENU *.pod
	@echo ""
	@echo "=== making book.pod ==="
	-rm -f book.pod
	-touch book.pod
	@for file in `awk '/^topics/{next} {print $$1}' MENU` ; do \
		if [ -f $$file.pod ] ; then \
			echo -n " $$file"; \
			../fixup $$file.pod > $$file.tmp ;\
			if grep '^=exec' $$file.pod >/dev/null 2>&1 ; then \
				help=`../$$file -h 2>&1` ;\
				awk -v HELP="$$help" ' \
					/^=exec/ {print HELP; next; } \
					{print} \
				' $$file.tmp > $$file.tmp3 ;\
				mv $$file.tmp3 $$file.tmp ;\
			fi ;\
			cat $$file.tmp >>book.pod ;\
			rm -f $$file.tmp ;\
		else \
			echo >&2 ">>> $$file.pod: missing; skipped" ;\
		fi \
	done
	@echo ""

book.tex: MENU book-header.tex book-footer.tex ../podlatex
	@echo ""
	@echo "=== building book.tex ==="
	@cp book-header.tex book.tex
	@for file in `awk '/^topics/{next} {print $$1}' MENU` ; do \
		echo -n " $$file"; \
		echo "%------------------------------------ $$file.pod ---" >> book.tex ;\
		if [ -f $$file.pod ] ; then \
			../fixup $$file.pod > $$file.tmp ;\
			../podlatex $$file.tmp ;\
			cat $$file.tmp.tex >> book.tex ;\
			rm -f $$file.tmp $$file.tmp.tex ;\
		else \
			echo >&2 ">>> $$file.pod: missing; skipped" ;\
		fi \
	done
	@echo ""
	@cat book-footer.tex  >>book.tex

# Have to do it twice to get the table-of-contents right
book.dvi: book.tex
	-TEX_OUTPUT=book.dvi latex '\batchmode \input book.tex'
	-TEX_OUTPUT=book.dvi latex '\batchmode \input book.tex'

xdvi: book.dvi
	xdvi book&

book.ps: book.dvi
	dvips -o book.ps book.dvi

book.pdf: ../podpdf book.pod
	../podpdf book.pod
	mv book.pod.pdf book.pdf

#------------------------------------------------------------ housekeeping ---
Makefile: Makefile.in fixup.config fixup VERSION BESTAVAILABLEVERSION
	@echo ""
	../fixup Makefile.in >Makefile

fixup.config: ../fixup.config
	@echo ".. copying fixup.config"
	cp ../fixup.config .

VERSION: ../VERSION
	@echo ".. copying VERSION"
	cp ../VERSION VERSION

BESTAVAILABLEVERSION: ../BESTAVAILABLEVERSION
	@echo ".. copying BESTAVAILABLEVERSION"
	cp ../BESTAVAILABLEVERSION BESTAVAILABLEVERSION

fixup: ../fixup fixup.config VERSION BESTAVAILABLEVERSION
	@echo ".. copying fixup"
	cp ../fixup .

clean:
	@echo ""
	rm -f $(TARGETS) $(TEXT) *.tmp? pod2html-dircache pod2html-itemcache \
		../CHANGES.old ../INSTALL podhtml--rawindex *.tex \
		book.pod book.dvi book.pdf book.ps book book.aux book.idx \
		book.ilg book.ind book.log book.toc book-index.aux book-index.dvi \
		book-index.ix book-index.log
