SHELL := /bin/bash

KERNELS_PATH=./kernels
MICROBENCH_PATH=./microbenchmarks
NPB_PATH=./npb
COMPILER?=uhcaf

help default:
	@printf '\n%10s\n' "If test suite is run from within performance directory, then USAGE: $(MAKE) [OPTIONS [COMPILER=uhcaf(default)|ifort|g95|crayftn] ]"
	@printf '%10s\n' "OPTIONS include:"
	@printf '%-25s\n' "| ( Note: <suite>: [kernels | microbenchmarks | npb | all] )"
	@printf '%-25s%-90s\n' "| "
	@printf '%-25s%-90s\n' "|_ compile_<suite>:" "compiles and generates logs for the codes"
	@printf '%-25s%-90s\n' "|_ execute_<suite>:" "executes and generates logs for the codes"
	@printf '%-25s%-90s\n' "|_ complete_<suite>:" "executes and generates logs for the codes"
	@printf '%-25s%-90s\n\n' "|_ clean<suite>:" "cleans up the logs, executables and all previous history of the regression runs"
	@echo -e "Before running any <suite>, please ensure that:\n The 'user-defined' parameters are set in support/CONFIG \n The compiler specific parameters in support/CONFIG-compiler.<compiler> \n"
	@ echo -e "There is no need to set the make.def* within  support/CONFIG. They are auto-generated by the Makefiles."
	@ echo -e "Before running any kernel tests, please ensure that the number of images(NPROCS) for every kernel is set in the *.def file within its directory. E.g. mm.def within kernels/src/mm sets the number of images to run the Matrix multiplication code"


compile_performance: compile_performance execute_performance

compile_performance compile_all: compile_kernels  compile_microbenchmarks compile_npb

compile_kernels:
	@cd $(KERNELS_PATH) ; make -s COMPILER=$(COMPILER);

compile_microbenchmarks:
	@cd $(MICROBENCH_PATH) ; make -s compile  COMPILER=$(COMPILER);

compile_npb:
	@cd $(NPB_PATH); ./test_npb.sh compile $(COMPILER);

execute_performance execute_all: execute_kernels  execute_microbenchmarks execute_npb

execute_kernels:
	@cd $(KERNELS_PATH) ; make -s runtests COMPILER=$(COMPILER);

execute_microbenchmarks:
	@cd $(MICROBENCH_PATH) ; make -s execute  COMPILER=$(COMPILER);

execute_npb:
	@cd $(NPB_PATH) ; ./test_npb.sh execute $(COMPILER);

complete_performance complete_all: complete_kernels  complete_microbenchmarks complete_npb

complete_kernels:
	@cd $(KERNELS_PATH) ; make -s runtests COMPILER=$(COMPILER);

complete_microbenchmarks:
	@cd $(MICROBENCH_PATH) ; make -s complete  COMPILER=$(COMPILER);

complete_npb:
	@cd $(NPB_PATH) ; ./test_npb.sh complete $(COMPILER);


# CLEAN-UP

.PHONY: clean clean_kernels clean_microbenchmarks clean_npb


cleanperformance cleanall: cleankernels cleanmicrobenchmarks cleannpb
	@rm -rf  support/make.def*

cleankernels:
	@cd $(KERNELS_PATH) ;   $(MAKE) -s clean

cleanmicrobenchmarks:
	@cd $(MICROBENCH_PATH) ;  $(MAKE) -s cleanall

cleannpb:
	@cd $(NPB_PATH) ;  $(MAKE) -s cleanall
