<commit_before>{ lib, stdenv, fetchurl, readline
, compat ? false
, callPackage
, packageOverrides ? (self: super: {})
, sourceVersion
, hash
, patches ? []
, postConfigure ? null
, postBuild ? null
}:
let
luaPackages = callPackage ../../lua-modules {lua=self; overrides=packageOverrides;};

plat = if stdenv.isLinux then "linux"
       else if stdenv.isDarwin then "macosx"
       else if stdenv.hostPlatform.isMinGW then "mingw"
       else if stdenv.isFreeBSD then "freebsd"
       else if stdenv.isSunOS then "solaris"
       else if stdenv.hostPlatform.isBSD then "bsd"
       else if stdenv.hostPlatform.isUnix then "posix"
       else "generic";

self = stdenv.mkDerivation rec {
  pname = "lua";
  luaversion = with sourceVersion; "${major}.${minor}";
  version = "${luaversion}.${sourceVersion.patch}";

  src = fetchurl {
    url = "https://www.lua.org/ftp/${pname}-${version}.tar.gz";
    sha256 = hash;
  };

  LuaPathSearchPaths    = luaPackages.getLuaPathList luaversion;
  LuaCPathSearchPaths   = luaPackages.getLuaCPathList luaversion;
  setupHook = luaPackages.lua-setup-hook LuaPathSearchPaths LuaCPathSearchPaths;

  buildInputs = [ readline ];

  inherit patches;

  postPatch = lib.optionalString (!stdenv.isDarwin) ''
    # Add a target for a shared library to the Makefile.
    sed -e '1s/^/LUA_SO = liblua.so/' \
        -e 's/ALL_T *= */&$(LUA_SO) /' \
        -i src/Makefile
    cat ${./lua-dso.make} >> src/Makefile
  '';

  # see configurePhase for additional flags (with space)
  makeFlags = [
    "INSTALL_TOP=${placeholder "out"}"
    "INSTALL_MAN=${placeholder "out"}/share/man/man1"
    "R=${version}"
    "LDFLAGS=-fPIC"
    "V=${luaversion}"
    "PLAT=${plat}"
    "CC=${stdenv.cc.targetPrefix}cc"
    "RANLIB=${stdenv.cc.targetPrefix}ranlib"
  ];

  configurePhase = ''
    runHook preConfigure

    makeFlagsArray+=(CFLAGS='-O2 -fPIC${lib.optionalString compat " -DLUA_COMPAT_ALL"} $(SYSCFLAGS)' )
    makeFlagsArray+=(${lib.optionalString stdenv.isDarwin "CC=\"$CC\""}${lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) " 'AR=${stdenv.cc.targetPrefix}ar rcu'"})

    installFlagsArray=( TO_BIN="lua luac" INSTALL_DATA='cp -d' \
      TO_LIB="${if stdenv.isDarwin then "liblua.${version}.dylib" else "liblua.a liblua.so liblua.so.${luaversion} liblua.so.${version}"}" )

    runHook postConfigure
  '';<commit_msg>lua5_1: fixup a recent regression<commit_after>{ lib, stdenv, fetchurl, readline
, compat ? false
, callPackage
, packageOverrides ? (self: super: {})
, sourceVersion
, hash
, patches ? []
, postConfigure ? null
, postBuild ? null
}:
let
luaPackages = callPackage ../../lua-modules {lua=self; overrides=packageOverrides;};

plat = if stdenv.isLinux then "linux"
       else if stdenv.isDarwin then "macosx"
       else if stdenv.hostPlatform.isMinGW then "mingw"
       else if stdenv.isFreeBSD then "freebsd"
       else if stdenv.isSunOS then "solaris"
       else if stdenv.hostPlatform.isBSD then "bsd"
       else if stdenv.hostPlatform.isUnix then "posix"
       else "generic";

self = stdenv.mkDerivation rec {
  pname = "lua";
  luaversion = with sourceVersion; "${major}.${minor}";
  version = "${luaversion}.${sourceVersion.patch}";

  src = fetchurl {
    url = "https://www.lua.org/ftp/${pname}-${version}.tar.gz";
    sha256 = hash;
  };

  LuaPathSearchPaths    = luaPackages.getLuaPathList luaversion;
  LuaCPathSearchPaths   = luaPackages.getLuaCPathList luaversion;
  setupHook = luaPackages.lua-setup-hook LuaPathSearchPaths LuaCPathSearchPaths;

  buildInputs = [ readline ];

  inherit patches;

  postPatch = lib.optionalString (!stdenv.isDarwin) ''
    # Add a target for a shared library to the Makefile.
    sed -e '1s/^/LUA_SO = liblua.so/' \
        -e 's/ALL_T *= */&$(LUA_SO) /' \
        -i src/Makefile
    cat ${./lua-dso.make} >> src/Makefile
  '';

  # see configurePhase for additional flags (with space)
  makeFlags = [
    "INSTALL_TOP=${placeholder "out"}"
    "INSTALL_MAN=${placeholder "out"}/share/man/man1"
    "R=${version}"
    "LDFLAGS=-fPIC"
    "V=${luaversion}"
    "PLAT=${plat}"
    "CC=${stdenv.cc.targetPrefix}cc"
    "RANLIB=${stdenv.cc.targetPrefix}ranlib"
  ];

  configurePhase = ''
    runHook preConfigure

    makeFlagsArray+=(CFLAGS='-O2 -fPIC${lib.optionalString compat " -DLUA_COMPAT_ALL"} $(${
      if lib.versionAtLeast luaversion "5.2" then "SYSCFLAGS" else "MYCFLAGS"})' )
    makeFlagsArray+=(${lib.optionalString stdenv.isDarwin "CC=\"$CC\""}${lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) " 'AR=${stdenv.cc.targetPrefix}ar rcu'"})

    installFlagsArray=( TO_BIN="lua luac" INSTALL_DATA='cp -d' \
      TO_LIB="${if stdenv.isDarwin then "liblua.${version}.dylib" else "liblua.a liblua.so liblua.so.${luaversion} liblua.so.${version}"}" )

    runHook postConfigure
  '';
{'fraction_non_alphanumeric': 0.15167840861997514, 'fraction_numerical': 0.003315375051802735, 'mean_word_length': 3.690962099125364, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '1455883', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1715, 'n_words': 343}