#
# Makefile for IPTraf 2
#

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

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

DEBUG		= #-g -DDEBUG

# comment this one out to prevent generation of profile code

PROF		= #-pg

# options to be passed to the compiler.  I don't believe they need to be
# modified (except for -m486 on non-Intel x86 platforms).

CFLAGS		= -Wall -O2 #-m486
DIRS		= -DWORKDIR=\"$(WORKDIR)\" \
		  -DLOGDIR=\"$(LOGDIR)\" -DEXECDIR=\"$(TARGET)\"
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.
#
# I have no plans to modify this program to be used by other users.

EXECPERM	=# -DALLOWUSERS

###################################################################
############### IPTRAF DIRECTORY DEFINITIONS.  YOU MAY CHANGE THESE
############### TO SUIT YOUR PREFERENCES.
###################################################################

# installation target directory.  The iptraf and rvnamed programs get
# stored here.  iptraf also exec's rvnamed from this directory.

TARGET		= /usr/local/bin

# The IPTraf working directory; if you change this.  Starting with this
# version, this definition overrides dirs.h.

WORKDIR		= /var/local/iptraf

# The IPTraf log file directory.  IPTraf log files are placed here.
# Starting with this version, this definition overrides dirs.h

LOGDIR		= /var/log/iptraf

#####################################################################
############### IPTRAF COMPILATION AND LINK RULES
#####################################################################

# Object file names

OBJS = 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 fltedit.o \
othfilter.o fltmgr.o ipfrag.o serv.o servname.o instances.c timer.o revname.o \
pktsize.o landesc.o isdntab.o options.o promisc.o ifaces.o error.o log.o \
mode.o getpath.o

BINS = iptraf rvnamed cfconv

all: $(BINS)
	@echo
	@size $(BINS)

iptraf: $(OBJS)
	$(CC) $(LDOPTS) $(PROF) -o iptraf $(OBJS) $(LIBS)

%.o: %.c *.h
	$(CC) $(CFLAGS) $(DIRS) $(INCLUDEDIR) $(PROF) $(DEBUG) $(EXECPERM) $(BSSETTING) 	-c -o $*.o $<

rvnamed: rvnamed.o getpath.o
	$(CC) $(LDOPTS) $(PROF) -o rvnamed rvnamed.o getpath.o

rvnamed.o: rvnamed.c rvnamed.h
	$(CC) $(CFLAGS) $(PROF) $(DEBUG) -c -o rvnamed.o rvnamed.c

cfconv: cfconv.c dirs.h
	$(CC) $(CFLAGS) $(DEBUG) -o cfconv cfconv.c

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

clean:
	rm -f *.o *~ $(BINS)

# I just included this rule to clear out the .o files, leaving the
# executables, stripped and ready for packing.

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

# installation rule

install:
	@echo
	@echo "Installing executable programs and preparing work directories"
	@echo
	$(INSTALL) -m 0700 -o root -g root -s iptraf $(TARGET)
	$(INSTALL) -m 0700 -o root -g root -s rvnamed $(TARGET)
	$(INSTALL) -m 0700 -o root -g root -d $(WORKDIR)
	$(INSTALL) -m 0700 -o root -g root -d $(LOGDIR)
	@echo
	@echo "*** iptraf and rvnamed executables are in $(TARGET)"
	@echo "*** Log files are placed in $(LOGDIR)"
	@echo
	@echo "************************************************************"
	@echo "Users of IPTraf 1.4.x and 2.0.x: If you're using filters,"
	@echo "do a 'make upgrade' now to correct a file placement bug"
	@echo "in these versions."
	@echo "************************************************************"
	@echo

# Upgrade rule
#
upgrade: cfconv
	@./cfconv
#
# I use this special rule to force linking of the panels and ncurses
# libraries into the executable, since there seems to be a lot of
# libncurses.so.3 installations around, and some don't have libncurses.so
# at all.  Till then, I'll force them in.  Do not use this rule under
# normal circumstances.

dist-bin: $(OBJS)
	$(CC) $(LDOPTS) $(PROF) -o iptraf $(OBJS) /usr/lib/libpanel.a /usr/lib/libncurses.a

static: $(OBJS)
	$(CC) -static $(PROC) -o iptraf $(OBJS) -lpanel -lncurses
	$(CC) -static -o rvnamed rvnamed.o getpath.o

