{% set name = "libiconv" %}
{% set version = "1.18" %}

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

source:
  - url: https://ftp.gnu.org/pub/gnu/{{ name }}/{{ name }}-{{ version }}.tar.gz
    sha256: 3b08f5f4f9b4eb82f151a7040bfd6fe6c6fb922efe4b1659c66ea933276965e8
    patches:
      - patches/glibc.patch  # [linux]
      - patches/CMakeLists.txt.patch  # [win]
      - patches/config.h.patch  # [win]
      - patches/configure.cmake.patch  # [win]
      - patches/utf_8_mac.patch  # [osx]
      - patches/fix-aclocal-exact-tool-pin.patch  # [osx]

build:
  number: 0
  
requirements:
  build:
    - {{ compiler('c') }}
    - {{ stdlib('c') }}
    - automake  # [osx]
    - autoconf  # [osx]
    - groff     # [osx]
    - gperf     # [osx]
    - libtool   # [unix]
    - cmake <4  # [win]
    - ninja-base  # [win]
    - make      # [unix]

outputs:
  - name: libiconv
    script: install.sh   # [unix]
    script: install.bat  # [win]
    build:
      run_exports:
        # Pretty good recently, let's trust them.
        # https://abi-laboratory.pro/tracker/timeline/libiconv
        - {{ pin_subpackage('libiconv') }}
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ stdlib('c') }}
        - cmake <4  # [win]
        - ninja-base     # [win]
        - libtool   # [unix]
        - make      # [unix]

    test:
      requires:
        - jq          # [unix]
        - pkg-config  # [win]
      commands:
        - iconv -l  # [unix]
        # Ensuring iconv executable is not present.
        # Otherwise the included license is wrong and should be GPL-3.0-only.
        - test ! -f ${PREFIX}/bin/iconv                   # [unix]
        - if exist %LIBRARY_PREFIX%\bin\iconv.exe exit 1  # [win]
        # Ensuring libiconv documentation and man pages is not present.
        # Otherwise inlcuded license is wrong and should be GPL-3.0-only.
        - test_man_files=$(jq '.files[] | select( . | startswith("share/man"))' $CONDA_PREFIX/conda-meta/{{ PKG_NAME }}-{{ PKG_VERSION }}-${PKG_BUILD_STRING}.json)  # [unix]
        - if [[ ${test_man_files} ]]; then echo "found GPL licensed files being packaged ${test_man_files}"; exit 1; fi  # [unix]
        - test_doc_files=$(jq '.files[] | select( . | startswith("share/doc"))' $CONDA_PREFIX/conda-meta/{{ PKG_NAME }}-{{ PKG_VERSION }}-${PKG_BUILD_STRING}.json)  # [unix]
        - if [[ ${test_doc_files} ]]; then echo "found GPL licensed files being packaged ${test_doc_files}"; exit 1; fi  # [unix]
        - if exist "%LIBRARY_PREFIX%\share\man\man3\iconv*" exit 1   # [win]
        - if exist "%LIBRARY_PREFIX%\share\doc\iconv*" exit 1        # [win]
        # Assert libraries are present
        - test -f $PREFIX/lib/libiconv${SHLIB_EXT}         # [unix]
        - test -f $PREFIX/lib/libcharset${SHLIB_EXT}       # [unix]
        - if not exist %LIBRARY_PREFIX%\lib\iconv.lib exit 1    # [win]
        - if not exist %LIBRARY_PREFIX%\lib\charset.lib exit 1  # [win]
        - if not exist %LIBRARY_PREFIX%\bin\iconv.dll exit 1    # [win]
        - if not exist %LIBRARY_PREFIX%\bin\charset.dll exit 1  # [win]
        # Regression test for https://github.com/conda-forge/libiconv-feedstock/issues/48
        - pkg-config --help  # [win]
    
    about:
      home: https://www.gnu.org/software/libiconv
      license: LGPL-2.1-only
      license_file: COPYING.LIB
      summary: Provides iconv for systems which don't have one (or that cannot convert from/to Unicode.)

about:
  home: https://www.gnu.org/software/libiconv
  license: GPL-3.0-or-later
  license_file: 
    - COPYING
    - COPYING.LIB
  license_family: GPL3
  summary: "Provides iconv for systems which don't have one (or that cannot convert from/to Unicode.)"
  description: |
    This library provides an iconv() implementation, for use on systems which don't have one,
    or whose implementation cannot convert from/to Unicode.
  doc_url: https://www.gnu.org/savannah-checkouts/gnu/libiconv/documentation/libiconv-1.18/iconv.1.html
  dev_url: https://git.savannah.gnu.org/cgit/libiconv.git/tree

extra:
  recipe-maintainers:
    - ocefpaf
    - jakirkham
    - jhamman
    - mingwandroid
    - scopatz
