{% set version = "3.7.2" %}

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

source:
  url: https://github.com/libarchive/libarchive/archive/v{{ version }}.tar.gz
  sha256: 63b40acff57467f7d3a64981d4bcff60b52f539fae7688aaaaee27a448b10266
  patches:
    - patches/0001-Add-lib-to-CMAKE_FIND_LIBRARY_PREFIXES-for-lzma.patch
    - patches/0003-VC9-compatibility-test-for-BCryptDeriveKeyPBKDF2.patch
    - patches/0004-VC9-compatibility-define-BCRYPT_SUCCESS.patch
    # This should not be applied in general. It exists so I can build it for
    # debugging Visual Studio where warnings are errors for some reason.
    # Hiding warnings is poor practice.
    # - patches/0005-VC9-compatibility-ignore-some-warnings.patch
    - patches/0006-VC-openssl-define-inline-as-__inline.patch
    # These warnings are errors when compiling lz-4 support
    - patches/0007-CMake-VC9-compatibility-ignore-some-warnings.patch

build:
  number: 0

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

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

    requirements:
      build:
        - {{ compiler('c') }}
        # Does not work in this recips at present
        # we manually convert C99 to C89 instead.
        # - c99-to-c89  # [win and vc<14]
        - msinttypes  # [win and vc<14]
        - autoconf    # [unix]
        - automake    # [unix]
        - libtool     # [unix]
        - pkg-config  # [unix]
        - cmake       # [win]
        - make        # [unix]
        - ninja       # [win]
        - m2-patch    # [win]
      host:
        - msinttypes  # [win and vc<14]
        - bzip2
        - libiconv    # [osx]
        - lz4-c
        - xz
        - lzo
        - openssl
        - libxml2
        - zlib
        - zstd
    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:
      skip: true  # [win]
    requirements:
      build:
        - {{ compiler('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
    - mingwandroid
    - ocefpaf
