# Copyright (c) 1994, 1995.  All rights reserved.
#
#        Peter Danzig of the University of Southern California.
#        Steve Miller of the University of Southern California.
#        Erhyuan Tsai of the University of Southern California.
#
# The Checker software may be used for academic, research, government,
# and internal business purposes without charge.  If you wish to sell
# or distribute the Checker software to commercial clients or partners,
# you must license the software. Please email requests to danzig@usc.edu.
#
# The Checker software is provided ``as is'', without express or
# implied warranty, and with no support nor obligation to assist in its
# use, correction, modification or enhancement.  We assume no liability
# with respect to the infringement of copyrights, trade secrets, or any
# patents, and are not responsible for consequential damages.  Proper
# use of the Checker software is entirely the responsibility of the user.
#
#
####################################################################
# Please overwrite the following defines for your system
####################################################################

# Hostname and IP address of host running checker+named
CHECKER_HOST = excalibur.usc.edu
CHECKER_IP   = 128.125.51.11

# UDP port number used by checker
CHECKER_PORT = 5222

# checker's home directory
CHECKER_PATH = /usr/checker
# files generated by checker
ERR_LOG      = $(CHECKER_PATH)/checker-err.log
ERR_STATS    = $(CHECKER_PATH)/checker-err.stats
PEC_LOG      = $(CHECKER_PATH)/checker-pec.log
PEC_RESULT   = $(CHECKER_PATH)/checker-pec.result

# path for placing patched script files,
# they shall be moved to the cgi-bin directory of http
CGI_PATH     = httpd/cgi-bin

# the source of script files
SCRIPTS_PATH = httpd/scripts

# path to dig for issuing commands to checker
DIG 	     = /usr/local/bin/dig
#
#
CC = cc
CFLAGS= -I../checker -g -c 
LIBS= ../res/libresolv.a ../compat/lib/lib44bsd.a
.KEEP_STATE:
#
####################################################################
############ no user servicable parts beyond this point ############
####################################################################

SCRIPTS = \
       checker-err-log.html            checker-pec-log.html    \
       checker-err.html                checker-pec.html        \
       checker-gen-err-report.html     checker-reconfig.html   \
       checker-gen-pec-report.html     err-recent-rpt          \
       checker-off.html                pec-filter.cgi          \
       checker-on.html                 pec-filter              \
       checker-pec-filter.html 
PATCHING = \
        -e 's?@hostname@?$(CHECKER_HOST)?g'	\
        -e 's?@ip@?$(CHECKER_IP)?g'		\
        -e 's?@port@?$(CHECKER_PORT)?g' 	\
        -e 's?@dig@?$(DIG)?g' 			\
        -e 's?@err_log@?$(ERR_LOG)?g' 		\
        -e 's?@err_stats@?$(ERR_STATS)?g' 	\
        -e 's?@pec_log@?$(PEC_LOG)?g' 		\
        -e 's?@pec_result@?$(PEC_RESULT)?g' 	\
        -e 's?@checker_path@?$(CHECKER_PATH)?g' 
#
#
SRC  = src
src1 = $(SRC)/checker-pec.c $(SRC)/checker.h $(SRC)/pec.c 
obj1 = checker-pec.o pec.o

src2 = $(SRC)/checker-err.c $(SRC)/hdl_pkt.c $(SRC)/access_i.c $(SRC)/access_q.c \
       $(SRC)/checks.c $(SRC)/reports.c  $(SRC)/config.c  
obj2 = checker-err.o hdl_pkt.o access_i.o access_q.o checks.o reports.o \
	config.o  

all:	cklib mkpass checker-err do-scripts

checker-pec.o   : $(SRC)/checker-pec.c $(SRC)/checker.h
	${CC} ${CFLAGS} $(SRC)/checker-pec.c

pec.o 		: $(SRC)/pec.c $(SRC)/checker.h
	${CC} ${CFLAGS} $(SRC)/pec.c

checker-err.o   : $(SRC)/checker-err.c $(SRC)/checker.h
	${CC} ${CFLAGS} $(SRC)/checker-err.c

hdl_pkt.o   	: $(SRC)/hdl_pkt.c $(SRC)/checker.h
	${CC} ${CFLAGS} $(SRC)/hdl_pkt.c

access_i.o   	: $(SRC)/access_i.c $(SRC)/checker.h
	${CC} ${CFLAGS} $(SRC)/access_i.c

access_q.o   	: $(SRC)/access_q.c $(SRC)/checker.h
	${CC} ${CFLAGS} $(SRC)/access_q.c

checks.o   	: $(SRC)/checks.c $(SRC)/checker.h
	${CC} ${CFLAGS} $(SRC)/checks.c

reports.o   	: $(SRC)/reports.c $(SRC)/checker.h
	${CC} ${CFLAGS} $(SRC)/reports.c

config.o   	: $(SRC)/config.c $(SRC)/checker.h
	${CC} ${CFLAGS} $(SRC)/config.c

makepass.o   	: $(SRC)/makepass.c
	${CC} ${CFLAGS} $(SRC)/makepass.c


cklib : $(obj1) $(src1)
	ar cru libckr.a ${obj1}
	ranlib libckr.a
	@echo "checker-pec library finished"

mkpass:	makepass.o
	cc -o makepass makepass.o
	@echo "makepass utility finished"

checker-err : $(obj2) $(src2)
	${CC} ${CFLAG} -o $@ $(obj2) ${LIBS}
	@echo "checker-err utility finished"

# patching scripts files for user's environment
do-scripts:
	for file in $(SCRIPTS); do \
	  sed $(PATCHING) $(SCRIPTS_PATH)/$$file.in > $(CGI_PATH)/$$file; \
	  chmod a+rx $(CGI_PATH)/$$file; \
	done 
	sed $(PATCHING) start_named.in > start_named 
	chmod a+rx start_named 

clean:
	rm -f $(obj1) $(obj2) makepass.o
	rm -f checker-err libckr.a makepass start_named
	rm -f httpd/cgi-bin/*
