#
# Makefile for document access counter.
#
# In case standard have advanced and I didn't follow, add -Dname to CFLAGS in
# order to specify the environment vatiable name for the refering document. As 
# for now it stands HTTP_REFERER when you use netscape, Mosaic doesn't support 
# this yet.
#

CC=g++

VERSION=2.0a

SOURCES=counter.cc devar.cc main.cc misc.cc url.cc
HEADERS=counter.h devar.h url.h
ALLFILES=${SOURCES} ${HEADERS} README Makefile INSTALL USAGE

OBJECTS=${SOURCES:.cc=.o}

#
# EXEC_G - The pathname to the program which will output a graphic count
# EXEC_A - The pathname to the program which will output a ascii count
#
EXEC_G=/usr/local/etc/httpd/cgi-bin/count_g_t
EXEC_A=/usr/local/etc/httpd/cgi-bin/count_a_t

#
# CFLAGS may contain:
#    -DLOGFILE=pathname to indicate a diffrent logfile then the default 
#    -DLOCKFILE=pathname to indicate a diffrent lockfile then the default
#    -DTMPFILE=pathname to indicate ...
#    -DENV_REFERER_NAME=env_name environment variable that specifies the name
#                       of the document which called the program
#    -DMAXCOUNT=count, The number of times it will retry to lock access before
#               failing
#    -DDELAY=delay, the delay in seconds between attempts
#    -DLOCAL_ONLY will remove the heading of the url in the logfile
#    -DHTTPD_CONF=file, ***MUST*** be defined with LOCAL_ONLY and contain the 
#               path to the httpd configuration file (in order to read aliases
#    -DIGNOREHOST=hostlist, list of hosts to ignore when counting
#    -DCMDLN, Enable command line options for maintenance.
#    -DPRG_FILTER, Enable teh use of the counter like a filter to count files
#              downloading.
#
HTTPDIR=/usr/local/etc/httpd
# HTTPDIR=/u/opers/balder/work/counter
REF=-DENV_REFERER_NAME=HTTP_REFERER
DFILE=-DLOGFILE=\"${HTTPDIR}/htdocs/counts.txt\"
LFILE=-DLOCKFILE=\"${HTTPDIR}/htdocs/counts.lck\"
TFILE=-DTMPFILE=\"${HTTPDIR}/htdocs/tmp.cnt\"
FILES=${DFILE} ${LFILE} ${TFILE}
MAXCOUNT=-DMAXCOUNT=5
DELAY=-DDELAY=1
# MISC=-DLOCAL_ONLY -DHTTPD_CONF=\"/usr/local/etc/httpd/conf/srm.conf\"
# ING=IGNOREHOST=\"host_a\",\"host_b"
MISC=-DCMDLN -DPRG_FILTER -DHTTPD_CONF=\"/usr/local/etc/httpd/conf/srm.conf\"

CFLAGS=-g ${REF} ${FILES} ${MAXCOUNT} ${DELAY} ${MISC} ${ING}

counter: ${OBJECTS} Makefile
	${CC} ${CFLAGS} -o counter ${OBJECTS}
	/bin/rm -f ${EXEC_G} ${EXEC_A}
	cp counter ${EXEC_G}
	ln -s ${EXEC_G} ${EXEC_A}
	chmod 755 ${EXEC_G}

clean:
	/bin/rm -rf ${OBJECTS} core counter

counter.o: counter.h counter.cc
	${CC} ${CFLAGS} -c counter.cc

devar.o: devar.h devar.cc 
	${CC} ${CFLAGS} -c devar.cc

main.o: counter.h main.cc Makefile
	${CC} ${CFLAGS} -c main.cc

misc.o: misc.cc
	${CC} ${CFLAGS} -c misc.cc
	
url.o: url.h url.cc
	${CC} ${CFLAGS} -c url.cc

archive: counter-${VERSION}.tar.gz

counter-${VERSION}.tar.gz: ${ALLFILES}
	tar cf counter-${VERSION}.tar ${ALLFILES}
	gzip -9 counter-${VERSION}.tar