#---------------------------------------------------------------------
#     Copyright (C) GFD Dennou Club, 2005. All rights reserved.
#---------------------------------------------------------------------
#= Makefile for gt4f90io/test
#
# Authors::   Eizi TOYODA (toyoda), Yasuhiro MORIKAWA (morikawa)
# Version::   $Id: Makefile,v 1.28 2008-02-11 14:24:13 morikawa Exp $
# Tag Name::  $Name: gt4f90io-20080602 $
# Copyright:: Copyright (C) GFD Dennou Club, 2004-2005. All rights reserved.
# License::   See COPYRIGHT[link:../../COPYRIGHT]
#
######################################################################
#
#== Settings

INCLUDEFILE = ../Config.mk
include $(INCLUDEFILE)

INCLUDE_GT=$(MODPATHFLAG)../src
#INCLUDE_GT=-M../src     # SunStudio
LIBGT4=../src/lib$(LIBNAME).a

TARGETS=histinquire histtest histaxis histget histcopy gt4_history_nmlinfo_test #histauto

TARGETS_DC=dc_test_test dc_string_test dc_url_test dc_args_test dc_hash_test \
	dc_date_test dc_clock_test dc_iounit_test

CLEANED=*.o $(MODS) $(TARGETS_DC) $(TARGETS) xdifs.log work.pc* \
	dc_clock_test.tmp \
	xhisttest/xhisttest?.nc xhisttest/xhisttest??.nc \
	xhisttest/xhisttest*.cdl \
	xhistaxis/xhistaxis?.nc xhistaxis/xhistaxis*.cdl \
	xhistget/xhistget?.nc xhistget/xhistgetdif?.cdl \
	xhistcopy/xhistcopy?.nc xhistcopy/xhistcopy*.cdl \
	xhistinquire?.nc \
	xhistauto/tmp.nc xhistauto/tmp?.nc xhistauto/tmp?_??.nc \
	xhistauto/tmp?_????.nc \
	xgt4_history_nmlinfo_test/*.cdl \
	xgt4_history_nmlinfo_test/Data?.nc \
	xgt4_history_nmlinfo_test/Data2_3_4.nc

CLEANED_DIR=tmp_dc_iounit_test

# End Settings
######################################################################

######################################################################
#== Rules
#

%: %.sh   # clear an implicit rule

all: $(LIBGT4) $(TARGETS_DC) $(TARGETS)

work.pcl: Makefile ../Config.mk
	sh ../chkpcl.sh $(SYSFFLAGS) $(INCLUDE_GT)

$(LIBGT4):
	$(MAKE) -C ../src

clean:
	@if [ ! X"$(wildcard $(CLEANED))" = X"" ]; then \
		echo $(RM) $(wildcard $(CLEANED)) ;\
		$(RM) $(wildcard $(CLEANED)) ;\
	fi
	@if [ ! X"$(wildcard $(CLEANED_DIR))" = X"" ]; then \
		echo $(RM) -r $(wildcard $(CLEANED_DIR)) ;\
		$(RM) -r $(wildcard $(CLEANED_DIR)) ;\
	fi

test: all
	@test -n "$(NCDUMP)" || \
	    eval 'echo ; echo "  Error: ncdump: command not found."; echo ; exit 1'
	@if [ ! "$(CROSS_COMPILING)" = "yes" ] && [ ! "$(CROSS_COMPILING)" = "maybe" ] ; then \
	    for i in $(TARGETS_DC) $(TARGETS) ; do  \
	      CROSS_COMPILING=$(CROSS_COMPILING) NCDUMP=$(NCDUMP) \
	      MKDIR=$(MKDIR) MAKE=$(MAKE) \
		 sh $$i.sh || \
	         eval 'echo "  Error: stderr is output to xdifs.log ." ; exit 1';\
	    done ;\
	else \
	    echo "" ;\
	    echo "   Cross compile mode will be used." ;\
	    echo "   After submitting ..." ;\
	    echo "          $(TARGETS_DC) $(TARGETS)," ;\
	    echo "" ;\
	    echo "   do \"make test-c\"" ;\
	    echo "" ;\
	    exit 1 ;\
	fi
	@echo ""
	@echo "   **** All Tests were Successful ****"
	@echo ""

test-f: all
	@test -n "$(NCDUMP)" || \
	    eval 'echo ; echo "  Error: ncdump: command not found."; echo ; exit 1'
	-@for i in $(TARGETS_DC) $(TARGETS) ; do  \
	  CROSS_COMPILING=$(CROSS_COMPILING) NCDUMP=$(NCDUMP) \
	      MKDIR=$(MKDIR) MAKE=$(MAKE) \
		 sh $$i.sh || \
	     echo "  $$i.sh: Error (continue mandatorily)";\
	done

test-c: all
	@test -n "$(NCDUMP)" || \
	    eval 'echo ; echo "  Error: ncdump: command not found."; echo ; exit 1'
	@for i in $(TARGETS) ; do  \
	  CROSS_COMPILING=$(CROSS_COMPILING) MAKE=$(MAKE) sh $$i.sh || exit 1; \
	done
	@echo ""
	@echo "   **** All Tests were Successful ****"
	@echo ""
