Arch Linux ARM openblas

I see the openblas is still broken upstream in Arch Linux ARM. If anyone’s having problems with it I made/adapted this PKGBUILD a while ago:

# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Giuseppe Borzi <gborzi _AT_ ieee _DOT_ org>
# Contributor: Feakster <feakster at posteo dot eu>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - set build targets
#  - clear Makefile.arm (bad cflags overrides)

pkgname=openblas
_pkgname=OpenBLAS
pkgver=0.3.15
pkgrel=1
pkgdesc='An optimized BLAS library based on GotoBLAS2 1.13 BSD'
arch=('arm' 'armv6h' 'armv7h' 'aarch64')
url='https://www.openblas.net/'
license=('BSD') # BSD 3-clause license
depends=('gcc-libs' 'openmp')
makedepends=('gcc-fortran')
provides=('blas=3.8.0') # 3.9.0? Does the version even need to be set?
conflicts=('blas')
source=("${_pkgname}-v${pkgver}.tar.gz::https://github.com/xianyi/${_pkgname}/archive/v${pkgver}.tar.gz")
sha512sums=('c07964ead5ffe9cf088364697bfe5cb409170663e420bdcd08a6366a028625d2a3c23ee4ddbaf0e625860a9fd08cbbb39f97eb985c366c052696d6f8598a844f')

prepare() {
    # Change Directory
    cd "$srcdir"/$_pkgname-$pkgver

    # Wipe 32-Bit ARM Makefile Contents
    truncate -s 0 Makefile.arm # See 'ALARM'.

    # Manually Set CONFIG Target & Opts
    if [ $CARCH = arm ]; then
        _CONFIG='TARGET=ARMV5'
    elif [ $CARCH = armv6h ]; then
        _CONFIG='TARGET=ARMV6'
    elif [ $CARCH = armv7h ]; then
        _CONFIG='TARGET=ARMV7'
        CFLAGS=`echo $CFLAGS | sed 's/vfpv3-d16/neon/'` # See 'ALARM'.
        CXXFLAGS="$CFLAGS" # See 'ALARM'. Used?
    elif [ $CARCH = aarch64 ]; then
        _CONFIG='TARGET=ARMV8 DYNAMIC_ARCH=1'
    else
        echo 'CPU architecture not supported'
        exit 1
    fi
}

build() {
    # Change Directory
    cd "$srcdir"/$_pkgname-$pkgver

    # Build Libs
    make \
    NO_STATIC=1 NO_LAPACK=1 NO_LAPACKE=1 NO_CBLAS=1 NO_AFFINITY=1 USE_OPENMP=1 \
    CFLAGS="$CPPFLAGS $CFLAGS" $_CONFIG \
    NUM_THREADS=64 MAJOR_VERSION=3 \
    libs shared
}

package() {
    # Change Directory
    cd "$srcdir"/$_pkgname-$pkgver

    # Install
    make install \
    PREFIX="$pkgdir"/usr

    # Remove Crud
    rm -f "$pkgdir"/usr/include/cblas.h "$pkgdir"/usr/include/lapack*
    rmdir "$pkgdir"/usr/bin

    # Install License
    install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE

    # Change Directory
    cd "$pkgdir"/usr/lib

    # Fix File Naming
    find . -maxdepth 1 -type f -name 'libopenblas*.so*' -exec mv {} libopenblas.so.${pkgver} \;
    find . -maxdepth 1 -type f -name 'libopenblas*.a' -exec mv {} libopenblas.${pkgver}.a \;

    # Regenerate Symlinks
    find . -maxdepth 1 -type l -name 'lib*.so*' -delete
    ln -frs libopenblas.${pkgver}.a libopenblas.a
    for LIB in libblas.so libblas.so.3 libopenblas.so libopenblas.so.3
    do
        ln -frs libopenblas.so.${pkgver} $LIB
    done

    # Mod Ancillary Files
    ln -rs "$pkgdir"/usr/lib/pkgconfig/openblas.pc "$pkgdir"/usr/lib/pkgconfig/blas.pc
    sed -i "s|$pkgdir||" "$pkgdir"/usr/lib/pkgconfig/openblas.pc
    sed -i "s|$pkgdir||" "$pkgdir"/usr/lib/cmake/openblas/OpenBLASConfig.cmake
}

# vim:set ts=2 sw=2 et:

Should serve as a temporary solution. Remove the DYNAMIC_ARCH=1 flag if you’re on aarch64, but don’t want openblas built for all possible ARMv8 targets. I’ll revisit this script at some point, but I haven’t had time recently.

2 Likes

Thank you for your contribution!

Pudge

1 Like