####################################################################
#   Copyright (c) 1996 NPACT Working Group. You may copy,          #
#   distribute, and modify it freely as long as you preserve this  #
#   copyright and permission notice.                               #
#                                                                  #
#   NPACT Working Group is a joint force of                        #
#      NPAC at Syracuse University,                                #
#      PACT at Harbin Institute of Technology, and                 #
#      PACT at Peking University                                   #
####################################################################

SHELL=/bin/sh

srcdir      = @srcdir@
top_srcdir  = @top_srcdir@

VERSION = @VERSION@

prefix      = @prefix@

exec_prefix = @exec_prefix@
bindir      = @bindir@

target=

VPATH = .:${srcdir}

all: update check

update: Makefile

Makefile: Makefile.in
	@echo 
	@echo Please configure the package to generate new makefile ...
	@exit 1

check:  hpf2dep hpfsc dumpdep unparse compare


hpf2dep:
	@echo "----------- Test Compiling ------------"
	@for i in `ls ${srcdir}/*.f`; do (echo "...Compiling " $$i; \
	if [ -x ../../../src/hpf2dep/hpf2dep ]; then ../../../src/hpf2dep/hpf2dep $$i; \
	else if [ -x ${bindir}/hpf2dep ]; then ${bindir}/hpf2dep $$i; \
	     else echo Pease make the package first ...; exit 1; \
             fi; \
	fi;) done  
	@if [ ${srcdir} != . ] ; then mv ${srcdir}/*.dep . ; fi 

hpfsc:
	@echo "---------- Test Semantics Checking ------------"
	@for i in `ls *.dep`; do (echo "...Second pass compiling " $$i; \
	if [ -x ../../../src/hpfsc/hpfsc ]; then ../../../src/hpfsc/hpfsc -c $$i 2> $$i.sem; \
	else if [ -x ${bindir}/hpfsc ]; then ${bindir}/hpfsc -c $$i 2> $$i.sem; \
	     else echo Pease make the package first ...; exit 1; \
             fi; \
	fi;) done  

dumpdep:
	@echo "---------- Test  Dumping  ------------"
	@for i in `ls *.dep`; do (echo "...Dumping " $$i; \
	if [ -x ../../../src/tools/dump/dumpdep ]; then ../../../src/tools/dump/dumpdep $$i > $$i.lnk; \
	else if [ -x ${bindir}/dumpdep ]; then ${bindir}/dumpdep $$i > $$i.lnk; \
	     else echo Pease make the package first ...; exit 1; \
             fi; \
	fi;) done  

unparse:
	@echo "---------- Test Unparsing ------------"
	@for i in `ls *.dep`; do (echo "...Unparsing " $$i; \
	if [ -x ../../../src/tools/unparse/unparse ]; then ../../../src/tools/unparse/unparse $$i > $$i.src; \
	else if [ -x ${bindir}/unparse ]; then ${bindir}/unparse $$i > $$i.src; \
	     else echo Pease make the package first ...; exit 1; \
             fi; \
	fi;) done  


clean:
	rm -f *.dep *.lst *.dep.lnk *.dep.sem *.dep.src core

distclean:
	rm -f *.lnk.rec 

record:
	for i in `ls *.lnk`; do (cp $$i  $$i.rec;) done
	for i in `ls *.sem`; do (cp $$i  $$i.rec;) done
	for i in `ls *.src`; do (cp $$i  $$i.rec;) done

compdep:
	@echo "---------- Comparing dep file results  ----------"
	@for i in `ls *.lnk`; do (echo "...Comparing" $$i; \
	diff $$i.rec $$i;) done

compare:
	@echo "---------- Comparing unparse results ----------"
	@for i in `ls *.src`; do (echo "...Comparing" $$i; \
	diff ${srcdir}/$$i.rec $$i;) done
	@echo "---------- Comparing semantics checking results  ----------"
	@for i in `ls *.sem`; do (echo "...Comparing" $$i; \
	diff ${srcdir}/$$i.rec $$i;) done

test: 
	@echo ${target}
	if [ -x ${bindir}/hpf2dep ]; then ${bindir}/hpf2dep ${target}.f; \
	else ../../../src/hpf2dep/hpf2dep ${target}.f; fi
	if [ -x ${bindir}/hpfsc ]; then ${bindir}/hpfsc -c ${target}.dep 2> ${target}.dep.sem; \
	else ../../../src/hpfsc/hpfsc -c ${target}.dep 2> ${target}.dep.sem; fi
	diff ${target}.dep.sem.rec ${target}.dep.sem
	if [ -x ${bindir}/dumpdep ]; then ${bindir}/dumpdep ${target}.dep > ${target}.dep.lnk; \
	else ../../../src/tools/dump/dumpdep ${target}.dep > ${target}.dep.lnk; fi
	diff ${target}.dep.lnk.rec ${target}.dep.lnk
	if [ -x ${bindir}/unparse ]; then ${bindir}/unparse ${target}.dep > ${target}.dep.src; \
	else ../../../src/tools/unparse/unparse ${target}.dep > ${target}.dep.src; fi
	diff ${target}.dep.src.rec ${target}.dep.src







