%global pkgvers 0
%global scdate0 20241209
%global schash0 ca156f7bc9109c552973414a63d310f76ef0cbf8
%global branch0 main
%global source0 https://github.com/pytorch/cpuinfo.git

%global sshort0 %{expand:%%{lua:print(('%{schash0}'):sub(1,8))}}

Name:           cpuinfo
Version:        0
Epoch:          1
Release:        %{scdate0}.%{pkgvers}.git%{sshort0}%{?dist}
Summary:        CPU INFOrmation library
License:        BSD

URL:            https://github.com/pytorch/cpuinfo

BuildRequires:  cmake gcc-c++ git

%global __cmake_in_source_build 1

%description
A library to detect essential for performance
optimization information about host CPU.

%package        devel
Summary:        Development files
Requires:       %{name} = %{epoch}:%{version}-%{release}

%description    devel
This package contains the development files for %{name}.


%prep
%setup -T -c -n %{name}
git clone --depth 1 -n -b %{branch0} %{source0} .
git fetch --depth 1 origin %{schash0}
git reset --hard %{schash0}
git log --format=fuller


%build
sed -i 's|clog STATIC|clog SHARED|'  deps/clog/CMakeLists.txt
sed -i 's|"hidden"|"default"|' deps/clog/include/clog.h
sed -i 's|"internal"|"default"|' deps/clog/include/clog.h
sed -i 's|clog PROPERTIES|clog PROPERTIES SOVERSION 1 VERSION 1.0|'  deps/clog/CMakeLists.txt
sed -i 's|cpuinfo PROPERTIES PUBLIC_HEADER include/cpuinfo.h|cpuinfo PROPERTIES PUBLIC_HEADER include/cpuinfo.h SOVERSION 1 VERSION 1.0|' CMakeLists.txt

mkdir build
pushd build
%cmake .. \
       -DCMAKE_SKIP_RPATH=ON \
       -DCMAKE_VERBOSE_MAKEFILE=OFF \
       -DCMAKE_BUILD_TYPE=RelWithDebInfo \
       -DCMAKE_INSTALL_LIBDIR=%{_libdir} \
       -DCPUINFO_LIBRARY_TYPE="shared" \
       -DCPUINFO_RUNTIME_TYPE="shared" \
       -DCPUINFO_BUILD_UNIT_TESTS=OFF \
       -DCPUINFO_BUILD_MOCK_TESTS=OFF \
       -DCPUINFO_BUILD_BENCHMARKS=OFF

make %{?_smp_mflags}
popd


%install
rm -rf %{buildroot}
pushd build
make install DESTDIR=%{buildroot}
popd


%files
%license LICENSE
%doc README.md
%ifnarch ppc64le
%{_bindir}/*
%endif
%{_libdir}/*.so.*

%files devel
%license LICENSE
%doc README.md
%{_includedir}/*
%{_libdir}/*.so
%{_datadir}/*
%{_libdir}/pkgconfig/*


%changelog
* Fri Sep 25 2020 Cristian Balint <cristian.balint@gmail.com>
- github upstream releases