{% set name = "libsolv" %}
{% set version = "0.7.32" %}
{% set sha256 = "8c5957fb417823768d70e0faefa6f75f497f41289641256e4fdfecd1954fa16c" %}

# For dispatching between Unix and Windows
{% set install_prefix = "." %}  # [unix]
{% set install_prefix = "Library" %}  # [win]
{% set shlib_ext = "so" %}  # [linux]
{% set shlib_ext = "dylib" %}  # [unix and not linux]
{% set shlib_ext = "dll" %}  # [win]

package:
  # Setting a dummy name, because multi-output behaviour with similar name has surprising behaviour
  name: {{ name|lower }}-split
  version: {{ version }}

source:
  fn: {{ name }}-{{ version }}.tar.gz
  url: https://github.com/openSUSE/libsolv/archive/{{ version }}.tar.gz
  sha256: {{ sha256 }}
  patches:
    - win_export_and_static_build.patch  # [win]
    - conda_variant_priorization.patch
    - no_error_subdir_mismatch.patch
    - add-missing-headers.patch  # For libsolv<=0.7.32

build:
  number: 2
  run_exports:
    - {{ pin_subpackage(name, max_pin='x.x.x') }}

requirements:
  build:
    - {{ compiler('c') }}
    - {{ stdlib("c") }}
    - {{ compiler('cxx') }}
    - ninja
    - cmake
  host:
    - zlib

outputs:
  - name: libsolv
    script: build_libsolv.sh  # [unix]
    script: build_libsolv.bat  # [win]
    build:
      run_exports:
        - {{ pin_subpackage('libsolv', max_pin='x.x') }}
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ stdlib("c") }}
        - {{ compiler('cxx') }}
        - ninja
        - cmake
      host:
        - zlib
    test:
      requires:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - ninja
        - cmake
      files:
        - test/*
      commands:
        - test -f "${PREFIX}/lib/libsolv${SHLIB_EXT}"         # [unix]
        - test -f "${PREFIX}/lib/libsolvext${SHLIB_EXT}"      # [unix]
        - test -f "${PREFIX}/lib/libsolv.so.1"                # [linux]
        - test -f "${PREFIX}/include/solv/repo.h"             # [unix]
        - if not exist %LIBRARY_INC%\solv\repo.h (exit 1)     # [win]
        - if not exist %LIBRARY_BIN%\solv.dll (exit 1)        # [win]
        - if not exist %LIBRARY_LIB%\solv.lib (exit 1)        # [win]
        - if not exist %LIBRARY_BIN%\solvext.dll (exit 1)     # [win]
        - if not exist %LIBRARY_LIB%\solvext.lib (exit 1)     # [win]
        - if exist %LIBRARY_LIB%\solv_static.lib (exit 1)     # [win]
        - if exist %LIBRARY_LIB%\solvext_static.lib (exit 1)  # [win]
        # Running the executables
        - dumpsolv.exe -h  # [win]
        - dumpsolv -h      # [unix]
        # Running a test trying to link to the library
        - cmake -G Ninja -S test/ -B build/ -D LIB_NAME="libsolv${SHLIB_EXT}" ${CMAKE_ARGS}  # [unix]
        - cmake -G Ninja -S test/ -B build/ -D LIB_NAME="solv" %CMAKE_ARGS%                  # [win]
        - cmake --build build/
        - cmake --build build --target test

  - name: libsolv-static
    script: build_libsolv.sh  # [unix]
    script: build_libsolv.bat  # [win]
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ stdlib("c") }}
        - {{ compiler('cxx') }}
        - ninja
        - cmake
      host:
        - zlib
        - {{ pin_subpackage("libsolv", exact=True) }}
      run:
        - {{ pin_subpackage("libsolv", exact=True) }}
    test:
      requires:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - ninja
        - cmake
      files:
        - test/*
      commands:
        - test -f "${PREFIX}/lib/libsolv.a"     # [unix]
        - test -f "${PREFIX}/lib/libsolvext.a"  # [unix]
        - if not exist %LIBRARY_LIB%\solv_static.lib (exit 1)     # [win]
        - if not exist %LIBRARY_LIB%\solvext_static.lib (exit 1)  # [win]
        # Running a test trying to link to the library
        - cmake -G Ninja -S test/ -B build/ -D LIB_NAME="libsolv.a" ${CMAKE_ARGS}   # [unix]
        - cmake -G Ninja -S test/ -B build/ -D LIB_NAME="solv_static" %CMAKE_ARGS%  # [win]
        - cmake --build build/
        - cmake --build build --target test

about:
  home: https://github.com/openSUSE/libsolv
  license: BSD-3-Clause
  license_family: BSD
  license_file: LICENSE.BSD
  summary: Library for solving packages and reading repositories
  description: libsolv, a free package dependency solver using a satisfiability algorithm.
  dev_url: https://github.com/openSUSE/libsolv

extra:
  recipe-maintainers:
    - AntoinePrv
    - pavelzw
    - SylvainCorlay
    - JohanMabille
    - wolfv
    - davidbrochart
    - adriendelsalle
