#= Makefile for gtool5/test
#
# Authors::   Yasuhiro MORIKAWA (morikawa), Eizi TOYODA (toyoda)
# Version::   $Id: Makefile,v 1.2 2008-09-23 12:29:16 morikawa Exp $
# Tag Name::  $Name: gtool5-20081006 $
# Copyright:: Copyright (C) GFD Dennou Club, 2004-2008. All rights reserved.
# License::   See COPYRIGHT[link:../../COPYRIGHT]
#
######################################################################
#
#== Settings

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

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

TARGETS=histinquire histtest histaxis histget histcopy histnmlinfo \
	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 dc_scaledsec_test

BCGT4=histgt4bc

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 xhistauto/*.cdl \
	xhistnmlinfo/*.cdl \
	xhistnmlinfo/Data?.nc \
	xhistnmlinfo/Data2_3_4.nc

CLEANED_DIR=tmp_dc_iounit_test

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

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

%: %.sh   # clear an implicit rule

all: $(LIBGTOOL) $(TARGETS_DC) $(TARGETS)

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

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

clean: clean-histauto
	@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

clean-histauto:
	cd xhistauto ; $(RM) -f `sh ../histauto.sh -l`

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) $(BCGT4) ; 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) $(BCGT4)  ; 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) $(BCGT4) ; do  \
	  CROSS_COMPILING=$(CROSS_COMPILING) MAKE=$(MAKE) sh $$i.sh || exit 1; \
	done
	@echo ""
	@echo "   **** All Tests were Successful ****"
	@echo ""
