#
# Makefile for IPTraf
#

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

# 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
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

# The IPTraf log file directory.  IPTraf log files are placed here.  Be
# sure to modify the appropriate paths in dirs.h if you change this.

LOGDIR		= /var/log/iptraf

# 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 othfilter.o \
fltmgr.o ipfrag.o serv.o servname.o instances.c timer.o revname.o landesc.o \
options.o promisc.o ifaces.o error.o log.o

BINS = iptraf rvnamed cfconv

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

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

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

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

cfconv: cfconv.o
	$(CC) $(LDOPTS) -o cfconv cfconv.o

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

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

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

# 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 "*** Log files are now placed in $(LOGDIR)"
	@echo
	@echo "*** If you defined additional ports for the TCP/UDP service"
	@echo "monitor, do a 'make upgrade' to update the data file for use"
	@echo "with this version.  If you're upgrading from 1.1.0, also run"
	@echo "the 'cfconv' utility from the 1.2.0 distribution to update"
	@echo "the configuration and filter data files."
	@echo

# 1.2.0 to 1.3.0 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

