SHELL    := @SHELL@

# Support out-of-tree builds
srcdir   := @srcdir@
VPATH    := @srcdir@

CXX      := @CXX@
CXXFLAGS := @CPPFLAGS@ @CXXFLAGS@ -I..
LDFLAGS  := @LDFLAGS@
LIBS     := @LIBS@

TARGETS  := ConfigTest EscapeTest
OBJS     := $(addsuffix .o, $(TARGETS))
ZNC_OBJS := Config.o ZNCDebug.o FileUtils.o Utils.o ZNCString.o MD5.o SHA256.o
ZNC_OBJS := $(addprefix ../, $(ZNC_OBJS))

ifneq "$(V)" ""
VERBOSE=1
endif
ifeq "$(VERBOSE)" ""
Q=@
E=@echo
C=-s
else
Q=
E=@\#
C=
endif

.PHONY: test

all: $(TARGETS)

ConfigTest: ConfigTest.o
	$(E) Linking $@...
	$(Q)$(CXX) $(LDFLAGS) -o $@ $< $(ZNC_OBJS) $(LIBS)

EscapeTest: EscapeTest.o
	$(E) Linking $@...
	$(Q)$(CXX) $(LDFLAGS) -o $@ $< $(ZNC_OBJS) $(LIBS)

%.o: %.cpp Makefile
	@mkdir -p .depend
	$(E) Building $@...
	$(Q)$(CXX) $(CXXFLAGS) -c -o $@ $< -MMD -MF .depend/$@.dep

test: $(TARGETS)
	for test in $(TARGETS) ; do \
		./$$test || exit 1 ; \
	done
