{% set version = "14.0.6" %}
{% set major_ver = version.split(".")[0] %}

package:
  name: llvm-package
  version: {{ version }}

source:
  url: https://github.com/llvm/llvm-project/releases/download/llvmorg-{{ version.replace(".rc", "-rc") }}/llvm-project-{{ version.replace(".rc", "rc") }}.src.tar.xz
  sha256: 8b3cfd7bc695bd6cea0f37f53f0981f34f87496e79e2529874fd03a2f9dd3a8a
  patches:
    # - patches/intel-D47188-svml-VF.patch    # Fixes vectorizer and extends SVML support
    # - patches/expect-fastmath-entrypoints-in-add-TLI-mappings.ll.patch # adjusts test added in 10.0.0 for intel-D47188-svml-VF.patch effects
    # - patches/amd-roc-2.7.0.diff
    - patches/0001-pass-through-QEMU_LD_PREFIX-SDKROOT.patch
    - patches/llvm-config-no-libLLVM.diff
    # https://reviews.llvm.org/D101972
    - patches/osx_ver.patch
    - patches/MSVC_DIA_SDK_path_fix.diff  # [win]
    - patches/llvm14-clear-gotoffsetmap.patch
    - patches/0004-Fixes-vectorizer-and-extends-SVML-support.patch

build:
  number: 4
  merge_build_host: false

requirements:
  build:
    - {{ compiler('cxx') }}
    - cmake
    - ninja
    - python >=3
    - libcxx {{ cxx_compiler_version }}  # [osx]
    - make      # [not win]
    - m2-coreutils  # [win]
    - m2-make   # [win]
    - m2-patch  # [win]
    - m2-grep   # [win]
    - m2-sed    # [win]
    - patch       # [not win]
    - m2-patch    # [win]
    - git         # [unix]
    - m2-git      # [win]
  host:
    - libcxx {{ cxx_compiler_version }}  # [osx]
    - zlib {{ zlib }}
    - libxml2 {{ libxml2 }} # [win]
    - libffi {{ libffi }}   # [unix]

outputs:
  # Contains everything
  - name: llvmdev
    script: install_llvm.sh  # [not win]
    script: install_llvm.bat  # [win]
    build:
      skip: true  # [(win and vc<14)]
      activate_in_script: true
      missing_dso_whitelist:  # [s390x]
        - '$RPATH/ld64.so.1'  # [s390x]
    requirements:
      build:
        - {{ compiler('cxx') }}
        - cmake
        - ninja
        - python >=3
      host:
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}
        - {{ pin_subpackage("llvm-tools", exact=True) }}
        - zlib {{ zlib }}
      run:
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}
        - {{ pin_subpackage("llvm-tools", exact=True) }}
        - libcxx >={{ cxx_compiler_version }}  # [osx]
    test:
      commands:
        - $PREFIX/bin/llvm-config --libs                   # [not win]
        - test -f $PREFIX/include/llvm/Pass.h              # [not win]
        - test -f $PREFIX/lib/libLLVMCore.a                # [not win]
        - $PREFIX/libexec/llvm/not false                   # [not win]
        - if not exist %LIBRARY_INC%\\llvm\\Pass.h exit 1  # [win]
        - if not exist "%LIBRARY_PREFIX%"\\libexec\llvm\not.exe exit 1  # [win]

  # Contains the shared libraries. To make different LLVM libraries co-installable
  # soversion is appended to the package name.
  - name: libllvm{{ major_ver }}
    script: install_llvm.sh  # [not win]
    build:
      skip: true  # [win and vc<14]
      activate_in_script: true
      run_exports:   # [not win]
        - {{ pin_subpackage("libllvm" + major_ver, max_pin="x.x") }}  # [not win]
      missing_dso_whitelist:  # [s390x]
        - '$RPATH/ld64.so.1'  # [s390x]
    requirements:
      build:
        - {{ compiler('cxx') }}
        - ninja                  # [not win]
        - cmake                  # [not win]
        - python >=3             # [not win]
      host:
        - libcxx >={{ cxx_compiler_version }}  # [osx]
        - zlib {{ zlib }}
        - libffi {{ libffi }} # [unix]
      run:
        - libcxx >={{ cxx_compiler_version }}  # [osx]
    test:
      commands:
        - test -f $PREFIX/lib/libLLVM-{{ major_ver }}${SHLIB_EXT}  # [not win]

  # This is a meta package so that people can use the latest libllvm and also
  # for run_exports
  - name: llvm
    build:
      skip: true  # [(win and vc<14)]
      run_exports:   # [not win]
        - {{ pin_subpackage("libllvm" + major_ver, max_pin="x.x") }}  # [not win]
    requirements:
      build:
      host:
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}  # [not win]
        - zlib {{ zlib }}
      run:   # [not win]
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}  # [not win]
      run_constrained:             # [not win]
        - llvmdev   {{ version }}  # [not win]
    test:
      commands:
        - echo "Hello World!"

  # Contains LLVM tools
  - name: llvm-tools
    script: install_llvm.sh   # [not win]
    script: install_llvm.bat  # [win]
    build:
      skip: true  # [(win and vc<14)]
      activate_in_script: true
      missing_dso_whitelist:  # [s390x]
        - '$RPATH/ld64.so.1'  # [s390x]
    requirements:
      build:
        - {{ compiler('cxx') }}
        - cmake
        - ninja
        - python >=3
      host:
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}
        - libxml2 {{ libxml2 }}  # [win]
        - zlib {{ zlib }}
      run:
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}
        - libcxx >={{ cxx_compiler_version }}  # [osx]
      run_constrained:
        - llvmdev   {{ version }}
    test:
      commands:
        - $PREFIX/bin/llc -version                               # [not win]
        - if not exist "%LIBRARY_BIN%"\\llc.exe exit 1           # [win]
        - llc -version                                           # [win]

  - name: lit
    build:
      script: python -m pip install llvm/utils/lit --no-deps --no-build-isolation -vv
      activate_in_script: true
      skip: true  # [py<30]
      entry_points:
        - lit = lit.main:main
      missing_dso_whitelist:  # [s390x]
        - '$RPATH/ld64.so.1'  # [s390x]
    requirements:
      host:
        - python
        - pip
        - setuptools
        - wheel
      run:
        - python
    test:
      imports:
        - lit
      commands:
        - lit -h

about:
  home: https://llvm.org/
  dev_url: https://github.com/llvm/llvm-project
  doc_url: https://llvm.org/docs/
  license: Apache-2.0 WITH LLVM-exception
  license_file: llvm/LICENSE.TXT
  license_family: Apache
  summary: Development headers and libraries for LLVM

extra:
  recipe-maintainers:
    - inducer
    - jakirkham
    - mingwandroid
    - SylvainCorlay
    - isuruf
    - timsnyder
    - xhochy
    - h-vetinari
