{% set version = "3.8.16" %}
{% set buildnumber = 0 %}
{% set ver2 = '.'.join(version.split('.')[0:2]) %}
{% set ver2nd = ''.join(version.split('.')[0:2]) %}
{% set ver3nd = ''.join(version.split('.')[0:3]) %}
{% set dbg_abi = '' %}

package:
  name: python-split
  version: {{ version }}

build:
  number: {{ buildnumber }}

source:
  - url: https://www.python.org/ftp/python/{{ version }}/Python-{{ version }}.tar.xz
    # md5 from: https://www.python.org/downloads/release/python-{{ ver3nd }}/
    md5: 621ac153586a3152e2ab7d3a8614df9a
    patches:
      - patches/0000-Fix-off-by-one-error-in-_winapi_WaitForMultipleObjec.patch
      - patches/0001-Add-Anaconda-Distribution-version-logic.patch
      - patches/0002-Darwin-Add-arch-x86_64-to-UnicCCompiler-ld_args.patch
      - patches/0003-Win32-Change-FD_SETSIZE-from-512-to-2048.patch
      - patches/0004-Win32-distutils-Add-support-to-cygwinccompiler-for-V.patch
      - patches/0005-Do-not-pass-g-to-GCC-when-not-Py_DEBUG.patch
      - patches/0006-Support-cross-compiling-byte-code.patch
      - patches/0007-Win32-Fixes-for-Windows-GCC-interop-needed-by-RPy2-a.patch
      - patches/0008-Darwin-Look-in-sysroot-usr-lib-include-if-sysroot-is.patch
      - patches/0009-runtime_library_dir_option-Use-1st-word-of-CC-as-com.patch
      - patches/0010-Win32-Do-not-download-externals.patch
      - patches/0011-Add-support-for-_CONDA_PYTHON_SYSCONFIGDATA_NAME-if-.patch
      - patches/0012-Fix-find_library-so-that-it-looks-in-sys.prefix-lib-.patch
      - patches/0013-Disable-new-dtags-in-unixccompiler.py.patch
      - patches/0014-Fix-cross-compilation-on-Debian-based-distros.patch
      - patches/0015-Disable-registry-lookup-unless-CONDA_PY_ALLOW_REG_PA.patch
      - patches/0016-Unvendor-openssl.patch  # [win]
      - patches/0017-Unvendor-sqlite3.patch
      # https://bugs.python.org/issue35644
      - patches/0018-venv-Revert-a-change-from-https-github.com-python-cp.patch
      - patches/0019-Win-Add-back-the-DLLSuffix-used-to-find-the-openssl-.patch
      - patches/0020-Use-ranlib-from-env-if-env-variable-is-set.patch
      # Python 3.8 is pretty broken without this, please port it carefully.
      - patches/0022-Add-CondaEcosystemModifyDllSearchPath.patch
      - patches/0023-Add-d1trimfile-SRC_DIR-to-make-pdbs-more-relocatable.patch
      - patches/0024-Doing-d1trimfile.patch
      - patches/0025-egg-debugging-with-Windows-debug-builds.patch
      - patches/0026-Revert-part-of-https-bugs.python.org-issue33895-http.patch
      - patches/0027-crypt-aarch64.patch  # [linux and aarch64]

      # Intel patches
      - patches/intel_version.patch
      - patches/intel_distutil_build.patch
      - patches/intel_cprt.patch
      - patches/intel_skip_hanging_test.patch     [osx]
      - patches/intel_build_py_with_pie.patch     [linux]
      - patches/intel_remove_wininst.patch
      - patches/intel_decouple_tcltk.patch
      - patches/intel_decouple_bzip2.patch
      - patches/intel_do_not_link_crypt.patch     [linux]

  # TODO :: Depend on our own packages for these:
  - url: https://github.com/python/cpython-source-deps/archive/xz-5.2.2.zip          # [win]
    folder: externals/xz-5.2.2                                                       # [win]
    sha256: 02b6d6f1e0369940e7e1f0d324992e069d09f5f3d32d86e2d22cd8b82ac3fb3f         # [win]
  # Used for populating $PREFIX/tcl directory
  - git_url: https://github.com/tcltk/tcl                                            # [win]
    git_tag: core-8-6-12                                                             # [win]
    folder: externals/tcl-core-8.6.12                                                # [win]
  - url: https://github.com/python/cpython-bin-deps/archive/tcltk-8.6.12.0.zip       # [win]
    folder: externals/tcltk-8.6.12.0                                                 # [win]
    sha256: 3a55e9e9fcb754b5a484a22d54841153f7624dd30f7b0c81b1cb05f38e2b5216         # [win]
  - url: https://github.com/python/cpython-source-deps/archive/tix-8.4.3.6.zip       # [win]
    sha256: 37cd629a75d2a34974a3d771ccab5c9e3caf3d138cea81040f9cdba1aded1cf2         # [win]
    folder: externals/tix-8.4.3.6                                                    # [win]
    sha256: e558e3dc5e67ac0942f8fceafce00ca46b177da9ebeaf38ec7fafd9b9913ac56         # [win]
  - url: https://github.com/python/cpython-source-deps/archive/bzip2-1.0.8.zip       # [win]
    folder: externals/bzip2-1.0.8                                                    # [win]
    sha256: 12c17d15f99e27235529574a722fb484a4e8fdf2427cef53b1b68bdf07e404a9         # [win]
  - url: https://github.com/python/cpython-source-deps/archive/zlib-1.2.12.zip       # [win]
    folder: externals/zlib-1.2.12                                                    # [win]
    sha256: 92197502951ac8414ece9f2d9fa2cc010c51d610e6b2ed9833ba4a35d65f222b         # [win]
    patches:                                                                         # [win]
      - patches/CVE-2022-37434.patch                                                 # [win]
  - url: https://github.com/python/cpython-bin-deps/archive/nasm-2.11.06.zip         # [win]
    folder: externals/nasm-2.11.06                                                   # [win]
    sha256: de3c87b26a80e789986d8e6950c6304175d3829afe9c6c7211eb7257266ab0ac         # [win]
  - url: https://github.com/python/cpython-bin-deps/archive/libffi-3.3.0.zip         # [win]
    folder: externals/libffi-3.3.0                                                   # [win]
    sha256: 69e3f7235108a75033cb9325a0a3535ba271d144ec66fccefe134eda27d7bcfe         # [win]

outputs:
  - name: python
    script: build_base.sh # [unix]
    script: build_base.bat # [win]
    build:
      number: {{ buildnumber }}
      no_link:
        - DLLs/_ctypes.pyd  # [win]
      ignore_run_exports:  # [unix]
        # We delete the shared libraries here.
        - bzip2  # [unix]
        # C++ only installed so CXX is defined for distutils/sysconfig.
        - libcxx  # [osx]
        - libcxxabi  # [osx]
        - libffi  # [unix]
        - libstdcxx-ng  # [linux]
      detect_binary_files_with_prefix: False
      binary_has_prefix_files:
        # - lib/libpython{{ ver2 }}.*.1.0
        # - bin/python{{ ver2 }}  # [linux]
        # - lib/libpython{{ ver2 }}.a  # [linux]
        # - lib/libpython{{ ver2 }}.nolto.a  # [linux]
        # - lib/libpython3.so  # [linux]
        # - lib/python{{ ver2 }}/lib-dynload/_hashlib.cpython-{{ ver2nd }}-x86_64-linux-gnu.so  # [linux]
        - lib/libpython3.dylib  # [osx]
        # match python.org compiler standard
      skip: True  # [win and int(float(vc)) < 14]
      string: h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}
      script_env:
        # commented out unused env vars
        # - PY_INTERP_LINKAGE_NATURE
        # - PY_INTERP_DEBUG
        # Putting these here means they get emitted to build_env_setup.{sh,bat} meaning we can launch IDEs
        # after sourcing or calling that script without examine the contents of conda_build.{sh,bat} for
        # important env. vars.
        # - 'OPENSSL_DIR=%PREFIX%\Library'  # [win]
        # - 'BZ2_DIR=%PREFIX%\Library'      # [win]
        # - 'SQLITE3_DIR=%PREFIX%\Library'  # [win]
      missing_dso_whitelist:  # [win]
        - '**/MSVCR71.dll'  # [win]
        - '**/MSVCR80.dll'  # [win]
        # - '$RPATH/libcrypt.so.1'  # [linux]
        # - '$RPATH/libpthread.so.0'  # [linux]
        # - '$RPATH/libc.so.6'  # [linux]
        # - '$RPATH/libdl.so.2'  # [linux]
        # - '$RPATH/libutil.so.1'  # [linux]
        # - '$RPATH/libm.so.6'  # [linux]
        # - '$RPATH/librt.so.1'  # [linux]
        # - '$RPATH/libnsl.so.1'  # [linux]
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - {{ cdt('xorg-x11-proto-devel') }}  # [linux]
        - {{ cdt('libx11-devel') }}  # [linux]
        - {{ cdt('libuuid-devel') }}  # [linux and not (ppc64le or aarch64)]
        - make  # [not win]
        - pkg-config  # [not win]
        - ld_impl_{{target_platform}}  # [linux]
        - libcxx                       # [osx]
      host:
        - bzip2
        - sqlite
        - xz
        - zlib
        - openssl
        - tk
        - libffi ==3.3                             # [unix]
        - vc 14.2                            # [win]
        - ld_impl_{{target_platform}}        # [linux]
      run:
        - bzip2
        - sqlite
        - xz
        - zlib
        - openssl
        - {{ pin_compatible('libffi', max_pin='x.x') }}  # [unix]
        - tk
        - vc 14.2                            # [win]
    test:
      commands:
        - python -V
        - python -V | grep -q "Intel Corporation"
        - python3 -V            # [not win]
        - 2to3 -h
        - pydoc -h
        - python3-config --help  # [not win]
        - python -m venv test-venv
        - python -c "import sysconfig; print(sysconfig.get_config_var('CC'))"  # [not win]
        - _CONDA_PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_x86_64_conda_cos6_linux_gnu python -c "import sysconfig; print(sysconfig.get_config_var('CC'))"  # [linux]
        - _CONDA_PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_x86_64_conda_cos7_linux_gnu python -c "import sysconfig; print(sysconfig.get_config_var('CC'))"  # [linux]

  - name: libpython-static
    script: build_static.sh  # [unix]
    script: build_static.bat  # [win]
    build:
      number: {{ buildnumber }}
      activate_in_script: true
      ignore_run_exports:
        - python_abi
      string: h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}_cpython  # ["conda-forge" in (channel_targets or "")]
      string: h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}  # ["conda-forge" not in (channel_targets or "")]
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
      host:
        - {{ pin_subpackage('python', exact=True) }}
      run:
        - {{ pin_subpackage('python', exact=True) }}
    test:
      files:
        - tests/prefix-replacement/*
      requires:
        - {{ compiler('c') }}
      commands:
        - test -f ${PREFIX}/lib/libpython${PKG_VERSION%.*}.a  # [unix]
        - test -f ${PREFIX}/lib/libpython${PKG_VERSION%.*}.nolto.a  # [unix]
        - test -f ${PREFIX}/lib/python${PKG_VERSION%.*}/config-${PKG_VERSION%.*}-darwin/libpython${PKG_VERSION%.*}.a  # [osx]
        - pushd tests/prefix-replacement    # [unix]
        - bash build-and-test.sh      # [unix]
        - popd    # [unix]

about:
  home: http://www.python.org/
  license: PSF
  license_file: LICENSE
  summary: General purpose programming language
  description: |
    <strong>LEGAL NOTICE: Use of this software package is subject to the
    software license agreement (as set forth above, in the license section of
    the installed Conda package and/or the README file) and all notices,
    disclaimers or license terms for third party or open source software
    included in or with the software.</strong> 
    <br/><br/>
    EULA: <a href="https://docs.python.org/3/license.html" target="_blank">PSF</a>
    <br/><br/>
    Python is a widely used high-level, general-purpose, interpreted, dynamic
    programming language. Its design philosophy emphasizes code
    readability, and its syntax allows programmers to express concepts in
    fewer lines of code than would be possible in languages such as C++ or
    Java. The language provides constructs intended to enable clear programs
    on both a small and large scale.
  doc_url: https://www.python.org/doc/versions/
  doc_source_url: https://github.com/python/pythondotorg/blob/master/docs/source/index.rst
  dev_url: https://docs.python.org/devguide/
