#TODO working with workarounds on SIGCHLD
#TODO no documentation
[source]
git = "https://github.com/neovim/neovim"
rev = "0cb6dde5eecc7bbae7762c5703628f95e6148621" # nightly 0.13
shallow_clone = true
patches = [
  "redox.patch"
]

[build]
template = "custom"
dependencies = [
    "libiconv",
    "libuv",
    "luv",
    "lpeg",
    "tree-sitter",
    "target:gettext",
    "unibilium",
    "utf8proc",
]
dev-dependencies = [
  "host:luajit",
]
script = """
DYNAMIC_INIT

# the only official way to cross compile in future is via zig
# https://github.com/neovim/neovim/issues/19579
# the only problem is to compile libnlua.so in host, so we do it here

COOKBOOK_CMAKE_FLAGS+=(-DLUA_GEN_PRG=luajit)
export DEPS_BUILD_DIR=$COOKBOOK_SYSROOT/usr
(export COOKBOOK_NINJA=true && cookbook_cmake) 

${CC_WRAPPER} gcc -shared -I${COOKBOOK_SOURCE}/src ${COOKBOOK_SOURCE}/src/nlua0.c \
  -o ./libnlua0.so -lluajit-5.1 -I${COOKBOOK_TOOLCHAIN}/include/luajit-2.1 -L${COOKBOOK_TOOLCHAIN}/lib

"${COOKBOOK_NINJA}" -j"${COOKBOOK_MAKE_JOBS}"
DESTDIR="${COOKBOOK_STAGE}" "${COOKBOOK_NINJA}" install -j"${COOKBOOK_MAKE_JOBS}"

# Lpeg is absolute path https://github.com/neovim/neovim/issues/23395
patchelf --replace-needed \
  "${COOKBOOK_SYSROOT}/usr/lib/liblpeg.so" \
  'liblpeg.so.1' ${COOKBOOK_STAGE}/usr/bin/nvim
"""
