{% set version = "3.54.0" %}
{% set year = "2026" %}
{% set version_split = version.split(".") %}
{% set major = version_split[0] %}
{% set minor = version_split[1]|int * 10 %}
{% set bugfix = version_split[2]|int * 100 %}
{% set version_coded=(major ~ (("%03d" % minor)|string) ~ (("%03d" % bugfix)|string)) %}
{% set build_number = 1 %}
{% if with_icu|string|lower == "false" %}
# deprioritize with_icu variant via build number
{% set build_number = build_number + 100 %}
{% endif %}

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

source:
  url: https://www.sqlite.org/{{ year }}/sqlite-autoconf-{{ version_coded }}.tar.gz
  sha256: 134ec0802dda5795816e25d25872d20b312cb3973438c49b30bc40b7705ea9ed

build:
  number: {{ build_number }}

requirements:
  build:
    - {{ compiler('c') }}
    - {{ stdlib("c") }}
    - make  # [not win]
  host:
    - icu  # [with_icu]
    - ncurses  # [not win]
    - readline  # [not win]
    - zlib  # [not win]


outputs:
  - name: libsqlite
    build:
      run_exports:
        # sometimes adds new symbols.  Default behavior is OK.
        #    https://abi-laboratory.pro/tracker/timeline/sqlite/
        - {{ pin_subpackage('libsqlite') }}
    files:
      - lib/libsqlite*             # [unix]
      - include/sqlite*.h          # [unix]
      - lib/pkgconfig/sqlite3.pc   # [unix]
      - Library\bin\sqlite3.dll    # [win]
      - Library\lib\sqlite3.lib    # [win]
      - Library\include\sqlite*.h  # [win]
      - Library\lib\pkgconfig\sqlite3.pc  # [win]
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ stdlib("c") }}
        - make  # [not win]
      host:
        # readline and ncurses are only required by the executable
        # not the library. Leaving it out of the host requirements
        # ensures it doesn't appear in the run section (through run_export)
        - icu  # [with_icu]
        - zlib  # [not win]
      run_constrained:
        - icu <0.0a0  # [not with_icu and not win]
    test:
      commands:
        - test -f $PREFIX/lib/libsqlite3${SHLIB_EXT}  # [not win]
        - test ! -f $PREFIX/lib/libsqlite3.a  # [not win]
        - test -f $PREFIX/include/sqlite3.h  # [not win]
        - test -f $PREFIX/include/sqlite3ext.h  # [not win]
        - test -f $PREFIX/lib/pkgconfig/sqlite3.pc  # [not win]
        - if not exist %PREFIX%\\Library\bin\sqlite3.dll exit 1  # [win]
        - if not exist %PREFIX%\\Library\lib\sqlite3.lib exit 1  # [win]
        - if not exist %PREFIX%\\Library\include\sqlite3.h exit 1  # [win]
        - if not exist %PREFIX%\\Library\include\sqlite3ext.h exit 1  # [win]
        - if not exist %PREFIX%\\Library\lib\pkgconfig\sqlite3.pc exit 1  # [win]
  - name: sqlite
    build:
      run_exports:
        # sometimes adds new symbols.  Default behavior is OK.
        #    https://abi-laboratory.pro/tracker/timeline/sqlite/
        - {{ pin_subpackage('libsqlite') }}
    files:
      - bin/sqlite3              # [unix]
      - Library\bin\sqlite3.exe  # [win]
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ stdlib("c") }}
        - make  # [not win]
      host:
        - icu  # [with_icu]
        - ncurses  # [not win]
        - readline  # [not win]
        - zlib  # [not win]
      run:
        - {{ pin_subpackage('libsqlite', exact=True) }}
      # sqlite depends on libsqlite exactly, so the constraint applies
      # to the CLI package too
      # run_constrained:
      #  - icu <0.0a0  # [not with_icu and not win]
    test:
      commands:
        - sqlite3 --version
        - echo "PRAGMA compile_options;" | sqlite3  # [not win]
        - echo PRAGMA compile_options; | sqlite3    # [win]
        - ldd $PREFIX/bin/sqlite3       # [linux and build_platform == target_platform]
        - otool -L $PREFIX/bin/sqlite3  # [osx and build_platform == target_platform]
        - ldd $PREFIX/bin/sqlite3 | grep -q libreadline       # [linux and build_platform == target_platform]
        - otool -L $PREFIX/bin/sqlite3 | grep -q libreadline  # [osx and build_platform == target_platform]
        # Verify DQS=3 behavior in both DML and DDL through the libsqlite dependency.
        - 'sqlite3 -bail :memory: ''SELECT "dqs_probe"; CREATE TABLE t(x CHECK (x = "dqs_probe"));'''  # [not win]
        - 'echo SELECT "dqs_probe"; CREATE TABLE t(x CHECK (x = "dqs_probe")); | sqlite3 -bail :memory:'  # [win]

about:
  home: http://www.sqlite.org/
  license: blessing
  license_url: http://www.sqlite.org/copyright.html
  summary: C library that implements an SQL database engine
  description: |
    SQLite is a small, fast, serverless SQL database engine. Programs that
    link with this library get SQL database access without running a
    separate RDBMS process.
  doc_url: http://www.sqlite.org/docs.html
  doc_source_url: https://www.sqlite.org/src/dir?ci=trunk&name=doc
  dev_url: https://www.sqlite.org/src/dir?ci=trunk

extra:
  recipe-maintainers:
    - jakirkham
    - msarahan
    - ocefpaf
    - flaviomartins
    - h-vetinari
