{% set version = "12.0.0" %}
{% set sha256 = "49dc47c8697a1a0abd4ee51629a696d7bfe803662f2a7252a3b16fc75f3a8b50" %}

{% 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-{{ version.replace(".rc", "rc") }}.src.tar.xz
  sha256: {{ sha256 }}
  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
    # Revert an upstream change for Numba
    # ref: https://github.com/numba/llvmlite/blob/v0.29.0/conda-recipes/0001-Revert-Limit-size-of-non-GlobalValue-name.patch
    - patches/numba-0001-Revert-Limit-size-of-non-GlobalValue-name.patch
    #- patches/amd-roc-2.7.0.diff
    - patches/pass-through-qemu-ld-prefix.diff
    # Don't link libLLVM.dylib to llvm-config. Makes it easier for cross compiling
    - patches/llvm-config-no-libLLVM.diff
    # https://reviews.llvm.org/D101972
    - patches/D101972.patch
    - patches/osx_ver.patch
build:
  number: 3
  merge_build_host: false

requirements:
  build:
    - {{ compiler('cxx') }}
    - cmake
    - ninja     # [win]
    - python    >=3
    - make
    - libcxx {{ cxx_compiler_version }}  # [osx]
  host:
    - libcxx {{ cxx_compiler_version }}  # [osx]
    - zlib
    - libxml2   # [win]
    - ffi       # [linux]

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
    requirements:
      build:
        - {{ compiler('cxx') }}
        - cmake
        - ninja     # [win]
        - python    >=3
      host:
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}
        - {{ pin_subpackage("llvm-tools", exact=True) }}
        - zlib
      run:
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}
        - {{ pin_subpackage("llvm-tools", exact=True) }}
        - libcxx >={{ cxx_compiler_version }}.a0  # [osx]
    test:
      commands:
        - $PREFIX/bin/llvm-config --libs                         # [not win]
        - if not exist %LIBRARY_INC%\\llvm\\Pass.h exit 1        # [win]
        - test -f $PREFIX/include/llvm/Pass.h                    # [unix]
        - test -f $PREFIX/lib/libLLVMCore.a                      # [not win]
        - $PREFIX/libexec/llvm/not false                               # [not 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]
    requirements:
      build:
        - {{ compiler('cxx') }}
        - cmake                    # [not win]
        - python    >=3            # [not win]
      host:
        - libcxx >={{ cxx_compiler_version }}.a0  # [osx]
        - zlib
      run:
        - libcxx >={{ cxx_compiler_version }}.a0  # [osx]
    test:
      commands:
        - test -f $PREFIX/lib/libLLVM-{{ major_ver }}${SHLIB_EXT}  # [unix]

  # 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
      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
    requirements:
      build:
        - {{ compiler('cxx') }}
        - cmake
        - ninja     # [win]
        - python    >=3
      host:
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}
        - libxml2  # [win]
        - zlib
      run:
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}
      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:
      noarch: python
      script: python -m pip install utils/lit --no-deps -vv
      activate_in_script: true
      skip: true  # [not linux64]
      entry_points:
        - lit = lit:main
    requirements:
      host:
        - python >=3
        - pip
      run:
        - python
    test:
      imports:
        - lit

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

extra:
  recipe-maintainers:
    - inducer
    - jakirkham
    - mingwandroid
    - SylvainCorlay
    - isuruf
    - timsnyder
