# ===================================================================
# project: Matrix v1.0
# author: Jean-Michel RICHER
# email: jean-michel.richer@univ-angers.fr
# ===================================================================

# set default compiler which can be overriden by setting
# it when calling make, like in 'make compiler=gnu'
# or 'make compiler=intel'
ifeq "$(compiler)" ""
compiler=gnu
endif

# distribution
ifeq "$(distrib)" ""
distrib=release
endif

# =====================================================
# configure compiler and compiler options
# =====================================================

include library.make
include $(compiler).make


SRCS=$(shell ls src/*.cpp)
OBJS=$(subst .cpp,.o, $(subst src/,obj/, $(SRCS)))
EXE=bin/matrix_product_$(distrib).exe

all: info $(EXE)


info:
	@echo "===========================" 
	@echo "build Matrix project"
	@echo "===========================" 
	@echo "sources=$(SRCS)" 
	@echo "objects=$(OBJS)" 
	@echo "compiler=$(CC)" 
	@echo "CPPFLAGS=$(CPPFLAGS)"
	@echo "COFLAGS=$(COFLAGS)"  
	@echo "==========================="

$(EXE): $(OBJS)
	@echo "- generate $@"
	@$(CC) -o $@ $(OBJS) $(COFLAGS) $(LIBS)

obj/%.o: src/%.cpp
	@echo "- compile $<"
	@$(CC) -c -o $@ $< $(CPPFLAGS) $(COFLAGS)

clean:
	@echo "===========================" 
	@echo "cleaning..."
	@echo "===========================" 
	rm -rf bin/*.exe obj/*.o

release:
	make --no-print-directory distrib=$@
	
debug:
	make --no-print-directory distrib=$@

profile:
	make --no-print-directory distrib=$@

tests:
	./test_matrix_product.sh

documentation:
	doxygen

deep_clean: clean
	rm -rf doc/html doc/latex results/*.txt results.png err.txt tmp.txt
 
