# Run Alchemical tests for orac 

# ----------------------------------------------------------------------
#  user serviceable
# ----------------------------------------------------------------------

# Define here the executable created with `make <TARGET>' (see $(O_SRC)/Makefile) 
O_BIN=GNU-FFTW-OMP/orac
# parallel
O_BIN_P=GNU-FFTW-OMP-MPI/orac


# ORAC root
O_ROOT=../..
# sources dir
O_SRC=$(O_ROOT)/src
ORAC=$(O_SRC)/$(O_BIN)
ORAC_P=$(O_SRC)/$(O_BIN_P)
BENNETT_DIR=$(O_ROOT)/tools/bennett

# Number of processors in parallel run:
NP=4

# ----------------------------------------------------------------------

CONFIGURE = ../configure
TEMP_FILES=\
  *~ \
  test.tt* \
  ?.pdb \
  *.out \
  *.tpgprm \
  *.wrk \
  bennett


OUT = 1.out 1r.out 2.out 2r.out 3.out 3r.out


# default: run all tests, gathering basic output this is very much
#  like 'make all' without lots of output files
default: $(ORAC) tools.bennett
	./run_serial_tests.bash $(ORAC)

parallel: $(ORAC_P) bennett
	./run_parallel_tests.bash $(ORAC_P) $(NP)

# make bennett in tools dir
tools.bennett: 
	$(MAKE) -i -C $(BENNETT_DIR) > /dev/null 2>&1 
	ln -f $(BENNETT_DIR)/bennett .

# view differences 

diff: diff-s 

diff-s: 
	diff OUT_TEST OUT

all: $(OUT) free_energy


$(ORAC) $(ORAC_P): config.H
	@ echo "-------------------------------------------------------------------------"
	@ echo "WARNING: the ORAC executable ("$@") is missing or outdated"
	@ echo "Make sure you created it in the src directory, using config.H in this dir"
	@ echo "Hints:"
	@ echo "  (a) check the name and path of ORAC or ORAC_P at the top of ./Makefile"
	@ echo "  (b) compare the copy of 'config.H' in this directory "
	@ echo "      to the one in "$(O_SRC)", and if they differ do:"
	@ echo "         cp ./config.H "$(O_SRC)
	@ echo "         cd "$(O_SRC)"; make <TARGET>"
	@ echo "-------------------------------------------------------------------------"

# will delete any target output if command fails
.DELETE_ON_ERROR:


# if config.H is missing, rebuild it - warning: not foolproof!
#config.H: 1.in
#	$(CONFIGURE) < $< > $@

# Static Pattern Rule: only for files in $(OUT), run %.in to produce %.out
$(OUT) :  %.out : %.in $(ORAC)
	$(ORAC)  <  $<  >  $@
# dependencies 
1r.out:  1.out
2r.out:  2.out
3r.out:  3.out

# service
clean: 
	./run_serial_tests.bash -z 
	./run_parallel_tests.bash -z

realclean: clean
	rm -rf $(TEMP_FILES) 

distclean: realclean
