#
# Build everything in directories...
#
# tailor this to taste, but must be ansi capable
# With 'gcc', optimization can not be used on tcplogger and udplogger
#
# If you have not run fix-includes, you must use -traditional with
# 'gcc'.  If you are not sure, then use it.
CC="gcc -traditional -g"
#
# SunOS 4 or Solaris (SunOS 5)?
#
#FLAGS=-DSUNOS4
FLAGS=-DSOLARIS
#
# For SunOS 5, use RANLIB=echo
#
#RANLIB=ranlib
RANLIB=echo
#
# For SunOS 5, use LIBS=-lsocket -lnsl
#
#LIBS=
LIBS=-lsocket -lnsl
#
#------------------------------------------------------------------------
#
ARGS=CC=$(CC) FLAGS=$(FLAGS) RANLIB=$(RANLIB) LIBS="$(LIBS)"

all: lib extract tcplogger udplogger icmplogger netwatch nstat

lib: lib/libsupport.a

lib/libsupport.a: lib/*.c
	(cd lib; $(MAKE) $(ARGS))

extract: bin/extract

bin/extract: extract/*.c extract/grammar.y include/version.h
	(cd extract; $(MAKE) $(ARGS))
	@mv extract/extract bin

tcplogger: bin/tcplogger

bin/tcplogger: tcplogger/*.c lib include/version.h
	(cd tcplogger; $(MAKE) $(ARGS))
	@mv tcplogger/tcplogger bin

udplogger: bin/udplogger

bin/udplogger: udplogger/*.c lib include/version.h
	(cd udplogger; $(MAKE) $(ARGS))
	@mv udplogger/udplogger bin

icmplogger: bin/icmplogger

bin/icmplogger: icmplogger/*.c lib include/version.h
	(cd icmplogger; $(MAKE) $(ARGS))
	@mv icmplogger/icmplogger bin

netwatch: bin/netwatch

bin/netwatch: netwatch/*.c netwatch/monitors/*.c lib include/version.h
	(cd netwatch; $(MAKE) $(ARGS))
	@mv netwatch/netwatch bin

nstat: bin/nstat

bin/nstat: nstat/*.c
	(cd nstat; $(MAKE) $(ARGS))
	@mv nstat/nstat bin
	@cp nstat/nload.awk bin
	@cp nstat/nsum.perl bin

clean:
	(cd lib; $(MAKE) clean)
	(cd extract; $(MAKE) clean)
	(cd tcplogger; $(MAKE) clean)
	(cd udplogger; $(MAKE) clean)
	(cd icmplogger; $(MAKE) clean)
	(cd netwatch; $(MAKE) clean)
	(cd nstat; $(MAKE) clean)
	$(RM) -f bin/extract bin/tcplogger bin/udplogger bin/nstat \
		bin/nload.awk bin/nsum.perl bin/netwatch bin/icmplogger
