
ifeq ($(shell [ ! -r Makefile.opts ] && echo 1),)
    include Makefile.opts
endif

NSTATS_SRC := nstats pcap packet conn util
NSTATS_OBJ := $(NSTATS_SRC:%=src/%.o)

NMON_SRC := nmon pcap packet util curs_util stats

ifeq ($(IPT_ENABLED),1)
    NMON_SRC := ipt
endif

NMON_OBJ := $(NMON_SRC:%=src/%.o)

BMON_SRC := bmon intf curs_util util
BMON_OBJ := $(BMON_SRC:%=src/%.o)

CMON_SRC := cmon aconn curs_util util pcap packet
CMON_OBJ := $(CMON_SRC:%=src/%.o)

export

all: Makefile.opts nstats nmon bmon cmon

Makefile.opts:
	@echo "**** No configuration found, please run ./configure"
	@exit 1

nstats: Makefile.opts Makefile $(NSTATS_OBJ)
	$(CC) $(CFLAGS) -o $@ $(NSTATS_OBJ) $(LDFLAGS) $(NSTATS_LIB)

nmon: Makefile.opts Makefile $(NMON_OBJ)
	$(CC) $(CFLAGS) -o $@ $(NMON_OBJ) $(LDFLAGS) $(NMON_LIB)

bmon: Makefile.opts Makefile $(BMON_OBJ)
	$(CC) $(CFLAGS) -o $@ $(BMON_OBJ) $(LDFLAGS) $(BMON_LIB)

cmon: Makefile.opts Makefile $(CMON_OBJ)
	$(CC) $(CFLAGS) -o $@ $(CMON_OBJ) $(LDFLAGS) $(CMON_LIB)

clean:
	rm -f nstats nmon cmon bmon src/*.o

distclean: clean
	rm -f Makefile.opts
	rm -f config.h
	rm -Rf .dep
	rm -f config*status config*cache config*log

install: nstats nmon
	mkdir -p $(DESTDIR)$(prefix)/bin/
	mkdir -p $(DESTDIR)$(mandir)/man8/
	install nstats $(DESTDIR)$(prefix)/bin/
	install bmon $(DESTDIR)$(prefix)/bin/
	install cmon $(DESTDIR)$(prefix)/bin/
	install nmon $(DESTDIR)$(prefix)/bin/
	install man/nstats.8 $(DESTDIR)$(mandir)/man8/
