# cgt: Makefile. To be used with make.
#
.SUFFIXES :			# Roll our own below.
.SUFFIXES : .out .inp .dif .Counts 

# Put longer tests first for better load balancing with pmake, except put
# simple, general tests first to get a quick check done first.

TESTS = test.out congen.out am94test5.out cgtest9.out gepol2.out gepol3.out \
	pbetest10.out pbetest11.out pbetest12.out \
	sphere.out pbetest.out gaussian.out pbetest2.out \
        cgpbe.out cgpbe2.out cgpbe3.out cgtest26.out \
	pbetest6.out pbetest7.out pbetest8.out testcons2.out transform.out cgtest22.out \
	cgtest23.out amtest1.out amtest2.out amtest3.out amtest4.out amtest5.out \
	amtest6.out amtest7.out \
	am94test1.out am94test2.out am94test3.out am94test4.out \
	am94test6.out am94test7.out am94test8.out \
	am94cycle.out am94spl.out am94gener.out \
	brbtest.out cgcycle.out cgfix.out cgfix2.out cghbuild.out cgmerge.out \
	cgrand.out cgrestart.out cgrestart2.out cgrestart3.out cgrestart4.out \
	cgtest1.out cgtest2.out \
	cgtest3.out cgtest4.out cgtest5.out cgtest6.out cgtest7.out \
	cgtest8.out cgtest10.out cgtest11.out \
	cgtest12.out cgtest13.out cgtest14.out cgtest15.out \
	cgtest16.out cgtest17.out cgtest18.out cgtest19.out \
	cgtest20.out cgtest21.out cgtest24.out cgtest25.out cgpara1.out\
	congen2.out cormantst.out \
	cortst1.out deltest.out djstest.out \
	drawtest.out dyntest1.out genertest.out gepol.out h2otst.out \
	hbcomp.out hbmbcomp.out ictest.out imh2otest.out \
	imptest0.out imptest1.out imptest2.out \
	imst2test.out imtest.out jtest1.out jtest2.out jtest3.out jtest4.out jtest5.out \
	nanatst1.out nanatst2.out \
	nanatst3.out noetest.out noetest2.out noetest3.out noetest4.out noetest5.out\
	pbetest3.out pbetest4.out pbetest5.out pbetest9.out \
	pdbtest1.out pdbtest2.out \
	readtest.out readtest2.out readtest3.out readtest4.out readtest5.out \
	searchnoe.out st2test.out surftst.out \
	testcons.out testhb.out testhom.out testparm.out \
	testrtf.out testrtf2.out testrtf3.out \
	testsel.out testspl.out \
	twist.out vibrtst.out 

DIFFS = $(TESTS:.out=.dif)

SOURCES = $(TESTS:.out=.inp) breaktest.tpu descrip.mms makefile brbtest.crd \
          h2otst.crd imh2otest.crd imh2otest.img imst2test.crd imst2test.img \
	  imtest.crd imtest.img st2test.crd \
	  tconslymn.crd test.crd testh.crd vibrtst.crd noecon.dat cgpara1_ref.cmp \
	  cgpbe2_ref.cmp amtest4cg.inp amtest5cg.inp noetest5.brk readtest2.brk \
	  readtest3.brk readtest4.brk readtest5.brk ignore.pats

COUNTS = $(TESTS:.out=.Counts)

tests:	$(TESTS) 

install all:    tests diffs

diffs:  tests $(DIFFS)

counts:	 $(COUNTS)

clean :	
	- rm -f $(DIFFS) foo.* foo_gauss* *.cg* *.chp* *.sts* *.stb *.stb_bak \
                *.peer core pbe.peerphi cgpara1.cmp cgpbe2.cmp testparm.mod \
                nanatst1.fs nanatst1.fsbig nanatst1.tor vibrtst.mode vibrtst.sd \
                *.raw
	- rm -f archive/*.out archive/*.cmp

prepare : $(SOURCES)
	$(MAKE) clean
	- rm -f $(TESTS)

$(TESTS):   ../source/congen $(SOURCES)

congen.Counts:	congen.inp
	-../source/congen.pixie <congen.inp >congen.foo

tovax: tovax.time

tovax.time: $(SOURCES)
	cp $? dino
	(cd dino/; chmod u+w $?)
	touch tovax.time

cgpara1.dif: cgpara1.out cgpara1_ref.cmp
	cmploop cgpara1.cg cgpara1.cmp
	comparecmp cgpara1.cmp cgpara1_ref.cmp >cgpara1.dif.raw
	-co -p archive/cgpara1.out | diff -a - cgpara1.out >>cgpara1.dif.raw
	ndiffpost -ignore=ignore.pats -sort -angle=2 <cgpara1.dif.raw >cgpara1.dif

cgpara1_ref.cmp:
	co -p archive/cgpara1_ref.cmp > cgpara1_ref.cmp

cgpbe2.dif: cgpbe2.out cgpbe2_ref.cmp
	cmploop cgpbe2.cg cgpbe2.cmp
	comparecmp cgpbe2.cmp cgpbe2_ref.cmp >cgpbe2.dif.raw
	-co -p archive/cgpbe2.out | diff -a - cgpbe2.out >>cgpbe2.dif.raw
	ndiffpost -ignore=ignore.pats -sort -angle=2 <cgpbe2.dif.raw >cgpbe2.dif

cgpbe2_ref.cmp:
	co -p archive/cgpbe2_ref.cmp > cgpbe2_ref.cmp

amtest4.out: amtest4.inp amtest4cg.inp

amtest5.out: amtest5.inp amtest5cg.inp

.inp.out:
	-ruc -i $* ../source

.out.dif:
	-co -p archive/$*.out | diff -a -w - $*.out | tee $*.dif.raw | ndiffpost -ignore=ignore.pats -sort -angle=2 >$*.dif

.inp.Counts:
	-../source/congen.pixie <$*.inp >$*.foo
	mv congen.Counts $*.Counts

.DEFAULT:
	co $<

