################ Change following ########################
##  some other parameters exist in opengatemd.h  ########
##########################################################
CONFIGPATH = /etc/opengate        ## directory of config file
INSTALLBINPATH = /usr/local/bin   ## install dir of executable file
MAKEDIR != pwd			## save present directory

.if exists(/usr/local/include/mysql)
CFLAGSMYSQL = -I/usr/local/include/mysql -pipe -fno-strict-aliasing
LIBMYSQL = -L/usr/local/lib/mysql -lmysqlclient  -pthread -lz -lm
.endif

.if exists(/usr/local/include/sqlite3.h)
LIBSQLITE = -lsqlite3 -lpthread
.endif

## This is memory leak check tool for debugging
#LIBCCMALLOC = -lccmalloc -L/usr/local/lib

CFLAGS= -g -O3 -Wall -I/usr/local/include ${CFLAGSMYSQL}

LIBS = -lezxml -lpcap -L../ezxml -L/usr/local/lib  ${LIBSQLITE} ${LIBMYSQL} ${LIBCCMALLOC}

OBJS = util.o error.o getparam.o managementdb.o workdb.c ipfw.o pcap.o packetcache.o macdbcache.o session.o ttlcheck.o udpserv.o watchlistcache.o signal.o
HDRS = opengatemd.h

MDMAINPROGO = opengatemd.o
MDMAINPROG = opengatemd

LIBOPT = ezxml

CLEANFILES = *.o *~ *.core a.out \\#*

all:	${MDMAINPROG} ${LIBOPT}

opengatemd:	${OBJS} ${MDMAINPROGO} ${LIBOPT}
		${CC} ${CFLAGS} -o $@ ${OBJS} ${MDMAINPROGO} ${LIBS}

ezxml:	
		${MAKE} -C ../ezxml
clean:
		rm -f ${MDMAINPROG} ${CLEANFILES}
		${MAKE} clean -C ../ezxml
		rm -f ../*/*~  ../*~ ../*/*/*~

install:	install-md-prg install-conf rm-lockfile

rm-lockfile:	#
		rm -f /tmp/opengatemd.lock
		rm -f /tmp/opengate.lock

install-md-prg:	${MDMAINPROG}
		## Install program and Set S bit ##
.if !exists(${INSTALLBINPATH})
		mkdir ${INSTALLBINPATH}
.endif
		cp ${MDMAINPROG} ${INSTALLBINPATH}/${MDMAINPROG}
		chmod 4755 ${INSTALLBINPATH}/${MDMAINPROG}
		cp ../rc.d/${MDMAINPROG} /etc/rc.d/${MDMAINPROG}
		chmod 555 /etc/rc.d/${MDMAINPROG}
		#

install-conf:
		## Copy Config files ##
.if !exists(${CONFIGPATH})
		mkdir ${CONFIGPATH}
.endif
		cp  ../conf/opengatemd.conf.sample ${CONFIGPATH}
		cp  ../conf/rc.firewall.sample ${CONFIGPATH}
		cp  ../conf/ipfwctrlmd.pl.sample ${CONFIGPATH}
		#
		#------------------------------------------------------#
		# COPY above x.sample to x and EDIT it.                #
		#   Eg. 'cp opengatemd.conf.sample  opengatemd.conf'   #
		#------------------------------------------------------#

opengatemd.o:	${HDRS}
		${CC} ${CFLAGS} -DMAKEDIR='"${MAKEDIR}"' -c $<

util.o:		${HDRS}

mamagementdb.o:	${HDRS}
.if !exists(/usr/local/include/mysql)
		${CC} ${CFLAGS} -DMYSQL_NOT_INSTALLED -c $<
.endif

workdb.o:	${HDRS}
.if !exists(/usr/local/include/sqlite3.h)
		${CC} ${CFLAGS} -DSQLITE3_NOT_INSTALLED -c $<
.endif

error.o:	${HDRS}

getparam.o:	${HDRS}

ipfw.o:		${HDRS}

pcap.o:		${HDRS}

packetcache.o:	${HDRS}

macdbcache.o:	${HDRS}

session.o:	${HDRS}

ttlcheck.o:	${HDRS}

getmac.o:	${HDRS}

queue.o:	${HDRS}

udpserv.o:	${HDRS}

watchlistcache.o:	${HDRS}

