################ Change following ########################
##  must be matched to descriptions in html files ########
##  some other parameters exist in opengatesrv.h  ########
##########################################################
WWWTOP = /usr/local/www
DOCDIR = /data
CGIDIR = /cgi-bin
OPENGATEDIR = /opengate
CONFIGPATH = /etc/opengate
LOCKFILE = /tmp/opengate.lock

DOCUMENTROOT = ${WWWTOP}${DOCDIR}
INSTALLDOCPATH = ${WWWTOP}${DOCDIR}${OPENGATEDIR}
INSTALLCGIPATH = ${WWWTOP}${CGIDIR}${OPENGATEDIR}

CFLAGS= -O4 -Wall

.if exists(/usr/local/include/ldap.h)
LIBS = -lssl -lcrypto -lradius -lpam -lezxml -L../ezxml -lldap -llber -L/usr/local/lib
.else
LIBS = -lssl -lcrypto -lradius -lpam -lezxml -L../ezxml
.endif

OBJS = utilities.o comm-auth.o comm-cgi.o watch-client.o comm-ipfw.o comm-ip6fw.c comm-arp.o comm-ndp.o error.o tcp_connect.o sock_ntop_host.o wrapper.o signal.o auth-pam.o auth-rad.o auth-pop3s.o comm-userdb.o get-param.o auth-ftps.o auth-ldap.o htmltemplate.o addr-convert.o get-mac.o ctrl-firewall.o ctrl-alarms.o
MAINPROGO = main.o
HDRS = opengatesrv.h
MAINPROG = opengatesrv
AUTHPROGO = opengateauth.o
AUTHPROG = opengateauth
FWDPROGO = opengatefwd.o
FWDPROG = opengatefwd
LIBOPT = ezxml

TESTPROGS = test-get-param test-comm-auth test-comm-ipfw test-watch-client test-cgi
CLEANFILES = *.o *~ *.core

all:	${MAINPROG} ${AUTHPROG} ${FWDPROG} ${TESTPROGS} ${LIBOPT}

opengatesrv:	${OBJS} ${MAINPROGO} ${LIBOPT}
		${CC} ${CFLAGS} -o $@ ${OBJS} ${MAINPROGO} ${LIBS}

opengateauth:	${OBJS} ${AUTHPROGO} ${LIBOPT}
		${CC} ${CFLAGS} -o $@ ${OBJS} ${AUTHPROGO} ${LIBS}

opengatefwd:	${OBJS} ${FWDPROGO} ${LIBOPT}
		${CC} ${CFLAGS} -o $@ ${OBJS} ${FWDPROGO} ${LIBS}

test-get-param:	${OBJS} test-get-param.o ${LIBOPT}
		${CC} ${CFLAGS} -o $@ ${OBJS} test-get-param.o ${LIBS}

test-comm-auth:	${OBJS} test-comm-auth.o ${LIBOPT}
		${CC} ${CFLAGS} -o $@ ${OBJS} test-comm-auth.o ${LIBS}

test-comm-ipfw:	${OBJS} test-comm-ipfw.o ${LIBOPT}
		${CC} ${CFLAGS} -o $@ ${OBJS} test-comm-ipfw.o ${LIBS}

test-watch-client:	${OBJS} test-watch-client.o ${LIBOPT}
		${CC} ${CFLAGS} -o $@ ${OBJS} test-watch-client.o ${LIBS}

test-cgi:	${OBJS} test-cgi.o ${LIBOPT}
		${CC} ${CFLAGS} -o $@ ${OBJS} test-cgi.o ${LIBS}

ezxml:	
		${MAKE} -C ../ezxml
clean:
		rm -f ${MAINPROG} ${AUTHPROG} ${FWDPROG} ${TESTPROGS} ${CLEANFILES}
		${MAKE} clean -C ../ezxml

install:	del-lockfile install-cgi install-html install-conf

del-lockfile:
.if exists(${LOCKFILE})
		# remove lockfile
		rm ${LOCKFILE}
.endif

install-cgi:	${MAINPROG} ${AUTHPROG} ${FWDPROG}
		## Copy main CGI program and Set S bit ##
.if !exists(${INSTALLCGIPATH})
		mkdir ${INSTALLCGIPATH}
.endif
		cp ${MAINPROG} ${INSTALLCGIPATH}/${MAINPROG}.cgi
		chmod 4755 ${INSTALLCGIPATH}/${MAINPROG}.cgi
		cp ${AUTHPROG} ${INSTALLCGIPATH}/${AUTHPROG}.cgi
		chmod 755 ${INSTALLCGIPATH}/${AUTHPROG}.cgi
		cp ${FWDPROG} ${INSTALLCGIPATH}/${FWDPROG}.cgi
		chmod 755 ${INSTALLCGIPATH}/${FWDPROG}.cgi
		#

install-html:
		## Copy HTML documents and java ##
.if !exists(${INSTALLDOCPATH})
		mkdir ${INSTALLDOCPATH}
.endif
		cp -R ../javahtml/* ${INSTALLDOCPATH}
		#
		# Replace index.html.var
.if exists(${DOCUMENTROOT}/index.html.var) && !exists(${DOCUMENTROOT}/index.html.var.original)
		mv ${DOCUMENTROOT}/index.html.var ${DOCUMENTROOT}/index.html.var.original
.endif
		mv ${INSTALLDOCPATH}/index.html.var ${DOCUMENTROOT}/index.html.var
		#
		# Remove favicon.ico
.if exists(${DOCUMENTROOT}/favicon.ico)
		mv ${DOCUMENTROOT}/favicon.ico ${DOCUMENTROOT}/favicon.ico.original
.endif
		#
		# Remove index.html
.if exists(${DOCUMENTROOT}/index.html) && !exists(${DOCUMENTROOT}/index.html.original)
		mv ${DOCUMENTROOT}/index.html ${DOCUMENTROOT}/index.html.original
.endif

install-conf:
		## Copy Config files ##
.if !exists(${CONFIGPATH})
		mkdir ${CONFIGPATH}
.endif
		cp  ../conf/opengatesrv.conf.sample ${CONFIGPATH}
		cp  ../conf/rc.firewall.sample ${CONFIGPATH}
		cp  ../conf/rc.firewall6.sample ${CONFIGPATH}
		cp ../conf/ipfwctrl.pl.sample  ${CONFIGPATH}
		sed 's|<DocumentRoot>.*</DocumentRoot>|<DocumentRoot>${DOCUMENTROOT}</DocumentRoot>|' ../conf/opengatesrv.conf.sample | sed 's|<CgiDir>.*</CgiDir>|<CgiDir>${CGIDIR}</CgiDir>|' | sed 's|<OpengateDir>.*</OpengateDir>|<OpengateDir>${OPENGATEDIR}</OpengateDir>|' | sed 's|<LockFile>.*</LockFile>|<LockFile>${LOCKFILE}</LockFile>|'  > ${CONFIGPATH}/opengatesrv.conf.sample
		#
		#------------------------------------------------------#
		# COPY above x.sample to x and EDIT it, if you need.   #
		#   Eg. 'cp opengatesrv.conf.sample  opengatesrv.conf' #
		#------------------------------------------------------#


main.o:		${HDRS}

utilities.o:	${HDRS}

comm-auth.o:	${HDRS}

comm-ipfw.o:	${HDRS}

comm-cgi.o:	${HDRS}

watch-client.o:	${HDRS}

comm-arp.o:	${HDRS}

comm-ndp.o:	${HDRS}

comm-userdb.o:	${HDRS}

ctrl-firewall.o:	${HDRS}

ctrl-alarms.o:	${HDRS}

auth-pam.o:	${HDRS}

auth-rad.o:	${HDRS}

auth-pop3s.o:	${HDRS}

auth-ftps.o:	${HDRS}

auth-ldap.o:	${HDRS}
.if exists(/usr/local/include/ldap.h)
		${CC} ${CFLAGS}  -I/usr/local/include -c $<
.else
		${CC} ${CFLAGS} -DLDAP_NOT_INSTALLED -c $<
.endif

get-param.o:	${HDRS}

get-mac.o:	${HDRS}

opengateauth.o:	${HDRS}

opengatefwd.o:	${HDRS}

htmltemplate.o:	${HDRS}

addr-convert.o:	${HDRS}

test-get-param.o:	${HDRS}

test-comm-auth.o:	${HDRS}

test-comm-ipfw.o:	${HDRS}

test-watch-client.o:	${HDRS}

test-cgi.o:	${HDRS}





