# Makefile for Nagios tests using libtap


# Source code directories
SRC_COMMON=../common
SRC_INCLUDE=../include
SRC_XDATA=../xdata
SRC_BASE=../base
SRC_CGI=../cgi
SRC_COMMON=../common

CC=@CC@
CFLAGS=@CFLAGS@ @DEFS@ -DNSCORE -I../include -I../tap/src

TESTS = test_logging test_events test_timeperiods test_nagios_config
TESTS += test_xsddefault
TESTS += test_checks
TESTS += test_strtoul
TESTS += test_commands
TESTS += test_downtime

XSD_OBJS = $(SRC_CGI)/statusdata-cgi.o $(SRC_CGI)/xstatusdata-cgi.o
XSD_OBJS += $(SRC_CGI)/objects-cgi.o $(SRC_CGI)/xobjects-cgi.o
XSD_OBJS += $(SRC_CGI)/comments-cgi.o $(SRC_CGI)/downtime-cgi.o
XSD_OBJS += $(SRC_CGI)/cgiutils.o $(SRC_CGI)/skiplist.o ../common/shared.o

TP_OBJS = $(SRC_BASE)/utils.o $(SRC_BASE)/config.o $(SRC_BASE)/macros-base.o
TP_OBJS += $(SRC_BASE)/objects-base.o $(SRC_BASE)/xobjects-base.o
TP_OBJS += $(SRC_BASE)/skiplist.o ../common/shared.o

CFG_OBJS = $(TP_OBJS)
CFG_OBJS += $(SRC_BASE)/comments-base.o $(SRC_BASE)/xcomments-base.o
CFG_OBJS += $(SRC_BASE)/downtime-base.o $(SRC_BASE)/xdowntime-base.o
CFG_OBJS += $(SRC_BASE)/retention-base.o $(SRC_BASE)/xretention-base.o


LDFLAGS=@LDFLAGS@
LIBS=@LIBS@

prefix=@prefix@
exec_prefix=@exec_prefix@
LOGDIR=@localstatedir@
CFGDIR=@sysconfdir@
BINDIR=@bindir@
CGIDIR=@sbindir@
HTMLDIR=@datarootdir@
INSTALL=@INSTALL@
INSTALL_OPTS=@INSTALL_OPTS@
COMMAND_OPTS=@COMMAND_OPTS@
STRIP=@STRIP@

CGIURL=@cgiurl@
HTMURL=@htmurl@

MATHLIBS=-lm
PERLLIBS=@PERLLIBS@
PERLXSI_O=@PERLXSI_O@
SOCKETLIBS=@SOCKETLIBS@
THREADLIBS=@THREADLIBS@
BROKERLIBS=@BROKERLIBS@

BROKER_LDFLAGS=@BROKER_LDFLAGS@ 

CP=@CP@

# External data I/O code and headers
XSDC=@XSDC@
XSDH=@XSDH@
XCDC=@XCDC@
XCDH=@XCDH@
XRDC=@XRDC@
XRDH=@XRDH@
XODC=@XODC@
XODH=@XODH@
XPDC=@XPDC@
XPDH=@XPDH@
XDDC=@XDDC@
XDDH=@XDDH@

# Extra base code
BASEEXTRALIBS=@BASEEXTRALIBS@

# Generated automatically from configure script
SNPRINTF_O=@SNPRINTF_O@
BROKER_O=@BROKER_O@
BROKER_H=@BROKER_H@

TAPOBJ=../tap/src/tap.o $(SNPRINTF_O)

all: $(TESTS)

########## TESTS ##########

test_logging: test_logging.o $(SRC_BASE)/logging.o $(TAPOBJ)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

test_events: test_events.o $(SRC_BASE)/events.o $(TAPOBJ)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(MATHLIBS) $(LIBS)

test_checks: test_checks.o $(SRC_BASE)/checks.o $(TAPOBJ)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(MATHLIBS) $(LIBS)

test_commands: test_commands.o $(SRC_COMMON)/shared.o $(TAPOBJ)
	$(CC) $(CFLAGS) -o $@ $^

test_downtime: test_downtime.o $(SRC_BASE)/downtime-base.o $(SRC_BASE)/xdowntime-base.o $(TAPOBJ)
	$(CC) $(CFLAGS) -o $@ $^

test_freshness: test_freshness.o $(SRC_BASE)/freshness.o $(TAPOBJ)
	$(CC) $(CFLAGS) -o $@ $^

test_nagios_config: test_nagios_config.o $(CFG_OBJS) $(TAPOBJ)
	$(CC) $(CFLAGS) -o $@ $^ $(BROKER_LDFLAGS) $(LDFLAGS) $(MATHLIBS) $(SOCKETLIBS) $(THREADLIBS) $(BROKERLIBS) $(LIBS)

test_timeperiods: test_timeperiods.o $(TP_OBJS) $(TAPOBJ)
	$(CC) $(CFLAGS) -o $@ $^ $(BROKER_LDFLAGS) $(LDFLAGS) $(MATHLIBS) $(SOCKETLIBS) $(THREADLIBS) $(BROKERLIBS) $(LIBS)

test_xsddefault: test_xsddefault.o $(XSD_OBJS) $(TAPOBJ)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

test_strtoul: test_strtoul.c
	$(CC) $(CFLAGS) -o $@ test_strtoul.c $(TAPOBJ)

test: $(TESTS)
	HARNESS_PERL=./test_each.t perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map { "./$$_" } @ARGV)' $(TESTS)

clean:
	rm -f nagios nagiostats core *.o gmon.out
	rm -f *~ *.*~

distclean: clean
	rm -f perlxsi.c
	rm -f Makefile

devclean: distclean

