File cling.spec of Package cling

#
# spec file for package cling
#
# Copyright (c) 2024, 2025 Boian Berberov
#
# 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/
#

### BEGIN Build Configuration ###

# Handle executables or shared libraries containing more than COUNT debugging
# information entries in their .debug_info section using a slower and more
# memory usage friendly mode and don’t attempt to optimize that object in
# multifile mode.  The default is 10 million DIEs.  There is a risk that for
# very large amounts of debugging information in a single shared library or
# executable there might not be enough memory (especially when dwz tool is
# 32‐bit binary, it might run out of available virtual address space even
# sooner).  Specifying none as argument disables the limit.
# OBS Default:  _dwz_low_mem_die_limit     10000000
#                                            ,  ,
%global         _dwz_low_mem_die_limit     40000000

# Don’t attempt to optimize executables or shared libraries containing more
# than COUNT DIEs at all.  The default is 50 million DIEs.  Specifying `none`
# as argument disables the limit.
# OBS Default:  _dwz_max_die_limit         50000000
#                                            ,  ,
%global         _dwz_max_die_limit        200000000

# Don't LTO on x86, OOM
# %%ifarch %%ix86
# %%{expand:%%global optflags $(echo "%%optflags" | sed -e s/-flto=[[:alnum:]]*//) }
# %%endif
%{expand:%%global optflags $(echo "%optflags" | sed -e 's/-flto=[[:alnum:]]*//; s/-D_FORTIFY_SOURCE=./-D_FORTIFY_SOURCE=0/; s/\\B-g\\b//g') }

%if 0%{?fedora}
%{expand:%%global optflags $(echo "%optflags" | sed -e s/-mtls-dialect=[[:alnum:]]*//) }
%endif

### END   Build Configuration ###

### BEGIN General Build Definitions ###

# BUG: cling-1.2/lib/Interpreter/Interpreter.cpp:270:47: error: no matching constructor for initialization of 'Parser'
# YES %%global         root_llvm_tag  cling-llvm18-20250110-01
# %%global         root_llvm_tag  cling-llvm18-20250113-01
# %%global         root_llvm_tag  cling-llvm18-20250117-01
# %%global         root_llvm_tag  cling-llvm18-20250124-01
%global         root_llvm_tag  cling-llvm18-20250207-01
#  NO %%global         root_llvm_tag  cling-llvm18-20250225-01
#  NO %%global         root_llvm_tag  cling-llvm18-20250313-01
# %%global         root_llvm_tag  cling-llvm18-20250616-01
#  NO %%global         root_llvm_tag  cling-llvm18-20250721-01

%if 0%{?is_opensuse}
# macros.cmake overrides
%global         __sourcedir    llvm-project-%{root_llvm_tag}/llvm
%else
# macros.cmake overrides
%global         _vpath_srcdir  llvm-project-%{root_llvm_tag}/llvm
%endif

### END   General Build Definitions ###


### BEGIN Package ###
Name:           cling
Version:        1.2
Release:        0%{?dist}
Group:          Development/Languages/C and C++
Summary:        The Interactive C++ Interpreter
License:        LGPL-2.1+
URL:            https://github.com/root-project/%{name}

Source0:        %{url}/archive/refs/tags/v%{version}.tar.gz
Source1:        https://github.com/root-project/llvm-project/archive/refs/tags/%{root_llvm_tag}.tar.gz
Source999:      %{name}.rpmlintrc

BuildRequires:  cmake >= 3.20

%if 0%{?is_opensuse}
# BuildRequires:  gcc-c++
BuildRequires:  clang18
# BuildRequires:  llvm18
# BuildRequires:  lld18
BuildRequires:  llvm18-gold
BuildRequires:  libstdc++-devel
# BuildRequires:  llvm18-libc++-devel
%else
# BuildRequires:  gcc-c++
BuildRequires:  clang
# BuildRequires:  llvm18
# BuildRequires:  lld18
BuildRequires:  libstdc++-devel
# BuildRequires:  libcxx-devel
%endif

%if 0%{?is_opensuse}
BuildRequires:  ninja
%else
BuildRequires:  ninja-build
%endif

BuildRequires:  libxml2-devel
BuildRequires:  zlib-devel

%description
Cling is an interactive C++ interpreter, built on top of Clang and LLVM compiler infrastructure. Cling realizes the read-eval-print loop (REPL) concept, in order to leverage rapid application development. Implemented as a small extension to LLVM and Clang, the interpreter reuses their strengths such as the praised concise and expressive compiler diagnostics.

### END   Package ###

### BEGIN Build Steps ###

%prep
%setup -q -c -a 1

# Remove the LLVM_PATH define
%__sed -i \
	-e '/we need to define LLVM_PATH/,$d' \
	%{name}-%{version}/lib/Interpreter/CMakeLists.txt



%build
%set_build_flags

%if 0%{?is_opensuse}
export CC=clang-18
export CXX=clang++-18
# export AR=llvm-ar
# export NM=llvm-nm
# export RANLIB=llvm-ranlib
%else
export CC=clang
export CXX=clang++
# export AR=llvm-ar
# export NM=llvm-nm
# export RANLIB=llvm-ranlib
%endif

# export CXXFLAGS="${CXXFLAGS} -stdlib=libc++"

# NOTE: -DLLVM_TARGETS_TO_BUILD="host;NVPTX" is required
%cmake \
	-DCMAKE_INSTALL_PREFIX:PATH="/opt/%{name}" \
	\
	-DBUILD_SHARED_LIBS:BOOL=OFF \
	-DBUILD_STATIC_LIBS:BOOL=OFF \
	\
	-DLLVM_ENABLE_BINDINGS=OFF \
	-DLLVM_ENABLE_PROJECTS="clang" \
	-DLLVM_EXTERNAL_CLING_SOURCE_DIR="../%{name}-%{version}" \
	-DLLVM_EXTERNAL_PROJECTS="%{name}" \
	-DLLVM_TARGETS_TO_BUILD="host;NVPTX" \
	\
	-DLLVM_BUILD_LLVM_DYLIB=OFF \
	-DLLVM_BUILD_TESTS:BOOL=OFF \
	-DLLVM_BUILD_TOOLS:BOOL=OFF \
	-DLLVM_INSTALL_TOOLCHAIN_ONLY:BOOL=OFF \
	-DLLVM_PARALLEL_LINK_JOBS=1 \
	\
	-DLIBCXX_ENABLE_SHARED=YES \
	-DLIBCXX_ENABLE_STATIC=NO \
	-DLIBCXX_INSTALL_MODULES=ON \
	-DLIBCXXABI_ENABLE_SHARED=YES \
	-DLIBCXXABI_ENABLE_STATIC=NO \
	-DLIBCXXABI_USE_LLVM_UNWINDER:BOOL=OFF \
	\
	-DCLING_INCLUDE_TESTS=NO \
	-DCLING_CXX_PATH="/opt/%{name}/bin/clang++" \
	\
%if 0%{?fedora}
	-DCMAKE_BUILD_TYPE=RelWithDebInfo \
%endif
	-DCMAKE_C_FLAGS_RELWITHDEBINFO="-O2 -DNDEBUG" \
	-DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -DNDEBUG"

%cmake_build



# %%check
# %%cmake_build cling-test



%install
%cmake_install



%files
%license        %{name}-%{version}/LICENSE.TXT

%dir            /opt/%{name}
%dir            /opt/%{name}/include
%dir            /opt/%{name}/lib
%dir            /opt/%{name}/lib/cmake
%dir            /opt/%{name}/share
%dir            /opt/%{name}/share/man

/opt/%{name}/bin/

/opt/%{name}/include/%{name}/
/opt/%{name}/include/clang-c/
/opt/%{name}/include/clang/
/opt/%{name}/include/llvm-c/
/opt/%{name}/include/llvm/

/opt/%{name}/lib/libLTO.so*
/opt/%{name}/lib/libRemarks.so*
/opt/%{name}/lib/libclang-cpp.so*
/opt/%{name}/lib/libclang.so*
/opt/%{name}/lib/libcling.so*
/opt/%{name}/lib/libclingJupyter.so*

/opt/%{name}/lib/*.a

/opt/%{name}/lib/clang/
/opt/%{name}/lib/cmake/%{name}/
/opt/%{name}/lib/cmake/clang/
/opt/%{name}/lib/cmake/llvm/
/opt/%{name}/lib/libear/
/opt/%{name}/lib/libscanbuild/

/opt/%{name}/libexec/

/opt/%{name}/share/clang/
/opt/%{name}/share/opt-viewer/
/opt/%{name}/share/scan-build/
/opt/%{name}/share/scan-view/

/opt/%{name}/share/man/man1/

### END   Build Steps ###



%changelog

* Wed Jul 23 2025 Boian Berberov
- Added changelog for openSUSE Leap 16
openSUSE Build Service is sponsored by