#
# Makefile for ipfm
#

CC   = gcc
#YACC = bison
YACC = bison -vy
LEX  = flex

INSTALL = /usr/bin/install -D
MKDIR   = mkdir -p

# defines
DEFINES += -DDEFAULT_OPTIONS_CONFIGFILE='"/etc/ipfm.conf"'
DEFINES += -DDEFAULT_OPTIONS_LOGFILE='"/var/log/ipfm/%d-%b.%H-%M"'
DEFINES += -DDEFAULT_OPTIONS_TIMEINTERVAL='24*60*60'
DEFINES += -DDEFAULT_OPTIONS_REVERSELOOKUP=1
DEFINES += -DDEFAULT_OPTIONS_SORT=0

LIBS = -lpcap

# gdb debboger
CFLAGS = -g -Wall

# Yacc debug 
#DEFINES += -DYYDEBUG=1 
#DEFINES += -DYYERROR_VERBOSE

# Debug
#DEFINES += -DDEBUG=3

SRCS=	ipfm.c   \
	pcap.c   \
	filter.c \
	y.tab.c  \
	lex.yy.c \
	data.c   \
	utils.c  \
	init.c

OBJS=$(SRCS:.c=.o)

DOCS =	ipfm.conf.man.5 \
	ipfm.man.8

SBINDIR = /usr/local/sbin
MANDIR = /usr/local/man

all: ipfm

ipfm: $(OBJS)
	$(CC) -o $@ $(OBJS) $(LIBS)

%.o: %.c %.h
	$(CC) $(CFLAGS) $(DEFINES) -c $<

%.o: %.c
	$(CC) $(CFLAGS) $(DEFINES) -c $<

y.tab.c: config.y
	$(YACC) -d config.y

lex.yy.c: config.l
	$(LEX) config.l

clean:
	rm -f $(OBJS) ipfm *~ core y.tab.c y.tab.h y.output lex.yy.c

install: $(DOCS) ipfm
	$(INSTALL) ipfm $(SBINDIR)/ipfm
	$(INSTALL) ipfm.conf.man.5 $(MANDIR)/man5/ipfm.conf.5
	$(INSTALL) ipfm.man.8 $(MANDIR)/man8/ipfm.8
	$(INSTALL) ipfm.conf.sample /etc/ipfm.conf
	$(MKDIR) /var/log/ipfm
