{% set alma_version = "9.5" %}
{% set glibc_version = "2.34" %}
{% set kernel_headers_version = "5.14.0" %}
{% set build_number = "2" %}

{% set rpm_url = "https://repo.almalinux.org/vault/" ~ alma_version ~ "/BaseOS/" ~ centos_machine ~ "/os/Packages" %}
{% set appstream_rpm_url = "https://repo.almalinux.org/vault/" ~ alma_version ~ "/AppStream/" ~ centos_machine ~ "/os/Packages" %}
{% set crb_rpm_url = "https://repo.almalinux.org/vault/" ~ alma_version ~ "/CRB/" ~ 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 (only `alma_version` needs to be set therein)
  # START source
  - folder: binary-glibc
    url: {{ rpm_url }}/glibc-2.34-125.el9_5.8.alma.1.{{ centos_machine }}.rpm
    sha256: 1848b9ced2dfec6c206791b23a5a8a6356939c5ed0492fc91c86bf1d3a255c1d  # [cross_target_platform == "linux-64"]
    sha256: 9d850f1736fdad076c46fbcae4355fbfdc63b1a13be112b01281a93029bd3b46  # [cross_target_platform == "linux-aarch64"]
    sha256: 1a128d79d70f4790f78f84bcf4fdcfd22d7aea0b1fad678e2690db1909beea41  # [cross_target_platform == "linux-ppc64le"]
    sha256: 9c685fdecfe7007163bd9759b75aca60f3fa27c33d16483e1b11b3b54c83157f  # [cross_target_platform == "linux-s390x"]

  - folder: binary-glibc-all-langpacks
    url: {{ rpm_url }}/glibc-all-langpacks-2.34-125.el9_5.8.alma.1.{{ centos_machine }}.rpm
    sha256: ce0681b433af2cf99b5da9e6f711087da4696a26dde4732b312ccf9a7c505536  # [cross_target_platform == "linux-64"]
    sha256: c70ca549a0fbc2bc2825837e28b9de1bd1ca474df21f95de367c48cde804c87e  # [cross_target_platform == "linux-aarch64"]
    sha256: 5717a4fdfa9a8d1117b3238b1b56204065250886cc7bd9db9ab1ae7da28b4c2f  # [cross_target_platform == "linux-ppc64le"]
    sha256: 3a0b7b2c01cdd00b517ce4c19fd0f1b51ea42c66390f7a94dc0e57e58410fa1d  # [cross_target_platform == "linux-s390x"]

  - folder: binary-glibc-common
    url: {{ rpm_url }}/glibc-common-2.34-125.el9_5.8.alma.1.{{ centos_machine }}.rpm
    sha256: 5b8582afb69c49880c2ceab98b392c22778e4670f348e8eb76697bd00c8f074e  # [cross_target_platform == "linux-64"]
    sha256: 5d4a52d5bdf07b9799ff80626451db59ddc32a9eba4c0582a982e7ed11a86306  # [cross_target_platform == "linux-aarch64"]
    sha256: 5ed8b096d3001291168e2688d39c1996ef00c1c68391f94c9abd86ef5f0ee4ef  # [cross_target_platform == "linux-ppc64le"]
    sha256: dbbc3dd80cfcb8456612682ddd80024690edf37b57ceb049d0ea343c36366387  # [cross_target_platform == "linux-s390x"]

  - folder: binary-glibc-devel
    url: {{ appstream_rpm_url }}/glibc-devel-2.34-125.el9_5.8.alma.1.{{ centos_machine }}.rpm
    sha256: bc0b102d7f9a6f730c75b8800e87a419b95c4ac8a20734e815bac45de7564e0c  # [cross_target_platform == "linux-64"]
    sha256: 4b5bd0c424b1ae5b9272de14e9dff24756316ff894fa91ed946a68e88d1cf9a6  # [cross_target_platform == "linux-aarch64"]
    sha256: f2a4303a2ec5d9d64b1de0401e740ed9f624c4e4bd47c6608792d11feb8ee485  # [cross_target_platform == "linux-ppc64le"]
    sha256: b50fe1ffc31801e732afabad2f7a3630147306721d308a51dee4354ee907bda3  # [cross_target_platform == "linux-s390x"]

  - folder: binary-glibc-gconv-extra
    url: {{ rpm_url }}/glibc-gconv-extra-2.34-125.el9_5.8.alma.1.{{ centos_machine }}.rpm
    sha256: b21cebfd6e96a3f8f8eb02b2317e69528649355657fe44a66b4b6dcc03fec638  # [cross_target_platform == "linux-64"]
    sha256: c60c4aa567dc37cbc7247cb981996d04f09f4ff4cf553ad5cdc346d66da768cc  # [cross_target_platform == "linux-aarch64"]
    sha256: 50808a6a71fd9a3d5b3db2604f825af8aa6cf0020dd8f1d0edca1b0bc77729f9  # [cross_target_platform == "linux-ppc64le"]
    sha256: e7a9df0d9eb747b1dacf13636a4defb42123a0aa3d166adff9970736d1be073c  # [cross_target_platform == "linux-s390x"]

  - folder: binary-glibc-headers                                              # [cross_target_platform in ("linux-64", "linux-s390x")]
    url: {{ appstream_rpm_url }}/glibc-headers-2.34-125.el9_5.8.alma.1.{{ centos_machine }}.rpm  # [cross_target_platform in ("linux-64", "linux-s390x")]
    sha256: 77fd486c81e4b841f52ac58fe0a713fb71fe3c688548e006b0752dd322616116  # [cross_target_platform == "linux-64"]
    sha256: d2188c627c579568192af0c25583b1bd442c39182a08c94391ccab2f727ecdf4  # [cross_target_platform == "linux-s390x"]

  - folder: binary-glibc-static
    url: {{ crb_rpm_url }}/glibc-static-2.34-125.el9_5.8.alma.1.{{ centos_machine }}.rpm
    sha256: 25a5b3547626c2d255a2f54333558b5d2e8054f305bbf8a2da85e11b187faec9  # [cross_target_platform == "linux-64"]
    sha256: 8d196658cb4a590bd1d587ced02f2396d8db3ce47d12b9ed1c5aba0f4ab57fbb  # [cross_target_platform == "linux-aarch64"]
    sha256: d4a8ada450f1629e58c1c3907f48f58c4fcd9587515fa7110f870e437f777be6  # [cross_target_platform == "linux-ppc64le"]
    sha256: ea543fc40c4a1746fde6bbe4d48f8b969dd4c9bedf000327fe44297d68c9171a  # [cross_target_platform == "linux-s390x"]

  - folder: binary-kernel-headers
    url: {{ appstream_rpm_url }}/kernel-headers-5.14.0-503.40.1.el9_5.{{ centos_machine }}.rpm
    sha256: df35eddfb6142d6f610c18580c8f95c2fcc7f2f6c14d3229d9bf2003a55042fc  # [cross_target_platform == "linux-64"]
    sha256: c7c218002ed32f236a3b94c6f277f147c855d670e506a5b2a894a863e7f6f188  # [cross_target_platform == "linux-aarch64"]
    sha256: befded36522113167ff4e8bd18e47b3134510e59deb2399c6ef4996b6b063e32  # [cross_target_platform == "linux-ppc64le"]
    sha256: 568f164c6beccf5fdba181f7bdc05f9dc3f1b915c53171a59d1f03f29f2cfb27  # [cross_target_platform == "linux-s390x"]
  # END source

build:
  number: {{ build_number }}
  noarch: generic
  missing_dso_whitelist:
    - '*'

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:
      noarch: generic
      binary_relocation: False
      detect_binary_files_with_prefix: False
      track_features:
        - sysroot_{{ cross_target_platform }}_{{ glibc_version }}               # [with_features]
        - sysroot_{{ cross_target_platform }}_{{ glibc_version }}_feature_2     # [with_features]
        - sysroot_{{ cross_target_platform }}_{{ glibc_version }}_feature_3     # [with_features]
      run_exports:
        strong:
          - __glibc >={{ glibc_version }},<3.0.a0
    requirements:
      host:
        - tzdata
      run:
        - __glibc >={{ glibc_version }}     # [not with_features]
        - {{ 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://repo.almalinux.org/vault/{{ alma_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:
  recipe-maintainers:
    - isuruf
    - scopatz
    - beckermr
