--- /dev/null
+diff -ruN clapack-3.2.1-CMAKE.1.allexfb/CMakeLists.txt clapack-3.2.1-CMAKE/CMakeLists.txt
+--- clapack-3.2.1-CMAKE.1.allexfb/CMakeLists.txt 2011-06-19 22:13:27.000000000 +0200
++++ clapack-3.2.1-CMAKE/CMakeLists.txt 2011-06-19 22:23:14.000000000 +0200
+@@ -30,6 +30,29 @@
+
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+
++if(BLAS_LIBRARIES)
++ include(CheckFortranFunctionExists)
++ set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
++ CHECK_FORTRAN_FUNCTION_EXISTS("dgemm" BLAS_FOUND)
++ unset( CMAKE_REQUIRED_LIBRARIES )
++ if(BLAS_FOUND)
++ message(STATUS "--> BLAS supplied by user is WORKING, will use ${BLAS_LIBRARIES}.")
++ else(BLAS_FOUND)
++ message(ERROR "--> BLAS supplied by user is not WORKING, CANNOT USE ${BLAS_LIBRARIES}.")
++ message(ERROR "--> Will use REFERENCE BLAS (by default)")
++ message(ERROR "--> Or Correct your BLAS_LIBRARIES entry ")
++ message(ERROR "--> Or Consider checking USE_OPTIMIZED_BLAS")
++ endif(BLAS_FOUND)
++else(BLAS_LIBRARIES)
++ # User did not provide a BLAS Library
++ find_package(PkgConfig)
++ pkg_check_modules(BLAS blas)
++endif (BLAS_LIBRARIES)
++
++if(NOT BLAS_FOUND)
++ message(FATAL_ERROR "--> BLAS libraries needed but not found.")
++endif(NOT BLAS_FOUND)
++
+ add_subdirectory(SRC)
+
+ if(ENABLE_TESTS)
+@@ -44,4 +67,3 @@
+ ${CLAPACK_BINARY_DIR}/clapack-config-version.cmake @ONLY)
+ configure_file(${CLAPACK_SOURCE_DIR}/clapack-config.cmake.in
+ ${CLAPACK_BINARY_DIR}/clapack-config.cmake @ONLY)
+-
+diff -ruN clapack-3.2.1-CMAKE.1.allexfb/SRC/CMakeLists.txt clapack-3.2.1-CMAKE/SRC/CMakeLists.txt
+--- clapack-3.2.1-CMAKE.1.allexfb/SRC/CMakeLists.txt 2011-06-19 22:13:44.000000000 +0200
++++ clapack-3.2.1-CMAKE/SRC/CMakeLists.txt 2011-06-19 22:15:04.000000000 +0200
+@@ -380,7 +380,7 @@
+ endif()
+
+ add_library(clapack SHARED ${ALLOBJ} ${ALLXOBJ})
+-target_link_libraries(clapack blas f2c m)
++target_link_libraries(clapack ${BLAS_LIBRARIES} f2c m)
+ set_target_properties(clapack PROPERTIES SOVERSION "${CLAPACK_VERSION}")
+
+ install(
--- /dev/null
+diff -ruN clapack-3.2.1-CMAKE.orig/CMakeLists.txt clapack-3.2.1-CMAKE/CMakeLists.txt
+--- clapack-3.2.1-CMAKE.orig/CMakeLists.txt 2011-06-17 23:01:05.275747599 +0200
++++ clapack-3.2.1-CMAKE/CMakeLists.txt 2011-06-17 23:07:49.128747755 +0200
+@@ -30,6 +30,28 @@
+
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+
++if(BLAS_LIBRARIES)
++ include(CheckFortranFunctionExists)
++ set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
++ CHECK_FORTRAN_FUNCTION_EXISTS("dgemm" BLAS_FOUND)
++ unset( CMAKE_REQUIRED_LIBRARIES )
++ if(BLAS_FOUND)
++ message(STATUS "--> BLAS supplied by user is WORKING, will use ${BLAS_LIBRARIES}.")
++ else(BLAS_FOUND)
++ message(ERROR "--> BLAS supplied by user is not WORKING, CANNOT USE ${BLAS_LIBRARIES}.")
++ message(ERROR "--> Will use REFERENCE BLAS (by default)")
++ message(ERROR "--> Or Correct your BLAS_LIBRARIES entry ")
++ message(ERROR "--> Or Consider checking USE_OPTIMIZED_BLAS")
++ endif(BLAS_FOUND)
++else(BLAS_LIBRARIES)
++ # User did not provide a BLAS Library
++ find_package( BLAS )
++endif (BLAS_LIBRARIES)
++
++if(NOT BLAS_FOUND)
++ message(FATAL_ERROR "--> BLAS libraries needed but not found.")
++endif(NOT BLAS_FOUND)
++
+ add_subdirectory(SRC)
+
+ if(ENABLE_TESTS)
+@@ -44,4 +66,3 @@
+ ${CLAPACK_BINARY_DIR}/clapack-config-version.cmake @ONLY)
+ configure_file(${CLAPACK_SOURCE_DIR}/clapack-config.cmake.in
+ ${CLAPACK_BINARY_DIR}/clapack-config.cmake @ONLY)
+-
+diff -ruN clapack-3.2.1-CMAKE.orig/SRC/CMakeLists.txt clapack-3.2.1-CMAKE/SRC/CMakeLists.txt
+--- clapack-3.2.1-CMAKE.orig/SRC/CMakeLists.txt 2011-06-17 23:01:05.276747599 +0200
++++ clapack-3.2.1-CMAKE/SRC/CMakeLists.txt 2011-06-17 23:08:43.761747789 +0200
+@@ -377,7 +377,7 @@
+ endif()
+
+ add_library(clapack SHARED ${ALLOBJ} ${ALLXOBJ})
+-target_link_libraries(clapack blas f2c m)
++target_link_libraries(clapack ${BLAS_LIBRARIES} f2c m)
+ set_target_properties(clapack PROPERTIES SOVERSION "${CLAPACK_VERSION}")
+
+ install(
--- /dev/null
+diff -u -r -N clapack-3.2.1-CMAKE.orig/CMakeLists.txt clapack-3.2.1-CMAKE/CMakeLists.txt
+--- clapack-3.2.1-CMAKE.orig/CMakeLists.txt 2009-08-10 20:46:33.000000000 +0200
++++ clapack-3.2.1-CMAKE/CMakeLists.txt 2010-08-28 14:04:30.000000000 +0200
+@@ -1,7 +1,10 @@
+ cmake_minimum_required(VERSION 2.6)
+ project(CLAPACK C)
+-enable_testing()
+-include(CTest)
++
++if(ENABLE_TESTS)
++ enable_testing()
++ include(CTest)
++endif(ENABLE_TESTS)
+
+ if(WIN32 AND NOT CYGWIN)
+ set(SECOND_SRC ${CLAPACK_SOURCE_DIR}/INSTALL/winsecond.c)
+@@ -11,24 +14,34 @@
+ set(SECOND_SRC ${CLAPACK_SOURCE_DIR}/INSTALL/second.c)
+ set(DSECOND_SRC ${CLAPACK_SOURCE_DIR}/INSTALL/dsecnd.c)
+ endif()
+-enable_testing()
++
+ option(USE_BLAS_WRAP "pre-pend f2c_ to each function in blas" OFF)
+ if(NOT USE_BLAS_WRAP)
+ # _zrotg_ seems to be missing in the wrap header
+ add_definitions(-DNO_BLAS_WRAP)
+ endif()
++
+ include_directories(${CLAPACK_SOURCE_DIR}/INCLUDE)
+-add_subdirectory(F2CLIBS)
+-add_subdirectory(BLAS)
+-add_subdirectory(SRC)
+-add_subdirectory(TESTING)
++
+ set(CLAPACK_VERSION 3.2.1)
+ set(CPACK_PACKAGE_VERSION_MAJOR 3)
+ set(CPACK_PACKAGE_VERSION_MINOR 2)
+ set(CPACK_PACKAGE_VERSION_PATCH 1)
++
++set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
++
++add_subdirectory(SRC)
++
++if(ENABLE_TESTS)
++ add_subdirectory(TESTING)
++endif(ENABLE_TESTS)
++
+ include(CPack)
+-export(TARGETS f2c blas lapack FILE clapack-targets.cmake)
++
++export(TARGETS clapack FILE clapack-targets.cmake)
++
+ configure_file(${CLAPACK_SOURCE_DIR}/clapack-config-version.cmake.in
+ ${CLAPACK_BINARY_DIR}/clapack-config-version.cmake @ONLY)
+ configure_file(${CLAPACK_SOURCE_DIR}/clapack-config.cmake.in
+ ${CLAPACK_BINARY_DIR}/clapack-config.cmake @ONLY)
++
+diff -u -r -N clapack-3.2.1-CMAKE.orig/SRC/CMakeLists.txt clapack-3.2.1-CMAKE/SRC/CMakeLists.txt
+--- clapack-3.2.1-CMAKE.orig/SRC/CMakeLists.txt 2009-08-10 19:47:54.000000000 +0200
++++ clapack-3.2.1-CMAKE/SRC/CMakeLists.txt 2010-08-28 14:32:17.000000000 +0200
+@@ -375,6 +375,20 @@
+ if(BUILD_COMPLEX16)
+ set(ALLOBJ ${ZLASRC} ${ALLAUX} ${DZLAUX})
+ endif()
+-add_library(lapack ${ALLOBJ} ${ALLXOBJ})
+-target_link_libraries(lapack blas)
+
++add_library(clapack SHARED ${ALLOBJ} ${ALLXOBJ})
++target_link_libraries(clapack blas f2c m)
++set_target_properties(clapack PROPERTIES SOVERSION "${CLAPACK_VERSION}")
++
++install(
++ TARGETS clapack EXPORT clapack
++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
++)
++
++install(
++ FILES ../INCLUDE/clapack.h DESTINATION include/clapack
++)
++
++install(
++ EXPORT clapack DESTINATION "share/cmake/Modules" FILE clapack-config.cmake
++)
+diff -u -r -N clapack-3.2.1-CMAKE.orig/TESTING/EIG/CMakeLists.txt clapack-3.2.1-CMAKE/TESTING/EIG/CMakeLists.txt
+--- clapack-3.2.1-CMAKE.orig/TESTING/EIG/CMakeLists.txt 2009-08-10 19:47:54.000000000 +0200
++++ clapack-3.2.1-CMAKE/TESTING/EIG/CMakeLists.txt 2010-08-28 13:46:40.000000000 +0200
+@@ -119,7 +119,7 @@
+
+ macro(add_eig_executable name )
+ add_executable(${name} ${ARGN})
+- target_link_libraries(${name} tmglib lapack )
++ target_link_libraries(${name} tmglib clapack )
+ endmacro(add_eig_executable)
+
+ add_eig_executable(xeigtsts ${SEIGTST} ${SCIGTST} ${AEIGTST}
+diff -u -r -N clapack-3.2.1-CMAKE.orig/TESTING/LIN/CMakeLists.txt clapack-3.2.1-CMAKE/TESTING/LIN/CMakeLists.txt
+--- clapack-3.2.1-CMAKE.orig/TESTING/LIN/CMakeLists.txt 2009-08-10 20:06:06.000000000 +0200
++++ clapack-3.2.1-CMAKE/TESTING/LIN/CMakeLists.txt 2010-08-28 13:46:40.000000000 +0200
+@@ -189,7 +189,7 @@
+
+ macro(add_lin_executable name )
+ add_executable(${name} ${ARGN})
+- target_link_libraries(${name} tmglib lapack)
++ target_link_libraries(${name} tmglib clapack)
+ endmacro(add_lin_executable)
+
+ add_lin_executable(xlintsts ${ALINTST} ${SCLNTST} ${SLINTST}
+diff -u -r -N clapack-3.2.1-CMAKE.orig/TESTING/MATGEN/CMakeLists.txt clapack-3.2.1-CMAKE/TESTING/MATGEN/CMakeLists.txt
+--- clapack-3.2.1-CMAKE.orig/TESTING/MATGEN/CMakeLists.txt 2009-08-10 19:47:54.000000000 +0200
++++ clapack-3.2.1-CMAKE/TESTING/MATGEN/CMakeLists.txt 2010-08-28 13:46:40.000000000 +0200
+@@ -65,5 +65,6 @@
+ if(BUILD_COMPLEX16)
+ set(ALLOBJ $(ZMATGEN) $(DZATGEN))
+ endif()
+-add_library(tmglib ${ALLOBJ} )
++
++add_library(tmglib ${ALLOBJ} i_len_trim.c i_ceiling.c )
+
+diff -u -r -N clapack-3.2.1-CMAKE.orig/TESTING/MATGEN/i_ceiling.c clapack-3.2.1-CMAKE/TESTING/MATGEN/i_ceiling.c
+--- clapack-3.2.1-CMAKE.orig/TESTING/MATGEN/i_ceiling.c 1970-01-01 01:00:00.000000000 +0100
++++ clapack-3.2.1-CMAKE/TESTING/MATGEN/i_ceiling.c 2010-08-28 13:46:40.000000000 +0200
+@@ -0,0 +1,38 @@
++/* file has been copied from the included f2c library - dilfridge */
++
++#include <f2c.h>
++
++#ifdef KR_headers
++integer i_sceiling(x) real *x;
++#else
++#ifdef __cplusplus
++extern "C" {
++#endif
++integer i_sceiling(real *x)
++#endif
++{
++#define CEIL(x) ((int)(x) + ((x) > 0 && (x) != (int)(x)))
++
++ return (integer) CEIL(*x);
++}
++#ifdef __cplusplus
++}
++#endif
++
++
++#ifdef KR_headers
++integer i_dceiling(x) doublereal *x;
++#else
++#ifdef __cplusplus
++extern "C" {
++#endif
++integer i_dceiling(doublereal *x)
++#endif
++{
++#define CEIL(x) ((int)(x) + ((x) > 0 && (x) != (int)(x)))
++
++ return (integer) CEIL(*x);
++}
++#ifdef __cplusplus
++}
++#endif
+diff -u -r -N clapack-3.2.1-CMAKE.orig/TESTING/MATGEN/i_len_trim.c clapack-3.2.1-CMAKE/TESTING/MATGEN/i_len_trim.c
+--- clapack-3.2.1-CMAKE.orig/TESTING/MATGEN/i_len_trim.c 1970-01-01 01:00:00.000000000 +0100
++++ clapack-3.2.1-CMAKE/TESTING/MATGEN/i_len_trim.c 2010-08-28 13:46:40.000000000 +0200
+@@ -0,0 +1,25 @@
++/* file has been copied from the included f2c library - dilfridge */
++
++#include <f2c.h>
++
++#ifdef __cplusplus
++extern "C" {
++#endif
++
++#ifdef KR_headers
++integer i_len_trim(s, n) char *s; ftnlen n;
++#else
++integer i_len_trim(char *s, ftnlen n)
++#endif
++{
++ int i;
++
++ for(i=n-1;i>=0;i--)
++ if(s[i] != ' ')
++ return i + 1;
++
++ return(0);
++}
++#ifdef __cplusplus
++}
++#endif