CXXSRC=classify.cpp SPLE_lib.cpp DataProvider.cpp
HEADER=$(CXXSRC:%.cpp=%.h)
OBJ=$(CXXSRC:%.cpp=%.o) io_png.o

CFLAGS=-fPIC -O2
CXXFLAGS=$(CFLAGS) -fopenmp -DNDEBUG -I./eigen

classify.so: $(OBJ)
	$(CXX) -shared -Wl,-soname,$@ $^ -o $@ -lpng -lgomp

%.o: %.cpp
	$(CXX) -c $(CXXFLAGS) $< -o $@

%.o: %.c
	$(CC) -c $(CFLAGS) $< -o $@

clean:
	@$(RM) *.o *.png core noise_data

dist_clean: clean
	$(RM) *.so

identest:
	@echo "test the shared library when its pSize is set to 8"
	cp ../sple/test/DataProvider.cpp8 DataProvider.cpp
	cp ../sple/test/DataProvider.h8 DataProvider.h
	$(MAKE)
	@./test/test.py && echo "TEST PASSED" || $(MAKE) fail
	@$(MAKE) clean

fail:
	$(error python port test failed)

beautify:
	sed -i "s:[\t ]*$$::g" ./test/test.py *.cpp *.h makefile

EIGEN_URL=http://bitbucket.org/eigen/eigen/get/3.2.1.tar.gz
EIGEN_TGZ=3.2.1.tar.gz
EIGEN_DIR=eigen

$(EIGEN_TGZ):
	wget $(EIGEN_URL)

$(EIGEN_DIR): $(EIGEN_TGZ)
	mkdir $@
	# strip-components makes $@ the main folder
	tar xfz $< -C $@ --strip-components=1
	$(RM) $<
