%global shortver  3
%global mediumver %{shortver}.7

# Build 64-bit interface binaries?
%ifarch %{ix86}
%global build64 0
%endif
%ifarch x86_64
%global build64 1
%endif


Summary: Numerical linear algebra package libraries
Summary(ja): 線形代数パッケージライブラリ
Name:    lapack
Version: %{mediumver}.1
Release: 4%{?_dist_release}

License: BSD
Group:   System Environment/Libraries
URL:     http://www.netlib.org/lapack/

Source0: http://www.netlib.org/lapack/lapack-%{version}.tgz
Source1: http://www.netlib.org/lapack/manpages.tgz
Source2: Makefile.blas
Source3: Makefile.lapack
Source4: Makefile.cblas
Source11: http://www.netlib.org/lapack/lapackqref.ps
Source12: http://www.netlib.org/blas/blasqr.ps

# Patch3:  lapack-3.4.0-make.inc.patch
# Patch4:  lapack-3.4.1-lapacke-shared.patch
# Patch5:  lapack-3.4.1-lapacke-disable-testing-functions.patch
# Patch6:  lapack-3.5.0-lapacke-matgenobj.patch
# Patch7:  lapack-3.5.0-lapacke-tmglib.patch
# Patch8:  lapack-3.5.0-R-blas-fixes.patch
Patch11: lapack-3.7.1-make.inc.patch
Patch12: lapack-3.7.1-lapacke-shared.patch
Patch13: lapack-3.7.1-lapacke-tmglib.patch

BuildRoot:     %{_tmppath}/%{name}-%{version}-root
BuildRequires: gcc-gfortran
BuildRequires: coreutils findutils

Vendor:       Project Vine
Distribution: Vine Linux
Packager:     inagaki, kenta


%description
LAPACK (Linear Algebra PACKage) is a standard library for numerical
linear algebra. LAPACK provides routines for solving systems of
simultaneous linear equations, least-squares solutions of linear
systems of equations, eigenvalue problems, and singular value problems.
Associated matrix factorizations (LU, Cholesky, QR, SVD, Schur, and
generalized Schur) and related computations (i.e., reordering of
Schur factorizations and estimating condition numbers) are also
included. LAPACK can handle dense and banded matrices, but not general
sparse matrices. Similar functionality is provided for real and complex
matrices in both single and double precision. LAPACK is coded in
Fortran90 and built with gcc.

%description -l ja
LAPACK(Linear Algebra PACKage)は線形代数用数値計算の標準ライブラリです。
LAPACKには、連立一次方程式、線形最小二乗解、固有値問題、特異値問題を解く
ためのルーチンがあります。関連する行列因子分解(LU、Cholesky、QR、SVD、
Schur、一般化Schur)と、それに関連する計算処理 (つまりSchur分解の再配列
およびコンディションナンバーの推定)も含まれます。
LAPACKは密なbanded行列は処理できますが、一般的な疎行列は処理できません。
同じ計算機能が、実行列および複素行列の単制度および倍精度で利用できます。
LAPACKはFortran 90で記述され、gccでビルドされています。

%package devel
Summary:     LAPACK development libraries
Summary(ja): LAPACK の開発用ライブラリ
Group:       Development/Libraries
Requires:    %{name} = %{version}-%{release}
Requires:    blas-devel = %{version}-%{release}

%description devel
LAPACK development libraries (shared).

%description devel -l ja
LAPACK の開発用ライブラリ(共有ライブラリ)です。

%package static
Summary:     LAPACK static libraries
Summary(ja): LAPACK の静的ライブラリ
Group:       Development/Libraries
Requires:    %{name}-devel = %{version}-%{release}

%description static
LAPACK static libraries.

%description static -l ja
LAPACK の静的ライブラリです。

%package -n blas
Summary:     The BLAS (Basic Linear Algebra Subprograms) library.
Summary(ja): 基本線形代数サブプログラム群のライブラリ
Group:       System Environment/Libraries

%description -n blas
BLAS (Basic Linear Algebra Subprograms) is a standard library which
provides a number of basic algorithms for numerical algebra.

%description -n blas -l ja
BLAS(Basic Linear Algebra Subprograms)は数値代数計算の標準ライブラリです。
BLASでは、線形代数計算における多くの基本アルゴリズムを利用できます。
Blasの計算は高速で十分テストされているFORTRAN 90のプログラムで、
gccでビルドされています。

%package -n blas-devel
Summary:     BLAS development libraries
Summary(ja): BLAS の開発用ライブラリ
Group:       Development/Libraries
Requires:    blas = %{version}-%{release}
Requires:    gcc-gfortran

%description -n blas-devel
BLAS development libraries (shared).

%description -n blas-devel -l ja
BLAS の開発用ライブラリ(共有ライブラリ)です。

%package -n blas-static
Summary:     BLAS static libraries
Summary(ja): BLAS の静的ライブラリ
Group:       Development/Libraries
Requires:    blas-devel = %{version}-%{release}

%description -n blas-static
BLAS static libraries.

%description -n blas-static -l ja
BLAS の静的ライブラリです。


%if %build64
%package -n lapack64
Summary: Numerical linear algebra package libraries
Group: System Environment/Libraries
Requires: blas64 = %{version}-%{release}

%description -n lapack64
LAPACK (Linear Algebra PACKage) is a standard library for numerical
linear algebra. LAPACK provides routines for solving systems of
simultaneous linear equations, least-squares solutions of linear
systems of equations, eigenvalue problems, and singular value
problems. Associated matrix factorizations (LU, Cholesky, QR, SVD,
Schur, and generalized Schur) and related computations (i.e.,
reordering of Schur factorizations and estimating condition numbers)
are also included. LAPACK can handle dense and banded matrices, but
not general sparse matrices. Similar functionality is provided for
real and complex matrices in both single and double precision. LAPACK
is coded in Fortran90 and built with gcc.
This build has 64bit INTEGER support.

%package -n lapack64-devel
Summary: LAPACK development libraries (64bit INTEGER)
Group: Development/Libraries
Requires: lapack64 = %{version}-%{release}
Requires: lapack-devel = %{version}-%{release}
Requires: blas64-devel = %{version}-%{release}

%description -n lapack64-devel
LAPACK development libraries (shared, 64bit INTEGER).

%package -n lapack64-static
Summary: LAPACK static libraries (64bit INTEGER)
Group: Development/Libraries
Requires: lapack64-devel = %{version}-%{release}

%description -n lapack64-static
LAPACK static libraries (64bit INTEGER).

%package -n blas64
Summary: The Basic Linear Algebra Subprograms library (64bit INTEGER)
Group: System Environment/Libraries

%description -n blas64
BLAS (Basic Linear Algebra Subprograms) is a standard library which
provides a number of basic algorithms for numerical algebra. This build
has 64bit INTEGER support.

%package -n blas64-devel
Summary: BLAS development libraries
Group: Development/Libraries
Requires: blas64 = %{version}-%{release}
Requires: blas-devel = %{version}-%{release}
Requires: gcc-gfortran

%description -n blas64-devel
BLAS development libraries (shared).

%package -n blas64-static
Summary: BLAS static libraries (64bit INTEGER)
Group: Development/Libraries
Requires: blas64-devel = %{version}-%{release}

%description -n blas64-static
BLAS static libraries (64bit INTEGER).
%endif


%prep
%setup -q
%setup -q -D -T -a1
# %patch3 -p1 -b .fedora
# %patch4 -p1 -b .shared
# %patch5 -p1 -b .disable-functions
# %patch6 -p1 -b .matgenobj
# %patch7 -p1 -b .tmglib
# %patch8 -p1 -b .R
%patch11 -p1 -b .fedora
%patch12 -p1 -b .shared
%patch13 -p1 -b .tmglib

cp -f INSTALL/make.inc.gfortran make.inc
cp -f %{SOURCE2} BLAS/SRC/Makefile
cp -f %{SOURCE3} SRC/Makefile
cp -f %{SOURCE4} CBLAS/src/Makefile

sed -i "s|@SHORTVER@|%{shortver}|g" BLAS/SRC/Makefile
sed -i "s|@SHORTVER@|%{shortver}|g" SRC/Makefile
sed -i "s|@SHORTVER@|%{shortver}|g" LAPACKE/Makefile
sed -i "s|@SHORTVER@|%{shortver}|g" CBLAS/src/Makefile
sed -i "s|@LONGVER@|%{version}|g" BLAS/SRC/Makefile
sed -i "s|@LONGVER@|%{version}|g" SRC/Makefile
sed -i "s|@LONGVER@|%{version}|g" LAPACKE/Makefile
sed -i "s|@LONGVER@|%{version}|g" CBLAS/src/Makefile

cp -p %{SOURCE11} lapackqref.ps
cp -p %{SOURCE12} blasqr.ps

%build
RPM_OPT_FLAGS="$RPM_OPT_FLAGS -frecursive"
RPM_OPT_O_FLAGS=$(echo $RPM_OPT_FLAGS | sed 's|-O2|-O0|')
export FC=gfortran

# Build BLAS
pushd BLAS/SRC
FFLAGS="$RPM_OPT_O_FLAGS" make dcabs1.o
FFLAGS="$RPM_OPT_FLAGS" CFLAGS="$RPM_OPT_FLAGS" make static
cp libblas.a ${RPM_BUILD_DIR}/%{name}-%{version}/
make clean
FFLAGS="$RPM_OPT_O_FLAGS -fPIC" make dcabs1.o
FFLAGS="$RPM_OPT_FLAGS -fPIC" CFLAGS="$RPM_OPT_FLAGS -fPIC" make shared
cp libblas.so.%{version} ${RPM_BUILD_DIR}/%{name}-%{version}/

%if %build64
make clean
FFLAGS="$RPM_OPT_O_FLAGS -fdefault-integer-8" make dcabs1.o
SYMBOLPREFIX="64_" FFLAGS="$RPM_OPT_FLAGS -fdefault-integer-8" CFLAGS="$RPM_OPT_FLAGS" make static
cp libblas64_.a ${RPM_BUILD_DIR}/%{name}-%{version}/libblas64_.a
make clean
FFLAGS="$RPM_OPT_O_FLAGS -fPIC -fdefault-integer-8" make dcabs1.o
SYMBOLPREFIX="64_" FFLAGS="$RPM_OPT_FLAGS -fPIC -fdefault-integer-8" CFLAGS="$RPM_OPT_FLAGS -fPIC" LDFLAGS="%{build_ldflags}" make shared
cp libblas64_.so.%{version} ${RPM_BUILD_DIR}/%{name}-%{version}/libblas64_.so.%{version}
%endif
popd

ln -s libblas.so.%{version} libblas.so
%if %build64
ln -s libblas64_.so.%{version} libblas64_.so
%endif

# Build CBLAS
cp CBLAS/include/cblas_mangling_with_flags.h.in CBLAS/include/cblas_mangling.h
pushd CBLAS/src
FFLAGS="$RPM_OPT_FLAGS" CFLAGS="$RPM_OPT_FLAGS -I../include" make static
cp libcblas.a ${RPM_BUILD_DIR}/%{name}-%{version}/
make clean
FFLAGS="$RPM_OPT_FLAGS -fPIC" CFLAGS="$RPM_OPT_FLAGS -fPIC -I../include" make shared
cp libcblas.so.%{version} ${RPM_BUILD_DIR}/%{name}-%{version}/

%if %build64
make clean
SYMBOLPREFIX="64_" FFLAGS="$RPM_OPT_FLAGS -fdefault-integer-8" CFLAGS="$RPM_OPT_FLAGS -I../include" make static
cp libcblas64_.a ${RPM_BUILD_DIR}/%{name}-%{version}/libcblas64_.a
make clean
SYMBOLPREFIX="64_" FFLAGS="$RPM_OPT_FLAGS -fPIC -fdefault-integer-8" CFLAGS="$RPM_OPT_FLAGS -fPIC -I../include" make shared
cp libcblas64_.so.%{version} ${RPM_BUILD_DIR}/%{name}-%{version}/libcblas64_.so.%{version}
%endif
popd

ln -s libcblas.so.%{version} libcblas.so
%if %build64
ln -s libcblas64_.so.%{version} libcblas64_.so
%endif

# Build the static dlamch, dsecnd, lsame, second, slamch bits
pushd INSTALL
make NOOPT="$RPM_OPT_O_FLAGS" OPTS="$RPM_OPT_FLAGS"
popd

# Build the static lapack library
pushd SRC
make FFLAGS="$RPM_OPT_FLAGS" CFLAGS="$RPM_OPT_FLAGS" static
cp liblapack.a ${RPM_BUILD_DIR}/%{name}-%{version}/
popd

# Build the static with pic dlamch, dsecnd, lsame, second, slamch bits
pushd INSTALL
make clean
make NOOPT="$RPM_OPT_O_FLAGS -fPIC" OPTS="$RPM_OPT_FLAGS -fPIC"
popd

# Build the static with pic lapack library
pushd SRC
make clean
make FFLAGS="$RPM_OPT_FLAGS -fPIC" CFLAGS="$RPM_OPT_FLAGS -fPIC" static
cp liblapack.a ${RPM_BUILD_DIR}/%{name}-%{version}/liblapack_pic.a
popd

%if %build64
# Build the static dlamch, dsecnd, lsame, second, slamch bits
pushd INSTALL
make NOOPT="$RPM_OPT_O_FLAGS -fdefault-integer-8" OPTS="$RPM_OPT_FLAGS -fdefault-integer-8"
popd

# Build the static lapack library
pushd SRC
make SYMBOLPREFIX="64_" FFLAGS="$RPM_OPT_FLAGS -fdefault-integer-8" CFLAGS="$RPM_OPT_FLAGS" static
cp liblapack64_.a ${RPM_BUILD_DIR}/%{name}-%{version}/liblapack64_.a
popd

# Build the static with pic dlamch, dsecnd, lsame, second, slamch bits (64bit INTEGER)
pushd INSTALL
make clean
make NOOPT="$RPM_OPT_O_FLAGS -fPIC -fdefault-integer-8" OPTS="$RPM_OPT_FLAGS -fPIC -fdefault-integer-8"
popd

# Build the static with pic lapack library (64bit INTEGER)
pushd SRC
make clean
make SYMBOLPREFIX="64_" FFLAGS="$RPM_OPT_FLAGS -fPIC -fdefault-integer-8" CFLAGS="$RPM_OPT_FLAGS -fPIC" static
cp liblapack64_.a ${RPM_BUILD_DIR}/%{name}-%{version}/liblapack64_pic.a
popd
%endif

# Build the shared dlamch, dsecnd, lsame, second, slamch bits
pushd INSTALL
make clean
make NOOPT="$RPM_OPT_O_FLAGS -fPIC" OPTS="$RPM_OPT_FLAGS -fPIC"
popd

# Build the shared lapack library
pushd SRC
make clean
make FFLAGS="$RPM_OPT_FLAGS -fPIC" CFLAGS="$RPM_OPT_FLAGS -fPIC" shared
cp liblapack.so.%{version} ${RPM_BUILD_DIR}/%{name}-%{version}/
popd

%if %build64
# Build the shared dlamch, dsecnd, lsame, second, slamch bits
pushd INSTALL
make clean
make NOOPT="$RPM_OPT_O_FLAGS -fPIC -fdefault-integer-8" OPTS="$RPM_OPT_FLAGS -fPIC -fdefault-integer-8"
popd

# Build the shared lapack library
pushd SRC
make clean
make SYMBOLPREFIX="64_" FFLAGS="$RPM_OPT_FLAGS -fPIC -fdefault-integer-8" CFLAGS="$RPM_OPT_FLAGS -fPIC -fdefault-integer-8" shared
cp liblapack64_.so.%{version} ${RPM_BUILD_DIR}/%{name}-%{version}/liblapack64_.so.%{version}
popd
%endif

ln -s liblapack.so.%{version} liblapack.so
%if %build64
ln -s liblapack64_.so.%{version} liblapack64_.so
%endif

# Build the lapacke libraries
make OPTS="$RPM_OPT_FLAGS -fPIC" tmglib
pushd LAPACKE
make clean
make CFLAGS="$RPM_OPT_FLAGS" lapacke
make clean
make CFLAGS="$RPM_OPT_FLAGS -fPIC" shlib
cp liblapacke.so.%{version} ${RPM_BUILD_DIR}/%{name}-%{version}/
popd

ln -s liblapacke.so.%{version} liblapacke.so


%install
rm -fr $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT%{_libdir}/blas
mkdir -p $RPM_BUILD_ROOT%{_libdir}/lapack
mkdir -p $RPM_BUILD_ROOT%{_mandir}/man3
chmod 755 $RPM_BUILD_ROOT%{_mandir}/man3

for f in libblas.so.%{version} libblas.a libcblas.so.%{version} libcblas.a; do
  cp -f $f $RPM_BUILD_ROOT%{_libdir}/blas/$f
done

for f in liblapack.so.%{version} liblapacke.so.%{version} liblapack.a liblapack_pic.a liblapacke.a; do
  cp -f $f $RPM_BUILD_ROOT%{_libdir}/lapack/$f
done

%if %build64
for f in libblas64_.so.%{version} libcblas64_.so.%{version} libblas64_.a libcblas64_.a; do
  cp -f $f ${RPM_BUILD_ROOT}%{_libdir}/blas/$f
done

for f in liblapack64_.so.%{version} liblapack64_.a liblapack64_pic.a; do
  cp -f $f ${RPM_BUILD_ROOT}%{_libdir}/lapack/$f
done
%endif

# Manpages
rm -rf manpages
mkdir -p manpages
cp -pr man/ manpages/

pushd manpages/
mkdir -p blas/man/man3
cd man/man3/
mv caxpy.f.3 caxpy.3 ccopy.f.3 ccopy.3 cdotc.f.3 cdotc.3 cdotu.f.3 cdotu.3 cgbmv.f.3 cgbmv.3 \
cgemm.f.3 cgemm.3 cgemv.f.3 cgemv.3 cgerc.f.3 cgerc.3 cgeru.f.3 cgeru.3 chbmv.f.3 chbmv.3 \
chemm.f.3 chemm.3 chemv.f.3 chemv.3 cher.f.3 cher.3 cher2.f.3 cher2.3 cher2k.f.3 cher2k.3 \
cherk.f.3 cherk.3 chpmv.f.3 chpmv.3 chpr.f.3 chpr.3 chpr2.f.3 chpr2.3 crotg.f.3 crotg.3 \
cscal.f.3 cscal.3 csrot.f.3 csrot.3 csscal.f.3 csscal.3 cswap.f.3 cswap.3 csymm.f.3 \
csymm.3 csyr2k.f.3 csyr2k.3 csyrk.f.3 csyrk.3 ctbmv.f.3 ctbmv.3 ctbsv.f.3 ctbsv.3 ctpmv.f.3 \
ctpmv.3 ctpsv.f.3 ctpsv.3 ctrmm.f.3 ctrmm.3 ctrmv.f.3 ctrmv.3 ctrsm.f.3 ctrsm.3 ctrsv.f.3 \
ctrsv.3 dasum.f.3 dasum.3 daxpy.f.3 daxpy.3 dcabs1.f.3 dcabs1.3 dcopy.f.3 dcopy.3 ddot.f.3 \
ddot.3 dgbmv.f.3 dgbmv.3 dgemm.f.3 dgemm.3 dgemv.f.3 dgemv.3 dger.f.3 dger.3 dnrm2.f.3 \
dnrm2.3 drot.f.3 drot.3 drotg.f.3 drotg.3 drotm.f.3 drotm.3 drotmg.f.3 drotmg.3 dsbmv.f.3 \
dsbmv.3 dscal.f.3 dscal.3 dsdot.f.3 dsdot.3 dspmv.f.3 dspmv.3 dspr.f.3 dspr.3 dspr2.f.3 \
dspr2.3 dswap.f.3 dswap.3 dsymm.f.3 dsymm.3 dsymv.f.3 dsymv.3 dsyr.f.3 dsyr.3 dsyr2.f.3 \
dsyr2.3 dsyr2k.f.3 dsyr2k.3 dsyrk.f.3 dsyrk.3 dtbmv.f.3 dtbmv.3 dtbsv.f.3 dtbsv.3 dtpmv.f.3 \
dtpmv.3 dtpsv.f.3 dtpsv.3 dtrmm.f.3 dtrmm.3 dtrmv.f.3 dtrmv.3 dtrsm.f.3 dtrsm.3 dtrsv.f.3 \
dtrsv.3 dzasum.f.3 dzasum.3 dznrm2.f.3 dznrm2.3 icamax.f.3 icamax.3 idamax.f.3 idamax.3 \
isamax.f.3 isamax.3 izamax.f.3 izamax.3 lsame.3 sasum.f.3 sasum.3 saxpy.f.3 saxpy.3 \
scabs1.f.3 scabs1.3 scasum.f.3 scasum.3 scnrm2.f.3 scnrm2.3 scopy.f.3 scopy.3 sdot.f.3 sdot.3 \
sdsdot.f.3 sdsdot.3 sgbmv.f.3 sgbmv.3 sgemm.f.3 sgemm.3 sgemv.f.3 sgemv.3 sger.f.3 sger.3 \
snrm2.f.3 snrm2.3 srot.f.3 srot.3 srotg.f.3 srotg.3 srotm.f.3 srotm.3 srotmg.f.3 srotmg.3 \
ssbmv.f.3 ssbmv.3 sscal.f.3 sscal.3 sspmv.f.3 sspmv.3 sspr.f.3 sspr.3 sspr2.f.3 sspr2.3 \
sswap.f.3 sswap.3 ssymm.f.3 ssymm.3 ssymv.f.3 ssymv.3 ssyr.f.3 ssyr.3 ssyr2.f.3 ssyr2.3 \
ssyr2k.f.3 ssyr2k.3 ssyrk.f.3 ssyrk.3 stbmv.f.3 stbmv.3 stbsv.f.3 stbsv.3 stpmv.f.3 stpmv.3 \
stpsv.f.3 stpsv.3 strmm.f.3 strmm.3 strmv.f.3 strmv.3 strsm.f.3 strsm.3 strsv.f.3 strsv.3 \
xerbla.3 xerbla_array.3 zaxpy.f.3 zaxpy.3 zcopy.f.3 zcopy.3 \
zdotc.f.3 zdotc.3 zdotu.f.3 zdotu.3 zdrot.f.3 zdrot.3 zdscal.f.3 zdscal.3 zgbmv.f.3 zgbmv.3 \
zgemm.f.3 zgemm.3 zgemv.f.3 zgemv.3 zgerc.f.3 zgerc.3 zgeru.f.3 zgeru.3 zhbmv.f.3 zhbmv.3 \
zhemm.f.3 zhemm.3 zhemv.f.3 zhemv.3 zher.f.3 zher.3 zher2.f.3 zher2.3 zher2k.f.3 zher2k.3 \
zherk.f.3 zherk.3 zhpmv.f.3 zhpmv.3 zhpr.f.3 zhpr.3 zhpr2.f.3 zhpr2.3 zrotg.f.3 zrotg.3 \
zscal.f.3 zscal.3 zswap.f.3 zswap.3 zsymm.f.3 zsymm.3 zsyr2k.f.3 zsyr2k.3 zsyrk.f.3 zsyrk.3 \
ztbmv.f.3 ztbmv.3 ztbsv.f.3 ztbsv.3 ztpmv.f.3 ztpmv.3 ztpsv.f.3 ztpsv.3 ztrmm.f.3 ztrmm.3 \
ztrmv.f.3 ztrmv.3 ztrsm.f.3 ztrsm.3 ztrsv.f.3 ztrsv.3 ../../blas/man/man3
cd ../..
popd

find manpages/blas/man/man3 -type f -printf "%{_mandir}/man3/%f*\n" > blasmans
find manpages/man/man3 -type f -printf "%{_mandir}/man3/%f*\n" > lapackmans

cp -f manpages/blas/man/man3/* $RPM_BUILD_ROOT%{_mandir}/man3
cp -f manpages/man/man3/* $RPM_BUILD_ROOT%{_mandir}/man3

# Cblas headers
mkdir -p %{buildroot}%{_includedir}/cblas/
cp -a CBLAS/include/*.h %{buildroot}%{_includedir}/cblas/

# Lapacke headers
mkdir -p $RPM_BUILD_ROOT%{_includedir}/lapacke/
cp -a LAPACKE/include/*.h $RPM_BUILD_ROOT%{_includedir}/lapacke/

pushd $RPM_BUILD_ROOT%{_libdir}/blas
ln -sf libblas.so.%{version} libblas.so
ln -sf libblas.so.%{version} libblas.so.%{shortver}
ln -sf libblas.so.%{version} libblas.so.%{mediumver}
ln -sf libcblas.so.%{version} libcblas.so
ln -sf libcblas.so.%{version} libcblas.so.%{shortver}
ln -sf libcblas.so.%{version} libcblas.so.%{mediumver}
%if %build64
ln -sf libblas64_.so.%{version} libblas64_.so
ln -sf libblas64_.so.%{version} libblas64_.so.%{shortver}
ln -sf libblas64_.so.%{version} libblas64_.so.%{mediumver}
ln -sf libcblas64_.so.%{version} libcblas64_.so
ln -sf libcblas64_.so.%{version} libcblas64_.so.%{shortver}
ln -sf libcblas64_.so.%{version} libcblas64_.so.%{mediumver}
%endif
popd

pushd $RPM_BUILD_ROOT%{_libdir}/lapack
ln -sf liblapack.so.%{version} liblapack.so
ln -sf liblapack.so.%{version} liblapack.so.%{shortver}
ln -sf liblapack.so.%{version} liblapack.so.%{mediumver}
ln -sf liblapacke.so.%{version} liblapacke.so
ln -sf liblapacke.so.%{version} liblapacke.so.%{shortver}
ln -sf liblapacke.so.%{version} liblapacke.so.%{mediumver}
%if %build64
ln -sf liblapack64_.so.%{version} liblapack64_.so
ln -sf liblapack64_.so.%{version} liblapack64_.so.%{shortver}
ln -sf liblapack64_.so.%{version} liblapack64_.so.%{mediumver}
%endif
popd

# pkgconfig
mkdir -p %{buildroot}%{_libdir}/pkgconfig/

# blas
cp -a BLAS/blas.pc.in %{buildroot}%{_libdir}/pkgconfig/blas-netlib.pc
sed -i 's|@CMAKE_INSTALL_FULL_LIBDIR@|%{_libdir}/blas|g' \
    %{buildroot}%{_libdir}/pkgconfig/blas-netlib.pc
sed -i 's|@CMAKE_INSTALL_FULL_INCLUDEDIR@|%{_includedir}|g' \
    %{buildroot}%{_libdir}/pkgconfig/blas-netlib.pc
sed -i 's|@LAPACK_VERSION@|%{version}|g' \
    %{buildroot}%{_libdir}/pkgconfig/blas-netlib.pc

%if %build64
cp -a %{buildroot}%{_libdir}/pkgconfig/blas-netlib.pc \
   %{buildroot}%{_libdir}/pkgconfig/blas64-netlib.pc
sed -i 's|-lblas|-lblas64_|g' \
    %{buildroot}%{_libdir}/pkgconfig/blas64-netlib.pc
%endif

# cblas
cp -a CBLAS/cblas.pc.in %{buildroot}%{_libdir}/pkgconfig/cblas-netlib.pc
sed -i 's|@CMAKE_INSTALL_FULL_LIBDIR@|%{_libdir}/blas|g' \
    %{buildroot}%{_libdir}/pkgconfig/cblas-netlib.pc
sed -i 's|@CMAKE_INSTALL_FULL_INCLUDEDIR@|%{_includedir}/cblas|g' \
    %{buildroot}%{_libdir}/pkgconfig/cblas-netlib.pc
sed -i 's|@LAPACK_VERSION@|%{version}|g' \
    %{buildroot}%{_libdir}/pkgconfig/cblas-netlib.pc

%if %build64
cp -a %{buildroot}%{_libdir}/pkgconfig/cblas-netlib.pc \
   %{buildroot}%{_libdir}/pkgconfig/cblas64-netlib.pc
sed -i 's|-lcblas|-lcblas64_|g' \
    %{buildroot}%{_libdir}/pkgconfig/cblas64-netlib.pc
sed -i 's|Requires.private: blas|Requires.private: blas64|g' \
    %{buildroot}%{_libdir}/pkgconfig/cblas64-netlib.pc
%endif

# lapack
cp -a lapack.pc.in %{buildroot}%{_libdir}/pkgconfig/lapack-netlib.pc
sed -i 's|@CMAKE_INSTALL_FULL_LIBDIR@|%{_libdir}/lapack|g' \
    %{buildroot}%{_libdir}/pkgconfig/lapack-netlib.pc
sed -i 's|@CMAKE_INSTALL_FULL_INCLUDEDIR@|%{_includedir}|g' \
    %{buildroot}%{_libdir}/pkgconfig/lapack-netlib.pc
sed -i 's|@LAPACK_VERSION@|%{version}|g' \
    %{buildroot}%{_libdir}/pkgconfig/lapack-netlib.pc

%if %build64
cp -a %{buildroot}%{_libdir}/pkgconfig/lapack-netlib.pc \
   %{buildroot}%{_libdir}/pkgconfig/lapack64-netlib.pc
sed -i 's|-llapack|-llapack64_|g' \
    %{buildroot}%{_libdir}/pkgconfig/lapack64-netlib.pc
sed -i 's|blas|blas64|g' \
    %{buildroot}%{_libdir}/pkgconfig/lapack64-netlib.pc
%endif

# lapacke
cp -a LAPACKE/lapacke.pc.in %{buildroot}%{_libdir}/pkgconfig/lapacke-netlib.pc
sed -i 's|@CMAKE_INSTALL_FULL_LIBDIR@|%{_libdir}/lapack|g' \
    %{buildroot}%{_libdir}/pkgconfig/lapacke-netlib.pc
sed -i 's|@CMAKE_INSTALL_FULL_INCLUDEDIR@|%{_includedir}/lapacke|g' \
    %{buildroot}%{_libdir}/pkgconfig/lapacke-netlib.pc
sed -i 's|@LAPACK_VERSION@|%{version}|g' \
    %{buildroot}%{_libdir}/pkgconfig/lapacke-netlib.pc


%clean
rm -fr $RPM_BUILD_ROOT


%post
update-alternatives \
    --install %{_libdir}/liblapack.so.3 liblapack.so.3 \
              %{_libdir}/lapack/liblapack.so.3 10 \
    --slave   %{_libdir}/liblapacke.so.3 liblapacke.so.3 \
              %{_libdir}/lapack/liblapacke.so.3
/sbin/ldconfig

%preun
if [ "$1" = "0" ]
then
    update-alternatives \
        --remove liblapack.so.3 %{_libdir}/lapack/liblapack.so.3
fi

%postun -p /sbin/ldconfig

%triggerpostun -- lapack < 3.7.1-2%{?_dist_release}
update-alternatives \
    --install %{_libdir}/liblapack.so.3 liblapack.so.3 \
              %{_libdir}/lapack/liblapack.so.3 10 \
    --slave   %{_libdir}/liblapacke.so.3 liblapacke.so.3 \
              %{_libdir}/lapack/liblapacke.so.3
/sbin/ldconfig


%post devel
update-alternatives \
    --install %{_libdir}/liblapack.so liblapack.so \
              %{_libdir}/lapack/liblapack.so 10 \
    --slave   %{_libdir}/liblapacke.so liblapacke.so \
              %{_libdir}/lapack/liblapacke.so \
    --slave   %{_libdir}/pkgconfig/lapack.pc lapack.pc \
              %{_libdir}/pkgconfig/lapack-netlib.pc \
    --slave   %{_libdir}/pkgconfig/lapacke.pc lapacke.pc \
              %{_libdir}/pkgconfig/lapacke-netlib.pc
/sbin/ldconfig

%preun devel
if [ "$1" = "0" ]
then
    update-alternatives \
        --remove liblapack.so %{_libdir}/lapack/liblapack.so
fi

%postun devel -p /sbin/ldconfig

%triggerpostun devel -- lapack-devel < 3.7.1-2%{?_dist_release}
update-alternatives \
    --install %{_libdir}/liblapack.so liblapack.so \
              %{_libdir}/lapack/liblapack.so 10 \
    --slave   %{_libdir}/liblapacke.so liblapacke.so \
              %{_libdir}/lapack/liblapacke.so \
    --slave   %{_libdir}/pkgconfig/lapack.pc lapack.pc \
              %{_libdir}/pkgconfig/lapack-netlib.pc \
    --slave   %{_libdir}/pkgconfig/lapacke.pc lapacke.pc \
              %{_libdir}/pkgconfig/lapacke-netlib.pc
/sbin/ldconfig


%post static
update-alternatives \
    --install %{_libdir}/liblapack.a liblapack.a \
              %{_libdir}/lapack/liblapack.a 10 \
    --slave   %{_libdir}/liblapacke.a liblapacke.a \
              %{_libdir}/lapack/liblapacke.a

%preun static
if [ "$1" = "0" ]
then
    update-alternatives \
        --remove liblapack.a %{_libdir}/lapack/liblapack.a
fi

%triggerpostun static -- lapack-static < 3.7.1-2%{?_dist_release}
update-alternatives \
    --install %{_libdir}/liblapack.a liblapack.a \
              %{_libdir}/lapack/liblapack.a 10 \
    --slave   %{_libdir}/liblapacke.a liblapacke.a \
              %{_libdir}/lapack/liblapacke.a


%post -n blas
update-alternatives \
    --install %{_libdir}/libblas.so.3 libblas.so.3 \
              %{_libdir}/blas/libblas.so.3 10 \
    --slave   %{_libdir}/libcblas.so.3 libcblas.so.3 \
              %{_libdir}/blas/libcblas.so.3
/sbin/ldconfig

%preun -n blas
if [ "$1" = "0" ]
then
    update-alternatives \
        --remove libblas.so.3 %{_libdir}/blas/libblas.so.3
fi

%postun -n blas -p /sbin/ldconfig

%triggerpostun -n blas -- blas < 3.7.1-2%{?_dist_release}
update-alternatives \
    --install %{_libdir}/libblas.so.3 libblas.so.3 \
              %{_libdir}/blas/libblas.so.3 10 \
    --slave   %{_libdir}/libcblas.so.3 libcblas.so.3 \
              %{_libdir}/blas/libcblas.so.3
/sbin/ldconfig


%post -n blas-devel
update-alternatives \
    --install %{_libdir}/libblas.so libblas.so \
              %{_libdir}/blas/libblas.so 10 \
    --slave   %{_libdir}/libcblas.so libcblas.so \
              %{_libdir}/blas/libcblas.so \
    --slave   %{_libdir}/pkgconfig/blas.pc blas.pc \
              %{_libdir}/pkgconfig/blas-netlib.pc \
    --slave   %{_libdir}/pkgconfig/cblas.pc cblas.pc \
              %{_libdir}/pkgconfig/cblas-netlib.pc
/sbin/ldconfig

%preun -n blas-devel
if [ "$1" = "0" ]
then
    update-alternatives \
        --remove libblas.so %{_libdir}/blas/libblas.so
fi

%postun -n blas-devel -p /sbin/ldconfig

%triggerpostun -n blas-devel -- blas-devel < 3.7.1-2%{?_dist_release}
update-alternatives \
    --install %{_libdir}/libblas.so libblas.so \
              %{_libdir}/blas/libblas.so 10 \
    --slave   %{_libdir}/libcblas.so libcblas.so \
              %{_libdir}/blas/libcblas.so \
    --slave   %{_libdir}/pkgconfig/blas.pc blas.pc \
              %{_libdir}/pkgconfig/blas-netlib.pc \
    --slave   %{_libdir}/pkgconfig/cblas.pc cblas.pc \
              %{_libdir}/pkgconfig/cblas-netlib.pc
/sbin/ldconfig

%post -n blas-static
update-alternatives \
    --install %{_libdir}/libblas.a libblas.a \
              %{_libdir}/blas/libblas.a 10 \
    --slave   %{_libdir}/libcblas.a libcblas.a \
              %{_libdir}/blas/libcblas.a

%preun -n blas-static
if [ "$1" = "0" ]
then
    update-alternatives \
        --remove libblas.a %{_libdir}/blas/libblas.a
fi

%triggerpostun -n blas-static -- blas-static < 3.7.1-2%{?_dist_release}
update-alternatives \
    --install %{_libdir}/libblas.a libblas.a \
              %{_libdir}/blas/libblas.a 10 \
    --slave   %{_libdir}/libcblas.a libcblas.a \
              %{_libdir}/blas/libcblas.a


%if %build64
%post -n lapack64
update-alternatives \
    --install %{_libdir}/liblapack64_.so.3 liblapack64_.so.3 \
              %{_libdir}/lapack/liblapack64_.so.3 10
/sbin/ldconfig

%preun -n lapack64
if [ "$1" = "0" ]
then
    update-alternatives \
        --remove liblapack64_.so.3 %{_libdir}/lapack/liblapack64_.so.3
fi

%postun -n lapack64 -p /sbin/ldconfig


%post -n lapack64-devel
update-alternatives \
    --install %{_libdir}/liblapack64_.so liblapack64_.so \
              %{_libdir}/lapack/liblapack64_.so 10 \
    --slave   %{_libdir}/pkgconfig/lapack64.pc lapack64.pc \
              %{_libdir}/pkgconfig/lapack64-netlib.pc
/sbin/ldconfig

%preun -n lapack64-devel
if [ "$1" = "0" ]
then
    update-alternatives \
        --remove liblapack64_.so %{_libdir}/lapack/liblapack64_.so
fi

%postun  -n lapack64-devel -p /sbin/ldconfig

%post -n lapack64-static
update-alternatives \
    --install %{_libdir}/liblapack64_.a liblapack64_.a \
              %{_libdir}/lapack/liblapack64_.a 10

%preun -n lapack64-static
if [ "$1" = "0" ]
then
    update-alternatives \
        --remove liblapack64_.a %{_libdir}/lapack/liblapack64_.a
fi


%post -n blas64
update-alternatives \
    --install %{_libdir}/libblas64_.so.3 libblas64_.so.3 \
              %{_libdir}/blas/libblas64_.so.3 10 \
    --slave   %{_libdir}/libcblas64_.so.3 libcblas64_.so.3 \
              %{_libdir}/blas/libcblas64_.so.3
/sbin/ldconfig

%preun -n blas64
if [ "$1" = "0" ]
then
    update-alternatives \
        --remove libblas64_.so.3 %{_libdir}/blas/libblas64_.so.3
fi

%postun -n blas64 -p /sbin/ldconfig


%post -n blas64-devel
update-alternatives \
    --install %{_libdir}/libblas64_.so libblas64_.so \
              %{_libdir}/blas/libblas64_.so 10 \
    --slave   %{_libdir}/libcblas64_.so libcblas64_.so \
              %{_libdir}/blas/libcblas64_.so \
    --slave   %{_libdir}/pkgconfig/blas64.pc blas64.pc \
              %{_libdir}/pkgconfig/blas64-netlib.pc \
    --slave   %{_libdir}/pkgconfig/cblas64.pc cblas64.pc \
              %{_libdir}/pkgconfig/cblas64-netlib.pc
/sbin/ldconfig

%preun -n blas64-devel
if [ "$1" = "0" ]
then
    update-alternatives \
        --remove libblas64_.so %{_libdir}/blas/libblas64_.so
fi

%postun -n blas64-devel -p /sbin/ldconfig

%post -n blas64-static
update-alternatives \
    --install %{_libdir}/libblas64_.a libblas64_.a \
              %{_libdir}/blas/libblas64_.a 10 \
    --slave   %{_libdir}/libcblas64_.a libcblas64_.a \
              %{_libdir}/blas/libcblas64_.a

%preun -n blas64-static
if [ "$1" = "0" ]
then
    update-alternatives \
        --remove libblas64_.a %{_libdir}/blas/libblas64_.a
fi
%endif


%files -f lapackmans
%defattr(-,root,root)
%doc README.md LICENSE lapackqref.ps
%dir %{_mandir}/man3/
%dir %{_libdir}/lapack
%{_libdir}/lapack/liblapack.so.*
%{_libdir}/lapack/liblapacke.so.*

%files devel
%defattr(-,root,root,-)
%{_includedir}/lapacke/
%{_libdir}/lapack/liblapack.so
%{_libdir}/lapack/liblapacke.so
%{_libdir}/pkgconfig/lapack-netlib.pc
%{_libdir}/pkgconfig/lapacke-netlib.pc

%files static
%defattr(-,root,root,-)
%{_libdir}/lapack/liblapack*.a

%files -n blas -f blasmans
%defattr(-,root,root)
%doc blasqr.ps LICENSE
%dir %{_mandir}/man3/
%dir %{_libdir}/blas
%{_libdir}/blas/libblas.so.*
%{_libdir}/blas/libcblas.so.*

%files -n blas-devel
%defattr(-,root,root,-)
%{_includedir}/cblas/
%{_libdir}/blas/libblas.so
%{_libdir}/blas/libcblas.so
%{_libdir}/pkgconfig/blas-netlib.pc
%{_libdir}/pkgconfig/cblas-netlib.pc

%files -n blas-static
%defattr(-,root,root,-)
%{_libdir}/blas/libblas.a
%{_libdir}/blas/libcblas.a

%if %build64
%files -n blas64
%doc LICENSE
%dir %{_libdir}/blas
%{_libdir}/blas/libblas64_.so.*
%{_libdir}/blas/libcblas64_.so.*

%files -n blas64-devel
%{_libdir}/blas/libblas64_.so
%{_libdir}/blas/libcblas64_.so
%{_libdir}/pkgconfig/blas64-netlib.pc
%{_libdir}/pkgconfig/cblas64-netlib.pc

%files -n blas64-static
%{_libdir}/blas/libblas64_.a
%{_libdir}/blas/libcblas64_.a

%files -n lapack64
%doc README.md LICENSE
%dir %{_libdir}/lapack
%{_libdir}/lapack/liblapack64_.so.*

%files -n lapack64-devel
%{_libdir}/lapack/liblapack64_.so
%{_libdir}/pkgconfig/lapack64-netlib.pc

%files -n lapack64-static
%{_libdir}/lapack/liblapack64_.a
%{_libdir}/lapack/liblapack64_pic.a
%endif


%changelog
* Fri Jan 25 2019 Toshiaki Ara <ara_t@384.jp> 3.7.1-4
- rebuild with gfortran-8.2.0

* Wed Jun 27 2018 Toshiaki Ara <ara_t@384.jp> 3.7.1-3
- Build versions of the 64-bit libraries with an additional suffix

* Mon Jun 25 2018 Toshiaki Ara <ara_t@384.jp> 3.7.1-2
- build cblas
- include pkgconfig files
- adapt update-alternatives

* Tue Jun 05 2018 Toshiaki Ara <ara_t@384.jp> 3.7.1-1
- updated to 3.7.1
- drop Patches 1 to 8
- update Source2 and 3 (Makefile.{blas,lapack}) and add Patches 11-13
  from Fedora package

* Tue Jan 27 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 3.5.0-1
- updated to 3.5.0
- moved lapack and blas to System Environment/Libraries Group

* Thu Feb 23 2012 NAKAMURA Kenta <kenta@vinelinux.org> 3.4.0-1
- update to 3.4.0
- build and include lapacke

* Sat Nov 26 2011 NAKAMURA Kenta <kenta@vinelinux.org> 3.3.1-1
- new upstream release
- update package descriptions

* Fri Feb 19 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.2.1-1
- new upstream release
- built with new toolchain
- added SOURCE1

* Wed Sep 24 2008 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.1.1-2
- applied new versioning policy
- spec in UTF-8

* Wed Aug 15 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.1.1-1vl3
- rebuilt for VineSeed

* Wed Aug 15 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.1.1-1vl2
- rebuilt for VinePlus/4.0
- added Patch4, Source102 and Source103 for compiling in g77
- added BuildRequires: coreutils, findutils

* Tue Aug  7 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.1.1-1vl1
- new upstream release based on Fedora packages
  * Wed Sep 14 2005 Tom "spot" Callaway <tcallawa@redhat.com> 3.0-30
  - make -devel packages
  - make liblapack_pic.a package
  * Wed Aug 20 2003 Jeremy Katz <katzj@redhat.com> 3.0-22
  - nuke -man subpackages (#97506)
- rebuilt with gfortran

* Fri Dec 26 2003 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.0-17vl3
- rebuild with new toolchains

* Mon Oct 13 2003 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.0-17vl2
- rebuild with new toolchains

* Thu Jul 18 2002 KOBAYASHI R. Taizo <tkoba@vinelinux.org> 3.0-17vl1
- modified for Vine.

* Fri Jun 21 2002 Tim Powers <timp@redhat.com>
- automated rebuild

* Thu May 23 2002 Tim Powers <timp@redhat.com>
- automated rebuild

* Wed May  1 2002 Trond Eivind Glomsr� <teg@redhat.com> 3.0-15
- Rebuild

* Wed Feb 27 2002 Fuhito Suguri <bitwalk@jcom.home.ne.jp>	3.0-14bw
- rebuild for RH7.2.

* Wed Jan 09 2002 Tim Powers <timp@redhat.com>
- automated rebuild

* Mon Aug 13 2001 Trond Eivind Glomsrod <teg@redhat.com> 3.0-12
- The man-pages for xerbla and lsame were in blas-man and lapack-man (#51605)

* Fri Jun  8 2001 Trond Eivind Glomsrod <teg@redhat.com>
- Reenable optimization for IA64

* Fri May 25 2001 Trond Eivind Glomsrod <teg@redhat.com>
- Add all patches from the LAPACK site as of 2001-05-25
- Use this workaround for IA64 instead
- Remove SPARC workaround
- Don't exclude IA64

* Thu Dec 07 2000 Trond Eivind Glomsrod <teg@redhat.com>
- rebuild for main distribution

* Mon Nov 20 2000 Trond Eivind Glomsrod <teg@redhat.com>
- add the LAPACK Quick Reference Guide to the docs
- add the BLAS Quick Reference Guide to the docs

* Tue Aug 01 2000 Trond Eivind Glomsrod <teg@redhat.com>
- fix lack of ldconfig in postuninstall script

* Mon Jul 24 2000 Prospector <prospector@redhat.com>
- rebuilt

* Mon Jul 10 2000 Trond Eivind Glomsrod <teg@redhat.com>
- updated with the latest updates (new tarfile..) from netlib 

* Thu Jun 15 2000 Trond Eivind Glomsrod <teg@redhat.com>
- use %%{_mandir}
- added some flags to work around SPARC compiler bug

* Wed Jan 19 2000 Tim Powers <timp@redhat.com>
- bzipped sources to conserve space

* Tue Jan  4 2000 Jeff Johnson <jbj@redhat.com>
- build for PowerTools 6.2.

* Sat Dec 25 1999 Joachim Frieben <jfrieben@hotmail.com>
- updated to version v3.0 + update as of Tue Nov 30 1999

* Sat Oct 23 1999 Joachim Frieben <jfrieben@hotmail.com>
- updated Red Hat makefiles to v3.0

* Mon Aug 2 1999 Tim Powers <timp@redhat.com>
- updated to v3.0
- built for 6.1

* Mon Apr 12 1999 Michael Maher <mike@redhat.com>
- built package for 6.0

* Sat Oct 24 1998 Jeff Johnson <jbj@redhat.com>
- new description/summary text.

* Fri Jul 17 1998 Jeff Johnson <jbj@redhat.com>
- repackage for powertools.

* Sun Feb 15 1998 Trond Eivind Glomsrod <teg@pvv.ntnu.no>
 [lapack-2.0-9]
 - No code updates, just built with a customized rpm -
   this should make dependencies right.

* Sat Feb 07 1998 Trond Eivind Glomsrod <teg@pvv.ntnu.no>
 [lapack-2.0-8]
 - Total rewrite of the spec file
 - Added my own makefiles - libs should build better,
   static libs should work (and be faster than they
	would be if they had worked earlier ;)
 - No patch necessary anymore.
 - Renamed lapack-blas and lapack-blas-man to
   blas and blas-man. "Obsoletes:" tag added.
   (oh - and as always: Dedicated to the girl I
   love, Eline Skirnisdottir)

* Sat Dec 06 1997 Trond Eivind Glomsrod <teg@pvv.ntnu.no>
 [lapack-2.0-7]
  - added a dependency to glibc, so people don't try with libc5

* Thu Nov 20 1997 Trond Eivind Glomsrod <teg@pvv.ntnu.no>
  [lapack-2.0-6]
  - removed etime.c
  - compiled with egcs, and for glibc 2.0

* Sun Oct 12 1997 Trond Eivind Glomsrod <teg@pvv.ntnu.no>
  [lapack-2.0-5]
  - added a changelog
  - cleaned up building of shared libs
  - now uses a BuildRoot
  - cleaned up the specfile