File root.spec of Package root

#
# spec file for package root
#
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
#
# 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}

%if "%{flavor}" == ""
ExclusiveArch: do_not_build
%endif

%if "%{flavor}" == "root"
%define pname root
%define libname %{pname}-libs
%define with_standalone_minuit2 0
%define mylibdir %{_libdir}/root
%define myincdir %{_includedir}/root
%endif

%if "%{flavor}" == "minuit2"
%define pname Minuit2
%define libname lib%{pname}
%define with_standalone_minuit2 1
%endif

%define series 6
%define sover 6_18
%define _lto_cflags %{nil}
Name:           %{pname}
Version:        6.18.04
Release:        0
Summary:        Numerical data analysis framework (OO)
License:        LGPL-2.1-or-later
URL:            https://root.cern.ch
Source0:        https://root.cern.ch/download/root_v%{version}.source.tar.gz
Source1:        root-rpmlintrc
BuildRequires:  Mesa-devel
BuildRequires:  cfitsio-devel
BuildRequires:  chrpath
BuildRequires:  cmake
BuildRequires:  desktop-file-utils
BuildRequires:  doxygen
BuildRequires:  fdupes
BuildRequires:  fftw3-devel
BuildRequires:  freetype2-devel
BuildRequires:  ftgl-devel
BuildRequires:  gcc-c++
BuildRequires:  gawk
BuildRequires:  giflib-devel
BuildRequires:  git
BuildRequires:  glew-devel
BuildRequires:  gmock
BuildRequires:  graphviz-devel
BuildRequires:  gsl-devel
BuildRequires:  gtest
BuildRequires:  hdf5-devel
BuildRequires:  libexpat-devel
BuildRequires:  libjpeg-devel
BuildRequires:  libmysqlclient-devel
BuildRequires:  libpng-devel
BuildRequires:  libtiff-devel
BuildRequires:  libxml2-devel
BuildRequires:  memory-constraints
BuildRequires:  openldap2-devel
BuildRequires:  openssl-devel
BuildRequires:  pcre-devel
BuildRequires:  pkgconfig
BuildRequires:  postgresql-devel
BuildRequires:  pythia-devel
BuildRequires:  python3-devel
BuildRequires:  python3-numpy-devel
BuildRequires:  ruby-devel >= 1.8
BuildRequires:  sqlite3-devel
BuildRequires:  unixODBC-devel >= 2.2.11
BuildRequires:  update-desktop-files
BuildRequires:  xorg-x11-libICE-devel
BuildRequires:  xorg-x11-libSM-devel
BuildRequires:  xorg-x11-libX11-devel
BuildRequires:  xorg-x11-libXext-devel
BuildRequires:  xrootd-client-devel >= 4.6
BuildRequires:  xrootd-private-devel >= 4.6
BuildRequires:  xz-devel
BuildRequires:  zlib-devel
BuildRequires:  pkgconfig(davix)
BuildRequires:  pkgconfig(glu)
BuildRequires:  pkgconfig(xft)
BuildRequires:  pkgconfig(xpm)
Requires:       %{name}-libs = %{version}
Requires:       font(droidsans)
Requires:       font(freemono)
Requires:       font(freesans)
Requires:       font(freeserif)
# SECTION Patches required for successful build
# PATCH-FIX-UPSTREAM root-no-gtest.patch badshah400@gmail.com -- Disable downloading and using own copy of gtest; use system installed package instead; patch taken from Fedora
Patch0:         root-no-gtest.patch
# PATCH-FIX-UPSTREAM root-reduce-compile-memory.patch badshah400@gmail.com -- Reduce the memory during compilation somewhat; patch taken from fedora
Patch1:         root-reduce-compile-memory.patch
# PATCH-FIX-UPSTREAM root-clang-ignore-gcc-options.patch badshah400@gmail.com -- Let clang ignore gcc options it doesn't support/recognise; patch taken from fedora
Patch2:         root-clang-ignore-gcc-options.patch
# PATCH-FIX-UPSTREAM root-minuit2-standalone-add-compilation-flag.patch badshah400@gmail.com -- Pass a preprocessor macro via cmake to avoid build failures
Patch3:         root-minuit2-standalone-add-compilation-flag.patch
# /SECTION
# SECTION Other patches
# PATCH-FIX-UPSTREAM root-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:         root-fontconfig.patch
# PATCH-FIX-UPSTREAM root-python3.patch badshah400@gmail.com -- Patch to enable python3 compatibility; patch taken from fedora
Patch11:         root-python3.patch
# PATCH-FEATURE-UPSTREAM root-minuit2-standalone-libdir.patch badshah400@gmail.com -- Install libraries to proper arch-dependent dir when building minuit2-standalone
Patch12:         root-minuit2-standalone-libdir.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}
License:        LGPL-2.1-or-later
%if "%{flavor}" == "root"
Provides:       root-Core-libs = %{version}
Provides:       root-extra-libs = %{version}
Provides:       root-Hist-libs = %{version}
Provides:       root-IO-libs = %{version}
Provides:       root-MathCore-libs = %{version}
Provides:       root-Matrix-libs = %{version}
Provides:       root-Minuit2-libs = %{version}
Provides:       root-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
License:        LGPL-2.1-or-later
%if "%{flavor}" == "root"
Requires:       %{name}-libs = %{version}
Provides:       root-Core-devel = %{version}
Provides:       root-extra-devel = %{version}
Provides:       root-Hist-devel = %{version}
Provides:       root-IO-devel = %{version}
Provides:       root-MathCore-devel = %{version}
Provides:       root-Matrix-devel = %{version}
Provides:       root-Minuit2-devel = %{version}
Provides:       root-Thread-devel = %{version}
%endif

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

%package -n python3-root-devel
Summary:        Python bindings for ROOT
License:        LGPL-2.1-or-later
Requires:       root-devel

%description -n python3-root-devel
This package provides python bindings for ROOT.

%package emacs
Summary:        Syntax highlighting and integration of ROOT with emacs
License:        LGPL-2.1-or-later
Recommends:     root-devel

%description emacs
This package provides a set of macros to integrate ROOT with the
emacs text editor. Includes syntax highlighting and help with ROOT
functions.

%package tutorials
Summary:        A set of tutorials for %{name}
License:        LGPL-2.1-or-later
Requires:       %{name}-devel = %{version}

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

%package test
Summary:        Tests for %{name}
License:        LGPL-2.1-or-later
Requires:       %{name}-devel = %{version}

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

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

# SECTION REMOVE NON-FREE FONTS
find ./fonts -type f -a '!' -name 'STIX*' -exec rm {} ';'
# /SECTION

%build
%if %{with_standalone_minuit2}
pushd math/minuit2
%cmake -Dminuit2_standalone=ON
%else
%cmake \
       -DCMAKE_INSTALL_LIBDIR:PATH=%{mylibdir} \
       -DCMAKE_INSTALL_INCDIR:PATH=%{myincdir} \
       -DCMAKE_INSTALL_SYSCONFDIR:PATH=%{_datadir}/%{name} \
       -DCMAKE_INSTALL_DOCDIR:PATH=%{_docdir}/%{name} \
       -DCMAKE_INSTALL_ELISPDIR:PATH=%{_datadir}/emacs/site-lisp \
       -Dgnuinstall:BOOL=ON \
       -Dbuiltin_afterimage:BOOL=OFF \
       -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_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=OFF \
       -Dbuiltin_vc:BOOL=OFF \
       -Dbuiltin_vdt:BOOL=OFF \
       -Dbuiltin_veccore:BOOL=OFF \
       -Dbuiltin_xrootd:BOOL=OFF \
       -Dbuiltin_xxhash:BOOL=OFF \
       -Dbuiltin_zlib:BOOL=OFF \
       -Dalien:BOOL=OFF \
       -Darrow:BOOL=OFF \
       -Dasimage:BOOL=ON \
       -Dastiff:BOOL=ON \
       -Dccache:BOOL=OFF \
       -Dcefweb:BOOL=OFF \
       -Dclad:BOOL=OFF \
       -Dcling:BOOL=ON \
       -Dcocoa:BOOL=OFF \
       -Dcuda:BOOL=OFF \
       -DCMAKE_CXX_STANDARD=11 \
       -Droot7:BOOL=OFF \
       -Dwebgui:BOOL=OFF \
       -Dcxxmodules:BOOL=OFF \
       -Ddavix:BOOL=ON \
       -Ddcache:BOOL=OFF \
       -Dexceptions:BOOL=ON \
       -Dexplicitlink:BOOL=ON \
       -Dfftw3:BOOL=ON \
       -DFIREFOX_EXECUTABLE:PATH=%{_bindir}/firefox \
       -Dfitsio:BOOL=ON \
       -Dfortran:BOOL=ON \
       -Dgdml:BOOL=ON \
       -Dgfal:BOOL=OFF \
       -Dgsl_shared:BOOL=ON \
       -Dgviz:BOOL=ON \
       -Dhttp:BOOL=ON \
       -Dimt:BOOL=OFF \
       -Djemalloc:BOOL=OFF \
       -Dlibcxx:BOOL=OFF \
       -Dmathmore:BOOL=ON \
       -Dmemory_termination:BOOL=OFF \
       -Dmemstat:BOOL=ON \
       -Dminuit2:BOOL=ON \
       -Dmonalisa:BOOL=OFF \
       -Dmysql:BOOL=ON \
       -Dodbc:BOOL=ON \
       -Dopengl:BOOL=ON \
       -Doracle:BOOL=OFF \
       -Dpch:BOOL=ON \
       -Dpgsql:BOOL=ON \
       -Dpythia6:BOOL=OFF \
       -Dpythia8:BOOL=ON \
       -Dpython: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 \
       -Dtcmalloc:BOOL=OFF \
       -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 \
       -Dvmc:BOOL=ON \
       -Dx11:BOOL=ON \
       -Dxml:BOOL=ON \
       -Dxrootd:BOOL=ON \
       -Dfail-on-missing:BOOL=ON \
       -Dtesting:BOOL=ON \
       -Dclingtest:BOOL=OFF \
       -Dcoverage:BOOL=OFF \
       -Droottest:BOOL=OFF \
       -Drootbench:BOOL=OFF
%endif

%cmake_build

%install
%if %{with_standalone_minuit2}
# SECTION INSTALL FOR MINUIT2 STANDALONE
pushd math/minuit2
%cmake_install
popd
mkdir -p %{buildroot}%{_libdir}/cmake
mv %{buildroot}%{_prefix}/lib/cmake/* %{buildroot}%{_libdir}/cmake/
# /SECTION

%else

# SECTION INSTALL FOR FULL ROOT
%cmake_install
# REPLACE env BASED HASHBANGS
for sc in rootbrowse rootcp rootdrawtree rooteventselector rootls rootmkdir rootmv rootprint rootrm rootslimtree
do
  sed -i "s|#!%{_bindir}/env python%{py3_ver}|#!%{_bindir}/python%{py3_ver}|" %{buildroot}%{_bindir}/${sc}
done
sed -i "s|#!%{_bindir}/env bash|#!/bin/bash|" %{buildroot}%{_bindir}/root-config
sed -i "s|#! %{_bindir}/env python|#!%{_bindir}/python%{py3_ver}|" %{buildroot}%{_datadir}/root/dictpch/makepch.py

# HANDLE NON-STANDARD LOCATIONS FOR PYTHON PACKAGES
install -d %{buildroot}%{python3_sitearch}
mv -t %{buildroot}%{python3_sitearch} \
  %{buildroot}%{_libdir}/root/ROOT.py  \
  %{buildroot}%{_libdir}/root/_pythonization.py  \
  %{buildroot}%{_libdir}/root/cmdLineUtils.py  \
  %{buildroot}%{_libdir}/root/cppyy.py  \
  %{buildroot}%{_libdir}/root/JsMVA/  \
  %{buildroot}%{_libdir}/root/JupyROOT/  \
  %{buildroot}%{_libdir}/root/libPyROOT.so  \
  %{buildroot}%{_libdir}/root/libPyMVA.so  \
  %{buildroot}%{_libdir}/root/libJupyROOT.so

mv %{buildroot}%{_libdir}/%{name}/__pycache__ %{buildroot}%{python3_sitearch}/

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

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

# REMOVE SOME UNNECESSARY FILES
rm %{buildroot}%{_datadir}/%{name}/proof/*.sample
rm -rf %{buildroot}%{_datadir}/%{name}/proof/utils
rm %{buildroot}%{_datadir}/%{name}/root.desktop
rm %{buildroot}%{_bindir}/setxrd*
rm %{buildroot}%{_bindir}/thisroot*
rm %{buildroot}%{_docdir}/%{name}/INSTALL
rm %{buildroot}%{_mandir}/man1/g2rootold.1
rm %{buildroot}%{_mandir}/man1/genmap.1
rm %{buildroot}%{_mandir}/man1/proofserva.1
rm %{buildroot}%{_mandir}/man1/roota.1
rm %{buildroot}%{_docdir}/%{name}/README.ALIEN
rm %{buildroot}%{_docdir}/%{name}/README.CXXMODULES.md
rm %{buildroot}%{_docdir}/%{name}/README.MONALISA
rm %{buildroot}%{_libexecdir}/lib*.py

# MOVE man FILES TO CORRECT LOC
mkdir -p %{buildroot}%{_mandir}/man1
mv %{buildroot}%{_mandir}/*.1 %{buildroot}%{_mandir}/man1/

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

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

# /SECTION
%endif

%if %{with_standalone_minuit2}
%post devel -p /sbin/ldconfig
%postun devel -p /sbin/ldconfig
%else
%post -n %{libname} -p /sbin/ldconfig
%postun -n %{libname} -p /sbin/ldconfig
%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}/*

%else

%files
%{_bindir}/*
%{_mandir}/man1/*.1%{?ext_man}
%exclude %{_bindir}/root-config
%exclude %{_mandir}/man1/root-config.1%{?ext_man}

%files emacs
%dir %{_datadir}/emacs
%dir %{_datadir}/emacs/site-lisp
%{_datadir}/emacs/site-lisp/*

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

%files devel
%doc %{_docdir}/%{name}/CREDITS
%doc %{_docdir}/%{name}/cfortran.doc
%doc %{_docdir}/%{name}/README*
%doc %{_docdir}/%{name}/ReleaseNotes/
%license %{_docdir}/%{name}/LICENSE
%{_bindir}/root-config
%{_libdir}/%{name}/lib*.rootmap
%{_libdir}/%{name}/lib*.pcm
%{_includedir}/%{name}/
%{_libdir}/%{name}/lib*.so
%{_datadir}/%{name}/
%{_mandir}/man1/root-config.1%{?ext_man}

%files -n python3-root-devel
%{python3_sitearch}/*

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

# FIXME: Disable test files until building with tests enabled is fixed
#%%files test
#%%dir %%{_docdir}/%%{name}
#%%{_docdir}/%%{name}/test/

%endif

%changelog