From 8d0016f00e01f2686c6dccc4579d46304d58406b Mon Sep 17 00:00:00 2001
From: Giovanni Bussi <giovanni.bussi@gmail.com>
Date: Fri, 20 Dec 2013 18:39:25 +0100
Subject: [PATCH] Added search for lapack/blas

---
 autoconf/configure    | 25 ++++++++++++++++++-------
 autoconf/configure.ac | 26 +++++++++++++++++++-------
 2 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/autoconf/configure b/autoconf/configure
index 7f2435358..934f2f1de 100755
--- a/autoconf/configure
+++ b/autoconf/configure
@@ -4431,10 +4431,12 @@ else
 fi
 
 
+save_LIBS="$LIBS"
 # Then check for blas. This is a bit complicated because we want to allow
 # either the version with underscore or the one without
 # If they are not found in the normal search path, we repeat the search with -lblas
 blas_found=
+lapack_found=
 ac_fn_cxx_check_func "$LINENO" "dgemv" "ac_cv_func_dgemv"
 if test "x$ac_cv_func_dgemv" = xyes; then :
   blas_found=nounderscore
@@ -4523,9 +4525,6 @@ fi
 $as_echo "$ac_cv_lib_blas_dgemv_" >&6; }
 if test "x$ac_cv_lib_blas_dgemv_" = xyes; then :
   LIBS="-lblas $LIBS" blas_found=underscore
-else
-
-  as_fn_error $? "blas not found - please set your LDFLAGS and LIBS so that they can be found" "$LINENO" 5
 
 fi
 
@@ -4536,12 +4535,12 @@ fi
 fi
 
 
+if test -n "$blas_found" ; then
 # Then we look for lapack using same underscoring
 case "$blas_found" in
 (underscore) search_for=dsyevr_ ;;
 (nounderscore) search_for=dsyevr ;;
 esac
-
 as_ac_var=`$as_echo "ac_cv_func_$search_for" | $as_tr_sh`
 ac_fn_cxx_check_func "$LINENO" "$search_for" "$as_ac_var"
 if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
@@ -4587,16 +4586,28 @@ eval ac_res=\$$as_ac_Lib
 	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
 $as_echo "$ac_res" >&6; }
 if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
-  LIBS="-llapack $LIBS"
-else
+  LIBS="-llapack $LIBS" lapack_found=yes
+
+fi
 
-  as_fn_error $? "lapack not found - please set your LDFLAGS and LIBS so that they can be found" "$LINENO" 5
 
 fi
 
+fi
+
+if test -z "$lapack_found" ; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: lapack/blas not found, reverting to internal ones" >&5
+$as_echo "$as_me: WARNING: lapack/blas not found, reverting to internal ones" >&2;}
+LIBS="$save_LIBS"
+
+$as_echo "#define __PLUMED_INTERNAL_LAPACK 1" >>confdefs.h
+
+$as_echo "#define __PLUMED_INTERNAL_BLAS 1" >>confdefs.h
+
 
 fi
 
+
 #### End of compulsory libraries ####
 
 
diff --git a/autoconf/configure.ac b/autoconf/configure.ac
index 758aa2e12..35fbfd4b4 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -129,28 +129,40 @@ AC_CHECK_FUNC(  [gettimeofday], [ ], [AC_MSG_ERROR([compulsory function not foun
 AC_CHECK_HEADER([dirent.h],     [ ], [AC_MSG_ERROR([compulsory header not found])] )
 AC_CHECK_FUNC(  [readdir],      [ ], [AC_MSG_ERROR([compulsory function not found])] )
 
+save_LIBS="$LIBS"
 # Then check for blas. This is a bit complicated because we want to allow
 # either the version with underscore or the one without
 # If they are not found in the normal search path, we repeat the search with -lblas
 blas_found=
+lapack_found=
 AC_CHECK_FUNC(  [dgemv], [blas_found=nounderscore], [
 AC_CHECK_FUNC(  [dgemv_],[blas_found=underscore],   [
 AC_CHECK_LIB(   [blas],[dgemv],  [LIBS="-lblas $LIBS"] [blas_found=nounderscore], [
-AC_CHECK_LIB(   [blas],[dgemv_], [LIBS="-lblas $LIBS"] [blas_found=underscore], [
-  AC_MSG_ERROR([blas not found - please set your LDFLAGS and LIBS so that they can be found])
-]) ]) ]) ])
+AC_CHECK_LIB(   [blas],[dgemv_], [LIBS="-lblas $LIBS"] [blas_found=underscore]
+) ]) ]) ])
 
+if test -n "$blas_found" ; then
 # Then we look for lapack using same underscoring
 case "$blas_found" in
 (underscore) search_for=dsyevr_ ;;
 (nounderscore) search_for=dsyevr ;;
 esac
-
 AC_CHECK_FUNC( [$search_for], [lapack_found=$blas_found], [
-AC_CHECK_LIB(  [lapack],[$search_for], [LIBS="-llapack $LIBS"], [
-  AC_MSG_ERROR([lapack not found - please set your LDFLAGS and LIBS so that they can be found])
-])
+AC_CHECK_LIB(  [lapack],[$search_for], [LIBS="-llapack $LIBS"] [lapack_found=yes]
+)
 ])
+fi
+
+if test -z "$lapack_found" ; then
+AC_MSG_WARN([lapack/blas not found, reverting to internal ones])
+LIBS="$save_LIBS"
+
+AC_DEFINE([__PLUMED_INTERNAL_LAPACK])
+AC_DEFINE([__PLUMED_INTERNAL_BLAS])
+
+fi
+
+
 #### End of compulsory libraries ####
 
 
-- 
GitLab