From 6e84837b5865ee12196a6de7955e16324ffa7d7c Mon Sep 17 00:00:00 2001
From: Min RK <benjaminrk@gmail.com>
Date: Thu, 15 Jun 2023 00:06:44 +0200
Subject: [PATCH] run host H5detect when cross-compiling

---
 configure.ac               | 8 ++++++++
 fortran/src/Makefile.am    | 4 ++--
 hl/fortran/src/Makefile.am | 2 +-
 src/Makefile.am            | 4 ++--
 4 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index 6e9421592f..598e8b6b64 100644
--- a/configure.ac
+++ b/configure.ac
@@ -129,6 +129,14 @@ AC_SUBST([AR_FLAGS])
 
 AC_SUBST([cross_compiling])
 
+## src_run for running h5detect
+## rely on $PATH for host-native h5detect
+if test "x${cross_compiling}" = "xyes"; then
+  src_run=""
+else
+  src_run="./"
+fi
+AC_SUBST([src_run])
 
 ## H5_CFLAGS (and company) are for CFLAGS that should be used on HDF5, but
 ## not exported to h5cc (or h5fc, etc.)
diff --git a/fortran/src/Makefile.am b/fortran/src/Makefile.am
index d42a41d2c9..a83df060cd 100644
--- a/fortran/src/Makefile.am
+++ b/fortran/src/Makefile.am
@@ -119,13 +119,13 @@ BUILT_SOURCES = H5f90i_gen.h
 # header, then H5match_types which includes that header, then
 # it needs to run H5match_types.
 H5fortran_types.F90 H5f90i_gen.h: H5match_types$(EXEEXT)
-	$(RUNSERIAL) ./H5match_types$(EXEEXT)
+	$(RUNSERIAL) $(src_run)H5match_types$(EXEEXT)
 
 # H5_buildiface.F90 generates all the APIs that have a KIND type associated
 # with them.
 
 H5_gen.F90: H5_buildiface$(EXEEXT)
-	$(RUNSERIAL) ./H5_buildiface$(EXEEXT)
+	$(RUNSERIAL) $(src_run)H5_buildiface$(EXEEXT)
 
 # H5_buildiface.F90 is included in the distribution, and Automake knows
 # how to compile a fortran program given its sources.
diff --git a/hl/fortran/src/Makefile.am b/hl/fortran/src/Makefile.am
index 8fe618d6d3..147c7ab566 100644
--- a/hl/fortran/src/Makefile.am
+++ b/hl/fortran/src/Makefile.am
@@ -95,7 +95,7 @@ noinst_PROGRAMS = H5HL_buildiface
 # with them.
 
 H5LTff_gen.F90: H5HL_buildiface$(EXEEXT)
-	$(RUNSERIAL) ./H5HL_buildiface$(EXEEXT)
+	$(RUNSERIAL) $(src_run)H5HL_buildiface$(EXEEXT)
 
 H5TBff_gen.F90: H5HL_buildiface$(EXEEXT)
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 5650c38e3d..c09fde515e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -198,7 +198,7 @@ H5Tinit.c: H5detect$(EXEEXT)
 	@if $(AM_V_P); then set -x; else echo "  GEN      H5Tinit.c"; fi;       \
 	LD_LIBRARY_PATH="$$LD_LIBRARY_PATH`echo $(LDFLAGS) |                    \
 	    sed -e 's/-L/:/g' -e 's/ //g'`"                                     \
-	$(RUNSERIAL) ./H5detect$(EXEEXT)  $@  ||                               	\
+	$(RUNSERIAL) $(src_run)H5detect$(EXEEXT)  $@  ||                               	\
 	    (test $$HDF5_Make_Ignore && echo "*** Error ignored") ||            \
 	    ($(RM) $@ ; exit 1)
 
@@ -211,7 +211,7 @@ H5lib_settings.c: H5make_libsettings$(EXEEXT) libhdf5.settings
 	@if $(AM_V_P); then set -x; else echo "  GEN      H5lib_settings.c"; fi;    \
 	LD_LIBRARY_PATH="$$LD_LIBRARY_PATH`echo $(LDFLAGS) |                        \
 	    sed -e 's/-L/:/g' -e 's/ //g'`"                                         \
-	$(RUNSERIAL) ./H5make_libsettings$(EXEEXT)  $@  ||                          \
+	$(RUNSERIAL) $(src_run)H5make_libsettings$(EXEEXT)  $@  ||                          \
 	    (test $$HDF5_Make_Ignore && echo "*** Error ignored") ||                \
 	    ($(RM) $@ ; exit 1)
 
-- 
2.41.0

