{% set version = "8.6.13" %}
{% set maj_min = ".".join(version.split(".")[:2]) %}
{% set build = 1 %}

package:
  name: tk
  version: {{ version }}

source:
  - url: https://downloads.sourceforge.net/tcl/tcl{{ version }}-src.tar.gz
    folder: tcl{{ version }}
    sha256: 43a1fae7412f61ff11de2cfd05d28cfc3a73762f354a417c62370a54e2caf066
  - url: https://downloads.sourceforge.net/tcl/tk{{ version }}-src.tar.gz
    folder: tk{{ version }}
    sha256: 2e65fa069a23365440a3c56c556b8673b5e32a283800d8d9b257e3f584ce0675


{% if tk_variant == 'noxft' and linux %}
# prioritize noxft variant via build number
{% set build = build + 100 %}
{% endif %}

build:
  number: {{ build }}
  string: "{{ tk_variant }}_h{{ PKG_HASH }}_{{ build }}"     # [linux]
  track_features:
    - tk_xft   # [tk_variant == 'xft']
  detect_binary_files_with_prefix: true
  run_exports:
    # pin to major.minor because library names have that info in them
    - {{ pin_subpackage('tk', max_pin='x.x') }}

requirements:
  build:
    - {{ compiler('c') }}
    - {{ cdt('xorg-x11-proto-devel') }}  # [linux]
    - {{ cdt('libx11-devel') }}          # [linux]
    - {{ cdt('libxcb') }}                # [linux]
    - {{ cdt('libxau') }}                # [linux]
    - make                               # [linux]
    - {{ cdt('freetype-devel') }}        # [linux and tk_variant == 'xft']
    - {{ cdt('fontconfig-devel') }}      # [linux and tk_variant == 'xft']
    - {{ cdt('libXrender-devel') }}      # [linux and tk_variant == 'xft']
    - {{ cdt('libXft-devel') }}          # [linux and tk_variant == 'xft']
    - pkg-config                         # [linux and tk_variant == 'xft']
  host:
    - zlib  # [unix]

test:

  files:
    - hello.tcl

  commands:
    # Check for binaries.
    {% for ver_suffix in ["", maj_min] %}
    - test -f "${PREFIX}/bin/tclsh{{ ver_suffix }}"                                            # [unix]
    - test -f "${PREFIX}/bin/wish{{ ver_suffix }}"                                             # [unix]
    - if not exist %LIBRARY_PREFIX%\\bin\\wish{{ ver_suffix.replace(".", "") }}.exe exit 1     # [win]
    - if not exist %LIBRARY_PREFIX%\\bin\\tclsh{{ ver_suffix.replace(".", "") }}.exe exit 1    # [win]
    {% endfor %}

    # Check for includes.
    {% set tcl_tk_includes = [
            "tcl",
            "tclDecls",
            "tclPlatDecls",
            "tclPlatDecls",
            "tclTomMathDecls",
            "tclTomMath",
            "tk",
            "tkDecls",
            "tkPlatDecls"
    ] %}
    {% for each_tcl_tk_include in tcl_tk_includes %}
    - test -f "${PREFIX}/include/{{ each_tcl_tk_include }}.h"                        # [unix]
    - if not exist %LIBRARY_PREFIX%\\include\\{{ each_tcl_tk_include }}.h exit 1     # [win]
    {% endfor %}

    # Check for libraries.
    # Library naming note: t means "full thread support" in Windows
    #    https://sourceforge.net/p/tcl/mailman/tcl-bugs/thread/From_noreply@sourceforge.net_Mon_Jul_23_11:46:16_2012/
    {% set tcl_tk_libs = [
            "tcl",
            "tk"
    ] %}
    {% for each_tcl_tk_lib in tcl_tk_libs %}
    - test -f "${PREFIX}/lib/lib{{ each_tcl_tk_lib }}{{ maj_min }}.dylib"                                        # [osx]
    - test -f "${PREFIX}/lib/lib{{ each_tcl_tk_lib }}{{ maj_min }}.so"                                           # [linux]
    - test -f "${PREFIX}/lib/lib{{ each_tcl_tk_lib }}stub{{ maj_min }}.a"                                        # [unix]
    - if not exist %LIBRARY_PREFIX%\\lib\\{{ each_tcl_tk_lib }}{{ maj_min.replace(".", "") }}t.lib exit 1         # [win]
    - if not exist %LIBRARY_PREFIX%\\bin\\{{ each_tcl_tk_lib }}{{ maj_min.replace(".", "") }}t.dll exit 1         # [win]
    - if not exist %LIBRARY_PREFIX%\\lib\\{{ each_tcl_tk_lib }}stub{{ maj_min.replace(".", "") }}.lib exit 1     # [win]
    {% endfor %}

    # Check commands work and run a simple program.
    - tclsh hello.tcl
    - tclsh{{ maj_min }} hello.tcl                       # [unix]
    - tclsh{{ maj_min.replace(".", "") }} hello.tcl      # [win]
    - wish hello.tcl
    - wish{{ maj_min }} hello.tcl                        # [unix]
    - wish{{ maj_min.replace(".", "") }}t hello.tcl      # [win]

about:
  home: http://www.tcl.tk/
  license: TCL
  license_family: BSD
  license_file: tcl{{ version }}/license.terms
  summary: A dynamic programming language with GUI support.  Bundles Tcl and Tk.
  dev_url: https://github.com/tcltk/tk

extra:
  recipe-maintainers:
    - jakirkham
    - msarahan
    - pelson
    - ocefpaf
    - isuruf
    - matthiasdiener
    - xhochy
