Last active
August 20, 2022 03:07
-
-
Save Techcable/b83df781602857dd2f6cf0074e50ba77 to your computer and use it in GitHub Desktop.
A small bash script to download & compile the Janet CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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