File rocm-llvm.spec of Package rocm-llvm

# spec file for package rocm-llvm
#
# Copyright (c) 2020 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/
#

# Upstream tags are based on rocm releases:
%global rocm_major 6
%global rocm_minor 2
%global rocm_patch 0
%global rocm_release %{rocm_major}.%{rocm_minor}
%global rocm_version %{rocm_release}.%{rocm_patch}
# AMD ROCm LLVM Code Object Manager
%global comgr_major 2
%global comgr_version %{comgr_major}.8.0
%define comgr_libname libamd_comgr%{comgr_major}
# ROCR-Runtime version
%define hsa_major 1
%define hsa_version %{hsa_major}.14.0
%define rocr_libname libhsa-runtime64-%{hsa_major}
# What LLVM is upstream using (use LLVM_VERSION_MAJOR from llvm/CMakeLists.txt):
%global llvm_maj_ver 18
%global llvm_version %{llvm_maj_ver}.0.0
%global llvm_dylib_suffix rocm%{rocm_major}%{rocm_minor}%{rocm_patch}

%global upstreamname llvm-project

# build-related CMake defs
%define build_flags $(echo %{optflags} | sed 's/-flto=auto//')
%define linker_flags %{?build_ldflags} -fuse-ld=lld -Wl,--as-needed -Wl,--no-undefined -Wl,-z,now -Wl,--build-id=sha1
%define module_linker_flags %{?build_ldflags} -fuse-ld=lld -Wl,--as-needed -Wl,--build-id=sha1

%bcond_with debug
%if %{with debug}
%global build_type DEBUG
%else
%global build_type relwithdebinfo
%endif

# What RPM spells ppc, GCC spells powerpc.
%define target_cpu %{lua:print((string.gsub(rpm.expand("%{_target_cpu}"), "ppc", "powerpc")))}
%define host_triple %{target_cpu}-%{_target_vendor}-%{_target_os}

%ifnarch ppc64le
%global openmp_cpu %{target_cpu}
%else
%global openmp_cpu ppc64
%endif

%define _llvm_prefix %{_prefix}/rocm/

%define cmake_llvm_opts \\\
    -DCMAKE_BUILD_TYPE=%build_type \\\
    -DCMAKE_INSTALL_PREFIX=%{_llvm_prefix} \\\
    -DCMAKE_CXX_COMPILER=%{_bindir}/clang++ \\\
    -DCMAKE_C_COMPILER=%{_bindir}/clang \\\
    -DCMAKE_LINKER=%{_bindir}/ld.lld \\\
    -DCMAKE_AR=%{_bindir}/llvm-ar \\\
    -DCMAKE_RANLIB=%{_bindir}/llvm-ranlib \\\
    -DCMAKE_EXE_LINKER_FLAGS="%linker_flags" \\\
    -DCMAKE_MODULE_LINKER_FLAGS="%module_linker_flags" \\\
    -DCMAKE_SHARED_LINKER_FLAGS="%linker_flags" \\\
    -DCMAKE_SKIP_INSTALL_RPATH=ON \\\
    -DCMAKE_INSTALL_DO_STRIP=ON \\\
    -DPython3_EXECUTABLE=%{_bindir}/python3 \\\
    -DBUILD_SHARED_LIBS=OFF \\\
    -DLLVM_BUILD_TESTS=ON \\\
    -DLLVM_INCLUDE_TESTS=ON \\\
    -DCLANG_INCLUDE_TESTS=ON \\\
    -DLLVM_ENABLE_PROJECTS="llvm;clang;lld" \\\
    -DLLVM_ENABLE_RUNTIMES="compiler-rt" \\\
    -DLLVM_OPTIMIZED_TABLEGEN=ON \\\
    -DLLVM_BINUTILS_INCDIR=%{_includedir} \\\
    -DLLVM_HOST_TRIPLE=%{host_triple} \\\
    -DLLVM_BUILD_LLVM_DYLIB=ON \\\
    -DLLVM_LINK_LLVM_DYLIB=ON \\\
    -DLLVM_BUILD_RUNTIME=OFF \\\
    -DLLVM_BUILD_TOOLS=ON \\\
    -DLLVM_TOOL_LLVM_EXEGESIS_BUILD=OFF \\\
    -DLLVM_BUILD_UTILS=OFF \\\
    -DLLVM_BUILD_EXAMPLES=OFF \\\
    -DLLVM_POLLY_BUILD=OFF \\\
    -DLLVM_INCLUDE_BENCHMARKS=OFF \\\
    -DLLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=OFF \\\
    -DLLVM_ENABLE_ASSERTIONS=OFF \\\
    -DLLVM_TARGETS_TO_BUILD="X86;AMDGPU" \\\
    -DLLVM_PARALLEL_COMPILE_JOBS="$max_compile_jobs" \\\
    -DLLVM_PARALLEL_LINK_JOBS="$max_link_jobs" \\\
    -DENABLE_LINKER_BUILD_ID=ON \\\
    -DLLVM_APPEND_VC_REV=OFF \\\
    -DCLANG_LINK_CLANG_DYLIB=ON \\\
    -DCLANG_ENABLE_ARCMT=OFF \\\
    -DCLANG_ENABLE_STATIC_ANALYZER=OFF \\\
    -DCLANG_LINK_FLANG=OFF \\\
    -DCLANG_LINK_FLANG_LEGACY=OFF \\\
    -DCLANG_DEFAULT_LINKER=lld \\\
    -DCOMPILER_RT_BUILD_SANITIZERS=OFF \\\
    -DCOMPILER_RT_BUILD_MEMPROF=OFF \\\
    -DCOMPILER_RT_BUILD_XRAY=OFF \\\
    -DLLDB_DISABLE_PYTHON=ON \\\
    -DLLVM_ENABLE_LTO=Thin \\\
%if "%{_lib}" == "lib64" \
    -DLLVM_LIBDIR_SUFFIX=64 \\\
%endif \
    -DLLVM_VERSION_SUFFIX=%{llvm_dylib_suffix} \\\
    -DLLVM_ENABLE_RTTI:BOOL=ON \\\
    -DLLVM_ENABLE_PIC=ON \\\
    -DLIBCXX_ENABLE_SHARED=NO \\\
    -DLIBCXX_ENABLE_STATIC=NO \\\
    -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=NO \\\
    -DLIBCXXABI_ENABLE_SHARED=NO \\\
    -DLIBCXXABI_ENABLE_STATIC=NO

%define use_rocmllvm_linker_flags -fuse-ld=%{_llvm_build_dir}/bin/ld.lld -Wl,--hash-style=both -Wl,--as-needed -Wl,--no-undefined -Wl,-z,now -Wl,--build-id=sha1
%define use_rocmllvm_module_linker_flags -fuse-ld=%{_llvm_build_dir}/bin/ld.lld -Wl,--as-needed -Wl,--build-id=sha1

%define cmake_use_rocmllvm_opts \\\
    -DCMAKE_BUILD_TYPE=%build_type \\\
    -DCMAKE_CXX_COMPILER=%{_llvm_build_dir}/bin/clang++ \\\
    -DCMAKE_C_COMPILER=%{_llvm_build_dir}/bin/clang \\\
    -DCMAKE_LINKER=%{_llvm_build_dir}/bin/ld.lld \\\
    -DCMAKE_AR=%{_llvm_build_dir}/bin/llvm-ar \\\
    -DCMAKE_RANLIB=%{_llvm_build_dir}/bin/llvm-ranlib \\\
    -DCMAKE_EXE_LINKER_FLAGS="%use_rocmllvm_linker_flags" \\\
    -DCMAKE_MODULE_LINKER_FLAGS="%use_rocmllvm_module_linker_flags" \\\
    -DCMAKE_SHARED_LINKER_FLAGS="%use_rocmllvm_linker_flags" \\\
    -DCMAKE_SKIP_INSTALL_RPATH=ON \\\
    -DCMAKE_INSTALL_DO_STRIP=ON \\\
    -DPython3_EXECUTABLE=%{_bindir}/python3 \\\
    -DLLVM_ROOT=%{_llvm_build_dir} \\\
    -DClang_DIR=%{_llvm_build_dir}/%{_lib}/cmake/clang \\\
    -DLLD_DIR=%{_llvm_build_dir}/%{_lib}/cmake/lld
    
%define comment() %{nil}

# Due to RPMs recursion limit, we have to split the lists into portions of ≤ 20.
%global llvm_ua_anchor llvm-ar
%global llvm_tools \
%{comment Optimizer, compiler, interpreter, linker} \
    llc \
    lli \
    llvm-jitlink \
    llvm-link \
    llvm-lto \
    llvm-lto2 \
    llvm-rtdyld \
    opt \
%{comment LLVM IR tools} \
    llvm-as \
    llvm-bcanalyzer \
    llvm-bitcode-strip \
    llvm-cat \
    llvm-diff \
    llvm-dis \
    llvm-extract \
    llvm-modextract \
    llvm-sim \
    llvm-split
%global llvm_elf_dwarf_tools \
%{comment ELF tools} \
    llvm-cfi-verify \
    llvm-nm \
    llvm-objcopy \
    llvm-objdump \
    llvm-ranlib \
    llvm-readelf \
    llvm-readobj \
    llvm-size \
    llvm-strip \
%{comment Debug info tools} \
    dsymutil \
    llvm-addr2line \
    llvm-debuginfo-analyzer \
    llvm-debuginfod \
    llvm-debuginfod-find \
    llvm-dwarfdump \
    llvm-dwarfutil \
    llvm-dwp \
    llvm-gsymutil
%global llvm_abi_coff_macho_tools \
%{comment ABI tools} \
    llvm-cxxdump \
    llvm-cxxfilt \
    llvm-cxxmap \
    llvm-ifs \
%{comment Windows/COFF} \
    llvm-cvtres \
    llvm-dlltool \
    llvm-lib \
    llvm-ml \
    llvm-mt \
    llvm-pdbutil \
    llvm-rc \
    llvm-undname \
    llvm-windres \
%{comment Apple/Mach-O} \
    llvm-install-name-tool \
    llvm-libtool-darwin \
    llvm-lipo \
    llvm-otool \
    llvm-readtapi
%global llvm_instr_devel_tools \
%{comment Instrumentation and introspection} \
    llvm-cov \
    llvm-opt-report \
    llvm-profdata \
    llvm-profgen \
    llvm-symbolizer \
    llvm-xray \
    sancov \
    sanstats \
%{comment Development utilities} \
    bugpoint \
    llvm-c-test \
    llvm-mc \
    llvm-mca \
    llvm-reduce \
    llvm-remarkutil \
    llvm-stress \
    llvm-strings \
%{comment     llvm-tblgen} \
    llvm-tli-checker \
    verify-uselistorder
%global llvm_offload_arch_tools \
    amdgpu-offload-arch \
    nvidia-arch \
    offload-arch

%global clang_ua_anchor clang
%global clang_binfiles \
    amdgpu-arch \
    c-index-test \
    clang++ \
    clang-cl \
    clang-cpp \
    clang-format \
    clang-linker-wrapper \
    clang-build-select-link \
    clang-offload-bundler \
    clang-offload-packager \
    clang-offload-wrapper \
    clang-refactor \
    clang-rename \
    clang-repl \
    clang-scan-deps \
    diagtool \
    nvptx-arch

%global lld_ua_anchor lld
%global lld_binfiles \
    ld.lld \
    lld-link \
    ld64.lld \
    wasm-ld

%global binfiles \
    %{clang_ua_anchor} %{clang_binfiles} \
    %{lld_ua_anchor} %{lld_binfiles} \
    %{llvm_ua_anchor} %{llvm_tools} %{llvm_elf_dwarf_tools} \
    %{llvm_abi_coff_macho_tools} %{llvm_instr_devel_tools} \
    %{llvm_offload_arch_tools}

# stripping
%define __strip %{_bindir}llvm-strip
%define __objdump %{_bindir}llvm-objdump

# Memory for build job
%define _dwz_low_mem_die_limit  40000000
%define _dwz_max_die_limit     200000000

%define mem_per_compile_job 1200000
%define mem_per_link_job 3000000

%define print_info() \
    echo "Available memory:" \
    cat /proc/meminfo \
    echo "System limits:" \
    ulimit -a

%define avail_mem %(awk '/MemAvailable/ { print $2 }' /proc/meminfo)

# set_jobs type memory
# Set max_<type>_jobs so that every job of the given type has at least the
# given amount of memory.
%define set_jobs() \
    max_%{1}_jobs="%{?jobs}" \
    test -z "${max_%{1}_jobs}" && max_%{1}_jobs=`nproc` || true \
    if test -n "${max_%{1}_jobs}" -a "${max_%{1}_jobs}" -gt 1 ; then \
        max_jobs="$((%{?avail_mem} / %2))" \
        test "${max_%{1}_jobs}" -gt "${max_jobs}" && max_%{1}_jobs="${max_jobs}" && \
        echo "Warning: Reducing number of %{1} jobs to $max_jobs because of memory limits" \
        test "${max_%{1}_jobs}" -le 0 && max_%{1}_jobs=1 && \
        echo "Warning: Not %{1}ing in parallel at all because of memory limits" \
    fi

# Recursion utils.
%global _stop0 1
%define _lapply_rec(p:f:) %{expand:%{%{-p*} %{-f*}} %%{?!_stop%#:%%{_lapply_rec -p %{-p*} -f %*}}}
%define _rapply_rec(p:f:) %{expand:%{%{-f*} %{-p*}} %%{?!_stop%#:%%{_rapply_rec -p %{-p*} -f %*}}}

# Usage:
#   %%global pattern foo_%%1
#   %%{lapply -p pattern a b c}
# produces foo_a foo_b foo_c.
%define lapply(p:) %{_lapply_rec -p %{-p*} -f %{shrink:%*}}
%define rapply(p:) %{_rapply_rec -p %{-p*} -f %{shrink:%*}}

Name:           rocm-llvm
Version:        %{llvm_maj_ver}+rocm%{rocm_version}
Release:        0
Summary:        The LLVM Compiler Infrastructure for building AMD ROCm stack
License:        Apache-2.0 WITH LLVM-exception
Group:          Development/Languages/Other
URL:            https://github.com/ROCm/%{upstreamname}
Source0:        %{url}/archive/refs/tags/rocm-%{rocm_version}.tar.gz#/%{name}-%{rocm_version}.tar.gz
Source1:        https://github.com/ROCm/ROCR-Runtime/archive/refs/tags/rocm-%{version}.tar.gz#/ROCR-Runtime-rocm-%{rocm_version}.tar.gz
Source2:        rocm-llvm-rpmlintrc

Patch0:         llvm-do-not-install-offload-arch-tools.patch
Patch1:         llvm-normally-versioned-libllvm.patch
Patch2:         clang-exclude-nvlink-wrapper.patch
Patch3:         check-no-llvm-exegesis.patch
Patch4:         llvm-do-not-install-static-libraries.patch
Patch5:         llvm-fix-shlib-test.patch
Patch6:         lld-libs-shared.patch
Patch7:         amd-hipcc-add-clang-launcher.patch
Patch8:         amd-hipcc-cleanup-build.patch
Patch9:         amd-hipcc-use-rocm-suffix.patch
Patch10:        amd-device-libs-use-shared-libllvm.patch
Patch11:        amd-device-libs-dont-install-docs.patch
Patch12:        amd-comgr-dont-install-docs.patch
Patch13:        llvm-Revert-ockl-Don-t-use-wave32-ballot-builtin.patch
Patch14:        clang-improve-distro-detection.patch
Patch15:        lld-default-sha1.patch
Patch16:        amd-comgr-fix-compiler.patch
Patch17:        clang-offloadbundler-use-rocm-suffix.patch
Patch18:        llvm-runtimes-fix-builtins-install-path.patch
Patch19:        llvm-Revert-GFX11-Add-a-new-target-gfx1152.patch
Patch20:        clang-prefer-rocm-tools.patch
Patch21:        openmp-use-in-tree-hsa-runtime.patch
Patch22:        openmp-fix-install-paths.patch
Patch23:        openmp-optional-nvidia-bc-lib.patch

Patch30:        rocr-runtime-link-drm_amdgpu.patch

BuildRequires:  binutils-devel
BuildRequires:  cmake
BuildRequires:  fdupes
BuildRequires:  git
BuildRequires:  memory-constraints
BuildRequires:  ninja
BuildRequires:  perl
BuildRequires:  python3-base
BuildRequires:  pkgconfig(libedit)
BuildRequires:  pkgconfig(zlib)

BuildRequires:  pkgconfig(libelf)
BuildRequires:  pkgconfig(libffi)
BuildRequires:  pkgconfig(libdrm)
BuildRequires:  pkgconfig(libdrm_amdgpu)
BuildRequires:  cmake(hsakmt) = %{rocm_release}
BuildRequires:  xxd

BuildRequires:  lld%{llvm_maj_ver}
BuildRequires:  llvm%{llvm_maj_ver}-devel
BuildRequires:  clang%{llvm_maj_ver}
BuildRequires:  clang%{llvm_maj_ver}-devel

Requires(post): update-alternatives
Requires(postun): update-alternatives

#Only the following architectures are useful for ROCm packages:
ExclusiveArch:  x86_64 # aarch64 ppc64le

%description
Advanced Micro Devices (AMD) fork of the Low Level Virtual Machine (LLVM) compiler infrastructure. 
The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
AMD Radeon Open Compute Platform (ROCm) is an Open software stack that includes programming models, 
tools, compilers, libraries, and runtimes for AI and HPC solution development on AMD GPUs.

%package     -n %{name}%{llvm_maj_ver}
Summary:        The LLVM Compiler Infrastructure for building AMD ROCm stack
Group:          Development/Tools/Building
Provides:       %{name} = %{rocm_version}
Provides:       rocm-release(llvm) = %{rocm_release}
Requires(post): update-alternatives
Requires(postun): update-alternatives

%description -n %{name}%{llvm_maj_ver}
This package contains common LLVM tools.

%package     -n %{name}%{llvm_maj_ver}-devel
Summary:        Development files for %{name}
Group:          Development/Tools/Building
Requires:       %{name}%{llvm_maj_ver} = %{version}-%{release}
Requires:       %{name}%{llvm_maj_ver}-libs = %{version}-%{release}
Provides:       rocm-llvm-devel = %{rocm_version}
Provides:       rocm-release(llvm-devel) = %{rocm_release}
Provides:       cmake(LLVM-ROCm) = %{rocm_release}
Conflicts:      cmake(LLVM-ROCm) < %{rocm_release}

%description -n %{name}%{llvm_maj_ver}-devel
This package contains library and header files needed to develop
new native programs that use the LLVM infrastructure.

%package     -n %{name}%{llvm_maj_ver}-libs
Summary:        Libraries for ROCM LLVM
Group:          System/Libraries/C and C++
Provides:       rocm-llvm-libs = %{rocm_version}
Provides:       rocm-release(llvm-libs) = %{rocm_release}

%description -n %{name}%{llvm_maj_ver}-libs
This package contains the shared libraries needed for LLVM.

%package     -n rocm-clang%{llvm_maj_ver}
Summary:        CLANG frontend for LLVM
Group:          Development/Languages/C and C++
URL:            https://clang.llvm.org/
Requires:       %{name}%{llvm_maj_ver} = %{version}-%{release}
Requires:       rocm-clang%{llvm_maj_ver}-libs = %{version}-%{release}
Requires:       rocm-lld%{llvm_maj_ver} = %{version}-%{release}
Provides:       rocm-clang = %{rocm_version}
Provides:       rocm-release(clang) = %{rocm_release}
Provides:       rocm-clang(major) = %{llvm_maj_ver}
Requires(post): update-alternatives
Requires(postun): update-alternatives
Recommends:     libstdc++-devel
Suggests:       libc++-devel

%description -n rocm-clang%{llvm_maj_ver}
This package contains the clang (C language) frontend for LLVM.

%package     -n rocm-clang%{llvm_maj_ver}-devel
Summary:        CLANG frontend for LLVM (devel package)
Group:          Development/Libraries/C and C++
URL:            https://clang.llvm.org/
Requires:       %{name}%{llvm_maj_ver}-devel = %{version}-%{release}
Requires:       rocm-clang%{llvm_maj_ver} = %{version}-%{release}
Provides:       rocm-clang-devel = %{rocm_version}
Provides:       rocm-release(clang-devel) = %{rocm_release}
Provides:       cmake(Clang-ROCm) = %{rocm_release}
Conflicts:      cmake(Clang-ROCm) < %{rocm_release}

%description -n rocm-clang%{llvm_maj_ver}-devel
This package contains the clang (C language) frontend for LLVM.
(development files)

%package     -n rocm-clang%{llvm_maj_ver}-libs
Summary:        Libraries for ROCM CLANG
Group:          Development/Languages/C and C++
URL:            https://clang.llvm.org/
Provides:       rocm-clang-libs = %{rocm_version}
Provides:       rocm-release(clang-libs) = %{rocm_release}

%description -n rocm-clang%{llvm_maj_ver}-libs
This package contains shared libraries exposing the C/C++ API to the Clang compiler.

%package     -n rocm-lld%{llvm_maj_ver}
Summary:        Linker for Clang/LLVM
Group:          Development/Tools/Building
URL:            https://lld.llvm.org/
Requires:       %{name}%{llvm_maj_ver} = %{version}-%{release}
Requires:       rocm-lld%{llvm_maj_ver}-libs = %{version}-%{release}
Provides:       rocm-lld = %{rocm_version}
Provides:       rocm-release(lld) = %{rocm_release}
Requires(post): update-alternatives
Requires(postun): update-alternatives

%description -n rocm-lld%{llvm_maj_ver}
LLD is a linker from the LLVM project.

%package     -n rocm-lld%{llvm_maj_ver}-devel
Summary:        Linker for Clang/LLVM
Group:          Development/Tools/Building
URL:            https://lld.llvm.org/
Requires:       %{name}%{llvm_maj_ver}-devel = %{version}-%{release}
Requires:       rocm-lld%{llvm_maj_ver} = %{version}-%{release}
Provides:       rocm-lld-devel = %{rocm_version}
Provides:       rocm-release(lld-devel) = %{rocm_release}
Provides:       cmake(LLD-ROCm) = %{rocm_release}
Conflicts:      cmake(LLD-ROCm) < %{rocm_release}

%description -n rocm-lld%{llvm_maj_ver}-devel
LLD is a linker from the LLVM project.
(development files).

%package     -n rocm-lld%{llvm_maj_ver}-libs
Summary:        Libraries for ROCM LLD
Group:          Development/Libraries/C and C++
URL:            https://lld.llvm.org/
Provides:       rocm-lld-libs = %{rocm_version}
Provides:       rocm-release(lld-libs) = %{rocm_release}

%description -n rocm-lld%{llvm_maj_ver}-libs
LLD is a linker from the LLVM project.

%package     -n rocm-libomp%{llvm_maj_ver}-devel
Summary:        MPI plugin for LLVM
Group:          Development/Libraries/C and C++
Provides:       rocm-libomp-devel = %{rocm_version}
Provides:       rocm-release(libomp-devel) = %{rocm_release}
Requires:       rocm-libomp%{llvm_maj_ver}-libs = %{version}-%{release}
Provides:       cmake(libomp-ROCm) = %{rocm_release}
Conflicts:      cmake(libomp-ROCm) < %{rocm_release}

%description -n rocm-libomp%{llvm_maj_ver}-devel
This package contains the OpenMP MPI plugin for LLVM.

%package     -n rocm-libomp%{llvm_maj_ver}-libs
Summary:        Libraries for MPI plugin for LLVM
Group:          Development/Libraries/C and C++
Provides:       rocm-libomp-libs = %{rocm_version}
Provides:       rocm-release(libomp-libs) = %{rocm_release}

%description -n rocm-libomp%{llvm_maj_ver}-libs
This package contains the OpenMP MPI libraries for LLVM.

%package        rpm-macros
Summary:        ROCm LLVM RPM macros
Group:          Development/Tools/Building
BuildArch:      noarch

%description    rpm-macros
This package contains ROCm LLVM compiler related RPM macros.

%package     -n hipcc
Summary:        HIP compiler driver
Group:          Development/Tools/Building
Requires:       rocm-release(amd-device-libs) >= %{rocm_release}
Requires:       rocm-release(llvm) >= %{rocm_release}
Requires:       rocm-release(clang) >= %{rocm_release}
Requires:       rocm-release(lld) >= %{rocm_release}

%description -n hipcc
hipcc is a compiler driver utility that will call clang or nvcc, depending on
target, and pass the appropriate include and library options for the target
compiler and HIP infrastructure.

hipcc will pass-through options to the target compiler. The tools calling hipcc
must ensure the compiler options are appropriate for the target compiler.

%package     -n rocm-device-libs
Summary:        AMD ROCm LLVM bit code libraries
Group:          Development/Libraries/C and C++
Requires:       rocm-clang(major) = %{llvm_maj_ver}
Provides:       rocm-release(amd-device-libs) = %{rocm_release}
Provides:       cmake(AMD-device-libs-ROCm) = %{rocm_release}
Conflicts:      cmake(AMD-device-libs-ROCm)

%description -n rocm-device-libs
This package contains a set of AMD specific device-side language runtime
libraries in the form of bit code. Specifically:
 - Open Compute library controls
 - Open Compute Math library
 - Open Compute Kernel library
 - OpenCL built-in library
 - HIP built-in library
 - Heterogeneous Compute built-in library

%package     -n %{comgr_libname}
Summary:        AMD ROCm LLVM Code Object Manager
Group:          Development/Libraries/C and C++
Provides:       %{comgr_libname}%{?_isa} = %{comgr_version}
Provides:       rocm-release(comgr) = %{rocm_release}

%description -n %{comgr_libname}
The AMD Code Object Manager (Comgr) is a shared library which provides
operations for creating and inspecting code objects.

%package     -n rocm-comgr-devel
Summary:        AMD ROCm LLVM Code Object Manager
Group:          Development/Libraries/C and C++
Requires:       %{comgr_libname} = %{version}-%{release}
Provides:       rocm-release(comgr-devel) = %{rocm_release}
Provides:       cmake(COMgr-ROCm) = %{rocm_release}
Conflicts:      cmake(COMgr-ROCm) < %{rocm_release}

%description -n rocm-comgr-devel
The AMD Code Object Manager (Comgr) development package.

%package     -n %{rocr_libname}
Summary:        ROCm Runtime Library
Group:          Development/Libraries/C and C++
Provides:       %{rocr_libname}%{?_isa} = %{hsa_version}
Provides:       rocm-release(rocm-runtime) = %{rocm_release}

%description -n %{rocr_libname}
This package contain the shared library.

%package     -n rocm-runtime-devel
Summary:        ROCm Runtime development files
Group:          Development/Libraries/C and C++
Requires:       %{rocr_libname} = %{version}-%{release}
Provides:       cmake(rocm-runtime) = %{rocm_release}
Provides:       rocm-release(rocm-runtime-devel) = %{rocm_release}

%description -n rocm-runtime-devel
ROCm Runtime development files.

%prep
%autosetup -N -a 1 -n %{upstreamname}-rocm-%{rocm_version}

# LLVM patches
%autopatch -M 23 -p1

pushd ROCR-Runtime-rocm-%{rocm_version}
%autopatch -m 30 -p1
sed -i -e '/install ( FILES ${CMAKE_CURRENT_SOURCE_DIR}\/LICENSE\.md/d' src/CMakeLists.txt
popd

# ##Fix issue with HIP, where compilation flags are incorrect, see issue:
# #https://github.com/RadeonOpenCompute/ROCm-CompilerSupport/issues/49
# #Remove redundant includes:
# sed -i 'N;/Args.push_back(HIPIncludePath/!P;D' amd/comgr/src/comgr-compiler.cpp
# sed -i 'N;/Args.push_back(ROCMIncludePath/!P;D' amd/comgr/src/comgr-compiler.cpp

# # Use rocm executables
# sed -i 's/clang"/clang-rocm"/' amd/comgr/src/comgr-compiler.cpp
# sed -i 's/lld"/lld-rocm"/' amd/comgr/src/comgr-compiler.cpp

sed -i 's/find_package(Clang REQUIRED CONFIG)/find_package(Clang REQUIRED)/' amd/comgr/CMakeLists.txt
sed -i 's/find_package(LLD REQUIRED CONFIG)/find_package(LLD REQUIRED)/' amd/comgr/CMakeLists.txt

# Tests known to fail with upstream LLVM (as opposed to the bundled llvm):
sed -i -e "/add_isa_test(fract/d" \
       -e "/add_isa_test(frexp/d" \
       amd/device-libs/test/compile/CMakeLists.txt
# This test fails
sed -i -e "/add_comgr_test(name_expression_map_test/d" \
        amd/comgr/test/CMakeLists.txt

%build
# llvm_maj_ver sanity check (we should be matching the bundled llvm major ver):
if ! grep -q "set(LLVM_VERSION_MAJOR %{llvm_maj_ver})" llvm/CMakeLists.txt; then
        echo "ERROR llvm_maj_ver macro is not correctly set"
        exit 1
fi

ROCM_LLVM_PKG_BUILD_DIR=$PWD

mkdir $PWD/rocmllvm-bin
export PATH="$PWD/rocmllvm-bin:$PATH"

# enable sccache during build if available
if command -v ccache > /dev/null; then
  export CMAKE_CXX_COMPILER_LAUNCHER=ccache
  export CMAKE_C_COMPILER_LAUNCHER=ccache
fi

%{print_info}

%set_jobs link %{mem_per_link_job}
%set_jobs compile %{mem_per_compile_job}

%define __builder ninja
%define __sourcedir llvm
%define __builddir build-llvm

%cmake %{cmake_llvm_opts}
%cmake_build
%cmake_build FileCheck
%cmake_build split-file
%cmake_build not

%define _llvm_build_dir $ROCM_LLVM_PKG_BUILD_DIR/build-llvm
%define _rocmllv_bin $ROCM_LLVM_PKG_BUILD_DIR/rocmllvm-bin

#ln -s %{_llvm_build_dir}/bin/lld %{_rocmllv_bin}/lld-rocm
#ln -s %{_llvm_build_dir}/bin/ld.lld %{_rocmllv_bin}/ld.lld-rocm

#ln -s %{_llvm_build_dir}/bin/llvm-ar %{_rocmllv_bin}/llvm-ar-rocm
#ln -s %{_llvm_build_dir}/bin/llvm-mc %{_rocmllv_bin}/llvm-mc-rocm
#ln -s %{_llvm_build_dir}/bin/llvm-link %{_rocmllv_bin}/llvm-link-rocm
ln -s %{_llvm_build_dir}/bin/llvm-objcopy %{_rocmllv_bin}/llvm-objcopy-rocm

#ln -s %{_llvm_build_dir}/bin/clang-offload-bundler %{_rocmllv_bin}/clang-offload-bundler-rocm

ln -s %{_llvm_build_dir}/bin/FileCheck %{_rocmllv_bin}/FileCheck
ln -s %{_llvm_build_dir}/bin/split-file %{_rocmllv_bin}/split-file
ln -s %{_llvm_build_dir}/bin/not %{_rocmllv_bin}/not

# Build amdgcn
cd "$ROCM_LLVM_PKG_BUILD_DIR"

%define __sourcedir amd/device-libs
%define __builddir build-device-libs

%global clang_prefix %{_lib}/clang/%{llvm_maj_ver}
%global amdgcn_dir %{clang_prefix}/amdgcn

# Fix up the location AMD_DEVICE_LIBS_PREFIX
sed -i 's|@AMD_DEVICE_LIBS_PREFIX_CODE@|set(AMD_DEVICE_LIBS_PREFIX "%{_llvm_prefix}/%{clang_prefix}")|' amd/device-libs/AMDDeviceLibsConfig.cmake.in

%cmake %{cmake_use_rocmllvm_opts} \
       -DROCM_DEVICE_LIBS_BITCODE_INSTALL_LOC_NEW="%amdgcn_dir" \
       -DROCM_DEVICE_LIBS_BITCODE_INSTALL_LOC_OLD="" \
       -DCMAKE_BUILD_TYPE="RELEASE" \
       -DCMAKE_INSTALL_PREFIX=%{_llvm_prefix}
%cmake_build

cp -r %{clang_prefix}/* %{_llvm_build_dir}/%{clang_prefix}/
cp -r %{_lib}/cmake/* %{_llvm_build_dir}/%{_lib}/cmake/

ln -s %amdgcn_dir amdgcn

cd %{_llvm_build_dir}
ln -s %amdgcn_dir amdgcn

export ROCM_PATH=%{_llvm_build_dir}

# Build HSA runtime
cd "$ROCM_LLVM_PKG_BUILD_DIR"

%define __sourcedir ROCR-Runtime-rocm-%{rocm_version}/src
%define __builddir build-rocr

%cmake %{cmake_use_rocmllvm_opts} \
       -DCMAKE_PREFIX_PATH=%{_llvm_build_dir} \
       -DCMAKE_INSTALL_LIBDIR=%{_lib} \
%ifnarch x86_64
       -DIMAGE_SUPPORT=OFF \
%endif
       -DINCLUDE_PATH_COMPATIBILITY=OFF
%cmake_build

ln -s $ROCM_LLVM_PKG_BUILD_DIR/ROCR-Runtime-rocm-%{rocm_version}/src/inc inc

%define _rocr_build_dir $ROCM_LLVM_PKG_BUILD_DIR/build-rocr

# Build libomp
cd "$ROCM_LLVM_PKG_BUILD_DIR"

%define __sourcedir openmp
%define __builddir build-openmp

%cmake %{cmake_use_rocmllvm_opts} \
       -DCMAKE_PREFIX_PATH=%{_llvm_build_dir} \
       -DCMAKE_INSTALL_PREFIX=%{_llvm_prefix} \
       -DBUILD_SHARED_LIBS=OFF \
%if "%{_lib}" == "lib64"
       -DOPENMP_LIBDIR_SUFFIX=64 \
%endif
       -DOPENMP_LLVM_TOOLS_DIR=%{_llvm_build_dir}/bin \
       -DCMAKE_INSTALL_INCLUDEDIR=%{_llvm_prefix}/%{clang_prefix}/include \
       -DLIBOMPTARGET_EXTERNAL_PROJECT_HSA_PATH=%{_rocr_build_dir} \
       -DLIBOMP_OMPD_GDB_SUPPORT=OFF \
       -DLIBOMPTARGET_BUILD_CUDA_PLUGIN=OFF \
       -DLIBOMPTARGET_BUILD_DEVICERTL_BCLIB=ON \
       -DLIBOMPTARGET_NVPTX_ENABLE_BCLIB=OFF \
       -DLIBOMP_INSTALL_ALIASES=OFF \
       -DLIBOMP_ARCHER_SUPPORT=OFF
%cmake_build

# Build comgr
cd "$ROCM_LLVM_PKG_BUILD_DIR"

sed -i "s@\${CLANG_CMAKE_DIR}/../../../@%{_llvm_build_dir}/%{_lib}/clang/%{llvm_maj_ver}/@" amd/comgr/cmake/opencl_pch.cmake

%define __sourcedir amd/comgr
%define __builddir build-comgr

%cmake %{cmake_use_rocmllvm_opts} \
       -DCMAKE_PREFIX_PATH=%{_llvm_build_dir} \
       -DLLVM_LINK_LLVM_DYLIB=ON \
       -DBUILD_TESTING=ON
%cmake_build

# Build hipcc
cd "$ROCM_LLVM_PKG_BUILD_DIR"

%define __sourcedir amd/hipcc
%define __builddir build-hipcc

%cmake -DCMAKE_BUILD_TYPE=%build_type \
       -DCMAKE_CXX_COMPILER=%{_bindir}/clang++ \
       -DCMAKE_SKIP_INSTALL_RPATH=ON \
       -DCMAKE_INSTALL_DO_STRIP=ON \
       -DHIPCC_BACKWARD_COMPATIBILITY=OFF
%cmake_build

%check
# LLVM test suite is written in python and has troubles with encoding if
# python 3 is used because it is written with assumption that python will
# default to UTF-8 encoding. However, it only does if the current locale is
# UTF-8.
export LANG=C.UTF-8

export PATH="$PWD/rocmllvm-bin:$PATH"
export ROCM_PATH=$PWD/build-llvm

%define __sourcedir llvm
%define __builddir build-llvm
unset ROCM_PATH
rm -rf %__builddir/%amdgcn_dir %__builddir/amdgcn
rm -rf llvm/test/tools/llvm-exegesis/
%__cmake --build %__builddir --target check-llvm{,-unit} check-clang{,-unit} check-lld check-compiler-rt

%define __sourcedir amd/device-libs
%define __builddir build-device-libs
%ctest

%define __sourcedir amd/comgr
%define __builddir build-comgr
%ctest

%install

%define __builddir build-llvm
%cmake_install

%define __builddir build-openmp
%cmake_install

%define __builddir build-device-libs
%cmake_install

%define __builddir build-comgr
%cmake_install

%define __builddir build-hipcc
%cmake_install

%define __builddir build-rocr
%cmake_install

# install FileCheck
install -m 0755 build-llvm/bin/FileCheck %{buildroot}%{_llvm_prefix}bin/FileCheck

rm -rf %{buildroot}%{_llvm_prefix}share/opt-viewer
rm %{buildroot}%{_llvm_prefix}bin/git-clang-format
rm %{buildroot}%{_llvm_prefix}bin/hmaptool
rm %{buildroot}%{_llvm_prefix}/share/clang/*.applescript
rm %{buildroot}%{_llvm_prefix}/share/clang/clang-format-sublime.py

# Don't use env in shebangs, and prefer python3.X. (https://www.python.org/dev/peps/pep-0394/#for-python-runtime-distributors)
sed -i -E "1s|/usr/bin/env *|/usr/bin/|; 1s|/usr/bin/python3?\$|$(realpath /usr/bin/python3)|" \
        %{buildroot}%{_llvm_prefix}/share/clang/*.py

# Macro definitions for update alternatives
%global ua_bin_suffix rocm
%global rocm_uaver %{llvm_maj_ver}%{rocm_major}%{rocm_minor}%{rocm_patch}
%global ua_install() %{_sbindir}/update-alternatives \\\
    --install %{_bindir}/%1-%ua_bin_suffix %1-%ua_bin_suffix %{_llvm_prefix}bin/%1-%llvm_maj_ver %{rocm_uaver}
%global ua_bin_slave() \\\
    --slave %{_bindir}/%1-%ua_bin_suffix %1-%ua_bin_suffix %{_llvm_prefix}bin/%1-%llvm_maj_ver
%global ua_remove() \
if [ ! -f %{_llvm_prefix}bin/%1-%llvm_maj_ver ] ; then \
    %{_sbindir}/update-alternatives --remove %1-%ua_bin_suffix %{_llvm_prefix}bin/%1-%llvm_maj_ver \
fi

# move bash completions
sed -i -E 's/_clang/_clang_%ua_bin_suffix/g; s/(complete -F _clang_%ua_bin_suffix).*/\1 clang-%ua_bin_suffix/' %{buildroot}%{_llvm_prefix}share/clang/bash-autocomplete.sh
mkdir -p %{buildroot}%{_datadir}/bash-completion/completions
mv %{buildroot}%{_llvm_prefix}share/clang/bash-autocomplete.sh %{buildroot}%{_datadir}/bash-completion/completions/clang-%ua_bin_suffix

# Fix the clang -> clang-X symlink to work with update-alternatives
mv %{buildroot}%{_llvm_prefix}bin/clang-%{llvm_maj_ver} %{buildroot}%{_llvm_prefix}bin/clang

# Prepare for update-alternatives usage
mkdir -p %{buildroot}%{_sysconfdir}/alternatives
mkdir -p %{buildroot}%{_bindir}

# Rewrite symlinks to point to new location
for p in %{shrink:%binfiles} ; do
    if [ -h "%{buildroot}%{_llvm_prefix}bin/$p" ] ; then
        ln -f -s %{_llvm_prefix}bin/$(readlink %{buildroot}%{_llvm_prefix}bin/$p)-%llvm_maj_ver %{buildroot}%{_llvm_prefix}bin/$p
    fi
done
for p in %{shrink:%binfiles} ; do
    mv %{buildroot}%{_llvm_prefix}/bin/$p %{buildroot}%{_llvm_prefix}/bin/$p-%llvm_maj_ver
    ln -s -f %{_llvm_prefix}/bin/$p-%llvm_maj_ver %{buildroot}%{_sysconfdir}/alternatives/$p-%ua_bin_suffix
    ln -s -f %{_llvm_prefix}/bin/$p-%llvm_maj_ver %{buildroot}%{_bindir}/$p-%ua_bin_suffix
done

# Also rewrite the CMake files referring to the binaries.
sed -i "$(
    for p in %{shrink:%binfiles}; do
        echo "s|\"\${_IMPORT_PREFIX}/bin/$p\"|\"\${_IMPORT_PREFIX}/bin/$p-%{llvm_maj_ver}\"|g"
    done
)" %{buildroot}%{_llvm_prefix}%{_lib}/cmake/{llvm/LLVMExports,clang/ClangTargets,lld/LLDTargets}-%{build_type}.cmake

# Standardize libomp name
mv %{buildroot}%{_llvm_prefix}%{_lib}/libomp.so %{buildroot}%{_llvm_prefix}%{_lib}/libomp.so.%{llvm_maj_ver}%{llvm_dylib_suffix}
ln -s libomp.so.%{llvm_maj_ver}%{llvm_dylib_suffix} %{buildroot}%{_llvm_prefix}%{_lib}/libomp.so

# Move LLVM lib binaries to standard lib directory
for linkname in %{buildroot}%{_llvm_prefix}%{_lib}/*.so*; do
  if [ -L "$linkname" ]; then
     linkpath=$(readlink -- "$linkname")
     [ "${linkpath:0:1}" == "/" ] && continue # skip if link paths is an absolute path
     abslinkpath=%{buildroot}%{_llvm_prefix}%{_lib}/"$linkpath"
     [ -L "$abslinkpath" ] && continue
     newpath=%{_libdir}/"$linkpath"
     absnewpath=%{buildroot}"$newpath"
     [ -e "$absnewpath" ] && exit 1
     mv "$abslinkpath" "$absnewpath"
     ln -s "$newpath" "$abslinkpath"
  fi
done

# Generate RPM macros for ROCm LLVM
cat <<"EOF" > macros.rocm-llvm
%%rocmllvm_prefix %{_llvm_prefix}
%%rocmllvm_major %llvm_maj_ver
%%rocmllvm_version %llvm_version
%%rocmllvm_dylib_suffix %llvm_dylib_suffix
%%rocmllvm_clang_prefix %{_llvm_prefix}%{_lib}/clang/%{llvm_maj_ver}
%%rocmllvm_cmake_prefix %{_llvm_prefix}%{_lib}/cmake
%%rocmllvm_bin_suffix %ua_bin_suffix
%%rocmllvm_rocm_version %rocm_version
%%rocmllvm_cmake_opts \\\
    -DCMAKE_CXX_COMPILER=%{_bindir}/clang++-%ua_bin_suffix \\\
    -DCMAKE_C_COMPILER=%{_bindir}/clang-%ua_bin_suffix \\\
    -DCMAKE_LINKER=%{_bindir}/ld.lld-%ua_bin_suffix \\\
    -DCMAKE_AR=%{_bindir}/llvm-ar-%ua_bin_suffix \\\
    -DCMAKE_RANLIB=%{_bindir}/llvm-ranlib-%ua_bin_suffix \\\
    -DCMAKE_SKIP_INSTALL_RPATH=ON \\\
    -DLLVM_ROOT=%{_llvm_prefix} \\\
    -DClang_DIR=%{_llvm_prefix}/%{_lib}/cmake/clang \\\
    -DLLD_DIR=%{_llvm_prefix}/%{_lib}/cmake/lld
EOF

# install RPM macros
install -Dpm 0644 macros.rocm-llvm %{buildroot}%{_rpmmacrodir}/macros.rocm-llvm

%fdupes -s %{buildroot}%{_llvm_prefix}include

%post -n %{name}%{llvm_maj_ver}
%{ua_install %llvm_ua_anchor} \
    %{lapply -p ua_bin_slave %llvm_tools} \
    %{lapply -p ua_bin_slave %llvm_elf_dwarf_tools} \
    %{lapply -p ua_bin_slave %llvm_abi_coff_macho_tools} \
    %{lapply -p ua_bin_slave %llvm_instr_devel_tools} \
    %{lapply -p ua_bin_slave %llvm_offload_arch_tools}
%end
%postun -n %{name}%{llvm_maj_ver}
%{ua_remove %llvm_ua_anchor}
%end

%ldconfig_scriptlets -n %{name}%{llvm_maj_ver}-libs
%ldconfig_scriptlets -n %{name}%{llvm_maj_ver}-devel

%post -n rocm-clang%{llvm_maj_ver}
%{ua_install %clang_ua_anchor} \
    %{lapply -p ua_bin_slave %clang_binfiles}
%end
%postun -n rocm-clang%{llvm_maj_ver}
%{ua_remove %clang_ua_anchor}
%end

%ldconfig_scriptlets -n rocm-clang%{llvm_maj_ver}-libs
%ldconfig_scriptlets -n rocm-clang%{llvm_maj_ver}-devel

%post -n rocm-lld%{llvm_maj_ver}
%{ua_install %lld_ua_anchor} \
    %{lapply -p ua_bin_slave %lld_binfiles}
%end
%postun -n rocm-lld%{llvm_maj_ver}
%{ua_remove %lld_ua_anchor}
%end

%ldconfig_scriptlets -n rocm-lld%{llvm_maj_ver}-libs
%ldconfig_scriptlets -n rocm-lld%{llvm_maj_ver}-devel
%ldconfig_scriptlets -n rocm-libomp%{llvm_maj_ver}-libs
%ldconfig_scriptlets -n rocm-libomp%{llvm_maj_ver}-devel
%ldconfig_scriptlets -n %{comgr_libname}
%ldconfig_scriptlets -n %{rocr_libname}


# Macro definitions for files lists
%global ghost_ua_bin_path() \
%ghost %{_bindir}/%1-%ua_bin_suffix
%global llvm_bin_path() \
%{_llvm_prefix}/bin/%1-%llvm_maj_ver
%global ghost_ua_bin_link() \
%ghost %{_sysconfdir}/alternatives/%1-%ua_bin_suffix

%files -n %{name}%{llvm_maj_ver}
%license llvm/LICENSE.TXT
%dir %{_llvm_prefix}
%dir %{_llvm_prefix}bin
%dir %{_llvm_prefix}%{_lib}
%dir %{_llvm_prefix}share
%{lapply -p ghost_ua_bin_path %llvm_ua_anchor %llvm_tools}
%{lapply -p ghost_ua_bin_path %llvm_elf_dwarf_tools}
%{lapply -p ghost_ua_bin_path %llvm_abi_coff_macho_tools}
%{lapply -p ghost_ua_bin_path %llvm_instr_devel_tools}
%{lapply -p ghost_ua_bin_path %llvm_offload_arch_tools}
%{lapply -p llvm_bin_path %llvm_ua_anchor %llvm_tools}
%{lapply -p llvm_bin_path %llvm_elf_dwarf_tools}
%{lapply -p llvm_bin_path %llvm_abi_coff_macho_tools}
%{lapply -p llvm_bin_path %llvm_instr_devel_tools}
%{lapply -p llvm_bin_path %llvm_offload_arch_tools}
%{lapply -p ghost_ua_bin_link %llvm_ua_anchor %llvm_tools}
%{lapply -p ghost_ua_bin_link %llvm_elf_dwarf_tools}
%{lapply -p ghost_ua_bin_link %llvm_abi_coff_macho_tools}
%{lapply -p ghost_ua_bin_link %llvm_instr_devel_tools}
%{lapply -p ghost_ua_bin_link %llvm_offload_arch_tools}

%files -n %{name}%{llvm_maj_ver}-libs
%license llvm/LICENSE.TXT
%{_libdir}/libLLVM.so.%{llvm_maj_ver}%{llvm_dylib_suffix}
%{_libdir}/libLTO.so.%{llvm_maj_ver}%{llvm_dylib_suffix}
%{_libdir}/libRemarks.so.%{llvm_maj_ver}%{llvm_dylib_suffix}

%files -n %{name}%{llvm_maj_ver}-devel
%license llvm/LICENSE.TXT
%dir %{_llvm_prefix}include
%dir %{_llvm_prefix}include/llvm
%dir %{_llvm_prefix}include/llvm-c
%dir %{_llvm_prefix}%{_lib}/cmake
%dir %{_llvm_prefix}%{_lib}/cmake/llvm
%{_llvm_prefix}bin/llvm-config
%{_llvm_prefix}bin/FileCheck
%{_llvm_prefix}include/llvm/*
%{_llvm_prefix}include/llvm-c/*
%{_llvm_prefix}%{_lib}/cmake/llvm/*
%{_llvm_prefix}%{_lib}/libLLVM.so
%{_llvm_prefix}%{_lib}/libLTO.so
%{_llvm_prefix}%{_lib}/libRemarks.so
%{_llvm_prefix}%{_lib}/LLVMgold.so
# symlinks to libdir
%{_llvm_prefix}%{_lib}/libLLVM.so.%{llvm_maj_ver}%{llvm_dylib_suffix}
%{_llvm_prefix}%{_lib}/libLTO.so.%{llvm_maj_ver}%{llvm_dylib_suffix}
%{_llvm_prefix}%{_lib}/libRemarks.so.%{llvm_maj_ver}%{llvm_dylib_suffix}

%files rpm-macros
%{_rpmmacrodir}/macros.rocm-llvm

%files -n rocm-clang%{llvm_maj_ver}
%license llvm/LICENSE.TXT
%{lapply -p ghost_ua_bin_path %clang_ua_anchor %clang_binfiles}
%{lapply -p llvm_bin_path %clang_ua_anchor %clang_binfiles}
%{lapply -p ghost_ua_bin_link %clang_ua_anchor %clang_binfiles}
%dir %{_llvm_prefix}%{_lib}/clang
%dir %{_llvm_prefix}%{_lib}/clang/%{llvm_maj_ver}
%dir %{_llvm_prefix}%{_lib}/clang/%{llvm_maj_ver}/include
%dir %{_llvm_prefix}%{_lib}/clang/%{llvm_maj_ver}/lib
%dir %{_llvm_prefix}%{_lib}/clang/%{llvm_maj_ver}/lib/linux
%dir %{_llvm_prefix}share/clang
%{_llvm_prefix}%{_lib}/clang/%{llvm_maj_ver}/include/*
%{_llvm_prefix}share/clang/*
%{_datadir}/bash-completion/completions/clang-%ua_bin_suffix
%{_llvm_prefix}%{_lib}/clang/%{llvm_maj_ver}/lib/linux/clang_rt.*.o
%{_llvm_prefix}%{_lib}/clang/%{llvm_maj_ver}/lib/linux/libclang_rt.*.a
%{_llvm_prefix}%{_lib}/clang/%{llvm_maj_ver}/lib/linux/liborc_rt-*.a

%files -n rocm-clang%{llvm_maj_ver}-libs
%{_libdir}/libclang.so.%{llvm_maj_ver}.0.0%{llvm_dylib_suffix}
%{_libdir}/libclang-cpp.so.%{llvm_maj_ver}%{llvm_dylib_suffix}

%files -n rocm-clang%{llvm_maj_ver}-devel
%license llvm/LICENSE.TXT
%dir %{_llvm_prefix}include/clang
%dir %{_llvm_prefix}include/clang-c
%dir %{_llvm_prefix}%{_lib}/cmake/clang
%{_llvm_prefix}include/clang/*
%{_llvm_prefix}include/clang-c/*
%{_llvm_prefix}%{_lib}/cmake/clang/*
%{_llvm_prefix}%{_lib}/libclang.so
%{_llvm_prefix}%{_lib}/libclang-cpp.so
%{_llvm_prefix}%{_lib}/libclang.so.%{llvm_maj_ver}%{llvm_dylib_suffix}
# symlinks to libdir
%{_llvm_prefix}%{_lib}/libclang.so.%{llvm_maj_ver}.0.0%{llvm_dylib_suffix}
%{_llvm_prefix}%{_lib}/libclang-cpp.so.%{llvm_maj_ver}%{llvm_dylib_suffix}

%files -n rocm-lld%{llvm_maj_ver}
%license llvm/LICENSE.TXT
%{lapply -p ghost_ua_bin_path %lld_ua_anchor %lld_binfiles}
%{lapply -p llvm_bin_path %lld_ua_anchor %lld_binfiles}
%{lapply -p ghost_ua_bin_link %lld_ua_anchor %lld_binfiles}

%files -n rocm-lld%{llvm_maj_ver}-devel
%license llvm/LICENSE.TXT
%dir %{_llvm_prefix}include/lld
%dir %{_llvm_prefix}%{_lib}/cmake/lld
%{_llvm_prefix}include/lld/*
%{_llvm_prefix}%{_lib}/cmake/lld/*
%{_llvm_prefix}%{_lib}/liblld*.so
# symlinks to libdir
%{_llvm_prefix}%{_lib}/liblld*.so.%{llvm_maj_ver}%{llvm_dylib_suffix}

%files -n rocm-lld%{llvm_maj_ver}-libs
%license llvm/LICENSE.TXT
%{_libdir}/liblld*.so.%{llvm_maj_ver}%{llvm_dylib_suffix}

%files -n rocm-libomp%{llvm_maj_ver}-devel
%license openmp/LICENSE.TXT
%dir %{_llvm_prefix}%{_lib}/libdevice
%dir %{_llvm_prefix}%{_lib}/omptest
%dir %{_llvm_prefix}%{_lib}/omptest/include
%{_llvm_prefix}%{_lib}/cmake/openmp
%{_llvm_prefix}%{_lib}/cmake/omptest
%{_llvm_prefix}%{_lib}/omptest/include
%{_llvm_prefix}%{_lib}/libomp.so
%{_llvm_prefix}%{_lib}/libomptest.so
# symlink
%{_llvm_prefix}%{_lib}/libomp.so.%{llvm_maj_ver}%{llvm_dylib_suffix}
%{_llvm_prefix}%{_lib}/libomptest.so.%{llvm_maj_ver}%{llvm_dylib_suffix}
%ifnarch %{ix86}
#%%{_llvm_prefix}bin/llvm-omp-device-info
#%%{_llvm_prefix}bin/llvm-omp-kernel-replay
%{_llvm_prefix}%{_lib}/libomptarget.so
# symlink
%{_llvm_prefix}%{_lib}/libomptarget.so.%{llvm_maj_ver}%{llvm_dylib_suffix}
%{_llvm_prefix}%{_lib}/libomptarget-amdgpu-*.bc
%ifarch aarch64 ppc64le x86_64
%{_llvm_prefix}%{_lib}/libdevice/libhostexec-*.bc
%{_llvm_prefix}%{_lib}/libomptarget.devicertl.a
%{_llvm_prefix}%{_lib}/disable_dynamic_devmem.ll
%{_llvm_prefix}%{_lib}/libomptarget.rtl.{%{openmp_cpu},amdgpu}.so
# symlink
%{_llvm_prefix}%{_lib}/libomptarget.rtl.{%{openmp_cpu},amdgpu}.so.%{llvm_maj_ver}%{llvm_dylib_suffix}
%endif
%endif

%files -n rocm-libomp%{llvm_maj_ver}-libs
%license openmp/LICENSE.TXT
%{_libdir}/libomp.so.%{llvm_maj_ver}%{llvm_dylib_suffix}
%{_libdir}/libomptest.so.%{llvm_maj_ver}%{llvm_dylib_suffix}
%ifnarch %{ix86}
%{_libdir}/libomptarget.so.%{llvm_maj_ver}%{llvm_dylib_suffix}
%ifarch aarch64 ppc64le x86_64
%{_libdir}/libomptarget.rtl.{%{openmp_cpu},amdgpu}.so.%{llvm_maj_ver}%{llvm_dylib_suffix}
%endif
%endif

%files -n hipcc
%license amd/hipcc/LICENSE.txt
%doc amd/hipcc/README.md
%{_bindir}/hipcc
%{_bindir}/hipconfig

%files -n rocm-device-libs
%license amd/device-libs/LICENSE.TXT
%doc amd/device-libs/README.md amd/device-libs/doc/*.md
%dir %{_llvm_prefix}/%{_lib}/cmake/AMDDeviceLibs
%dir %{_llvm_prefix}/%amdgcn_dir
%{_llvm_prefix}/%{_lib}/cmake/AMDDeviceLibs/*
%{_llvm_prefix}/%amdgcn_dir/*

%files -n %{comgr_libname}
%license amd/comgr/LICENSE.txt amd/comgr/NOTICES.txt
%doc amd/comgr/README.md
%{_libdir}/libamd_comgr.so.%{comgr_version}
%{_libdir}/libamd_comgr.so.%{comgr_major}

%files -n rocm-comgr-devel
%dir %{_includedir}/amd_comgr
%dir %{_libdir}/cmake/amd_comgr
%{_includedir}/amd_comgr/amd_comgr.h
%{_libdir}/libamd_comgr.so
%{_libdir}/cmake/amd_comgr/*

%files -n %{rocr_libname}
%license ROCR-Runtime-rocm-%{rocm_version}/LICENSE.txt
%doc ROCR-Runtime-rocm-%{rocm_version}/README.md
%{_libdir}/libhsa-runtime64.so.%{hsa_version}
%{_libdir}/libhsa-runtime64.so.%{hsa_major}

%files -n rocm-runtime-devel
%{_includedir}/hsa/
%{_libdir}/libhsa-runtime64.so
%{_libdir}/cmake/hsa-runtime64/

%changelog
openSUSE Build Service is sponsored by