mkdir -p bootstrap && wget -qO- https://github.com/crystal-lang/crystal/releases/download/1.21.0/crystal-1.21.0-1-linux-x86_64.tar.gz | tar xz -C bootstrap --strip-components=1

export release=1
export verbose=1
export interpreter=1
export CXXFLAGS="$SLKCFLAGS"
export LLVM_CONFIG=$(find /usr/bin -name "llvm-config*" -print -quit)
export CRYSTAL="$(pwd)/bootstrap/bin/crystal"
make CRYSTAL="$CRYSTAL"

# Stage 2: rebuild using the compiler we just built
make CRYSTAL="$(pwd)/.build/crystal"
make docs
make man/

install -D -m 755 .build/crystal $PKG/usr/bin/crystal
install -vDm 644 man/*.1 -t $PKG/usr/man/man1/
mkdir -p $PKG/usr/share/crystal/
cp -r src samples $PKG/usr/share/crystal
install -D -m 644 etc/completion.bash $PKG/usr/share/bash-completion/completions/crystal
install -D -m 644 etc/completion.fish $PKG/usr/share/fish/vendor_completions.d/crystal.fish
install -D -m 644 etc/completion.zsh $PKG/usr/share/zsh/site-functions/_crystal
