# $Header: /home/vikas/netmgt/nocol/src/RCS/Makefile,v 1.11 1994/11/29 20:14:39 vikas Exp $
#
# Makefile for 'nocol'. This file simply calls on other Makefiles in
# the subdirectories to do all the work. All the definitions are used
# by the other Makefiles which then do all the compile time definitions.
#
# Check: SRCDIR, TOP, PING, NLOG_HOST, SYSLIBS, NEEDOBJS
#
# To 'make' for only one program, use 
#	make "SRCS=trapmon" [install|clean]
#

##
# CHECK THE VALUE OF IPPING and OSIPING below.

##
# Set TOP here to a directory where everything will be installed (etc, data)
# 'nocol' does a chroot to this directory when it runs.
TOP  =		/nocol

##
# Set SRCDIR to the toplevel location of the NOCOL sources (this directory ?)
SRCDIR=		$(TOP)/src

##
# Set MANDIR for the manpages and MANEXT for the man pages extension
MANDIR = $(TOP)/man
MANEXT = n

##
# Library calls not a part of your system. Define NEEDOBJS here.
# These will be compiled into 'lib/libnocol'
#   putenv.o		for putenv() library call - on NeXT
#   random.o		if you don't have random()  - on Solaris, HP
#   bstring.o		for bcmp() bzero()  bcopy() - on Solaris, HP
#   ftime.o		for ftime() - on Solaris, HP, OSF
#   
NEEDOBJS =	# putenv.o random.o

##
# Hostname of the machine that will be running the noclogd logging
# daemon (can give IP address instead).
#
NLOG_HOST =	nocol.navya.com

##
# An email address for receiving periodic statistical reports and
# first notifications of a site going critical.
OPSMAIL =	ops@your.domain

##
# Location of PERL on your system. This is used for substitutions in
# the perlnocol/ monitors.
PERL =		/usr/local/bin/perl

##
# The special system definitions. Define:
#	-DNOCOL		Always defined.
#  	-DMULTIPING	If setting IPPING to use 'multiping'. Check IPPING also
#
SYSDEFS =	-DNOCOL  -DMULTIPING

##
# Special libraries that might be needed to link on your system.
#  -lresolv		On SunOS, Solaris2.x, BSDI
#  -lsocket		On Solaris2.x
#  -lnsl		On Solaris2.x
#  -lcompat		On BSDI/386 for ftime.o
#
SYSLIBS =	-lresolv # -lsocket -lnsl

##
# special defines for  pingmon. Can have an IP ICMP ping, an IP RPC ping and
# an OSI ping.
#	Set IPPING to /etc/ping or $(BINDIR)/ping or $(BINDIR)/multiping
#	Make sure that the output of the ping command is something like:
#		% ping -s nisc.jvnc.net 100 5
#	See INSTALL or pingmon/poll_sites.c for more details.
#
#	If using 'multiping', also set SYSDEFS value.
#
IPPING =        $(BINDIR)/multiping
RPCPING =	$(BINDIR)/rpcping
OSIPING =       /usr/sunlink/osi/etc/osi_ping

## Location of useful utility programs
#   CO		location of the 'RCS' check-out program (unless in path)
#   AR		the archive program to build object libraries, typically
#		'ar r'. On Solaris set to 'ld -r -o'.
#   RANLIB	if you don't have it, set to 'touch' or 'ls'. Solaris/HP
#		systems dont have it.
#   INSTALL	Set to a BSD type 'install'. (bsdinst/installbsd on OSF
#		or SCO systems).  If in doubt, simply point to
#		'$(SRCDIR)/utility/myinstall'  (HP/Solaris systems).
#		
#   
CO =		co
AR =		ar r
RANLIB =	ranlib
INSTALL =	install


# Which programs are to be compiled and installed.
#	etherload	ethernet load and pps monitor
#	eventselect	print out events that match certain criterion
#	genmon		Generic monitoring interface (ascii to nocol struct)
#	netconsole	the nocol display for all the monitored data
#	noclog		the noclogd logging daemon
#	nsmon		Nameserver monitor
#	perlnocol	Perl interface and associated monitors
#	pingmon		Reachability monitors (ICMP, RPC, OSI)
#	portmon		Check TCP ports on various machines.
#	tpmon		Data thruput monitor
#	trapmon		SNMP trap monitor
#	utility		Small utility programs
#	doc		Documentation and manual pages
#
SRCS =   	lib eventselect etherload genmon netconsole noclog nsmon \
		perlnocol pingmon portmon tpmon trapmon \
		utility doc support/multiping support/rpcping

####
####	Can leave the rest alone
####

# These are defined here so that install can create these directories
# if they do not exist.
#	BINDIR		where the programs are installed
#	ETCDIR		location of configuration files
#	DATADIR		where datafiles for monitoring programs are created
#	MSGSDIR		for message files that the nocol display shows in
#			in the 'messages' sub-window
BINDIR= 	$(TOP)/bin
ETCDIR=		$(TOP)/etc
DATADIR=	$(TOP)/data
MSGSDIR=	$(TOP)/msgs

# This is needed for building and linking common routines.
LIBDIR=		$(SRCDIR)/lib

# Directory/file definitions that override the ones in the other 'Makefile's
DIRDEFS=	TOP="$(TOP)" \
		SRCDIR="$(SRCDIR)" \
		LIBDIR="$(LIBDIR)" \
		BINDIR="$(BINDIR)" \
		ETCDIR="$(ETCDIR)" \
		DATADIR="$(DATADIR)" \
		MSGSDIR="$(MSGSDIR)" \
		MANDIR="$(MANDIR)" \
		IPPING="$(IPPING)" \
		RPCPING="$(RPCPING)" \
		OSIPING="$(OSIPING)"

##
# Compile defs
#	CC	which C compiler. 'GCC' earlier than 2.x might fail on Sparc
#	CFLAGS	-I<includes dir> [-DDEBUG]
#	YACC	'yacc' or 'bison -y'
#
CC =		cc
CFLAGS =	-g -I$(SRCDIR)/include -L$(LIBDIR)
YACC =		yacc

# General definitions that override the ones in the other 'Makefile's
GENDEFS=	NLOG_HOST="$(NLOG_HOST)" OPSMAIL="$(OPSMAIL)" PERL="$(PERL)" \
		MANEXT="$(MANEXT)" NEEDOBJS="$(NEEDOBJS)" \
		SYSDEFS="$(SYSDEFS)" SYSLIBS="$(SYSLIBS)" \
		CC="$(CC)" CFLAGS="$(CFLAGS)" YACC="$(YACC)" \
		CO="$(CO)" AR="$(AR)" RANLIB="$(RANLIB)" INSTALL="$(INSTALL)"

##
# This is the list of files that need to be 'tar-red'. Using the FF option
# in the tar command and also excluding the RCS directories further down.
DIST =	COPYRIGHT HISTORY INSTALL PORTING README Makefile \
	cmu-snmp include $(SRCS)

##
# Following files are excluded from the distribution
NOTDIST = makefile etherload/docs local-stuff support/mping \
	  cmu-snmp/bin cmu-snmp/oldmibs


all:	libnocol.a
	@-if [ "$(OS)" = "" ]; then \
	    OS=`uname -s -r`; \
	 fi; \
	 for i in $(SRCS); do \
	  ( echo "" ; echo "MAKING IN $$i" ; echo "----------" ; cd $$i ; \
	    make $(MFLAGS) OS="$$OS" $(GENDEFS) $(DIRDEFS) ; ) \
	 done

lib:	libnocol.a
libnocol.a:
	@echo "" ; echo "MAKING IN lib" ; echo "----------"
	@-if [ "$(OS)" = "" ]; then \
	    OS=`uname -s -r`; \
	 fi; \
	 ( cd lib ; make $(MFLAGS) OS="$$OS" $(GENDEFS) $(DIRDEFS) ;) 


## Ultrix make balked at the tests for directories, hence the second test
install:	lib
	-[ -d $(TOP) ] || mkdir  $(TOP)
	-[ -d $(DATADIR) ] || mkdir $(DATADIR)
	-[ -d $(ETCDIR) ] || mkdir $(ETCDIR)
	-[ -d $(ETCDIR)/samples ] || mkdir $(ETCDIR)/samples
	-[ -d $(BINDIR) ] || mkdir $(BINDIR)
	@[ -d $(TOP) ] && [ -d $(DATADIR) ] && [ -d $(ETCDIR) ] \
		&& [ -d $(BINDIR) ]
	@-(touch NoColL ; $(INSTALL) -c -m 750 NoColL /tmp/;) >/dev/null 2>&1 ;
	@(if [ -f /tmp/NoColL ]; then rm -f NoColL /tmp/NoColL; else \
	  echo "YOU HAVE AN INCOMPATIBLE install, use 'myinstall' instead" ;\
	  rm -f NoColL /tmp/NoColL ; exit 1 ; fi)

	@echo make $(MFLAGS) $(GENDEFS) $(DIRDEFS) install ;
	@-for i in $(SRCS); do \
	  ( echo "" ; echo "MAKING IN $$i" ; echo "----------" ; cd $$i ; \
		make $(MFLAGS) $(GENDEFS) $(DIRDEFS) install ; ) ;\
	done
	@-for i in */*-confg; do \
		$(INSTALL) -m 444 -c  $$i $(ETCDIR)/samples/ ;\
	done

tar:	nocol.tar

nocol.tar:
	@( if [ ! -d /var/tmp/t ]; then mkdir /var/tmp/t ;fi ;\
	   if [ ! -d /var/tmp/t/nocol ]; then mkdir /var/tmp/t/nocol ; fi ;\
	   if [ ! -d /var/tmp/t/nocol ]; then \
		echo "Fatal error: cannot create directory  /var/tmp/t/nocol";\
		exit 1 ; fi ;\
	   (cd /var/tmp/t/nocol/ ; rm -rf XCLUDEFILES src ; mkdir src) ;\
	   for i in $(DIST) ; do \
		find $$i \( -name RCS -o -name '*~' \) -print  >> /var/tmp/t/nocol/XCLUDEFILES ;\
	   done ;\
	   for i in $(NOTDIST) ; do \
		echo "$$i" >> /var/tmp/t/nocol/XCLUDEFILES ;\
	   done ;\
	   echo "Copying src files to tmp location" ;\
	   tar cfX - /var/tmp/t/nocol/XCLUDEFILES $(DIST) |\
			 ( cd /var/tmp/t/nocol/src ; tar xf -) ;\
	   rm -f /var/tmp/t/nocol/XCLUDEFILES ;\
	   cd /var/tmp/t/ ;\
	   echo "*** Present working directory is `pwd` ***" ;\
	   if [ ! `pwd` = '/var/tmp/t' ]; then \
		echo "FATAL ERROR, couldn't cd to tmp dir" ;\
		exit 1 ;\
	   fi ;\
	   tar cf nocol.tar nocol )
	@( mv /var/tmp/t/nocol.tar nocol.tar ;\
	    /bin/rm -rf /var/tmp/t ;\
	    tar tf nocol.tar )
	@echo "CREATED nocol.tar"
	    

clean:
	@for i in $(SRCS); do \
		( cd $$i ; make $(MFLAGS) $(DIRDEFS) $(GENDEFS) clean ; ) ;\
	done

rcs:
	@-for i in $(SRCS); do \
		( cd $$i ; make $(MFLAGS) $(GENDEFS) rcs ; ) ;\
	done 
###
