File hdf5plugin-system-libs.patch of Package python-hdf5plugin

Index: hdf5plugin-5.0.0/setup.py
===================================================================
--- hdf5plugin-5.0.0.orig/setup.py
+++ hdf5plugin-5.0.0/setup.py
@@ -35,6 +35,7 @@ from pathlib import Path
 import itertools
 import logging
 import os
+import subprocess
 import sys
 import sysconfig
 import tempfile
@@ -136,32 +137,21 @@ class HostConfig:
         self.__compiler = get_compiler(compiler)
 
         # Set architecture specific compile args
-        if self.ARCH in ('X86_32', 'X86_64', 'MIPS_64'):
-            self.native_compile_args = ("-march=native",)
-        elif self.ARCH in ('ARM_7', 'ARM_8', 'PPC_64'):
-            self.native_compile_args = ("-mcpu=native",)
-        else:
-            self.native_compile_args = ()
+        self.native_compile_args = ()
 
         if self.ARCH in ('X86_32', 'X86_64'):
             self.sse2_compile_args = ('-msse2',)  # /arch:SSE2 is on by default
         else:
             self.sse2_compile_args = ()
 
-        if self.ARCH in ('X86_32', 'X86_64'):
-            self.ssse3_compile_args = ('-mssse3',)  # There is no /arch:SSSE3
-        else:
-            self.ssse3_compile_args = ()
+        self.ssse3_compile_args = ()
 
         if self.ARCH in ('X86_32', 'X86_64'):
             self.avx2_compile_args = ('-mavx2', '/arch:AVX2')
         else:
             self.avx2_compile_args = ()
 
-        if self.ARCH in ('X86_32', 'X86_64'):
-            self.avx512_compile_args = ('-mavx512f', '-mavx512bw', '/arch:AVX512')
-        else:
-            self.avx512_compile_args = ()
+        self.avx512_compile_args = ()
 
     def get_shared_lib_extension(self) -> str:
         """Returns shared library file extension"""
@@ -253,7 +243,7 @@ class HostConfig:
 
     def has_ssse3(self) -> bool:
         """Check SSSE3 availability on host"""
-        return self._has_x86_simd('ssse3')
+        return False  # SSE3 not available on openSUSE non hwcaps libs
 
     def has_avx2(self) -> bool:
         """Check AVX2 availability on host"""
@@ -261,7 +251,7 @@ class HostConfig:
 
     def has_avx512(self) -> bool:
         """Check AVX512 "F" and "BW" instruction sets availability on host"""
-        return self._has_x86_simd('avx512f', 'avx512bw')
+        return False  # Disabled on openSUSE non hwcaps libs
 
     def has_openmp(self) -> bool:
         """Check OpenMP availability on host"""
@@ -731,40 +721,62 @@ def get_lz4_clib(field=None):
     if BuildConfig.INTEL_IPP_DIR is not None:
         return _get_lz4_ipp_clib(field)
 
-    cflags = ['-O3', '-ffast-math', '-std=gnu99']
-    cflags += ['/Ox', '/fp:fast']
+    if os.environ.get('HDF5PLUGIN_SYSTEM_LZ4', None):
+        config = dict(
+            sources=[],
+            include_dirs=[subprocess.check_output(
+                            ["pkg-config", '--variable=includedir', 'liblz4']
+                          )],
+            cflags=[],
+        )
+        libraries = [l.strip()[2:] for l in subprocess.check_output(
+                        ["pkg-config", '--libs', 'liblz4']
+                     ).decode().strip().split(" ")]
+    else:
+        cflags = ['-O3', '-ffast-math', '-std=gnu99']
+        cflags += ['/Ox', '/fp:fast']
 
-    lz4_dir = glob('src/c-blosc2/internal-complibs/lz4*')[0]
+        lz4_dir = glob('src/c-blosc2/internal-complibs/lz4*')[0]
 
-    config = dict(
-        sources=glob(f'{lz4_dir}/*.c'),
-        include_dirs=[lz4_dir],
-        cflags=cflags,
-    )
+        config = dict(
+            sources=glob(f'{lz4_dir}/*.c'),
+            include_dirs=[lz4_dir],
+            cflags=cflags,
+        )
+        libraries = []
 
     if field is None:
         return 'lz4', config
     if field == 'extra_link_args':
         return []
     if field == 'libraries':
-        return []
+        return libraries
     return config[field]
 
 
 def get_snappy_clib(field=None):
     """snappy static lib build config"""
-    snappy_dir = 'src/snappy'
+    if os.environ.get('HDF5PLUGIN_SYSTEM_SNAPPY', None):
+        config = dict(
+            sources=[],
+            include_dirs=[subprocess.check_output(
+                            ["pkg-config", '--variable=includedir', 'snappy']
+                          )],
+            cflags=[],
+        )
+    else:    
+        snappy_dir = 'src/snappy'
 
-    config = dict(
-        sources=prefix(snappy_dir, [
-            'snappy-c.cc',
-            'snappy-sinksource.cc',
-            'snappy-stubs-internal.cc',
-            'snappy.cc',
-        ]),
-        include_dirs=[snappy_dir],
-        cflags=['-std=c++11'],
-    )
+        config = dict(
+            sources=prefix(snappy_dir, [
+                'snappy-c.cc',
+                'snappy-sinksource.cc',
+                'snappy-stubs-internal.cc',
+                'snappy.cc',
+            ]),
+            include_dirs=[snappy_dir],
+            cflags=['-std=c++11'],
+        )
 
     if field is None:
         return 'snappy', config
@@ -812,40 +824,62 @@ def get_zfp_clib(field=None):
 
 def get_zlib_clib(field=None):
     """ZLib static lib build config"""
-    cflags = ['-O3', '-ffast-math', '-std=gnu99']
-    cflags += ['/Ox', '/fp:fast']
+    if os.environ.get('HDF5PLUGIN_SYSTEM_ZLIB', None):
+        config = dict(
+            sources=[],
+            include_dirs=[subprocess.check_output(
+                            ["pkg-config", '--variable=includedir', 'zlib']
+                          )],
+            cflags=[]
+        )
+    else:
+        cflags = ['-O3', '-ffast-math', '-std=gnu99']
+        cflags += ['/Ox', '/fp:fast']
 
-    zlib_dir = glob('src/c-blosc/internal-complibs/zlib*')[0]
+        zlib_dir = glob('src/c-blosc/internal-complibs/zlib*')[0]
 
-    config = dict(
-        sources=glob(f'{zlib_dir}/*.c'),
-        include_dirs=[zlib_dir],
-        cflags=cflags,
-    )
+        config = dict(
+            sources=glob(f'{zlib_dir}/*.c'),
+            include_dirs=[zlib_dir],
+            cflags=cflags,
+        )
 
     if field is None:
-        return 'zlib', config
+        return 'z', config
     return config[field]
 
 
 def get_zstd_clib(field=None):
-    """zstd static lib build config"""
-    cflags = ['-O3', '-ffast-math', '-std=gnu99']
-    cflags += ['/Ox', '/fp:fast']
+    """zstd static lib build config"""    
+    if os.environ.get('HDF5PLUGIN_SYSTEM_ZSTD', None):
+        if field == 'extra_objects':
+            return []
+        config = dict(
+            sources=[],
+            include_dirs=[subprocess.check_output(
+                            ["pkg-config", '--variable=includedir', 'libzstd']
+                          )],
+            cflags=[],
+        )
+    else:
+        cflags = ['-O3', '-ffast-math', '-std=gnu99']
+        cflags += ['/Ox', '/fp:fast']
 
-    zstd_dir = glob('src/c-blosc2/internal-complibs/zstd*')[0]
+        zstd_dir = glob('src/c-blosc2/internal-complibs/zstd*')[0]
 
-    config = dict(
-        sources=glob(f'{zstd_dir}/*/*.c'),
-        include_dirs=[zstd_dir, f'{zstd_dir}/common'],
-        macros=[] if BuildConfig.USE_BMI2 else [('ZSTD_DISABLE_ASM', 1)],
-        cflags=cflags,
-    )
+        if field == 'extra_objects':
+            return glob(f'{zstd_dir}/*/*.S') if BuildConfig.USE_BMI2 else []
+
+        config = dict(
+            sources=glob(f'{zstd_dir}/*/*.c'),
+            include_dirs=[zstd_dir, f'{zstd_dir}/common'],
+            cflags=cflags,
+        )
+
+    config['macros'] = [] if BuildConfig.USE_BMI2 else [('ZSTD_DISABLE_ASM', 1)]
 
     if field is None:
         return 'zstd', config
-    if field == 'extra_objects':
-        return glob(f'{zstd_dir}/*/*.S') if BuildConfig.USE_BMI2 else []
     return config[field]
 
 
@@ -858,16 +892,25 @@ def get_blosc_plugin():
     Plugin from https://github.com/Blosc/hdf5-blosc
     c-blosc from https://github.com/Blosc/c-blosc
     """
-    blosc_dir = 'src/c-blosc/blosc'
     hdf5_blosc_dir = 'src/hdf5-blosc/src'
 
-    # blosc sources
-    sources = glob(f'{blosc_dir}/*.c')
-    include_dirs = ['src/c-blosc', blosc_dir]
+    if os.environ.get('HDF5PLUGIN_SYSTEM_BLOSC', None):
+        sources = []
+        include_dirs = [subprocess.check_output(
+            ["pkg-config", '--variable=includedir', 'blosc']
+        )]
+        libraries = [l.strip()[2:] for l in subprocess.check_output(
+            ["pkg-config", '--libs', 'blosc']
+        ).decode().strip().split(" ")]
+    else:
+        # blosc sources
+        blosc_dir = 'src/c-blosc/blosc'
+        sources = glob(f'{blosc_dir}/*.c')
+        include_dirs = ['src/c-blosc', blosc_dir]
+        libraries = []
     define_macros = []
     extra_link_args = []
-    libraries = []
-
+    
     # compression libs
     # lz4
     include_dirs += get_lz4_clib('include_dirs')
@@ -913,7 +956,7 @@ def get_blosc_plugin():
     )
 
 
-PLUGIN_LIB_DEPENDENCIES['blosc'] = 'snappy', 'lz4', 'zlib', 'zstd'
+PLUGIN_LIB_DEPENDENCIES['blosc'] = 'snappy', 'lz4', 'z', 'zstd'
 
 
 def get_blosc2_plugin():
@@ -922,43 +965,44 @@ def get_blosc2_plugin():
     Source from PyTables and c-blosc2
     """
     hdf5_blosc2_dir = 'src/PyTables/hdf5-blosc2/src'
-    blosc2_dir = 'src/c-blosc2'
-    plugins_dir = f'{blosc2_dir}/plugins'
+    if os.environ.get('HDF5PLUGIN_SYSTEM_BLOSC2', None):
+        sources = []
+        include_dirs = [subprocess.check_output(
+            ["pkg-config", '--variable=includedir', 'blosc2']
+        )]
+        libraries = [l.strip()[2:] for l in subprocess.check_output(
+            ["pkg-config", '--libs', 'blosc2']
+        ).decode().strip().split(" ")]
+    else:
+        blosc2_dir = 'src/c-blosc2'
+        plugins_dir = f'{blosc2_dir}/plugins'
+
+        # blosc sources
+        sources = glob(f'{blosc2_dir}/blosc/*.c')
+        sources += [  # Add embedded codecs, filters and tuners
+            src_file
+            for src_file in glob(f'{plugins_dir}/*.c') + glob(f'{plugins_dir}/*/*.c') + glob(f'{plugins_dir}/*/*/*.c')
+            if not os.path.basename(src_file).startswith("test")
+        ]
+        sources += glob(f'{plugins_dir}/codecs/zfp/src/*.c')  # Add ZFP embedded sources
 
-    # blosc sources
-    sources = glob(f'{blosc2_dir}/blosc/*.c')
-    sources += [  # Add embedded codecs, filters and tuners
-        src_file
-        for src_file in glob(f'{plugins_dir}/*.c') + glob(f'{plugins_dir}/*/*.c') + glob(f'{plugins_dir}/*/*/*.c')
-        if not os.path.basename(src_file).startswith("test")
-    ]
-    sources += glob(f'{plugins_dir}/codecs/zfp/src/*.c')  # Add ZFP embedded sources
-
-    include_dirs = [
-        blosc2_dir,
-        f'{blosc2_dir}/blosc',
-        f'{blosc2_dir}/include',
-        f'{blosc2_dir}/plugins/codecs/zfp/include',
-    ]
+        include_dirs = [
+            blosc2_dir,
+            f'{blosc2_dir}/blosc',
+            f'{blosc2_dir}/include',
+            f'{blosc2_dir}/plugins/codecs/zfp/include',
+        ]
+        libraries = []
 
     define_macros = [('HAVE_PLUGINS', 1)]
-    if platform.machine() == 'ppc64le':
-        define_macros.append(('SHUFFLE_ALTIVEC_ENABLED', 1))
-        define_macros.append(('NO_WARN_X86_INTRINSICS', None))
-    else:
-        define_macros.append(('SHUFFLE_SSE2_ENABLED', 1))
-        define_macros.append(('SHUFFLE_AVX2_ENABLED', 1))
-        define_macros.append(('SHUFFLE_AVX512_ENABLED', 1))
-        define_macros.append(('SHUFFLE_NEON_ENABLED', 1))
+    define_macros.append(('SHUFFLE_SSE2_ENABLED', 0))
+    define_macros.append(('SHUFFLE_AVX2_ENABLED', 1))
+    define_macros.append(('SHUFFLE_AVX512_ENABLED', 0))
+    define_macros.append(('SHUFFLE_NEON_ENABLED', 0))
 
     extra_compile_args = []
     extra_link_args = []
-    libraries = []
 
-    if HostConfig.ARCH == 'ARM_8':
-        extra_compile_args += ['-flax-vector-conversions']
-    if HostConfig.ARCH == 'ARM_7':
-        extra_compile_args += ['-mfpu=neon', '-flax-vector-conversions']
 
     # compression libs
     # lz4
@@ -980,10 +1024,6 @@ def get_blosc2_plugin():
     include_dirs += get_zstd_clib('include_dirs')
     define_macros.append(('HAVE_ZSTD', 1))
 
-    extra_compile_args += ['-O3', '-std=gnu99']
-    extra_compile_args += ['/Ox']
-    extra_compile_args += ['-pthread']
-    extra_link_args += ['-pthread']
 
     return HDF5PluginExtension(
         "hdf5plugin.plugins.libh5blosc2",
@@ -999,7 +1039,7 @@ def get_blosc2_plugin():
     )
 
 
-PLUGIN_LIB_DEPENDENCIES['blosc2'] = 'lz4', 'zlib', 'zstd'
+PLUGIN_LIB_DEPENDENCIES['blosc2'] = 'lz4', 'z', 'zstd'
 
 
 def get_zstandard_plugin():
@@ -1081,31 +1121,47 @@ PLUGIN_LIB_DEPENDENCIES['lz4'] = ('lz4',
 
 def get_bzip2_plugin():
     """BZip2 plugin build config"""
-    bzip2_dir = "src/bzip2"
+    if os.environ.get('HDF5PLUGIN_SYSTEM_BZIP2', None):
+        bzip2_extra_compile_args = []
+        sources = []
+        include_dirs = [subprocess.check_output(
+            ["pkg-config", '--variable=includedir', 'bzip2']
+        )]
+        libraries = [l.strip()[2:] for l in subprocess.check_output(
+            ["pkg-config", '--libs', 'bzip2']
+        ).decode().strip().split(" ")]
+
+    else:    
+        bzip2_dir = "src/bzip2"
+
+        bzip2_extra_compile_args = [
+            "-Wall",
+            "-Winline",
+            "-O2",
+            "-g",
+            "-D_FILE_OFFSET_BITS=64"
+        ]
+
+        sources = prefix(bzip2_dir, [
+            "blocksort.c",
+            "huffman.c",
+            "crctable.c",
+            "randtable.c",
+            "compress.c",
+            "decompress.c",
+            "bzlib.c",
+        ])
+        include_dirs = [bzip2_dir]
+        libraries=[]
 
-    bzip2_extra_compile_args = [
-        "-Wall",
-        "-Winline",
-        "-O2",
-        "-g",
-        "-D_FILE_OFFSET_BITS=64"
-    ]
-
-    sources = ['src/PyTables/src/H5Zbzip2.c', 'src/H5Zbzip2_plugin.c']
-    sources += prefix(bzip2_dir, [
-        "blocksort.c",
-        "huffman.c",
-        "crctable.c",
-        "randtable.c",
-        "compress.c",
-        "decompress.c",
-        "bzlib.c",
-    ])
+    include_dirs += ['src/PyTables/src/']
+    sources += ['src/PyTables/src/H5Zbzip2.c', 'src/H5Zbzip2_plugin.c']
 
     return HDF5PluginExtension(
         "hdf5plugin.plugins.libh5bzip2",
         sources=sources,
-        include_dirs=['src/PyTables/src/', bzip2_dir],
+        include_dirs=include_dirs,
+        libraries=libraries,
         define_macros=[('HAVE_BZ2_LIB', 1)],
         extra_compile_args=bzip2_extra_compile_args,
     )
@@ -1178,7 +1234,7 @@ def get_sz_plugin():
     )
 
 
-PLUGIN_LIB_DEPENDENCIES['sz'] = ('zlib', 'zstd')
+PLUGIN_LIB_DEPENDENCIES['sz'] = ('z', 'zstd')
 
 
 def get_sz3_plugin():
@@ -1242,13 +1298,14 @@ def apply_filter_strip(libraries, extens
     if 'all' in stripped_filters:
         return [], []
 
-    # Filter out library that won't be used because of stripped filters
+    # Filter out library that won't be used because of stripped filters or is usable from system
     lib_names = set(
         itertools.chain.from_iterable(
             lib_names for filter_name, lib_names in dependencies.items()
-            if filter_name not in stripped_filters
+            if (filter_name not in stripped_filters
+                and not os.environ.get(f"HDF5PLUGIN_SYSTEM_{filter_name.upper()}", None))
         )
-    )
+    ) 
 
     libraries = [
         lib for lib in libraries if lib[0] in lib_names
openSUSE Build Service is sponsored by