%global __provides_exclude_from ^%{_libdir}/pmdk_debug/.*\\.so.*$

%define min_libfabric_ver 1.4.2
%define min_ndctl_ver 60.1
%define upstreamversion 1.4.2

Name:		nvml
Summary:	Persistent Memory Development Kit (formerly NVML)
Version:	1.4.2
Release:	4
License:	BSD
URL:		http://pmem.io/pmdk

Source0:	https://github.com/pmem/%{name}/archive/%{upstreamversion}.tar.gz#/%{name}-%{upstreamversion}.tar.gz

Patch001: fix-build-error.patch
Patch002: 0001-delete-extra-tests.patch
Patch003: Initialize-child_idx.patch

BuildRequires:	gcc make glibc-devel autoconf automake man doxygen pkgconfig gdb
BuildRequires:	ndctl-devel >= %{min_ndctl_ver} daxctl-devel >= %{min_ndctl_ver}
BuildRequires:	libfabric-devel >= %{min_libfabric_ver}

Requires: libfabric >= %{min_libfabric_ver} openssh-clients

ExclusiveArch: x86_64

Provides: libpmemobj++-static = %{version}-%{release}
Obsoletes: nvml-tools < %{version}-%{release}

Obsoletes: libpmemblk-debug < %{version}-%{release}
Obsoletes: libpmemblk-devel < %{version}-%{release}
Obsoletes: libpmemblk < %{version}-%{release}
Obsoletes: libpmem-debug < %{version}-%{release}
Obsoletes: libpmem-devel < %{version}-%{release}
Obsoletes: libpmemlog < %{version}-%{release}
Obsoletes: libpmem < %{version}-%{release}
Obsoletes: libpmemobj++-devel < %{version}-%{release}
Obsoletes: libvmmalloc-debug < %{version}-%{release}
Obsoletes: libvmmalloc-devel < %{version}-%{release}
Obsoletes: libvmmalloc < %{version}-%{release}
Obsoletes: libvmem-debug < %{version}-%{release}
Obsoletes: libvmem-devel < %{version}-%{release}
Obsoletes: libvmem < %{version}-%{release}
Obsoletes: libpmemobj-devel < %{version}-%{release}
Obsoletes: libpmemobj < %{version}-%{release}
Obsoletes: libpmemlog-debug < %{version}-%{release}
Obsoletes: libpmemlog-devel < %{version}-%{release}
Obsoletes: daxio < %{version}-%{release}
Obsoletes: libpmemcto-devel < %{version}-%{release}
Obsoletes: pmempool < %{version}-%{release}
Obsoletes: libpmemcto-debug < %{version}-%{release}
Obsoletes: libpmemcto < %{version}-%{release}
Obsoletes: rpmemd < %{version}-%{release}
Obsoletes: libpmempool < %{version}-%{release}
Obsoletes: libpmempool-devel < %{version}-%{release}
Obsoletes: libpmempool-debug < %{version}-%{release}
Obsoletes: librpmem < %{version}-%{release}
Obsoletes: librpmem-devel < %{version}-%{release}
Obsoletes: libpmemobj-debug < %{version}-%{release}
Obsoletes: librpmem-debug < %{version}-%{release}

Provides: libpmemblk-debug = %{version}-%{release}
Provides: libpmemblk-devel = %{version}-%{release}
Provides: libpmemblk = %{version}-%{release}
Provides: libpmem-debug = %{version}-%{release}
Provides: libpmem-devel = %{version}-%{release}
Provides: libpmemlog = %{version}-%{release}
Provides: libpmem = %{version}-%{release}
Provides: libpmemobj++-devel = %{version}-%{release}
Provides: libvmmalloc-debug = %{version}-%{release}
Provides: libvmmalloc-devel = %{version}-%{release}
Provides: libvmmalloc = %{version}-%{release}
Provides: libvmem-debug = %{version}-%{release}
Provides: libvmem-devel = %{version}-%{release}
Provides: libvmem = %{version}-%{release}
Provides: libpmemobj-devel = %{version}-%{release}
Provides: libpmemobj
Provides: libpmemlog-debug = %{version}-%{release}
Provides: libpmemlog-devel = %{version}-%{release}
Provides: daxio
Provides: libpmemcto-devel = %{version}-%{release}
Provides: pmempool = %{version}-%{release}
Provides: libpmemcto-debug = %{version}-%{release}
Provides: libpmemcto = %{version}-%{release}
Provides: rpmemd = %{version}-%{release}
Provides: libpmempool = %{version}-%{release}
Provides: libpmempool-devel = %{version}-%{release}
Provides: libpmempool-debug = %{version}-%{release}
Provides: librpmem = %{version}-%{release}
Provides: librpmem-devel = %{version}-%{release}
Provides: libpmemobj-debug = %{version}-%{release}
Provides: librpmem-debug = %{version}-%{release}

%description
The Persistent Memory Development Kit (PMDK), formerly known as NVML, is
a growing collection of libraries and tools. Tuned and validated on both
Linux and Windows, the libraries build on the DAX feature of those operating
systems (short for Direct Access) which allows applications to access persistent
memory as memory-mapped files

%package_help

%prep
%autosetup -p1 -n pmdk-%{upstreamversion}

%build

CFLAGS="%{optflags}" \
LDFLAGS="%{?__global_ldflags}" \
make %{?_smp_mflags} NORPATH=1

%install
make install DESTDIR=%{buildroot} \
	LIB_AR= \
	prefix=%{_prefix} \
	libdir=%{_libdir} \
	includedir=%{_includedir} \
	mandir=%{_mandir} \
	bindir=%{_bindir} \
	sysconfdir=%{_sysconfdir} \
	docdir=%{_docdir} \
	CPP_DOC_DIR=libpmemobj++-devel
mkdir -p %{buildroot}%{_datadir}/pmdk
cp utils/pmdk.magic %{buildroot}%{_datadir}/pmdk/

%check
echo "PMEM_FS_DIR=/tmp" > src/test/testconfig.sh
echo "PMEM_FS_DIR_FORCE_PMEM=1" >> src/test/testconfig.sh
sed -i 's/uint16_t checksum;/uint16_t checksum = 0;/g' src/test/obj_realloc/obj_realloc.c
sed -i 's/size_t check_size;/size_t check_size = 0;/g' src/test/obj_realloc/obj_realloc.c
make check

%ldconfig_scriptlets

%files
%license LICENSE
%doc ChangeLog CONTRIBUTING.md README.md
%dir %{_datadir}/pmdk
%{_libdir}/libpmem.so.*
%{_datadir}/pmdk/pmdk.magic
%{_libdir}/libpmem.so
%{_libdir}/pkgconfig/libpmem.pc
%{_includedir}/libpmem.h
%dir %{_libdir}/pmdk_debug
%{_libdir}/pmdk_debug/libpmem.so
%{_libdir}/pmdk_debug/libpmem.so.*
%{_libdir}/libpmemblk.so.*
%{_libdir}/libpmemblk.so
%{_libdir}/pkgconfig/libpmemblk.pc
%{_includedir}/libpmemblk.h
%dir %{_libdir}/pmdk_debug
%{_libdir}/pmdk_debug/libpmemblk.so
%{_libdir}/pmdk_debug/libpmemblk.so.*
%{_libdir}/libpmemlog.so.*
%{_libdir}/libpmemlog.so
%{_libdir}/pkgconfig/libpmemlog.pc
%{_includedir}/libpmemlog.h
%dir %{_libdir}/pmdk_debug
%{_libdir}/pmdk_debug/libpmemlog.so
%{_libdir}/pmdk_debug/libpmemlog.so.*
%{_libdir}/libpmemobj.so.*
%{_libdir}/libpmemobj.so
%{_libdir}/pkgconfig/libpmemobj.pc
%{_includedir}/libpmemobj.h
%{_includedir}/libpmemobj/*.h
%dir %{_libdir}/pmdk_debug
%{_libdir}/pmdk_debug/libpmemobj.so
%{_libdir}/pmdk_debug/libpmemobj.so.*
%{_libdir}/libvmem.so
%{_libdir}/pkgconfig/libvmem.pc
%{_includedir}/libvmem.h
%dir %{_libdir}/pmdk_debug
%{_libdir}/pmdk_debug/libvmem.so
%{_libdir}/pmdk_debug/libvmem.so.*
%{_libdir}/libvmmalloc.so.*
%dir %{_libdir}/pmdk_debug
%{_libdir}/pmdk_debug/libvmmalloc.so
%{_libdir}/pmdk_debug/libvmmalloc.so.*
%{_libdir}/pkgconfig/libpmemobj++.pc
%{_includedir}/libpmemobj++/*.hpp
%{_includedir}/libpmemobj++/detail/*.hpp
%{_docdir}/libpmemobj++-devel/*
%{_libdir}/libpmempool.so.*
%{_libdir}/libpmempool.so
%{_libdir}/pkgconfig/libpmempool.pc
%{_includedir}/libpmempool.h
%dir %{_libdir}/pmdk_debug
%{_libdir}/pmdk_debug/libpmempool.so
%{_libdir}/pmdk_debug/libpmempool.so.*
%{_libdir}/librpmem.so.*
%{_libdir}/librpmem.so
%{_libdir}/pkgconfig/librpmem.pc
%{_includedir}/librpmem.h
%dir %{_libdir}/pmdk_debug
%{_libdir}/pmdk_debug/librpmem.so
%{_libdir}/pmdk_debug/librpmem.so.*
%{_bindir}/rpmemd
%{_libdir}/libpmemcto.so.*
%{_libdir}/libpmemcto.so
%{_libdir}/pkgconfig/libpmemcto.pc
%{_includedir}/libpmemcto.h
%dir %{_libdir}/pmdk_debug
%{_libdir}/pmdk_debug/libpmemcto.so
%{_libdir}/pmdk_debug/libpmemcto.so.*
%{_bindir}/pmempool
%config(noreplace) %{_sysconfdir}/bash_completion.d/pmempool
%{_bindir}/daxio
%{_libdir}/libvmmalloc.so
%{_libdir}/pkgconfig/libvmmalloc.pc
%{_includedir}/libvmmalloc.h
%{_libdir}/libvmem.so.*

%files help
%{_mandir}/man1/pmempool.1.gz
%{_mandir}/man1/pmempool-*.1.gz
%{_mandir}/man1/daxio.1.gz
%{_mandir}/man1/rpmemd.1.gz
%{_mandir}/man3/pmem_*.3.gz
%{_mandir}/man3/pmemblk_*.3.gz
%{_mandir}/man3/pmemlog_*.3.gz
%{_mandir}/man3/pmemobj_*.3.gz
%{_mandir}/man3/pobj_*.3.gz
%{_mandir}/man3/oid_*.3.gz
%{_mandir}/man3/toid*.3.gz
%{_mandir}/man3/direct_*.3.gz
%{_mandir}/man3/d_r*.3.gz
%{_mandir}/man3/tx_*.3.gz
%{_mandir}/man3/vmem_*.3.gz
%{_mandir}/man3/pmempool_*.3.gz
%{_mandir}/man3/rpmem_*.3.gz
%{_mandir}/man3/pmemcto*.3.gz
%{_mandir}/man5/poolset.5.gz
%{_mandir}/man5/poolset.5.gz
%{_mandir}/man5/poolset.5.gz
%{_mandir}/man5/poolset.5.gz
%{_mandir}/man5/poolset.5.gz
%{_mandir}/man7/libpmem.7.gz
%{_mandir}/man7/libpmemblk.7.gz
%{_mandir}/man7/libpmemlog.7.gz
%{_mandir}/man7/libpmemobj.7.gz
%{_mandir}/man7/libvmem.7.gz
%{_mandir}/man7/libpmempool.7.gz
%{_mandir}/man7/librpmem.7.gz
%{_mandir}/man7/libpmemcto.7.gz
%{_mandir}/man7/libvmmalloc.7.gz

%if 0%{?__debug_package} == 0
%debug_package
%endif

%changelog
* Sat Nov 20 2021 zhangtao <zhangtao221@huawei.com> - 1.4.2-4
- Initialize child_idx to fix warning
- fix build error problems and delete extra tests

* Fri Dec 4 2020 Ge Wang <wangge20@huawei.com> - 1.4.2-3
- Fix coding error to solve check failure

* Fri Dec 6 2019 caomeng<caomeng5@huawei.com> - 1.4.2-2
- Package init
