File root6.spec of Package root6

#
# spec file for package root6
#
# Copyright (c) 2023 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%global flavor @BUILD_FLAVOR@%{nil}
%global srcdir root-%{version}
%global __builder ninja
%if "%{flavor}" == ""
%define pname root6
%define libname %{pname}-libs
%define mylibdir %{_libdir}/%{pname}
# LTO build on aarch is hit or miss
%ifarch aarch64
%define _lto_cflags %{nil}
%endif
%bcond_with standalone_minuit2
# BUILDING ON i586 FAILS NO MATTER THE MEMORY
ExcludeArch:    i586
# Disable tests, they require data downloads from the network anyway
%bcond_with test
%endif
%if "%{flavor}" == "minuit2"
%define pname Minuit2
%define libname lib%{pname}
%bcond_without standalone_minuit2
%bcond_without test
%endif
%if 0%{?suse_version} < 1600
# Explicit python311 for Leap
%define pythons python311
# For <filesystem> support
%define gcc_ver 9
%else
# Only default python3 flavour for TW
%define pythons python3
%endif

# glew is built with EGL, which causes builds to fail [boo#1235150]
%bcond_with opengl

# Incompatible with GCC 15
%if 0%{?suse_version} > 1650
%define gcc_ver 14
%endif

%define series 6
%define sover 6_32
# build is already a populated dir in tarball
%define __builddir _build
Name:           %{pname}
Version:        6.32.14
Release:        0
Summary:        Numerical data analysis framework
License:        LGPL-2.1-or-later
URL:            https://root.cern.ch
Source0:        https://root.cern.ch/download/root_v%{version}.source.tar.gz
Source1:        root6-rpmlintrc
# SECTION Common BuildRequires for full build and standalone minuit2
BuildRequires:  cmake
BuildRequires:  ninja
BuildRequires:  gcc%{?gcc_ver}-c++
# /SECTION
%if %{without standalone_minuit2}
# SECTION Full build
BuildRequires:  %{python_module PyYAML}
BuildRequires:  %{python_module devel}
BuildRequires:  %{python_module numpy-devel}
BuildRequires:  %{python_module pygments}
BuildRequires:  Mesa-devel
BuildRequires:  chrpath
BuildRequires:  desktop-file-utils
BuildRequires:  doxygen
BuildRequires:  fdupes
BuildRequires:  gawk
BuildRequires:  giflib-devel
BuildRequires:  git
BuildRequires:  graphviz-devel
BuildRequires:  gtest
BuildRequires:  hdf5-devel
BuildRequires:  libmysqlclient-devel
BuildRequires:  memory-constraints
BuildRequires:  openldap2-devel
BuildRequires:  pkgconfig
BuildRequires:  pythia-devel
BuildRequires:  python-rpm-macros
BuildRequires:  ruby-devel >= 1.8
BuildRequires:  sqlite3-devel
BuildRequires:  xrootd-client-devel >= 4.6
BuildRequires:  xrootd-private-devel >= 4.6
BuildRequires:  pkgconfig(cfitsio)
BuildRequires:  pkgconfig(davix)
BuildRequires:  pkgconfig(expat)
BuildRequires:  pkgconfig(fftw3)
# Needed for root6-fontconfig.patch
BuildRequires:  pkgconfig(fontconfig)
#
BuildRequires:  pkgconfig(freetype2)
BuildRequires:  pkgconfig(glu)
BuildRequires:  pkgconfig(gsl)
BuildRequires:  pkgconfig(ice)
BuildRequires:  pkgconfig(libjpeg)
BuildRequires:  pkgconfig(libedit)
BuildRequires:  pkgconfig(liblz4)
BuildRequires:  pkgconfig(liblzma)
BuildRequires:  pkgconfig(libpcre2-posix)
BuildRequires:  pkgconfig(libpng16)
BuildRequires:  pkgconfig(libpq)
BuildRequires:  pkgconfig(libtiff-4)
BuildRequires:  pkgconfig(libxml-2.0)
BuildRequires:  pkgconfig(libxxhash)
BuildRequires:  pkgconfig(libzstd)
BuildRequires:  pkgconfig(ncurses)
BuildRequires:  pkgconfig(nlohmann_json)
BuildRequires:  pkgconfig(odbc) >= 2.2.11
BuildRequires:  pkgconfig(openssl)
BuildRequires:  pkgconfig(sm)
BuildRequires:  pkgconfig(x11)
BuildRequires:  pkgconfig(xext)
BuildRequires:  pkgconfig(xft)
BuildRequires:  pkgconfig(xpm)
BuildRequires:  pkgconfig(z3)
BuildRequires:  pkgconfig(zlib)
%if %{with opengl}
BuildRequires:  gl2ps-devel
BuildRequires:  pkgconfig(ftgl)
BuildRequires:  pkgconfig(glew)
%endif
%if %{with test}
BuildRequires:  gmock
%endif
%if 0%{?suse_version} >= 1699
BuildRequires:  cmake(ryml)
%endif
# /SECTION Full build
%endif
# SECTION Patches required for successful build
# PATCH-FIX-UPSTREAM root6-reduce-compile-memory.patch badshah400@gmail.com -- Reduce the memory during compilation somewhat; patch taken from fedora
Patch1:         root6-reduce-compile-memory.patch
# /SECTION
# SECTION Other patches (start at number 10)
# PATCH-FEATURE-OPENSUSE root6-fontconfig.patch badshah400@gmail.com -- Make root use system installed TTF fonts; this is needed to avoid licensing issues with non-free fonts bundled by upstream tarball; patch taken from fedora
Patch10:        root6-fontconfig.patch
# PATCH-FIX-UPSTREAM root6-gitinfo-use-file-timestamp.patch badshah400@gmail.com -- Set timestamp info in generated file to top-level README.md file modification time instead of setting it to current build time, for reproducibility's sake
Patch11:        root6-gitinfo-use-file-timestamp.patch
# PATCH-FIX-UPSTREAM root6-python3.11-no-code.h.patch badshah400@gmail.com -- code.h is no longer available with python 3.11, use Python.h instead
Patch13:        root6-python3.11-no-code.h.patch
# /SECTION
%if !0%{?sles_version}
BuildRequires:  freetype-devel
%endif

%description
The ROOT system provides a set of OO frameworks with all the
functionality needed to handle and analyze large amounts of data
efficiently.

With the data defined as a set of objects, specialized storage methods
can give direct access to the separate attributes of the selected
objects, without having to touch the bulk of the data. Included are
histogramming methods in 1, 2 and 3 dimensions, curve fitting, function
evaluation, minimization, graphics and visualization classes to allow the
easy creation of an analysis system that can query and process the data
interactively or in batch mode.

The command language, the scripting (or macro) language, and the
programming language are all C++, thanks to the built-in CINT C++
interpreter. This interpreter removes the time consuming compile/link
cycle, allowing for fast prototyping of the macros, and providing a
good environment to learn C++. If more performance is needed, the
interactively developed macros can be compiled using a C++ compiler.

The system has been designed in such a way that it can query its
databases in parallel on MPP machines or on clusters of workstations
or high-end PCs. ROOT is an open system that can be dynamically
extended by linking external libraries. This makes ROOT a premier
platform on which to build data acquisition, simulation and data
analysis systems.

%package -n %{libname}
Summary:        Shared libraries for %{name}
%if ! %{with standalone_minuit2}
Provides:       root6-Core-libs = %{version}
Provides:       root6-extra-libs = %{version}
Provides:       root6-Hist-libs = %{version}
Provides:       root6-IO-libs = %{version}
Provides:       root6-MathCore-libs = %{version}
Provides:       root6-Matrix-libs = %{version}
Provides:       root6-Minuit2-libs = %{version}
Provides:       root6-Thread-libs = %{version}
%endif

%description -n %{libname}
This package provides the shared libraries for %{name}.

%package devel
Summary:        Headers and sources for ROOT's Core library
%if ! %{with standalone_minuit2}
Requires:       %{name}-libs = %{version}
Requires:       gcc-c++
Requires:       gnu-free-fonts
Requires:       google-droid-fonts
Provides:       root6-Core-devel = %{version}
Provides:       root6-extra-devel = %{version}
Provides:       root6-Hist-devel = %{version}
Provides:       root6-IO-devel = %{version}
Provides:       root6-MathCore-devel = %{version}
Provides:       root6-Matrix-devel = %{version}
Provides:       root6-Minuit2-devel = %{version}
Provides:       root6-Thread-devel = %{version}
# The root6 pkg previously provided binaries that no longer work w/o the devel pkg anyway
Provides:       root6 = %{version}
Obsoletes:      root6 < %{version}-%{release}
%endif

%description devel
This package provides the headers and sources for programming with ROOT.

%package -n %{python_prefix}-root6
Summary:        Python bindings for ROOT
Requires:       gnu-free-fonts
Requires:       google-droid-fonts
Requires:       root6-devel = %{version}
%if 0%{?suse_version} >= 1699
Provides:       python3-root6 = %{version}
Obsoletes:      python3-root6 < %{version}-%{release}
%endif

%description -n %{python_prefix}-root6
This package provides python bindings for ROOT.

%package config
Summary:        Config scripts for setting up root6 for different shell env
Requires:       root6-devel = %{version}
BuildArch:      noarch

%description config
This package provides config scripts for setting up the root6 working
environment in different shells such as bash, csh, fish, etc.

Note that you do not need this package for standard root6 installations.

%package tutorials
Summary:        A set of tutorials for %{name}
Requires:       root6-devel = %{version}
BuildArch:      noarch

%description tutorials
This package provides a set of tutorials for Root.

%package test
Summary:        Tests for %{name}
Requires:       root6-devel = %{version}
BuildArch:      noarch

%description test
This package provides a set of tests for Root.

%package utils
Summary:        Utilities for working with ROOT files
Requires:       python3-root6

%description utils
This package provides a few utilities to work with ROOT files.

%prep
%autosetup -n %{srcdir} -p1

# SECTION REMOVE NON-FREE FONTS (needs root6-fontconfig.patch)
find ./fonts -type f -a '!' -name 'STIX*' -print -delete
# /SECTION

sed -Ei "1{/\/usr\/bin\/env/d}" \
  bindings/jupyroot/python/JupyROOT/kernel/rootkernel.py \
  bindings/pyroot/cppyy/cppyy-backend/cling/python/cppyy_backend/_cppyy_generator.py \
  main/python/cmdLineUtils.py
  
# Remove runtime tool from EXPORT set -- https://github.com/root-project/root/issues/17350
sed -i -e '/ROOT_EXECUTABLE/ s@\(rootreadspeed.*\) LIBRARIES@\1 CMAKENOEXPORT LIBRARIES@' main/CMakeLists.txt
grep ROOT_EXECUTABLE main/CMakeLists.txt

%build
%if %{with standalone_minuit2}
pushd math/minuit2
cp -r ../../core/foundation/inc/ROOT/RVersion.hxx ./
%cmake \
       -DCMAKE_C_COMPILER=gcc%{?gcc_ver:-%{gcc_ver}} \
       -DCMAKE_CXX_COMPILER=g++%{?gcc_ver:-%{gcc_ver}} \
       -Dminuit2_standalone:BOOL=ON \
       -Dminuit2_openmp:BOOL=ON
%else
%limit_build -m 2000
# Directly passing RPM optflags to CMAKE_CXX_FLAGS causes build errors,
# need to reset CMAKE_CXX_FLAGS and pass optflags to CMAKE_REQUIRED_FLAGS instead
# Upstream Recommends -O3 optimization for RelwithDebugInfo
%cmake \
       -DCMAKE_C_COMPILER=gcc%{?gcc_ver:-%{gcc_ver}} \
       -DCMAKE_CXX_COMPILER=g++%{?gcc_ver:-%{gcc_ver}} \
       -DCMAKE_INSTALL_INCLUDEDIR:PATH=%{_includedir}/root \
       -DCMAKE_INSTALL_LIBDIR:PATH=%{mylibdir} \
       -DCMAKE_INSTALL_SYSCONFDIR:PATH=%{_datadir}/root \
       -DCMAKE_INSTALL_DOCDIR:PATH=%{_docdir}/%{name} \
       -DCMAKE_REQUIRED_FLAGS="%{optflags}" \
       -DCMAKE_CXX_FLAGS="-O3" \
%ifarch aarch64 %{ix86}
       -DCMAKE_C_FLAGS_RELWITHDEBINFO="-O3 -g1 -DNDEBUG" \
       -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O3 -g1 -DNDEBUG" \
%endif
       -Dgnuinstall:BOOL=ON \
       -Dbuiltin_afterimage:BOOL=ON \
       -Dbuiltin_cfitsio:BOOL=OFF \
       -Dbuiltin_clang:BOOL=ON \
       -Dbuiltin_davix:BOOL=OFF \
       -Dbuiltin_fftw3:BOOL=OFF \
       -Dbuiltin_freetype:BOOL=OFF \
       -Dbuiltin_ftgl:BOOL=OFF \
       -Dbuiltin_gl2ps:BOOL=OFF \
       -Dbuiltin_glew:BOOL=OFF \
       -Dbuiltin_gsl:BOOL=OFF \
       -Dbuiltin_gtest:BOOL=OFF \
       -Dbuiltin_llvm:BOOL=ON \
       -Dbuiltin_lz4:BOOL=OFF \
       -Dbuiltin_lzma:BOOL=OFF \
       -Dbuiltin_openssl:BOOL=OFF \
       -Dbuiltin_pcre:BOOL=OFF \
       -Dbuiltin_tbb:BOOL=OFF \
       -Dbuiltin_unuran:BOOL=ON \
       -Dbuiltin_vc:BOOL=OFF \
       -Dbuiltin_vdt:BOOL=OFF \
       -Dbuiltin_veccore:BOOL=OFF \
       -Dbuiltin_xrootd:BOOL=OFF \
       -Dbuiltin_xxhash:BOOL=OFF \
       -Dbuiltin_zlib:BOOL=OFF \
       -Darrow:BOOL=OFF \
       -Dasimage:BOOL=ON \
       -Dastiff:BOOL=ON \
       -Dcefweb:BOOL=OFF \
       -Dclad:BOOL=OFF \
       -Dcling:BOOL=ON \
       -Dcocoa:BOOL=OFF \
       -Dcuda:BOOL=OFF \
       -Droot7:BOOL=OFF \
       -Dwebgui:BOOL=OFF \
       -Ddavix:BOOL=ON \
       -Ddcache:BOOL=OFF \
       -Dexplicitlink:BOOL=ON \
       -Dfftw3:BOOL=ON \
       -DFIREFOX_EXECUTABLE:PATH=%{_bindir}/firefox \
       -Dfitsio:BOOL=ON \
       -Dfortran:BOOL=ON \
       -Dgdml:BOOL=ON \
       -Dgviz:BOOL=ON \
       -Dhttp:BOOL=ON \
       -Dimt:BOOL=OFF \
       -Dlibcxx:BOOL=OFF \
       -Dmathmore:BOOL=ON \
       -Dmemory_termination:BOOL=OFF \
       -Dmemstat:BOOL=OFF \
       -Dminuit2_openmp:BOOL=ON \
       -Dmysql:BOOL=ON \
       -Dodbc:BOOL=ON \
       -Dopengl:BOOL=%{?with_opengl:ON}%{!?with_opengl:OFF} \
       -Dpch:BOOL=ON \
       -Dpgsql:BOOL=ON \
       -Dpythia8:BOOL=ON \
       -Dqt5web:BOOL=ON \
       -Dr:BOOL=OFF \
       -Droofit:BOOL=ON \
       -Drpath:BOOL=OFF \
       -Druby:BOOL=OFF \
       -Druntime_cxxmodules:BOOL=OFF \
       -Dshadowpw:BOOL=ON \
       -Dshared:BOOL=ON \
       -Dsoversion:BOOL=ON \
       -Dsqlite:BOOL=ON \
       -Dssl:BOOL=ON \
       -Dthread:BOOL=ON \
       -Dtmva:BOOL=ON \
       -Dtmva-cpu:BOOL=OFF \
       -Dtmva-gpu:BOOL=OFF \
       -Dtmva-pymva:BOOL=ON \
       -Dtmva-rmva:BOOL=ON \
       -Dunuran:BOOL=ON \
       -Dvc:BOOL=OFF \
       -Dvdt:BOOL=OFF \
       -Dveccore:BOOL=OFF \
       -Dvecgeom:BOOL=OFF \
       -Dx11:BOOL=ON \
       -Dxml:BOOL=ON \
       -Dxrootd:BOOL=ON \
       -Dtesting:BOOL=%{?with_test:ON}%{!?with_test:OFF} \
       -Dclingtest:BOOL=OFF \
       -Dcoverage:BOOL=OFF \
       -Droottest:BOOL=OFF \
       -Drootbench:BOOL=OFF \
       -Wno-dev
%endif
%cmake_build

%install
%if %{with standalone_minuit2}
# SECTION INSTALL FOR MINUIT2 STANDALONE
pushd math/minuit2
%cmake_install
popd
mkdir -p %{buildroot}%{_libdir}/cmake

if [ "%{_lib}" != "lib" ]
then
  mv %{buildroot}%{_prefix}/lib/cmake/* %{buildroot}%{_libdir}/cmake/
fi

# /SECTION

%else

# SECTION INSTALL FOR FULL ROOT
%cmake_install

# Hashbang fixes
%python3_fix_shebang
%{python_expand sed -i "s|#! %{_bindir}/env python|#!%{_bindir}/python%{$python_version}|" %{buildroot}%{_datadir}/root/dictpch/makepch.py
sed -i "s|#!%{_bindir}/python|#!%{_bindir}/python%{$python_version}|" %{buildroot}%{_datadir}/root/pdg_table_update.py
}
sed -i "s|#!%{_bindir}/env bash|#!/bin/bash|" %{buildroot}%{_bindir}/{root-config,rootssh}

# Python libs installation
%{python_expand # HANDLE NON-STANDARD LOCATIONS FOR PYTHON PACKAGES
install -d %{buildroot}%{$python_sitearch}
mv -t %{buildroot}%{$python_sitearch} \
  %{buildroot}%{_libdir}/%{name}/__pycache__ \
  %{buildroot}%{_libdir}/%{name}/ROOT \
  %{buildroot}%{_libdir}/%{name}/cppyy \
  %{buildroot}%{_libdir}/%{name}/cppyy_backend \
  %{buildroot}%{_libdir}/%{name}/cmdLineUtils.py  \
  %{buildroot}%{_libdir}/%{name}/JupyROOT/ \
  %{buildroot}%{_libdir}/%{name}/DistRDF \
  %{nil}

ln -s -t %{buildroot}%{$python_sitearch} \
  %{_libdir}/%{name}/libcppyy.so \
  %{_libdir}/%{name}/libcppyy_backend.so \
  %{_libdir}/%{name}/libPyMVA.so  \
  %{_libdir}/%{name}/libROOTPythonizations.so \
  %{_libdir}/%{name}/libROOTTPython.so

%fdupes %{buildroot}%{$python_sitearch}/
}
# /Python

# REMOVE STATIC LIBS
find %{buildroot}%{_libdir}/%{name} -name "*.a" -delete -print;

# REMOVE FONTS
rm -fr %{buildroot}%{_datadir}/root/fonts

# REMOVE SOME UNNECESSARY FILES
rm -rf %{buildroot}%{_datadir}/root/proof/utils
rm %{buildroot}%{_datadir}/root/proof/*.sample \
   %{buildroot}%{_datadir}/root/root.desktop \
   %{buildroot}%{_docdir}/%{name}/INSTALL

# Move config files to sysconfdir...
mkdir -p %{buildroot}%{_sysconfdir}/profile.d
mv %{buildroot}%{_bindir}/setxrd* \
   %{buildroot}%{_bindir}/thisroot* \
   %{buildroot}%{_sysconfdir}/profile.d/

#... and drop roots script
rm %{buildroot}%{_bindir}/roots

# REGISTER NON-STD LOCATION OF LIBS AT /etc/ld.so.conf.d
mkdir -p %{buildroot}/%{_sysconfdir}/ld.so.conf.d
echo "%{_libdir}/%{name}" > %{buildroot}/%{_sysconfdir}/ld.so.conf.d/root6.conf

# Remove an empty file from tutorials
rm %{buildroot}%{_docdir}/%{name}/tutorials/doc/v602/index.md

# Install desktop icon and application
mkdir -p %{buildroot}%{_datadir}/pixmaps
ln -s %{_datadir}/root/icons/Root6Icon.png %{buildroot}%{_datadir}/pixmaps/Root6.png
echo "Icon=Root6" >> ./etc/root.desktop
install -D -m0644 ./etc/root.desktop %{buildroot}%{_datadir}/applications/root.desktop

%fdupes %{buildroot}%{_docdir}/%{name}/
%fdupes %{buildroot}%{_libdir}/%{name}/
%fdupes %{buildroot}%{_datadir}/root/

# /SECTION
%endif

%if %{with test}
%check
%if %{with standalone_minuit2}
pushd math/minuit2
export Minuit2_DIR=%{buildroot}%{_libdir}/cmake/Minuit2
export LD_LIBRARY_PATH+=:%{buildroot}%{_libdir}
%else
export LD_LIBRARY_PATH+=:%{buildroot}%{mylibdir}
# This is no longer just 'build' (because of python_expand usage?)
cp -r _build.tmp build
%endif
export CXX=g++%{?gcc_ver:-%{gcc_ver}}
%ctest
%endif

%if %{with standalone_minuit2}
%ldconfig_scriptlets -n %{name}-devel
%else
%ldconfig_scriptlets -n %{libname}
%endif

%if %{with standalone_minuit2}
%files devel
%license math/minuit2/LICENSE
%doc math/minuit2/README.md math/minuit2/test
%{_libdir}/lib*.so
%{_libdir}/cmake/
%{_includedir}/Minuit2/

%else

%files libs
%dir %{mylibdir}
%{mylibdir}/lib*.so.*
%config %{_sysconfdir}/ld.so.conf.d/*.conf

%files devel
%doc %{_docdir}/%{name}/CREDITS
%doc %{_docdir}/%{name}/DEVELOPMENT.md
%doc %{_docdir}/%{name}/cfortran.doc
%doc %{_docdir}/%{name}/README*
%doc %{_docdir}/%{name}/ReleaseNotes/
%license %{_docdir}/%{name}/LICENSE
%{_bindir}/proofserv
%{_bindir}/rmkdepend
%{_bindir}/root
%{_bindir}/root.exe
%{_bindir}/rootcling
%{_bindir}/rootcint
%{_bindir}/rootn.exe
%{_bindir}/rootnb.exe
%{_bindir}/root-config
%{_bindir}/roots.exe
%{_datadir}/root/
%{_libdir}/%{name}/lib*.rootmap
%{_libdir}/%{name}/lib*.pcm
%{_includedir}/root/
%{_libdir}/%{name}/lib*.so
%if %{with test}
%{_libdir}/%{name}/TestSupport/
%endif
%{_mandir}/man1/*.1%{?ext_man}
# Should be part of the utils package, but see https://github.com/root-project/root/issues/11448
%{_bindir}/hadd
%{_bindir}/hist2workspace
%{_datadir}/applications/*.desktop
%{_datadir}/pixmaps/Root6.png

%files config
%config %{_sysconfdir}/profile.d/*

%files -n %{python_prefix}-root6
%{python_sitearch}/DistRDF/
%{python_sitearch}/cppyy*/
%{python_sitearch}/*.so
%{python_sitearch}/*ROOT/
%{python_sitearch}/cmdLineUtils.py
%pycache_only %{python_sitearch}/__pycache__/*

%files tutorials
%dir %{_docdir}/%{name}
%{_docdir}/%{name}/tutorials/

%files test
%doc test

%files utils
%{_bindir}/genreflex
%{_bindir}/prepareHistFactory
%{_bindir}/rootbrowse
%{_bindir}/rootcp
%{_bindir}/rootdrawtree
%{_bindir}/rooteventselector
%{_bindir}/rootls
%{_bindir}/rootmkdir
%{_bindir}/rootmv
%{_bindir}/rootprint
%{_bindir}/rootreadspeed
%{_bindir}/rootrm
%{_bindir}/rootssh
%{_bindir}/rootslimtree

%endif

%changelog
openSUSE Build Service is sponsored by