<commit_before>{ stdenv
, fetchurl
, fetchFromGitHub
, lib
, python3Packages
}:

# TODO: build release tarballs, repo vendors pdfs

let
  date = "2019-03-01";
in
stdenv.mkDerivation rec {
  name = "opengl-headers-${date}";

  src = fetchurl {
    name = "opengl-headers-${date}.tar.xz";
    multihash = "QmdguDdKPiByjdNGu5bCpsoPcHyrTXq5UoycS3hrpZMtNX";
    sha256 = "64a86c8157ebb9fcdc3adaf563d28e65ad6b0b85b9a609fad0890b5c61ccb423";
  };

  configurePhase = ":";

  buildPhase = ":";

  installPhase = ''
    for api in GL{,ES{,2,3},SC{,2}}; do
      pushd $api/
        while read header; do
          install -D -m644 -v $header $out/include/$(basename "$api")/$header
        done < <(find . -name "*.h" -printf '%P\n')
      popd
    done

    for xml in xml/*.xml; do
      install -D -m644 -v "$xml" \
        "$out"/share/opengl-registry/"$(basename "$xml")"
    done
  '';

  passthru = {
    generateDistTarball = stdenv.mkDerivation rec {
      name = "opengl-headers-${date}";

      src = fetchFromGitHub {
        version = 6;
        owner = "KhronosGroup";
        repo = "OpenGL-Registry";
        rev = "68dba34a93b67d626b1c8b7294e4562bdaf4c996";
        sha256 = "6046f2eef181fe96379d23938de26e32621a59061d384b946db7e969bf16e99a";
      };

      nativeBuildInputs = [
        python3Packages.lxml
        python3Packages.python
      ];

      postPatch = ''
        sed -i xml/genglvnd.py \
          -e 's,drafts/,,'

        # Fix impure date in headers
        grep -q "time.strftime('%Y%m%d')" xml/genheaders.py
        sed -i xml/genheaders.py \
          -e "s,time.strftime('%Y%m%d'),'${lib.replaceStrings ["-"] [""] date}',"
      '';

      configurePhase = ":";

      buildPhase = ''
        # Some headers such as glx.h are not pre-generated, regenerate all
        # to be sure none are missing.
        pushd xml/
          python genheaders.py
        popd
        pushd api/
          for header in glcorearb.h glext.h gl.h; do
            python ../xml/genglvnd.py -registry ../xml/gl.xml GL/$header.h
          done
        popd
        for xml in xml/*.xml; do
          install -D -m644 -v "$xml" \
            api/xml/"$(basename "$xml")"
        done

        tar -Jcvf opengl-headers-${date}.tar.xz api/
      '';

      installPhase = ''
        install -D -m644 -v 'opengl-headers-${date}.tar.xz' \
          "$out/opengl-headers-${date}.tar.xz"
      '';
    };
  };

  meta = with lib; {
    description = "OpenGL, OpenGL ES, and OpenGL ES-SC API headers.";
    homepage = https://github.com/KhronosGroup/OpenGL-Registry;
    license = licenses.mit;
    maintainers = with maintainers; [
      codyopel
    ];<commit_msg>opengl-headers: use makefile and namespace variables<commit_after>{ stdenv
, fetchurl
, fetchFromGitHub
, lib
, python3Packages
}:

# We build our own dist tarballs, upstream repo vendors pdfs.

let
  date = "2019-03-01";
in
stdenv.mkDerivation rec {
  name = "opengl-headers-${date}";

  src = fetchurl {
    name = "opengl-headers-${date}.tar.xz";
    multihash = "QmRMy2iGHh535k8mjVKhZ4CMypWbK5hE21bZg1MB7eDyS3";
    sha256 = "7b6ba3e1c12dc8d4150c853ad8b6338e52f2f93a1cff609da55cd381bb47d3dd";
  };

  configurePhase = ":";

  buildPhase = ":";

  installPhase = ''
    local opengl_api
    for opengl_api in GL{,ES{,2,3},SC{,2}}; do
      pushd $opengl_api/
        local -a opengl_headers
        mapfile -t opengl_headers < <(find . -name '*.h' -printf '%P\n')
        for opengl_header in "''${opengl_headers[@]}"; do
          install -D -m644 -v "$opengl_header" \
            "$out"/include/"$(basename "$opengl_api")"/"$opengl_header"
        done
      popd
    done

    local opengl_xml
    for opengl_xml in xml/*.xml; do
      install -D -m644 -v "$opengl_xml" \
        "$out"/share/opengl-registry/"$(basename "$opengl_xml")"
    done
  '';

  passthru = {
    generateDistTarball = stdenv.mkDerivation rec {
      name = "opengl-headers-${date}";

      src = fetchFromGitHub {
        version = 6;
        owner = "KhronosGroup";
        repo = "OpenGL-Registry";
        rev = "68dba34a93b67d626b1c8b7294e4562bdaf4c996";
        sha256 = "6046f2eef181fe96379d23938de26e32621a59061d384b946db7e969bf16e99a";
      };

      nativeBuildInputs = [
        python3Packages.lxml
        python3Packages.python
      ];

      postPatch = ''
        patchShebangs xml/genheaders.py

        # Fix impure date in headers
        grep -q "time.strftime('%Y%m%d')" xml/genheaders.py
        sed -i xml/genheaders.py \
          -e "s,time.strftime('%Y%m%d'),'${lib.replaceStrings ["-"] [""] date}',"
      '';

      configurePhase = ":";

      preBuild = ''
        cd xml/
      '';

      # If Mesa finally aligns their glx.h with the upstream header from
      # Khronos this should be enabled.
      #postBuild = ''
      #  # Fix missing includes in generated glx.h.
      #  # https://www.khronos.org/registry/OpenGL/ABI/#4
      #  grep -q '#define __glx_glx_h_ 1' ../api/GL/glx.h
      #  sed -i ../api/GL/glx.h \
      #    -e '/^#define __glx_glx_h_ 1/a #include <X11/Xlib.h>\n#include <X11/Xutil.h>'
      #'';

      installPhase = ''
        cd ../
        # Install xml registry files.
        local opengl_xml
        for opengl_xml in xml/*.xml; do
          install -D -m644 -v "$opengl_xml" \
            api/xml/"$(basename "$opengl_xml")"
        done

        tar -Jcvf opengl-headers-${date}.tar.xz api/

        install -D -m644 -v 'opengl-headers-${date}.tar.xz' \
          "$out/opengl-headers-${date}.tar.xz"
      '';
    };
  };

  meta = with lib; {
    description = "OpenGL, OpenGL ES, and OpenGL ES-SC API headers.";
    homepage = https://github.com/KhronosGroup/OpenGL-Registry;
    license = licenses.mit;
    maintainers = with maintainers; [
      codyopel
    ];
{'fraction_non_alphanumeric': 0.14075739235690818, 'fraction_numerical': 0.05135742694103407, 'mean_word_length': 2.1710526315789473, 'pattern_counts': {'":': 6, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, 'xml': 38}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1875493', 'n_tokens_mistral': 2368, 'n_tokens_neox': 2165, 'n_words': 420}