#
#  ipband - IP bandwidth watchdog
#  Change this variables to match your installation
#
#  Note: When the version changes, you also have to change
#  the RPM spec file

V=0.8

MAKE=make

CPPFLAGS=-I/usr/include/pcap
LIBS=-lpcap
CFLAGS=-Wall
CC=gcc 

ifndef PREFIX
PREFIX=/usr/local/
endif

ifndef BINDIR
BINDIR=$(PREFIX)/bin
endif

ifndef MANDIR
MANDIR=$(PREFIX)/man
endif

ifndef MAN1DIR
MAN1DIR=$(MANDIR)/man1
endif

ifndef SYSCONFDIR
#SYSCONFDIR=$(PREFIX)/etc
SYSCONFDIR=/etc
endif

ifndef RCDIR
RCDIR=$(SYSCONFDIR)/rc.d/init.d
endif


BIN 	= ipband
SRC_C 	= main.c error.c init.c packets.c \
	  pcapfunc.c popen.c reports.c utils.c hash.c
OBJ_C   = $(SRC_C:.c=.o)


all: 	$(BIN)

$(BIN):	$(OBJ_C)
	$(CC) -o $(BIN) $(OBJ_C) $(LIBS) $(CFLAGS)
	strip $(BIN)

install-strip:	install

install: all
	mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(MAN1DIR)
	mkdir -p $(DESTDIR)$(SYSCONFDIR)
	mkdir -p $(DESTDIR)$(RCDIR)
	install -D ipband   		$(DESTDIR)$(BINDIR)/ipband
	install -D ipband.1 		$(DESTDIR)$(MAN1DIR)/ipband.1
	install -D ipband.sample.conf 	$(DESTDIR)$(SYSCONFDIR)/ipband.sample.conf
	install -D ipband.rc 		$(DESTDIR)$(RCDIR)/ipband


clean:
	rm -f *.o
	rm -f ipband


#
#  -------------------------------------------------------------------------
#
#  If we need rpm

SRC_ROOT = Makefile CHANGELOG COPYING README INSTALL ipband.spec styles.css
SRC_SRCS = Makefile *.c *.h ipband.1
SRC_CONF = ipband.sample.conf ipband.rc

tgz:	
	mkdir ipband-$(V)
	cp $(SRC_ROOT) ipband-$(V)/
	cp $(SRC_SRCS) ipband-$(V)/
	cp $(SRC_CONF) ipband-$(V)/
	tar -czvf ipband-$(V).tgz ipband-$(V)/
	rm -rf ipband-$(V)

rpm:    tgz
	mv ipband-$(V).tgz /usr/src/packages/SOURCES
	cp ipband.spec /usr/src/packages/SPECS
	rpmbuild -bb ipband.spec
