diff --git a/build/Makefile.in b/build/Makefile.in
index a82f103bc3a50f7d90d196ef11114d485dd3982b..ac105e2334fff5ff736df9e6914a58a2736f72a1 100644
--- a/build/Makefile.in
+++ b/build/Makefile.in
@@ -463,6 +463,7 @@ ECHO_C = @ECHO_C@
 ECHO_N = @ECHO_N@
 ECHO_T = @ECHO_T@
 EGREP = @EGREP@
+ENABLE_ILP64 = @ENABLE_ILP64@
 ETAGS = @ETAGS@
 EXEEXT = @EXEEXT@
 F77 = @F77@
diff --git a/build/configure b/build/configure
index 67e4ee42698a4e46ecd84deb4a13e4c3c14b60c9..22808d5f4190243353c57e6d5fbfe52b8368b68e 100755
--- a/build/configure
+++ b/build/configure
@@ -668,6 +668,7 @@ OMPFLAGS
 OFFLOADFLAGS
 BUILDFORTRAN_FALSE
 BUILDFORTRAN_TRUE
+ENABLE_ILP64
 HDF5_LDFLAGS
 CXXCPP
 LT_SYS_LIBRARY_PATH
@@ -812,6 +813,7 @@ with_aix_soname
 with_gnu_ld
 with_sysroot
 enable_libtool_lock
+enable_ilp64
 enable_fortran
 enable_offload
 enable_openmp
@@ -1477,6 +1479,7 @@ Optional Features:
   --enable-fast-install[=PKGS]
                           optimize for fast installation [default=yes]
   --disable-libtool-lock  avoid locking (might break parallel builds)
+  --enable-ilp64          enable 64-bit indexing [default=yes]
   --enable-fortran        enable legacy FORTRAN compilation [default=auto]
   --enable-offload        enable target offloading (requires g++ version >=
                           13) [default=auto]
@@ -1496,7 +1499,8 @@ Optional Packages:
   --with-sysroot[=DIR]    Search for dependent libraries within DIR (or the
                           compiler's sysroot if not specified).
   --with-lapack           use LAPACK [default=auto]
-  --with-magma            use MAGMA [default=auto]
+  --with-magma[=MAGMA_DIR]
+                          use MAGMA [default=auto]
   --with-include          additional include folders [default=none]
   --with-fflags=flags     FORTRAN compiler flags [default="-std=legacy -O3"]
   --with-ldflags=flags    custom linker flags [default=none]
@@ -7881,9 +7885,9 @@ EOF
     fi
 
 
-	if test "x$CXX_IS_MPI" != "x0"; then
+        if test "x$CXX_IS_MPI" != "x0"; then
           as_fn_error $? "MPI was requested, but $CXX is not a MPI compiler!" "$LINENO" 5
-	fi
+        fi
       fi
     fi
 
@@ -24829,42 +24833,62 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 # Environment setup
 
-    export -p | grep HDF5_ROOT > /dev/null
-    result=$?
-    if test "x$result" = "x0"; then
-      if test "x$HDF5_INCLUDE" = "x"; then
-        export HDF5_INCLUDE=${HDF5_ROOT}/include
-      fi
-      if test "x$HDF5_LIB" = "x"; then
-        export HDF5_LIB=${HDF5_ROOT}/lib
-      fi
-    fi
-    export -p | grep HDF5_DIR > /dev/null
-    result=$?
-    if test "x$result" = "x0"; then
-      if test "x$HDF5_INCLUDE" = "x"; then
-        export HDF5_INCLUDE=${HDF5_DIR}/include
-      fi
-      if test "x$HDF5_LIB" = "x"; then
-        export HDF5_LIB=${HDF5_DIR}/lib
+    if test "x${HDF5_INCLUDE}${HDF5_LIB}" = "x"; then
+      pkg-config --version > /dev/null
+      use_pkg_config=$?
+      if test "x$use_pkg_config" = "x0"; then
+        declare -a pkg_array=$(pkg-config --list-all | grep hdf5-serial)
+        for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep hdf5-serial > /dev/null
+        result=$?
+        if test "x$result" = "x0"; then
+          cflags=$(pkg-config --cflags-only-I hdf5-serial)
+          export HDF5_INCLUDE=$(echo "${cflags:2}")
+          ldflags=$(pkg-config --libs-only-L hdf5-serial)
+          export HDF5_LIB=$(echo "${ldflags:2}")
+        else
+          declare -a pkg_array=$(pkg-config --list-all | grep hdf5)
+          for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep hdf5 > /dev/null
+          result=$?
+          if test "x$result" = "x0"; then
+            cflags=$(pkg-config --cflags-only-I hdf5)
+            export HDF5_INCLUDE=$(echo "${cflags:2}")
+            ldflags=$(pkg-config --libs-only-L hdf5)
+            export HDF5_LIB=$(echo "${ldflags:2}")
+          fi
+        fi
+      else
+        export -p | grep HDF5_ROOT > /dev/null
+        result=$?
+        if test "x$result" = "x0"; then
+          if test "x$HDF5_INCLUDE" = "x"; then
+            export HDF5_INCLUDE=${HDF5_ROOT}/include
+          fi
+          if test "x$HDF5_LIB" = "x"; then
+            export HDF5_LIB=${HDF5_ROOT}/lib
+          fi
+        fi
+        export -p | grep HDF5_DIR > /dev/null
+        result=$?
+        if test "x$result" = "x0"; then
+          if test "x$HDF5_INCLUDE" = "x"; then
+            export HDF5_INCLUDE=${HDF5_DIR}/include
+          fi
+          if test "x$HDF5_LIB" = "x"; then
+            export HDF5_LIB=${HDF5_DIR}/lib
+          fi
+        fi
+        if test "x$HDF5_INCLUDE" = "x"; then
+          export HDF5_INCLUDE="/usr/include/hdf5/serial"
+        fi
+        if test "x$HDF5_LIB" = "x"; then
+          export HDF5_LIB="/usr/lib/x86_64-linux-gnu/hdf5/serial"
+        fi
       fi
     fi
-    if test "x$HDF5_INCLUDE" = "x"; then
-      export HDF5_INCLUDE="/usr/include/hdf5/serial"
-    fi
-    if test "x$HDF5_LIB" = "x"; then
-      export HDF5_LIB="/usr/lib/x86_64-linux-gnu/hdf5/serial"
-    fi
 
 
 
-# Check for required headers
-# AC_CHECK_HEADER(
-#  [${HDF5_INCLUDE}/hdf5.h],
-#  ,
-#  AC_MSG_ERROR([Could not find HDF5 headers!]),
-# )
-if test -f ${HDF5_INCLUDE}/hdf5.h
+if test "x${HDF5_INCLUDE}" != "x"
 then :
   { printf "%s\n" "$as_me:${as_lineno-$LINENO}: HDF5 headers found in ${HDF5_INCLUDE}" >&5
 printf "%s\n" "$as_me: HDF5 headers found in ${HDF5_INCLUDE}" >&6;}
@@ -24873,6 +24897,15 @@ else case e in #(
  ;;
 esac
 fi
+if test "x${HDF5_LIB}" != "x"
+then :
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: HDF5 libraries found in ${HDF5_LIB}" >&5
+printf "%s\n" "$as_me: HDF5 libraries found in ${HDF5_LIB}" >&6;}
+else case e in #(
+  e) as_fn_error $? "HDF5 libraries not found!" "$LINENO" 5
+ ;;
+esac
+fi
 
 # Check for required libraries
 
@@ -24897,12 +24930,34 @@ then :
   HDF5_LDFLAGS="-L${HDF5_LIB} -lhdf5"
 
 else case e in #(
-  e) as_fn_error $? "\"HDF5 library not found!\"" "$LINENO" 5
+  e) as_fn_error $? "\"HDF5 library not working!\"" "$LINENO" 5
  ;;
 esac
 fi
 
 # Configure the optional features
+# Check whether --enable-ilp64 was given.
+if test ${enable_ilp64+y}
+then :
+  enableval=$enable_ilp64;
+    if test "x$enableval" = "xno"; then
+      ENABLE_ILP64=""
+
+    else
+      ENABLE_ILP64="yes"
+
+    fi
+
+else case e in #(
+  e)
+    ENABLE_ILP64="yes"
+
+
+ ;;
+esac
+fi
+
+
 # Check whether --enable-fortran was given.
 if test ${enable_fortran+y}
 then :
@@ -25114,15 +25169,67 @@ then :
 
     else
 
-    export -p | grep MKL > /dev/null
-    MKL_DEF=$?
-    if test "x$MKL_DEF" = "x0"; then
-      export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL -DLAPACK_ILP64 -DUSE_ILP64 -I{MKLROOT}/include"
-      export LAPACKLDFLAGS="-L${MKLROOT}/lib -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl"
+    if test "x$ENABLE_ILP64" = "xyes"; then
+      # 64-bit indices are enabled
+      LAPACK_ILP64_FLAG="-DLAPACK_ILP64 -DUSE_ILP64"
+      LAPACK_ILP64_LDSPEC="_ilp64"
+      LAPACK_LDSPEC="64"
+      MKL_BUILD="mkl-dynamic-ilp64-gomp"
     else
-      if test -f /usr/include/lapacke.h; then
-        export LAPACKFLAGS="-DUSE_LAPACK -DLAPACK_ILP64 -DUSE_ILP64"
-	export LAPACKLDFLAGS="-llapacke64"
+      # 64-bit indices are disabled
+      LAPACK_ILP64_FLAG=""
+      LAPACK_ILP64_LDSPEC="_lp64"
+      LAPACK_LDSPEC=""
+      MKL_BUILD="mkl-dynamic-lp64-gomp"
+    fi # end of 64-bit decision tree
+    pkg-config --version > /dev/null
+    use_pkg_config=$?
+    if test "x$use_pkg_config" = "x0"; then
+      # pkg-config is available
+      declare -a pkg_array=$(pkg-config --list-all | grep ${MKL_BUILD})
+      for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep ${MKL_BUILD} > /dev/null
+      result=$?
+      if test "x$result" = "x0"; then
+        # MKL was found
+        MKL_INCLUDE=$(pkg-config --cflags-only-I ${MKL_BUILD})
+        export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL ${LAPACK_ILP64_FLAG} ${MKL_INCLUDE}"
+        export LAPACKLDFLAGS=$(pkg-config --libs ${MKL_BUILD})
+      else
+        # MKL was not found, so configuration searches for LAPACKe
+        declare -a pkg_array=$(pkg-config --list-all | grep lapacke${LAPACK_LDSPEC})
+        for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep lapacke${LAPACK_LDSPEC} > /dev/null
+        result=$?
+        if test "x$result" = "x0"; then
+          # LAPACKe was found
+          LAPACK_INCLUDE=$(pkg-config --cflags-only-I lapacke${LAPACK_LDSPEC})
+          export LAPACKFLAGS="-DUSE_LAPACK ${LAPACK_ILP64_FLAG} ${LAPACK_INCLUDE}"
+          export LAPACKLDFLAGS=$(pkg-config --libs lapacke${LAPACK_LDSPEC})
+        fi # end of LAPACKe decision tree
+        if test "x${LAPACKFLAGS}${LAPACKLDFLAGS}" = "x"; then
+          # LAPACKe was not found, so configuration searches for LAPACK
+          declare -a pkg_array=$(pkg-config --list-all | grep lapack${LAPACK_LDSPEC})
+          for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep lapack${LAPACK_LDSPEC} > /dev/null
+          result=$?
+          if test "x$result" = "x0"; then
+            # LAPACK was found
+            LAPACK_INCLUDE=$(pkg-config --cflags-only-I lapack${LAPACK_LDSPEC})
+            export LAPACKFLAGS="-DUSE_LAPACK ${LAPACK_ILP64_FLAG} ${LAPACK_INCLUDE}"
+            export LAPACKLDFLAGS=$(pkg-config --libs lapack${LAPACK_LDSPEC})
+          fi # end of LAPACK decision tree
+        fi # end of LAPACKe decision tree
+      fi # end of MKL decision tree
+    else
+      # pkg-config is not available
+      export -p | grep MKL > /dev/null
+      MKL_DEF=$?
+      if test "x$MKL_DEF" = "x0"; then
+        export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL ${LAPACK_ILP64_FLAG} -I{MKLROOT}/include"
+        export LAPACKLDFLAGS="-L${MKLROOT}/lib -Wl,--no-as-needed -lmkl_intel${LAPACK_ILP64_LDSPEC} -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl"
+      else
+        if test -f /usr/include/lapacke.h; then
+          export LAPACKFLAGS="-DUSE_LAPACK ${LAPACK_ILP64_FLAG}"
+          export LAPACKLDFLAGS="-llapacke${LAPACK_LDSPEC}"
+        fi
       fi
     fi
 
@@ -25146,15 +25253,67 @@ fi
 else case e in #(
   e)
 
-    export -p | grep MKL > /dev/null
-    MKL_DEF=$?
-    if test "x$MKL_DEF" = "x0"; then
-      export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL -DLAPACK_ILP64 -DUSE_ILP64 -I{MKLROOT}/include"
-      export LAPACKLDFLAGS="-L${MKLROOT}/lib -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl"
+    if test "x$ENABLE_ILP64" = "xyes"; then
+      # 64-bit indices are enabled
+      LAPACK_ILP64_FLAG="-DLAPACK_ILP64 -DUSE_ILP64"
+      LAPACK_ILP64_LDSPEC="_ilp64"
+      LAPACK_LDSPEC="64"
+      MKL_BUILD="mkl-dynamic-ilp64-gomp"
+    else
+      # 64-bit indices are disabled
+      LAPACK_ILP64_FLAG=""
+      LAPACK_ILP64_LDSPEC="_lp64"
+      LAPACK_LDSPEC=""
+      MKL_BUILD="mkl-dynamic-lp64-gomp"
+    fi # end of 64-bit decision tree
+    pkg-config --version > /dev/null
+    use_pkg_config=$?
+    if test "x$use_pkg_config" = "x0"; then
+      # pkg-config is available
+      declare -a pkg_array=$(pkg-config --list-all | grep ${MKL_BUILD})
+      for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep ${MKL_BUILD} > /dev/null
+      result=$?
+      if test "x$result" = "x0"; then
+        # MKL was found
+        MKL_INCLUDE=$(pkg-config --cflags-only-I ${MKL_BUILD})
+        export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL ${LAPACK_ILP64_FLAG} ${MKL_INCLUDE}"
+        export LAPACKLDFLAGS=$(pkg-config --libs ${MKL_BUILD})
+      else
+        # MKL was not found, so configuration searches for LAPACKe
+        declare -a pkg_array=$(pkg-config --list-all | grep lapacke${LAPACK_LDSPEC})
+        for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep lapacke${LAPACK_LDSPEC} > /dev/null
+        result=$?
+        if test "x$result" = "x0"; then
+          # LAPACKe was found
+          LAPACK_INCLUDE=$(pkg-config --cflags-only-I lapacke${LAPACK_LDSPEC})
+          export LAPACKFLAGS="-DUSE_LAPACK ${LAPACK_ILP64_FLAG} ${LAPACK_INCLUDE}"
+          export LAPACKLDFLAGS=$(pkg-config --libs lapacke${LAPACK_LDSPEC})
+        fi # end of LAPACKe decision tree
+        if test "x${LAPACKFLAGS}${LAPACKLDFLAGS}" = "x"; then
+          # LAPACKe was not found, so configuration searches for LAPACK
+          declare -a pkg_array=$(pkg-config --list-all | grep lapack${LAPACK_LDSPEC})
+          for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep lapack${LAPACK_LDSPEC} > /dev/null
+          result=$?
+          if test "x$result" = "x0"; then
+            # LAPACK was found
+            LAPACK_INCLUDE=$(pkg-config --cflags-only-I lapack${LAPACK_LDSPEC})
+            export LAPACKFLAGS="-DUSE_LAPACK ${LAPACK_ILP64_FLAG} ${LAPACK_INCLUDE}"
+            export LAPACKLDFLAGS=$(pkg-config --libs lapack${LAPACK_LDSPEC})
+          fi # end of LAPACK decision tree
+        fi # end of LAPACKe decision tree
+      fi # end of MKL decision tree
     else
-      if test -f /usr/include/lapacke.h; then
-        export LAPACKFLAGS="-DUSE_LAPACK -DLAPACK_ILP64 -DUSE_ILP64"
-	export LAPACKLDFLAGS="-llapacke64"
+      # pkg-config is not available
+      export -p | grep MKL > /dev/null
+      MKL_DEF=$?
+      if test "x$MKL_DEF" = "x0"; then
+        export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL ${LAPACK_ILP64_FLAG} -I{MKLROOT}/include"
+        export LAPACKLDFLAGS="-L${MKLROOT}/lib -Wl,--no-as-needed -lmkl_intel${LAPACK_ILP64_LDSPEC} -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl"
+      else
+        if test -f /usr/include/lapacke.h; then
+          export LAPACKFLAGS="-DUSE_LAPACK ${LAPACK_ILP64_FLAG}"
+          export LAPACKLDFLAGS="-llapacke${LAPACK_LDSPEC}"
+        fi
       fi
     fi
 
@@ -25190,34 +25349,83 @@ then :
       MAGMALDFLAGS=""
 
     else
-      if test "x$withval" != "xyes" and "x$withval" != "xauto"; then
-        export MAGMA_HOME=$withval
+      if test "x$withval" != "xyes"; then
+        if test "x$withval" != "xauto"; then
+          export MAGMA_HOME=$withval
+	fi
       fi
 
-    if test -f /usr/local/cuda/include/cuda.h; then
-      CUDAFLAGS="-I/usr/local/cuda/include"
-      CUDALDFLAGS="-L/usr/local/cuda/lib64 -lcudart"
-    elif test -f /usr/include/cuda.h; then
-      CUDAFLAGS="-I/usr/include"
-      CUDALDFLAGS="-lcudart"
-    elif test "x$CUDA_HOME" != "x"; then
-      CUDAFLAGS="-I${CUDA_HOME}/include"
-      CUDALDFLAGS="-L${CUDA_HOME}/lib64 -lcudart"
-    fi
-    if test "x$CUDAFLAGS" != "x"; then
-      if test -f /usr/include/magma_v2.h; then
-        export MAGMAFLAGS="-DUSE_MAGMA -DMAGMA_ILP64 $CUDAFLAGS -I/usr/include"
-	export MAGMALDFLAGS="$CUDALDFLAGS -lmagma"
-      elif test -f /usr/local/include/magma_v2.h; then
-        export MAGMAFLAGS="-DUSE_MAGMA -DMAGMA_ILP64 $CUDAFLAGS -I/usr/local/include"
-	export MAGMALDFLAGS="$CUDALDFLAGS -lmagma"
-      elif test "x$MAGMA_HOME" != "x"; then
-        export MAGMAFLAGS="-DUSE_MAGMA -DMAGMA_ILP64 $CUDAFLAGS -I${MAGMA_HOME}/include"
-	export MAGMALDFLAGS="$CUDALDFLAGS -L${MAGMA_HOME}/lib -lmagma"
-      elif test "x$MAGMA_ROOT" != "x"; then
-        export MAGMAFLAGS="-DUSE_MAGMA -DMAGMA_ILP64 $CUDAFLAGS -I${MAGMA_ROOT}/include"
-	export MAGMALDFLAGS="$CUDALDFLAGS -L${MAGMA_ROOT}/lib -lmagma"
+    if test "x$ENABLE_ILP64" = "xyes"; then
+      # 64-bit indices are enabled
+      MAGMA_ILP64_FLAG="-DMAGMA_ILP64"
+      MAGMA_LD_SPEC="64"
+    else
+      # 64-bit indices are disabled
+      MAGMA_ILP64_FLAG=""
+      MAGMA_LD_SPEC=""
+    fi # end of 64-bit decision tree
+    pkg-config --version > /dev/null
+    use_pkg_config=$?
+    if test "x$use_pkg_config" = "x0"; then
+      # pkg-config is available
+      declare -a pkg_array=$(pkg-config --list-all | grep cudart)
+      for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep cudart > /dev/null
+      result=$?
+      if test "x$result" = "x0"; then
+        # CUDA runtime detected
+        cuda_pkg=$(for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep cudart)
+	CUDAFLAGS=$(pkg-config --cflags ${cuda_pkg})
+	CUDALDFLAGS=$(pkg-config --libs ${cuda_pkg})
+      fi # end of CUDA runtime decision tree
+    else
+      # pkg-config is not available
+      if test -f /usr/local/cuda/include/cuda.h; then
+        CUDAFLAGS="-I/usr/local/cuda/include"
+        CUDALDFLAGS="-L/usr/local/cuda/lib64 -lcudart"
+      elif test -f /usr/include/cuda.h; then
+        CUDAFLAGS="-I/usr/include"
+        CUDALDFLAGS="-lcudart"
+      elif test "x$CUDA_HOME" != "x"; then
+        CUDAFLAGS="-I${CUDA_HOME}/include"
+        CUDALDFLAGS="-L${CUDA_HOME}/lib64 -lcudart"
+      fi
+    fi # end of pkg-config decision tree
+    if test "x${MAGMA_ROOT}${MAGMA_HOME}${MAGMA_DIR}" = "x"; then
+      # MAGMA environment is not defined
+      if "x$use_pkg_config" = "x0"; then
+        # use pkg-config to search for MAGMA
+        declare -a pkg_array=$(pkg-config --list-all | grep magma)
+        for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep magma > /dev/null
+        result=$?
+	if test "x$result" = "x0"; then
+	  # MAGMA was found
+	  magma_pkg=$(for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep magma)
+	  MAGMA_INCLUDE=$(pkg-config --cflags-only-I ${magma_pkg})
+	  MAGMA_LIBS_DIR=$(pkg-config --cflags-only-L ${magma_pkg})
+          export MAGMAFLAGS="-DUSE_MAGMA ${MAGMA_ILP64_FLAG} $CUDAFLAGS ${MAGMA_INCLUDE}"
+          export MAGMALDFLAGS="$CUDALDFLAGS ${MAGMA_LIBS_DIR} -lmagma"
+	fi # end of MAGMA decision tree
+      else
+        # search for MAGMA in some standard folders
+        if test "x$CUDAFLAGS" != "x"; then
+          if test -f /usr/include/magma_v2.h; then
+            export MAGMAFLAGS="-DUSE_MAGMA ${MAGMA_ILP64_FLAG} $CUDAFLAGS -I/usr/include"
+            export MAGMALDFLAGS="$CUDALDFLAGS -lmagma"
+          elif test -f /usr/local/include/magma_v2.h; then
+            export MAGMAFLAGS="-DUSE_MAGMA ${MAGMA_ILP64_FLAG} $CUDAFLAGS -I/usr/local/include"
+            export MAGMALDFLAGS="$CUDALDFLAGS -lmagma"
+          fi
+        fi
+      fi # end of pkg-config decision tree
+    else
+      # MAGMA environment is defined, so configuration makes sure that MAGMA_ROOT is defined too
+      if test "x${MAGMA_HOME}" != "x"; then
+        MAGMA_ROOT="${MAGMA_HOME}"
+      elif test "x${MAGMA_DIR}" != "x"; then
+        MAGMA_ROOT="${MAGMA_DIR}"
       fi
+      export MAGMAFLAGS="-DUSE_MAGMA -DMAGMA_ILP64 $CUDAFLAGS -I${MAGMA_ROOT}/include"
+      export MAGMALDFLAGS="$CUDALDFLAGS -L${MAGMA_ROOT}/lib -lmagma"
     fi
 
 
@@ -25240,30 +25448,77 @@ fi
 else case e in #(
   e)
 
-    if test -f /usr/local/cuda/include/cuda.h; then
-      CUDAFLAGS="-I/usr/local/cuda/include"
-      CUDALDFLAGS="-L/usr/local/cuda/lib64 -lcudart"
-    elif test -f /usr/include/cuda.h; then
-      CUDAFLAGS="-I/usr/include"
-      CUDALDFLAGS="-lcudart"
-    elif test "x$CUDA_HOME" != "x"; then
-      CUDAFLAGS="-I${CUDA_HOME}/include"
-      CUDALDFLAGS="-L${CUDA_HOME}/lib64 -lcudart"
-    fi
-    if test "x$CUDAFLAGS" != "x"; then
-      if test -f /usr/include/magma_v2.h; then
-        export MAGMAFLAGS="-DUSE_MAGMA -DMAGMA_ILP64 $CUDAFLAGS -I/usr/include"
-	export MAGMALDFLAGS="$CUDALDFLAGS -lmagma"
-      elif test -f /usr/local/include/magma_v2.h; then
-        export MAGMAFLAGS="-DUSE_MAGMA -DMAGMA_ILP64 $CUDAFLAGS -I/usr/local/include"
-	export MAGMALDFLAGS="$CUDALDFLAGS -lmagma"
-      elif test "x$MAGMA_HOME" != "x"; then
-        export MAGMAFLAGS="-DUSE_MAGMA -DMAGMA_ILP64 $CUDAFLAGS -I${MAGMA_HOME}/include"
-	export MAGMALDFLAGS="$CUDALDFLAGS -L${MAGMA_HOME}/lib -lmagma"
-      elif test "x$MAGMA_ROOT" != "x"; then
-        export MAGMAFLAGS="-DUSE_MAGMA -DMAGMA_ILP64 $CUDAFLAGS -I${MAGMA_ROOT}/include"
-	export MAGMALDFLAGS="$CUDALDFLAGS -L${MAGMA_ROOT}/lib -lmagma"
+    if test "x$ENABLE_ILP64" = "xyes"; then
+      # 64-bit indices are enabled
+      MAGMA_ILP64_FLAG="-DMAGMA_ILP64"
+      MAGMA_LD_SPEC="64"
+    else
+      # 64-bit indices are disabled
+      MAGMA_ILP64_FLAG=""
+      MAGMA_LD_SPEC=""
+    fi # end of 64-bit decision tree
+    pkg-config --version > /dev/null
+    use_pkg_config=$?
+    if test "x$use_pkg_config" = "x0"; then
+      # pkg-config is available
+      declare -a pkg_array=$(pkg-config --list-all | grep cudart)
+      for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep cudart > /dev/null
+      result=$?
+      if test "x$result" = "x0"; then
+        # CUDA runtime detected
+        cuda_pkg=$(for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep cudart)
+	CUDAFLAGS=$(pkg-config --cflags ${cuda_pkg})
+	CUDALDFLAGS=$(pkg-config --libs ${cuda_pkg})
+      fi # end of CUDA runtime decision tree
+    else
+      # pkg-config is not available
+      if test -f /usr/local/cuda/include/cuda.h; then
+        CUDAFLAGS="-I/usr/local/cuda/include"
+        CUDALDFLAGS="-L/usr/local/cuda/lib64 -lcudart"
+      elif test -f /usr/include/cuda.h; then
+        CUDAFLAGS="-I/usr/include"
+        CUDALDFLAGS="-lcudart"
+      elif test "x$CUDA_HOME" != "x"; then
+        CUDAFLAGS="-I${CUDA_HOME}/include"
+        CUDALDFLAGS="-L${CUDA_HOME}/lib64 -lcudart"
+      fi
+    fi # end of pkg-config decision tree
+    if test "x${MAGMA_ROOT}${MAGMA_HOME}${MAGMA_DIR}" = "x"; then
+      # MAGMA environment is not defined
+      if "x$use_pkg_config" = "x0"; then
+        # use pkg-config to search for MAGMA
+        declare -a pkg_array=$(pkg-config --list-all | grep magma)
+        for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep magma > /dev/null
+        result=$?
+	if test "x$result" = "x0"; then
+	  # MAGMA was found
+	  magma_pkg=$(for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep magma)
+	  MAGMA_INCLUDE=$(pkg-config --cflags-only-I ${magma_pkg})
+	  MAGMA_LIBS_DIR=$(pkg-config --cflags-only-L ${magma_pkg})
+          export MAGMAFLAGS="-DUSE_MAGMA ${MAGMA_ILP64_FLAG} $CUDAFLAGS ${MAGMA_INCLUDE}"
+          export MAGMALDFLAGS="$CUDALDFLAGS ${MAGMA_LIBS_DIR} -lmagma"
+	fi # end of MAGMA decision tree
+      else
+        # search for MAGMA in some standard folders
+        if test "x$CUDAFLAGS" != "x"; then
+          if test -f /usr/include/magma_v2.h; then
+            export MAGMAFLAGS="-DUSE_MAGMA ${MAGMA_ILP64_FLAG} $CUDAFLAGS -I/usr/include"
+            export MAGMALDFLAGS="$CUDALDFLAGS -lmagma"
+          elif test -f /usr/local/include/magma_v2.h; then
+            export MAGMAFLAGS="-DUSE_MAGMA ${MAGMA_ILP64_FLAG} $CUDAFLAGS -I/usr/local/include"
+            export MAGMALDFLAGS="$CUDALDFLAGS -lmagma"
+          fi
+        fi
+      fi # end of pkg-config decision tree
+    else
+      # MAGMA environment is defined, so configuration makes sure that MAGMA_ROOT is defined too
+      if test "x${MAGMA_HOME}" != "x"; then
+        MAGMA_ROOT="${MAGMA_HOME}"
+      elif test "x${MAGMA_DIR}" != "x"; then
+        MAGMA_ROOT="${MAGMA_DIR}"
       fi
+      export MAGMAFLAGS="-DUSE_MAGMA -DMAGMA_ILP64 $CUDAFLAGS -I${MAGMA_ROOT}/include"
+      export MAGMALDFLAGS="$CUDALDFLAGS -L${MAGMA_ROOT}/lib -lmagma"
     fi
 
 
diff --git a/build/configure.ac b/build/configure.ac
index 7ea86e2fd8c6e01e2ddea97608620aafbc0cac7b..5b30c9aa30f1fd1caf4cd65d69edacd775a41012 100644
--- a/build/configure.ac
+++ b/build/configure.ac
@@ -1,4 +1,62 @@
 # CAPABILITY TESTING MACROS
+m4_define(
+  [M4_DETECT_HDF5],
+  [
+    if test "x${HDF5_INCLUDE}${HDF5_LIB}" = "x"; then
+      pkg-config --version > /dev/null
+      use_pkg_config=$?
+      if test "x$use_pkg_config" = "x0"; then
+        declare -a pkg_array=$(pkg-config --list-all | grep hdf5-serial)
+        for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep hdf5-serial > /dev/null
+        result=$?
+        if test "x$result" = "x0"; then
+          cflags=$(pkg-config --cflags-only-I hdf5-serial)
+          export HDF5_INCLUDE=$(echo "${cflags:2}")
+          ldflags=$(pkg-config --libs-only-L hdf5-serial)
+          export HDF5_LIB=$(echo "${ldflags:2}")
+        else
+          declare -a pkg_array=$(pkg-config --list-all | grep hdf5)
+          for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep hdf5 > /dev/null
+          result=$?
+          if test "x$result" = "x0"; then
+            cflags=$(pkg-config --cflags-only-I hdf5)
+            export HDF5_INCLUDE=$(echo "${cflags:2}")
+            ldflags=$(pkg-config --libs-only-L hdf5)
+            export HDF5_LIB=$(echo "${ldflags:2}")
+          fi
+        fi
+      else
+        export -p | grep HDF5_ROOT > /dev/null
+        result=$?
+        if test "x$result" = "x0"; then
+          if test "x$HDF5_INCLUDE" = "x"; then
+            export HDF5_INCLUDE=${HDF5_ROOT}/include
+          fi
+          if test "x$HDF5_LIB" = "x"; then
+            export HDF5_LIB=${HDF5_ROOT}/lib
+          fi
+        fi
+        export -p | grep HDF5_DIR > /dev/null
+        result=$?
+        if test "x$result" = "x0"; then
+          if test "x$HDF5_INCLUDE" = "x"; then
+            export HDF5_INCLUDE=${HDF5_DIR}/include
+          fi
+          if test "x$HDF5_LIB" = "x"; then
+            export HDF5_LIB=${HDF5_DIR}/lib
+          fi
+        fi
+        if test "x$HDF5_INCLUDE" = "x"; then
+          export HDF5_INCLUDE="/usr/include/hdf5/serial"
+        fi
+        if test "x$HDF5_LIB" = "x"; then
+          export HDF5_LIB="/usr/lib/x86_64-linux-gnu/hdf5/serial"
+        fi
+      fi
+    fi
+  ]
+)
+
 m4_define(
   [M4_HDF5_LIB],
   [
@@ -19,50 +77,70 @@ EOF
   ]
 )
 
-m4_define(
-  [M4_DETECT_HDF5],
-  [
-    export -p | grep HDF5_ROOT > /dev/null
-    result=$?
-    if test "x$result" = "x0"; then
-      if test "x$HDF5_INCLUDE" = "x"; then
-        export HDF5_INCLUDE=${HDF5_ROOT}/include
-      fi
-      if test "x$HDF5_LIB" = "x"; then
-        export HDF5_LIB=${HDF5_ROOT}/lib
-      fi
-    fi
-    export -p | grep HDF5_DIR > /dev/null
-    result=$?
-    if test "x$result" = "x0"; then
-      if test "x$HDF5_INCLUDE" = "x"; then
-        export HDF5_INCLUDE=${HDF5_DIR}/include
-      fi
-      if test "x$HDF5_LIB" = "x"; then
-        export HDF5_LIB=${HDF5_DIR}/lib
-      fi
-    fi
-    if test "x$HDF5_INCLUDE" = "x"; then
-      export HDF5_INCLUDE="/usr/include/hdf5/serial"
-    fi
-    if test "x$HDF5_LIB" = "x"; then
-      export HDF5_LIB="/usr/lib/x86_64-linux-gnu/hdf5/serial"
-    fi
-  ]
-)
-
 m4_define(
   [M4_DETECT_LAPACK],
   [
-    export -p | grep MKL > /dev/null
-    MKL_DEF=$?
-    if test "x$MKL_DEF" = "x0"; then
-      export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL -DLAPACK_ILP64 -DUSE_ILP64 -I{MKLROOT}/include"
-      export LAPACKLDFLAGS="-L${MKLROOT}/lib -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl"
+    if test "x$ENABLE_ILP64" = "xyes"; then
+      # 64-bit indices are enabled
+      LAPACK_ILP64_FLAG="-DLAPACK_ILP64 -DUSE_ILP64"
+      LAPACK_ILP64_LDSPEC="_ilp64"
+      LAPACK_LDSPEC="64"
+      MKL_BUILD="mkl-dynamic-ilp64-gomp"
+    else
+      # 64-bit indices are disabled
+      LAPACK_ILP64_FLAG=""
+      LAPACK_ILP64_LDSPEC="_lp64"
+      LAPACK_LDSPEC=""
+      MKL_BUILD="mkl-dynamic-lp64-gomp"
+    fi # end of 64-bit decision tree
+    pkg-config --version > /dev/null
+    use_pkg_config=$?
+    if test "x$use_pkg_config" = "x0"; then
+      # pkg-config is available
+      declare -a pkg_array=$(pkg-config --list-all | grep ${MKL_BUILD})
+      for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep ${MKL_BUILD} > /dev/null
+      result=$?
+      if test "x$result" = "x0"; then
+        # MKL was found
+        MKL_INCLUDE=$(pkg-config --cflags-only-I ${MKL_BUILD})
+        export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL ${LAPACK_ILP64_FLAG} ${MKL_INCLUDE}"
+        export LAPACKLDFLAGS=$(pkg-config --libs ${MKL_BUILD})
+      else
+        # MKL was not found, so configuration searches for LAPACKe
+        declare -a pkg_array=$(pkg-config --list-all | grep lapacke${LAPACK_LDSPEC})
+        for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep lapacke${LAPACK_LDSPEC} > /dev/null
+        result=$?
+        if test "x$result" = "x0"; then
+          # LAPACKe was found
+          LAPACK_INCLUDE=$(pkg-config --cflags-only-I lapacke${LAPACK_LDSPEC})
+          export LAPACKFLAGS="-DUSE_LAPACK ${LAPACK_ILP64_FLAG} ${LAPACK_INCLUDE}"
+          export LAPACKLDFLAGS=$(pkg-config --libs lapacke${LAPACK_LDSPEC})
+        fi # end of LAPACKe decision tree
+        if test "x${LAPACKFLAGS}${LAPACKLDFLAGS}" = "x"; then
+          # LAPACKe was not found, so configuration searches for LAPACK
+          declare -a pkg_array=$(pkg-config --list-all | grep lapack${LAPACK_LDSPEC})
+          for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep lapack${LAPACK_LDSPEC} > /dev/null
+          result=$?
+          if test "x$result" = "x0"; then
+            # LAPACK was found
+            LAPACK_INCLUDE=$(pkg-config --cflags-only-I lapack${LAPACK_LDSPEC})
+            export LAPACKFLAGS="-DUSE_LAPACK ${LAPACK_ILP64_FLAG} ${LAPACK_INCLUDE}"
+            export LAPACKLDFLAGS=$(pkg-config --libs lapack${LAPACK_LDSPEC})
+          fi # end of LAPACK decision tree
+        fi # end of LAPACKe decision tree
+      fi # end of MKL decision tree
     else
-      if test -f /usr/include/lapacke.h; then
-        export LAPACKFLAGS="-DUSE_LAPACK -DLAPACK_ILP64 -DUSE_ILP64"
-	export LAPACKLDFLAGS="-llapacke64"
+      # pkg-config is not available
+      export -p | grep MKL > /dev/null
+      MKL_DEF=$?
+      if test "x$MKL_DEF" = "x0"; then
+        export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL ${LAPACK_ILP64_FLAG} -I{MKLROOT}/include"
+        export LAPACKLDFLAGS="-L${MKLROOT}/lib -Wl,--no-as-needed -lmkl_intel${LAPACK_ILP64_LDSPEC} -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl"
+      else
+        if test -f /usr/include/lapacke.h; then
+          export LAPACKFLAGS="-DUSE_LAPACK ${LAPACK_ILP64_FLAG}"
+          export LAPACKLDFLAGS="-llapacke${LAPACK_LDSPEC}"
+        fi
       fi
     fi
   ]
@@ -71,30 +149,77 @@ m4_define(
 m4_define(
   [M4_DETECT_MAGMA],
   [
-    if test -f /usr/local/cuda/include/cuda.h; then
-      CUDAFLAGS="-I/usr/local/cuda/include"
-      CUDALDFLAGS="-L/usr/local/cuda/lib64 -lcudart"
-    elif test -f /usr/include/cuda.h; then
-      CUDAFLAGS="-I/usr/include"
-      CUDALDFLAGS="-lcudart"
-    elif test "x$CUDA_HOME" != "x"; then
-      CUDAFLAGS="-I${CUDA_HOME}/include"
-      CUDALDFLAGS="-L${CUDA_HOME}/lib64 -lcudart"
-    fi
-    if test "x$CUDAFLAGS" != "x"; then
-      if test -f /usr/include/magma_v2.h; then
-        export MAGMAFLAGS="-DUSE_MAGMA -DMAGMA_ILP64 $CUDAFLAGS -I/usr/include"
-	export MAGMALDFLAGS="$CUDALDFLAGS -lmagma"
-      elif test -f /usr/local/include/magma_v2.h; then
-        export MAGMAFLAGS="-DUSE_MAGMA -DMAGMA_ILP64 $CUDAFLAGS -I/usr/local/include"
-	export MAGMALDFLAGS="$CUDALDFLAGS -lmagma"
-      elif test "x$MAGMA_HOME" != "x"; then
-        export MAGMAFLAGS="-DUSE_MAGMA -DMAGMA_ILP64 $CUDAFLAGS -I${MAGMA_HOME}/include"
-	export MAGMALDFLAGS="$CUDALDFLAGS -L${MAGMA_HOME}/lib -lmagma"
-      elif test "x$MAGMA_ROOT" != "x"; then
-        export MAGMAFLAGS="-DUSE_MAGMA -DMAGMA_ILP64 $CUDAFLAGS -I${MAGMA_ROOT}/include"
-	export MAGMALDFLAGS="$CUDALDFLAGS -L${MAGMA_ROOT}/lib -lmagma"
+    if test "x$ENABLE_ILP64" = "xyes"; then
+      # 64-bit indices are enabled
+      MAGMA_ILP64_FLAG="-DMAGMA_ILP64"
+      MAGMA_LD_SPEC="64"
+    else
+      # 64-bit indices are disabled
+      MAGMA_ILP64_FLAG=""
+      MAGMA_LD_SPEC=""
+    fi # end of 64-bit decision tree
+    pkg-config --version > /dev/null
+    use_pkg_config=$?
+    if test "x$use_pkg_config" = "x0"; then
+      # pkg-config is available
+      declare -a pkg_array=$(pkg-config --list-all | grep cudart)
+      for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep cudart > /dev/null
+      result=$?
+      if test "x$result" = "x0"; then
+        # CUDA runtime detected
+        cuda_pkg=$(for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep cudart)
+	CUDAFLAGS=$(pkg-config --cflags ${cuda_pkg})
+	CUDALDFLAGS=$(pkg-config --libs ${cuda_pkg})
+      fi # end of CUDA runtime decision tree
+    else
+      # pkg-config is not available
+      if test -f /usr/local/cuda/include/cuda.h; then
+        CUDAFLAGS="-I/usr/local/cuda/include"
+        CUDALDFLAGS="-L/usr/local/cuda/lib64 -lcudart"
+      elif test -f /usr/include/cuda.h; then
+        CUDAFLAGS="-I/usr/include"
+        CUDALDFLAGS="-lcudart"
+      elif test "x$CUDA_HOME" != "x"; then
+        CUDAFLAGS="-I${CUDA_HOME}/include"
+        CUDALDFLAGS="-L${CUDA_HOME}/lib64 -lcudart"
       fi
+    fi # end of pkg-config decision tree
+    if test "x${MAGMA_ROOT}${MAGMA_HOME}${MAGMA_DIR}" = "x"; then
+      # MAGMA environment is not defined
+      if "x$use_pkg_config" = "x0"; then
+        # use pkg-config to search for MAGMA
+        declare -a pkg_array=$(pkg-config --list-all | grep magma)
+        for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep magma > /dev/null
+        result=$?
+	if test "x$result" = "x0"; then
+	  # MAGMA was found
+	  magma_pkg=$(for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep magma)
+	  MAGMA_INCLUDE=$(pkg-config --cflags-only-I ${magma_pkg})
+	  MAGMA_LIBS_DIR=$(pkg-config --cflags-only-L ${magma_pkg})
+          export MAGMAFLAGS="-DUSE_MAGMA ${MAGMA_ILP64_FLAG} $CUDAFLAGS ${MAGMA_INCLUDE}"
+          export MAGMALDFLAGS="$CUDALDFLAGS ${MAGMA_LIBS_DIR} -lmagma"
+	fi # end of MAGMA decision tree
+      else
+        # search for MAGMA in some standard folders
+        if test "x$CUDAFLAGS" != "x"; then
+          if test -f /usr/include/magma_v2.h; then
+            export MAGMAFLAGS="-DUSE_MAGMA ${MAGMA_ILP64_FLAG} $CUDAFLAGS -I/usr/include"
+            export MAGMALDFLAGS="$CUDALDFLAGS -lmagma"
+          elif test -f /usr/local/include/magma_v2.h; then
+            export MAGMAFLAGS="-DUSE_MAGMA ${MAGMA_ILP64_FLAG} $CUDAFLAGS -I/usr/local/include"
+            export MAGMALDFLAGS="$CUDALDFLAGS -lmagma"
+          fi
+        fi
+      fi # end of pkg-config decision tree
+    else
+      # MAGMA environment is defined, so configuration makes sure that MAGMA_ROOT is defined too
+      if test "x${MAGMA_HOME}" != "x"; then
+        MAGMA_ROOT="${MAGMA_HOME}"
+      elif test "x${MAGMA_DIR}" != "x"; then
+        MAGMA_ROOT="${MAGMA_DIR}"
+      fi
+      export MAGMAFLAGS="-DUSE_MAGMA -DMAGMA_ILP64 $CUDAFLAGS -I${MAGMA_ROOT}/include"
+      export MAGMALDFLAGS="$CUDALDFLAGS -L${MAGMA_ROOT}/lib -lmagma"
     fi
   ]
 )
@@ -199,7 +324,7 @@ AC_ARG_ENABLE(
         fi
       else
         # Test if given CXX defines mpi.h
-	M4_TEST_MPI
+        M4_TEST_MPI
       fi
     elif test "x$enableval" = "xyes"; then
       if test "x$CXX" = "x"; then
@@ -211,10 +336,10 @@ AC_ARG_ENABLE(
         fi
       else
         # Test if given CXX defines mpi.h
-	M4_TEST_MPI
-	if test "x$CXX_IS_MPI" != "x0"; then
+        M4_TEST_MPI
+        if test "x$CXX_IS_MPI" != "x0"; then
           AC_MSG_ERROR([MPI was requested, but $CXX is not a MPI compiler!])
-	fi
+        fi
       fi
     fi
   ],
@@ -253,27 +378,41 @@ LT_INIT
 # Environment setup
 M4_DETECT_HDF5
 
-# Check for required headers
-# AC_CHECK_HEADER(
-#  [${HDF5_INCLUDE}/hdf5.h],
-#  ,
-#  AC_MSG_ERROR([Could not find HDF5 headers!]),
-# )
 AS_IF(
-  [test -f ${HDF5_INCLUDE}/hdf5.h],
+  [test "x${HDF5_INCLUDE}" != "x"],
   [AC_MSG_NOTICE([HDF5 headers found in ${HDF5_INCLUDE}])],
   [AC_MSG_ERROR([HDF5 headers not found!])]
 )
+AS_IF(
+  [test "x${HDF5_LIB}" != "x"],
+  [AC_MSG_NOTICE([HDF5 libraries found in ${HDF5_LIB}])],
+  [AC_MSG_ERROR([HDF5 libraries not found!])]
+)
 
 # Check for required libraries
 M4_HDF5_LIB
 AS_IF(
   [test "x$TEST_HDF5_LIB" = "x0"],
   [AC_SUBST([HDF5_LDFLAGS], ["-L${HDF5_LIB} -lhdf5"])],
-  [AC_MSG_ERROR(["HDF5 library not found!"])]
+  [AC_MSG_ERROR(["HDF5 library not working!"])]
 )
 
 # Configure the optional features
+AC_ARG_ENABLE(
+  [ilp64],
+  [AS_HELP_STRING([--enable-ilp64], [enable 64-bit indexing [default=yes]])],
+  [
+    if test "x$enableval" = "xno"; then
+      AC_SUBST([ENABLE_ILP64], [""])
+    else
+      AC_SUBST([ENABLE_ILP64], ["yes"])
+    fi
+  ],
+  [
+    AC_SUBST([ENABLE_ILP64], ["yes"])
+  ]
+)
+
 AC_ARG_ENABLE(
   [fortran],
   [AS_HELP_STRING([--enable-fortran], [enable legacy FORTRAN compilation [default=auto]])],
@@ -403,14 +542,16 @@ AC_ARG_WITH(
 
 AC_ARG_WITH(
   [magma],
-  [AS_HELP_STRING([--with-magma], [use MAGMA @<:@default=auto@:>@])],
+  [AS_HELP_STRING([--with-magma[[=MAGMA_DIR]]], [use MAGMA @<:@default=auto@:>@])],
   [
     if test "x$withval" = "xno"; then
       AC_SUBST([MAGMAFLAGS], [""])
       AC_SUBST([MAGMALDFLAGS], [""])
     else
-      if test "x$withval" != "xyes" and "x$withval" != "xauto"; then
-        export MAGMA_HOME=$withval
+      if test "x$withval" != "xyes"; then
+        if test "x$withval" != "xauto"; then
+          export MAGMA_HOME=$withval
+	fi
       fi
       M4_DETECT_MAGMA
       AS_IF(