# $Id: Makefile,v 1.3 1992/06/19 00:40:23 aggarwal Exp $
#
# Makefile for 'trapmon'
#

## SET THIS
# Directories needed by the Makefile. See description in ../Makefile
#
TOP = 		/usr/nocol
SRCDIR =	$(TOP)/src
BINDIR = 	$(TOP)/bin

# directory for CMU snmp sources
CMUSNMP =	$(SRCDIR)/cmu-snmp
INCLUDEDIR = 	$(SRCDIR)/include

## SET THIS
# Directories needed by the program.
#	DATADIR			for creating the NSMON-OUTPUT
DATADIR = 	$(TOP)/data

## SET THIS
# Set the various defines for compile time defines:
#
#       -DNFS           if you are using NFS for file locking.
#
SYSDEFS =  -DNFS

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

##
# The various directories that are needed in the program. Should NOT
# have trailing '/'.
DIRDEFS =	-DDATADIR=\"$(DATADIR)\"

## Compilation definitions
#  The CDEF specs are specific to this sub-module. The CFLAGS can be
#  over-ridden by the top level makefile.
CC =		cc
CDEFS =		$(DIRDEFS) $(SYSDEFS) -DHAVE_FD_MACROS  \
		-I$(CMUSNMP)/include
LIBS =		-L$(CMUSNMP)/lib -lsnmp
CFLAGS = 	-g -I$(INCLUDEDIR)

OBJECTS = 	trapmon.o

TRAPMON =	trapmon

$(TRAPMON): CMU $(OBJECTS) Makefile
	$(CC) $(CFLAGS) $(OBJECTS) $(LIBS) -o $@

CMU:
	@echo 'Making the CMU SNMP library under $(CMUSNMP)'
	cd $(CMUSNMP)/snmplib ; make all install

.c.o:
	$(CC) -c $(CFLAGS) $(CDEFS) $<

## The dependencies in case 'mkdep' not used
#
$(OBJECTS): $(INCLUDEDIR)/nocol.h  $(INCLUDEDIR)/trapmon.h

install: $(TRAPMON)
	install -c -m 4750 $(TRAPMON) $(BINDIR)/
	@if [ `whoami` = "root" ]; then \
		chown root $(BINDIR)/$(TRAPMON) ;\
		ls -lg $(BINDIR)/$(TRAPMON) ;\
	 else \
		echo "___Installed $(TRAPMON) needs to be root suid___" ;\
		echo "Do as root manually" ;\
	 fi

clean:
	/bin/rm -f $(TRAPMON) $(OBJECTS) core a.out
	if [ -d $(CMUSNMP)/snmplib ]; then \
		( cd $(CMUSNMP)/snmplib ; make clean ) ;\
	else \
		: ;\
	fi

rcs:
	@echo "Doing 'rcs' in 'nsmon'
	@-for i in $(OBJS); do \
		$(CO) -q `basename $$i .o`.c ;\
	  done
