# Run basic test for orac 

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

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

# ORAC root
O_ROOT=../..
# sources dir
O_SRC=$(O_ROOT)/src
ORAC=$(O_SRC)/$(O_BIN)

CONFIGURE = ../configure

OUT =\
 0.out \
 1.out \
 2.out \
 3.out \
 4.out \
 5.out \
6a.out \
6b.out \
6c.out \
7a.out \
7b.out \
7c.out

# 6x tests cannot be checked as of now
CHECKABLE=$(filter-out 6%,$(OUT))

TMP_FILES=\
  *.out \
  *.pdb \
  *.prmtpg \
  *.rst \
  tmp* \
  *.vor \
  tt.* \
  *.frq \
  solution* \
  *_file \
  6.* \
  *.dump \
  *.check \
  *.param

# default: build orac if needed, then run all tests gathering basic output
all test : $(OUT)

$(ORAC) : 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 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:

diff: $(CHECKABLE)
	@ for i in $(CHECKABLE); do printf "%s -> " $$i ; grep "Total    = " $$i > $$i.check ; diff $$i.check ref/$$i.check && echo "test OK" ; done	


# Static Pattern Rule: only for files in $(OUT), run %.in to produce %.out
$(OUT) :  %.out : %.in $(ORAC)
	@ -grep $@ README
	$(ORAC)  <  $<  >  $@

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

# additional prereq's
1.out:  0.in 0.out     	
2.out:  1.out      	
3.out:  2.out     	
#4.out:  3.out      	
5.out:  3.out       	
6a.out: 5.out 	
6b.out: 5.out 	
6c.out: 5.out 	
7a.out: agbnp.a.param
7b.out: agbnp.b.param
7c.out: agbnp.c.param

agbnp.a.param:
	@ cp ../../lib/AGBNP.OPLS.param $@
	@ cp $@ agbnp.param
agbnp.b.param: 
	@ sed "s/80\.0/5\.0/g" ../../lib/AGBNP.OPLS.param > $@
	@ cp $@ agbnp.param
agbnp.c.param: 
	@ sed "s/80\.0/5\.0/g" ../../lib/AGBNP.OPLS.param > $@
	@ cp $@ agbnp.param

# service
clean: 
	rm OUT_TEST ?*[~#] $(TMP_FILES)

clean_conf:
	rm *.h
clean_lnk:
	rm orac

realclean: clean

distclean: clean

temp: 
	echo $(filter-out 6%,$(OUT))
