diff --git a/Geo/GFace.cpp b/Geo/GFace.cpp
index 428296164b884eec45c24062e5ce8b97c9121c63..e001d89afe26d965a914c3e63e55fafc91f48e87 100644
--- a/Geo/GFace.cpp
+++ b/Geo/GFace.cpp
@@ -421,9 +421,9 @@ end:
         meanPlane.c * v->z() - meanPlane.d;
       if(fabs(d) > lc * 1.e-3) {
         Msg::Error("Plane surface %d (%gx+%gy+%gz+%g=0) is not plane!",
-            tag(), meanPlane.a, meanPlane.b, meanPlane.c, meanPlane.d);
+                   tag(), meanPlane.a, meanPlane.b, meanPlane.c, meanPlane.d);
         Msg::Error("Control point %d = (%g,%g,%g), val=%g",
-            v->tag(), v->x(), v->y(), v->z(), d);
+                   v->tag(), v->x(), v->y(), v->z(), d);
         return;
       }
     }
diff --git a/Numeric/FunctionSpace.cpp b/Numeric/FunctionSpace.cpp
index 79d67fe3dbf9801dff7ce863f92616213ce42480..7b08bb0d53372c68fff0fd4933bc7ffc305320c6 100644
--- a/Numeric/FunctionSpace.cpp
+++ b/Numeric/FunctionSpace.cpp
@@ -131,7 +131,7 @@ Double_Matrix generatePascalSerendipityTetrahedron(int order)
   Double_Matrix monomialsMaxOrder = generateMonomialSubspace(3, order);
   int nbMaxOrder = monomialsMaxOrder.size1();
     
-  Double_Matrix(monomials.touchSubmatrix(index, nbMaxOrder, 0, 3)).memcpy(monomialsMaxOrder);
+  monomials.submatrix(index, nbMaxOrder, 0, 3).memcpy(monomialsMaxOrder);
   return monomials;
 }
 
@@ -147,7 +147,7 @@ Double_Matrix generatePascalTetrahedron(int order)
   for (int p = 0; p <= order; p++) {
     Double_Matrix monOrder = generateMonomialSubspace(3, p);
     int nb = monOrder.size1();
-    Double_Matrix(monomials.touchSubmatrix(index, nb, 0, 3)).memcpy(monOrder);
+    monomials.submatrix(index, nb, 0, 3).memcpy(monOrder);
     index += nb;
   }
 
@@ -511,7 +511,7 @@ Double_Matrix gmshGeneratePointsTriangle(int order, bool serendip)
         Double_Matrix inner = gmshGeneratePointsTriangle(order - 3, serendip);
         inner.scale(1. - 3. * dd);
         inner.add(dd);
-        Double_Matrix(point.touchSubmatrix(index, nbPoints - index, 0, 2)).memcpy(inner);
+        point.submatrix(index, nbPoints - index, 0, 2).memcpy(inner);
       }
     }
   }
@@ -527,10 +527,9 @@ Double_Matrix generateLagrangeMonomialCoefficients(const Double_Matrix& monomial
   }
   
   int ndofs = monomial.size1();
-  int dim   = monomial.size2();
+  int dim = monomial.size2();
   
   Double_Matrix Vandermonde(ndofs, ndofs);
-  
   for (int i = 0; i < ndofs; i++) {
     for (int j = 0; j < ndofs; j++) {
       double dd = 1.;
@@ -538,21 +537,14 @@ Double_Matrix generateLagrangeMonomialCoefficients(const Double_Matrix& monomial
       Vandermonde(i, j) = dd;
     }
   }
-  
-  // check for independence
-
 
   double det = Vandermonde.determinant();
 
-  //  printf("coucou2 %g\n",det);
-
-  if (det == 0.0){
+  if (det == 0.){
     Msg::Fatal("Vandermonde matrix has zero determinant!?");
     return Double_Matrix(1, 1);
   }
-
   Double_Matrix coefficient(ndofs, ndofs);
-  
   for (int i = 0; i < ndofs; i++) {
     for (int j = 0; j < ndofs; j++) {
       int f = (i + j) % 2 == 0 ? 1 : -1;
@@ -560,20 +552,6 @@ Double_Matrix generateLagrangeMonomialCoefficients(const Double_Matrix& monomial
       coefficient(i, j) = f * cofactor.determinant() / det;
     }
   }
-  //  printf("coucou3 %g\n",det);
-
-
-  Vandermonde.set_all(0.);
-  
-  for (int i = 0; i < ndofs; i++) {
-    for (int j = 0; j < ndofs; j++) {
-      double dd = 1.;
-      for (int k = 0; k < dim; k++) dd *= pow(point(i, k), monomial(j, k));
-      for (int k = 0; k < ndofs; k++) {
-        Vandermonde(i, k) += coefficient(k, j) * dd;
-      }
-    }
-  }
   return coefficient;
 }
 
diff --git a/Numeric/GmshMatrix.h b/Numeric/GmshMatrix.h
index 7922f6a041a2580b510cfbc8cddea52e988d4266..e7894d1618ff64877a4bfd96e92dae1e424be6a1 100644
--- a/Numeric/GmshMatrix.h
+++ b/Numeric/GmshMatrix.h
@@ -79,23 +79,24 @@ class Gmsh_Matrix
       b[i] = sum / (*this)(i, i);
     }
   }
-  bool _lu_decomposition(int *indx , SCALAR &determinant)
+  bool _lu_decomposition(int *indx, SCALAR &determinant)
   {
     if(_r != _c) 
-      Msg::Fatal("Cannot compute lu factorization of non-square matrix");
+      Msg::Fatal("Cannot LU factorize non-square matrix");
     int i, imax, j, k;
     SCALAR big, dum, sum, temp;
     SCALAR *vv = new SCALAR[_c];    
-    determinant = 1.0;
+    determinant = 1.;
     for(i = 0; i < _c; i++){
       big = 0.;
       for(j = 0; j < _c; j++)
 	if((temp = fabs((*this)(i, j))) > big) big = temp;
       if(big == 0.) {
+        delete [] vv;
+        Msg::Error("Zero pivot in LU factorization");
 	return false;
-	big = 1.e-12;
       }      
-      vv[i] = 1.0 / big;
+      vv[i] = 1. / big;
     }
     for(j = 0; j < _c; j++){
       for(i = 0; i < j; i++){
@@ -126,7 +127,7 @@ class Gmsh_Matrix
       indx[j] = imax;
       if((*this)(j, j) == 0.) (*this)(j, j) = 1.e-20;
       if(j != _c){
-	dum = 1.0 / ((*this)(j, j));
+	dum = 1. / ((*this)(j, j));
 	for(i = j + 1; i < _c; i++) (*this)(i, j) *= dum;
       }
     }
@@ -179,7 +180,7 @@ class Gmsh_Matrix
 	  c._data[i + _r * j] += (*this)(i, k) * b(k, j);
   }
   inline void blas_dgemm(const Gmsh_Matrix<SCALAR> &b, Gmsh_Matrix<SCALAR> &c, 
-			 const SCALAR alpha=1.0, const SCALAR beta=1.0)
+			 const SCALAR alpha=1., const SCALAR beta=1.)
   {
     Gmsh_Matrix<SCALAR> temp(b.size1(), c.size2());
     temp.mult(b, c);
@@ -191,15 +192,40 @@ class Gmsh_Matrix
   {
     for(int i = 0; i < _r * _c; i++) _data[i] = m;
   }
-  inline void lu_solve(const Gmsh_Vector<SCALAR> &rhs, Gmsh_Vector<SCALAR> &result)
+  inline bool lu_solve(const Gmsh_Vector<SCALAR> &rhs, Gmsh_Vector<SCALAR> &result)
   {
     int *indx = new int[_c];
     SCALAR d;
-    if(!_lu_decomposition(indx, d))
-      Msg::Fatal("LU fatorization failed (singular matrix)");
+    if(!_lu_decomposition(indx, d)){
+      delete [] indx;
+      return false;
+    }
     for(int i = 0; i < _c; i++) result(i) = rhs(i);
     _back_substitution(indx, result._data);
     delete [] indx; 
+    return true;
+  }
+  inline bool invert()
+  {
+    Gmsh_Matrix y(_r, _c);
+    SCALAR *col = new SCALAR[_c];
+    int *indx = new int[_c];
+    SCALAR d;
+    if (!_lu_decomposition(indx, d)){
+      delete [] col;
+      delete [] indx;
+      return false;
+    }
+    for(int j = 0; j < _c; j++){
+      for(int i = 0; i < _c; i++) col[i] = 0.0;
+      col[j] = 1.0;
+      _back_substitution(indx, col);
+      for(int i = 0; i < _c; i++) y(i, j) = col[i];
+    }
+    (*this) = y;
+    delete [] col;
+    delete [] indx;
+    return true;
   }
   Gmsh_Matrix<SCALAR> cofactor(int i, int j) const 
   {
@@ -221,10 +247,10 @@ class Gmsh_Matrix
       for(int j = 0; j < _c; j++)
 	y._data[i] += (*this)(i, j) * x(j);
   }
-  SCALAR determinant() const 
+  SCALAR determinant() const
   {
     Gmsh_Matrix<SCALAR> copy = *this;
-    SCALAR factor = 1.0;
+    SCALAR factor = 1.;
     int *indx = new int[_c];
     if(!copy._lu_decomposition(indx, factor)) return 0.;
     SCALAR det = factor;
@@ -232,9 +258,9 @@ class Gmsh_Matrix
     delete [] indx;
     return det;
   }
-  inline Gmsh_Matrix<SCALAR> touchSubmatrix(int i0, int ni, int j0, int nj) 
+  inline Gmsh_Matrix<SCALAR> submatrix(int i0, int ni, int j0, int nj)  const
   {
-    Msg::Fatal("Gmsh_Matrix::touchSubmatrix is not implemented");
+    Msg::Fatal("submatrix not implemented yet for Gmsh_Matrix");
     Gmsh_Matrix<SCALAR> subm(ni, nj);
     return subm;
   }  
@@ -308,12 +334,7 @@ class GSL_Matrix
  private:
   gsl_matrix_view _view;
   gsl_matrix *_data;
-  inline const gsl_matrix_view _see_submatrix(int i0, int ni, int j0, int nj) const
-  {
-    return gsl_matrix_submatrix(_data, i0, j0, ni, nj);
-  }
  public:
-  GSL_Matrix(gsl_matrix_view view) : _view(view), _data(&_view.matrix) {}
   GSL_Matrix(int r, int  c) { _data = gsl_matrix_calloc(r, c); }
   GSL_Matrix(const GSL_Matrix &other) : _data(0)
   {
@@ -321,6 +342,7 @@ class GSL_Matrix
     _data = gsl_matrix_calloc(other._data->size1, other._data->size2);
     gsl_matrix_memcpy(_data, other._data);
   }
+  GSL_Matrix(gsl_matrix_view view) : _view(view), _data(&_view.matrix) {}
   GSL_Matrix() : _data(0) {}
   ~GSL_Matrix() { if(_data && _data->owner == 1) gsl_matrix_free(_data); }
   inline int size1() const { return _data->size1; }
@@ -351,7 +373,7 @@ class GSL_Matrix
     gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1., _data, b._data, 0., c._data);
   }
   inline void blas_dgemm(const GSL_Matrix &x, GSL_Matrix &b, 
-			 const double alpha = 1.0, const double beta = 1.0)
+			 const double alpha=1., const double beta=1.)
   {      
     gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, alpha, x._data, b._data, beta, _data);
   }
@@ -359,13 +381,26 @@ class GSL_Matrix
   {
     gsl_matrix_set_all(_data, m);
   }
-  inline void lu_solve(const GSL_Vector &rhs, GSL_Vector &result)
+  inline bool lu_solve(const GSL_Vector &rhs, GSL_Vector &result)
   {
     int s;
     gsl_permutation * p = gsl_permutation_alloc(size1());
     gsl_linalg_LU_decomp(_data, p, &s);
     gsl_linalg_LU_solve(_data, p, rhs._data, result._data);
     gsl_permutation_free(p);
+    return true;
+  }
+  inline bool invert()
+  {
+    int s;
+    gsl_permutation *p = gsl_permutation_alloc(size1());
+    gsl_linalg_LU_decomp(_data, p, &s);
+    gsl_matrix *inv = gsl_matrix_calloc(size1(), size2());
+    gsl_linalg_LU_invert(_data, p, inv) ;
+    gsl_matrix_memcpy(_data, inv);
+    gsl_matrix_free(inv);
+    gsl_permutation_free(p);
+    return true;
   }
   GSL_Matrix cofactor(int i, int j) const 
   {
@@ -374,19 +409,19 @@ class GSL_Matrix
     GSL_Matrix cof(ni - 1, nj - 1);
     if(i > 0) {
       if(j > 0)
-        GSL_Matrix(cof.touchSubmatrix(0, i , 0, j)).
-          memcpy(GSL_Matrix(_see_submatrix(0, i, 0, j)));
+        cof.submatrix(0, i, 0, j).
+          memcpy(submatrix(0, i, 0, j));
       if(j < nj - 1)
-        GSL_Matrix(cof.touchSubmatrix(0, i, j, nj - j - 1)).
-          memcpy(GSL_Matrix(_see_submatrix(0, i, j + 1,nj - j - 1)));
+        cof.submatrix(0, i, j, nj - j - 1).
+          memcpy(submatrix(0, i, j + 1, nj - j - 1));
     }
     if(i < ni - 1) {  
       if(j < nj - 1)
-        GSL_Matrix(cof.touchSubmatrix(i, ni - i - 1, j, nj - j - 1)).
-          memcpy(GSL_Matrix(_see_submatrix(i + 1, ni - i - 1, j + 1, nj - j - 1)));
+        cof.submatrix(i, ni - i - 1, j, nj - j - 1).
+          memcpy(submatrix(i + 1, ni - i - 1, j + 1, nj - j - 1));
       if(j > 0)
-        GSL_Matrix(cof.touchSubmatrix(i, ni - i - 1, 0, j)).
-          memcpy(GSL_Matrix(_see_submatrix(i + 1, ni - i - 1, 0, j)));
+        cof.submatrix(i, ni - i - 1, 0, j).
+          memcpy(submatrix(i + 1, ni - i - 1, 0, j));
     }
     return cof;
   }
@@ -403,9 +438,9 @@ class GSL_Matrix
     gsl_permutation_free(p);
     return gsl_linalg_LU_det(copy._data, s);
   } 
-  inline gsl_matrix_view touchSubmatrix(int i0, int ni, int j0, int nj) 
+  inline GSL_Matrix submatrix(int i0, int ni, int j0, int nj) const
   {
-    return gsl_matrix_submatrix(_data, i0, j0, ni, nj);
+    return GSL_Matrix(gsl_matrix_submatrix(_data, i0, j0, ni, nj));
   }  
   inline void scale(const double s) 
   {
diff --git a/configure b/configure
index 757fe2c09954627145f76f3e0cca9cd59fd1317b..cb2a8f1277dea5155584608bb90bd32b4f19dfd4 100755
--- a/configure
+++ b/configure
@@ -1316,8 +1316,7 @@ Optional Packages:
   --with-mpi-prefix=PFX   prefix where MPI is installed
   --with-fftw3-prefix=PFX prefix where FFTW3 is installed
   --with-fm-prefix=PFX    prefix where FourierModel is installed
-  --with-blas-lapack-prefix=PFX
-                          prefix where BLAS and LAPACK are installed
+  --with-blas-prefix=PFX  prefix where BLAS (and LAPACK) are installed
 
 Some influential environment variables:
   CC          C compiler command
@@ -1842,9 +1841,9 @@ if test "${with_fm_prefix+set}" = set; then
 fi
 
 
-# Check whether --with-blas-lapack-prefix was given.
-if test "${with_blas_lapack_prefix+set}" = set; then
-  withval=$with_blas_lapack_prefix; BLAS_LAPACK_PREFIX=$withval
+# Check whether --with-blas-prefix was given.
+if test "${with_blas_prefix+set}" = set; then
+  withval=$with_blas_prefix; BLAS_PREFIX=$withval
 fi
 
 
@@ -3740,7 +3739,6 @@ done
 done
 IFS=$as_save_IFS
 
-  test -z "$ac_cv_path_FLTKCONFIG" && ac_cv_path_FLTKCONFIG=""""
   ;;
 esac
 fi
@@ -3866,8 +3864,6 @@ fi
 echo "${ECHO_T}$ac_cv_lib_OSMesa_main" >&6; }
 if test $ac_cv_lib_OSMesa_main = yes; then
   OSMESA="yes"
-else
-  OSMESA="no"
 fi
 
   fi
@@ -3891,8 +3887,6 @@ fi
 echo "${ECHO_T}$ac_cv_file___contrib_NativeFileChooser_Fl_Native_File_Chooser_cxx" >&6; }
 if test $ac_cv_file___contrib_NativeFileChooser_Fl_Native_File_Chooser_cxx = yes; then
   NATIVE="yes"
-else
-  NATIVE="no"
 fi
 
   if test "x${NATIVE}" = "xyes"; then
@@ -3925,11 +3919,8 @@ fi
     fi
   fi
 
-  FL_JPEG=""
   expr "x${GMSH_LIBS}" : 'x.*fltk_jpeg.*' >/dev/null && FL_JPEG="yes"
-  FL_PNG=""
   expr "x${GMSH_LIBS}" : 'x.*fltk_png.*' >/dev/null && FL_PNG="yes"
-  FL_ZLIB=""
   expr "x${GMSH_LIBS}" : 'x.*fltk_z.*' >/dev/null && FL_ZLIB="yes"
 
     if test "x$enable_jpeg" != "xno"; then
@@ -3996,8 +3987,6 @@ fi
 echo "${ECHO_T}$ac_cv_lib_jpeg_main" >&6; }
 if test $ac_cv_lib_jpeg_main = yes; then
   JPEG="yes"
-else
-  JPEG="no"
 fi
 
       if test "x${JPEG}" = "xyes"; then
@@ -4012,8 +4001,7 @@ fi
     fi
   fi
 
-    ZLIB=""
-  if test "x$enable_zlib" != "xno"; then
+    if test "x$enable_zlib" != "xno"; then
         if test "x${FL_ZLIB}" = "xyes"; then
       ZLIB="yes"
     else
@@ -4077,8 +4065,6 @@ fi
 echo "${ECHO_T}$ac_cv_lib_z_main" >&6; }
 if test $ac_cv_lib_z_main = yes; then
   ZLIB="yes"
-else
-  ZLIB="no"
 fi
 
     fi
@@ -4148,8 +4134,6 @@ fi
 echo "${ECHO_T}$ac_cv_lib_png_main" >&6; }
 if test $ac_cv_lib_png_main = yes; then
   PNG="yes"
-else
-  PNG="no"
 fi
 
       if test "x${PNG}" = "xyes"; then
@@ -4186,8 +4170,7 @@ else
     GMSH_DIRS="${GMSH_DIRS} Numeric"
   GMSH_LIBS="${GMSH_LIBS} -lGmshCommon -lGmshNumeric"
 
-    ZLIB=""
-  if test "x$enable_zlib" != "xno"; then
+    if test "x$enable_zlib" != "xno"; then
     if test "x${ZLIB_PREFIX}" != "x"; then
       LDFLAGS="-L${ZLIB_PREFIX} -L${ZLIB_PREFIX}/lib ${LDFLAGS}"
     fi
@@ -4248,8 +4231,6 @@ fi
 echo "${ECHO_T}$ac_cv_lib_z_main" >&6; }
 if test $ac_cv_lib_z_main = yes; then
   ZLIB="yes"
-else
-  ZLIB="no"
 fi
 
   fi
@@ -4475,8 +4456,6 @@ fi
 echo "${ECHO_T}$ac_cv_file___contrib_ANN_include_ANN_ANN_h" >&6; }
 if test $ac_cv_file___contrib_ANN_include_ANN_ANN_h = yes; then
   ANN="yes"
-else
-  ANN="no"
 fi
 
     if test "x${ANN}" = "xyes"; then
@@ -4513,8 +4492,6 @@ fi
 echo "${ECHO_T}$ac_cv_file___contrib_gmm_gmm_h" >&6; }
 if test $ac_cv_file___contrib_gmm_gmm_h = yes; then
   GMM="yes"
-else
-  GMM="no"
 fi
 
     if test "x${GMM}" = "xyes"; then
@@ -4548,8 +4525,6 @@ fi
 echo "${ECHO_T}$ac_cv_file___contrib_Chaco_main_interface_c" >&6; }
 if test $ac_cv_file___contrib_Chaco_main_interface_c = yes; then
   CHACO="yes"
-else
-  CHACO="no"
 fi
 
     if test "x${CHACO}" = "xyes"; then
@@ -4585,8 +4560,6 @@ fi
 echo "${ECHO_T}$ac_cv_file___contrib_Metis_metis_h" >&6; }
 if test $ac_cv_file___contrib_Metis_metis_h = yes; then
   METIS="yes"
-else
-  METIS="no"
 fi
 
     if test "x${METIS}" = "xyes"; then
@@ -4624,8 +4597,6 @@ fi
 echo "${ECHO_T}$ac_cv_file___contrib_Netgen_libsrc_meshing_meshclass_cpp" >&6; }
 if test $ac_cv_file___contrib_Netgen_libsrc_meshing_meshclass_cpp = yes; then
   NETGEN="yes"
-else
-  NETGEN="no"
 fi
 
     if test "x${NETGEN}" = "xyes"; then
@@ -4661,8 +4632,6 @@ fi
 echo "${ECHO_T}$ac_cv_file___contrib_Tetgen_tetgen_h" >&6; }
 if test $ac_cv_file___contrib_Tetgen_tetgen_h = yes; then
   TETGEN="yes"
-else
-  TETGEN="no"
 fi
 
     if test "x${TETGEN}" = "xyes"; then
@@ -4700,8 +4669,6 @@ fi
 echo "${ECHO_T}$ac_cv_file___contrib_MathEval_matheval_cpp" >&6; }
 if test $ac_cv_file___contrib_MathEval_matheval_cpp = yes; then
   MATHEVAL="yes"
-else
-  MATHEVAL="no"
 fi
 
     if test "x${MATHEVAL}" = "xyes"; then
@@ -4785,8 +4752,6 @@ fi
 echo "${ECHO_T}$ac_cv_lib_TKernel_main" >&6; }
 if test $ac_cv_lib_TKernel_main = yes; then
   OCC="yes"
-else
-  OCC="no"
 fi
 
   if test "x${OCC}" = "xyes"; then
@@ -4832,8 +4797,6 @@ ac_res=`eval echo '${'$as_ac_File'}'`
 echo "${ECHO_T}$ac_res" >&6; }
 if test `eval echo '${'$as_ac_File'}'` = yes; then
   OMC="yes"
-else
-  OMC="no"
 fi
 
     if test "x${OMC}" = "xyes"; then
@@ -4909,8 +4872,6 @@ fi
 echo "${ECHO_T}$ac_cv_lib_hdf5_main" >&6; }
 if test $ac_cv_lib_hdf5_main = yes; then
   HDF5="yes"
-else
-  HDF5="no"
 fi
 
   if test "x${HDF5}" = "xyes"; then
@@ -4982,8 +4943,6 @@ fi
 echo "${ECHO_T}$ac_cv_lib_cgns_main" >&6; }
 if test $ac_cv_lib_cgns_main = yes; then
   CGNS="yes"
-else
-  CGNS="no"
 fi
 
   if test "x${CGNS}" = "xyes"; then
@@ -5059,8 +5018,6 @@ fi
 echo "${ECHO_T}$ac_cv_lib_med_main" >&6; }
 if test $ac_cv_lib_med_main = yes; then
   MED="yes"
-else
-  MED="no"
 fi
 
     if test "x${MED}" = "xyes"; then
@@ -5159,8 +5116,6 @@ fi
 echo "${ECHO_T}$ac_cv_lib_gsl_main" >&6; }
 if test $ac_cv_lib_gsl_main = yes; then
   GSL="yes"
-else
-  GSL="no"
 fi
 
   if test "x${GSL}" = "xyes"; then
@@ -5193,8 +5148,6 @@ fi
 echo "${ECHO_T}$ac_cv_file___contrib_NR_dsvdcmp_cpp" >&6; }
 if test $ac_cv_file___contrib_NR_dsvdcmp_cpp = yes; then
   NR="yes"
-else
-  NR="no"
 fi
 
   if test "x${NR}" = "xyes"; then
@@ -5274,8 +5227,6 @@ fi
 echo "${ECHO_T}$ac_cv_lib_FourierModel_main" >&6; }
 if test $ac_cv_lib_FourierModel_main = yes; then
   FM="yes"
-else
-  FM="no"
 fi
 
   if test "x${FM}" = "xyes"; then
@@ -5365,10 +5316,8 @@ echo "$as_me: WARNING: Could not find FFTW3: disabling FourierModel." >&2;}
   fi
 fi
 
-BLAS_LIBS=""
-BLAS_PATH=""
-if test "x${BLAS_LAPACK_PREFIX}" != "x"; then
-  LDFLAGS="-L${BLAS_LAPACK_PREFIX} -L${BLAS_LAPACK_PREFIX}/lib ${LDFLAGS}"
+if test "x${BLAS_PREFIX}" != "x"; then
+  LDFLAGS="-L${BLAS_PREFIX} -L${BLAS_PREFIX}/lib ${LDFLAGS}"
 fi
 { echo "$as_me:$LINENO: checking for cblas_dgemm in -lcblas" >&5
 echo $ECHO_N "checking for cblas_dgemm in -lcblas... $ECHO_C" >&6; }
@@ -5432,20 +5381,17 @@ fi
 { echo "$as_me:$LINENO: result: $ac_cv_lib_cblas_cblas_dgemm" >&5
 echo "${ECHO_T}$ac_cv_lib_cblas_cblas_dgemm" >&6; }
 if test $ac_cv_lib_cblas_cblas_dgemm = yes; then
-  CBLAS="yes"
-else
-  CBLAS="no"
+  CBLAS="yes" BLAS_LIBS="-lcblas"
 fi
 
-if test "x$CBLAS" = "xyes"; then
-  BLAS_LIBS="-lcblas"
-    { echo "$as_me:$LINENO: checking for main in -latlas" >&5
-echo $ECHO_N "checking for main in -latlas... $ECHO_C" >&6; }
-if test "${ac_cv_lib_atlas_main+set}" = set; then
+if test "x${CBLAS}" != "xyes"; then
+  { echo "$as_me:$LINENO: checking for cblas_dgemm in -lcblas" >&5
+echo $ECHO_N "checking for cblas_dgemm in -lcblas... $ECHO_C" >&6; }
+if test "${ac_cv_lib_cblas_cblas_dgemm+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   ac_check_lib_save_LIBS=$LIBS
-LIBS="-latlas  $LIBS"
+LIBS="-lcblas -latlas $LIBS"
 cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
@@ -5453,11 +5399,17 @@ cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 
-
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char cblas_dgemm ();
 int
 main ()
 {
-return main ();
+return cblas_dgemm ();
   ;
   return 0;
 }
@@ -5480,30 +5432,34 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
 	 test ! -s conftest.err
        } && test -s conftest$ac_exeext &&
        $as_test_x conftest$ac_exeext; then
-  ac_cv_lib_atlas_main=yes
+  ac_cv_lib_cblas_cblas_dgemm=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-	ac_cv_lib_atlas_main=no
+	ac_cv_lib_cblas_cblas_dgemm=no
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
       conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_atlas_main" >&5
-echo "${ECHO_T}$ac_cv_lib_atlas_main" >&6; }
-if test $ac_cv_lib_atlas_main = yes; then
-  BLAS_LIBS="${BLAS_LIBS} -latlas"
+{ echo "$as_me:$LINENO: result: $ac_cv_lib_cblas_cblas_dgemm" >&5
+echo "${ECHO_T}$ac_cv_lib_cblas_cblas_dgemm" >&6; }
+if test $ac_cv_lib_cblas_cblas_dgemm = yes; then
+  CBLAS="yes" BLAS_LIBS="-lcblas -latlas"
 fi
 
-  if test "x${BLAS_LAPACK_PREFIX}" != "x"; then
-    BLAS_PATH="-L${BLAS_LAPACK_PREFIX} -L${BLAS_LAPACK_PREFIX}/lib"
+fi
+if test "x${CBLAS}" = "xyes"; then
+  if test "x${BLAS_PREFIX}" != "x"; then
+    BLAS_PATH="-L${BLAS_PREFIX} -L${BLAS_PREFIX}/lib"
   fi
+  FLAGS="${FLAGS} -DHAVE_CBLAS"
 else
-  if test "x$GSL" = "xyes"; then
+  if test "x${GSL}" = "xyes"; then
         BLAS_LIBS="-lgslcblas"
+    FLAGS="${FLAGS} -DHAVE_CBLAS"
   fi
 fi
 
@@ -5768,7 +5724,6 @@ ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
 ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
 
-  F77LIB=""
   case "${F77}" in
     *gfortran*)
       F77LIB="-lgfortran"
@@ -5776,15 +5731,18 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
     *g77*)
       F77LIB="-lg2c"
       ;;
+    *)
+      F77LIB=""
+      ;;
   esac
   LDFLAGS="${LDFLAGS} ${F77LIB}"
-  { echo "$as_me:$LINENO: checking for dgemm in -lblas" >&5
-echo $ECHO_N "checking for dgemm in -lblas... $ECHO_C" >&6; }
-if test "${ac_cv_lib_blas_dgemm+set}" = set; then
+  { echo "$as_me:$LINENO: checking for ATL_xerbla in -latlas" >&5
+echo $ECHO_N "checking for ATL_xerbla in -latlas... $ECHO_C" >&6; }
+if test "${ac_cv_lib_atlas_ATL_xerbla+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   ac_check_lib_save_LIBS=$LIBS
-LIBS="-lblas  $LIBS"
+LIBS="-latlas  $LIBS"
 cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
@@ -5798,11 +5756,11 @@ cat >>conftest.$ac_ext <<_ACEOF
 #ifdef __cplusplus
 extern "C"
 #endif
-char dgemm ();
+char ATL_xerbla ();
 int
 main ()
 {
-return dgemm ();
+return ATL_xerbla ();
   ;
   return 0;
 }
@@ -5825,34 +5783,28 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
 	 test ! -s conftest.err
        } && test -s conftest$ac_exeext &&
        $as_test_x conftest$ac_exeext; then
-  ac_cv_lib_blas_dgemm=yes
+  ac_cv_lib_atlas_ATL_xerbla=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-	ac_cv_lib_blas_dgemm=no
+	ac_cv_lib_atlas_ATL_xerbla=no
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
       conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_blas_dgemm" >&5
-echo "${ECHO_T}$ac_cv_lib_blas_dgemm" >&6; }
-if test $ac_cv_lib_blas_dgemm = yes; then
-  BLAS="yes"
-else
-  BLAS="no"
-fi
-
-  if test "x$BLAS" != "xyes"; then
-    { echo "$as_me:$LINENO: checking for dgemm_ in -lblas" >&5
-echo $ECHO_N "checking for dgemm_ in -lblas... $ECHO_C" >&6; }
-if test "${ac_cv_lib_blas_dgemm_+set}" = set; then
+{ echo "$as_me:$LINENO: result: $ac_cv_lib_atlas_ATL_xerbla" >&5
+echo "${ECHO_T}$ac_cv_lib_atlas_ATL_xerbla" >&6; }
+if test $ac_cv_lib_atlas_ATL_xerbla = yes; then
+  { echo "$as_me:$LINENO: checking for dgemm_ in -lf77blas" >&5
+echo $ECHO_N "checking for dgemm_ in -lf77blas... $ECHO_C" >&6; }
+if test "${ac_cv_lib_f77blas_dgemm_+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   ac_check_lib_save_LIBS=$LIBS
-LIBS="-lblas  $LIBS"
+LIBS="-lf77blas -latlas $LIBS"
 cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
@@ -5893,34 +5845,34 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
 	 test ! -s conftest.err
        } && test -s conftest$ac_exeext &&
        $as_test_x conftest$ac_exeext; then
-  ac_cv_lib_blas_dgemm_=yes
+  ac_cv_lib_f77blas_dgemm_=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-	ac_cv_lib_blas_dgemm_=no
+	ac_cv_lib_f77blas_dgemm_=no
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
       conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_blas_dgemm_" >&5
-echo "${ECHO_T}$ac_cv_lib_blas_dgemm_" >&6; }
-if test $ac_cv_lib_blas_dgemm_ = yes; then
-  BLAS="yes"
-else
-  BLAS="no"
+{ echo "$as_me:$LINENO: result: $ac_cv_lib_f77blas_dgemm_" >&5
+echo "${ECHO_T}$ac_cv_lib_f77blas_dgemm_" >&6; }
+if test $ac_cv_lib_f77blas_dgemm_ = yes; then
+  BLAS="yes" BLAS_LIBS="${BLAS_LIBS} -lf77blas -latlas"
 fi
 
-  fi
-  { echo "$as_me:$LINENO: checking for dbdsqr in -llapack" >&5
-echo $ECHO_N "checking for dbdsqr in -llapack... $ECHO_C" >&6; }
-if test "${ac_cv_lib_lapack_dbdsqr+set}" = set; then
+fi
+
+  if test "x${BLAS}" != "xyes"; then
+    { echo "$as_me:$LINENO: checking for dgemm_ in -lblas" >&5
+echo $ECHO_N "checking for dgemm_ in -lblas... $ECHO_C" >&6; }
+if test "${ac_cv_lib_blas_dgemm_+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   ac_check_lib_save_LIBS=$LIBS
-LIBS="-llapack -lblas $LIBS"
+LIBS="-lblas  $LIBS"
 cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
@@ -5934,11 +5886,11 @@ cat >>conftest.$ac_ext <<_ACEOF
 #ifdef __cplusplus
 extern "C"
 #endif
-char dbdsqr ();
+char dgemm_ ();
 int
 main ()
 {
-return dbdsqr ();
+return dgemm_ ();
   ;
   return 0;
 }
@@ -5961,34 +5913,34 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
 	 test ! -s conftest.err
        } && test -s conftest$ac_exeext &&
        $as_test_x conftest$ac_exeext; then
-  ac_cv_lib_lapack_dbdsqr=yes
+  ac_cv_lib_blas_dgemm_=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-	ac_cv_lib_lapack_dbdsqr=no
+	ac_cv_lib_blas_dgemm_=no
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
       conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_lapack_dbdsqr" >&5
-echo "${ECHO_T}$ac_cv_lib_lapack_dbdsqr" >&6; }
-if test $ac_cv_lib_lapack_dbdsqr = yes; then
-  LAPACK="yes"
-else
-  LAPACK="no"
+{ echo "$as_me:$LINENO: result: $ac_cv_lib_blas_dgemm_" >&5
+echo "${ECHO_T}$ac_cv_lib_blas_dgemm_" >&6; }
+if test $ac_cv_lib_blas_dgemm_ = yes; then
+  BLAS="yes" BLAS_LIBS="${BLAS_LIBS} -lblas"
 fi
 
-  if test "x$LAPACK" != "xyes"; then
+  fi
+  if test "x${BLAS}" = "xyes"; then
+    FLAGS="${FLAGS} -DHAVE_BLAS"
     { echo "$as_me:$LINENO: checking for dbdsqr_ in -llapack" >&5
 echo $ECHO_N "checking for dbdsqr_ in -llapack... $ECHO_C" >&6; }
 if test "${ac_cv_lib_lapack_dbdsqr_+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   ac_check_lib_save_LIBS=$LIBS
-LIBS="-llapack -lblas $LIBS"
+LIBS="-llapack ${BLAS_LIBS} $LIBS"
 cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
@@ -6044,14 +5996,12 @@ fi
 { echo "$as_me:$LINENO: result: $ac_cv_lib_lapack_dbdsqr_" >&5
 echo "${ECHO_T}$ac_cv_lib_lapack_dbdsqr_" >&6; }
 if test $ac_cv_lib_lapack_dbdsqr_ = yes; then
-  LAPACK="yes"
-else
-  LAPACK="no"
+  LAPACK="yes" BLAS_LIBS="-llapack ${BLAS_LIBS}"
 fi
 
-  fi
-  if test "x$LAPACK" = "xyes" -a "x$BLAS" = "xyes"; then
-    BLAS_LIBS="-llapack ${BLAS_LIBS} -lblas ${F77LIB}"
+    if test "x${LAPACK}" = "xyes"; then
+      FLAGS="${FLAGS} -DHAVE_LAPACK"
+    fi
   fi
 fi
 
@@ -6120,8 +6070,6 @@ fi
 echo "${ECHO_T}$ac_cv_lib_mpi_cxx_main" >&6; }
 if test $ac_cv_lib_mpi_cxx_main = yes; then
   MPI="yes"
-else
-  MPI="no"
 fi
 
   if test "x${MPI}" = "xyes"; then
diff --git a/configure.in b/configure.in
index 169c74b80d42f0590d659617a22e4cd462523ed2..296cb4a024561ef608b36da057a71384ee9c64ae 100644
--- a/configure.in
+++ b/configure.in
@@ -69,10 +69,10 @@ AC_ARG_WITH(fm-prefix,
             AC_HELP_STRING([--with-fm-prefix=PFX],
                            [prefix where FourierModel is installed]),
             [FM_PREFIX=$withval])
-AC_ARG_WITH(blas-lapack-prefix,
-            AC_HELP_STRING([--with-blas-lapack-prefix=PFX],
-                           [prefix where BLAS and LAPACK are installed]),
-            [BLAS_LAPACK_PREFIX=$withval])
+AC_ARG_WITH(blas-prefix,
+            AC_HELP_STRING([--with-blas-prefix=PFX],
+                           [prefix where BLAS (and LAPACK) are installed]),
+            [BLAS_PREFIX=$withval])
 
 dnl Parse '--enable' command line options
 AC_ARG_ENABLE(gsl,
@@ -244,7 +244,7 @@ if test "x$enable_gui" != "xno"; then
   FLAGS="-DHAVE_FLTK ${FLAGS}"
 
   if test "x${FLTK_PREFIX}" != "x" ; then
-    AC_PATH_PROG(FLTKCONFIG,fltk-config,"",[${FLTK_PREFIX}:${FLTK_PREFIX}/bin:$PATH])
+    AC_PATH_PROG(FLTKCONFIG,fltk-config,[],[${FLTK_PREFIX}:${FLTK_PREFIX}/bin:$PATH])
     dnl Find the libs/includes even if fltk is _not_ properly installed (ugly hack!)
     GMSH_LIBS="${GMSH_LIBS} -L${FLTK_PREFIX}/lib"
     FLAGS="${FLAGS} -I${FLTK_PREFIX}"
@@ -260,12 +260,11 @@ if test "x$enable_gui" != "xno"; then
     if test "x${OSMESA_PREFIX}" != "x"; then
       LDFLAGS="-L${OSMESA_PREFIX} -L${OSMESA_PREFIX}/lib ${LDFLAGS}"
     fi
-    AC_CHECK_LIB(OSMesa,main,OSMESA="yes",OSMESA="no")
+    AC_CHECK_LIB(OSMesa,main,OSMESA="yes")
   fi
 
   dnl Check for native file chooser
-  AC_CHECK_FILE(./contrib/NativeFileChooser/Fl_Native_File_Chooser.cxx, 
-                NATIVE="yes", NATIVE="no")
+  AC_CHECK_FILE(./contrib/NativeFileChooser/Fl_Native_File_Chooser.cxx,NATIVE="yes")
   if test "x${NATIVE}" = "xyes"; then
     if (test "x${UNAME}" = "xLinux" -a "x$enable_native_file_chooser" = "xyes" ||
         test "x${UNAME}" != "xLinux" -a "x$enable_native_file_chooser" != "xno"); then
@@ -297,11 +296,8 @@ if test "x$enable_gui" != "xno"; then
     fi
   fi
 
-  FL_JPEG=""
   expr "x${GMSH_LIBS}" : 'x.*fltk_jpeg.*' >/dev/null && FL_JPEG="yes"
-  FL_PNG=""
   expr "x${GMSH_LIBS}" : 'x.*fltk_png.*' >/dev/null && FL_PNG="yes"
-  FL_ZLIB=""
   expr "x${GMSH_LIBS}" : 'x.*fltk_z.*' >/dev/null && FL_ZLIB="yes"
 
   dnl Check for libjpeg
@@ -313,7 +309,7 @@ if test "x$enable_gui" != "xno"; then
       if test "x${JPEG_PREFIX}" != "x"; then
         LDFLAGS="-L${JPEG_PREFIX} -L${JPEG_PREFIX}/lib ${LDFLAGS}"
       fi
-      AC_CHECK_LIB(jpeg,main,JPEG="yes",JPEG="no")
+      AC_CHECK_LIB(jpeg,main,JPEG="yes")
       if test "x${JPEG}" = "xyes"; then
         FLAGS="-DHAVE_LIBJPEG ${FLAGS}"
         if test "x${JPEG_PREFIX}" = "x"; then
@@ -328,7 +324,6 @@ if test "x$enable_gui" != "xno"; then
   fi
 
   dnl Check for libz
-  ZLIB=""
   if test "x$enable_zlib" != "xno"; then
     dnl If provided by FLTK, use that one; otherwise, look for it
     if test "x${FL_ZLIB}" = "xyes"; then
@@ -337,7 +332,7 @@ if test "x$enable_gui" != "xno"; then
       if test "x${ZLIB_PREFIX}" != "x"; then
         LDFLAGS="-L${ZLIB_PREFIX} -L${ZLIB_PREFIX}/lib ${LDFLAGS}"
       fi
-      AC_CHECK_LIB(z,main,ZLIB="yes",ZLIB="no")
+      AC_CHECK_LIB(z,main,ZLIB="yes")
     fi
   fi
 
@@ -350,7 +345,7 @@ if test "x$enable_gui" != "xno"; then
       if test "x${PNG_PREFIX}" != "x"; then
         LDFLAGS="-L${PNG_PREFIX} -L${PNG_PREFIX}/lib ${LDFLAGS}"
       fi
-      AC_CHECK_LIB(png,main,PNG="yes",PNG="no")
+      AC_CHECK_LIB(png,main,PNG="yes")
       if test "x${PNG}" = "xyes"; then
         FLAGS="-DHAVE_LIBPNG ${FLAGS}"
         if test "x${PNG_PREFIX}" = "x"; then
@@ -388,12 +383,11 @@ else
   GMSH_LIBS="${GMSH_LIBS} -lGmshCommon -lGmshNumeric"
 
   dnl Check for libz
-  ZLIB=""
   if test "x$enable_zlib" != "xno"; then
     if test "x${ZLIB_PREFIX}" != "x"; then
       LDFLAGS="-L${ZLIB_PREFIX} -L${ZLIB_PREFIX}/lib ${LDFLAGS}"
     fi
-    AC_CHECK_LIB(z,main,ZLIB="yes",ZLIB="no")
+    AC_CHECK_LIB(z,main,ZLIB="yes")
   fi
 
 fi
@@ -403,7 +397,7 @@ dnl added to $LIBS, used for further checks)
 AC_CHECK_LIB(m,main)
 
 dnl Check for various functions
-AC_CHECK_FUNC(vsnprintf,,FLAGS="-DHAVE_NO_VSNPRINTF ${FLAGS}")
+AC_CHECK_FUNC(vsnprintf,[],FLAGS="-DHAVE_NO_VSNPRINTF ${FLAGS}")
 
 dnl Check if Unix98 socklen_t type is available
 AC_TRY_COMPILE(
@@ -416,7 +410,7 @@ if test "x$enable_contrib" != "xno"; then
 
   dnl Check for ANN
   if test "x$enable_ann" != "xno"; then
-    AC_CHECK_FILE(./contrib/ANN/include/ANN/ANN.h, ANN="yes", ANN="no")
+    AC_CHECK_FILE(./contrib/ANN/include/ANN/ANN.h,ANN="yes")
     if test "x${ANN}" = "xyes"; then
       GMSH_DIRS="${GMSH_DIRS} contrib/ANN"
       GMSH_LIBS="${GMSH_LIBS} -lGmshANN"
@@ -433,7 +427,7 @@ if test "x$enable_contrib" != "xno"; then
 
   dnl Check for gmm++ linear solver
   if test "x$enable_gmm" != "xno"; then
-    AC_CHECK_FILE(./contrib/gmm/gmm.h, GMM="yes", GMM="no")
+    AC_CHECK_FILE(./contrib/gmm/gmm.h,GMM="yes")
     if test "x${GMM}" = "xyes"; then
       FLAGS="${FLAGS} -DHAVE_GMM"
       echo "********************************************************************"
@@ -447,7 +441,7 @@ if test "x$enable_contrib" != "xno"; then
 
   dnl Check for Chaco partitionner
   if test "x$enable_chaco" != "xno"; then
-    AC_CHECK_FILE(./contrib/Chaco/main/interface.c, CHACO="yes", CHACO="no")
+    AC_CHECK_FILE(./contrib/Chaco/main/interface.c,CHACO="yes")
     if test "x${CHACO}" = "xyes"; then
       GMSH_DIRS="${GMSH_DIRS} contrib/Chaco"
       GMSH_LIBS="${GMSH_LIBS} -lGmshChaco"
@@ -463,7 +457,7 @@ if test "x$enable_contrib" != "xno"; then
 
   dnl Check for Metis partitionner
   if test "x$enable_metis" != "xno"; then
-    AC_CHECK_FILE(./contrib/Metis/metis.h, METIS="yes", METIS="no")
+    AC_CHECK_FILE(./contrib/Metis/metis.h,METIS="yes")
     if test "x${METIS}" = "xyes"; then
       GMSH_DIRS="${GMSH_DIRS} contrib/Metis"
       GMSH_LIBS="${GMSH_LIBS} -lGmshMetis"
@@ -481,7 +475,7 @@ if test "x$enable_contrib" != "xno"; then
 
   dnl Check for Netgen
   if test "x$enable_netgen" != "xno"; then
-    AC_CHECK_FILE(./contrib/Netgen/libsrc/meshing/meshclass.cpp, NETGEN="yes", NETGEN="no")
+    AC_CHECK_FILE(./contrib/Netgen/libsrc/meshing/meshclass.cpp,NETGEN="yes")
     if test "x${NETGEN}" = "xyes"; then
       GMSH_DIRS="${GMSH_DIRS} contrib/Netgen"
       GMSH_LIBS="${GMSH_LIBS} -lGmshNetgen"
@@ -497,7 +491,7 @@ if test "x$enable_contrib" != "xno"; then
 
   dnl Check for Tetgen
   if test "x$enable_tetgen" != "xno"; then
-    AC_CHECK_FILE(./contrib/Tetgen/tetgen.h, TETGEN="yes", TETGEN="no")
+    AC_CHECK_FILE(./contrib/Tetgen/tetgen.h,TETGEN="yes")
     if test "x${TETGEN}" = "xyes"; then
       GMSH_DIRS="${GMSH_DIRS} contrib/Tetgen"
       GMSH_LIBS="${GMSH_LIBS} -lGmshTetgen"
@@ -515,7 +509,7 @@ if test "x$enable_contrib" != "xno"; then
 
   dnl Check for MathEval
   if test "x$enable_matheval" != "xno"; then
-    AC_CHECK_FILE(./contrib/MathEval/matheval.cpp, MATHEVAL="yes", MATHEVAL="no")
+    AC_CHECK_FILE(./contrib/MathEval/matheval.cpp,MATHEVAL="yes")
     if test "x${MATHEVAL}" = "xyes"; then
       GMSH_DIRS="${GMSH_DIRS} contrib/MathEval"
       GMSH_LIBS="${GMSH_LIBS} -lGmshMathEval"
@@ -541,7 +535,7 @@ if test "x$enable_occ" = "xyes"; then
   if test "x${OCC_PREFIX}" != "x"; then
     LDFLAGS="-L${OCC_PREFIX}/lib ${LDFLAGS}"
   fi
-  AC_CHECK_LIB(TKernel,main,OCC="yes",OCC="no")
+  AC_CHECK_LIB(TKernel,main,OCC="yes")
   if test "x${OCC}" = "xyes"; then
     # DataExchange (subset; see occ/ros/adm/make/Makefile for more info)
     OCC_LIBS="-lTKSTEP -lTKSTEP209 -lTKSTEPAttr -lTKSTEPBase -lTKIGES -lTKXSBase"
@@ -565,7 +559,7 @@ fi
 dnl Check for OpenCascade mesh constraints
 if test "x${OCC}" = "xyes"; then
   if test "x${OCC_MESH_CONTRAINTS_PREFIX}" != "x"; then
-    AC_CHECK_FILE(${OCC_MESH_CONTRAINTS_PREFIX}/MeshGmsh_Constrain.hxx, OMC="yes", OMC="no")
+    AC_CHECK_FILE(${OCC_MESH_CONTRAINTS_PREFIX}/MeshGmsh_Constrain.hxx,OMC="yes")
     if test "x${OMC}" = "xyes"; then
       FLAGS="${FLAGS} -DHAVE_OCC_MESH_CONSTRAINTS -I${OCC_MESH_CONTRAINTS_PREFIX}"
     fi
@@ -583,7 +577,7 @@ if test "x$enable_hdf5" = "xyes"; then
   if test "x${HDF5_PREFIX}" != "x"; then
     LDFLAGS="-L${HDF5_PREFIX}/lib ${LDFLAGS}"
   fi
-  AC_CHECK_LIB(hdf5,main,HDF5="yes",HDF5="no")
+  AC_CHECK_LIB(hdf5,main,HDF5="yes")
   if test "x${HDF5}" = "xyes"; then
     LIBS="-lhdf5 ${LIBS}"  # Necessary for CGNS with HDF5
   fi
@@ -597,7 +591,7 @@ if test "x$enable_cgns" = "xyes"; then
   if test "x${CGNS_PREFIX}" != "x"; then
     LDFLAGS="-L${CGNS_PREFIX}/lib ${LDFLAGS}"
   fi
-  AC_CHECK_LIB(cgns,main,CGNS="yes",CGNS="no")
+  AC_CHECK_LIB(cgns,main,CGNS="yes")
   if test "x${CGNS}" = "xyes"; then
     if test "x${CGNS_PREFIX}" = "x"; then
       GMSH_LIBS="${GMSH_LIBS} -lcgns"
@@ -615,7 +609,7 @@ if test "x${HDF5}" = "xyes"; then
     if test "x${MED_PREFIX}" != "x"; then
       LDFLAGS="-L${MED_PREFIX}/lib ${LDFLAGS}"
     fi
-    AC_CHECK_LIB(med,main,MED="yes",MED="no")
+    AC_CHECK_LIB(med,main,MED="yes")
     if test "x${MED}" = "xyes"; then
       if test "x${MED_PREFIX}" = "x"; then
         GMSH_LIBS="${GMSH_LIBS} -lmed"
@@ -662,7 +656,7 @@ if test "x$enable_gsl" != "xno"; then
   if test "x${GSL_PREFIX}" != "x"; then
     LDFLAGS="-L${GSL_PREFIX} -L${GSL_PREFIX}/lib ${LDFLAGS}"
   fi
-  AC_CHECK_LIB(gsl,main,GSL="yes",GSL="no",-lgslcblas)
+  AC_CHECK_LIB(gsl,main,GSL="yes",[],-lgslcblas)
   if test "x${GSL}" = "xyes"; then
     FLAGS="-DHAVE_GSL ${FLAGS}"
     if test "x${GSL_PREFIX}" = "x"; then
@@ -675,7 +669,7 @@ if test "x$enable_gsl" != "xno"; then
 fi
 if test "x${GSL}" != "xyes"; then
   dnl Check if non-free numerical recipes routines are in the tree
-  AC_CHECK_FILE(./contrib/NR/dsvdcmp.cpp,NR="yes",NR="no")
+  AC_CHECK_FILE(./contrib/NR/dsvdcmp.cpp,NR="yes")
   if test "x${NR}" = "xyes"; then
     GMSH_DIRS="${GMSH_DIRS} contrib/NR"
     GMSH_LIBS="${GMSH_LIBS} -lGmshNR"
@@ -695,7 +689,7 @@ if test "x$enable_fm" != "xno"; then
   if test "x${FM_PREFIX}" != "x"; then
     LDFLAGS="-L${FM_PREFIX}/lib ${LDFLAGS}"
   fi
-  AC_CHECK_LIB(FourierModel,main,FM="yes",FM="no")
+  AC_CHECK_LIB(FourierModel,main,FM="yes")
   if test "x${FM}" = "xyes"; then
     dnl Check for FFTW3
     if test "x${FFTW3_PREFIX}" != "x"; then
@@ -724,23 +718,23 @@ if test "x$enable_fm" != "xno"; then
 fi
 
 dnl Check for C version of BLAS
-BLAS_LIBS=""
-BLAS_PATH=""
-if test "x${BLAS_LAPACK_PREFIX}" != "x"; then
-  LDFLAGS="-L${BLAS_LAPACK_PREFIX} -L${BLAS_LAPACK_PREFIX}/lib ${LDFLAGS}"
+if test "x${BLAS_PREFIX}" != "x"; then
+  LDFLAGS="-L${BLAS_PREFIX} -L${BLAS_PREFIX}/lib ${LDFLAGS}"
 fi
-AC_CHECK_LIB(cblas,cblas_dgemm,CBLAS="yes",CBLAS="no")
-if test "x$CBLAS" = "xyes"; then
-  BLAS_LIBS="-lcblas"
-  dnl add atlas if cblas came from it
-  AC_CHECK_LIB(atlas,main,BLAS_LIBS="${BLAS_LIBS} -latlas",)
-  if test "x${BLAS_LAPACK_PREFIX}" != "x"; then
-    BLAS_PATH="-L${BLAS_LAPACK_PREFIX} -L${BLAS_LAPACK_PREFIX}/lib"
+AC_CHECK_LIB(cblas,cblas_dgemm,CBLAS="yes" BLAS_LIBS="-lcblas")
+if test "x${CBLAS}" != "xyes"; then
+  AC_CHECK_LIB(cblas,cblas_dgemm,CBLAS="yes" BLAS_LIBS="-lcblas -latlas",[],-latlas)
+fi
+if test "x${CBLAS}" = "xyes"; then
+  if test "x${BLAS_PREFIX}" != "x"; then
+    BLAS_PATH="-L${BLAS_PREFIX} -L${BLAS_PREFIX}/lib"
   fi
+  FLAGS="${FLAGS} -DHAVE_CBLAS"
 else 
-  if test "x$GSL" = "xyes"; then
+  if test "x${GSL}" = "xyes"; then
     dnl use unoptimized gsl version
     BLAS_LIBS="-lgslcblas"
+    FLAGS="${FLAGS} -DHAVE_CBLAS"
   fi
 fi
 
@@ -748,7 +742,6 @@ dnl Check for Fortran version of blas and lapack (only used in
 dnl FourierModel at the moment)
 if test "x${FM}" = "xyes"; then
   AC_PROG_F77
-  F77LIB=""
   case "${F77}" in
     *gfortran*)
       F77LIB="-lgfortran"
@@ -756,18 +749,24 @@ if test "x${FM}" = "xyes"; then
     *g77*)
       F77LIB="-lg2c"
       ;;
+    *)
+      F77LIB=""
+      ;;
   esac
   LDFLAGS="${LDFLAGS} ${F77LIB}"
-  AC_CHECK_LIB(blas,dgemm,BLAS="yes",BLAS="no")
-  if test "x$BLAS" != "xyes"; then
-    AC_CHECK_LIB(blas,dgemm_,BLAS="yes",BLAS="no")
+  AC_CHECK_LIB(atlas,ATL_xerbla,
+    AC_CHECK_LIB(f77blas,dgemm_,
+     [BLAS="yes" BLAS_LIBS="${BLAS_LIBS} -lf77blas -latlas"],[],-latlas))
+  if test "x${BLAS}" != "xyes"; then
+    AC_CHECK_LIB(blas,dgemm_,[BLAS="yes" BLAS_LIBS="${BLAS_LIBS} -lblas"])
   fi
-  AC_CHECK_LIB(lapack,dbdsqr,LAPACK="yes",LAPACK="no",-lblas)
-  if test "x$LAPACK" != "xyes"; then
-    AC_CHECK_LIB(lapack,dbdsqr_,LAPACK="yes",LAPACK="no",-lblas)
-  fi
-  if test "x$LAPACK" = "xyes" -a "x$BLAS" = "xyes"; then
-    BLAS_LIBS="-llapack ${BLAS_LIBS} -lblas ${F77LIB}"
+  if test "x${BLAS}" = "xyes"; then
+    FLAGS="${FLAGS} -DHAVE_BLAS"
+    AC_CHECK_LIB(lapack,dbdsqr_,
+      [LAPACK="yes" BLAS_LIBS="-llapack ${BLAS_LIBS}"],[],${BLAS_LIBS})
+    if test "x${LAPACK}" = "xyes"; then
+      FLAGS="${FLAGS} -DHAVE_LAPACK"
+    fi
   fi
 fi
 
@@ -780,7 +779,7 @@ if test "x$enable_mpi" = "xyes"; then
   if test "x${MPI_PREFIX}" != "x"; then
     LDFLAGS="-L${MPI_PREFIX}/lib ${LDFLAGS}"
   fi
-  AC_CHECK_LIB(mpi_cxx,main,MPI="yes",MPI="no")
+  AC_CHECK_LIB(mpi_cxx,main,MPI="yes")
   if test "x${MPI}" = "xyes"; then
     if test "x${MPI_PREFIX}" = "x"; then
       GMSH_LIBS="${GMSH_LIBS} -lmpi_cxx -lmpi"