MKOCTFILE ?= mkoctfile
GREP ?= grep

CC_SOURCES  := $(wildcard *.cc)
CC_TST_SOURCES := $(shell $(GREP) --files-with-matches '^%!' $(CC_SOURCES))
TST_SOURCES := $(patsubst %.cc,../inst/test/%.cc-tst,$(CC_TST_SOURCES))

all: fastlscomplex.oct $(TST_SOURCES)

fastlscomplex.oct: fastlscomplex.cc
	$(MKOCTFILE) fastlscomplex.cc

# fastlsreal compilation is disabled for the time being
#fastlsreal.oct: fastlsreal.cc
#	$(MKOCTFILE) fastlsreal.cc

../inst/test:
	@mkdir -p "$@"

$(TST_SOURCES): ../inst/test/%.cc-tst: %.cc | ../inst/test
	@echo "Extracting tests from $< ..."
	@$(RM) -f "$@" "$@-t"
	@(	echo "## Generated from $<"; \
		$(GREP) '^%!' "$<") > "$@"

# helper function just in case
clean:
	rm -f *.o *.oct *~ octave-core $(TST_SOURCES)
