{% set name = "librsvg" %}
{% set version = "2.54.4" %}
{% set abi_version = "2.0" %}
{% set version_majmin = version.rsplit('.', 1)[0] %}
{% set sha256 = "ea152a243f6a43c0e036a28c70de3fcbcdea5664c6811c78592bc229ecc24833" %}

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

source:
  fn: {{ name }}-{{ version }}.tar.xz
  url: https://download.gnome.org/sources/{{ name }}/{{ version_majmin }}/{{ name }}-{{ version }}.tar.xz
  sha256: {{ sha256 }}
  patches:  # [not win]
    - patches/0001_add_rust_lto.patch  # [not win]

build:
  skip: true # [win and vc<14]
  number: 2
  run_exports:
    # Looks good but no new info after 2.43 so keeping it x.x for safety.
    # https://abi-laboratory.pro/?view=timeline&l=librsvg
    - {{ pin_subpackage('librsvg', max_pin='x') }}
  missing_dso_whitelist:         # [linux]
    - '**/libc.so.6'             # [linux]
    - '**/libpthread.so.0'       # [linux]
    - '**/libdl.so.2'            # [linux]
    - '**/librt.so.1'            # [linux]
    - '**/libm.so.6'             # [linux]
    - '**/ld-linux-x86-64.so.2'  # [linux]
    - '**/ld64.so.1'             # [linux]

requirements:
  build:
    - cmake  # [win]
    - make  # [unix]
    - pkg-config
    - docutils
    - gi-docgen
    - binutils    # [linux]
    - gobject-introspection
    - rust_win-64 1.64.0       # [win]
    - rust        1.64.0       # [win]
    - {{ compiler('rust') }}   # [not win]
    - {{ compiler('c') }}
    - autoconf    # [unix]
    - automake    # [unix]
    - sed         # [unix]
    - gawk        # [unix]
    - libtool     # [unix]
    - patch       # [unix]
    - gnuconfig   # [unix]
    - python 3.9  # [win]
    - pthread-stubs                      # [linux]
    - {{ cdt('libxau-devel') }}          # [linux]
    - {{ cdt('libxau') }}                # [linux]
    - {{ cdt('xorg-x11-util-macros') }}  # [linux]
    - {{ cdt('xorg-x11-proto-devel') }}  # [linux]
    - {{ cdt('libx11-devel') }}          # [linux]
    - {{ cdt('libx11-common') }}         # [linux]
    - {{ cdt('libx11') }}                # [linux]
    - {{ cdt('libxext-devel') }}         # [linux]
    - {{ cdt('libxext') }}               # [linux]
    - {{ cdt('libxrender-devel') }}      # [linux]
  host:
    - gobject-introspection 1.*
    - glib 2.*
    - gettext   # [osx]
    - harfbuzz 4.3.0
    - fontconfig 2.14
    - freetype
    - libiconv  # [win and osx]
    - libxml2 2.9
    - cairo 1.16
    - gdk-pixbuf 2.42.10
    - pango
    - libpng 1.6
    - libzip 1.8.0
    - freetype 2.10
    - libdeflate 1.17
    - zlib
  run:
    - libdeflate
    - harfbuzz
    - fontconfig
    - libiconv  # [win or osx]
    - libxml2
    - cairo
    - gdk-pixbuf
    - pango
    - libpng
    - zlib
    - freetype

test:
  requires:
    - pkg-config
  commands:
    - rsvg-convert --version # [unix]
    - rsvg-convert.exe --version # [win]

    {% set name_abi = name + "-" + abi_version %}
    {% set lib = name + "-" + abi_version.split('.', 1)[0] %}  # [unix]
    {% set lib = "rsvg-" + abi_version %}  # [win]
    {% set vs_major = dict(vs2015="14", vs2017="15", vs2019="16")[c_compiler] %}  # [win]

    # verify that libs get installed and can be located through pkg-config
    - test -f $PREFIX/lib/{{ lib }}${SHLIB_EXT}  # [unix]
    - test ! -f $PREFIX/lib/{{ lib }}.a  # [unix]
    - test -f `pkg-config --variable=libdir --dont-define-prefix {{ name_abi }}`/{{ lib }}${SHLIB_EXT}  # [unix]
    - if not exist %PREFIX%\\Library\\bin\\{{ lib }}-vs{{ vs_major }}.dll exit 1  # [win]
    - for /f "usebackq tokens=*" %%a in (`pkg-config --variable=exec_prefix --dont-define-prefix {{ name_abi }}`) do if not exist "%%a/bin/{{ lib }}-vs{{ vs_major }}.dll" exit 1  # [win]
    - if not exist %PREFIX%\\Library\\lib\\{{ lib }}.lib exit 1  # [win]
    - for /f "usebackq tokens=*" %%a in (`pkg-config --variable=libdir --dont-define-prefix {{ name_abi }}`) do if not exist "%%a/{{ lib }}.lib" exit 1  # [win]

    # verify that gdk-pixbuf loader library gets installed
    - test -f $PREFIX/lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.so  # [unix]
    - test ! -f $PREFIX/lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.a  # [unix]
    - if not exist %PREFIX%\\Library\\lib\\gdk-pixbuf-2.0\\2.10.0\\loaders\\libpixbufloader-svg.dll exit 1  # [win]

    # verify that headers get installed
    - test -f $PREFIX/include/{{ name_abi }}/{{ name }}/rsvg-features.h  # [unix]
    - test -f $PREFIX/include/{{ name_abi }}/{{ name }}/rsvg-cairo.h  # [unix]
    - test -f $PREFIX/include/{{ name_abi }}/{{ name }}/rsvg.h  # [unix]
    - if not exist %PREFIX%\\Library\\include\\{{ name_abi }}\\{{ name }}\\rsvg-features.h exit 1  # [win]
    - if not exist %PREFIX%\\Library\\include\\{{ name_abi }}\\{{ name }}\\rsvg-cairo.h exit 1  # [win]
    - if not exist %PREFIX%\\Library\\include\\{{ name_abi }}\\{{ name }}\\rsvg.h exit 1  # [win]

    # test for gobject-introspection files
    - test -f $PREFIX/lib/girepository-1.0/Rsvg-2.0.typelib  # [unix]
    # introspection is disabled for now on windows
    #- if not exist %LIBRARY_LIB%\\girepository-1.0\\Rsvg-2.0.typelib exit 1  # [win]

about:
  home: https://wiki.gnome.org/Projects/LibRsvg
  license: LGPL-2.1-or-later
  license_file: COPYING.LIB
  license_family: LGPL
  summary: librsvg is a library to render SVG files using cairo.
  description: |
    Librsvg is a small library to render Scalable Vector Graphics
    (SVG), associated with the GNOME Project.  It renders
    SVG files to Cairo surfaces.  Cairo is the 2D, antialiased
    drawing library that GNOME uses to draw things to the screen or to
    generate output for printing.
  dev_url: https://gitlab.gnome.org/GNOME/librsvg
  doc_url: https://gnome.pages.gitlab.gnome.org/librsvg/doc/librsvg/index.html

extra:
  recipe-maintainers:
    - pkgw
    - tschoonj
