# A Makefile for newimage unit tests.
include ${FSLCONFDIR}/default.mk

PROJNAME   = test-melodic
TESTXFILES = test-melodic

# Most of these libs are not currently used, but are available
# for future melodic tests.
LIBS = -lfsl-newimage -lfsl-miscmaths -lfsl-NewNifti \
       -lfsl-cprob -lfsl-utils -lfsl-znz -lboost_unit_test_framework

# The test program uses the Boost unit
# testing framework, which needs librt
# on linux.
SYSTYPE := $(shell uname -s)
ifeq ($(SYSTYPE), Linux)
LIBS  += -lrt
RPATH := -Wl,-rpath,'$$ORIGIN/..'
endif
ifeq ($(SYSTYPE), Darwin)
RPATH := -Wl,-rpath,'@executable_path/..'
endif

all: ${TESTXFILES}

OBJS := $(wildcard test_*.cc)
OBJS := $(OBJS:%.cc=%.o)

# The pyfeeds-based CI build _only_ copies the test directory
# and so ".." won't contain webstats.h. There are a number of ways
# to deal with this - one fix is use the command-line override
# variable MELODIC_SRC_PATH in the pyfeeds run to point at the
# test environment, for local testing the path will be "..".
MELODIC_SRC_PATH = ..
USRCXXFLAGS := -I${MELODIC_SRC_PATH}
# Note the below %.cc rule is _not_ being applied to cc files ( no -I.. )
# hence USRCXXFLAGS is being set. This is due to the pattern rule in
# FSLDIR/config/rules.mk overriding ( plus pyfeeds problem )
# A specific target needed to override e.g.
#test_webstats.o: test_webstats.cc
#	$(CXX)  -I.. ${CXXFLAGS} -c -o $@ $<
# Or the .deps dependencies to replace the pattern rule:
#%.o: %.cc | .deps/%.cc.c.d .deps
#	$(CXX)  -I.. ${CXXFLAGS} -c -o $@ $<

%.o: %.cc
	$(CXX)  -I.. ${CXXFLAGS} -c -o $@ $<

test-melodic: ${OBJS}
	$(CXX) -o $@ $^ -L.. ${RPATH} ${LDFLAGS}
