# $Id: Makefile,v 1.11 1992/06/19 00:44:10 aggarwal 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 =           /usr/nocol
SRCDIR =	$(TOP)/src

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

## SET THIS
# Directories needed by the program.
# 	DATADIR			for creating the PING-OUTPUT
#	IPNODESFILE		location of IP nodes/hosts file
#	IPPING			location of the IP ping program
#	OSINODESFILE		location of the OSI nodes/hosts file
DATADIR =       $(TOP)/data

IPNODESFILE =	$(ETCDIR)/ipnodes
IPPING =	/usr/etc/ping

OSINODESFILE =	$(ETCDIR)/osinodes
OSIPING =	/usr/sunlink/bin/osiping

## Default protocol is IP Set to OSI for OSIpingmon.
PROTOCOL = 	IP

## 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 '/'.
IPDIRDEFS =	-DDATADIR=\"$(DATADIR)\" \
                -DNODESFILE=\"$(IPNODESFILE)\" \
		-DPING=\"$(IPPING)\"


OSIDIRDEFS =	-DDATADIR=\"$(DATADIR)\" \
                -DNODESFILE=\"$(OSINODESFILE)\" \
		-DPING=\"$(OSIPING)\"


# Compilation definitions
# 	-DMULTIPING	in IP_CDEFS if using IPPING = 'multiping'
CC =		cc
IP_CDEFS = 	$(SYSDEFS) $(IPDIRDEFS)  -DIP
OSI_CDEFS = 	$(SYSDEFS) $(OSIDIRDEFS) -DOSI
LIBS =
CFLAGS = 	-g -I$(INCLUDEDIR)

OBJECTS = 	fgetline.o pingmon.o poll_sites.o standalone.o

PINGMONS =	ippingmon osipingmon

$(PINGMONS): pingmon

pingmon: reset $(OBJECTS) Makefile
	$(CC) $(CFLAGS) $(OBJECTS) $(LIBS) -o pingmon
	@if [ $(PROTOCOL) = "IP" ]; then \
		make $(IPPING) IPPING=$(IPPING) ;\
		cp pingmon ippingmon ;\
		echo "Made $(PROTOCOL) version of pingmon" ;\
		ls -lg ippingmon ;\
	 else \
		make $(OSIPING) OSIPING=$(OSIPING)  ;\
		cp pingmon osipingmon ;\
		echo "Made $(PROTOCOL) version of pingmon" ;\
		ls -lg osipingmon ;\
	 fi

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

.c.o:
	@if [ $(PROTOCOL) = "IP" ]; then \
		$(CC) -c $(CFLAGS) $(IP_CDEFS)  $< ;\
		echo "$(CC) -c $(CFLAGS) $(IP_CDEFS)  $<" ;\
	 elif [ $(PROTOCOL) = "OSI" ]; then \
		$(CC) -c $(CFLAGS) $(OSI_CDEFS) $< ;\
		echo "$(CC) -c $(CFLAGS) $(OSI_CDEFS)  $<" ;\
	 fi


$(IPPING) $(OSIPING): IFC
	@-[ -x $@ ] || \
	 { \
		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 p in $(PINGMONS); do \
		if [ -x $$p ]; then\
			install -c -m 751 $$p $(BINDIR)/ ; fi ;\
	 done


## Clean up all except the newly created required binary. This cleanup allows
# the same Makefile to make ippingmon and osipingmon
reset:
	/bin/rm -f $(OBJECTS) core a.out

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

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