easyblock = 'ConfigureMake'

name = 'OpenBLAS'
version = '0.2.18'

lapackver = '3.6.1'
versionsuffix = '-LAPACK-%s' % lapackver

homepage = 'http://xianyi.github.com/OpenBLAS/'
description = """OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version."""

toolchain = {'name': 'GCC', 'version': '5.4.0-2.26'}

lapack_src = 'lapack-%s.tgz' % lapackver
large_src = 'large.tgz'
timing_src = 'timing.tgz'

lapack_unpack_cmd = 'cd %(name)s-%(version)s; rm -rf lapack-netlib;'
lapack_unpack_cmd += 'mkdir lapack-netlib;'
lapack_unpack_cmd += 'tar -C lapack-netlib --strip-components=1 -zxf %s; cd -'

source_urls = [
    # order matters, trying to download the LAPACK tarball from GitHub causes trouble
    "http://www.netlib.org/lapack/",
    "http://www.netlib.org/lapack/timing/",
    "https://github.com/xianyi/OpenBLAS/archive/",
]
sources = [
    'v%(version)s.tar.gz',
    {'filename': lapack_src, 'extract_cmd': lapack_unpack_cmd},
    large_src,
    timing_src,
]
patches = [
    (large_src, '.'),
    (timing_src, '.'),
]
checksums = [
    '7d9f8d4ea4a65ab68088f3bb557f03a7ac9cb5036ef2ba30546c3a28774a4112',  # v0.2.18.tar.gz
    '888a50d787a9d828074db581c80b2d22bdb91435a673b1bf6cd6eb51aa50d1de',  # lapack-3.6.1.tgz
    'f328d88b7fa97722f271d7d0cfea1c220e0f8e5ed5ff01d8ef1eb51d6f4243a1',  # large.tgz
    '999c65f8ea8bd4eac7f1c7f3463d4946917afd20a997807300fe35d70122f3af',  # timing.tgz
    'f328d88b7fa97722f271d7d0cfea1c220e0f8e5ed5ff01d8ef1eb51d6f4243a1',  # large.tgz
    '999c65f8ea8bd4eac7f1c7f3463d4946917afd20a997807300fe35d70122f3af',  # timing.tgz
]

skipsteps = ['configure']

buildopts = 'BINARY=64 USE_THREAD=1 CC="$CC" FC="$F77" NO_AFFINITY=1'
installopts = "USE_THREAD=1 PREFIX=%(installdir)s"

# extensive testing can be enabled by uncommenting the line below
# runtest = 'PATH=.:$PATH lapack-timing'

sanity_check_paths = {
    'files': ['include/cblas.h', 'include/f77blas.h', 'include/lapacke_config.h', 'include/lapacke.h',
              'include/lapacke_mangling.h', 'include/lapacke_utils.h', 'include/openblas_config.h',
              'lib/libopenblas.a', 'lib/libopenblas.%s' % SHLIB_EXT],
    'dirs': [],
}

moduleclass = 'numlib'
