#
# Makefile for IPTraf
#

CC		= gcc
LIBS		= -lpanel -lncurses      # in this order!

# comment this one out to omit debug code when done.

DEBUG		=# -g

# options to be passed to the compiler.  I don't believe they need to be
# modified.

OPTIONS		= -Wall -O2 -m486
LDOPTS		= #-static

# you may want to change this to point to your ncurses include directory
# if the ncurses include files are not in the default location.

INCLUDEDIR	= -I/usr/include/ncurses

# You can uncomment this one to disable the backspace key in input fields.
# This means you must use the Del key or Ctrl+H combination to erase the
# character left of the cursor.  You may need to use this directive if you
# have an earlier version of ncurses.  (Please note that earlier ncurses
# versions have quirks that may result in undesirable screen behavior as
# well.)

BSSETTING	=# -DDISABLEBS

# Define this one to allow non-root users to use the program when setuid
# root.  Undefine to restrict use to root only.  It is recommended that
# you restrict execution to root only.  This option does not install the
# executable program with the setuid bit on, or with world-execute
# permissions.  If you want it, you'll have to do it yourself with chmod.

EXECPERM	=# -DALLOWUSERS

# installation target directory

TARGET		= /usr/local/bin

# The IPTraf working directory; if you change this, be sure also to
# appropriately modify the definitions in dirs.h.

WORKDIR		= /var/local/iptraf

############### Explicit Compilation Rules ###############

all: iptraf rvnamed

iptraf: iptraf.o itrafmon.o packet.o tcptable.o othptab.o ifstats.o deskman.o ipcsum.o stdwinset.o \
input.o menurt.o hostmon.o utfilter.o othfilter.o serv.o timer.o revname.o \
options.o promisc.o error.o log.o
	$(CC) $(OPTIONS) $(DEBUG) $(LDOPTS) -o iptraf iptraf.o itrafmon.o packet.o tcptable.o \
	othptab.o ifstats.o deskman.o ipcsum.o menurt.o input.o stdwinset.o hostmon.o \
	utfilter.o othfilter.o serv.o timer.o revname.o promisc.o options.o \
	error.o log.o $(LIBS)

iptraf.o: iptraf.c *.h
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) $(EXECPERM) -o iptraf.o iptraf.c

itrafmon.o: itrafmon.c *.h
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) -o itrafmon.o itrafmon.c

packet.o: packet.c *.h
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) -o packet.o packet.c

tcptable.o: tcptable.c *.h
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) -o tcptable.o tcptable.c

othptab.o: othptab.c *.h
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) -o othptab.o othptab.c

ifstats.o: ifstats.c *.h
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) -o ifstats.o ifstats.c

deskman.o: deskman.c *.h
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) -o deskman.o deskman.c

menurt.o: menurt.c *.h
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) -o menurt.o menurt.c

input.o: input.c *.h
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) $(BSSETING) -o input.o input.c

ipcsum.o: ipcsum.c *.h
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) -o ipcsum.o ipcsum.c

stdwinset.o: stdwinset.c *.h
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) -o stdwinset.o stdwinset.c

serv.o: serv.c *.h
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) -o serv.o serv.c

timer.o: timer.c timer.h
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) -o timer.o timer.c

revname.o: revname.c
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) -o revname.o revname.c

hostmon.o: hostmon.c *.h
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) -o hostmon.o hostmon.c

utfilter.o: utfilter.c *.h
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) -o utfilter.o utfilter.c

othfilter.o: othfilter.c *.h
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) -o othfilter.o othfilter.c

options.o: options.c *.h
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) -o options.o options.c

promisc.o: promisc.c
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) -o promisc.o promisc.c

error.o: error.c *.h
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) -o error.o error.c

log.o: log.c log.h
	$(CC) $(OPTIONS) $(INCLUDEDIR) -c $(DEBUG) -o log.o log.c

rvnamed: rvnamed.c rvnamed.h
	$(CC) $(OPTIONS) $(DEBUG) $(LDOPTS) -o rvnamed rvnamed.c

# rule to clear out all object files and the executables (pow!)

clean:
	rm -f *.o iptraf rvnamed *~

# I just included this rule to clear out the .o files, leaving the
# executables.

cleano:
	rm -f *.o *~
	strip iptraf
	strip rvnamed

# installation rule

install:
	install -m 0700 -o root -g root -s iptraf $(TARGET)
	install -m 0700 -o root -g root -d $(WORKDIR)
	install -m 0700 -o root -g root -s rvnamed $(WORKDIR)
