{% set version = "2.78.4" %}
{% set major_minor = ".".join(version.split(".")[:2]) %}
{% set posix = 'm2-' if win else '' %}
{% set native = 'm2w64-' if win else '' %}

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

source:
  url: https://download.gnome.org/sources/glib/{{ major_minor }}/glib-{{ version }}.tar.xz
  sha256: 24b8e0672dca120cc32d394bccb85844e732e04fe75d18bb0573b2dbc7548f63
  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-replace-hardcoded-paths.patch
    - patches/0002-Manually-link-with-libiconv-whenever-we-use-libintl.patch  # [win]
    - patches/0004-Attempt-to-mask-out-qemu-failing-tests.patch       # [ppc64le or aarch64]
    - patches/0006-correct-osx-tests-skips.patch
    - patches/0007-win-pkgconfig-test-bash-friendly.patch # [win]
    - patches/0008-skip-tests-needing-system-utils.patch # [linux]
    - patches/0009-s390x-skip-locale-check.patch # [s390x]

build:
  number: 0
  ignore_run_exports_from:
    - python *

requirements:
  build:
    - patch # [unix]
    - {{ posix }}patch  # [win]
    - meson >=0.60.0
    - cmake
    - ninja
    - {{ native }}pkg-config
    - {{ compiler('c') }}
    - {{ compiler('cxx') }}
    - python >=3.5
    - setuptools
  host:
    - libffi {{ libffi }}
    - gettext 0.21.0  # [osx]
    - zlib {{ zlib }}
    - pcre2 10.42
    - libiconv 1.16

outputs:
  - name: libglib
    script: install.sh  # [unix]
    script: install.bat  # [not unix]
    build:
      ignore_run_exports_from:
        - python *
      run_exports:
        - {{ pin_subpackage("libglib") }}
    requirements:
      build:
        - meson >=0.60.0
        - ninja
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - python >=3.5
        - setuptools
      host:
        - libffi {{ libffi }}
        - gettext 0.21.0  # [osx]
        - zlib {{ zlib }}
        - pcre2 10.42
        - libiconv 1.16
      run:
        - gettext >=0.21.0,<1.0a0  # [osx]
        # bounds through run_exports
        - libffi
        - zlib
        - pcre2
        - libiconv
      run_constrained:
        # Avoid colliding with older glib builds that didn't have a libglib output
        - glib {{ version }} *_{{ PKG_BUILDNUM }}
    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]
  - name: glib-tools
    script: install.sh  # [unix]
    script: install.bat  # [not unix]
    build:
      ignore_run_exports_from:
        - python *
    requirements:
      build:
        - meson >=0.60.0
        - ninja
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - python >=3.5
        - setuptools
        - gettext 0.21.0  # [osx]
      host:
        - {{ pin_subpackage("libglib", exact=True) }}
      run:
        - {{ pin_subpackage("libglib", exact=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:
      ignore_run_exports_from:
        - python *
      run_exports:
        - {{ pin_subpackage("libglib") }}
    requirements:
      build:
        - meson >=0.60.0
        - ninja
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - python >=3.5
        - setuptools
      host:
        - {{ pin_subpackage("libglib", exact=True) }}
        - {{ pin_subpackage("glib-tools", exact=True) }}
        - gettext 0.21.0  # [osx]
      run:
        - python
        - gettext >=0.21.0,<1.0a0  # [osx]
        - {{ pin_subpackage("libglib", exact=True) }}
        - {{ pin_subpackage("glib-tools", exact=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
