{% set version = "2.68.3" %}
{% 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: e7e1a3c20c026109c45c9ec4a31d8dcebc22e86c69486993e565817d64be3138
  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
    #
    - hardcoded-paths.patch  # [unix]

    # skip some problematic tests
    - skip-gio-tests-meson.build.patch
    - skip-gio-tests-resources.c.patch
    - skip-glib-tests-fileutils.c.patch

    #- 0001-Attempt-to-mask-out-qemu-failing-tests.patch               # [ppc64le or aarch64]
    # Windows:
    - 0001-Manually-link-with-libiconv-whenever-we-use-libintl.patch  # [win]
    - 0002-Increase-some-test-timeouts.patch                          # [win]

build:
  number: 0
  ignore_run_exports_from:
    - python *

requirements:
  build:
    - {{ posix }}patch  # [win]
    - meson
    # see https://github.com/mesonbuild/meson/issues/7611
    - meson !=0.56.*  # [win]
    - ninja
    - {{ native }}pkg-config
    - {{ compiler('c') }}
    - {{ compiler('cxx') }}
    - python >=2.7
    - setuptools
  host:
    - libffi
    - gettext
    - zlib
    - pcre
    - libiconv
  run:
    - python >=2.7

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:
        - {{ posix }}patch  # [win]
        - meson
        # see https://github.com/mesonbuild/meson/issues/7611
        - meson !=0.56.*  # [win]
        - ninja
        - {{ native }}pkg-config
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - ninja
        - python >=2.7
        - setuptools
      host:
        - libffi
        - gettext
        - zlib
        - pcre
        - libiconv
      run_constrained:
        # Avoid colliding with older glib builds that didn't have a libglib output
        - glib {{ version }} *_{{ PKG_BUILDNUM }}
        - __osx >={{ MACOSX_DEPLOYMENT_TARGET|default("10.9") }}  # [osx]
    test:
      commands:
        - test -f ${PREFIX}/lib/libglib-2.0.0{{ SHLIB_EXT }}  # [osx]
        - test -f ${PREFIX}/lib/libglib-2.0{{ SHLIB_EXT }}.0  # [linux]
        - 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]
  - name: glib-tools
    script: install.sh  # [unix]
    script: install.bat  # [not unix]
    build:
      ignore_run_exports_from:
        - python *
    requirements:
      build:
        - {{ posix }}patch  # [win]
        - meson
        # see https://github.com/mesonbuild/meson/issues/7611
        - meson !=0.56.*  # [win]
        - ninja
        - {{ native }}pkg-config
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - ninja
        - python >=2.7
        - setuptools
      host:
        - {{ pin_subpackage("libglib", exact=True) }}
      run:
        - {{ pin_subpackage("libglib", exact=True) }}
    test:
      commands:
        - glib-compile-schemas --help
        - glib-compile-resources --help
        - gio version
        - gio-querymodules .
  - name: glib
    script: install.sh  # [unix]
    script: install.bat  # [not unix]
    build:
      ignore_run_exports_from:
        - python *
      run_exports:
        - {{ pin_subpackage("libglib") }}
    requirements:
      build:
        - {{ posix }}patch  # [win]
        - meson
        # see https://github.com/mesonbuild/meson/issues/7611
        - meson !=0.56.*  # [win]
        - ninja
        - {{ native }}pkg-config
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - ninja
        - python >=2.7
        - setuptools
      host:
        - {{ pin_subpackage("libglib", exact=True) }}
        - {{ pin_subpackage("glib-tools", exact=True) }}
        - gettext
      run:
        - python *
        - {{ pin_subpackage("libglib", exact=True) }}
        - {{ pin_subpackage("glib-tools", exact=True) }}
    test:
      commands:
        - test -f ${PREFIX}/lib/libglib-2.0${SHLIB_EXT}  # [not win]
        # Check that binaries can run -- instigated by Meson Linux rpath issue
        - gapplication help  # [linux]
        - gdbus help
        - gobject-query --help
        - gresource help
        - gtester --help  # [not win]

about:
  home: https://developer.gnome.org/glib/
  license: LGPL-2.1-or-later
  license_file: COPYING
  summary: Provides core application building blocks for libraries and applications written in C.

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