#TODO signal handling is disabled, it should be re-enabled when Redox is ready
#TODO language files are not built for fennel and crstalline langauges
#TODO configuration - https://docs.helix-editor.com/install.html#configuring-helixs-runtime-files
[source]
git = "https://github.com/greyshaman/helix.git"
branch = "port-to-redoxos"

[build]
template = "custom"
script = """
DYNAMIC_INIT
export CFLAGS="$CFLAGS -D__redox__"
COOKBOOK_CARGO_PATH="helix-term" cookbook_cargo
mv "${COOKBOOK_STAGE}/usr/bin/hx" "${COOKBOOK_STAGE}/usr/bin/helix"
mkdir -p "${COOKBOOK_STAGE}/usr/lib/helix/runtime/grammars"
mkdir -p "${COOKBOOK_STAGE}/usr/lib/helix/runtime/queries"
mkdir -p "${COOKBOOK_STAGE}/usr/lib/helix/runtime/themes"
echo "show runtime grammars dir content"
cp ${COOKBOOK_SOURCE}/runtime/grammars/*.so ${COOKBOOK_STAGE}/usr/lib/helix/runtime/grammars/
cp -r ${COOKBOOK_SOURCE}/runtime/queries/* ${COOKBOOK_STAGE}/usr/lib/helix/runtime/queries/
cp -r ${COOKBOOK_SOURCE}/runtime/themes/* ${COOKBOOK_STAGE}/usr/lib/helix/runtime/themes/
cp "${COOKBOOK_SOURCE}/runtime/tutor" ${COOKBOOK_STAGE}/usr/lib/helix/runtime/

echo '#!/usr/bin/env bash' > "${COOKBOOK_STAGE}/usr/bin/hx"
echo 'export HELIX_RUNTIME=/usr/lib/helix/runtime' >> "${COOKBOOK_STAGE}/usr/bin/hx"
echo '/usr/bin/helix $@' >> "${COOKBOOK_STAGE}/usr/bin/hx"

chmod +x ${COOKBOOK_STAGE}/usr/bin/hx
"""

