##------------------------------------------------------------ -*- makefile -*-
# Copyright by The HDF Group.
# Copyright by the Board of Trustees of the University of Illinois.
# All rights reserved.
#
# This file is part of HDF5.  The full HDF5 copyright notice, including
# terms governing use, modification, and redistribution, is contained in
# the files COPYING and Copyright.html.  COPYING can be found at the root
# of the source code distribution tree; Copyright.html can be found at the
# root level of an installed copy of the electronic HDF5 document set and
# is linked from the top-level documents page.  It can also be found at
# http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have
# access to either file, you may request a copy from help@hdfgroup.org.
##
##
## The following section of this makefile comes from the
## `./config/conclude' file which was generated with config.status
## from `./config/conclude.in'.
##-----------------------------------------------------------------------------

## This is the target for the library described in the main body of the
## makefile.
##
lib: $(LIB)
$(LIB) __no_library__: $(LIB_OBJ)
	@$(LT_LINK_LIB) -o $@ $(CFLAGS) $(LIB_OBJ) $(LDFLAGS) $(LIBS)
	@for d in X $(SUBDIRS); do                                      \
	    if test $$d != X; then                                      \
	        (set -x; cd $$d && $(MAKE) lib) || exit 1;              \
	    fi;                                                         \
	done

progs: $(LIB) $(PROGS)
	@for d in X $(SUBDIRS); do                                      \
	    if test $$d != X; then                                      \
	        (set -x; cd $$d && $(MAKE) progs) || exit 1;            \
	    fi;                                                         \
	done

## Build a tags file in this directory.
##
TAGS: $(LIB_SRC)
	$(RM) $@
	-etags $(LIB_SRC)

## Runs each test in order, passing $(TEST_FLAGS) to the program.
## Since tests are done in a shell loop, "make -i" does apply inside it.
## Set HDF5_Make_Ignore to a non-blank string to ignore errors inside the loop.
## The timestamps give a rough idea how much time the tests use.
##
tests: $(TEST_PROGS) $(TEST_PROGS_PARA) $(TEST_SCRIPTS) $(LIB)
check test _test: tests
	@echo "===Tests in `echo ${PWD} | sed -e s:.*/::` begin `date`==="
	$(MAKE) _check-s
	$(MAKE) _check-p
	@echo "===Tests in `echo ${PWD} | sed -e s:.*/::` ended `date`==="

## serial tests
check-s: tests
	@echo "===Serial tests in `echo ${PWD} | sed -e s:.*/::` begin `date`==="
	$(MAKE) _check-s
	@echo "===Serial tests in `echo ${PWD} | sed -e s:.*/::` ended `date`==="

## parallel tests
check-p: tests
	@echo "===Parallel tests in `echo ${PWD} | sed -e s:.*/::` begin `date`==="
	$(MAKE) _check-p
	@echo "===Parallel tests in `echo ${PWD} | sed -e s:.*/::` ended `date`==="

## Actual execution of sequtial tests.
_check-s: tests
	@for test in $(TEST_PROGS) dummy; do                                  \
	   if test $$test != dummy; then				      \
	      echo "============================";			      \
	      echo "Testing $$test $(TEST_FLAGS)";			      \
	      echo "============================";			      \
	      srcdir="$(srcdir)"					      \
		 $(TIME) $(RUNTEST) ./$$test $(TEST_FLAGS) ||		      \
		 (test $$HDF5_Make_Ignore && echo "*** Error ignored") ||     \
		 break;							      \
	      echo "";							      \
	   fi;								      \
	done;								      \
	test $$test = dummy || false
	@for test in $(TEST_SCRIPTS) dummy; do                                \
	   if test $$test != dummy; then				      \
	      echo "============================";			      \
	      echo "Testing $$test $(TEST_FLAGS)";			      \
	      echo "============================";			      \
	      RUNSERIAL="$(RUNSERIAL)" RUNPARALLEL="$(RUNPARALLEL)"           \
	         srcdir="$(srcdir)"					      \
		 $(TIME) /bin/sh $$test $(TEST_FLAGS) ||	              \
		 (test $$HDF5_Make_Ignore && echo "*** Error ignored") ||     \
		 break;							      \
	      echo "";							      \
	   fi;								      \
	done;								      \
	test $$test = dummy || false

## Actual execution of parallel tests.
_check-p: tests
	@if test -n "$(TEST_PROGS_PARA)"; then				      \
	    echo "**** Hint ****";					      \
	    echo "Parallel test files reside in the current directory"	      \
	         "by default.";						      \
	    echo "Set HDF5_PARAPREFIX to use another directory. E.g.,";	      \
	    echo "    HDF5_PARAPREFIX=/PFS/user/me";			      \
	    echo "    export HDF5_PARAPREFIX";				      \
	    echo "    make check";					      \
	    echo "**** end of Hint ****";				      \
	fi
	@for test in $(TEST_PROGS_PARA) dummy; do                             \
	   if test $$test != dummy; then				      \
	      echo "============================";			      \
	      echo "Testing $$test $(TEST_FLAGS)";			      \
	      echo "============================";			      \
	      srcdir="$(srcdir)"					      \
		 $(TIME) $(RUNPARALLEL) ./$$test $(TEST_FLAGS) ||	      \
		 (test $$HDF5_Make_Ignore && echo "*** Error ignored") ||     \
		 break;							      \
	      echo "";							      \
	   fi;								      \
	done;								      \
	test $$test = dummy || false
	@for test in $(TEST_SCRIPTS_PARA) dummy; do                                \
	   if test $$test != dummy; then				      \
	      echo "============================";			      \
	      echo "Testing $$test $(TEST_FLAGS)";			      \
	      echo "============================";			      \
	      RUNSERIAL="$(RUNSERIAL)" RUNPARALLEL="$(RUNPARALLEL)"           \
	         srcdir="$(srcdir)"					      \
		 $(TIME) /bin/sh $$test $(TEST_FLAGS) ||	              \
		 (test $$HDF5_Make_Ignore && echo "*** Error ignored") ||     \
		 break;							      \
	      echo "";							      \
	   fi;								      \
	done;								      \
	test $$test = dummy || false

## Run test with different Virtual File Driver
check-vfd:
	@for vfd in $(VFD_LIST) dummy; do				      \
	    if test $$vfd != dummy; then                                      \
		echo "============================";                          \
		echo "Testing Virtual File Driver $$vfd";		      \
		echo "============================";                          \
		HDF5_DRIVER=$$vfd $(MAKE) check;			      \
	    fi;								      \
	done

## Make installation directories directories if they don't exist.
##
$(libdir):
	-$(top_srcdir)/bin/mkdirs $@

$(includedir):
	-$(top_srcdir)/bin/mkdirs $@

$(bindir):
	-$(top_srcdir)/bin/mkdirs $@

$(DOCDIR):
	-$(top_srcdir)/bin/mkdirs $@

$(EXAMPLEDIR):
	-$(top_srcdir)/bin/mkdirs $@

## Install the library, the public header files, and public programs.
##
install: $(AUX_LIB) $(PUB_LIB) $(PUB_HDR) $(PUB_PROGS) $(libdir) $(includedir) $(bindir)
	@for f in X $(PUB_LIB); do					      \
	   if test $$f != X; then					      \
	      ($(LT_INSTALL_LIB) $$f $(libdir)/. || exit 1);		      \
	   fi;								      \
	done
	@if test -f libhdf5.settings; then				      \
	   (set -x; $(INSTALL_DATA) libhdf5.settings $(libdir)/. || exit 1);  \
	fi
	@for f in X $(PUB_HDR); do					      \
	   if test $$f != X; then					      \
	      if test -f $$f; then					      \
		 (set -x; $(INSTALL_DATA) $$f $(includedir)/. || exit 1);     \
	      else							      \
	         (set -x; $(INSTALL_DATA) $(srcdir)/$$f $(includedir)/. ||    \
		    exit 1);						      \
	      fi;							      \
	   fi;								      \
	done
	@for f in X $(PUB_PROGS); do					      \
	   if test $$f != X; then					      \
	     if test "X$(PARALLEL)" != "Xno"; then                            \
	       if test $$f = "h5cc"; then                     		      \
	         ($(LT_INSTALL_PROG) $$f $(bindir)/h5pcc || exit 1);          \
	       elif test $$f = "h5fc"; then                                   \
	         ($(LT_INSTALL_PROG) $$f $(bindir)/h5pfc || exit 1);          \
	       else							      \
	         ($(LT_INSTALL_PROG) $$f $(bindir)/. || exit 1);	      \
	       fi;							      \
	     else                                                             \
	       ($(LT_INSTALL_PROG) $$f $(bindir)/. || exit 1);		      \
	     fi;							      \
	   fi;							              \
	done
	@for d in X $(SUBDIRS); do                                            \
	    if test $$d != X; then                                            \
	       (set -x; cd $$d && $(MAKE) $@) || exit 1;                      \
	    fi;                                                               \
	done

install-examples: $(EXAMPLE_PROGS) $(EXAMPLEDIR)
	@for f in X $(EXAMPLE_PROGS); do				      \
	  if test $$f != X; then					      \
	    (set -x; $(INSTALL_DATA) $(srcdir)/$$f $(EXAMPLEDIR)/. || exit 1);\
	  fi;								      \
	done

uninstall-examples:
	@if test -n "$(EXAMPLE_PROGS)"; then 				      \
	  set -x; cd $(EXAMPLEDIR) && $(RM) $(EXAMPLE_PROGS);		      \
	fi

## Install the documents.
##
install-doc: $(PUB_DOCS) $(DOCDIR)
	@if test -n "$(DOCDIR)"; then                                         \
	    if test -d "$(DOCDIR)"; then                                      \
	       :;                                                             \
	    else                                                              \
	       mkdir $(DOCDIR) && chmod 755 $(DOCDIR);                        \
	    fi;                                                               \
	fi
	@if test -n "$(SUBDOCDIR)"; then                                      \
	    if test -d "$(SUBDOCDIR)" ; then                                  \
	       :;                                                             \
	    else                                                              \
	       mkdir $(SUBDOCDIR) && chmod 755 $(SUBDOCDIR);                  \
	    fi;                                                               \
	fi
	@for d in X $(SUBDIRS); do                                            \
	   if test $$d != X; then                                             \
	      (set -x; cd $$d && $(MAKE) $@) || exit 1;                       \
	   fi;                                                                \
	done
	@for f in X $(PUB_DOCS); do                                           \
	   if test $$f != X; then                                             \
	      if test -f $$f; then                                            \
		 (set -x; $(INSTALL_DATA) $$f $(DOCDIR)/. || exit 1);         \
	      else                                                            \
	         (set -x; $(INSTALL_DATA) $(srcdir)/$$f $(DOCDIR)/. ||        \
		    exit 1);                                                  \
	      fi;                                                             \
	   fi;                                                                \
	done
	@for f in X $(PUB_SUBDOCS); do                                        \
	   if test $$f != X; then                                             \
	      if test -f $$f; then                                            \
		 (set -x; $(INSTALL_DATA) $$f $(SUBDOCDIR)/. || exit 1);      \
	      else                                                            \
	         (set -x; $(INSTALL_DATA) $(srcdir)/$$f $(SUBDOCDIR)/. ||     \
		    exit 1);                                                  \
	      fi;                                                             \
	   fi;                                                                \
	done

## Removes those things that `make install' (would have) installed.
##
uninstall:
	@for f in libhdf5.settings $(LIB); do				      \
          $(LT_UNINSTALL) $(libdir)/$$f;				      \
	done
	@if test -n "$(PUB_HDR)"; then                                        \
	  set -x; cd $(includedir) && $(RM) $(PUB_HDR);			      \
	fi
	@for f in X $(PUB_PROGS); do					      \
	    if test $$f != X; then					      \
	        $(LT_UNINSTALL) $(bindir)/$$f;				      \
	    fi;								      \
	done

## Removes those things that `make install-doc' (would have) installed.
##
uninstall-doc:
	@for d in X $(SUBDIRS); do					      \
	  if test $$d != X; then					      \
	    (set -x; cd $$d && $(MAKE) $@) || exit 1;                         \
	  fi;								      \
	done
	@if test -n "$(PUB_DOCS)"; then 				      \
	  set -x; cd $(DOCDIR) && $(RM) $(PUB_DOCS);			      \
	fi
	@if test -n "$(PUB_SUBDOCS)"; then				      \
	  set -x; cd $(DOCDIR) && $(RM) $(PUB_SUBDOCS);			      \
	fi

## Removes temporary files without removing the final target files.  That is,
## remove things like object files but not libraries or executables.
##
mostlyclean:
	@for d in X $(SUBDIRS); do                                            \
	    if test $$d != X; then                                            \
	        (set -x; cd $$d; $(MAKE) $@) || exit 1;                       \
	    fi;                                                               \
	done
	@if test -n "$(LIB_OBJ)"; then                                        \
	    $(RM) $(LIB_OBJ) $(LIB_OBJ:.lo=.o);                              \
	fi
	@if test -n "$(TEST_OBJ)"; then                                       \
	    $(RM) $(TEST_OBJ) $(TEST_OBJ:.lo=.o);                            \
	fi
	@if test -n "$(PROG_OBJ)" || test -n "$(MOSTLYCLEAN)"; then           \
	    $(RM) $(PROG_OBJ) $(PROG_OBJ:.lo=.o) $(MOSTLYCLEAN);             \
	fi

## Like `mostlyclean' except it also removes the final targets: things like
## libraries and executables.  This target doesn't remove any file that
## is part of the HDF5 distribution.
##
clean: mostlyclean
	@for d in X $(SUBDIRS); do                                            \
	    if test $$d != X; then                                            \
	        (set -x; cd $$d; $(MAKE) $@) || exit 1;                       \
	    fi;                                                               \
	done
	@if test -n "$(LIB)" -o -n "$(TEST_PROGS)" -o -n "$(TEST_PROGS_PARA)" -o -n "$(PROGS)" -o -n "$(CLEAN)"; then \
	    $(RM) $(LIB) $(TEST_PROGS) $(TEST_PROGS_PARA) $(PROGS) $(CLEAN);                     \
	fi;
	-$(RM) -r .libs

## Like `clean' except it also removes files that were created by running
## configure.  If you've unpacked the source and built HDF5 without creating
## any other files, then `make distclean' will leave only the files that were
## in the distribution.
##
distclean: clean
	-$(RM) .depend TAGS *~ core *.core *.bak *.old *.new $(DISTCLEAN)
	@for d in X $(SUBDIRS); do					      \
	  if test $$d != X; then					      \
	    (set -x; cd $$d; $(MAKE) $@) || exit 1;			      \
	  fi;								      \
	done
	@if test -f $(srcdir)/Makefile.in; then				      \
	   (set -x; $(RM) Makefile);					      \
	fi

## Like `distclean' except it deletes all files that can be regenerated from
## the makefile, including those generated from autoheader and autoconf.
##
maintainer-clean: distclean
	@for d in X $(SUBDIRS); do                                            \
	    if test $$d != X; then                                            \
	        (set -x; cd $$d; $(MAKE) $@) || exit 1;                       \
	    fi;                                                               \
	done
	-$(RM) *~ core core.* *.core *.bak *.contrib gmon.out

## Implicit rules
##
.c.o:
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $<

.c.lo:
	@$(LT_COMPILE) $(CFLAGS) $(CPPFLAGS) -c $<

##-----------------------------------------------------------------------------
## The following section of this makefile contains dependencies between the
## source files and the header files.
##-----------------------------------------------------------------------------
.PHONY: dep depend
dep depend: $(srcdir)/Dependencies

@DEPEND@
