File openblas.spec of Package openblas

#
# spec file for package openblas
#
# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


Name:           openblas
Version:        0.2.19
Release:        0
Summary:        An optimized BLAS library based on GotoBLAS2
License:        BSD-3-Clause
Group:          Productivity/Scientific/Math
Url:            http://www.openblas.net
Source0:        https://github.com/xianyi/OpenBLAS/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
Source1:        README.SUSE
# PATCH-FIX-UPSTREAM c_xerbla_no-void-return.patch
Patch1:         c_xerbla_no-void-return.patch
# PATCH-FIX-UPSTREAM openblas-noexecstack.patch
Patch2:         openblas-noexecstack.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  gcc-fortran
BuildRequires:  update-alternatives
Requires(post): update-alternatives
Requires(preun): update-alternatives

%description
OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.

%package     -n lib%{name}_serial0
Summary:        An optimized BLAS library based on GotoBLAS2, serial version
Group:          System/Libraries
Requires(post): update-alternatives
Requires(preun): update-alternatives
Obsoletes:      lib%{name}0 < %{version}
Provides:       lib%{name}0 = %{version}

%description -n lib%{name}_serial0
OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.

%package     -n lib%{name}_serial-devel
Summary:        Development libraries for OpenBLAS, serial version
Group:          Development/Libraries/C and C++
Requires:       %{name}-devel-headers = %{version}
Requires:       lib%{name}_serial0 = %{version}

%description -n lib%{name}_serial-devel
OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.

This package contains the development libraries for serial OpenBLAS version.

%package     -n lib%{name}_openmp0
Summary:        An optimized BLAS library based on GotoBLAS2, OpenMP version
Group:          System/Libraries
Requires(post): update-alternatives
Requires(preun): update-alternatives
Obsoletes:      lib%{name}0 < %{version}
Provides:       lib%{name}0 = %{version}

%description -n lib%{name}_openmp0
OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.

This package contains the library compiled with OpenMP support.

# libopenblaso0 can be deleted after openSUSE 13.2 EOL
%package     -n lib%{name}o0
Summary:        An optimized BLAS library based on GotoBLAS2, OpenMP version
Group:          System/Libraries
Requires:       lib%{name}_openmp0 = %{version}

%description -n lib%{name}o0
OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.

This package contains files for backward compatibility.

%package     -n lib%{name}_openmp-devel
Summary:        Development libraries for OpenBLAS, OpenMP version
Group:          Development/Libraries/C and C++
Requires:       %{name}-devel-headers = %{version}
Requires:       lib%{name}_openmp0 = %{version}

%description -n lib%{name}_openmp-devel
OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.

This package contains the development libraries for OpenMP OpenBLAS version.

%package     -n lib%{name}_pthreads0
Summary:        An optimized BLAS library based on GotoBLAS2, pthreads version
Group:          System/Libraries
Requires(post): update-alternatives
Requires(preun): update-alternatives
Obsoletes:      lib%{name}0 < %{version}
Provides:       lib%{name}0 = %{version}

%description -n lib%{name}_pthreads0
OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.

This package contains the library compiled with threading support.

# libopenblasp0 can be deleted after openSUSE 13.2 EOL
%package     -n lib%{name}p0
Summary:        An optimized BLAS library based on GotoBLAS2, pthreads version
Group:          System/Libraries
Requires:       lib%{name}_pthreads0 = %{version}

%description -n lib%{name}p0
OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.

This package contains files for backward compatibility.

%package     -n lib%{name}_pthreads-devel
Summary:        Development headers and libraries for OpenBLAS, pthreads version
Group:          Development/Libraries/C and C++
Requires:       %{name}-devel-headers = %{version}
Requires:       lib%{name}_pthreads0 = %{version}

%description -n lib%{name}_pthreads-devel
OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.

This package contains the development libraries for pthreads OpenBLAS version.

%package        devel
Summary:        Development headers and libraries for OpenBLAS
Group:          Development/Libraries/C and C++
Requires:       %{name}-devel-headers = %{version}
%ifarch %ix86 x86_64
Requires:       lib%{name}_pthreads-devel = %{version}
%else
Requires:       lib%{name}_openmp-devel = %{version}
%endif

%description    devel
OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.

This package contains the development libraries and headers for OpenBLAS.

%package        devel-headers
Summary:        Development headers for OpenBLAS
Group:          Development/Libraries/C and C++
Conflicts:      %{name}-devel < %{version}
BuildArch:      noarch

%description    devel-headers
OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.

This package contains headers for OpenBLAS.

%package        devel-static
Summary:        Static version of OpenBLAS
Group:          Development/Libraries/C and C++
Requires:       %{name}-devel = %{version}

%description    devel-static
OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.

This package contains the static libraries.

%prep
%setup -q -c -T

# Untar source
tar -zxf %{SOURCE0}
cd OpenBLAS-%{version}
%patch1 -p1
%patch2 -p1
cd ..

# Prepare build for serial, pthreads and OpenMP versions
cp -ar OpenBLAS-%{version} openmp
cp -ar OpenBLAS-%{version} pthreads
mv OpenBLAS-%{version} serial

cp %{SOURCE1} .

%build
# Only x86/x86-64 CPUs support DYNAMIC_ARCH
%ifarch %ix86 x86_64
%define openblas_target DYNAMIC_ARCH=1
%endif
# Temporary fix, OpenBLAS does not autodetect aarch64
%ifarch aarch64
%define openblas_target TARGET=ARMV8
%endif
# Make serial, threaded and OpenMP versions
make -C serial %{?openblas_target} USE_THREAD=0 USE_OPENMP=0 LIBNAMESUFFIX=serial \
        FC=gfortran CC=gcc COMMON_OPT="%{optflags}" NUM_THREADS=64 V=1
make -C openmp %{?openblas_target} USE_THREAD=1 USE_OPENMP=1 LIBNAMESUFFIX=openmp \
        FC=gfortran CC=gcc COMMON_OPT="%{optflags}" NUM_THREADS=64 V=1
make -C pthreads %{?openblas_target} USE_THREAD=1 USE_OPENMP=0 LIBNAMESUFFIX=pthreads \
        FC=gfortran CC=gcc COMMON_OPT="%{optflags}" NUM_THREADS=64 V=1

%install
# Install serial library and headers
make -C serial USE_THREAD=0 LIBNAMESUFFIX=serial \
        OPENBLAS_LIBRARY_DIR=%{buildroot}%{_libdir} \
        OPENBLAS_INCLUDE_DIR=%{buildroot}%{_includedir}/%{name} \
        OPENBLAS_CMAKE_DIR=%{buildroot}%{_libdir}/cmake/%{name} \
        PREFIX=%{buildroot}%{_prefix} install

# Put libraries in correct location
rm -rf %{buildroot}%{_libdir}/lib%{name}*

# Install the serial library
install -D -p -m 755 serial/lib%{name}_serial.so %{buildroot}%{_libdir}/lib%{name}_serial.so.0
install -D -p -m 644 serial/lib%{name}_serial.a %{buildroot}%{_libdir}/lib%{name}_serial.a

# Install the OpenMP library
install -D -p -m 755 openmp/lib%{name}_openmp.so %{buildroot}%{_libdir}/lib%{name}_openmp.so.0
install -D -p -m 644 openmp/lib%{name}_openmp.a %{buildroot}%{_libdir}/lib%{name}_openmp.a

# Install the threaded library
install -D -p -m 755 pthreads/lib%{name}_pthreads.so %{buildroot}%{_libdir}/lib%{name}_pthreads.so.0
install -D -p -m 644 pthreads/lib%{name}_pthreads.a %{buildroot}%{_libdir}/lib%{name}_pthreads.a

# Fix source permissions (also applies to LAPACK)
find -name \*.f -exec chmod 644 {} +

# Dummy target for update-alternatives
install -d %{buildroot}/%{_sysconfdir}/alternatives
ln -s lib%{name}.so.0 %{buildroot}/%{_libdir}/lib%{name}.so.0
ln -s lib%{name}.so.0 %{buildroot}/%{_sysconfdir}/alternatives/lib%{name}.so.0
ln -s lib%{name}.so.0 %{buildroot}/%{_libdir}/libblas.so.3
ln -s lib%{name}.so.0 %{buildroot}/%{_libdir}/libcblas.so.3
ln -s lib%{name}.so.0 %{buildroot}/%{_libdir}/liblapack.so.3
ln -s lib%{name}.so.0 %{buildroot}/%{_sysconfdir}/alternatives/libblas.so.3
ln -s lib%{name}.so.0 %{buildroot}/%{_sysconfdir}/alternatives/libcblas.so.3
ln -s lib%{name}.so.0 %{buildroot}/%{_sysconfdir}/alternatives/liblapack.so.3

# Fix symlinks
pushd %{buildroot}%{_libdir}
ln -sf lib%{name}.so.0 lib%{name}.so
# Serial libraries
ln -sf lib%{name}_serial.so.0 lib%{name}_serial.so
# OpenMP libraries
ln -sf lib%{name}_openmp.so.0 lib%{name}_openmp.so
ln -sf lib%{name}_openmp.so.0 lib%{name}o.so.0
ln -sf lib%{name}o.so.0 lib%{name}o.so
# Threaded libraries
ln -sf lib%{name}_pthreads.so.0 lib%{name}_pthreads.so
ln -sf lib%{name}_pthreads.so.0 lib%{name}p.so.0
ln -sf lib%{name}p.so.0 lib%{name}p.so

# Fix cmake config file
sed -i 's|%{buildroot}||g' %{buildroot}%{_libdir}/cmake/%{name}/*.cmake
sed -i 's|_serial||g' %{buildroot}%{_libdir}/cmake/%{name}/*.cmake

# Delete info about OBS host cpu
%ifarch %ix86 x86_64
sed -i '/#define OPENBLAS_NEEDBUNDERSCORE/,/#define OPENBLAS_VERSION/{//!d}' %{buildroot}%{_includedir}/%{name}/openblas_config.h
%endif

%post -n lib%{name}_serial0
%{_sbindir}/update-alternatives --install \
   %{_libdir}/libblas.so.3 libblas.so.3 %{_libdir}/lib%{name}_serial.so.0  20
%{_sbindir}/update-alternatives --install \
   %{_libdir}/libcblas.so.3 libcblas.so.3 %{_libdir}/lib%{name}_serial.so.0  20
%{_sbindir}/update-alternatives --install \
   %{_libdir}/liblapack.so.3 liblapack.so.3 %{_libdir}/lib%{name}_serial.so.0  20
%{_sbindir}/update-alternatives --install \
   %{_libdir}/lib%{name}.so.0 lib%{name}.so.0 %{_libdir}/lib%{name}_serial.so.0  20
/sbin/ldconfig

%preun -n lib%{name}_serial0
if [ "$1" = 0 ] ; then
   %{_sbindir}/update-alternatives --remove libblas.so.3 %{_libdir}/lib%{name}_serial.so.0
   %{_sbindir}/update-alternatives --remove libcblas.so.3 %{_libdir}/lib%{name}_serial.so.0
   %{_sbindir}/update-alternatives --remove liblapack.so.3 %{_libdir}/lib%{name}_serial.so.0
   %{_sbindir}/update-alternatives --remove lib%{name}.so.0 %{_libdir}/lib%{name}_serial.so.0
fi

%postun -n lib%{name}_serial0 -p /sbin/ldconfig

%posttrans -n lib%{name}_serial0
if [ "$1" = 0 ] ; then
  if ! [ -f %{_libdir}/lib%{name}.so.0 ] ; then
      %{_sbindir}/update-alternatives --auto lib%{name}.so.0
  fi
fi

%post -n lib%{name}_openmp0
# Migration script can be deleted after openSUSE 13.2 EOL
# Check config
config_blas_mode=$(%{_sbindir}/update-alternatives --query libblas.so.3 | grep 'Status:' | sed -e 's/Status: //g')
config_blas_value=$(%{_sbindir}/update-alternatives --query libblas.so.3 | grep 'Value:' | grep -o 'openblas.')
config_lapack_mode=$(%{_sbindir}/update-alternatives --query liblapack.so.3 | grep 'Status:' | sed -e 's/Status: //g')
config_lapack_value=$(%{_sbindir}/update-alternatives --query liblapack.so.3 | grep 'Value:' | grep -o 'openblas.')
# Install
%{_sbindir}/update-alternatives --install \
   %{_libdir}/libblas.so.3 libblas.so.3 %{_libdir}/lib%{name}_openmp.so.0  20
%{_sbindir}/update-alternatives --install \
   %{_libdir}/libcblas.so.3 libcblas.so.3 %{_libdir}/lib%{name}_openmp.so.0  20
%{_sbindir}/update-alternatives --install \
   %{_libdir}/liblapack.so.3 liblapack.so.3 %{_libdir}/lib%{name}_openmp.so.0  20
%{_sbindir}/update-alternatives --install \
%ifarch %ix86 x86_64
   %{_libdir}/lib%{name}.so.0 lib%{name}.so.0 %{_libdir}/lib%{name}_openmp.so.0  20
%else
   %{_libdir}/lib%{name}.so.0 lib%{name}.so.0 %{_libdir}/lib%{name}_openmp.so.0  50
%endif
# Reconfigure
if [ ${config_blas_mode} = "manual" ] && [ ${config_blas_value} = "openblaso" ]; then
    %{_sbindir}/update-alternatives --set libblas.so.3 %{_libdir}/lib%{name}_openmp.so.0
fi
if [ ${config_lapack_mode} = "manual" ] && [ ${config_lapack_value} == "openblaso" ]; then
    %{_sbindir}/update-alternatives --set liblapack.so.3 %{_libdir}/lib%{name}_openmp.so.0
fi
# Remove old variants
%{_sbindir}/update-alternatives --remove libblas.so.3 %{_libdir}/lib%{name}o.so.0
%{_sbindir}/update-alternatives --remove liblapack.so.3 %{_libdir}/lib%{name}o.so.0
/sbin/ldconfig

%preun -n lib%{name}_openmp0
if [ "$1" = 0 ] ; then
   %{_sbindir}/update-alternatives --remove libblas.so.3 %{_libdir}/lib%{name}_openmp.so.0
   %{_sbindir}/update-alternatives --remove libcblas.so.3 %{_libdir}/lib%{name}_openmp.so.0
   %{_sbindir}/update-alternatives --remove liblapack.so.3 %{_libdir}/lib%{name}_openmp.so.0
   %{_sbindir}/update-alternatives --remove lib%{name}.so.0 %{_libdir}/lib%{name}_openmp.so.0
fi

%postun -n lib%{name}_openmp0 -p /sbin/ldconfig

%posttrans -n lib%{name}_openmp0
if [ "$1" = 0 ] ; then
  if ! [ -f %{_libdir}/lib%{name}.so.0 ] ; then
      %{_sbindir}/update-alternatives --auto lib%{name}.so.0
  fi
fi

%post -n lib%{name}_pthreads0
# Migration script can be deleted after openSUSE 13.2 EOL
# Check config
config_blas_mode=$(%{_sbindir}/update-alternatives --query libblas.so.3 | grep 'Status:' | sed -e 's/Status: //g')
config_blas_value=$(%{_sbindir}/update-alternatives --query libblas.so.3 | grep 'Value:' | grep -o 'openblas.')
config_lapack_mode=$(%{_sbindir}/update-alternatives --query liblapack.so.3 | grep 'Status:' | sed -e 's/Status: //g')
config_lapack_value=$(%{_sbindir}/update-alternatives --query liblapack.so.3 | grep 'Value:' | grep -o 'openblas.')
# Install
%{_sbindir}/update-alternatives --install \
   %{_libdir}/libblas.so.3 libblas.so.3 %{_libdir}/lib%{name}_pthreads.so.0  20
%{_sbindir}/update-alternatives --install \
   %{_libdir}/libcblas.so.3 libcblas.so.3 %{_libdir}/lib%{name}_pthreads.so.0  20
%{_sbindir}/update-alternatives --install \
   %{_libdir}/liblapack.so.3 liblapack.so.3 %{_libdir}/lib%{name}_pthreads.so.0  20
%{_sbindir}/update-alternatives --install \
%ifarch %ix86 x86_64
   %{_libdir}/lib%{name}.so.0 lib%{name}.so.0 %{_libdir}/lib%{name}_pthreads.so.0  50
%else
   %{_libdir}/lib%{name}.so.0 lib%{name}.so.0 %{_libdir}/lib%{name}_pthreads.so.0  20
%endif
# Reconfigure
if [ ${config_blas_mode} = "manual" ] && [ ${config_blas_value} = "openblasp" ]; then
    %{_sbindir}/update-alternatives --set libblas.so.3 %{_libdir}/lib%{name}_pthreads.so.0
fi
if [ ${config_lapack_mode} = "manual" ] && [ ${config_lapack_value} == "openblasp" ]; then
    %{_sbindir}/update-alternatives --set liblapack.so.3 %{_libdir}/lib%{name}_pthreads.so.0
fi
# Remove old variants
%{_sbindir}/update-alternatives --remove libblas.so.3 %{_libdir}/lib%{name}p.so.0
%{_sbindir}/update-alternatives --remove liblapack.so.3 %{_libdir}/lib%{name}p.so.0
/sbin/ldconfig

%preun -n lib%{name}_pthreads0
if [ "$1" = 0 ] ; then
   %{_sbindir}/update-alternatives --remove libblas.so.3 %{_libdir}/lib%{name}_pthreads.so.0
   %{_sbindir}/update-alternatives --remove libcblas.so.3 %{_libdir}/lib%{name}_pthreads.so.0
   %{_sbindir}/update-alternatives --remove liblapack.so.3 %{_libdir}/lib%{name}_pthreads.so.0
   %{_sbindir}/update-alternatives --remove lib%{name}.so.0 %{_libdir}/lib%{name}_pthreads.so.0
fi

%postun -n lib%{name}_pthreads0 -p /sbin/ldconfig

%posttrans -n lib%{name}_pthreads0
if [ "$1" = 0 ] ; then
  if ! [ -f %{_libdir}/lib%{name}.so.0 ] ; then
      %{_sbindir}/update-alternatives --auto lib%{name}.so.0
  fi
fi

%files -n lib%{name}_serial0
%defattr(-,root,root,-)
%{_libdir}/lib%{name}_serial.so.0
%ghost %{_libdir}/lib%{name}.so.0
%ghost %{_libdir}/libblas.so.3
%ghost %{_libdir}/libcblas.so.3
%ghost %{_libdir}/liblapack.so.3
%ghost %{_sysconfdir}/alternatives/lib%{name}.so.0
%ghost %{_sysconfdir}/alternatives/libblas.so.3
%ghost %{_sysconfdir}/alternatives/libcblas.so.3
%ghost %{_sysconfdir}/alternatives/liblapack.so.3

%files -n lib%{name}_serial-devel
%defattr(-,root,root,-)
%{_libdir}/lib%{name}_serial.so

%files -n lib%{name}_openmp0
%defattr(-,root,root,-)
%{_libdir}/lib%{name}_openmp.so.0
%ghost %{_libdir}/lib%{name}.so.0
%ghost %{_libdir}/libblas.so.3
%ghost %{_libdir}/libcblas.so.3
%ghost %{_libdir}/liblapack.so.3
%ghost %{_sysconfdir}/alternatives/lib%{name}.so.0
%ghost %{_sysconfdir}/alternatives/libblas.so.3
%ghost %{_sysconfdir}/alternatives/libcblas.so.3
%ghost %{_sysconfdir}/alternatives/liblapack.so.3

%files -n lib%{name}o0
%defattr(-,root,root,-)
%{_libdir}/lib%{name}o.so.0

%files -n lib%{name}_openmp-devel
%defattr(-,root,root,-)
%{_libdir}/lib%{name}_openmp.so
%{_libdir}/lib%{name}o.so

%files -n lib%{name}_pthreads0
%defattr(-,root,root,-)
%{_libdir}/lib%{name}_pthreads.so.0
%ghost %{_libdir}/lib%{name}.so.0
%ghost %{_libdir}/libblas.so.3
%ghost %{_libdir}/libcblas.so.3
%ghost %{_libdir}/liblapack.so.3
%ghost %{_sysconfdir}/alternatives/lib%{name}.so.0
%ghost %{_sysconfdir}/alternatives/libblas.so.3
%ghost %{_sysconfdir}/alternatives/libcblas.so.3
%ghost %{_sysconfdir}/alternatives/liblapack.so.3

%files -n lib%{name}p0
%defattr(-,root,root,-)
%{_libdir}/lib%{name}p.so.0

%files -n lib%{name}_pthreads-devel
%defattr(-,root,root,-)
%{_libdir}/lib%{name}_pthreads.so
%{_libdir}/lib%{name}p.so

%files devel
%defattr(-,root,root,-)
%doc serial/Changelog.txt serial/GotoBLAS* serial/LICENSE serial/README.md README.SUSE
%{_libdir}/lib%{name}.so
%dir %{_libdir}/cmake
%{_libdir}/cmake/%{name}/

%files devel-headers
%defattr(-,root,root,-)
%{_includedir}/%{name}/

%files devel-static
%defattr(-,root,root,-)
%{_libdir}/lib%{name}_serial.a
%{_libdir}/lib%{name}_openmp.a
%{_libdir}/lib%{name}_pthreads.a

%changelog