Skip to content

Instantly share code, notes, and snippets.

@kaushalmodi
Last active May 29, 2018 22:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaushalmodi/261ba46487cbea9c6ad10c62ca2ee3e8 to your computer and use it in GitHub Desktop.
Save kaushalmodi/261ba46487cbea9c6ad10c62ca2ee3e8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Time-stamp: <2017-05-18 08:18:01 kmodi>
# Usage: ./mybuild.sh # Installs using origin/devel
# ./mybuild.sh --rev v0.17.0
# ./mybuild.sh --rev origin/master
set -euo pipefail # http://redsymbol.net/articles/unofficial-bash-strict-mode
IFS=$'\n\t'
nim_rev="origin/devel"
while [ $# -gt 0 ]
do
case "$1" in
"-r"|"--rev" ) shift
nim_rev="$1";;
* ) echo >&2 "Error: Invalid option: $1"
esac
shift # expose next argument
done
# If ${nim_rev} is origin/master, ${nim_rev_basename} = master
# If ${nim_rev} is v0.17.0, ${nim_rev_basename} = v0.17.0
nim_rev_basename=$(basename "${nim_rev}")
git fetch --all # fetch new branch names if any
git checkout "${nim_rev_basename}"
git fetch --all
git reset --hard "${nim_rev}"
echo ""
wait_time=5 # seconds
temp_cnt=${wait_time}
# https://www.cyberciti.biz/faq/csh-shell-scripting-loop-example/
while [[ ${temp_cnt} -gt 0 ]];
do
printf "\rWaiting for %2d second(s) .. Press Ctrl+C to cancel this installation." ${temp_cnt}
sleep 1
((temp_cnt--))
done
echo ""
# https://github.com/nim-lang/Nim#compiling
if [[ ! -e ./csources ]]
then
git clone --depth 1 https://github.com/nim-lang/csources.git
cd csources
else
cd csources
git pull
fi
# We are now in the Nim/csources/ directory
sh build.sh
# We are now in the Nim/ directory
cd ../
./bin/nim c koch
./koch boot -d:release
echo "Version check:"
./bin/nim -v
# Build nimsuggest, nimgrep and nimble
./koch tools
# https://github.com/nim-lang/nimble#nimble-refresh
./bin/nimble refresh # First time update of nimble package cache
# nim_install_dir="${STOW_PKGS_ROOT}/nim/${nim_rev_basename}"
# nim_install_dir="${HOME}/usr_local/6/bin"
nim_install_dir="${STOW_PKGS_ROOT}/nim/${nim_rev_basename}"
mkdir -p "${nim_install_dir}"
# Create a wrapper script that calls nim with few default options
# c is an alias for compile, which compiles the Nim sources into C and then
# invokes the C compiler on them
# -r is an alias for --run, which runs the program
# --verbosity:0 makes the compiler only output essential messages, since by
# default it also outputs some debugging messages.
echo '#!/usr/bin/env bash' > ./bin/nimm
echo 'nim c -r --verbosity:0 "$@"' >> ./bin/nimm
chmod 744 ./bin/nimm
cp -rf ./bin "${nim_install_dir}"/.
cp -rf ./config "${nim_install_dir}"/.
cp -rf ./lib "${nim_install_dir}"/.
cp -rf ./doc "${nim_install_dir}"/.
cp -rf ./examples "${nim_install_dir}"/.
cp -rf ./compiler "${nim_install_dir}"/.
echo ""
echo "Now update the '~/scripts/bash/stow_it.sh' script and rerun that script if needed."
echo " That would be needed if you are installing 'nim' for the first time, or changing the version."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment