aboutsummaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorKyle Guinn <elyk03@gmail.com>2016-01-02 14:41:52 -0600
committerWilly Sudiarto Raharjo <willysr@slackbuilds.org>2016-01-09 07:12:48 +0700
commit52065c8c10a894530d015229abf72d81e41300de (patch)
tree78dae5307b8a5e3fafa117583717da9048c2c0cf /libraries
parent0837ea4faa1760aa053e6e6dfd5e41611f38ba77 (diff)
libraries/blas: Updated for version 3.6.0.
Signed-off-by: Kyle Guinn <elyk03@gmail.com>
Diffstat (limited to 'libraries')
-rw-r--r--libraries/blas/blas.SlackBuild76
-rw-r--r--libraries/blas/blas.info6
-rw-r--r--libraries/blas/patches/cmake-piecewise.diff615
-rw-r--r--libraries/blas/patches/generate-pkgconfig.diff117
-rw-r--r--libraries/blas/patches/link-dependencies.diff232
-rw-r--r--libraries/blas/patches/target-cleanup.diff776
6 files changed, 1776 insertions, 46 deletions
diff --git a/libraries/blas/blas.SlackBuild b/libraries/blas/blas.SlackBuild
index f1a563d57adf..b37074312046 100644
--- a/libraries/blas/blas.SlackBuild
+++ b/libraries/blas/blas.SlackBuild
@@ -2,7 +2,7 @@
# Slackware build script for BLAS
-# Copyright 2014-2015 Kyle Guinn <elyk03@gmail.com>, USA
+# Copyright 2014-2016 Kyle Guinn <elyk03@gmail.com>, USA
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
@@ -24,8 +24,8 @@
PRGNAM=blas
SRCNAM=lapack
-VERSION=${VERSION:-3.5.0}
-BUILD=${BUILD:-2}
+VERSION=${VERSION:-3.6.0}
+BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
if [ -z "$ARCH" ]; then
@@ -45,16 +45,12 @@ DOCS="LICENSE"
if [ "$ARCH" = "i486" ]; then
SLKCFLAGS="-O2 -march=i486 -mtune=i686"
- LIBDIRSUFFIX=""
elif [ "$ARCH" = "i686" ]; then
SLKCFLAGS="-O2 -march=i686 -mtune=i686"
- LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
SLKCFLAGS="-O2 -fPIC"
- LIBDIRSUFFIX="64"
else
SLKCFLAGS="-O2"
- LIBDIRSUFFIX=""
fi
set -e
@@ -68,31 +64,30 @@ cd $SRCNAM-$VERSION
chown -R root:root .
chmod -R u+w,go-w,a+rX-st .
-# `make install` wants to compile and install the rest of lapack,
-# so install files manually instead.
-#
-# Avoid adding an RPATH entry to the shared lib. It's unnecessary, and
-# since we're not running `make install` we don't want to end up with
-# a temporary RPATH that refers to the build directory.
-#
-# WARNING: The SONAME is "libblas.so", not "libblas.so.0" nor
-# "libblas.so.$MAJOR" as crafted in previous versions of this script.
-# I don't know if this is intentional or an omission by upstream.
+# Fix lots of bugs with the cmake build system and .pc files.
+# More importantly, allow building only the BLAS component.
+patch -p1 < $CWD/patches/generate-pkgconfig.diff
+patch -p1 < $CWD/patches/link-dependencies.diff
+patch -p1 < $CWD/patches/target-cleanup.diff
+patch -p1 < $CWD/patches/cmake-piecewise.diff
+
+# Avoid adding an RPATH entry to the shared lib. It's unnecessary (except for
+# running the test suite), and it's broken on 64-bit (needs LIBDIRSUFFIX).
mkdir -p shared
cd shared
cmake \
-DCMAKE_Fortran_FLAGS:STRING="$SLKCFLAGS" \
-DCMAKE_INSTALL_PREFIX=/usr \
- -DLIB_SUFFIX=${LIBDIRSUFFIX} \
- -DCMAKE_BUILD_TYPE=Release \
+ -DCMAKE_BUILD_TYPE=None \
-DCMAKE_RULE_MESSAGES=OFF \
-DCMAKE_VERBOSE_MAKEFILE=TRUE \
+ -DBUILD_BLAS=ON \
+ -DBUILD_TESTING=OFF \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_SKIP_RPATH=YES \
..
- make blas/fast
- install -D -m0755 -s lib/libblas.so $PKG/usr/lib${LIBDIRSUFFIX}/libblas.so
- install -D -m0644 BLAS/blas.pc $PKG/usr/lib${LIBDIRSUFFIX}/pkgconfig/blas.pc
+ make
+ make install/strip DESTDIR=$PKG
cd ..
# cmake doesn't appear to let us build both shared and static libs
@@ -103,37 +98,32 @@ cd static
cmake \
-DCMAKE_Fortran_FLAGS:STRING="$SLKCFLAGS" \
-DCMAKE_INSTALL_PREFIX=/usr \
- -DLIB_SUFFIX=${LIBDIRSUFFIX} \
- -DCMAKE_BUILD_TYPE=Release \
+ -DCMAKE_BUILD_TYPE=None \
-DCMAKE_RULE_MESSAGES=OFF \
-DCMAKE_VERBOSE_MAKEFILE=TRUE \
+ -DBUILD_BLAS=ON \
+ -DBUILD_TESTING=OFF \
..
- make blas/fast
- install -D -m0644 lib/libblas.a $PKG/usr/lib${LIBDIRSUFFIX}/libblas.a
+ make
+ make install/strip DESTDIR=$PKG
cd ..
-# Fix the pkg-config file:
-# 1. Version is missing.
-# 2. -L is hard-coded when a variable exists.
-sed -i \
- -e "/^Version:/cVersion: ${VERSION}" \
- -e "/^Libs:/s/-L[^ ]*/-L\${libdir}/" \
- $PKG/usr/lib${LIBDIRSUFFIX}/pkgconfig/blas.pc
-
-# Generate man pages. Also requires some fix-ups:
+# Generate man pages. Requires some fix-ups:
+# 0. Join all escaped newlines so the entire value is replaced.
# 1. Replace "LAPACK" with "BLAS" in headers/footers.
-# 2. Version is wrong.
-# 3. Only generate on the BLAS sources.
+# 2. Only generate on the BLAS sources.
+# 3. Turn off recursion. Only operate on directories in INPUT.
# 4. Turn off some repetitive comments.
# 5. Turn off HAVE_DOT. Graphs are unnecessary for this purpose.
# 6. Turn off MAN_LINKS. See below.
sed -i \
- -e "s/^\(PROJECT_NAME *=\).*/\1 BLAS/" \
- -e "s/^\(PROJECT_NUMBER *=\).*/\1 ${VERSION}/" \
- -e "s/^\(INPUT *=\).*/\1 BLAS\/SRC/" \
- -e "s/^\(REPEAT_BRIEF *=\).*/\1 NO/" \
- -e "s/^\(HAVE_DOT *=\).*/\1 NO/" \
- -e "s/^\(MAN_LINKS *=\).*/\1 NO/" \
+ -e ':a;/\\$/N;s/\\\n//;ta' \
+ -e 's/^\(PROJECT_NAME *=\).*/\1 BLAS/' \
+ -e 's/^\(INPUT *=\).*/\1 BLAS\/SRC/' \
+ -e 's/^\(RECURSIVE *=\).*/\1 NO/' \
+ -e 's/^\(REPEAT_BRIEF *=\).*/\1 NO/' \
+ -e 's/^\(HAVE_DOT *=\).*/\1 NO/' \
+ -e 's/^\(MAN_LINKS *=\).*/\1 NO/' \
DOCS/Doxyfile_man
doxygen DOCS/Doxyfile_man
# Doxygen generates manpages on a file-by-file basis (note the .f extensions).
diff --git a/libraries/blas/blas.info b/libraries/blas/blas.info
index c910648705bc..61a211d07237 100644
--- a/libraries/blas/blas.info
+++ b/libraries/blas/blas.info
@@ -1,8 +1,8 @@
PRGNAM="blas"
-VERSION="3.5.0"
+VERSION="3.6.0"
HOMEPAGE="http://www.netlib.org/blas/"
-DOWNLOAD="http://www.netlib.org/lapack/lapack-3.5.0.tgz"
-MD5SUM="b1d3e3e425b2e44a06760ff173104bdf"
+DOWNLOAD="http://www.netlib.org/lapack/lapack-3.6.0.tgz"
+MD5SUM="f2f6c67134e851fe189bb3ca1fbb5101"
DOWNLOAD_x86_64=""
MD5SUM_x86_64=""
REQUIRES=""
diff --git a/libraries/blas/patches/cmake-piecewise.diff b/libraries/blas/patches/cmake-piecewise.diff
new file mode 100644
index 000000000000..13402a52e711
--- /dev/null
+++ b/libraries/blas/patches/cmake-piecewise.diff
@@ -0,0 +1,615 @@
+diff --git a/CBLAS/CMakeLists.txt b/CBLAS/CMakeLists.txt
+--- a/CBLAS/CMakeLists.txt
++++ b/CBLAS/CMakeLists.txt
+@@ -1,8 +1,6 @@
+ message(STATUS "CBLAS enable")
+ enable_language(C)
+
+-set(LAPACK_INSTALL_EXPORT_NAME cblas-targets)
+-
+ # Create a header file cblas.h for the routines called in my C programs
+ include(FortranCInterface)
+ FortranCInterface_HEADER( ${CMAKE_CURRENT_SOURCE_DIR}/include/cblas_mangling.h
+@@ -40,51 +38,8 @@
+ add_subdirectory(examples)
+ endif(BUILD_TESTING)
+
+-if(NOT BLAS_FOUND)
+- set(ALL_TARGETS ${ALL_TARGETS} blas)
+-endif(NOT BLAS_FOUND)
+-
+-# Export cblas targets from the
+-# install tree, if any.
+-set(_cblas_config_install_guard_target "")
+-if(ALL_TARGETS)
+- install(EXPORT cblas-targets
+- DESTINATION lib/cmake/cblas-${LAPACK_VERSION})
+- # Choose one of the cblas targets to use as a guard for
+- # cblas-config.cmake to load targets from the install tree.
+- list(GET ALL_TARGETS 0 _cblas_config_install_guard_target)
+-endif()
+-
+-# Export cblas targets from the build tree, if any.
+-set(_cblas_config_build_guard_target "")
+-if(ALL_TARGETS)
+- export(TARGETS ${ALL_TARGETS} FILE cblas-targets.cmake)
+-
+- # Choose one of the cblas targets to use as a guard
+- # for cblas-config.cmake to load targets from the build tree.
+- list(GET ALL_TARGETS 0 _cblas_config_build_guard_target)
+-endif()
+-
+-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cblas-config-version.cmake.in
+- ${LAPACK_BINARY_DIR}/cblas-config-version.cmake @ONLY)
+-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cblas-config-build.cmake.in
+- ${LAPACK_BINARY_DIR}/cblas-config.cmake @ONLY)
+-
+-
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cblas.pc.in ${CMAKE_CURRENT_BINARY_DIR}/cblas.pc @ONLY)
+ install(FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/cblas.pc
+ DESTINATION ${PKG_CONFIG_DIR}
+ )
+-
+-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cblas-config-install.cmake.in
+- ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/cblas-config.cmake @ONLY)
+-install(FILES
+- ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/cblas-config.cmake
+- ${LAPACK_BINARY_DIR}/cblas-config-version.cmake
+- DESTINATION lib/cmake/cblas-${LAPACK_VERSION}
+- )
+-
+-#install(EXPORT cblas-targets
+-# DESTINATION lib/cmake/cblas-${LAPACK_VERSION})
+-
+diff --git a/CBLAS/cmake/cblas-config-build.cmake.in b/CBLAS/cmake/cblas-config-build.cmake.in
+deleted file mode 100644
+--- a/CBLAS/cmake/cblas-config-build.cmake.in
++++ /dev/null
+@@ -1,14 +0,0 @@
+-# Load the LAPACK package with which we were built.
+-set(LAPACK_DIR "@LAPACK_BINARY_DIR@")
+-find_package(LAPACK NO_MODULE)
+-
+-# Load lapack targets from the build tree, including lapacke targets.
+-if(NOT TARGET lapacke)
+- include("@LAPACK_BINARY_DIR@/lapack-targets.cmake")
+-endif()
+-
+-# Report lapacke header search locations.
+-set(CBLAS_INCLUDE_DIRS "@LAPACK_SOURCE_DIR@/cblas/include")
+-
+-# Report lapacke libraries.
+-set(CBLAS_LIBRARIES cblas)
+diff --git a/CBLAS/cmake/cblas-config-install.cmake.in b/CBLAS/cmake/cblas-config-install.cmake.in
+deleted file mode 100644
+--- a/CBLAS/cmake/cblas-config-install.cmake.in
++++ /dev/null
+@@ -1,23 +0,0 @@
+-# Compute locations from <prefix>/lib/cmake/lapacke-<v>/<self>.cmake
+-get_filename_component(_CBLAS_SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
+-get_filename_component(_CBLAS_PREFIX "${_CBLAS_SELF_DIR}" PATH)
+-get_filename_component(_CBLAS_PREFIX "${_CBLAS_PREFIX}" PATH)
+-get_filename_component(_CBLAS_PREFIX "${_CBLAS_PREFIX}" PATH)
+-
+-# Load the LAPACK package with which we were built.
+-set(LAPACK_DIR "${_CBLAS_PREFIX}/lib/cmake/lapack-@LAPACK_VERSION@")
+-find_package(LAPACK NO_MODULE)
+-
+-# Load lapacke targets from the install tree.
+-if(NOT TARGET cblas)
+- include(${_CBLAS_SELF_DIR}/cblas-targets.cmake)
+-endif()
+-
+-# Report lapacke header search locations.
+-set(CBLAS_INCLUDE_DIRS ${_CBLAS_PREFIX}/include)
+-
+-# Report lapacke libraries.
+-set(CBLAS_LIBRARIES cblas)
+-
+-unset(_CBLAS_PREFIX)
+-unset(_CBLAS_SELF_DIR)
+diff --git a/CBLAS/cmake/cblas-config-version.cmake.in b/CBLAS/cmake/cblas-config-version.cmake.in
+deleted file mode 100644
+--- a/CBLAS/cmake/cblas-config-version.cmake.in
++++ /dev/null
+@@ -1,8 +0,0 @@
+-set(PACKAGE_VERSION "@LAPACK_VERSION@")
+-if(NOT ${PACKAGE_FIND_VERSION} VERSION_GREATER ${PACKAGE_VERSION})
+- set(PACKAGE_VERSION_COMPATIBLE 1)
+- if(${PACKAGE_FIND_VERSION} VERSION_EQUAL ${PACKAGE_VERSION})
+- set(PACKAGE_VERSION_EXACT 1)
+- endif()
+-endif()
+-
+diff --git a/CMAKE/lapack-config-build.cmake.in b/CMAKE/lapack-config-build.cmake.in
+deleted file mode 100644
+--- a/CMAKE/lapack-config-build.cmake.in
++++ /dev/null
+@@ -1,10 +0,0 @@
+-# Load lapack targets from the build tree if necessary.
+-set(_LAPACK_TARGET "@_lapack_config_build_guard_target@")
+-if(_LAPACK_TARGET AND NOT TARGET "${_LAPACK_TARGET}")
+- include("@LAPACK_BINARY_DIR@/lapack-targets.cmake")
+-endif()
+-unset(_LAPACK_TARGET)
+-
+-# Report the blas and lapack raw or imported libraries.
+-set(LAPACK_blas_LIBRARIES "@BLAS_LIBRARIES@")
+-set(LAPACK_lapack_LIBRARIES "@LAPACK_LIBRARIES@")
+diff --git a/CMAKE/lapack-config-install.cmake.in b/CMAKE/lapack-config-install.cmake.in
+deleted file mode 100644
+--- a/CMAKE/lapack-config-install.cmake.in
++++ /dev/null
+@@ -1,15 +0,0 @@
+-# Compute locations from <prefix>/lib/cmake/lapack-<v>/<self>.cmake
+-get_filename_component(_LAPACK_SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
+-
+-# Load lapack targets from the install tree if necessary.
+-set(_LAPACK_TARGET "@_lapack_config_install_guard_target@")
+-if(_LAPACK_TARGET AND NOT TARGET "${_LAPACK_TARGET}")
+- include("${_LAPACK_SELF_DIR}/lapack-targets.cmake")
+-endif()
+-unset(_LAPACK_TARGET)
+-
+-# Report the blas and lapack raw or imported libraries.
+-set(LAPACK_blas_LIBRARIES "@BLAS_LIBRARIES@")
+-set(LAPACK_lapack_LIBRARIES "@LAPACK_LIBRARIES@")
+-
+-unset(_LAPACK_SELF_DIR)
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -55,8 +55,6 @@
+ endif()
+ # --------------------------------------------------
+
+-set(LAPACK_INSTALL_EXPORT_NAME lapack-targets)
+-
+ if (UNIX)
+ include(GNUInstallDirs)
+ set(ARCHIVE_DIR ${CMAKE_INSTALL_LIBDIR})
+@@ -70,7 +68,6 @@
+
+ macro(lapack_install_library lib)
+ install(TARGETS ${lib}
+- EXPORT ${LAPACK_INSTALL_EXPORT_NAME}
+ ARCHIVE DESTINATION ${ARCHIVE_DIR}
+ LIBRARY DESTINATION ${LIBRARY_DIR}
+ RUNTIME DESTINATION ${RUNTIME_DIR}
+@@ -96,20 +93,6 @@
+ include( CheckLAPACKCompilerFlags )
+ CheckLAPACKCompilerFlags()
+
+-# --------------------------------------------------
+-# Check second function
+-
+-include(CheckTimeFunction)
+-set(TIME_FUNC NONE ${TIME_FUNC})
+-CHECK_TIME_FUNCTION(NONE TIME_FUNC)
+-CHECK_TIME_FUNCTION(INT_CPU_TIME TIME_FUNC)
+-CHECK_TIME_FUNCTION(EXT_ETIME TIME_FUNC)
+-CHECK_TIME_FUNCTION(EXT_ETIME_ TIME_FUNC)
+-CHECK_TIME_FUNCTION(INT_ETIME TIME_FUNC)
+-message(STATUS "--> Will use second_${TIME_FUNC}.f and dsecnd_${TIME_FUNC}.f as timing function.")
+-
+-set(SECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/second_${TIME_FUNC}.f)
+-set(DSECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/dsecnd_${TIME_FUNC}.f)
+ set(PKG_CONFIG_DIR ${LIBRARY_DIR}/pkgconfig)
+
+ set(prefix ${CMAKE_INSTALL_PREFIX})
+@@ -120,6 +103,11 @@
+ endif()
+
+ # --------------------------------------------------
++# By default static library
++option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
++option(BUILD_STATIC_LIBS "Build static libraries" ON)
++
++# --------------------------------------------------
+ # Precision to build
+ # By default all precisions are generated
+ option(BUILD_SINGLE "Build Single Precision" ON)
+@@ -150,236 +138,134 @@
+ Please enable at least one of these: BUILD_SINGLE, BUILD_DOUBLE, BUILD_COMPLEX, BUILD_COMPLEX16.")
+ endif()
+
+-# --------------------------------------------------
+-# Subdirectories that need to be processed
++# deprecated LAPACK routines
++option(BUILD_DEPRECATED "Build deprecated routines" OFF)
+
++# --------------------------------------------------
++# BLAS
+ option(USE_OPTIMIZED_BLAS "Whether or not to use an optimized BLAS library instead of included netlib BLAS" OFF)
+-
++option(BUILD_BLAS "Build BLAS" OFF)
+
+ # Check the usage of the user provided BLAS libraries
+ if(BLAS_LIBRARIES)
+ include(CheckFortranFunctionExists)
+ set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
+ CHECK_FORTRAN_FUNCTION_EXISTS("dgemm" BLAS_FOUND)
+- unset( CMAKE_REQUIRED_LIBRARIES )
++ 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()
++ message(SEND_ERROR "--> BLAS supplied by user is NOT WORKING, cannot use ${BLAS_LIBRARIES}.")
++ endif()
+
+ # User did not provide a BLAS Library but specified to search for one
+-elseif( USE_OPTIMIZED_BLAS )
+- find_package( BLAS )
+-endif (BLAS_LIBRARIES)
++elseif(USE_OPTIMIZED_BLAS)
++ find_package(BLAS)
+
+-# Neither user specified or optimized BLAS libraries can be used
+-if(NOT BLAS_FOUND)
+- message(STATUS "Using supplied NETLIB BLAS implementation")
+- add_subdirectory(BLAS)
+- set( BLAS_LIBRARIES blas )
+-else()
+- set( CMAKE_EXE_LINKER_FLAGS
+- "${CMAKE_EXE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
+- CACHE STRING "Linker flags for executables" FORCE)
+- set( CMAKE_MODULE_LINKER_FLAGS
+- "${CMAKE_MODULE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
+- CACHE STRING "Linker flags for modules" FORCE)
+- set( CMAKE_SHARED_LINKER_FLAGS
+- "${CMAKE_SHARED_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
+- CACHE STRING "Linker flags for shared libs" FORCE)
+-endif( NOT BLAS_FOUND )
++elseif(BUILD_BLAS)
++ set(BLAS_LIBRARIES blas)
++ set(BLAS_FOUND TRUE)
+
++ add_subdirectory(BLAS)
++endif()
+
+ # --------------------------------------------------
+ # CBLAS
+-option(CBLAS "Build CBLAS" OFF)
++option(BUILD_CBLAS "Build CBLAS" OFF)
+
+-if(CBLAS)
++if(BUILD_CBLAS)
++ set(NEED_BLAS TRUE)
+ add_subdirectory(CBLAS)
+-endif(CBLAS)
++endif(BUILD_CBLAS)
+
+ # --------------------------------------------------
+ # XBLAS
+-
+ option(USE_XBLAS "Build extended precision (needs XBLAS)" OFF)
+-if (USE_XBLAS)
++
++if(USE_XBLAS)
+ find_library(XBLAS_LIBRARY NAMES xblas)
+ endif(USE_XBLAS)
+-
+-option(USE_OPTIMIZED_LAPACK "Whether or not to use an optimized LAPACK library instead of included netlib LAPACK" OFF)
+
+ # --------------------------------------------------
+ # LAPACK
+-# User did not provide a LAPACK Library but specified to search for one
+-if( USE_OPTIMIZED_LAPACK )
+- find_package( LAPACK )
+-endif (USE_OPTIMIZED_LAPACK)
++option(USE_OPTIMIZED_LAPACK "Whether or not to use an optimized LAPACK library instead of included netlib LAPACK" OFF)
++option(BUILD_LAPACK "Build LAPACK" OFF)
+
+ # Check the usage of the user provided or automatically found LAPACK libraries
+ if(LAPACK_LIBRARIES)
+ include(CheckFortranFunctionExists)
+ set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES})
+ # Check if new routine of 3.4.0 is in LAPACK_LIBRARIES
+- CHECK_FORTRAN_FUNCTION_EXISTS("dgeqrt" LATESTLAPACK_FOUND)
+- unset( CMAKE_REQUIRED_LIBRARIES )
+- if(LATESTLAPACK_FOUND)
++ CHECK_FORTRAN_FUNCTION_EXISTS("dgeqrt" LAPACK_FOUND)
++ unset(CMAKE_REQUIRED_LIBRARIES)
++ if(LAPACK_FOUND)
+ message(STATUS "--> LAPACK supplied by user is WORKING, will use ${LAPACK_LIBRARIES}.")
+- else(LAPACK_FOUND)
+- message(ERROR "--> LAPACK supplied by user is not WORKING or is older than LAPACK 3.4.0, CANNOT USE ${LAPACK_LIBRARIES}.")
+- message(ERROR "--> Will use REFERENCE LAPACK (by default)")
+- message(ERROR "--> Or Correct your LAPACK_LIBRARIES entry ")
+- message(ERROR "--> Or Consider checking USE_OPTIMIZED_LAPACK")
+- endif(LATESTLAPACK_FOUND)
+-endif (LAPACK_LIBRARIES)
++ else()
++ message(SEND_ERROR "--> LAPACK supplied by user is NOT WORKING or is older than LAPACK 3.4.0, cannot use ${LAPACK_LIBRARIES}.")
++ endif()
++
++# User did not provide a LAPACK Library but specified to search for one
++elseif(USE_OPTIMIZED_LAPACK)
++ find_package(LAPACK)
++
++elseif(BUILD_LAPACK)
++ set(LAPACK_LIBRARIES lapack)
++ set(LAPACK_FOUND TRUE)
++
++ set(NEED_BLAS TRUE)
++
++ # Check second function
++ include(CheckTimeFunction)
++ set(TIME_FUNC NONE ${TIME_FUNC})
++ CHECK_TIME_FUNCTION(NONE TIME_FUNC)
++ CHECK_TIME_FUNCTION(INT_CPU_TIME TIME_FUNC)
++ CHECK_TIME_FUNCTION(EXT_ETIME TIME_FUNC)
++ CHECK_TIME_FUNCTION(EXT_ETIME_ TIME_FUNC)
++ CHECK_TIME_FUNCTION(INT_ETIME TIME_FUNC)
++ message(STATUS "--> Will use second_${TIME_FUNC}.f and dsecnd_${TIME_FUNC}.f as timing function.")
++
++ set(SECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/second_${TIME_FUNC}.f)
++ set(DSECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/dsecnd_${TIME_FUNC}.f)
+
+-# Neither user specified or optimized LAPACK libraries can be used
+-if(NOT LATESTLAPACK_FOUND)
+- message(STATUS "Using supplied NETLIB LAPACK implementation")
+- set( LAPACK_LIBRARIES lapack )
+ add_subdirectory(SRC)
+-else()
+- set( CMAKE_EXE_LINKER_FLAGS
+- "${CMAKE_EXE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
+- CACHE STRING "Linker flags for executables" FORCE)
+- set( CMAKE_MODULE_LINKER_FLAGS
+- "${CMAKE_MODULE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
+- CACHE STRING "Linker flags for modules" FORCE)
+- set( CMAKE_SHARED_LINKER_FLAGS
+- "${CMAKE_SHARED_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}"
+- CACHE STRING "Linker flags for shared libs" FORCE)
+-endif( NOT LATESTLAPACK_FOUND )
+-
+-message(STATUS "BUILD TESTING : ${BUILD_TESTING}" )
+-if(BUILD_TESTING)
+- add_subdirectory(TESTING)
+-endif(BUILD_TESTING)
+
+-# deprecated LAPACK routines
+-option(BUILD_DEPRECATED "Build deprecated routines" OFF)
++ message(STATUS "BUILD TESTING : ${BUILD_TESTING}")
++ if(BUILD_TESTING)
++ add_subdirectory(TESTING)
++ endif()
++
++ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc @ONLY)
++ install(FILES
++ ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc
++ DESTINATION ${PKG_CONFIG_DIR})
++endif()
+
+ # --------------------------------------------------
+ # LAPACKE
+-option(LAPACKE "Build LAPACKE" OFF)
++option(BUILD_LAPACKE "Build LAPACKE" OFF)
+
+ # LAPACKE has also the interface to some routines from tmglib,
+ # if LAPACKE_WITH_TMG is selected, we need to add those routines to LAPACKE
+ option(LAPACKE_WITH_TMG "Build LAPACKE with tmglib routines" OFF)
+ if (LAPACKE_WITH_TMG)
+- set(LAPACKE ON)
++ set(BUILD_LAPACKE ON)
+ if(NOT BUILD_TESTING)
+ add_subdirectory(TESTING/MATGEN)
+ endif(NOT BUILD_TESTING)
+ endif(LAPACKE_WITH_TMG)
+
+-if(LAPACKE)
++if(BUILD_LAPACKE)
++ set(NEED_LAPACK TRUE)
+ add_subdirectory(LAPACKE)
+-endif(LAPACKE)
+-
+-# --------------------------------------------------
+-# CPACK Packaging
+-
+-SET(CPACK_PACKAGE_NAME "LAPACK")
+-SET(CPACK_PACKAGE_VENDOR "University of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd")
+-SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LAPACK- Linear Algebra Package")
+-set(CPACK_PACKAGE_VERSION_MAJOR 3)
+-set(CPACK_PACKAGE_VERSION_MINOR 5)
+-set(CPACK_PACKAGE_VERSION_PATCH 0)
+-set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
+-SET(CPACK_PACKAGE_INSTALL_DIRECTORY "LAPACK")
+-IF(WIN32 AND NOT UNIX)
+- # There is a bug in NSI that does not handle full unix paths properly. Make
+- # sure there is at least one set of four (4) backlasshes.
+- SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\http://icl.cs.utk.edu/lapack-forum")
+- SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.netlib.org/lapack")
+- SET(CPACK_NSIS_CONTACT "lapack@eecs.utk.edu")
+- SET(CPACK_NSIS_MODIFY_PATH ON)
+- SET(CPACK_NSIS_DISPLAY_NAME "LAPACK-${LAPACK_VERSION}")
+- set(CPACK_PACKAGE_RELOCATABLE "true")
+-ELSE(WIN32 AND NOT UNIX)
+- SET(CPACK_GENERATOR "TGZ")
+- SET(CPACK_SOURCE_GENERATOR TGZ)
+- SET(CPACK_SOURCE_PACKAGE_FILE_NAME "lapack-${LAPACK_VERSION}" )
+- SET(CPACK_SOURCE_IGNORE_FILES ~$ .svn ${CPACK_SOURCE_IGNORE_FILES} )
+-ENDIF(WIN32 AND NOT UNIX)
+-INCLUDE(CPack)
++endif(BUILD_LAPACKE)
+
+
+-# --------------------------------------------------
+-# By default static library
+-OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF )
+-OPTION(BUILD_STATIC_LIBS "Build static libraries" ON )
+-#OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON )
+-
+-if(NOT BLAS_FOUND)
+- set(ALL_TARGETS ${ALL_TARGETS} blas)
+-endif(NOT BLAS_FOUND)
+-
+-if(NOT LATESTLAPACK_FOUND)
+- set(ALL_TARGETS ${ALL_TARGETS} lapack)
+-endif(NOT LATESTLAPACK_FOUND)
+-
+-if(BUILD_TESTING OR LAPACKE_WITH_TMG)
+- set(ALL_TARGETS ${ALL_TARGETS} tmglib)
+-endif(BUILD_TESTING OR LAPACKE_WITH_TMG)
+-
+-# Export lapack targets, not including lapacke, from the
+-# install tree, if any.
+-set(_lapack_config_install_guard_target "")
+-if(ALL_TARGETS)
+- install(EXPORT lapack-targets
+- DESTINATION ${LIBRARY_DIR}/cmake/lapack-${LAPACK_VERSION})
+-
+- # Choose one of the lapack targets to use as a guard for
+- # lapack-config.cmake to load targets from the install tree.
+- list(GET ALL_TARGETS 0 _lapack_config_install_guard_target)
++# Neither user specified or optimized BLAS libraries can be used
++if(NEED_BLAS AND NOT BLAS_FOUND)
++ message(FATAL_ERROR "--> No BLAS library found. Specify BLAS_LIBRARIES or enable USE_OPTIMIZED_BLAS or BUILD_BLAS.")
+ endif()
+
+-# Include cblas in targets exported from the build tree.
+-if(CBLAS)
+- set(ALL_TARGETS ${ALL_TARGETS} cblas)
+-endif(CBLAS)
+-
+-# Include lapacke in targets exported from the build tree.
+-if(LAPACKE)
+- set(ALL_TARGETS ${ALL_TARGETS} lapacke)
+-endif(LAPACKE)
+-
+-# Export lapack and lapacke targets from the build tree, if any.
+-set(_lapack_config_build_guard_target "")
+-if(ALL_TARGETS)
+- export(TARGETS ${ALL_TARGETS} FILE lapack-targets.cmake)
+-
+- # Choose one of the lapack or lapacke targets to use as a guard
+- # for lapack-config.cmake to load targets from the build tree.
+- list(GET ALL_TARGETS 0 _lapack_config_build_guard_target)
++# Neither user specified or optimized LAPACK libraries can be used
++if(NEED_LAPACK AND NOT LAPACK_FOUND)
++ message(FATAL_ERROR "--> No LAPACK library found. Specify LAPACK_LIBRARIES or enable USE_OPTIMIZED_LAPACK or BUILD_LAPACK.")
+ endif()
+-
+-configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-build.cmake.in
+- ${LAPACK_BINARY_DIR}/lapack-config.cmake @ONLY)
+-
+-
+-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc @ONLY)
+- install(FILES
+- ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc
+- DESTINATION ${PKG_CONFIG_DIR}
+- )
+-
+-configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-install.cmake.in
+- ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake @ONLY)
+-
+-include(CMakePackageConfigHelpers)
+-write_basic_package_version_file(
+- ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
+- VERSION ${LAPACK_VERSION}
+- COMPATIBILITY SameMajorVersion
+- )
+-
+-install(FILES
+- ${LAPACK_BINARY_DIR}/CMakeFiles/lapack-config.cmake
+- ${LAPACK_BINARY_DIR}/lapack-config-version.cmake
+- DESTINATION ${LIBRARY_DIR}/cmake/lapack-${LAPACK_VERSION}
+- )
+diff --git a/LAPACKE/CMakeLists.txt b/LAPACKE/CMakeLists.txt
+--- a/LAPACKE/CMakeLists.txt
++++ b/LAPACKE/CMakeLists.txt
+@@ -1,8 +1,6 @@
+ message(STATUS "LAPACKE enable")
+ enable_language(C)
+
+-set(LAPACK_INSTALL_EXPORT_NAME lapacke-targets)
+-
+ # Create a header file netlib.h for the routines called in my C programs
+ include(FortranCInterface)
+ FortranCInterface_HEADER( ${CMAKE_CURRENT_SOURCE_DIR}/include/lapacke_mangling.h
+@@ -74,19 +72,3 @@
+ ${CMAKE_CURRENT_BINARY_DIR}/lapacke.pc
+ DESTINATION ${PKG_CONFIG_DIR}
+ )
+-
+-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/lapacke-config-version.cmake.in
+- ${LAPACK_BINARY_DIR}/lapacke-config-version.cmake @ONLY)
+-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/lapacke-config-build.cmake.in
+- ${LAPACK_BINARY_DIR}/lapacke-config.cmake @ONLY)
+-
+-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/lapacke-config-install.cmake.in
+- ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/lapacke-config.cmake @ONLY)
+-install(FILES
+- ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/lapacke-config.cmake
+- ${LAPACK_BINARY_DIR}/lapacke-config-version.cmake
+- DESTINATION lib/cmake/lapacke-${LAPACK_VERSION}
+- )
+-
+-install(EXPORT lapacke-targets
+- DESTINATION lib/cmake/lapacke-${LAPACK_VERSION})
+diff --git a/LAPACKE/cmake/lapacke-config-build.cmake.in b/LAPACKE/cmake/lapacke-config-build.cmake.in
+deleted file mode 100644
+--- a/LAPACKE/cmake/lapacke-config-build.cmake.in
++++ /dev/null
+@@ -1,14 +0,0 @@
+-# Load the LAPACK package with which we were built.
+-set(LAPACK_DIR "@LAPACK_BINARY_DIR@")
+-find_package(LAPACK NO_MODULE)
+-
+-# Load lapack targets from the build tree, including lapacke targets.
+-if(NOT TARGET lapacke)
+- include("@LAPACK_BINARY_DIR@/lapack-targets.cmake")
+-endif()
+-
+-# Report lapacke header search locations.
+-set(LAPACKE_INCLUDE_DIRS "@LAPACK_SOURCE_DIR@/lapacke/include")
+-
+-# Report lapacke libraries.
+-set(LAPACKE_LIBRARIES lapacke)
+diff --git a/LAPACKE/cmake/lapacke-config-install.cmake.in b/LAPACKE/cmake/lapacke-config-install.cmake.in
+deleted file mode 100644
+--- a/LAPACKE/cmake/lapacke-config-install.cmake.in
++++ /dev/null
+@@ -1,23 +0,0 @@
+-# Compute locations from <prefix>/lib/cmake/lapacke-<v>/<self>.cmake
+-get_filename_component(_LAPACKE_SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
+-get_filename_component(_LAPACKE_PREFIX "${_LAPACKE_SELF_DIR}" PATH)
+-get_filename_component(_LAPACKE_PREFIX "${_LAPACKE_PREFIX}" PATH)
+-get_filename_component(_LAPACKE_PREFIX "${_LAPACKE_PREFIX}" PATH)
+-
+-# Load the LAPACK package with which we were built.
+-set(LAPACK_DIR "${_LAPACKE_PREFIX}/lib/cmake/lapack-@LAPACK_VERSION@")
+-find_package(LAPACK NO_MODULE)
+-
+-# Load lapacke targets from the install tree.
+-if(NOT TARGET lapacke)
+- include(${_LAPACKE_SELF_DIR}/lapacke-targets.cmake)
+-endif()
+-
+-# Report lapacke header search locations.
+-set(LAPACKE_INCLUDE_DIRS ${_LAPACKE_PREFIX}/include)
+-
+-# Report lapacke libraries.
+-set(LAPACKE_LIBRARIES lapacke)
+-
+-unset(_LAPACKE_PREFIX)
+-unset(_LAPACKE_SELF_DIR)
+diff --git a/LAPACKE/cmake/lapacke-config-version.cmake.in b/LAPACKE/cmake/lapacke-config-version.cmake.in
+deleted file mode 100644
+--- a/LAPACKE/cmake/lapacke-config-version.cmake.in
++++ /dev/null
+@@ -1,8 +0,0 @@
+-set(PACKAGE_VERSION "@LAPACK_VERSION@")
+-if(NOT ${PACKAGE_FIND_VERSION} VERSION_GREATER ${PACKAGE_VERSION})
+- set(PACKAGE_VERSION_COMPATIBLE 1)
+- if(${PACKAGE_FIND_VERSION} VERSION_EQUAL ${PACKAGE_VERSION})
+- set(PACKAGE_VERSION_EXACT 1)
+- endif()
+-endif()
+-
diff --git a/libraries/blas/patches/generate-pkgconfig.diff b/libraries/blas/patches/generate-pkgconfig.diff
new file mode 100644
index 000000000000..f481ab80853d
--- /dev/null
+++ b/libraries/blas/patches/generate-pkgconfig.diff
@@ -0,0 +1,117 @@
+diff --git a/BLAS/CMakeLists.txt b/BLAS/CMakeLists.txt
+--- a/BLAS/CMakeLists.txt
++++ b/BLAS/CMakeLists.txt
+@@ -2,7 +2,7 @@
+ if(BUILD_TESTING)
+ add_subdirectory(TESTING)
+ endif(BUILD_TESTING)
+-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/blas.pc.in ${CMAKE_CURRENT_BINARY_DIR}/blas.pc)
++configure_file(${CMAKE_CURRENT_SOURCE_DIR}/blas.pc.in ${CMAKE_CURRENT_BINARY_DIR}/blas.pc @ONLY)
+ install(FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/blas.pc
+ DESTINATION ${PKG_CONFIG_DIR}
+diff --git a/BLAS/blas.pc.in b/BLAS/blas.pc.in
+--- a/BLAS/blas.pc.in
++++ b/BLAS/blas.pc.in
+@@ -1,7 +1,7 @@
+ prefix=@prefix@
+ libdir=@libdir@
+
+-Name: blas
++Name: BLAS
+ Description: Basic Linear Algebra Subprograms F77 reference implementations
+ Version: @LAPACK_VERSION@
+ URL: http://www.netlib.org/blas/
+diff --git a/CBLAS/CMakeLists.txt b/CBLAS/CMakeLists.txt
+--- a/CBLAS/CMakeLists.txt
++++ b/CBLAS/CMakeLists.txt
+@@ -71,7 +71,7 @@
+ ${LAPACK_BINARY_DIR}/cblas-config.cmake @ONLY)
+
+
+-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cblas.pc.in ${CMAKE_CURRENT_BINARY_DIR}/cblas.pc)
++configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cblas.pc.in ${CMAKE_CURRENT_BINARY_DIR}/cblas.pc @ONLY)
+ install(FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/cblas.pc
+ DESTINATION ${PKG_CONFIG_DIR}
+diff --git a/CBLAS/cblas.pc.in b/CBLAS/cblas.pc.in
+--- a/CBLAS/cblas.pc.in
++++ b/CBLAS/cblas.pc.in
+@@ -1,9 +1,9 @@
+ prefix=@prefix@
+ libdir=@libdir@
+
+-Name: lapacke
+-Description: C Standard Interface to BLAS Linear Algebra PACKage
++Name: CBLAS
++Description: C Standard Interface to BLAS Basic Linear Algebra Subprograms
+ Version: @LAPACK_VERSION@
+-URL: http://www.netlib.org/lapack/
++URL: http://www.netlib.org/blas/#_cblas
+ Libs: -L${libdir} -lcblas
+ Requires: blas
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -112,6 +112,13 @@
+ set(DSECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/dsecnd_${TIME_FUNC}.f)
+ set(PKG_CONFIG_DIR ${LIBRARY_DIR}/pkgconfig)
+
++set(prefix ${CMAKE_INSTALL_PREFIX})
++if(NOT IS_ABSOLUTE ${LIBRARY_DIR})
++ set(libdir "\${prefix}/${LIBRARY_DIR}")
++else()
++ set(libdir "${LIBRARY_DIR}")
++endif()
++
+ # --------------------------------------------------
+ # Precision to build
+ # By default all precisions are generated
+@@ -333,7 +340,7 @@
+ ${LAPACK_BINARY_DIR}/lapack-config.cmake @ONLY)
+
+
+-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc)
++configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc @ONLY)
+ install(FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/lapack.pc
+ DESTINATION ${PKG_CONFIG_DIR}
+diff --git a/LAPACKE/CMakeLists.txt b/LAPACKE/CMakeLists.txt
+--- a/LAPACKE/CMakeLists.txt
++++ b/LAPACKE/CMakeLists.txt
+@@ -65,7 +65,7 @@
+ endif(BUILD_TESTING)
+
+
+-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapacke.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapacke.pc)
++configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lapacke.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lapacke.pc @ONLY)
+ install(FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/lapacke.pc
+ DESTINATION ${PKG_CONFIG_DIR}
+diff --git a/LAPACKE/lapacke.pc.in b/LAPACKE/lapacke.pc.in
+--- a/LAPACKE/lapacke.pc.in
++++ b/LAPACKE/lapacke.pc.in
+@@ -1,9 +1,9 @@
+ prefix=@prefix@
+ libdir=@libdir@
+
+-Name: lapacke
++Name: LAPACKE
+ Description: C Standard Interface to LAPACK Linear Algebra PACKage
+ Version: @LAPACK_VERSION@
+-URL: http://www.netlib.org/lapack/
++URL: http://www.netlib.org/lapack/#_standard_c_language_apis_for_lapack
+ Libs: -L${libdir} -llapacke
+ Requires: lapack blas
+diff --git a/lapack.pc.in b/lapack.pc.in
+--- a/lapack.pc.in
++++ b/lapack.pc.in
+@@ -1,7 +1,7 @@
+ prefix=@prefix@
+ libdir=@libdir@
+
+-Name: lapack
++Name: LAPACK
+ Description: FORTRAN reference implementation of LAPACK Linear Algebra PACKage
+ Version: @LAPACK_VERSION@
+ URL: http://www.netlib.org/lapack/
diff --git a/libraries/blas/patches/link-dependencies.diff b/libraries/blas/patches/link-dependencies.diff
new file mode 100644
index 000000000000..31a2bcc6424f
--- /dev/null
+++ b/libraries/blas/patches/link-dependencies.diff
@@ -0,0 +1,232 @@
+diff --git a/BLAS/SRC/CMakeLists.txt b/BLAS/SRC/CMakeLists.txt
+--- a/BLAS/SRC/CMakeLists.txt
++++ b/BLAS/SRC/CMakeLists.txt
+@@ -137,13 +137,9 @@
+
+
+ add_library(blas ${ALLOBJ})
+-#if(UNIX)
+-# target_link_libraries(blas m)
+-#endif()
+ set_target_properties(
+ blas PROPERTIES
+ VERSION ${LAPACK_VERSION}
+ SOVERSION ${LAPACK_MAJOR_VERSION}
+ )
+-target_link_libraries(blas)
+ lapack_install_library(blas)
+diff --git a/BLAS/blas.pc.in b/BLAS/blas.pc.in
+--- a/BLAS/blas.pc.in
++++ b/BLAS/blas.pc.in
+@@ -6,4 +6,3 @@
+ Version: @LAPACK_VERSION@
+ URL: http://www.netlib.org/blas/
+ Libs: -L${libdir} -lblas
+-Libs.private: -lm
+diff --git a/CBLAS/cblas.pc.in b/CBLAS/cblas.pc.in
+--- a/CBLAS/cblas.pc.in
++++ b/CBLAS/cblas.pc.in
+@@ -6,4 +6,4 @@
+ Version: @LAPACK_VERSION@
+ URL: http://www.netlib.org/blas/#_cblas
+ Libs: -L${libdir} -lcblas
+-Requires: blas
++Requires.private: blas
+diff --git a/CBLAS/examples/CMakeLists.txt b/CBLAS/examples/CMakeLists.txt
+--- a/CBLAS/examples/CMakeLists.txt
++++ b/CBLAS/examples/CMakeLists.txt
+@@ -1,8 +1,8 @@
+ add_executable(xexample1_CBLAS cblas_example1.c )
+ add_executable(xexample2_CBLAS cblas_example2.c )
+
+-target_link_libraries(xexample1_CBLAS cblas ${BLAS_LIBRARIES})
+-target_link_libraries(xexample2_CBLAS cblas ${BLAS_LIBRARIES})
++target_link_libraries(xexample1_CBLAS cblas)
++target_link_libraries(xexample2_CBLAS cblas)
+
+ add_test(example1_CBLAS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample1_CBLAS)
+ add_test(example2_CBLAS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample2_CBLAS)
+diff --git a/CBLAS/src/CMakeLists.txt b/CBLAS/src/CMakeLists.txt
+--- a/CBLAS/src/CMakeLists.txt
++++ b/CBLAS/src/CMakeLists.txt
+@@ -164,5 +164,9 @@
+ endif(CBLAS_COMPLEX16)
+
+ add_library(cblas ${ALLOBJ})
+-target_link_libraries(cblas ${BLAS_LIBRARIES} )
++target_link_libraries(cblas PRIVATE ${BLAS_LIBRARIES})
++set_target_properties(
++ cblas PROPERTIES
++ LINKER_LANGUAGE C
++ )
+ lapack_install_library(cblas)
+diff --git a/CBLAS/testing/CMakeLists.txt b/CBLAS/testing/CMakeLists.txt
+--- a/CBLAS/testing/CMakeLists.txt
++++ b/CBLAS/testing/CMakeLists.txt
+@@ -55,9 +55,9 @@
+ add_executable(xscblat2 c_sblat2.f ${STESTL2O} ${LAPACK_BINARY_DIR}/include/cblas_test.h)
+ add_executable(xscblat3 c_sblat3.f ${STESTL3O} ${LAPACK_BINARY_DIR}/include/cblas_test.h)
+
+- target_link_libraries(xscblat1 cblas ${BLAS_LIBRARIES})
+- target_link_libraries(xscblat2 cblas ${BLAS_LIBRARIES})
+- target_link_libraries(xscblat3 cblas ${BLAS_LIBRARIES})
++ target_link_libraries(xscblat1 cblas)
++ target_link_libraries(xscblat2 cblas)
++ target_link_libraries(xscblat3 cblas)
+
+ add_cblas_test(stest1.out "" xscblat1)
+ add_cblas_test(stest2.out sin2 xscblat2)
+@@ -71,9 +71,9 @@
+ add_executable(xdcblat2 c_dblat2.f ${DTESTL2O} ${LAPACK_BINARY_DIR}/include/cblas_test.h)
+ add_executable(xdcblat3 c_dblat3.f ${DTESTL3O} ${LAPACK_BINARY_DIR}/include/cblas_test.h)
+
+- target_link_libraries(xdcblat1 cblas ${BLAS_LIBRARIES})
+- target_link_libraries(xdcblat2 cblas ${BLAS_LIBRARIES})
+- target_link_libraries(xdcblat3 cblas ${BLAS_LIBRARIES})
++ target_link_libraries(xdcblat1 cblas)
++ target_link_libraries(xdcblat2 cblas)
++ target_link_libraries(xdcblat3 cblas)
+
+ add_cblas_test(dtest1.out "" xdcblat1)
+ add_cblas_test(dtest2.out din2 xdcblat2)
+@@ -87,9 +87,9 @@
+ add_executable(xccblat2 c_cblat2.f ${CTESTL2O} ${LAPACK_BINARY_DIR}/include/cblas_test.h)
+ add_executable(xccblat3 c_cblat3.f ${CTESTL3O} ${LAPACK_BINARY_DIR}/include/cblas_test.h)
+
+- target_link_libraries(xccblat1 cblas ${BLAS_LIBRARIES})
+- target_link_libraries(xccblat2 cblas ${BLAS_LIBRARIES})
+- target_link_libraries(xccblat3 cblas ${BLAS_LIBRARIES})
++ target_link_libraries(xccblat1 cblas)
++ target_link_libraries(xccblat2 cblas)
++ target_link_libraries(xccblat3 cblas)
+
+ add_cblas_test(ctest1.out "" xccblat1)
+ add_cblas_test(ctest2.out cin2 xccblat2)
+@@ -103,9 +103,9 @@
+ add_executable(xzcblat2 c_zblat2.f ${ZTESTL2O} ${LAPACK_BINARY_DIR}/include/cblas_test.h)
+ add_executable(xzcblat3 c_zblat3.f ${ZTESTL3O} ${LAPACK_BINARY_DIR}/include/cblas_test.h)
+
+- target_link_libraries(xzcblat1 cblas ${BLAS_LIBRARIES})
+- target_link_libraries(xzcblat2 cblas ${BLAS_LIBRARIES})
+- target_link_libraries(xzcblat3 cblas ${BLAS_LIBRARIES})
++ target_link_libraries(xzcblat1 cblas)
++ target_link_libraries(xzcblat2 cblas)
++ target_link_libraries(xzcblat3 cblas)
+
+ add_cblas_test(ztest1.out "" xzcblat1)
+ add_cblas_test(ztest2.out zin2 xzcblat2)
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -1,5 +1,5 @@
+ cmake_minimum_required(VERSION 2.8.10)
+-project(LAPACK Fortran)
++project(LAPACK C Fortran)
+
+ set(LAPACK_MAJOR_VERSION 3)
+ set(LAPACK_MINOR_VERSION 6)
+diff --git a/LAPACKE/CMakeLists.txt b/LAPACKE/CMakeLists.txt
+--- a/LAPACKE/CMakeLists.txt
++++ b/LAPACKE/CMakeLists.txt
+@@ -46,17 +46,21 @@
+
+ if (USE_XBLAS)
+ add_library(lapacke ${SRC_OBJ} ${SRCX_OBJ} ${UTILS_OBJ})
+- target_link_libraries(lapacke ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} ${XBLAS_LIBRARY})
++ target_link_libraries(lapacke PRIVATE ${LAPACK_LIBRARIES})
+ else (USE_XBLAS)
+ if (LAPACKE_WITH_TMG)
+ add_library(lapacke ${SRC_OBJ} ${MATGEN_OBJ} ${UTILS_OBJ})
+- target_link_libraries(lapacke tmglib ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
++ target_link_libraries(lapacke PRIVATE tmglib ${LAPACK_LIBRARIES})
+ else (LAPACKE_WITH_TMG)
+ add_library(lapacke ${SRC_OBJ} ${UTILS_OBJ})
+- target_link_libraries(lapacke ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
++ target_link_libraries(lapacke PRIVATE ${LAPACK_LIBRARIES})
+ endif(LAPACKE_WITH_TMG)
+ endif(USE_XBLAS)
+
++set_target_properties(
++ lapacke PROPERTIES
++ LINKER_LANGUAGE C
++ )
+ lapack_install_library(lapacke)
+ INSTALL( FILES ${LAPACKE_INCLUDE} DESTINATION include )
+
+diff --git a/LAPACKE/example/CMakeLists.txt b/LAPACKE/example/CMakeLists.txt
+--- a/LAPACKE/example/CMakeLists.txt
++++ b/LAPACKE/example/CMakeLists.txt
+@@ -3,10 +3,10 @@
+ add_executable(xexample_DGELS_rowmajor example_DGELS_rowmajor.c lapacke_example_aux.c lapacke_example_aux.h)
+ add_executable(xexample_DGELS_colmajor example_DGELS_colmajor.c lapacke_example_aux.c lapacke_example_aux.h)
+
+-target_link_libraries(xexample_DGESV_rowmajor lapacke ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
+-target_link_libraries(xexample_DGESV_colmajor lapacke ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
+-target_link_libraries(xexample_DGELS_rowmajor lapacke ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
+-target_link_libraries(xexample_DGELS_colmajor lapacke ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
++target_link_libraries(xexample_DGESV_rowmajor lapacke)
++target_link_libraries(xexample_DGESV_colmajor lapacke)
++target_link_libraries(xexample_DGELS_rowmajor lapacke)
++target_link_libraries(xexample_DGELS_colmajor lapacke)
+
+ add_test(example_DGESV_rowmajor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGESV_rowmajor)
+ add_test(example_DGESV_colmajor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGESV_colmajor)
+diff --git a/LAPACKE/lapacke.pc.in b/LAPACKE/lapacke.pc.in
+--- a/LAPACKE/lapacke.pc.in
++++ b/LAPACKE/lapacke.pc.in
+@@ -6,4 +6,4 @@
+ Version: @LAPACK_VERSION@
+ URL: http://www.netlib.org/lapack/#_standard_c_language_apis_for_lapack
+ Libs: -L${libdir} -llapacke
+-Requires: lapack blas
++Requires.private: lapack
+diff --git a/SRC/CMakeLists.txt b/SRC/CMakeLists.txt
+--- a/SRC/CMakeLists.txt
++++ b/SRC/CMakeLists.txt
+@@ -455,12 +455,10 @@
+ list(REMOVE_DUPLICATES ALLOBJ)
+
+ add_library(lapack ${ALLOBJ} ${ALLXOBJ})
+-target_link_libraries(lapack ${BLAS_LIBRARIES} ${XBLAS_LIBRARY})
+-
++target_link_libraries(lapack PRIVATE ${BLAS_LIBRARIES} ${XBLAS_LIBRARY})
+ set_target_properties(
+ lapack PROPERTIES
+ VERSION ${LAPACK_VERSION}
+ SOVERSION ${LAPACK_MAJOR_VERSION}
+ )
+-
+ lapack_install_library(lapack)
+diff --git a/TESTING/EIG/CMakeLists.txt b/TESTING/EIG/CMakeLists.txt
+--- a/TESTING/EIG/CMakeLists.txt
++++ b/TESTING/EIG/CMakeLists.txt
+@@ -119,7 +119,7 @@
+
+ macro(add_eig_executable name )
+ add_executable(${name} ${ARGN})
+- target_link_libraries(${name} tmglib ${LAPACK_LIBRARIES})
++ target_link_libraries(${name} tmglib ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
+ endmacro(add_eig_executable)
+
+ if (BUILD_SINGLE)
+diff --git a/TESTING/LIN/CMakeLists.txt b/TESTING/LIN/CMakeLists.txt
+--- a/TESTING/LIN/CMakeLists.txt
++++ b/TESTING/LIN/CMakeLists.txt
+@@ -193,7 +193,7 @@
+
+ macro(add_lin_executable name )
+ add_executable(${name} ${ARGN})
+- target_link_libraries(${name} tmglib ${LAPACK_LIBRARIES})
++ target_link_libraries(${name} tmglib ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
+ endmacro(add_lin_executable)
+
+ IF(BUILD_SINGLE)
+diff --git a/lapack.pc.in b/lapack.pc.in
+--- a/lapack.pc.in
++++ b/lapack.pc.in
+@@ -6,4 +6,4 @@
+ Version: @LAPACK_VERSION@
+ URL: http://www.netlib.org/lapack/
+ Libs: -L${libdir} -llapack
+-Requires: blas
++Requires.private: blas
diff --git a/libraries/blas/patches/target-cleanup.diff b/libraries/blas/patches/target-cleanup.diff
new file mode 100644
index 000000000000..8f1529437484
--- /dev/null
+++ b/libraries/blas/patches/target-cleanup.diff
@@ -0,0 +1,776 @@
+diff --git a/BLAS/SRC/CMakeLists.txt b/BLAS/SRC/CMakeLists.txt
+--- a/BLAS/SRC/CMakeLists.txt
++++ b/BLAS/SRC/CMakeLists.txt
+@@ -113,29 +113,22 @@
+
+ set(ZBLAS3 zgemm.f zsymm.f zsyrk.f zsyr2k.f ztrmm.f ztrsm.f
+ zhemm.f zherk.f zher2k.f)
+-# default build all of it
+-set(ALLOBJ ${SBLAS1} ${SBLAS2} ${SBLAS3} ${DBLAS1} ${DBLAS2} ${DBLAS3}
+- ${CBLAS1} ${CBLAS2} ${CBLAS3} ${ZBLAS1}
+- ${ZBLAS2} ${ZBLAS3} ${ALLBLAS})
+-
+-if(BLAS_SINGLE)
+- set(ALLOBJ ${SBLAS1} ${ALLBLAS}
+- ${SBLAS2} ${SBLAS3})
++
++set(ALLOBJ)
++if(BUILD_SINGLE)
++ list(APPEND ALLOBJ ${SBLAS1} ${ALLBLAS} ${SBLAS2} ${SBLAS3})
+ endif()
+-if(BLAS_DOUBLE)
+- set(ALLOBJ ${DBLAS1} ${ALLBLAS}
+- ${DBLAS2} ${DBLAS3})
++if(BUILD_DOUBLE)
++ list(APPEND ALLOBJ ${DBLAS1} ${ALLBLAS} ${DBLAS2} ${DBLAS3})
+ endif()
+-if(BLAS_COMPLEX)
+- set(ALLOBJ ${BLASLIB} ${CBLAS1} ${CB1AUX}
+- ${ALLBLAS} ${CBLAS2})
++if(BUILD_COMPLEX)
++ list(APPEND ALLOBJ ${BLASLIB} ${CBLAS1} ${CB1AUX} ${ALLBLAS} ${CBLAS2} ${CBLAS3})
+ endif()
+-if(BLAS_COMPLEX16)
+- set(ALLOBJ ${BLASLIB} ${ZBLAS1} ${ZB1AUX}
+- ${ALLBLAS} ${ZBLAS2} ${ZBLAS3})
++if(BUILD_COMPLEX16)
++ list(APPEND ALLOBJ ${BLASLIB} ${ZBLAS1} ${ZB1AUX} ${ALLBLAS} ${ZBLAS2} ${ZBLAS3})
+ endif()
+-
+-
++list(REMOVE_DUPLICATES ALLOBJ)
++
+ add_library(blas ${ALLOBJ})
+ set_target_properties(
+ blas PROPERTIES
+diff --git a/CBLAS/CMakeLists.txt b/CBLAS/CMakeLists.txt
+--- a/CBLAS/CMakeLists.txt
++++ b/CBLAS/CMakeLists.txt
+@@ -65,9 +65,9 @@
+ list(GET ALL_TARGETS 0 _cblas_config_build_guard_target)
+ endif()
+
+-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMAKE/cblas-config-version.cmake.in
++configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cblas-config-version.cmake.in
+ ${LAPACK_BINARY_DIR}/cblas-config-version.cmake @ONLY)
+-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMAKE/cblas-config-build.cmake.in
++configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cblas-config-build.cmake.in
+ ${LAPACK_BINARY_DIR}/cblas-config.cmake @ONLY)
+
+
+diff --git a/CBLAS/src/CMakeLists.txt b/CBLAS/src/CMakeLists.txt
+--- a/CBLAS/src/CMakeLists.txt
++++ b/CBLAS/src/CMakeLists.txt
+@@ -28,34 +28,26 @@
+ cblas_ddot.c cblas_dsdot.c cblas_dnrm2.c cblas_dasum.c
+ cblas_idamax.c ddotsub.f dsdotsub.f dnrm2sub.f
+ dasumsub.f idamaxsub.f)
+-
+ #
+ # All object files for single complex precision
+ #
+ set (CLEV1 cblas_cswap.c cblas_cscal.c cblas_csscal.c cblas_ccopy.c
+ cblas_caxpy.c cblas_cdotu_sub.c cblas_cdotc_sub.c
+ cblas_icamax.c cdotcsub.f cdotusub.f icamaxsub.f)
+-
+ #
+ # All object files for double complex precision
+ #
+ set (ZLEV1 cblas_zswap.c cblas_zscal.c cblas_zdscal.c cblas_zcopy.c
+- cblas_zaxpy.c cblas_zdotu_sub.c cblas_zdotc_sub.c cblas_dznrm2.c
+- cblas_dzasum.c cblas_izamax.c zdotcsub.f zdotusub.f
+- dzasumsub.f dznrm2sub.f izamaxsub.f)
+-
+-
++ cblas_zaxpy.c cblas_zdotu_sub.c cblas_zdotc_sub.c
++ cblas_izamax.c zdotcsub.f zdotusub.f izamaxsub.f)
+ #
+ # Common files for single complex precision
+ #
+ set (SCLEV1 cblas_scasum.c scasumsub.f cblas_scnrm2.c scnrm2sub.f)
+-
+-
+ #
+-# All object files
++# Common files for double complex precision
+ #
+-set (ALEV1 ${slev1} ${dlev1} ${clev1} ${zlev1} ${sclev1})
+-
++set (DZLEV1 cblas_dzasum.c dzasumsub.f cblas_dznrm2.c dznrm2sub.f)
+
+ #
+ #
+@@ -72,8 +64,6 @@
+ cblas_sspr.c cblas_sspr2.c cblas_ssymv.c cblas_ssyr.c cblas_ssyr2.c
+ cblas_stbmv.c cblas_stbsv.c cblas_stpmv.c cblas_stpsv.c cblas_strmv.c
+ cblas_strsv.c)
+-
+-
+ #
+ # All object files for double real precision
+ #
+@@ -81,7 +71,6 @@
+ cblas_dspr.c cblas_dspr2.c cblas_dsymv.c cblas_dsyr.c cblas_dsyr2.c
+ cblas_dtbmv.c cblas_dtbsv.c cblas_dtpmv.c cblas_dtpsv.c cblas_dtrmv.c
+ cblas_dtrsv.c)
+-
+ #
+ # All object files for single complex precision
+ #
+@@ -89,7 +78,6 @@
+ cblas_ctrmv.c cblas_ctbmv.c cblas_ctpmv.c cblas_ctrsv.c cblas_ctbsv.c
+ cblas_ctpsv.c cblas_cgeru.c cblas_cgerc.c cblas_cher.c cblas_cher2.c
+ cblas_chpr.c cblas_chpr2.c)
+-
+ #
+ # All object files for double complex precision
+ #
+@@ -97,10 +85,6 @@
+ cblas_ztrmv.c cblas_ztbmv.c cblas_ztpmv.c cblas_ztrsv.c cblas_ztbsv.c
+ cblas_ztpsv.c cblas_zgeru.c cblas_zgerc.c cblas_zher.c cblas_zher2.c
+ cblas_zhpr.c cblas_zhpr2.c)
+-#
+-# All object files
+-#
+-set (AVEL2 ${slev2} ${dlev2} ${clev2} ${zlev2})
+
+ #
+ #
+@@ -132,36 +116,21 @@
+ set (ZLEV3 cblas_zgemm.c cblas_zsymm.c cblas_zhemm.c cblas_zherk.c
+ cblas_zher2k.c cblas_ztrmm.c cblas_ztrsm.c cblas_zsyrk.c
+ cblas_zsyr2k.c)
+-#
+-# All object files
+-#
+-set (ALEV3 ${slev3} ${dlev3} ${clev3} ${zlev3})
+-
+-# default build all of it
+-set(ALLOBJ ${SCLEV1} ${SLEV1} ${SLEV2} ${SLEV3} ${ERRHAND}
+- ${DLEV1} ${DLEV2} ${DLEV3}
+- ${CLEV1} ${CLEV2} ${CLEV3}
+- ${ZLEV1} ${ZLEV2} ${ZLEV3} )
+-
+-# Single real precision
+-if(CBLAS_SINGLE)
+- set(ALLOBJ ${SCLEV1} ${SLEV1} ${SLEV2} ${SLEV3} ${ERRHAND})
+-endif(CBLAS_SINGLE)
+-
+-# Double real precision
+-if(CBLAS_DOUBLE)
+- set(ALLOBJ ${DLEV1} ${DLEV2} ${DLEV3} ${ERRHAND})
+-endif(CBLAS_DOUBLE)
+-
+-# Single complex precision
+-if (CBLAS_COMPLEX)
+- set(ALLOBJ ${CLEV1} ${SCLEV1} ${CLEV2} ${CLEV3} ${ERRHAND})
+-endif(CBLAS_COMPLEX)
+
+-# Double complex precision
+-if (CBLAS_COMPLEX16)
+- set(ALLOBJ ${ZLEV1} ${ZLEV2} ${ZLEV3} ${ERRHAND})
+-endif(CBLAS_COMPLEX16)
++set(ALLOBJ)
++if(BUILD_SINGLE)
++ list(APPEND ALLOBJ ${SLEV1} ${SCLEV1} ${ERRHAND} ${SLEV2} ${SLEV3})
++endif()
++if(BUILD_DOUBLE)
++ list(APPEND ALLOBJ ${DLEV1} ${DZLEV1} ${ERRHAND} ${DLEV2} ${DLEV3})
++endif()
++if(BUILD_COMPLEX)
++ list(APPEND ALLOBJ ${CLEV1} ${SCLEV1} ${ERRHAND} ${CLEV2} ${CLEV3})
++endif()
++if(BUILD_COMPLEX16)
++ list(APPEND ALLOBJ ${ZLEV1} ${DZLEV1} ${ERRHAND} ${ZLEV2} ${ZLEV3})
++endif()
++list(REMOVE_DUPLICATES ALLOBJ)
+
+ add_library(cblas ${ALLOBJ})
+ target_link_libraries(cblas PRIVATE ${BLAS_LIBRARIES})
+diff --git a/CBLAS/src/Makefile b/CBLAS/src/Makefile
+--- a/CBLAS/src/Makefile
++++ b/CBLAS/src/Makefile
+@@ -52,9 +52,8 @@
+ # All object files for double complex precision
+ #
+ zlev1 = cblas_zswap.o cblas_zscal.o cblas_zdscal.o cblas_zcopy.o \
+- cblas_zaxpy.o cblas_zdotu_sub.o cblas_zdotc_sub.o cblas_dznrm2.o \
+- cblas_dzasum.o cblas_izamax.o zdotcsub.o zdotusub.o \
+- dzasumsub.o dznrm2sub.o izamaxsub.o
++ cblas_zaxpy.o cblas_zdotu_sub.o cblas_zdotc_sub.o \
++ cblas_izamax.o zdotcsub.o zdotusub.o izamaxsub.o
+
+ #
+ # Common files for single / complex precision
+@@ -62,9 +61,14 @@
+ sclev1 = cblas_scasum.o scasumsub.o cblas_scnrm2.o scnrm2sub.o
+
+ #
++# Common files for double / complex precision
++#
++dzlev1 = cblas_dzasum.o dzasumsub.o cblas_dznrm2.o dznrm2sub.o
++
++#
+ # All object files
+ #
+-alev1 = $(slev1) $(dlev1) $(clev1) $(zlev1) $(sclev1)
++alev1 = $(slev1) $(dlev1) $(clev1) $(zlev1) $(sclev1) $(dzlev1)
+
+
+ #
+@@ -77,8 +81,8 @@
+ $(RANLIB) $(CBLASLIB)
+
+ # Double real precision
+-dlib1: $(dlev1)
+- $(ARCH) $(ARCHFLAGS) $(CBLASLIB) $(dlev1)
++dlib1: $(dlev1) $(dzlev1)
++ $(ARCH) $(ARCHFLAGS) $(CBLASLIB) $(dlev1) $(dzlev1)
+ $(RANLIB) $(CBLASLIB)
+
+ # Single complex precision
+@@ -87,8 +91,8 @@
+ $(RANLIB) $(CBLASLIB)
+
+ # Double complex precision
+-zlib1: $(zlev1)
+- $(ARCH) $(ARCHFLAGS) $(CBLASLIB) $(zlev1)
++zlib1: $(zlev1) $(dzlev1)
++ $(ARCH) $(ARCHFLAGS) $(CBLASLIB) $(zlev1) $(dzlev1)
+ $(RANLIB) $(CBLASLIB)
+
+ # All precisions
+diff --git a/CBLAS/testing/CMakeLists.txt b/CBLAS/testing/CMakeLists.txt
+--- a/CBLAS/testing/CMakeLists.txt
++++ b/CBLAS/testing/CMakeLists.txt
+@@ -28,8 +28,6 @@
+
+ # Object files for single real precision
+ SET( STESTL1O c_sblas1.c)
+-
+-SET( STESTL2O c_sblas2.c c_s2chke.c auxiliary.c c_xerbla.c)
+ SET( STESTL2O c_sblas2.c c_s2chke.c auxiliary.c c_xerbla.c)
+ SET( STESTL3O c_sblas3.c c_s3chke.c auxiliary.c c_xerbla.c)
+
+@@ -62,11 +60,9 @@
+ add_cblas_test(stest1.out "" xscblat1)
+ add_cblas_test(stest2.out sin2 xscblat2)
+ add_cblas_test(stest3.out sin3 xscblat3)
+-
+ endif()
+
+ if(BUILD_DOUBLE)
+-
+ add_executable(xdcblat1 c_dblat1.f ${DTESTL1O} ${LAPACK_BINARY_DIR}/include/cblas_test.h)
+ add_executable(xdcblat2 c_dblat2.f ${DTESTL2O} ${LAPACK_BINARY_DIR}/include/cblas_test.h)
+ add_executable(xdcblat3 c_dblat3.f ${DTESTL3O} ${LAPACK_BINARY_DIR}/include/cblas_test.h)
+@@ -78,11 +74,9 @@
+ add_cblas_test(dtest1.out "" xdcblat1)
+ add_cblas_test(dtest2.out din2 xdcblat2)
+ add_cblas_test(dtest3.out din3 xdcblat3)
+-
+ endif()
+
+ if(BUILD_COMPLEX)
+-
+ add_executable(xccblat1 c_cblat1.f ${CTESTL1O} ${LAPACK_BINARY_DIR}/include/cblas_test.h)
+ add_executable(xccblat2 c_cblat2.f ${CTESTL2O} ${LAPACK_BINARY_DIR}/include/cblas_test.h)
+ add_executable(xccblat3 c_cblat3.f ${CTESTL3O} ${LAPACK_BINARY_DIR}/include/cblas_test.h)
+@@ -94,11 +88,9 @@
+ add_cblas_test(ctest1.out "" xccblat1)
+ add_cblas_test(ctest2.out cin2 xccblat2)
+ add_cblas_test(ctest3.out cin3 xccblat3)
+-
+ endif()
+
+ if(BUILD_COMPLEX16)
+-
+ add_executable(xzcblat1 c_zblat1.f ${ZTESTL1O} ${LAPACK_BINARY_DIR}/include/cblas_test.h)
+ add_executable(xzcblat2 c_zblat2.f ${ZTESTL2O} ${LAPACK_BINARY_DIR}/include/cblas_test.h)
+ add_executable(xzcblat3 c_zblat3.f ${ZTESTL3O} ${LAPACK_BINARY_DIR}/include/cblas_test.h)
+@@ -110,5 +102,4 @@
+ add_cblas_test(ztest1.out "" xzcblat1)
+ add_cblas_test(ztest2.out zin2 xzcblat2)
+ add_cblas_test(ztest3.out zin3 xzcblat3)
+-
+ endif()
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -122,7 +122,33 @@
+ # --------------------------------------------------
+ # Precision to build
+ # By default all precisions are generated
++option(BUILD_SINGLE "Build Single Precision" ON)
++option(BUILD_DOUBLE "Build Double Precision" ON)
++option(BUILD_COMPLEX "Build Complex Precision" ON)
++option(BUILD_COMPLEX16 "Build Double Complex Precision" ON)
++
++set(PRECISIONS)
++if(BUILD_SINGLE)
++ message(STATUS "Building Single Precision")
++ list(APPEND PRECISIONS "single")
++endif()
++if(BUILD_DOUBLE)
++ message(STATUS "Building Double Precision")
++ list(APPEND PRECISIONS "double")
++endif()
++if(BUILD_COMPLEX)
++ message(STATUS "Building Complex Precision")
++ list(APPEND PRECISIONS "complex")
++endif()
++if(BUILD_COMPLEX16)
++ message(STATUS "Building Double Complex Precision")
++ list(APPEND PRECISIONS "complex16")
++endif()
+
++if(NOT PRECISIONS)
++ message(FATAL_ERROR "--> Nothing to build, no precision selected.
++ Please enable at least one of these: BUILD_SINGLE, BUILD_DOUBLE, BUILD_COMPLEX, BUILD_COMPLEX16.")
++endif()
+
+ # --------------------------------------------------
+ # Subdirectories that need to be processed
+@@ -214,10 +240,6 @@
+ if(NOT LATESTLAPACK_FOUND)
+ message(STATUS "Using supplied NETLIB LAPACK implementation")
+ set( LAPACK_LIBRARIES lapack )
+- option(BUILD_SINGLE "Build LAPACK Single Precision" ON)
+- option(BUILD_DOUBLE "Build LAPACK Double Precision" ON)
+- option(BUILD_COMPLEX "Build LAPACK Complex Precision" ON)
+- option(BUILD_COMPLEX16 "Build LAPACK Double Complex Precision" ON)
+ add_subdirectory(SRC)
+ else()
+ set( CMAKE_EXE_LINKER_FLAGS
+diff --git a/SRC/CMakeLists.txt b/SRC/CMakeLists.txt
+--- a/SRC/CMakeLists.txt
++++ b/SRC/CMakeLists.txt
+@@ -1,22 +1,28 @@
+ #######################################################################
+ # This is the makefile to create a library for LAPACK.
+ # The files are organized as follows:
+-# ALLAUX -- Auxiliary routines called from all precisions
+-# ALLXAUX -- Auxiliary routines called from all precisions but
+-# only from routines using extra precision.
+-# SCLAUX -- Auxiliary routines called from both REAL and COMPLEX
+-# DZLAUX -- Auxiliary routines called from both DOUBLE PRECISION
+-# and COMPLEX*16
+-# SLASRC -- Single precision real LAPACK routines
++# ALLAUX -- Auxiliary routines called from all precisions
++#
++# SCLAUX -- Auxiliary routines called from both REAL and COMPLEX.
++# DZLAUX -- Auxiliary routines called from both DOUBLE and COMPLEX*16.
++#
++# DSLASRC -- Double-single mixed precision real routines called from
++# single, single-extra and double precision real LAPACK
++# routines (i.e. from SLASRC, SXLASRC, DLASRC).
++# ZCLASRC -- Double-single mixed precision complex routines called from
++# single, single-extra and double precision complex LAPACK
++# routines (i.e. from CLASRC, CXLASRC, ZLASRC).
++#
++# SLASRC -- Single precision real LAPACK routines
+ # SXLASRC -- Single precision real LAPACK routines using extra
+ # precision.
+-# CLASRC -- Single precision complex LAPACK routines
++# CLASRC -- Single precision complex LAPACK routines
+ # CXLASRC -- Single precision complex LAPACK routines using extra
+ # precision.
+-# DLASRC -- Double precision real LAPACK routines
++# DLASRC -- Double precision real LAPACK routines
+ # DXLASRC -- Double precision real LAPACK routines using extra
+ # precision.
+-# ZLASRC -- Double precision complex LAPACK routines
++# ZLASRC -- Double precision complex LAPACK routines
+ # ZXLASRC -- Double precision complex LAPACK routines using extra
+ # precision.
+ #
+@@ -51,8 +57,6 @@
+ ../INSTALL/ilaver.f ../INSTALL/lsame.f xerbla.f xerbla_array.f
+ ../INSTALL/slamch.f)
+
+-set(ALLXAUX )
+-
+ set(SCLAUX
+ sbdsdc.f
+ sbdsqr.f sdisna.f slabad.f slacpy.f sladiv.f slae2.f slaebz.f
+@@ -97,8 +101,8 @@
+ sgels.f sgelsd.f sgelss.f sgelsy.f sgeql2.f sgeqlf.f
+ sgeqp3.f sgeqr2.f sgeqr2p.f sgeqrf.f sgeqrfp.f sgerfs.f sgerq2.f sgerqf.f
+ sgesc2.f sgesdd.f sgesv.f sgesvd.f sgesvdx.f sgesvx.f sgetc2.f sgetf2.f
+- sgetrf.f sgetrf2.f sgetri.f
+- sgetrs.f sggbak.f sggbal.f
++ sgetrf2.f sgetri.f
++ sggbak.f sggbal.f
+ sgges.f sgges3.f sggesx.f sggev.f sggev3.f sggevx.f
+ sggglm.f sgghrd.f sgghd3.f sgglse.f sggqrf.f
+ sggrqf.f sggsvd3.f sggsvp3.f sgtcon.f sgtrfs.f sgtsv.f
+@@ -123,7 +127,7 @@
+ sormr3.f sormrq.f sormrz.f sormtr.f spbcon.f spbequ.f spbrfs.f
+ spbstf.f spbsv.f spbsvx.f
+ spbtf2.f spbtrf.f spbtrs.f spocon.f spoequ.f sporfs.f sposv.f
+- sposvx.f spotf2.f spotrf.f spotrf2.f spotri.f spotrs.f spstrf.f spstf2.f
++ sposvx.f spotf2.f spotrf2.f spotri.f spstrf.f spstf2.f
+ sppcon.f sppequ.f
+ spprfs.f sppsv.f sppsvx.f spptrf.f spptri.f spptrs.f sptcon.f
+ spteqr.f sptrfs.f sptsv.f sptsvx.f spttrs.f sptts2.f srscl.f
+@@ -172,8 +176,8 @@
+ cgeqr2.f cgeqr2p.f cgeqrf.f cgeqrfp.f cgerfs.f cgerq2.f cgerqf.f
+ cgesc2.f cgesdd.f cgesv.f cgesvd.f cgesvdx.f
+ cgesvj.f cgejsv.f cgsvj0.f cgsvj1.f
+- cgesvx.f cgetc2.f cgetf2.f cgetrf.f cgetrf2.f
+- cgetri.f cgetrs.f
++ cgesvx.f cgetc2.f cgetf2.f cgetrf2.f
++ cgetri.f
+ cggbak.f cggbal.f
+ cgges.f cgges3.f cggesx.f cggev.f cggev3.f cggevx.f
+ cggglm.f cgghrd.f cgghd3.f cgglse.f cggqrf.f cggrqf.f
+@@ -207,7 +211,7 @@
+ claswp.f clasyf.f clasyf_rook.f clatbs.f clatdf.f clatps.f clatrd.f clatrs.f clatrz.f
+ clauu2.f clauum.f cpbcon.f cpbequ.f cpbrfs.f cpbstf.f cpbsv.f
+ cpbsvx.f cpbtf2.f cpbtrf.f cpbtrs.f cpocon.f cpoequ.f cporfs.f
+- cposv.f cposvx.f cpotf2.f cpotrf.f cpotrf2.f cpotri.f cpotrs.f cpstrf.f cpstf2.f
++ cposv.f cposvx.f cpotf2.f cpotrf2.f cpotri.f cpstrf.f cpstf2.f
+ cppcon.f cppequ.f cpprfs.f cppsv.f cppsvx.f cpptrf.f cpptri.f cpptrs.f
+ cptcon.f cpteqr.f cptrfs.f cptsv.f cptsvx.f cpttrf.f cpttrs.f cptts2.f
+ crot.f cspcon.f cspmv.f cspr.f csprfs.f cspsv.f
+@@ -409,52 +413,45 @@
+ zla_heamv.f zla_hercond_c.f zla_hercond_x.f zla_herpvgrw.f
+ zla_lin_berr.f zlarscl2.f zlascl2.f zla_wwaddw.f)
+
+-
+-if( USE_XBLAS)
+- set(ALLXOBJ ${SXLASRC} ${DXLASRC} ${CXLASRC} ${ZXLASRC} ${ALLXAUX})
++if(USE_XBLAS)
++ list(APPEND SLASRC ${SXLASRC})
++ list(APPEND DLASRC ${DXLASRC})
++ list(APPEND CLASRC ${CXLASRC})
++ list(APPEND ZLASRC ${ZXLASRC})
+ endif()
+
+ if(BUILD_DEPRECATED)
+- LIST(APPEND SLASRC DEPRECATED/sgegs.f DEPRECATED/sgegv.f
++ LIST(APPEND SLASRC DEPRECATED/sgegs.f DEPRECATED/sgegv.f
+ DEPRECATED/sgeqpf.f DEPRECATED/sgelsx.f DEPRECATED/sggsvd.f
+ DEPRECATED/sggsvp.f DEPRECATED/slahrd.f DEPRECATED/slatzm.f DEPRECATED/stzrqf.f)
+- LIST(APPEND DLASRC DEPRECATED/dgegs.f DEPRECATED/dgegv.f
++ LIST(APPEND DLASRC DEPRECATED/dgegs.f DEPRECATED/dgegv.f
+ DEPRECATED/dgeqpf.f DEPRECATED/dgelsx.f DEPRECATED/dggsvd.f
+- DEPRECATED/dggsvp.f DEPRECATED/dlahrd.f DEPRECATED/dlatzm.f DEPRECATED/dtzrqf.f )
++ DEPRECATED/dggsvp.f DEPRECATED/dlahrd.f DEPRECATED/dlatzm.f DEPRECATED/dtzrqf.f)
+ LIST(APPEND CLASRC DEPRECATED/cgegs.f DEPRECATED/cgegv.f
+ DEPRECATED/cgeqpf.f DEPRECATED/cgelsx.f DEPRECATED/cggsvd.f
+ DEPRECATED/cggsvp.f DEPRECATED/clahrd.f DEPRECATED/clatzm.f DEPRECATED/ctzrqf.f)
+ LIST(APPEND ZLASRC DEPRECATED/zgegs.f DEPRECATED/zgegv.f
+ DEPRECATED/zgeqpf.f DEPRECATED/zgelsx.f DEPRECATED/zggsvd.f
+ DEPRECATED/zggsvp.f DEPRECATED/zlahrd.f DEPRECATED/zlatzm.f DEPRECATED/ztzrqf.f)
+- message(STATUS "Building deprecated routines")
++ message(STATUS "Building LAPACK deprecated routines")
+ endif()
+
++set(ALLOBJ)
+ if(BUILD_SINGLE)
+-set(ALLOBJ ${SLASRC} ${ALLAUX} ${SCLAUX} )
+-message(STATUS "Building Single Precision")
++ list(APPEND ALLOBJ ${SLASRC} ${ALLAUX} ${SCLAUX} ${DSLASRC})
+ endif()
+ if(BUILD_DOUBLE)
+- set(ALLOBJ ${ALLOBJ} ${DLASRC} ${ALLAUX} ${DZLAUX} ${DSLASRC})
+-message(STATUS "Building Double Precision")
++ list(APPEND ALLOBJ ${DLASRC} ${ALLAUX} ${DZLAUX} ${DSLASRC})
+ endif()
+ if(BUILD_COMPLEX)
+- set(ALLOBJ ${ALLOBJ} ${CLASRC} ${ALLAUX} ${SCLAUX} )
+-message(STATUS "Building Complex Precision")
++ list(APPEND ALLOBJ ${CLASRC} ${ALLAUX} ${SCLAUX} ${ZCLASRC})
+ endif()
+ if(BUILD_COMPLEX16)
+- set(ALLOBJ ${ALLOBJ} ${ZLASRC} ${ALLAUX} ${DZLAUX} ${ZCLASRC})
+-message(STATUS "Building Double Complex Precision")
+-endif()
+-
+-if (NOT ALLOBJ)
+- message(FATAL_ERROR "-->LAPACK SRC BUILD: NOTHING TO BUILD, NO PRECISION SELECTED:
+- PLEASE ENABLE AT LEAST ONE OF THOSE: BUILD_SINGLE, BUILD_COMPLEX, BUILD_DOUBLE, BUILD_COMPLEX16.")
++ list(APPEND ALLOBJ ${ZLASRC} ${ALLAUX} ${DZLAUX} ${ZCLASRC})
+ endif()
+-
+ list(REMOVE_DUPLICATES ALLOBJ)
+
+-add_library(lapack ${ALLOBJ} ${ALLXOBJ})
++add_library(lapack ${ALLOBJ})
+ target_link_libraries(lapack PRIVATE ${BLAS_LIBRARIES} ${XBLAS_LIBRARY})
+ set_target_properties(
+ lapack PROPERTIES
+diff --git a/TESTING/CMakeLists.txt b/TESTING/CMakeLists.txt
+--- a/TESTING/CMakeLists.txt
++++ b/TESTING/CMakeLists.txt
+@@ -289,7 +289,7 @@
+ endif()
+
+
+-if (BUILD_SIMPLE)
++if (BUILD_SINGLE)
+ if (BUILD_DOUBLE)
+ #
+ # ======== SINGLE-DOUBLE PROTO LIN TESTS ==============
+diff --git a/TESTING/LIN/CMakeLists.txt b/TESTING/LIN/CMakeLists.txt
+--- a/TESTING/LIN/CMakeLists.txt
++++ b/TESTING/LIN/CMakeLists.txt
+@@ -13,10 +13,10 @@
+ schksp.f schksy.f schksy_rook.f schktb.f schktp.f schktr.f
+ schktz.f
+ sdrvgt.f sdrvls.f sdrvpb.f
+- sdrvpp.f sdrvpt.f sdrvsp.f sdrvsy.f sdrvsy_rook.f
++ sdrvpp.f sdrvpt.f sdrvsp.f sdrvsy_rook.f
+ serrgt.f serrlq.f serrls.f
+- serrpo.f serrps.f serrql.f serrqp.f serrqr.f
+- serrrq.f serrsy.f serrtr.f serrtz.f serrvx.f
++ serrps.f serrql.f serrqp.f serrqr.f
++ serrrq.f serrtr.f serrtz.f
+ sgbt01.f sgbt02.f sgbt05.f sgelqs.f sgeqls.f sgeqrs.f
+ sgerqs.f sget01.f sget02.f
+ sget03.f sget04.f sget06.f sget07.f sgtt01.f sgtt02.f
+@@ -37,9 +37,11 @@
+ sqrt04.f sqrt05.f schkqrt.f serrqrt.f schkqrtp.f serrqrtp.f)
+
+ if(USEXBLAS)
+- list(APPEND SLINTST sdrvgex.f serrgex.f sdrvgbx.f sdrvpox.f sebchvxx.f)
++ list(APPEND SLINTST serrvxx.f sdrvgex.f sdrvsyx.f serrgex.f sdrvgbx.f sdrvpox.f
++ sebchvxx.f serrsyx.f serrpox.f)
+ else()
+- list(APPEND SLINTST sdrvge.f serrge.f sdrvgb.f sdrvpo.f)
++ list(APPEND SLINTST serrvx.f sdrvge.f sdrvsy.f serrge.f sdrvgb.f sdrvpo.f
++ serrsy.f serrpo.f)
+ endif()
+
+ set(CLINTST cchkaa.f
+@@ -48,13 +50,12 @@
+ cchkpo.f cchkps.f cchkpp.f cchkpt.f cchkq3.f cchkql.f
+ cchkqr.f cchkrq.f cchksp.f cchksy.f cchksy_rook.f cchktb.f
+ cchktp.f cchktr.f cchktz.f
+- cdrvgt.f cdrvhe.f cdrvhe_rook.f cdrvhp.f
++ cdrvgt.f cdrvhe_rook.f cdrvhp.f
+ cdrvls.f cdrvpb.f cdrvpp.f cdrvpt.f
+- cdrvsp.f cdrvsy.f cdrvsy_rook.f
+- cerrgt.f cerrhe.f cerrlq.f
++ cdrvsp.f cdrvsy_rook.f
++ cerrgt.f cerrlq.f
+ cerrls.f cerrps.f cerrql.f cerrqp.f
+- cerrqr.f cerrrq.f cerrsy.f cerrtr.f cerrtz.f
+- cerrvx.f
++ cerrqr.f cerrrq.f cerrtr.f cerrtz.f
+ cgbt01.f cgbt02.f cgbt05.f cgelqs.f cgeqls.f cgeqrs.f
+ cgerqs.f cget01.f cget02.f
+ cget03.f cget04.f cget07.f cgtt01.f cgtt02.f
+@@ -77,10 +78,11 @@
+ cqrt04.f cqrt05.f cchkqrt.f cerrqrt.f cchkqrtp.f cerrqrtp.f )
+
+ if(USEXBLAS)
+- list(APPEND
+- CLINTST cdrvgex.f cdrvgbx.f cerrgex.f cdrvpox.f cerrpox.f cebchvxx.f)
++ list(APPEND CLINTST cerrvxx.f cdrvgex.f cdrvsyx.f cdrvgbx.f cerrgex.f cdrvpox.f
++ cdrvhex.f cerrpox.f cebchvxx.f cerrsyx.f cerrhex.f)
+ else()
+- list(APPEND CLINTST cdrvge.f cdrvgb.f cerrge.f cdrvpo.f cerrpo.f)
++ list(APPEND CLINTST cerrvx.f cdrvge.f cdrvsy.f cdrvgb.f cerrge.f cdrvpo.f
++ cdrvhe.f cerrpo.f cerrsy.f cerrhe.f)
+ endif()
+
+ set(DLINTST dchkaa.f
+@@ -90,10 +92,10 @@
+ dchksp.f dchksy.f dchksy_rook.f dchktb.f dchktp.f dchktr.f
+ dchktz.f
+ ddrvgt.f ddrvls.f ddrvpb.f
+- ddrvpp.f ddrvpt.f ddrvsp.f ddrvsy.f ddrvsy_rook.f
++ ddrvpp.f ddrvpt.f ddrvsp.f ddrvsy_rook.f
+ derrgt.f derrlq.f derrls.f
+ derrps.f derrql.f derrqp.f derrqr.f
+- derrrq.f derrsy.f derrtr.f derrtz.f derrvx.f
++ derrrq.f derrtr.f derrtz.f
+ dgbt01.f dgbt02.f dgbt05.f dgelqs.f dgeqls.f dgeqrs.f
+ dgerqs.f dget01.f dget02.f
+ dget03.f dget04.f dget06.f dget07.f dgtt01.f dgtt02.f
+@@ -114,11 +116,11 @@
+ dqrt04.f dqrt05.f dchkqrt.f derrqrt.f dchkqrtp.f derrqrtp.f )
+
+ if(USEXBLAS)
+- list(APPEND
+- DLINTST ddrvgex.f ddrvgbx.f derrgex.f ddrvpox.f derrpox.f debchvxx.f)
++ list(APPEND DLINTST derrvxx.f ddrvgex.f ddrvsyx.f ddrvgbx.f derrgex.f ddrvpox.f derrpox.f
++ debchvxx.f derrsyx.f)
+ else()
+- list(APPEND
+- DLINTST ddrvge.f ddrvgb.f derrge.f ddrvpo.f derrpo.f)
++ list(APPEND DLINTST derrvx.f ddrvge.f ddrvsy.f ddrvgb.f derrge.f ddrvpo.f derrpo.f
++ derrsy.f)
+ endif()
+
+ set(ZLINTST zchkaa.f
+@@ -127,17 +129,16 @@
+ zchkpo.f zchkps.f zchkpp.f zchkpt.f zchkq3.f zchkql.f
+ zchkqr.f zchkrq.f zchksp.f zchksy.f zchksy_rook.f zchktb.f
+ zchktp.f zchktr.f zchktz.f
+- zdrvgt.f zdrvhe.f zdrvhe_rook.f zdrvhp.f
++ zdrvgt.f zdrvhe_rook.f zdrvhp.f
+ zdrvls.f zdrvpb.f zdrvpp.f zdrvpt.f
+- zdrvsp.f zdrvsy.f zdrvsy_rook.f
+- zerrgt.f zerrhe.f zerrlq.f
++ zdrvsp.f zdrvsy_rook.f
++ zerrgt.f zerrlq.f
+ zerrls.f zerrps.f zerrql.f zerrqp.f
+- zerrqr.f zerrrq.f zerrsy.f zerrtr.f zerrtz.f
+- zerrvx.f
++ zerrqr.f zerrrq.f zerrtr.f zerrtz.f
+ zgbt01.f zgbt02.f zgbt05.f zgelqs.f zgeqls.f zgeqrs.f
+ zgerqs.f zget01.f zget02.f
+ zget03.f zget04.f zget07.f zgtt01.f zgtt02.f
+- zgtt05.f zhet01.f zhet01.f zhet01_rook.f zhpt01.f zlaipd.f zlaptm.f zlarhs.f zlatb4.f zlatb5.f
++ zgtt05.f zhet01.f zhet01_rook.f zhpt01.f zlaipd.f zlaptm.f zlarhs.f zlatb4.f zlatb5.f
+ zlatsp.f zlatsy.f zlattb.f zlattp.f zlattr.f
+ zlavhe.f zlavhe_rook.f zlavhp.f zlavsp.f zlavsy.f zlavsy_rook.f zlqt01.f
+ zlqt02.f zlqt03.f zpbt01.f zpbt02.f zpbt05.f
+@@ -156,11 +157,11 @@
+ zqrt04.f zqrt05.f zchkqrt.f zerrqrt.f zchkqrtp.f zerrqrtp.f )
+
+ if(USEXBLAS)
+- list(APPEND
+- ZLINTST zdrvgex.f zdrvgbx.f zerrgex.f zdrvpox.f zerrpox.f zebchvxx.f)
++ list(APPEND ZLINTST zerrvxx.f zdrvgex.f zdrvsyx.f zdrvgbx.f zerrgex.f zdrvpox.f zdrvhex.f
++ zerrpox.f zebchvxx.f zerrsyx.f zerrhex.f)
+ else()
+- list(APPEND
+- ZLINTST zdrvge.f zdrvgb.f zerrge.f zdrvpo.f zerrpo.f)
++ list(APPEND ZLINTST zerrvx.f zdrvge.f zdrvsy.f zdrvgb.f zerrge.f zdrvpo.f zdrvhe.f
++ zerrpo.f zerrsy.f zerrhe.f)
+ endif()
+
+ set(DSLINTST dchkab.f
+@@ -197,29 +198,29 @@
+ endmacro(add_lin_executable)
+
+ IF(BUILD_SINGLE)
+-add_lin_executable(xlintsts ${ALINTST} ${SCLNTST} ${SLINTST} ${SECOND_SRC} )
++add_lin_executable(xlintsts ${ALINTST} ${SLINTST} ${SCLNTST} ${SECOND_SRC})
+ add_lin_executable(xlintstrfs ${SLINTSTRFP} ${SECOND_SRC})
+ endif()
+
+ if(BUILD_DOUBLE)
+-add_lin_executable(xlintstd ${ALINTST} ${DLINTST} ${DZLNTST} ${DSECOND_SRC})
++add_lin_executable(xlintstd ${ALINTST} ${DLINTST} ${DZLNTST} ${DSECOND_SRC})
+ add_lin_executable(xlintstrfd ${DLINTSTRFP} ${DSECOND_SRC})
+ endif()
+
+ IF(BUILD_SINGLE AND BUILD_DOUBLE)
+-add_lin_executable(xlintstds ${DSLINTST} ${SECOND_SRC} ${DSECOND_SRC} )
++add_lin_executable(xlintstds ${DSLINTST} ${SECOND_SRC} ${DSECOND_SRC})
+ endif()
+
+ if(BUILD_COMPLEX)
+-add_lin_executable(xlintstc ${ALINTST} ${CLINTST} ${SCLNTST} ${SECOND_SRC} )
+-add_lin_executable(xlintstrfc ${CLINTSTRFP} ${SECOND_SRC})
++add_lin_executable(xlintstc ${ALINTST} ${CLINTST} ${SCLNTST} ${SECOND_SRC})
++add_lin_executable(xlintstrfc ${CLINTSTRFP} ${SECOND_SRC})
+ endif()
+
+ if(BUILD_COMPLEX16)
+-add_lin_executable(xlintstz ${ALINTST} ${ZLINTST} ${DZLNTST} ${DSECOND_SRC})
++add_lin_executable(xlintstz ${ALINTST} ${ZLINTST} ${DZLNTST} ${DSECOND_SRC})
+ add_lin_executable(xlintstrfz ${ZLINTSTRFP} ${DSECOND_SRC})
+ endif()
+
+ IF(BUILD_COMPLEX AND BUILD_COMPLEX16)
+-add_lin_executable(xlintstzc ${ZCLINTST} ${SECOND_SRC} ${DSECOND_SRC} )
++add_lin_executable(xlintstzc ${ZCLINTST} ${SECOND_SRC} ${DSECOND_SRC})
+ endif()
+diff --git a/TESTING/MATGEN/CMakeLists.txt b/TESTING/MATGEN/CMakeLists.txt
+--- a/TESTING/MATGEN/CMakeLists.txt
++++ b/TESTING/MATGEN/CMakeLists.txt
+@@ -31,45 +31,41 @@
+ #
+ #######################################################################
+
+-set(SCATGEN slatm1.f slaran.f slarnd.f)
++set(SCATGEN slatm1.f slatm7.f slaran.f slarnd.f)
+
+ set(SMATGEN slatms.f slatme.f slatmr.f slatmt.f
+ slagge.f slagsy.f slakf2.f slarge.f slaror.f slarot.f slatm2.f
+- slatm3.f slatm5.f slatm6.f slatm7.f slahilb.f)
++ slatm3.f slatm5.f slatm6.f slahilb.f)
+
+ set(CMATGEN clatms.f clatme.f clatmr.f clatmt.f
+ clagge.f claghe.f clagsy.f clakf2.f clarge.f claror.f clarot.f
+- clatm1.f clarnd.f clatm2.f clatm3.f clatm5.f clatm6.f clahilb.f slatm7.f)
++ clatm1.f clarnd.f clatm2.f clatm3.f clatm5.f clatm6.f clahilb.f)
+
+-set(DZATGEN dlatm1.f dlaran.f dlarnd.f)
++set(DZATGEN dlatm1.f dlatm7.f dlaran.f dlarnd.f)
+
+ set(DMATGEN dlatms.f dlatme.f dlatmr.f dlatmt.f
+ dlagge.f dlagsy.f dlakf2.f dlarge.f dlaror.f dlarot.f dlatm2.f
+- dlatm3.f dlatm5.f dlatm6.f dlatm7.f dlahilb.f)
++ dlatm3.f dlatm5.f dlatm6.f dlahilb.f)
+
+ set(ZMATGEN zlatms.f zlatme.f zlatmr.f zlatmt.f
+- zlagge.f zlaghe.f zlagsy.f zlakf2.f zlarge.f zlaror.f zlarot.f
+- zlatm1.f zlarnd.f zlatm2.f zlatm3.f zlatm5.f zlatm6.f zlahilb.f dlatm7.f)
++ zlagge.f zlaghe.f zlagsy.f zlakf2.f zlarge.f zlaror.f zlarot.f
++ zlatm1.f zlarnd.f zlatm2.f zlatm3.f zlatm5.f zlatm6.f zlahilb.f)
+
++set(ALLOBJ)
+ if(BUILD_SINGLE)
+- set(ALLOBJ ${SMATGEN} ${SCATGEN})
++ list(APPEND ALLOBJ ${SMATGEN} ${SCATGEN})
+ endif()
+ if(BUILD_DOUBLE)
+- set(ALLOBJ ${ALLOBJ} ${DMATGEN} ${DZATGEN})
++ list(APPEND ALLOBJ ${DMATGEN} ${DZATGEN})
+ endif()
+ if(BUILD_COMPLEX)
+- set(ALLOBJ ${ALLOBJ} ${CMATGEN} ${SCATGEN})
++ list(APPEND ALLOBJ ${CMATGEN} ${SCATGEN})
+ endif()
+ if(BUILD_COMPLEX16)
+- set(ALLOBJ ${ALLOBJ} ${ZMATGEN} ${DZATGEN})
++ LIST(APPEND ALLOBJ ${ZMATGEN} ${DZATGEN})
+ endif()
++list(REMOVE_DUPLICATES ALLOBJ)
+
+-if (NOT ALLOBJ)
+-set(ALLOBJ ${SMATGEN} ${CMATGEN} ${SCATGEN} ${DMATGEN} ${ZMATGEN}
+- ${DZATGEN})
+-else()
+- list(REMOVE_DUPLICATES ALLOBJ)
+-endif()
+-add_library(tmglib ${ALLOBJ} )
++add_library(tmglib ${ALLOBJ})
+ target_link_libraries(tmglib ${LAPACK_LIBRARIES})
+ lapack_install_library(tmglib)
+diff --git a/TESTING/MATGEN/Makefile b/TESTING/MATGEN/Makefile
+--- a/TESTING/MATGEN/Makefile
++++ b/TESTING/MATGEN/Makefile
+@@ -33,21 +33,21 @@
+ #
+ #######################################################################
+
+-SCATGEN = slatm1.o slaran.o slarnd.o
++SCATGEN = slatm1.o slatm7.o slaran.o slarnd.o
+
+ SMATGEN = slatms.o slatme.o slatmr.o slatmt.o \
+ slagge.o slagsy.o slakf2.o slarge.o slaror.o slarot.o slatm2.o \
+- slatm3.o slatm5.o slatm6.o slatm7.o slahilb.o
++ slatm3.o slatm5.o slatm6.o slahilb.o
+
+ CMATGEN = clatms.o clatme.o clatmr.o clatmt.o \
+ clagge.o claghe.o clagsy.o clakf2.o clarge.o claror.o clarot.o \
+ clatm1.o clarnd.o clatm2.o clatm3.o clatm5.o clatm6.o clahilb.o
+
+-DZATGEN = dlatm1.o dlaran.o dlarnd.o
++DZATGEN = dlatm1.o dlatm7.o dlaran.o dlarnd.o
+
+ DMATGEN = dlatms.o dlatme.o dlatmr.o dlatmt.o \
+ dlagge.o dlagsy.o dlakf2.o dlarge.o dlaror.o dlarot.o dlatm2.o \
+- dlatm3.o dlatm5.o dlatm6.o dlatm7.o dlahilb.o
++ dlatm3.o dlatm5.o dlatm6.o dlahilb.o
+
+ ZMATGEN = zlatms.o zlatme.o zlatmr.o zlatmt.o \
+ zlagge.o zlaghe.o zlagsy.o zlakf2.o zlarge.o zlaror.o zlarot.o \