# Makefile - for remstats documentation

HTMLDIR=/home/remstats/html
OWNER=remstats
GROUP=remstats
VERSION=1.0.13a
MANDIR=/home/remstats/man
MANSECT=1

.SUFFIXES:
.SUFFIXES: .pod .html .txt .man $(SUFFIXES)

HTML= \
  alert-cgi.html \
  alert-email.html \
  alert-monitor.html \
  alert-syslog.html \
  alert-winpopup.html \
  alert-yahoo.html \
  alerter.html \
  architecture.html \
  availability-report-cgi.html \
  availability-report.html \
  bugs.html \
  cgis.html \
  check-config.html \
  check-rrdlast.html \
  cisco-access-server-collector.html \
  collectors.html \
  config-tools.html \
  configfile-access.html \
  configfile-alert-destination-map.html \
  configfile-alert-template-map.html \
  configfile-alert-templates.html \
  configfile-alerts.html \
  configfile-archives.html \
  configfile-availability.html \
  configfile-colors.html \
  configfile-customgraphs.html \
  configfile-dbi-connects.html \
  configfile-dbi-selects.html \
  configfile-discovery.html \
  configfile-environment.html \
  configfile-general.html \
  configfile-groups.html \
  configfile-host-templates.html \
  configfile-hosts.html \
  configfile-html.html \
  configfile-links.html \
  configfile-ntops.html \
  configfile-oids.html \
  configfile-page-templates.html \
  configfile-pages.html \
  configfile-remotepings.html \
  configfile-rrds.html \
  configfile-run-stages.html \
  configfile-run.html \
  configfile-scripts.html \
  configfile-times.html \
  configfile-tools.html \
  configfile-view-templates.html \
  configfile-views.html \
  configuration.html \
  conventions.html \
  convert-config-links.html \
  cookies.html \
  dataimage-cgi.html \
  datapage-alert-writer.html \
  datapage-cgi.html \
  datapage-interfaces.html \
  datapage-inventory.html \
  datapage-status.html \
  dbi-collector.html \
  do-traceroutes.html \
  done.html \
  error-collector.html \
  faq.html \
  files.html \
  functions.html \
  genindex.html \
  genmenu.html \
  graph-cgi.html \
  graph-paths.html \
  graph-writer.html \
  host-pages.html \
  htmlpod.html \
  index.html \
  install-servers.html \
  install-user.html \
  install-webserver.html \
  install.html \
  lib-alert.html \
  lib-cgi.html \
  lib-data.html \
  lib-html.html \
  lib-remstats.html \
  lib-snmp.html \
  lib-socket.html \
  lockfile.html \
  log-collector.html \
  log-event-cgi.html \
  log-server.html \
  macinfo-cgi.html \
  macinfo.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 \
  ntop-collector.html \
  page-writer.html \
  pagemakers.html \
  pattern-query.html \
  ping-cgi.html \
  ping-collector.html \
  ping-monitor.html \
  podhtml.html \
  podlatex.html \
  podpdf.html \
  port-collector.html \
  port-query.html \
  private.html \
  program-collector.html \
  releasenotes.html \
  remoteping-collector.html \
  remoteping-server.html \
  remstats-backup.html \
  remstats-cleanup.html \
  remstats-monitor.html \
  remstats-rrdtune.html \
  remstats-version.html \
  rename-host.html \
  required.html \
  rrd-report.html \
  rrds.html \
  rt-updater.html \
  run-remstats.html \
  run-remstats2.html \
  servers.html \
  show-config-cgi.html \
  showlog-cgi.html \
  snmp-collector.html \
  snmp-get.html \
  snmp-route-collector.html \
  snmp-showif.html \
  snmpif-description-updater.html \
  snmpif-setspeed.html \
  thanks.html \
  todo.html \
  tools.html \
  topology-monitor.html \
  traceroute-cgi.html \
  traceroute.html \
  troubleshooting.html \
  unix-status-collector.html \
  unix-status-server.html \
  update-switch-ports.html \
  updater.html \
  view-writer.html \
  webgroup.html \
  whois-cgi.html

MANS = \
	alert-cgi.man \
	alert-email.man \
	alert-monitor.man \
	alert-syslog.man \
	alert-winpopup.man \
	alert-yahoo.man \
	alerter.man \
	architecture.man \
	availability-report-cgi.man \
	availability-report.man \
	check-config.man \
	check-rrdlast.man \
	cisco-access-server-collector.man \
	configfile-access.man \
	configfile-alert-destination-map.man \
	configfile-alert-template-map.man \
	configfile-alert-templates.man \
	configfile-alerts.man \
	configfile-archives.man \
	configfile-availability.man \
	configfile-colors.man \
	configfile-customgraphs.man \
	configfile-dbi-connects.man \
	configfile-dbi-selects.man \
	configfile-discovery.man \
	configfile-environment.man \
	configfile-general.man \
	configfile-groups.man \
	configfile-host-templates.man \
	configfile-hosts.man \
	configfile-html.man \
	configfile-links.man \
	configfile-ntops.man \
	configfile-oids.man \
	configfile-page-templates.man \
	configfile-pages.man \
	configfile-remotepings.man \
	configfile-rrds.man \
	configfile-run-stages.man \
	configfile-run.man \
	configfile-scripts.man \
	configfile-times.man \
	configfile-tools.man \
	configfile-view-templates.man \
	configfile-views.man \
	configuration.man \
	convert-config-links.man \
	dataimage-cgi.man \
	datapage-alert-writer.man \
	datapage-cgi.man \
	datapage-interfaces.man \
	datapage-inventory.man \
	datapage-status.man \
	dbi-collector.man \
	do-traceroutes.man \
	error-collector.man \
	genindex.man \
	genmenu.man \
	graph-cgi.man \
	graph-paths.man \
	graph-writer.man \
	host-pages.man \
	htmlpod.man \
	lib-alert.man \
	lib-cgi.man \
	lib-data.man \
	lib-html.man \
	lib-misc.man \
	lib-remstats.man \
	lib-snmp.man \
	lib-socket.man \
	lockfile.man \
	log-collector.man \
	log-event-cgi.man \
	log-server.man \
	macinfo-cgi.man \
	macinfo.man \
	multiping.man \
	new-config.man \
	new-ping-hosts.man \
	new-port-hosts.man \
	new-snmp-hosts.man \
	new-unix-hosts.man \
	nt-discover.man \
	nt-status-collector.man \
	nt-status-server.man \
	ntop-collector.man \
	page-writer.man \
	pattern-query.man \
	ping-cgi.man \
	ping-collector.man \
	ping-monitor.man \
	podhtml.man \
	podlatex.man \
	podpdf.man \
	port-collector.man \
	port-query.man \
	program-collector.man \
	remoteping-collector.man \
	remoteping-server.man \
	remstats-backup.man \
	remstats-cleanup.man \
	remstats-monitor.man \
	remstats-rrdtune.man \
	remstats-version.man \
	rename-host.man \
	rrd-report.man \
	rrds.man \
	rt-updater.man \
	run-remstats.man \
	run-remstats2.man \
	show-config-cgi.man \
	showlog-cgi.man \
	snmp-collector.man \
	snmp-get.man \
	snmp-route-collector.man \
	snmp-showif.man \
	snmpif-description-updater.man \
	snmpif-setspeed.man \
	topology-monitor.man \
	traceroute-cgi.man \
	traceroute.man \
	unix-status-collector.man \
	unix-status-server.man \
	update-switch-ports.man \
	updater.man \
	view-writer.man \
	whois-cgi.man

SPECIALHTML = install.html todo.html releasenotes.html faq.html \
	topics.html
SPECIALTEXT = ../BUGS ../CHANGES.old ../INSTALL ../TODO ../RELEASENOTES \
	../FAQ topics.txt
EXTRA = topindex.html topics.html

TARGETS = $(HTML) $(SPECIALTEXT) $(EXTRA)

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

# Make .html from .pod
.pod.html: Makefile HEADER.pod HEADER2.pod FOOTER.pod fixup.config \
		../fixup ../htmlfixup ../podhtml ../genmenu MENU
	@../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*
	@echo "$@ done"

# Make man pages from .pod
.pod.man: Makefile ../fixup fixup.config
	../fixup $*.pod > $*.tmp1
	if grep '^=exec' $*.pod 2>/dev/null ; then \
		../$* -h 2>&1 | sed -e 's/^usage:/\
usage:/' \
			-e 's/^where /\
where /' > HELP.tmp; \
		sed \
			-e 's|^=head[234]|=head1|' \
			-e '/^=exec/r HELP.tmp' \
			-e "s|^=exec.*||" \
			$*.tmp1 > $*.tmp2; \
		mv $*.tmp2 $*.tmp1; \
	fi
	pod2man --name="$*" --center="Remstats $(VERSION)" \
		$*.tmp1 > $*.man
#	rm -f $*.tmp1 $*.tmp2 HELP.tmp 2>/dev/null

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

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

.PHONY: all

all: VERSION BESTAVAILABLEVERSION $(TARGETS)

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

#install: all book.ps book.pdf
install: all
	@echo ""
	@echo "=== Installing docs ==="
	@[ -d $(HTMLDIR) ] || ../makeadir $(OWNER) $(GROUP) 755 $(HTMLDIR)
	@[ -d $(HTMLDIR)/release ] || \
		../makeadir $(OWNER) $(GROUP) 755 $(HTMLDIR)/release
	@[ -d $(HTMLDIR)/release/src ] || \
		../makeadir $(OWNER) $(GROUP) 755 $(HTMLDIR)/release/src
	@cp $(HTML) $(EXTRA) $(HTMLDIR)/release
	@-cp book.pdf book.ps $(HTMLDIR)/release
	@cp $(SPECIALTEXT) $(SPECIALHTML) $(HTMLDIR)/release/src

install-man: man
	@echo ""
	@echo "=== Installing man-pages ==="
	for f in $(MANS) ; do \
		cp $$f $(MANDIR)/`basename $$f .man`.$(MANSECT); \
		chmod 644 $(MANDIR)/`basename $$f .man`.$(MANSECT); \
	done

#--------------------------------------------------------------------- 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

podhtml-rawindex: $(HTML)
	@echo ""
	cat *.phri >$@ || ( rm -f $@; exit 1)

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*
	@echo "$@ done"

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

book-header.tex: book-header.tex.in
	@../fixup book-header.tex.in > book-header.tex
	@echo "$@ done";

book-footer.tex: book-footer.tex.in
	@../fixup book-footer.tex.in > book-footer.tex
	@echo "$@ done";

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
	@echo "$@ done"

book.pdf: ../podpdf book.pod
	../podpdf book.pod 2>/dev/null
	mv book.pod.pdf book.pdf
	@echo "$@ done"

man: $(MANS)

#------------------------------------------------------------ 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 *.phri *.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 topindex.html topics.html topics.txt

distclean:
	@echo ""
	rm -f fixup fixup.config VERSION BESTAVAILABLEVERSION $(SPECIALTEXT)
