File openblas.spec of Package openblas

#
# spec file for package openblas
#
# Copyright (c) 2014 SUSE LINUX Products 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.11
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
# PATCH-FIX-UPSTREAM openblas-libs.patch: Link against libgfortran
Patch0:         openblas-libs.patch
# PATCH-FIX-UPSTREAM c_xerbla_no-void-return.patch
Patch1:         c_xerbla_no-void-return.patch
# PATCH-FEATURE-OPENSUSE openblas-0.1.0-soname.patch
Patch2:         openblas-0.1.0-soname.patch
# PATCH-FIX-UPSTREAM openblas-noexecstack.patch
Patch3:         openblas-noexecstack.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
ExclusiveArch:  %ix86 ia64 ppc ppc64 x86_64
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. The
project is supported by the Lab of Parallel Software and Computational Science,
ISCAS. http://www.rdcps.ac.cn

%package     -n libopenblas0
Summary:        An optimized BLAS library based on GotoBLAS2, serial version
Group:          System/Libraries

%description -n libopenblas0
OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version. The
project is supported by the Lab of Parallel Software and Computational Science,
ISCAS. http://www.rdcps.ac.cn


%package     -n libopenblaso0
Summary:        An optimized BLAS library based on GotoBLAS2, OpenMP version
Group:          System/Libraries

%description -n libopenblaso0
OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version. The
project is supported by the Lab of Parallel Software and Computational Science,
ISCAS. http://www.rdcps.ac.cn

This package contains the library compiled with OpenMP support.

%package     -n libopenblasp0
Summary:        An optimized BLAS library based on GotoBLAS2, pthreads version
Group:          System/Libraries

%description -n libopenblasp0
OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version. The
project is supported by the Lab of Parallel Software and Computational Science,
ISCAS. http://www.rdcps.ac.cn

This package contains the library compiled with threading support.

%package        devel
Summary:        Development headers and libraries for OpenBLAS
Group:          Development/Libraries/C and C++
Requires:       lib%{name}0 = %{version}
Requires:       lib%{name}o0 = %{version}
Requires:       lib%{name}p0 = %{version}

%description    devel
OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version. The
project is supported by the Lab of Parallel Software and Computational Science,
ISCAS. http://www.rdcps.ac.cn

This package contains the development headers and libraries.

%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. The
project is supported by the Lab of Parallel Software and Computational Science,
ISCAS. http://www.rdcps.ac.cn

This package contains the static libraries.

%prep
%setup -q -c -T

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

cd ..
# prepare build for serial, threaded and OpenMP versions
cp -ar OpenBLAS-%{version} openmp
cp -ar OpenBLAS-%{version} threaded
mv OpenBLAS-%{version} serial

%build
# Make serial, threaded and OpenMP versions
make -C serial DYNAMIC_ARCH=1 USE_THREAD=0 USE_OPENMP=0 \
        FC=gfortran CC=gcc COMMON_OPT="%{optflags}" NUM_THREADS=64
make -C openmp DYNAMIC_ARCH=1 USE_THREAD=0 USE_OPENMP=1 LIBNAMESUFFIX=o \
        FC=gfortran CC=gcc COMMON_OPT="%{optflags}" NUM_THREADS=64
make -C threaded DYNAMIC_ARCH=1 USE_THREAD=1 USE_OPENMP=0 LIBNAMESUFFIX=p \
        FC=gfortran CC=gcc COMMON_OPT="%{optflags}" NUM_THREADS=64

%install
# Install serial library and headers
make -C serial USE_THREAD=0 PREFIX=%{buildroot}%{_prefix} install

# Move include files to package specific directory, so that they don't clash with reference BLAS and LAPACK
mkdir %{buildroot}%{_includedir}/%{name}
mv %{buildroot}%{_includedir}/*.h %{buildroot}%{_includedir}/%{name}

# Put libraries in correct location
rm -rf %{buildroot}%{_prefix}/lib
mkdir -p %{buildroot}%{_libdir}

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

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

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

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

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

# Get rid of executable stacks
# for lib in %%{buildroot}%%{_libdir}/libopenblas{,o,p}*.so; do
#  execstack -c $lib
# done

%post -n libopenblas0
"%_sbindir/update-alternatives" --install \
   %{_libdir}/libblas.so.3 libblas.so.3 %{_libdir}/libopenblas.so.0  20
"%_sbindir/update-alternatives" --install \
   %{_libdir}/liblapack.so.3 liblapack.so.3 %{_libdir}/libopenblas.so.0  20
/sbin/ldconfig

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

%postun -n libopenblas0 -p /sbin/ldconfig

%post -n libopenblaso0
"%_sbindir/update-alternatives" --install \
   %{_libdir}/libblas.so.3 libblas.so.3 %{_libdir}/libopenblaso.so.0  20
"%_sbindir/update-alternatives" --install \
   %{_libdir}/liblapack.so.3 liblapack.so.3 %{_libdir}/libopenblaso.so.0  20
/sbin/ldconfig

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

%postun -n libopenblaso0 -p /sbin/ldconfig

%post -n libopenblasp0
"%_sbindir/update-alternatives" --install \
   %{_libdir}/libblas.so.3 libblas.so.3 %{_libdir}/libopenblasp.so.0  20
"%_sbindir/update-alternatives" --install \
   %{_libdir}/liblapack.so.3 liblapack.so.3 %{_libdir}/libopenblasp.so.0  20
/sbin/ldconfig

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

%postun -n libopenblasp0 -p /sbin/ldconfig

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

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

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

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

%files devel-static
%defattr(-,root,root,-)
%{_libdir}/lib%{name}.a
%{_libdir}/lib%{name}o.a
%{_libdir}/lib%{name}p.a

%changelog
openSUSE Build Service is sponsored by