summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 29b8c29a6044cef7d229a362a135296b5387374f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
pkgname=mingw-w64-suitesparse
pkgver=5.8.1
pkgrel=1
pkgdesc="A collection of sparse matrix libraries (mingw-w64)"
url="https://people.engr.tamu.edu/davis/suitesparse.html"
arch=('any')
depends=('mingw-w64-lapack' 'mingw-w64-metis' 'mingw-w64-mpfr')
makedepends=('mingw-w64-cmake' 'mingw-w64-make')
license=('GPL')
options=('!buildflags' '!strip' 'staticlibs')
source=("https://github.com/DrTimothyAldenDavis/SuiteSparse/archive/v${pkgver}.tar.gz" suitesparse-no-demo.patch)
sha256sums=('06726e471fbaa55f792578f9b4ab282ea9d008cf39ddcc3b42b73400acddef40' SKIP)

_architectures="i686-w64-mingw32 x86_64-w64-mingw32"

prepare () {
  cd "$srcdir"/SuiteSparse-${pkgver}

  # no demos
  patch -p1 -i "$srcdir"/suitesparse-no-demo.patch
  sed -i "s|default: all|default: library|g" */Makefile
  sed -i "s|all: C cov|all: library|g" */Makefile

  # undefined refs to gcov
  sed -i "s|SET(CMAKE_EXE_LINKER_FLAGS_DEBUG|#SET(CMAKE_EXE_LINKER_FLAGS_DEBUG|g" Mongoose/CMakeLists.txt
  sed -i "s|SET(CMAKE_CXX_FLAGS_DEBUG|#SET(CMAKE_CXX_FLAGS_DEBUG|g" Mongoose/CMakeLists.txt
  sed -i "s|SET(CMAKE_C_FLAGS_DEBUG|#SET(CMAKE_C_FLAGS_DEBUG|g" Mongoose/CMakeLists.txt

  # related to mingw
  curl -L https://raw.githubusercontent.com/msys2/MINGW-packages/master/mingw-w64-suitesparse/0001-mingw-w64-Use-a-not-lib-as-AR_TARGET-extension.patch | patch -p1
  curl -L https://raw.githubusercontent.com/msys2/MINGW-packages/master/mingw-w64-suitesparse/0002-mingw-w64-Set-SO_OPTS--shared-move-dlls-create-import-libs.patch | patch -p1
  curl -L https://raw.githubusercontent.com/msys2/MINGW-packages/master/mingw-w64-suitesparse/0004-mingw-w64-install-static-libs.patch | patch -p1
  sed -i 's| \-lsuitesparseconfig| \-L../../lib \-lsuitesparseconfig \-lssp|g' */Lib/Makefile

  # x86_64 conversion errors
  sed -i "s|nzmax = std::max(nzmax, 1L)|nzmax = std::max(nzmax, (csi)1)|g" Mongoose/Source/Mongoose_CSparse.cpp
  sed -i "s|Int M, N, nz;|long M, N, nz;|g" Mongoose/Source/Mongoose_IO.cpp
  sed -i "s|mm_read_mtx_crd_data(file, M, N, nz, I, J, val, matcode);|mm_read_mtx_crd_data(file, M, N, nz, (long*)I, (long*)J, val, matcode);|g" Mongoose/Source/Mongoose_IO.cpp

  # sliplu is weirder
  sed -i "s|default: C|default: library|g" SLIP_LU/Makefile
  sed -i "/SO_PLAIN/d" SLIP_LU/Lib/Makefile
  sed -i "/SO_MAIN/d" SLIP_LU/Lib/Makefile
}

build() {
  cd "$srcdir"
  for _arch in ${_architectures}; do
    cp -r SuiteSparse-${pkgver} build-${_arch} && pushd build-${_arch}
    ${_arch}-make \
      UNAME=Windows BLAS="-llapack -lblas -lgfortran -lquadmath" \
      CMAKE_OPTIONS="-DCMAKE_INSTALL_PREFIX=\"/usr/${_arch}\" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=\"/usr/share/mingw/toolchain-${_arch}.cmake\"" \
      MY_METIS_LIB="-lmetis"
    popd
  done
}

package() {
  for _arch in ${_architectures}; do
    install -dm755 "${pkgdir}"/usr/${_arch}/{bin,lib,include/suitesparse}
    cd "${srcdir}"/build-${_arch}
    ${_arch}-make install \
      UNAME=Windows BLAS="-llapack -lblas -lgfortran -lquadmath" \
      CMAKE_OPTIONS="-DCMAKE_INSTALL_PREFIX=\"/usr/${_arch}\" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=\"/usr/share/mingw/toolchain-${_arch}.cmake\"" \
      MY_METIS_LIB="-lmetis" \
      DESTDIR="${pkgdir}" INSTALL="${pkgdir}"/usr/${_arch}
    mv "${pkgdir}"/usr/${_arch}/lib/libsliplu.dll "${pkgdir}"/usr/${_arch}/bin
    rm "${pkgdir}"/usr/${_arch}/bin/*.exe
    rm -rf "${pkgdir}"/usr/${_arch}/share
    ${_arch}-strip --strip-unneeded "$pkgdir"/usr/${_arch}/bin/*.dll
    ${_arch}-strip -g "$pkgdir"/usr/${_arch}/lib/*.a
  done
}