{% set version = "3.8.1" %}

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

source:
  url: https://github.com/libarchive/libarchive/archive/v{{ version }}.tar.gz
  sha256: ad5dfe0d9a5999494c445b9bc3271d84160950bb1790cf892fb132f563d036b6
  patches:
    - patches/0001-Add-lib-to-CMAKE_FIND_LIBRARY_PREFIXES-for-lzma.patch

{% set build = 0 %}
{% if license_family == 'gpl' %}
    {% set build = build + 100 %}
{% endif %}

build:
  number: {{ build }}
  string: {{ license_family }}_h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}

outputs:
  - name: libarchive
    script: build_libarchive.sh  # [unix]
    script: build_libarchive.bat  # [win]

    build:
      string: {{ license_family }}_h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}
      run_exports:
        # https://abi-laboratory.pro/index.php?view=timeline&l=libarchive
        - {{ pin_subpackage('libarchive', max_pin='x.x') }}

    requirements:
      build:
        - {{ compiler('c') }}
        - {{ stdlib('c') }}
        - autoconf    # [unix]
        - automake    # [unix]
        - libtool     # [unix]
        - pkg-config  # [unix]
        - cmake <4    # [win]
        - make        # [unix]
        - ninja       # [win]
        - m2-patch    # [win]
      host:
        - bzip2
        - libiconv    # [osx]
        - lz4-c
        - liblzma-devel
    {% if license_family == 'gpl' %}
        - lzo
    {% endif %}
        - openssl
        - libxml2
        - zlib
        - zstd
    {% if license_family != 'gpl' %}
      run_constrained:
        # isuruf/xhochy/hmaarrfk - 2025/03
        # We wish to communicate to the end user that if
        # libarchive and lzo are co-installed, then libarchive
        # can take advantage of it
        # If there is a good reason to remove this constraint, lets discuss!
        - lzo <0.0a0
    {% endif %}
    test:
      files:
        - test/hello_world.xar
      commands:
        # Verify pkg-config file is in place.
        - test -f "${PREFIX}/lib/pkgconfig/libarchive.pc"  # [unix]

        # Verify headers are in place.
        - test -f "${PREFIX}/include/archive.h"            # [unix]
        - test -f "${PREFIX}/include/archive_entry.h"      # [unix]

        # Verify libraries are in place.
        - test -f "${PREFIX}/lib/libarchive.a"             # [unix]
        - test -f "${PREFIX}/lib/libarchive${SHLIB_EXT}"   # [unix]

        # Check for commands
        - bsdcat --version
        - bsdcpio --version
        - bsdtar --version
        - bsdtar -tf test/hello_world.xar


  - name: libarchive-minimal-static
    script: build_minimal.sh
    build:
      string: {{ license_family }}_h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}
      skip: true  # [win]
      {% if license_family == 'gpl' %}
      skip: true
      {% endif %}
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ stdlib("c") }}
        - autoconf    # [unix]
        - automake    # [unix]
        - libtool     # [unix]
        - pkg-config  # [unix]
        - make        # [unix]
      host:
        - libiconv    # [osx]
        - bzip2
        - zlib
        - zstd

    test:
      commands:
        # Verify pkg-config file is in place.
        - test -f "${PREFIX}/lib/pkgconfig/libarchive.pc"  # [unix]

        # Verify headers are in place.
        - test -f "${PREFIX}/include/archive.h"            # [unix]
        - test -f "${PREFIX}/include/archive_entry.h"      # [unix]

        # Verify libraries are in place.
        - test -f "${PREFIX}/lib/libarchive.a"             # [unix]

about:
  home: http://www.libarchive.org/
  summary: Multi-format archive and compression library
  license: BSD-2-Clause
  license_file: COPYING
  license_family: BSD

extra:
  recipe-maintainers:
    - jakirkham
    - ocefpaf
    - jjerphan
