{% set rocky_version = "8.9" %}
{% set glibc_version = "2.28" %}
{% set kernel_headers_version = "4.18.0" %}
{% set build_number = "1" %}

{% set rpm_url = "https://download.rockylinux.org/vault/rocky/" ~ rocky_version ~ "/BaseOS/" ~ centos_machine ~ "/os/Packages" %}
{% set appstream_rpm_url = "https://download.rockylinux.org/vault/rocky/" ~ rocky_version ~ "/AppStream/" ~ centos_machine ~ "/os/Packages" %}
{% set powertools_rpm_url = "https://download.rockylinux.org/vault/rocky/" ~ rocky_version ~ "/PowerTools/" ~ centos_machine ~ "/os/Packages" %}

package:
  name: linux-sysroot
  version: {{ glibc_version }}

source:
  # for calculating the hashes below, you can run `python update.py`
  # in the recipe folder (after ensuring the versions in CBC are correct)
  # START source
  - folder: binary-glibc
    url: {{ rpm_url }}/g/glibc-2.28-236.el8_9.13.{{ centos_machine }}.rpm
    sha256: b245492a8d830a9e2f8ee1a6d24333559bf80f885c511a7643749ce35045a1b0  # [cross_target_platform == "linux-64"]
    sha256: 553c0240b0ff5c6c0d8aedf0bd46d6bb1a9784c9fcd04af4bff1fa56f12e6c34  # [cross_target_platform == "linux-aarch64"]

  - folder: binary-glibc-all-langpacks
    url: {{ rpm_url }}/g/glibc-all-langpacks-2.28-236.el8_9.13.{{ centos_machine }}.rpm
    sha256: 6b5d8154e5879cd6b72bb39ac155f01945e31ed0f24658077984c80569062691  # [cross_target_platform == "linux-64"]
    sha256: 33e70521847cfbdf0546ee06facf23c39741dab4e4d2c5ff75e6275999e6feef  # [cross_target_platform == "linux-aarch64"]

  - folder: binary-glibc-common
    url: {{ rpm_url }}/g/glibc-common-2.28-236.el8_9.13.{{ centos_machine }}.rpm
    sha256: 0717831be3893442ee3433f30ce9af15789b20a91ddbad0cefa3f76707365d59  # [cross_target_platform == "linux-64"]
    sha256: 3e0c92a02ae6704f22546c64b3e9b19dc36c724fc17fc7a3346bcaca45e77adf  # [cross_target_platform == "linux-aarch64"]

  - folder: binary-glibc-devel
    url: {{ rpm_url }}/g/glibc-devel-2.28-236.el8_9.13.{{ centos_machine }}.rpm
    sha256: f12426894a073245c0e159747edd2e43c062b1402bc6871dc8bdf6efbb564b4c  # [cross_target_platform == "linux-64"]
    sha256: 8b38670e1c370541e4a63373b45e429f3970d9289094332b1854d899c9472570  # [cross_target_platform == "linux-aarch64"]

  - folder: binary-glibc-gconv-extra
    url: {{ rpm_url }}/g/glibc-gconv-extra-2.28-236.el8_9.13.{{ centos_machine }}.rpm
    sha256: 4c71893e437e55c14020d6843a91cd33c0691c330fe9c7ce8991b839fd7b4137  # [cross_target_platform == "linux-64"]
    sha256: 59f9a7ff7eb3abea83d38efa40a38927bc40a1c6538ec41d57eedbeb2ff7d79d  # [cross_target_platform == "linux-aarch64"]

  - folder: binary-glibc-headers
    url: {{ rpm_url }}/g/glibc-headers-2.28-236.el8_9.13.{{ centos_machine }}.rpm
    sha256: 8169525314b2c212da60c3f10a7515debd883fef7e056070fbc6cc4ff63eaefc  # [cross_target_platform == "linux-64"]
    sha256: a55155dee5e2319b1bdf19d268cede6007c35e7c7a0c20b5e29b5aa0969b9132  # [cross_target_platform == "linux-aarch64"]

  - folder: binary-glibc-static
    url: {{ powertools_rpm_url }}/g/glibc-static-2.28-236.el8_9.13.{{ centos_machine }}.rpm
    sha256: 02eac28a7fda9f3541b880ae896582765f875a8293165ca351b7b24b6d385e9e  # [cross_target_platform == "linux-64"]
    sha256: ccab4baf384a61c857120bcf29247dfb23a4bcee97392a341b5536c556a57d67  # [cross_target_platform == "linux-aarch64"]

  - folder: binary-kernel-headers
    url: {{ rpm_url }}/k/kernel-headers-4.18.0-513.24.1.el8_9.{{ centos_machine }}.rpm
    sha256: 9e6b11688073157daa2b14868002d890f4adc3d6afe11e95cf3ee22d128c611a  # [cross_target_platform == "linux-64"]
    sha256: 342d3ce38ce5fc9efca741a556d7f87d15c202730af80777e2c9a611001636c3  # [cross_target_platform == "linux-aarch64"]
  # END source

build:
  number: {{ build_number }}
  noarch: generic
  # This package builds cross targets so only need to run once.
  skip: True  # [not (linux and x86_64)]

outputs:
  - name: kernel-headers_{{ cross_target_platform }}
    version: {{ kernel_headers_version }}
    script: build-kernel-headers.sh
    build:
      noarch: generic
      binary_relocation: False
      detect_binary_files_with_prefix: False
    requirements:
      run_constrained:
        - sysroot_{{ cross_target_platform }} =={{ glibc_version }}
    test:
      commands:
        test -f $PREFIX/{{ target_machine }}-{{ ctng_vendor }}-linux-gnu/sysroot/usr/include/linux/version.h

  - name: sysroot_{{ cross_target_platform }}
    script: build-sysroot.sh
    build:
      missing_dso_whitelist:
        - '*'
      noarch: generic
      binary_relocation: False
      detect_binary_files_with_prefix: False
      run_exports:
        strong:
          - __glibc >={{ glibc_version }},<3.0.a0
    requirements:
      host:
        - tzdata
        - __glibc >={{ glibc_version }}
      run:
        - {{ pin_subpackage('kernel-headers_' ~ cross_target_platform, exact=True) }}
        - tzdata
    test:
      commands:
        - test -f $PREFIX/{{ target_machine }}-conda-linux-gnu/sysroot/lib/libc.so.6
        - test -f $PREFIX/{{ target_machine }}-conda-linux-gnu/sysroot/sbin/ldconfig
        - test -f $PREFIX/{{ target_machine }}-conda-linux-gnu/sysroot/usr/lib/crt1.o
        - test -f $PREFIX/{{ target_machine }}-conda-linux-gnu/sysroot/usr/include/limits.h
        - test -f $PREFIX/{{ target_machine }}-conda-linux-gnu/sysroot/usr/include/gnu/stubs-64.h  # [cross_target_platform == "linux-64"]
        - test -f $PREFIX/{{ target_machine }}-conda-linux-gnu/sysroot/usr/include/gnu/stubs.h  # [cross_target_platform != "linux-64"]
        - test -d $PREFIX/{{ target_machine }}-conda-linux-gnu/sysroot/usr/share/locale
        - test -f $PREFIX/{{ target_machine }}-conda-linux-gnu/sysroot/usr/bin/ldd
        - test -f $PREFIX/{{ target_machine }}-{{ ctng_vendor }}-linux-gnu/sysroot/lib/libc.so.6
        - find "${PREFIX}" \( -name 'libnsl*' -o -path '*/rpcsvc/yp*' \) | { ! grep . ; }
        - find "${PREFIX}" \( -name 'libcrypt*' -o -name 'crypt.*' \) | { ! grep . ; }

about:
  home: https://download.rockylinux.org/vault/rocky/{{ rocky_version }}
  license: LGPL-2.0-or-later AND LGPL-2.0-or-later WITH exceptions AND GPL-2.0-or-later
  license_family: GPL
  license_file: LICENSE
  # license files are packaged with source
  summary: "(CDT) The GNU libc libraries and header files for the Linux kernel for use by glibc"
  description: |
        The glibc package contains standard libraries which are used by multiple
        programs on the system. In order to save disk space and memory, as well as to
        make upgrading easier, common system code is kept in one place and shared
        between programs. This particular package contains the most important sets of
        shared libraries: the standard C library and the standard math library.
        Without these two libraries, a Linux system will not function.

        Kernel-headers includes the C header files that specify the interface between
        the Linux kernel and userspace libraries and programs.  The header files
        define structures and constants that are needed for building most standard
        programs and are also needed for rebuilding the glibc package.

extra:
  skip-lints:
    - missing_dev_url
    - missing_documentation
    - incorrect_license
    - host_section_needs_exact_pinnings
  recipe-maintainers:
    - isuruf
    - scopatz
    - beckermr
