#######################################################################
# Author: David Goz (david.goz@inaf.it)                               #
# June  2024                                                          #
#######################################################################
#
# To see all the compilation options
# $ make info
#######################################################################

# make.def defines how the application is compiled
include make.def
#######################################################################

.PHONY: info serial omp valgrind_memcheck valgrind_callgrind valgrind_cachegrind debug clean 

info:
	@echo ' '
	@echo '--------------------------------------------------------------------------------------------'
	@echo '$$ make serial                 ---> compile the serial application                          '
	@echo '$$ make omp                    ---> compile the omp application                             '
	@echo '$$ make debug                  ---> debug the omp application                               '
	@echo '$$ make valgrind_memcheck      ---> run the omp application using Valgrind under Memcheck   '
	@echo '$$ make valgrind_callgrind     ---> run the omp application using Valgrind under Callgrind  '
	@echo '$$ make valgrind_cachegrind    ---> run the omp application using Valgrind under Cachegrind '
	@echo '$$ make clean                  ---> clean up all                                            '
	@echo '$$ make info                   ---> get make info                                           '
	@echo '--------------------------------------------------------------------------------------------'
	@echo ' '

serial: $(PROG)

omp: $(PROG_OMP)

debug: $(PROG_DEBUG)
	@echo 'OOOooo... debugging ...oooOOO'
	gdb --args ./$<
	@echo 'OOOooo... debugging ... oooOOO'

valgrind_memcheck: $(PROG_MEMCHECK)
	@echo 'oooOOO... valgrind_memcheck ...OOOooo'
	valgrind --tool=memcheck -s --leak-check=full --show-leak-kinds=all --track-origins=yes --read-var-info=yes --log-file=valgrind_memcheck_log_%p.txt ./$< 10 10 2
	@echo 'oooOOO... valgrind_memcheck ...OOOooo'

valgrind_callgrind: $(PROG_CALLGRIND)
	@echo 'oooOOO... valgrind_callgrind ...OOOooo'
	valgrind --tool=callgrind --dump-instr=yes --collect-jumps=yes --log-file=valgrind_callgrind_log_.%p.txt ./$< 128 128 2
	@echo ' '
	@echo 'To generate a function-by-function summary from the profile data file:'
	@echo '$$ callgrind_annotate --auto=yes callgrind.out.<pid> | less'
	@echo '(kcachegrind is required in order to visualize the output using the GUI)'

valgrind_cachegrind: $(PROG_CACHEGRIND)
	@echo 'oooOOO... valgrind_cachegrind ...OOOooo'
	valgrind --tool=cachegrind --log-file=valgrind_cachegrind_log_.%p.txt ./$< 128 128 2
	@echo '$$ cg_annotate --auto=yes cachegrind.out.<pid> | less'
	@echo '(kcachegrind is required in order to visualize the output using the GUI)'
	@echo 'oooOOO... valgrind_cachegrind ...OOOooo'

clean:
	rm -f *~ .*~ ./src/*~ ./src/*# ./include/*~ ./include/*# *~
	rm -f $(PROG) $(PROG_OMP) $(PROG_DEBUG) $(PROG_MEMCHECK) $(PROG_CALLGRIND) $(PROG_CACHEGRIND)
	rm -f valgrind_*.txt
	rm -f cachegrind.out.*
	rm -f callgrind.*
	rm -f *bin
	rm -f jacobi_*
