<commit_before>{ stdenv
, fetchFromGitHub
, fetchurl
, lib
, perl
, yasm

# Limit default decoder max to WHXGA
, sizeLimit ? "5120x3200" # limit max size to allow in the decoder
, examplesSupport ? true # build examples (vpxdec & vpxenc are part of examples)
, postprocSupport ? true # postprocessing
, multithreadSupport ? true # multithreaded decoding & encoding
, internalStatsSupport ? false # output of encoder internal stats for debug, if supported (encoders)
, spatialResamplingSupport ? true # spatial sampling (scaling)
, realtimeOnlySupport ? false # build for real-time encoding
, ontheflyBitpackingSupport ? false # on-the-fly bitpacking in real-time encoding
, errorConcealmentSupport ? false # decoder conceals losses
, postprocVisualizerSupport ? false # macro block/block level visualizers
, multiResEncodingSupport ? false # multiple-resolution encoding
, temporalDenoisingSupport ? true # use temporal denoising instead of spatial denoising
, coefficientRangeCheckingSupport ? false # decoder checks if intermediate transform coefficients are in valid range
, experimentalSupport ? false # experimental features
, betterHWCompatibility ? true
# Experimental features
, experimentalSpatialSvcSupport ? false # Spatial scalable video coding
, experimentalFpMbStatsSupport ? false
, experimentalEmulateHardwareSupport ? false
, experimentalMiscFixes ? false

, channel
}:

assert internalStatsSupport -> postprocSupport;
/* If spatialResamplingSupport not enabled, build will fail with
   undeclared variable errors. Variables called in
   vpx_scale/generic/vpx_scale.c are declared by vpx_scale/vpx_scale_rtcd.pl,
   but is only executed if spatialResamplingSupport is enabled */
assert spatialResamplingSupport;
assert postprocVisualizerSupport -> postprocSupport;

let
  inherit (builtins)
    compareVersions;
  inherit (stdenv)
    targetSystem;
  inherit (lib)
    boolEn
    boolString
    elem
    optional
    optionals
    platforms
    versionAtLeast;

  sources = {
    "1.6" = {
      version = "1.6.1";
      sha256 = "1c2c0c2a97fba9474943be34ee39337dee756780fc12870ba1dc68372586a819";
    };
    # master
    "1.999" = {
      fetchzipversion = 3;
      version = "2017-07-28";
      rev = "5d0bef4763b7e87451b4176771d344d4172960df";
      sha256 = "15c829f4bd8f7ae290c7fd75921f25706b924c4cb43ae14caea29314ae61deb1";
    };
  };
  source = sources."${channel}";

  reqMin = v: (compareVersions v channel != 1);
  reqMax = v: (compareVersions channel v != 1);

  # Deprecated flag
  deprFlag = deprVer: flag:
    if reqMax deprVer then
      flag
    else
      null;
  # Flag added in later versions
  newFlag = minVer: flag:
    if reqMin minVer then
      flag
    else
      null;
in
stdenv.mkDerivation rec {
  name = "libvpx-${source.version}";

  src =
    if versionAtLeast channel "1.999" then
      fetchFromGitHub {
        version = source.fetchzipversion;
        owner = "webmproject";
        repo = "libvpx";
        inherit (source) rev sha256;
      }
    else
      fetchurl {
        url = "https://storage.googleapis.com/downloads.webmproject.org/"
          + "releases/webm/${name}.tar.bz2";
        inherit (source) sha256;
      };

  nativeBuildInputs = [
    perl
    yasm
  ];

  postPatch = ''
    patchShebangs ./build/make/rtcd.pl
  '';

  # Do NOT base configure flags on what is returned by --help, libvpx
  # uses FFmpeg's shell configure script and actual optionals are
  # defined in lists.  The help info is static and does not always
  # represent current options. See CMDLINE_SELECT in the configure script.
  configureFlags = [
    "--enable-dependency-tracking"
    #external_build
    "--enable-extra-warnings"
    "--disable-werror"
    "--disable-install-docs"
    "--${boolEn examplesSupport}-install-bins"
    "--enable-install-libs"
    "--disable-install-srcs"
    "--disable-debug"
    "--disable-gprof"
    "--disable-gcov"
    # Required to build shared libraries
    "--enable-pic"
    "--enable-optimizations"
    "--disable-ccache"
    "--enable-runtime-cpu-detect"
    "--disable-thumb"
    "--enable-libs"
    "--${boolEn examplesSupport}-examples"
    "--disable-docs"
    #libc
    "--as=yasm"<commit_msg>libvpx: use nasm<commit_after>{ stdenv
, fetchFromGitHub
, fetchurl
, lib
, nasm
, perl

# Limit default decoder max to WHXGA
, sizeLimit ? "5120x3200" # limit max size to allow in the decoder
, examplesSupport ? true # build examples (vpxdec & vpxenc are part of examples)
, postprocSupport ? true # postprocessing
, multithreadSupport ? true # multithreaded decoding & encoding
, internalStatsSupport ? false # output of encoder internal stats for debug, if supported (encoders)
, spatialResamplingSupport ? true # spatial sampling (scaling)
, realtimeOnlySupport ? false # build for real-time encoding
, ontheflyBitpackingSupport ? false # on-the-fly bitpacking in real-time encoding
, errorConcealmentSupport ? false # decoder conceals losses
, postprocVisualizerSupport ? false # macro block/block level visualizers
, multiResEncodingSupport ? false # multiple-resolution encoding
, temporalDenoisingSupport ? true # use temporal denoising instead of spatial denoising
, coefficientRangeCheckingSupport ? false # decoder checks if intermediate transform coefficients are in valid range
, experimentalSupport ? false # experimental features
, betterHWCompatibility ? true
# Experimental features
, experimentalSpatialSvcSupport ? false # Spatial scalable video coding
, experimentalFpMbStatsSupport ? false
, experimentalEmulateHardwareSupport ? false
, experimentalMiscFixes ? false

, channel
}:

assert internalStatsSupport -> postprocSupport;
/* If spatialResamplingSupport not enabled, build will fail with
   undeclared variable errors. Variables called in
   vpx_scale/generic/vpx_scale.c are declared by vpx_scale/vpx_scale_rtcd.pl,
   but is only executed if spatialResamplingSupport is enabled */
assert spatialResamplingSupport;
assert postprocVisualizerSupport -> postprocSupport;

let
  inherit (builtins)
    compareVersions;
  inherit (stdenv)
    targetSystem;
  inherit (lib)
    boolEn
    boolString
    elem
    optional
    optionals
    platforms
    versionAtLeast;

  sources = {
    "1.6" = {
      version = "1.6.1";
      sha256 = "1c2c0c2a97fba9474943be34ee39337dee756780fc12870ba1dc68372586a819";
    };
    # master
    "1.999" = {
      fetchzipversion = 3;
      version = "2017-07-28";
      rev = "5d0bef4763b7e87451b4176771d344d4172960df";
      sha256 = "15c829f4bd8f7ae290c7fd75921f25706b924c4cb43ae14caea29314ae61deb1";
    };
  };
  source = sources."${channel}";

  reqMin = v: (compareVersions v channel != 1);
  reqMax = v: (compareVersions channel v != 1);

  # Deprecated flag
  deprFlag = deprVer: flag:
    if reqMax deprVer then
      flag
    else
      null;
  # Flag added in later versions
  newFlag = minVer: flag:
    if reqMin minVer then
      flag
    else
      null;
in
stdenv.mkDerivation rec {
  name = "libvpx-${source.version}";

  src =
    if versionAtLeast channel "1.999" then
      fetchFromGitHub {
        version = source.fetchzipversion;
        owner = "webmproject";
        repo = "libvpx";
        inherit (source) rev sha256;
      }
    else
      fetchurl {
        url = "https://storage.googleapis.com/downloads.webmproject.org/"
          + "releases/webm/${name}.tar.bz2";
        inherit (source) sha256;
      };

  nativeBuildInputs = [
    nasm
    perl
  ];

  postPatch = ''
    patchShebangs ./build/make/rtcd.pl
  '';

  # Do NOT base configure flags on what is returned by --help, libvpx
  # uses FFmpeg's shell configure script and actual optionals are
  # defined in lists.  The help info is static and does not always
  # represent current options. See CMDLINE_SELECT in the configure script.
  configureFlags = [
    "--enable-dependency-tracking"
    #external_build
    "--enable-extra-warnings"
    "--disable-werror"
    "--disable-install-docs"
    "--${boolEn examplesSupport}-install-bins"
    "--enable-install-libs"
    "--disable-install-srcs"
    "--disable-debug"
    "--disable-gprof"
    "--disable-gcov"
    # Required to build shared libraries
    "--enable-pic"
    "--enable-optimizations"
    "--disable-ccache"
    "--enable-runtime-cpu-detect"
    "--disable-thumb"
    "--enable-libs"
    "--${boolEn examplesSupport}-examples"
    "--disable-docs"
    #libc
    "--as=nasm"
{'fraction_non_alphanumeric': 0.09288184094431859, 'fraction_numerical': 0.036961964945749375, 'mean_word_length': 3.348367029548989, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3811711', 'n_tokens_mistral': 2771, 'n_tokens_neox': 2544, 'n_words': 687}