name       : llvm
version    : 19.1.6
release    : 130
source     :
    - https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.6/llvm-project-19.1.6.src.tar.xz : e3f79317adaa9196d2cfffe1c869d7c100b7540832bc44fe0d3f44a12861fa34
homepage   : http://llvm.org/
license    : Apache-2.0 WITH LLVM-exception
description: |
    The LLVM package contains a collection of modular and reusable compiler and toolchain technologies. The Low Level Virtual Machine (LLVM) Core libraries provide a modern source and target-independent optimizer, along with code generation support for many popular CPUs (as well as some less common ones!). These libraries are built around a well specified code representation known as the LLVM intermediate representation ("LLVM IR").
summary    :
    - libs : LLVM shared libraries
    - 32bit-libs : 32bit LLVM shared libraries
    - Low Level Virtual Machine (Reusable compiler and toolchains)
    - devel : Libraries and header files for LLVM
    - ^clang-libs : Clang shared libraries
    - ^clang-32bit-libs : 32bit Clang shared libraries
    - ^clang : Clang Compiler frontend to LLVM
    - ^clang-devel : Libraries and header files for clang
    - ^clang-32bit-devel : Libraries and header files for 32bit clang
    - ^libcxx : C++ standard library targeting C++11
    - ^libcxx-32bit : 32bit libraries for libcxx
    - ^libcxx-devel : Libraries and header files for libcxx
    - ^libcxx-32bit-devel : Libraries and header files for 32bit libcxx
    - ^libomp : OpenMP runtime for clang
    - ^libomp-devel : Libraries and header files for libomp
    - ^lld-libs : LLD Shared libraries
    - ^lld : The LLVM Linker
    - ^lld-devel : Libraries and header files for LLD
    - ^mlir : Multi-Level Intermediate Representation Overview
    - ^mlir-devel : Libraries and header files for MLIR
    - ^polly : Polyhedral optimizations for LLVM
    - ^polly-devel : Libraries and header files for Polly
    - clang : Temporary package for clang rename
    - clang-32bit : Temporary package for clang rename
    - clang-devel : Temporary package for clang rename
    - clang-32bit-devel : Temporary package for clang rename
component  :
    - libs : programming.library
    - 32bit-libs : emul32
    - programming
    - devel : programming.devel
    - ^clang-libs : programming.library
    - ^clang : programming
    - ^clang-32bit : emul32
    - ^clang-devel : programming.devel
    - ^clang-32bit-devel : programming.devel
    - ^libcxx : programming.library
    - ^libcxx-32bit : emul32
    - ^libcxx-devel : programming.devel
    - ^libcxx-32bit-devel : programming.devel
    - ^libomp : programming.library
    - ^libomp-devel : programming.devel
    - ^lld-libs : programming.library
    - ^lld : programming
    - ^lld-devel : programming.devel
    - ^mlir : programming
    - ^mlir-devel : programming.devel
    - ^polly : programming
    - ^polly-devel : programming.devel
    - clang : programming
    - clang-32bit : emul32
    - clang-devel : programming.devel
    - clang-32bit-devel : emul32
debug      : no
emul32     : no
libsplit   : no
clang      : yes
builddeps  :
    - pkgconfig32(libedit)
    - pkgconfig32(libelf)
    - pkgconfig32(libffi)
    - pkgconfig32(libxml-2.0)
    - pkgconfig32(libzstd)
    - pkgconfig32(zlib)
    - pkgconfig(mimalloc)
    - binutils-devel
    - doxygen
    - glibc-32bit-devel
    - libgcc-32bit
    - libstdc++-32bit
    - llvm-bolt
    - python-myst-parser
    - swig
rundeps    :
    - 32bit-libs :
        - llvm-libs
    - devel :
        - libedit-devel
        - mlir
        - polly-devel
        - zstd-devel
    - 32bit-devel :
        - libedit-32bit-devel
        - llvm-devel
        - zstd-32bit-devel
    - ^clang-32bit-libs :
        - clang-libs
    - ^clang :
        - llvm
        - lld
        - polly
        - libcxx-devel
        - libomp-devel
    - ^clang-32bit :
        - clang
        - libcxx-32bit-devel
    - ^clang-devel :
        - clang
        - llvm-devel
    - ^clang-32bit-devel :
        - clang-32bit
        - clang-devel
        - llvm-32bit-devel
    - ^lld-devel :
        - lld
        - llvm-devel
    - ^libcxx-32bit :
        - libcxx
    - ^libcxx-devel :
        - libcxx
    - ^libcxx-32bit-devel :
        - libcxx-32bit
        - libcxx-devel
    - ^libomp-devel :
        - libomp
    - ^mlir-devel :
        - llvm-devel
    - ^polly-devel :
        - polly
    # Temp until revdeps are rebuilt
    - clang :
        - clang
    - clang-32bit :
        - clang-32bit
    - clang-devel :
        - clang-devel
    - clang-32bit-devel :
        - clang-32bit-devel
patterns   :
    # If there's anything in this package the patterns need to be updated
    - ^BAD-PACKAGER-NO-COOKIE-FOR-YOU :
        - /*
    - libs :
        - /usr/lib64/bfd-plugins
        - /usr/lib64/libLLVM.so.*
        - /usr/lib64/libLTO.so.*
        - /usr/lib64/libRemarks.so.*
        - /usr/lib64/LLVMgold.so
    - 32bit-libs :
        - /usr/lib32/libLLVM.so.*
        - /usr/lib32/libLTO.so.*
        - /usr/lib32/libRemarks.so.*
        - /usr/lib32/LLVMgold.so
    - main :
        - /usr/bin/FileCheck
        - /usr/bin/UnicodeNameMappingGenerator
        - /usr/bin/bugpoint
        - /usr/bin/dsymutil
        - /usr/bin/llc
        - /usr/bin/lli
        - /usr/bin/llvm-*
        - /usr/bin/obj2yaml
        - /usr/bin/opt
        - /usr/bin/reduce-chunk-list
        - /usr/bin/sancov
        - /usr/bin/sanstats
        - /usr/bin/split-file
        - /usr/bin/verify-uselistorder
        - /usr/bin/yaml2obj
        - /usr/share/opt-viewer
        - /usr/share/man/man1/FileCheck.1
        - /usr/share/man/man1/bugpoint.1
        - /usr/share/man/man1/dsymutil.1
        - /usr/share/man/man1/llc.1
        - /usr/share/man/man1/lli.1
        - /usr/share/man/man1/llvm-*.1
        - /usr/share/man/man1/opt.1
    - devel :
        - /usr/bin/count
        - /usr/bin/lli-child-target
        - /usr/bin/llvm-config
        - /usr/bin/not
        - /usr/bin/yaml-bench
        - /usr/lib64/libLLVM.so
        - /usr/lib64/libLLVM-*.so
        - /usr/lib64/libLLVM*.a
        - /usr/lib64/libLTO.so
        - /usr/lib64/libRemarks.so
        - /usr/lib64/cmake/llvm
        - /usr/include/llvm*
        - /usr/share/llvm/cmake
        - /usr/share/man/man1/llvm-config.1
    - 32bit-devel :
        - /usr/bin/llvm-config32
        - /usr/lib32/libLLVM.so
        - /usr/lib32/libLLVM-*.so
        - /usr/lib32/libLLVM*.a
        - /usr/lib32/libLTO.so
        - /usr/lib32/libRemarks.so
        - /usr/lib32/cmake/llvm
        - /usr/include/llvm/Config/32
        - /usr/include/llvm/Config/llvm-config-32.h
    - ^clang-libs :
        - /usr/lib64/libclang.so.*
        - /usr/lib64/libclang-cpp.so.*
        - /usr/lib64/clang/*/include
    - ^clang-32bit-libs :
        - /usr/lib32/libclang.so.*
        - /usr/lib32/libclang-cpp.so.*
        - /usr/lib32/clang/*/include
    - ^clang :
        - /usr/bin/amdgpu-arch
        - /usr/bin/analyze-build
        - /usr/bin/c-index-test
        - /usr/bin/*clang*
        - /usr/bin/diagtool
        - /usr/bin/find-all-symbols
        - /usr/bin/hmaptool
        - /usr/bin/intercept-build
        - /usr/bin/modularize
        - /usr/bin/nvptx-arch
        - /usr/bin/pp-trace
        - /usr/bin/scan-*
        - /usr/lib/libear
        - /usr/lib/libscanbuild
        - /usr/lib64/clang/*/bin
        - /usr/lib64/clang/*/lib/x86_64-*
        - /usr/lib64/clang/*/share
        - /usr/lib64/x86_64-*/libomp*.so
        - /usr/libexec
        - /usr/share/clang*
        - /usr/share/scan-*
        - /usr/share/man/man1/*clang*.1
        - /usr/share/man/man1/diagtool.1
        - /usr/share/man/man1/scan-*.1
    - ^clang-32bit :
        - /usr/lib32/libear
        - /usr/lib32/libscanbuild
        - /usr/lib32/clang/*/lib/i386-*
        - /usr/lib32/clang/*/share
        - /usr/include/i686-*
    - ^clang-devel :
        - /usr/bin/clang-tblgen
        - /usr/lib64/libclang*.so
        - /usr/lib64/cmake/clang/
        - /usr/include/clang*
        - /usr/share/man/man1/clang-tblgen.1
    - ^clang-32bit-devel :
        - /usr/lib32/libclang*.so
        - /usr/lib32/cmake/clang
    - ^lld-libs :
        - /usr/lib64/liblld*.so.*
    - ^lld :
        - /usr/bin/*lld*
        - /usr/bin/wasm-ld
        - /usr/share/man/man1/ld.lld.1
    - ^lld-devel :
        - /usr/lib64/liblld*.so
        - /usr/lib64/cmake/lld
        - /usr/include/lld
    - ^libcxx :
        - /usr/lib64/libc++.so.*
        - /usr/lib64/libc++abi.so.*
    - ^libcxx-32bit :
        - /usr/lib32/libc++.so.*
        - /usr/lib32/libc++abi.so.*
    - ^libcxx-devel :
        - /usr/lib64/libc++.a
        - /usr/lib64/libc++.so
        - /usr/lib64/libc++abi.a
        - /usr/lib64/libc++abi.so
        - /usr/lib64/libc++experimental.a
        - /usr/lib64/libc++.modules.json
        - /usr/include/x86_64-*/c++
        - /usr/include/c++
        - /usr/share/libc++
    - ^libcxx-32bit-devel :
        - /usr/lib32/libc++.a
        - /usr/lib32/libc++.so
        - /usr/lib32/libc++abi.a
        - /usr/lib32/libc++abi.so
        - /usr/lib32/libc++experimental.a
        - /usr/lib32/libc++.modules.json
    - ^libomp :
        - /usr/lib64/libarcher.so
        - /usr/lib64/libomp*.so
        - /usr/lib64/libomptarget.so.*
    - ^libomp-devel :
        - /usr/lib64/libomptarget*.a
        - /usr/lib64/libomptarget*.bc
        - /usr/lib64/libomptarget*.so
        - /usr/lib64/cmake/openmp
    - ^mlir :
        - /usr/bin/mlir-*
        - /usr/bin/tblgen-lsp-server
        - /usr/bin/tblgen-to-irdl
        - /usr/lib64/libMLIR*.so.*
        - /usr/lib64/libmlir_*.so.*
        - /usr/share/man/man1/mlir-*.1
        - /usr/share/man/man1/tblgen.1
    - ^mlir-devel :
        - /usr/lib64/libMLIR*.a
        - /usr/lib64/libMLIR*.so
        - /usr/lib64/libmlir_*.so
        - /usr/lib64/cmake/mlir
        - /usr/include/mlir*
    - ^polly :
        - /usr/lib64/LLVMPolly.so
        - /usr/lib64/libPollyISL.so
        - /usr/share/man/man1/polly.1
    - ^polly-devel :
        - /usr/lib64/cmake/polly
        - /usr/lib64/libPolly.a
        - /usr/include/polly
    ## TEMP:
    - clang :
        - /usr/share/tmp/llvm-clang
    - clang-32bit :
        - /usr/share/tmp/llvm-clang-32bit
    - clang-devel :
        - /usr/share/tmp/llvm-clang-devel
    - clang-32bit-devel :
        - /usr/share/tmp/llvm-clang-32bit-devel
replaces   :
    - 32bit-libs : llvm-32bit
#     - clang : clang
#     - clang-devel : clang-devel
environment: |
    # Decontaminate build environment
    unset LDFLAGS
    unset LD_AS_NEEDED
    unset CFLAGS
    unset CXXFLAGS

    # Set to 1 to bootstrap against itself e.g. for major llvm update or flag changes.
    # For point releases or backports this can be set to 0.
    export BOOTSTRAP=0

    ## BUILD STEPS for packager reference
    # Bootstrap build (optional)
    # PGO gen build
    # PGO profiling build
    # PGO use build
    # EMUL32 PGO use build
    # Install emul32 pgo use build
    # Install PGO use build
    # BOLT instrument libclang/libLLVM from PGO use build
    # BOLT profiling build
    # BOLT optimize libclang/libLLVM from PGO use build
    # Install BOLT'd PGO use libs

    export _LLVM_FLAGS_FINAL="-march=x86-64 -mtune=generic -O3 -fstack-protector -fPIC -ffat-lto-objects -pipe -gline-tables-only"
    export CC=clang
    export CXX=clang++

    export LDFLAGS="${LDFLAGS} -Wl,--icf=all -Wl,--as-needed -Wl,-z,pack-relative-relocs -Wl,-z,now"

    # Set flags, projects and targets to build for PGO gen/use builds.
    # We compile just the neccessities during the pgo gen build to speed things up
    if [[ ! -z "${PGO_GEN_BUILD}" ]]; then
        export PGOFLAGS="${_LLVM_FLAGS_FINAL} -fprofile-instr-generate=default-%m.profraw"
        export _PROJECTS="clang;lld;llvm"
        export _RUNTIMES="compiler-rt"
        export _TARGETS="host"
    fi
    if [[ ! -z "${PGO_USE_BUILD}" ]]; then
        PGO_PATH="/home/build/YPKG/root/llvm/pgo/default.profdata"
        export PGOFLAGS="${_LLVM_FLAGS_FINAL} -fprofile-instr-use=$PGO_PATH"
        export _PROJECTS="clang;clang-tools-extra;lld;llvm;mlir;polly"
        export _RUNTIMES="libcxxabi;libcxx;compiler-rt;openmp;offload"
        export _TARGETS="all"
    fi

    # Set common build options here
    export CMAKE_COMMON_OPTIONS="
        -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DCLANG_DEFAULT_LINKER=lld \
        -DCLANG_DEFAULT_OBJCOPY=llvm-objcopy \
        -DCLANG_DEFAULT_PIE_ON_LINUX=ON \
        -DCLANG_LINK_CLANG_DYLIB=ON \
        -DCOMPILER_RT_BUILTINS_ENABLE_PIC=ON \
        -DCOMPILER_RT_USE_LLVM_UNWINDER=OFF \
        -DENABLE_LINKER_BUILD_ID=ON \
        -DLIBCXX_INCLUDE_BENCHMARKS=OFF \
        -DLIBCXXABI_USE_LLVM_UNWINDER=OFF \
        -DLIBOMP_INSTALL_ALIASES=OFF \
        -DLLVM_APPEND_VC_REV=OFF \
        -DLLVM_BINUTILS_INCDIR=/usr/include \
        -DLLVM_BUILD_LLVM_DYLIB=ON \
        -DLLVM_DYLIB_COMPONENTS="all" \
        -DLLVM_ENABLE_ASSERTIONS=OFF \
        -DLLVM_ENABLE_FFI=ON \
        -DLLVM_ENABLE_LTO=Thin \
        -DLLVM_ENABLE_MODULES=OFF \
        -DLLVM_ENABLE_PIC=ON \
        -DLLVM_ENABLE_RTTI=ON \
        -DLLVM_ENABLE_ZLIB=ON \
        -DLLVM_ENABLE_ZSTD=ON \
        -DLLVM_INCLUDE_BENCHMARKS=OFF \
        -DLLVM_INCLUDE_TESTS=OFF \
        -DLLVM_INSTALL_UTILS=ON \
        -DLLVM_LINK_LLVM_DYLIB=ON \
        -DLLVM_USE_PERF=ON \
        -DMLIR_BUILD_MLIR_C_DYLIB=ON \
        -DMLIR_INSTALL_AGGREGATE_OBJECTS=OFF"

    # Used by everything except emul32 build
    export CMAKE_X84_64_OPTIONS="
         -DLIBCXX_INSTALL_LIBRARY_DIR=lib%LIBSUFFIX% \
         -DLIBCXXABI_INSTALL_LIBRARY_DIR=lib%LIBSUFFIX% \
         -DLLVM_DEFAULT_TARGET_TRIPLE=%HOST% \
         -DLLVM_ENABLE_MIMALLOC=ON \
         -DLLVM_TARGET_ARCH=x86_64 \
         -DLLVM_LIBDIR_SUFFIX=%LIBSUFFIX% \
         -DOFFLOAD_INSTALL_LIBDIR=/usr/lib64 \
         -DOPENMP_INSTALL_LIBDIR=/usr/lib64"

    # Use the PGO Gen/Use Compiler
    export CMAKE_USE_COMPILER="
        -DCMAKE_AR=$workdir/solusBuildDir/bin/llvm-ar \
        -DCMAKE_NM=$workdir/solusBuildDir/bin/llvm-nm \
        -DCMAKE_RANLIB=$workdir/solusBuildDir/bin/llvm-ranlib \
        -DCMAKE_C_COMPILER=$workdir/solusBuildDir/bin/clang \
        -DCMAKE_CXX_COMPILER=$workdir/solusBuildDir/bin/clang++ \
        -DLLVM_CCACHE_BUILD=ON"

    # Optionally use the bootstrapped compiler
    if [[ ${BOOTSTRAP} == "1" ]]; then
        echo "SETTING UP BOOTSTRAP PREPROCESSOR ARGS"

        export PATH="$PKG_BUILD_DIR/../bootstrap/bin:${PATH}"
        export CMAKE_COMMON_OPTIONS="${CMAKE_COMMON_OPTIONS} \
            -DCMAKE_AR=$PKG_BUILD_DIR/../bootstrap/bin/llvm-ar \
            -DCMAKE_NM=$PKG_BUILD_DIR/../bootstrap/bin/llvm-nm \
            -DCMAKE_RANLIB=$PKG_BUILD_DIR/../bootstrap/bin/llvm-ranlib \
            -DCMAKE_C_COMPILER=$PKG_BUILD_DIR/../bootstrap/bin/clang \
            -DCMAKE_CXX_COMPILER=$PKG_BUILD_DIR/../bootstrap/bin/clang++ \
            -DCLANG_TABLEGEN=$PKG_BUILD_DIR/../bootstrap/bin/clang-tblgen \
            -DLLVM_TABLEGEN=$PKG_BUILD_DIR/../bootstrap/bin/llvm-tblgen \
            -DLLVM_CCACHE_BUILD=ON"
    fi
setup      : |
    # Just annoying.
    %patch -p1 -i $pkgfiles/0001-Silently-ignore-copy-dt-needed-entries.patch
    # Support solus, it's triplet, etc.
    %patch -p1 -i $pkgfiles/0001-Support-solus-as-a-distro.patch
    # Apply the linker flat --emit-relocs for libLLVM and libclang-cpp only without having on everything else
    %patch -p1 -i $pkgfiles/0001-Emit-relocations-for-BOLT.patch
    %patch -p1 -i $pkgfiles/0001-Build-lld-libraries-shared.patch
    %patch -p1 -i $pkgfiles/0001-Build-polly-libraries-shared.patch
    %patch -p1 -i $pkgfiles/0003-PATCH-clang-Don-t-install-static-libraries.patch

    # Patch cfe for Solus specific options
    %patch -p1 -i $pkgfiles/0001-cfe-Use-correct-Solus-multilib-paths.patch
    # Allow us to ignore -Werror even when projects force append them
    %patch -p1 -i $pkgfiles/0001-clang-lib-Ignore-Werror-if-CLANG_IGNORE_WERROR-is-se.patch
    %patch -p1 -i $pkgfiles/0001-Solus-Make-it-easier-to-set-version-from-ypkg.patch

    # Pull lld in line with binutils linkers for consistency
    %patch -p1 -i $pkgfiles/0001-Enable-as-needed-with-LD_AS_NEEDED-variable.patch
    %patch -p1 -i $pkgfiles/0001-Make-gnuhash-the-default-when-not-specified.patch
    %patch -p1 -i $pkgfiles/0001-Update-default-binutils-version.patch
    %patch -p1 -i $pkgfiles/0001-lld-Always-enable-build-id-and-use-20-byte-hashes.patch
    %patch -p1 -i $pkgfiles/0001-Solus-Use-zstd-compression-for-debug-symbols-by-defa.patch

    %patch -p1 -i $pkgfiles/0001-Use-mimalloc-for-clang-lld-llvm.patch

    # Set the Solus version string
    sed -i "s|@@SOLUS_VERSION_STRING@@|Solus ${version}-${release}|g" clang/CMakeLists.txt

    ### Bootstrap compiler (optional)
    if [[ ! -z "${PGO_GEN_BUILD}" && ${BOOTSTRAP} == "1" ]]; then

        echo "BUILDING BOOTSTRAP COMPILER"

        mkdir -p $PKG_BUILD_DIR/../bootstrap

        cd $PKG_BUILD_DIR/../bootstrap

        cmake -G Ninja $workdir/llvm \
            -DCMAKE_BUILD_TYPE=Release \
            -DCLANG_DEFAULT_LINKER=lld \
            -DCLANG_DEFAULT_OBJCOPY=llvm-objcopy \
            -DENABLE_LINKER_BUILD_ID=ON \
            -DLLVM_ENABLE_LTO=Thin \
            ${CMAKE_X84_64_OPTIONS} \
            -DCMAKE_C_FLAGS="$_LLVM_FLAGS_FINAL" \
            -DCMAKE_CXX_FLAGS="$_LLVM_FLAGS_FINAL" \
            -DLLVM_ENABLE_PROJECTS='clang;lld;llvm' \
            -DLLVM_ENABLE_RUNTIMES='compiler-rt' \
            -DLLVM_OPTIMIZED_TABLEGEN=ON
        ninja %JOBS% clang compiler-rt lld llvm-profdata llvm-ar llvm-nm llvm-ranlib llvm-objcopy -v
    fi
build      : |
    ### PGO gen/use build for amd64.
    cmake -G Ninja -B solusBuildDir -S llvm \
        ${CMAKE_COMMON_OPTIONS} \
        ${CMAKE_X84_64_OPTIONS} \
        -DCMAKE_C_FLAGS="$PGOFLAGS" \
        -DCMAKE_CXX_FLAGS="$PGOFLAGS" \
        -DLLVM_ENABLE_PROJECTS=$_PROJECTS \
        -DLLVM_ENABLE_RUNTIMES=$_RUNTIMES \
        -DLLVM_TARGETS_TO_BUILD=$_TARGETS \
        -DLLVM_BUILD_DOCS=ON \
        -DLLVM_ENABLE_SPHINX=ON \
        -DSPHINX_EXECUTABLE="/usr/bin/sphinx-build" \
        -DSPHINX_OUTPUT_MAN=ON \
        -DSPHINX_OUTPUT_HTML=OFF \
        -DSPHINX_WARNINGS_AS_ERRORS=OFF
    %ninja_build -v

    # Build this target explicitly, otherwise it won't happen until the install phase
    if [[ ! -z "${PGO_USE_BUILD}" ]]; then
        %ninja_build -v runtimes
    fi

    ### EMUL32 Build
    # Reusing profile data from amd64 build saving a bunch of time (but slightly inaccurate).
    if [[ ! -z "${PGO_USE_BUILD}" ]]; then
        export PKG_CONFIG_PATH=/usr/lib32/pkgconfig:/usr/share/pkgconfig:/usr/lib/pkgconfig
        export LT_SYS_LIBRARY_PATH=/usr/lib32

        export CC="$workdir/solusBuildDir/bin/clang -m32"
        export CXX="$workdir/solusBuildDir/bin/clang++ -m32"

        export CFLAGS="-march=i686 -msse2 -mtune=generic -O3 -fstack-protector -pipe -fprofile-instr-use=$PGO_PATH -m32 -fPIC -ffat-lto-objects"
        export CXXFLAGS="-march=i686 -msse2 -mtune=generic -O3 -fstack-protector -pipe -fprofile-instr-use=$PGO_PATH -m32 -fPIC -ffat-lto-objects"

        cmake -G Ninja -B emul32 -S llvm \
          ${CMAKE_COMMON_OPTIONS} \
          -DCMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX=32 \
          -DLIBCXX_INSTALL_LIBRARY_DIR=lib32 \
          -DLIBCXXABI_INSTALL_LIBRARY_DIR=lib32 \
          -DLLVM_LIBDIR_SUFFIX=32 \
          -DLLVM_TARGET_ARCH=i686 \
          -DLLVM_DEFAULT_TARGET_TRIPLE=i686-pc-linux-gnu \
          -DLLVM_ENABLE_MIMALLOC=OFF \
          -DLLVM_ENABLE_PROJECTS="clang;llvm" \
          -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;compiler-rt" \
          -DLLVM_TARGETS_TO_BUILD="host;AMDGPU;BPF" \
          -DLLVM_CCACHE_BUILD=ON
        ninja %JOBS% -C emul32 -v
        ninja %JOBS% -C emul32 -v runtimes
    fi
profile    : |
    # Profiling with the instrumented compiler is very slow...
    # Building runtimes is only ~1200 files and we still get most of the benefits.
    cmake -G Ninja -B profile -S runtimes \
        ${CMAKE_COMMON_OPTIONS} \
        ${CMAKE_X84_64_OPTIONS} \
        ${CMAKE_USE_COMPILER} \
        -DLLVM_ENABLE_RUNTIMES='libcxx;libcxxabi' \
        -DCMAKE_C_FLAGS_RELEASE="$_LLVM_FLAGS_FINAL" \
        -DCMAKE_CXX_FLAGS_RELEASE="$_LLVM_FLAGS_FINAL"
    ninja %JOBS% -C profile -v
install    : |
    # Install emul32 build
    DESTDIR="%installroot%" ninja install -C emul32 -v
    mv $installdir/usr/bin/llvm-config{,32}

    # Make sure that the .defs files are arch-dependent
    pushd $installdir/usr/include/llvm/Config
    mv llvm-config.h llvm-config-32.h
    mkdir 32
    mv *.def 32/
    popd

    # Install x86_64 build
    %ninja_install -v

    # Cleanup libdirs
    major="$( cut -d '.' -f 1 <<< "$version" )"
    mv -v $installdir/usr/lib/clang/${major}/lib/x86_64-solus-linux/* $installdir/usr/lib64/clang/${major}/lib/x86_64-solus-linux/
    mv -v $installdir/usr/lib/clang/${major}/lib/i386-pc-linux-gnu/* $installdir/usr/lib32/clang/${major}/lib/i386-pc-linux-gnu/
    mv -v $installdir/usr/lib/clang/${major}/lib/i386-solus-linux $installdir/usr/lib32/clang/${major}/lib/
    mv -v $installdir/usr/lib64/clang/${major}/lib/i386-solus-linux/* $installdir/usr/lib32/clang/${major}/lib/i386-solus-linux/
    rmdir --ignore-fail-on-non-empty --parents -v $installdir/usr/lib/clang/${major}/lib/x86_64-solus-linux/ \
                                                  $installdir/usr/lib/clang/${major}/lib/i386-pc-linux-gnu/ \
                                                  $installdir/usr/lib64/clang/${major}/lib/i386-solus-linux/

    ### BOLT
    # Instrument
    #bolt_instr $workdir/solusBuildDir/lib64/libclang-cpp.so.18.1
    #bolt_instr $workdir/solusBuildDir/lib64/libLLVM.so.18.1
    # Profile
    # cmake -G Ninja -B bolt-profile -S runtimes \
    #     ${CMAKE_COMMON_OPTIONS} \
    #     ${CMAKE_X84_64_OPTIONS} \
    #     -DCMAKE_AR=$workdir/solusBuildDir/bin/llvm-ar \
    #     -DCMAKE_NM=$workdir/solusBuildDir/bin/llvm-nm \
    #     -DCMAKE_RANLIB=$workdir/solusBuildDir/bin/llvm-ranlib \
    #     -DCMAKE_C_COMPILER=$workdir/solusBuildDir/bin/clang \
    #     -DCMAKE_CXX_COMPILER=$workdir/solusBuildDir/bin/clang++ \
    #     -DLLVM_ENABLE_RUNTIMES='libcxx;libcxxabi' \
    #     -DCMAKE_C_FLAGS_RELEASE="$_LLVM_FLAGS_FINAL" \
    #     -DCMAKE_CXX_FLAGS_RELEASE="$_LLVM_FLAGS_FINAL"
    # ninja %JOBS% -C bolt-profile -v
    # Merge and optimize
    #bolt_merge $workdir/solusBuildDir/lib64/libclang-cpp.so.18.1
    #bolt_merge $workdir/solusBuildDir/lib64/libLLVM.so.18.1
    #bolt_opt $workdir/solusBuildDir/lib64/libclang-cpp.so.18.1
    #bolt_opt $workdir/solusBuildDir/lib64/libLLVM.so.18.1
    # Install BOLT'd libs over the LTO build
    #install -Dm00755 $workdir/solusBuildDir/lib64/libLLVM.so.18.1 $installdir/usr/lib64/libLLVM.so.18.1
    #install -Dm00755 $workdir/solusBuildDir/lib64/libclang-cpp.so.18.1 $installdir/usr/lib64/libclang-cpp.so.18.1

    # Make sure that the .defs files are arch-dependent
    pushd $installdir/usr/include/llvm/Config
    mv llvm-config.h llvm-config-64.h
    mkdir 64
    for i in *.def; do
        mv $i 64/
        cat $pkgfiles/defs.h.in | sed "s|@@REPLACE@@|$i|g" > $i
    done
    popd

    # Remove static libs with equivalent shared libraries
    rm -v $installdir/usr/lib*/libarcher_static.a

    # Don't seem to correspond to something used
    rm -v $installdir/usr/share/man/man1/{lit,lldb-tblgen}.1

    # Seems to not have an install section for some reason (https://github.com/llvm/llvm-project/issues/41800)
    install -Dm00644 lld/docs/ld.lld.1 -t $installdir/usr/share/man/man1

    # LTO Plugin
    install -d -D -m 00755 $installdir/%libdir%/bfd-plugins
    ln -sv ../LLVMgold.so $installdir/%libdir%/bfd-plugins/.
    # Finally add our compatibility header
    install -m 00644 $pkgfiles/llvm-config.h $installdir/usr/include/llvm/Config/llvm-config.h

    # Temporary for transition packages
    install -dm0755 $installdir/usr/share/tmp
    echo "TEMPORARY" >> $installdir/usr/share/tmp/llvm-clang
    echo "TEMPORARY" >> $installdir/usr/share/tmp/llvm-clang-32bit
    echo "TEMPORARY" >> $installdir/usr/share/tmp/llvm-clang-devel
    echo "TEMPORARY" >> $installdir/usr/share/tmp/llvm-clang-32bit-devel
