#
# SellaNMS
# Id: Makefile.in,v 2.9 2002/03/25 10:18:28 sella Exp 
# Copyright (c) 2001,2002 Digital Genesis Software, LLC. All Rights Reserved.
# Released under the GPL Version 2 License.
# http://www.digitalgenesis.com
#

# --------------------------------------
#                Source
# --------------------------------------

OBJS				= main.o
EXTOBJS			=
SUBDIRS			= libs watchdog discovery monitor output internal
TARGET			=
LIBRARY			=
LIBRARY_MAJOR	=
SUPPORT			= ../support/sella_nms.conf ../support/sella_nms-complete.conf ../support/policy-statements.conf ../support/format-statements.conf ../support/map-statements.conf ../html/config.php ../support/admin-sella_nms.sh ../support/sella_nms-mysql.sql ../support/sella_nms.init.d ../support/sella_nms.man ../support/sella_nms.conf.man ../support/policy-statements.conf.man ../support/format-statements.conf.man ../support/map-statements.conf.man

# --------------------------------------
#                Programs
# --------------------------------------

CC					= @CC@
CXX				= @CXX@
CPP				= @CPP@
AR					= @AR@
RANLIB			= @RANLIB@
INSTALL			= @INSTALL@
MKDIR				= @MKDIR@
LN_S				= @LN_S@
SED				= @SED@
FIND				= @FIND@
TEST				= @TEST@
XARGS				= @XARGS@
STRIP				= @STRIP@
RM					= @RM@
CP					= @CP@
MV					= @MV@
WC					= @WC@
SHELL				= @SHELL@
CHKCONFIG		= @CHKCONFIG@
PACKAGE_NAME	= @PACKAGE_NAME@
PACKAGE_TARNAME= @PACKAGE_TARNAME@
PACKAGE_VERSION= @PACKAGE_VERSION@
PACKAGE_STRING	= @PACKAGE_STRING@
INITSCRIPT		= @ENABLE_INITSCRIPT@
IFLAGS_PROG		= -o root -m 755 # -s
IFLAGS_DSO		= -m 755
IFLAGS_SCRIPT	= -m 755
IFLAGS_SUPPORT	= -m 644
INSTALL_PROG	= $(INSTALL) $(IFLAGS_PROG)
INSTALL_DSO		= $(INSTALL) $(IFLAGS_DSO)
INSTALL_SCRIPT	= $(INSTALL) $(IFLAGS_SCRIPT)
INSTALL_SUPPORT= $(INSTALL) $(IFLAGS_SUPPORT)

# --------------------------------------
#                Paths
# --------------------------------------

root				=
prefix			= @real_prefix@
exec_prefix		= @exec_prefix@
bindir			= @bindir@
sbindir			= @sbindir@
libexecdir		= @libexecdir@
mandir			= @mandir@
sysconfdir		= @sysconfdir@
datadir			= @datadir@
htmldir			= @htmldir@
rrddir			= @rrddir@
includedir		= @includedir@
localstatedir	= @localstatedir@

# --------------------------------------
#                Flags
# --------------------------------------

SRCDIR			= @srcdir@
MFLAGS			= SRCDIR=$(SRCDIR)/..
DEFINES			= @DEFINES@ @DEFS@ -I$(SRCDIR) -I$(SRCDIR)/include -I$(SRCDIR)/libs @STLPORT@ @DBI_INCDIR@
CPPFLAGS			= @CPPFLAGS@
CFLAGS			= @CFLAGS@ $(CPPFLAGS)
CXXFLAGS			= @CXXFLAGS@ $(CPPFLAGS)
LDFLAGS			= -Wl,-export-dynamic @LDFLAGS@
LIBS				= @LIBS@
VPATH				= .

# --------------------------------------
#                Targets
# --------------------------------------

.SUFFIXES: .c .cc .cxx .c++ .cpp .o
 
.c.o:
	$(CC) $(DEFINES) -c $(CFLAGS) $<
.cc.o:
	$(CXX) $(DEFINES) -c $(CXXFLAGS) $<
.cxx.o:
	$(CXX) $(DEFINES) -c $(CXXFLAGS) $<
.c++.o:
	$(CXX) $(DEFINES) -c $(CXXFLAGS) $<
.cpp.o:
	$(CPP) $(DEFINES) -c $(CPPFLAGS) $<

all: build

build: $(OBJS) $(LIBRARY) $(TARGET)
	@SUBDIRS="$(SUBDIRS)"; \
	for DIR in $${SUBDIRS}; do \
		echo "@term_bold@==> $${DIR}@term_norm@"; \
		(cd $${DIR} && $(MAKE) $(MFLAGS) build) || exit 1; \
		echo "@term_bold@<== $${DIR}@term_norm@"; \
	done

rebuild:
	$(MAKE) clean all

$(TARGET): $(OBJS) $(EXTOBJS)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(EXTOBJS) $(LIBS)
 
$(LIBRARY): $(LIBRARY).@LIB_EXT@
 
$(LIBRARY).so: $(LIBRARY).so.$(LIBRARY_MAJOR)
 
$(LIBRARY).so.$(LIBRARY_MAJOR): $(OBJS) $(EXTOBJS)
	$(CXX) -shared -Wall -Wl,-soname,$@ -o $@ $(OBJS) $(EXTOBJS) $(LIBS)
 
$(LIBRARY).a: $(OBJS) $(EXTOBJS)
	$(AR) cr $@ $(OBJS) $(EXTOBJS)
	$(RANLIB) $@

docs:
	@echo "Not done yet.."

install: build install-mktree install-program install-library install-support install-script
	@echo '@term_bold@'
	@echo '  -------------------------------------------------------------'
	@echo '               I N S T A L L      C O M P L E T E'
	@echo '  -------------------------------------------------------------'
	@echo '   $(PACKAGE_STRING) has been successfully built and installed'
	@echo '   on your server. There are a couple of files you will need'
	@echo '   to modify, to configure $(PACKAGE_NAME) for your network.'
	@echo
	@echo '   You will need to edit the sella_nms.conf file:'
	@echo
	@echo '     $(sysconfdir)/sella_nms.conf'
	@echo
	@echo '   You may also need to edit the Web GUI config file:'
	@echo
	@echo '     $(htmldir)/config/config.php'
	@echo
	@echo '   Additionally, to make the $(PACKAGE_NAME) man pages available to'
	@echo '   users of this server, edit /etc/man.config and add:'
	@echo
	@echo '     MANPATH $(mandir)'
	@echo
	@echo '   The $(PACKAGE_NAME) daemon has been installed as:'
	@echo
	@echo '     $(root)$(sbindir)/sella_nms'
	@echo
	@echo '   See docs/INSTALL for further instructions.'
	@echo '  -------------------------------------------------------------'
	@echo '@term_norm@'

install-mktree:
	@echo
	@echo '@term_bold@Creating $(PACKAGE_NAME) installation tree..@term_norm@'
	$(INSTALL) -d $(root)$(sbindir)/discovery
	$(INSTALL) -d $(root)$(sbindir)/monitor
	$(INSTALL) -d $(root)$(sbindir)/output
	$(INSTALL) -d $(root)$(sbindir)/internal
	$(INSTALL) -d $(root)$(libexecdir)
	$(INSTALL) -d $(root)$(mandir)/man5
	$(INSTALL) -d $(root)$(mandir)/man8
	$(INSTALL) -d $(root)$(sysconfdir)
	$(INSTALL) -d $(root)$(localstatedir)
	$(INSTALL) -d $(root)$(htmldir)
	$(INSTALL) -d $(root)$(datadir)/mibs
	$(INSTALL) -d $(root)$(datadir)/mibs/rfc
	$(INSTALL) -d $(root)$(datadir)/mibs/juniper
	$(INSTALL) -d $(root)$(datadir)/mibs/cisco
	$(INSTALL) -d $(root)$(datadir)/mibs/extreme
	$(INSTALL) -d $(root)$(datadir)/mibs/netscreen
	$(INSTALL) -d $(root)$(datadir)/mibs/arbor

install-program:
	@echo
	@echo '@term_bold@Installing $(PACKAGE_NAME) program files..@term_norm@'
	$(INSTALL_PROG) watchdog/sella_nms $(root)$(sbindir)
	$(INSTALL_SCRIPT) ../support/admin-sella_nms.sh $(root)$(sbindir)
	@echo
	@echo '@term_bold@Installing $(PACKAGE_NAME) discovery modules..@term_norm@'
	$(INSTALL_PROG) discovery/icmp/icmpd $(root)$(sbindir)/discovery
	$(INSTALL_PROG) discovery/snmp/snmpd $(root)$(sbindir)/discovery
	$(INSTALL_PROG) discovery/topology/topologyd $(root)$(sbindir)/discovery
	@echo
	@echo '@term_bold@Installing $(PACKAGE_NAME) monitor modules..@term_norm@'
	$(INSTALL_PROG) monitor/icmp/icmpd $(root)$(sbindir)/monitor
	$(INSTALL_PROG) monitor/snmptrap/snmptrapd $(root)$(sbindir)/monitor
	$(INSTALL_PROG) monitor/syslog/syslogd $(root)$(sbindir)/monitor
#	$(INSTALL_PROG) monitor/bgp/bgpd $(root)$(sbindir)/monitor
	$(INSTALL_PROG) monitor/state/stated $(root)$(sbindir)/monitor
	@echo
	@echo '@term_bold@Installing $(PACKAGE_NAME) output modules..@term_norm@'
	$(INSTALL_PROG) output/gui/guid $(root)$(sbindir)/output
	$(INSTALL_PROG) output/email/emaild $(root)$(sbindir)/output
	$(INSTALL_PROG) output/syslog/syslogd $(root)$(sbindir)/output
	@echo
	@echo '@term_bold@Installing $(PACKAGE_NAME) internal modules..@term_norm@'
	$(INSTALL_PROG) internal/tidy/tidyd $(root)$(sbindir)/internal

install-library:
	@echo
	@echo '@term_bold@Installing $(PACKAGE_NAME) libraries..@term_norm@'
	$(INSTALL_DSO) libs/common/libcommon.so.0 $(root)$(libexecdir)
	-(cd $(root)$(libexecdir) && rm -f libcommon.so; $(LN_S) libcommon.so.0 libcommon.so)
	$(INSTALL_DSO) libs/storage/libstorage.so.0 $(root)$(libexecdir)
	-(cd $(root)$(libexecdir) && rm -f libstorage.so; $(LN_S) libstorage.so.0 libstorage.so)
	$(INSTALL_DSO) libs/configuration/flatfile/libflatfile.so.0 $(root)$(libexecdir)
	-(cd $(root)$(libexecdir) && rm -f libflatfile.so; $(LN_S) libflatfile.so.0 libflatfile.so)
	$(INSTALL_DSO) libs/policy_framework/libpolicy.so.0 $(root)$(libexecdir)
	-(cd $(root)$(libexecdir) && rm -f libpolicy.so; $(LN_S) libpolicy.so.0 libpolicy.so)
	$(INSTALL_DSO) libs/state/libstate.so.0 $(root)$(libexecdir)
	-(cd $(root)$(libexecdir) && rm -f libstate.so; $(LN_S) libstate.so.0 libstate.so)

install-script:
	@echo
	@-if [ -w /etc/rc.d/init.d -a -x $(CHKCONFIG) -a $(INITSCRIPT) -eq 1 ]; then \
		echo '@term_bold@Installing $(PACKAGE_NAME) scripts..@term_norm@'; \
	else \
		echo '@term_bold@Installing $(PACKAGE_NAME) scripts.. (skipping)@term_norm@'; \
	fi
	-if [ -w /etc/rc.d/init.d -a -x $(CHKCONFIG) -a $(INITSCRIPT) -eq 1 ]; then \
		$(INSTALL_SCRIPT) ../support/sella_nms.init.d $(root)/etc/rc.d/init.d/sella_nms; \
		$(CHKCONFIG) --add sella_nms; \
	fi

install-support:
	@echo
	@echo '@term_bold@Installing $(PACKAGE_NAME) configuration files..@term_norm@'
	if [ ! -e "$(root)$(sysconfdir)/sella_nms.conf" ]; then \
		$(INSTALL_SUPPORT) ../support/sella_nms.conf $(root)$(sysconfdir); \
	else \
		$(INSTALL_SUPPORT) ../support/sella_nms.conf $(root)$(sysconfdir)/sella_nms.conf.default; \
	fi
	if [ ! -e "$(root)$(sysconfdir)/policy-statements.conf" ]; then \
		$(INSTALL_SUPPORT) ../support/policy-statements.conf $(root)$(sysconfdir); \
	else \
		$(INSTALL_SUPPORT) ../support/policy-statements.conf $(root)$(sysconfdir)/policy-statements.conf.default; \
	fi
	if [ ! -e "$(root)$(sysconfdir)/format-statements.conf" ]; then \
		$(INSTALL_SUPPORT) ../support/format-statements.conf $(root)$(sysconfdir); \
	else \
		$(INSTALL_SUPPORT) ../support/format-statements.conf $(root)$(sysconfdir)/format-statements.conf.default; \
	fi
	if [ ! -e "$(root)$(sysconfdir)/map-statements.conf" ]; then \
		$(INSTALL_SUPPORT) ../support/map-statements.conf $(root)$(sysconfdir); \
	else \
		$(INSTALL_SUPPORT) ../support/map-statements.conf $(root)$(sysconfdir)/map-statements.conf.default; \
	fi
	if [ ! -d "$(root)$(sysconfdir)/policy.d" ]; then \
		$(MKDIR) "$(root)$(sysconfdir)/policy.d"; \
	fi
	-FILES="`echo ../support/policy.d/*.conf`"; \
	for FILE in $${FILES}; do \
		if [ ! -d "$${FILE}" ]; then \
			if [ ! -e "$(root)$(sysconfdir)/policy.d/$${FILE}" ]; then \
				$(INSTALL_SUPPORT) "$${FILE}" $(root)$(sysconfdir)/policy.d; \
			fi \
		fi \
	done
	@echo
	@echo '@term_bold@Installing $(PACKAGE_NAME) syntax file..@term_norm@'
	-SUBDIRS="`echo /share/vim/vim*/syntax /usr/share/vim/vim*/syntax /usr/local/share/vim/vim*/syntax /usr/local/vim/vim*/syntax`"; \
	for DIR in $${SUBDIRS}; do \
		$(TEST) -d "$${DIR}" && $(CP) -p ../support/sella_nms.vim $${DIR} || true; \
	done
	@echo
	@echo '@term_bold@Installing $(PACKAGE_NAME) Web GUI files..@term_norm@'
	-if [ -e "$(root)$(htmldir)/config/config.php" ]; then \
		$(MV) -f "$(root)$(htmldir)/config/config.php" "$(root)$(htmldir)/config/config.php.original"; \
	fi
	cd $(root)$(htmldir)/tmp && $(FIND) . -name "sella_nms-*.php" -print | $(XARGS) $(RM) -f 2>/dev/null || true;
	-$(TEST) -d ../html && (cd ../html && $(CP) -rp * $(root)$(htmldir));
	-if [ -e "$(root)$(htmldir)/config/config.php.original" ]; then \
		$(MV) -f "$(root)$(htmldir)/config/config.php" "$(root)$(htmldir)/config/config.php.default"; \
		$(MV) -f "$(root)$(htmldir)/config/config.php.original" "$(root)$(htmldir)/config/config.php"; \
	fi
	cd $(root)$(htmldir) && chmod 1777 tmp && $(FIND) . -name "CVS" -type d -print | $(XARGS) $(RM) -rf 2>/dev/null || true;
	@echo
	@echo '@term_bold@Installing $(PACKAGE_NAME) mibs..@term_norm@'
	$(INSTALL_SUPPORT) ../support/mibs/*.txt $(root)$(datadir)/mibs
	$(INSTALL_SUPPORT) ../support/mibs/rfc/*-mib $(root)$(datadir)/mibs/rfc
	$(INSTALL_SUPPORT) ../support/mibs/juniper/*.txt $(root)$(datadir)/mibs/juniper
	$(INSTALL_SUPPORT) ../support/mibs/cisco/*.my $(root)$(datadir)/mibs/cisco
	$(INSTALL_SUPPORT) ../support/mibs/extreme/*.mib $(root)$(datadir)/mibs/extreme
	$(INSTALL_SUPPORT) ../support/mibs/netscreen/*.mib $(root)$(datadir)/mibs/netscreen
	$(INSTALL_SUPPORT) ../support/mibs/arbor/*.mib $(root)$(datadir)/mibs/arbor
	$(INSTALL_SUPPORT) ../support/sella_nms.man $(root)$(mandir)/man8/sella_nms.8
	$(INSTALL_SUPPORT) ../support/sella_nms.conf.man $(root)$(mandir)/man5/sella_nms.conf.5
	$(INSTALL_SUPPORT) ../support/policy-statements.conf.man $(root)$(mandir)/man5/policy-statements.conf.5
	$(INSTALL_SUPPORT) ../support/format-statements.conf.man $(root)$(mandir)/man5/format-statements.conf.5
	$(INSTALL_SUPPORT) ../support/map-statements.conf.man $(root)$(mandir)/man5/map-statements.conf.5

lines:
	@$(FIND) -path './third-party' -prune -o -regex '^.*\.[chi][xn]*' -print | $(XARGS) $(WC) -l
		
clean:
	$(RM) -f $(TARGET) *.so.* *.o
	-@SUBDIRS="$(SUBDIRS)"; \
	for DIR in $${SUBDIRS}; do \
		echo "@term_bold@==> $${DIR}@term_norm@"; \
		(cd $${DIR} && $(MAKE) $(MFLAGS) clean) || exit 1; \
		echo "@term_bold@<== $${DIR}@term_norm@"; \
	done

distclean:
	$(RM) -f $(TARGET) $(SUPPORT) *.o config.h Makefile config.cache config.status config.log
	-@SUBDIRS="$(SUBDIRS)"; \
	for DIR in $${SUBDIRS}; do \
		echo "@term_bold@==> $${DIR}@term_norm@"; \
		(cd $${DIR} && $(MAKE) $(MFLAGS) distclean) || exit 1; \
		echo "@term_bold@<== $${DIR}@term_norm@"; \
	done

depend:
	$(SED) -ne '1,/^# DEPENDENCIES/p' Makefile.in > Makefile.depend && \
	$(CXX) -MM ${OBJS:.o=.c*} $(DEFINES) >> Makefile.depend && \
	mv -f Makefile.depend Makefile.in || rm Makefile.depend
	-@SUBDIRS="$(SUBDIRS)"; \
	for DIR in $${SUBDIRS}; do \
		echo "@term_bold@==> $${DIR}@term_norm@"; \
		(cd $${DIR} && $(MAKE) $(MFLAGS) depend) || exit 1; \
		echo "@term_bold@<== $${DIR}@term_norm@"; \
	done
	@echo
	@echo "@term_bold@You will need to re-run 'configure' to utilize the new dependencies.@term_norm@"

# --------------------------------------
#              Dependencies
# --------------------------------------

# DEPENDENCIES - DO NOT EDIT MANUALLY
main.o: main.cxx main.h config.h include/defaults.h include/defines.h \
  include/stl.h libs/common/trace.h include/stl/string include/stl/vector \
  include/stl/hash_map libs/configuration/configuration.h \
  libs/common/confignode.h include/stl/slist include/stl/utility \
  include/api.h libs/configuration/flatfile/flatfile.h \
  libs/common/nprocs.h libs/common/setproctitle.h
