{% set version = "2.86.3" %}
{% set major_minor = ".".join(version.split(".")[:2]) %}

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

source:
  url: https://download.gnome.org/sources/glib/{{ major_minor }}/glib-{{ version }}.tar.xz
  sha256: b3211d8d34b9df5dca05787ef0ad5d7ca75dec998b970e1aab0001d229977c65
  patches:
    # Related to this patch https://bugzilla.gnome.org/show_bug.cgi?id=673135
    # However, it was rejected by upstream. Homebrew decided to keep their own
    # copy ( https://raw.githubusercontent.com/Homebrew/patches/59e4d32/glib/hardcoded-paths.diff ).
    # We are essentially using that copy, but with some tweaks. Info at the link below.
    #
    # https://github.com/Homebrew/legacy-homebrew/blob/21ce7a56cb3fc40fe93d731cc654c69268796772/Library/Formula/glib.rb#L33-L39
    - patches/0001-remove-hardcoded-paths.patch
    # "Fixes" for tests that apply to all platforms:
    - patches/0002-crossplatform-test-tweaks.patch
    - patches/0003-Attempt-to-mask-out-qemu-failing-tests.patch  # [aarch64]
    # Windows:
    - patches/0004-Manually-link-with-libiconv-whenever-we-use-libintl..patch  # [win]
    - patches/0005-Increase-some-test-timeouts.patch  # [win]
    # Seems like our CIs are likely incompatible with some dbus tests
    # https://github.com/conda-forge/glib-feedstock/pull/199#issuecomment-2578085726
    # This is a modified patch '0006-Skip-flaky-tests-on-linux64-CI.patch' from
    # conda-forge compatible with all linux platforms.
    - patches/0006-Skip-flaky-tests-on-linux-CI.patch  # [linux]

build:
  number: 0
  # Keep in sync with
  # https://gitlab.gnome.org/GNOME/glib/-/blob/2.84.2/meson.build?ref_type=tags#L2503
  skip: True  # [py<37]

requirements:
  build:
    - meson >=1.4.0
    - cmake
    - ninja-base
    - pkg-config
    - {{ stdlib('c') }}
    - {{ compiler('c') }}
    - {{ compiler('cxx') }}
    - python
    - setuptools
    # Git is needed to download dependencies: proxy-libintl and sysprof.
    # In the current CI version, only win is missing git.
    - git # [win]
  host:
    - python
    - libffi {{ libffi }}
    - gettext {{ gettext }}  # [osx]
    - zlib {{ zlib }}
    - pcre2 {{ pcre2 }}
    - libiconv 1.16
  run:
    - python
    # run-dep as a workaround for now; upstream package still imports from distutils
    # imports distutils.msvccompiler which has been removed on recent setuptools
    - setuptools <74  # [py>311]

outputs:
  - name: libglib
    script: install.sh  # [unix]
    script: install.bat  # [not unix]
    build:
      run_exports:
        - {{ pin_subpackage("libglib") }}
    requirements:
      build:
        - meson >=1.4.0
        - ninja-base
        - pkg-config  # [not win]
        - {{ stdlib('c') }}
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - python
        - setuptools
      host:
        - libffi {{ libffi }}
        - gettext {{ gettext }}  # [osx]
        - zlib {{ zlib }}
        - pcre2 {{ pcre2 }}
        - libiconv
      run:
        - gettext >=0.21.0,<1.0a0  # [osx]
        # bounds through run_exports
        - libffi
        - zlib
        - pcre2
        - libiconv

    test:
      commands:
        - test -f ${PREFIX}/lib/libglib-2.0.0{{ SHLIB_EXT }}  # [osx]
        - test -f ${PREFIX}/lib/libglib-2.0{{ SHLIB_EXT }}.0  # [linux]
        - if not exist "%LIBRARY_BIN%\\glib-2.0-0.dll" exit 1  # [win]
        - if not exist "%LIBRARY_LIB%\\glib-2.0.lib" exit 1   # [win]
        - test ! -f ${PREFIX}/lib/libgobject-2.0.la  # [not win]
        - test ! -f ${PREFIX}/lib/libglib-2.0${SHLIB_EXT}  # [not win]
        - test -f ${PREFIX}/lib/pkgconfig/glib-2.0.pc  # [unix]
        - test -f ${PREFIX}/etc/conda/activate.d/libglib_activate.sh  # [not win]
        - test -f ${PREFIX}/etc/conda/deactivate.d/libglib_deactivate.sh  # [not win]
        # Introspection test
        - test -f ${PREFIX}/share/gir-1.0/GLib-2.0.gir              # [unix]
        - test -f ${PREFIX}/lib/girepository-1.0/GLib-2.0.typelib   # [unix]
        - if not exist %LIBRARY_PREFIX%\share\gir-1.0\GLib-2.0.gir exit 1             # [win]
        - if not exist %LIBRARY_PREFIX%\lib\girepository-1.0\GLib-2.0.typelib exit 1  # [win]

  - name: glib-tools
    script: install.sh  # [unix]
    script: install.bat  # [not unix]
    build:
    requirements:
      build:
        - meson >=1.4.0
        - ninja-base
        - pkg-config  # [not win]
        - {{ stdlib('c') }}
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - python
        - setuptools
        - gettext {{ gettext }}  # [osx]
      host:
        - {{ pin_subpackage("libglib", skip_build_id=True) }}
      run:
        - {{ pin_subpackage("libglib", skip_build_id=True) }}
        - gettext >=0.21.0,<1.0a0  # [osx]
    test:
      commands:
        # Check that binaries can run -- instigated by Meson Linux rpath issue
        - gapplication help  # [linux]
        - gdbus help
        - gio version
        - gio-querymodules .
        - glib-compile-schemas --help
        - gresource help

  - name: glib
    script: install.sh  # [unix]
    script: install.bat  # [not unix]
    build:
      run_exports:
        - {{ pin_subpackage("libglib") }}
    requirements:
      build:
        - meson >=1.4.0
        - ninja-base
        - pkg-config  # [not win]
        - {{ stdlib('c') }}
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - python
        - setuptools
      host:
        - {{ pin_subpackage("libglib", skip_build_id=True) }}
        - {{ pin_subpackage("glib-tools", skip_build_id=True) }}
        - gettext {{ gettext }}  # [osx]
      run:
        - python
        - gettext >=0.21.0,<1.0a0  # [osx]
        - {{ pin_subpackage("libglib", skip_build_id=True) }}
        - {{ pin_subpackage("glib-tools", skip_build_id=True) }}
    test:
      commands:
        - test -f ${PREFIX}/lib/libglib-2.0${SHLIB_EXT}  # [not win]
        - glib-compile-resources --help
        - glib-compile-schemas --help
        - gobject-query --help
        - gresource help
        - gtester --help  # [not win]

about:
  home: https://docs.gtk.org/glib
  license: LGPL-2.1-or-later
  license_family: LGPL
  license_file: COPYING
  summary: Provides core application building blocks for libraries and applications written in C.
  description: |
    GLib provides the core application building blocks for libraries and
    applications written in C. It provides the core object system used in
    GNOME, the main loop implementation, and a large set of utility functions
    functions for strings and common data structures.
  doc_url: https://docs.gtk.org/glib
  dev_url: https://gitlab.gnome.org/GNOME/glib

extra:
  feedstock-name: glib
  recipe-maintainers:
    - ccordoba12
    - jakirkham
    - scopatz
    - ocefpaf
    - pkgw
    - isuruf
    - chenghlee
    - xhochy
    - tschoonj
