Created
June 24, 2018 16:20
-
-
Save kaushalmodi/93c342b86ce38c6c3d79933b8af0d11d to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# Time-stamp: <2018-06-23 22:16:08 kmodi> | |
# Usage: ./mybuild.sh # Installs using upstream/devel | |
# ./mybuild.sh --rev v0.18.0 | |
# ./mybuild.sh --rev upstream/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 upstream/master, ${nim_rev_basename} = master | |
# If ${nim_rev} is v0.18.0, ${nim_rev_basename} = v0.18.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 | |
echo "Inside $(pwd)" | |
sh build.sh | |
# We are now in the Nim/ directory | |
cd ../ | |
echo "Inside $(pwd)" | |
./bin/nim c koch | |
./koch boot -d:release | |
echo "Version check:" | |
./bin/nim -v | |
# echo "Building nimble .." | |
# ./koch nimble | |
echo "Building nimsuggest, nimgrep and nimble .." | |
./koch tools | |
if [[ ${nim_rev} == "origin/devel" ]] | |
then | |
echo "Building nimpretty.." | |
./bin/nim c -d:release -o:./bin/nimpretty ./nimpretty/nimpretty.nim | |
fi | |
echo "Building doc site .." | |
./koch web | |
# 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 | |
nim c -r --verbosity:0 --nep1:on "$@"' > ./bin/nimm | |
chmod 744 ./bin/nimm | |
rm -rf ./doc/nimcache/ | |
rm -rf ./tools/nimcache/ | |
if [[ -d ./dist1 ]] | |
then | |
rm -rf ./dist1 | |
fi | |
mkdir -p ./dist1 | |
cp -rf ./bin ./dist1/. | |
cp -rf ./config ./dist1/. | |
cp -rf ./lib ./dist1/. | |
cp -rf ./doc ./dist1/. | |
cp -rf ./examples ./dist1/. | |
cp -rf ./compiler ./dist1/. | |
nim_install_dir="${STOW_PKGS_ROOT}/nim/${nim_rev_basename}" | |
echo "Copying the distribution to ${nim_install_dir} .." | |
if [[ -d "${nim_install_dir}" ]] | |
then | |
rm -rf "${nim_install_dir}" | |
fi | |
cp -r ./dist1 "${nim_install_dir}" | |
echo "Done!" | |
echo "" | |
# https://github.com/nim-lang/nimble#nimble-refresh | |
"${nim_install_dir}"/bin/nimble refresh # First time update of nimble package cache | |
echo "If 'nimble refresh' above failed, do '~/scripts/bash/stow_it.sh', followed by 'resourcef', and try again." | |
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