#
# Makefile for the man page directory
#
top_builddir=..
VPATH		= @srcdir@

#
# install stuff
#

OTHERINSTALL=maninstall
OTHERUNINSTALL=manuninstall
#
# local stuff
#

MAN1  = snmpinform.1
MAN1G = snmpbulkget.1 snmpcmd.1 snmpget.1 snmpset.1 snmpwalk.1 \
	snmpbulkwalk.1 snmpgetnext.1 snmptest.1 snmptranslate.1 snmptrap.1 \
	snmpusm.1 snmpvacm.1 snmptable.1 snmpstatus.1 snmpconf.1 mib2c.1 \
	snmpnetstat.1 snmpdelta.1 snmpdf.1
MAN3  = snmp_close.3 snmp_free_pdu.3 snmp_open.3 snmp_read.3 \
	snmp_select_info.3 snmp_send.3 snmp_timeout.3			       \
	snmp_sess_async_send.3 snmp_sess_close.3 snmp_sess_error.3     \
	snmp_sess_init.3 snmp_sess_open.3 snmp_sess_read.3	       \
	snmp_sess_select_info.3 snmp_sess_send.3 snmp_sess_timeout.3   \
	snmp_sess_session.3 snmp_perror.3 snmp_sess_perror.3	       \
	snmp_error.3 snmp_api_errstring.3 init_mib.3 add_mibdir.3      \
	init_mib_internals.3 snmp_set_mib_warnings.3 read_module.3     \
	read_all_mibs.3 read_mib.3 read_module_node.3 read_objid.3     \
	add_module_replacement.3 shutdown_mib.3 print_mib.3	       \
	print_variable.3 print_value.3 print_objid.3		       \
	print_description.3 snmp_set_save_descriptions.3	       \
	get_module_node.3 netsnmp_agent.3 netsnmp_bulk_to_next.3       \
	netsnmp_debug.3 netsnmp_example_scalar_int.3 netsnmp_handler.3 \
	netsnmp_instance.3 netsnmp_mib_handler_methods.3	       \
	netsnmp_multiplexer.3 netsnmp_old_api.3 netsnmp_read_only.3    \
	netsnmp_serialize.3 netsnmp_table.3 netsnmp_table_array.3      \
	netsnmp_table_data.3 netsnmp_table_dataset.3		       \
	netsnmp_table_iterator.3 netsnmp_scalar.3       \
	netsnmp_watcher.3 netsnmp_mode_end_call.3 netsnmp_library.3    \
	netsnmp_mib_utilities.3 netsnmp_Container_iterator.3	       \
	netsnmp_baby_steps.3 netsnmp_cache_handler.3		       \
	netsnmp_container.3 netsnmp_iterator_info_s.3 netsnmp_leaf.3   \
	netsnmp_row_merge.3		       \
	netsnmp_scalar_group_group.3 netsnmp_stash_cache.3	       \
	netsnmp_utilities.3

MAN3G = default_store.3 mib_api.3 read_config.3 snmp_agent_api.3 snmp_alarm.3 \
	snmp_api.3 snmp_sess_api.3 snmp_trap_api.3
MAN5G = snmpd.conf.5 snmptrapd.conf.5 snmp.conf.5 snmp_config.5 variables.5 \
        mib2c.conf.5
MAN8G = snmptrapd.8 snmpd.8

MANALL = $(MAN1) $(MAN1G) $(MAN3) $(MAN3G) $(MAN5G) $(MAN8G)

TARGETS = $(MAN5G) $(MAN1G) $(MAN3G) $(MAN8G)
OTHERCLEANTARGETS=$(TARGETS) default_store.3.h

all: $(TARGETS) standardall

snmpbulkget.1: snmpbulkget.1.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmpbulkget.1.def > snmpbulkget.1

snmpbulkwalk.1: snmpbulkwalk.1.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmpbulkwalk.1.def > snmpbulkwalk.1

snmpcmd.1: snmpcmd.1.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmpcmd.1.def > snmpcmd.1

snmpconf.1: snmpconf.1.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmpconf.1.def > snmpconf.1

snmpd.8: snmpd.8.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmpd.8.def > snmpd.8

snmpdelta.1: snmpdelta.1.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmpdelta.1.def > snmpdelta.1

snmpdf.1: snmpdf.1.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmpdf.1.def > snmpdf.1

snmpget.1: snmpget.1.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmpget.1.def > snmpget.1

snmpgetnext.1: snmpgetnext.1.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmpgetnext.1.def > snmpgetnext.1

snmpnetstat.1: snmpnetstat.1.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmpnetstat.1.def > snmpnetstat.1

snmpset.1: snmpset.1.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmpset.1.def > snmpset.1

snmpstatus.1: snmpstatus.1.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmpstatus.1.def > snmpstatus.1

snmptable.1: snmptable.1.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmptable.1.def > snmptable.1

snmptest.1: snmptest.1.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmptest.1.def > snmptest.1

snmptranslate.1: snmptranslate.1.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmptranslate.1.def > snmptranslate.1

snmptrap.1: snmptrap.1.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmptrap.1.def > snmptrap.1

snmpusm.1: snmpusm.1.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmpusm.1.def > snmpusm.1

snmpvacm.1: snmpvacm.1.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmpvacm.1.def > snmpvacm.1

mib2c.1: mib2c.1.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/mib2c.1.def > mib2c.1

snmpwalk.1: snmpwalk.1.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmpwalk.1.def > snmpwalk.1

mib_api.3: mib_api.3.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/mib_api.3.def > mib_api.3

read_config.3: read_config.3.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/read_config.3.def > read_config.3

snmp_agent_api.3: snmp_agent_api.3.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmp_agent_api.3.def > snmp_agent_api.3

snmp_alarm.3: snmp_alarm.3.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmp_alarm.3.def > snmp_alarm.3

snmp_api.3: snmp_api.3.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmp_api.3.def > snmp_api.3

snmp_sess_api.3: snmp_sess_api.3.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmp_sess_api.3.def > snmp_sess_api.3

snmp_trap_api.3: snmp_trap_api.3.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmp_trap_api.3.def > snmp_trap_api.3

snmp.conf.5: snmp.conf.5.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmp.conf.5.def > snmp.conf.5

snmp_config.5: snmp_config.5.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmp_config.5.def > snmp_config.5

snmpd.conf.5: snmpd.conf.5.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmpd.conf.5.def > snmpd.conf.5

snmptrapd.conf.5: snmptrapd.conf.5.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmptrapd.conf.5.def > snmptrapd.conf.5

variables.5: variables.5.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/variables.5.def > variables.5

snmptrapd.8: snmptrapd.8.def ../sedscript
	$(SED) -f ../sedscript < $(srcdir)/snmptrapd.8.def > snmptrapd.8

default_store.3.h: $(srcdir)/../include/net-snmp/library/default_store.h
	awk '{ if ($$0 == "     * begin storage definitions ") { p = 1 } else if ($$0 == "     * end storage definitions ") { p = 0 } else if (p) { print $$0}}' < $(srcdir)/../include/net-snmp/library/default_store.h > default_store.3.h

default_store.3: $(srcdir)/default_store.3.top default_store.3.h $(srcdir)/default_store.3.bot
	$(SED) -f ../sedscript < $(srcdir)/default_store.3.top > default_store.3
	cat default_store.3.h $(srcdir)/default_store.3.bot >> default_store.3

mib2c.conf.5: $(top_srcdir)/local/mib2c mib2c.conf.5.in $(srcdir)/mib2c.extract.pl
	-test -d $(srcdir)/CVS && perl $(srcdir)/mib2c.extract.pl $(top_srcdir)/local/mib2c $(srcdir)/mib2c.conf.5.in > mib2c.conf.5

maninstall:  maninstalldirs $(MAN1) $(MAN1G) $(MAN3) $(MAN5G) $(MAN8)
	@for i in $(MAN1) ; do $(INSTALL_DATA) $(srcdir)/$$i $(INSTALL_PREFIX)$(man1dir) ; echo "install:  installed $$i in $(INSTALL_PREFIX)$(man1dir)" ; done
	@$(INSTALL_DATA) $(MAN1G) $(INSTALL_PREFIX)$(man1dir)
	@for i in $(MAN1G) ; do echo "install:  installed $$i in $(INSTALL_PREFIX)$(man1dir)" ; done
	@for i in $(MAN3) ; do $(INSTALL_DATA) $(srcdir)/$$i $(INSTALL_PREFIX)$(man3dir) ; echo "install:  installed $$i in $(INSTALL_PREFIX)$(man3dir)" ; done
	@$(INSTALL_DATA) $(MAN3G) $(INSTALL_PREFIX)$(man3dir)
	@for i in $(MAN3G) ; do echo "install:  installed $$i in $(INSTALL_PREFIX)$(man3dir)" ; done
	-@$(INSTALL_DATA) $(MAN5G) $(INSTALL_PREFIX)$(man5dir)
	@for i in $(MAN5G) ; do echo "install:  installed $$i in $(INSTALL_PREFIX)$(man5dir)" ; done
	@$(INSTALL_DATA) $(MAN8G) $(INSTALL_PREFIX)$(man8dir)
	@for i in $(MAN8G) ; do echo "install:  installed $$i in $(INSTALL_PREFIX)$(man8dir)" ; done

manuninstall:
	@for i in $(MAN1G) $(MAN1) ; do rm -f $(INSTALL_PREFIX)$(man1dir)/$$i ; echo "removed $$i from $(INSTALL_PREFIX)$(man1dir)" ; done
	@for i in $(MAN3G) $(MAN3) ; do rm -f $(INSTALL_PREFIX)$(man3dir)/$$i ; echo "removed $$i from $(INSTALL_PREFIX)$(man3dir)" ; done
	@for i in $(MAN5G) ; do rm -f $(INSTALL_PREFIX)$(man5dir)/$$i ; echo "removed $$i from $(INSTALL_PREFIX)$(man5dir)" ; done
	@for i in $(MAN8G) ; do rm -f $(INSTALL_PREFIX)$(man8dir)/$$i ; echo "removed $$i from $(INSTALL_PREFIX)$(man8dir)" ; done

maninstalldirs:
	@$(SHELL) $(srcdir)/../mkinstalldirs $(INSTALL_PREFIX)$(man1dir) $(INSTALL_PREFIX)$(man3dir) $(INSTALL_PREFIX)$(man5dir) $(INSTALL_PREFIX)$(man8dir)


#
# internal administrative
#
html: $(MANALL)
	for i in $(MANALL); do \
	   if test `wc -l $$i | awk '{print $$1}'` != 1 ; then \
		   base=`echo $$i | sed 's/.[0-9]$$//;'` ; \
		   echo "<HTML><BODY bgcolor=\"#ffffff\" background=\"../ucd-snmp-bg3.gif\"><PRE>" > $$base.html; \
		   man2html -r ./$$i | perl -p -e 's/HREF=\"..\/man.\//HREF=\"/g;s/\.[1-9]\.html/.html/g;' | grep -v 'Content-type:' >> $$base.html; \
		   a="$$a $$i"; \
	   fi ; \
	done ;\
	perl make_index.pl man_sections.txt $$a > index.html
