# $Id: Makefile,v 1.18 1994/06/17 18:02:26 vikas Exp $
#
# Makefile for 'pingmon'
#
# This file is pretty complicated because the same objects create OSIpingmon
# as well as IPpingmon. Only the compile time definitions are different.
# One way was to have two separate Makefile's but passing the definitions
# between three layers of 'make' is kinda hairy (3 layers since invoked from
# the main 'nocol' makefile).
#
# Anyway, you can do the following:
#
# 	make PROTOCOL=IP
#	make PROTOCOL=OSI
#
## SET THIS
# Directories needed by the Makefile
TOP =           /home/netmgt/nocol
SRCDIR =	$(TOP)/src

BINDIR =        $(TOP)/bin
ETCDIR =        $(TOP)/etc
INCLUDEDIR =    $(SRCDIR)/include
LIBDIR =	$(SRCDIR)/lib

## SET THIS
# Directories needed by the program.
#	IPPING		location of the IP ping program (useing multiping ?)
#	RPCPING		location of the RPC ping (see under support/ dir)
#	OSIPING		location of the OSI ping program
IPPING =	/usr/etc/ping
OSIPING =	/usr/sunlink/bin/osiping
RPCPING =	rpcping

## SET THIS
# Set the various defines for compile time defines:
# 	-DMULTIPING	if using IPPING = 'multiping'
#
SYSDEFS =	# -DMULTIPING

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

CC =		cc
CDEFS =		$(SYSDEFS)
LIBS =		-lnocol  $(SYSLIBS)
CFLAGS = 	-g -I$(INCLUDEDIR) -I../include -L$(LIBDIR) -L../lib

PINGMONS =	ippingmon osipingmon rpcpingmon
OBJECTS = 	pingmon.o poll_sites.o

## The following is a bit hairy since we are trying to build two
#  similar targets with very minor differences. The idea is to
#  always build both targets (hence we delete the objects after
#  building the first target). Note that we also have to pass
#  the INCLUDEDIR thru- hence the SRCDIR definition...

all:	$(PINGMONS)
	@touch $(PINGMONS) IFCpingmon

# Delete the objects after making the first two targets. Leave them after
# making the last target.
ippingmon: IFCpingmon
	@/bin/rm -f $(OBJECTS)
	@make CC="$(CC)" CDEFS="$(CDEFS) -DIP -DPING='\"$(IPPING)\"' " \
		CFLAGS="$(CFLAGS)" SRCDIR=$(SRCDIR) pingmon ;\
	 mv pingmon ippingmon ; /bin/rm -f $(OBJECTS) ; \
	 echo "" ; echo " ======== Made IP version of pingmon ========" ;

osipingmon: IFCpingmon
	@make CC="$(CC)" CDEFS="$(CDEFS) -DOSI -DPING='\"$(OSIPING)\"' " \
		CFLAGS="$(CFLAGS)" SRCDIR=$(SRCDIR) pingmon ;\
	 mv pingmon osipingmon ; /bin/rm -f $(OBJECTS) ; \
	 echo "" ; echo " ======== Made OSI version of pingmon ========" ;

rpcpingmon: IFCpingmon
	@/bin/rm -f $(OBJECTS)
	@make CC="$(CC)" CDEFS="$(CDEFS) -DRPC -DPING='\"$(RPCPING)\"' " \
		CFLAGS="$(CFLAGS)" SRCDIR=$(SRCDIR) pingmon ;\
	 mv pingmon rpcpingmon ; \
	 echo "" ; echo " ======== Made RPC version of pingmon ========" ;

IFCpingmon:	*.c $(INCLUDEDIR)/nocol.h  $(INCLUDEDIR)/pingmon.h
	/bin/rm -f IFCpingmon

pingmon: $(OBJECTS)
	$(CC) $(CFLAGS) $(OBJECTS) $(LIBS) -o pingmon

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

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

$(IPPING) $(OSIPING) $(RPCPING): IFC
	@-[ -f "$@" ] || \
	 { \
		echo "WARNING: $@ does not exist" ;\
		echo "      Install $@ with proper owner and mode"; \
		echo '      (Mode should be 4751 and owner should be root) '; \
	exit 1 ;\
	 }

# To force checking
IFC:

install: 	$(PINGMONS)
	-for i in $(PINGMONS); \
	   do [ -f $$i ] && $(INSTALL) -c -m 751 $$i $(BINDIR)/ ;done
	@echo ""; echo "___Update CONFIG files with hostnames ___ in $(ETCDIR)"

clean:
	/bin/rm -f $(PINGMONS) $(OBJECTS) IFCpingmon pingmon core a.out

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