Skip to content

Instantly share code, notes, and snippets.

@Techcable
Last active August 20, 2022 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Techcable/b83df781602857dd2f6cf0074e50ba77 to your computer and use it in GitHub Desktop.
Save Techcable/b83df781602857dd2f6cf0074e50ba77 to your computer and use it in GitHub Desktop.
A small bash script to download & compile the Janet CLI
#!/bin/bash
# Available as github gist: https://gist.github.com/Techcable/b83df781602857dd2f6cf0074e50ba77
set -e
if [[ $# -eq 1 ]]; then
OUT_FILE="$(realpath "$1")";
else
echo "ERROR: Invalid arguments" >&2;
echo "" >&2;
echo "Need output file as first parameter " >&2;
echo "Example: bash ./getjanet.sh <out>" >&2;
exit 1;
fi
if [[ -f "$OUT_FILE" ]]; then
echo "ERROR: $OUT_FILE already exists" >&2;
exit 1;
fi
if [[ -z "$JANET_VERSION" ]]; then
JANET_VERSION="v1.24.0";
fi
if [[ -z "$JANET_FLAGS" ]]; then
export JANET_FLAGS=(-O1 -DJANET_NO_INT_TYPES -DJANET_NO_EV -DJANET_NO_THREADS);
fi
if [[ -z "$CC" ]]; then
export CC="cc";
fi
BUILDDIR=$(mktemp -d)
pushd "$BUILDDIR" > /dev/null
echo "Downloading sources for Janet $JANET_VERSION"
curl -sSOL "https://github.com/janet-lang/janet/releases/download/$JANET_VERSION/{janet.c,janet.h,shell.c}"
echo "Compiling w/ $CC"
$CC "${JANET_FLAGS[@]}" -I . janet.c shell.c -o "janet.exe"
popd >/dev/null
mv -i "$BUILDDIR/janet.exe" "$OUT_FILE"
rm -rf "$BUILDDIR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment