# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem                  1.0
PortGroup                   cmake 1.1

# This custom compiler toolchain is based on llvm|clang-8 but each release adds fixes for newer SDKs.
name                        llvm-cx
version                     22.1.1
revision                    2
dist_subdir                 wine
categories                  lang
platforms                   {darwin >= 18}
license                     NCSA
maintainers                 nomaintainer
description                 CodeWeavers custom compiler for -mwine32 targets ${version}.
long_description            {*}${description}
homepage                    https://codeweavers.com/
master_sites                https://media.codeweavers.com/pub/crossover/source/
extract.suffix              .tar.gz
distname                    crossover-sources-${version}
checksums                   rmd160  e514c407e3b7f75339a60fac84360f00791e97bb \
                            sha256  cdfe282ce33788bd4f969c8bfb1d3e2de060eb6c296fa1c3cdf4e4690b8b1831 \
                            size    147879629

supported_archs             x86_64

# Use cmake-bootstrap
depends_build-replace       path:bin/cmake:cmake port:cmake-bootstrap
depends_skip_archcheck-append cmake-bootstrap
configure.cmd               ${prefix}/libexec/cmake-bootstrap/bin/cmake


worksrcdir                  sources/clang/llvm

post-extract {
    ln -s ${workpath}/sources/clang/clang ${workpath}/sources/clang/llvm/projects/clang
}

# sterilize MacPorts build environment; we want nothing picked up from MP prefix
compiler.cpath
compiler.library_path
configure.cxx_stdlib
configure.cflags
configure.cxxflags
configure.cppflags
configure.optflags
configure.ldflags
configure.ccache            no
configure.distcc            no

# sterilize PATH
configure.env-append        PATH=/usr/bin:/bin:/usr/sbin:/sbin
build.env-append            PATH=/usr/bin:/bin:/usr/sbin:/sbin

cmake.build_type            Release
cmake.generator             {Unix Makefiles}

# Install everything into libexec
cmake.install_prefix        ${prefix}/libexec/${name}

configure.pre_args-replace  {*}[cmake::system_prefix_path] \
                            -DCMAKE_SYSTEM_PREFIX_PATH="${cmake.install_prefix}\;/usr"

configure.pre_args-replace  {*}[cmake::rpath_flags] \
                            -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF

configure.pre_args-delete   {*}[cmake::module_path]
configure.pre_args-delete   {*}[cmake::ccaching]
configure.pre_args-delete   -DCMAKE_INSTALL_NAME_DIR="${cmake.install_prefix}/lib"
configure.args-append       -DLLVM_TARGETS_TO_BUILD=X86

configure.args-append       -DLLVM_ENABLE_TERMINFO=OFF \
                            -DLLVM_ENABLE_LIBXML2=OFF \
                            -DLLVM_ENABLE_LIBEDIT=OFF \
                            -DLLVM_ENABLE_LIBPFM=OFF \
                            -DLLVM_ENABLE_THREADS=ON \
                            -DLLVM_ENABLE_ZLIB=OFF

# remove need for port:libxml2 dependency
configure.args-append       -DLIBXML2_LIBRARIES=IGNORE

# We want to fallback on Xcode provided copy of libLTO.dylib
# this resolves build issues with Xcode16 due to missing symbols
post-destroot {
  delete ${destroot}${prefix}/libexec/llvm-cx/lib/libLTO.dylib
}

livecheck.type              none
