forked from jcosborn/qex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
installNim
executable file
·165 lines (146 loc) · 3.33 KB
/
installNim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash
usage() {
s="------------------------------------------------------------------------"
echo $s
echo "$0:"
echo " installs Nim compiler and tools (https://nim-lang.org)"
echo $s
echo "options:"
echo " -h (this help message)"
echo " stable (install latest stable version)"
echo " <version> (install named version, e.g. 0.16.0)"
echo " master (install master branch tracking version)"
echo " devel (install devel branch tracking version)"
echo " default stable|<version>|master|devel"
echo " (set default version)"
echo $s
echo "The default installation location is in '\$HOME/nim'."
echo "This directory will be created if it does not already exist."
echo "It will also create symlinks in '\$HOME/bin' if that directory exists."
echo $s
exit
}
if [ "X$1" = "X" ]; then
usage
fi
switch="0"
if [ "X$1" = "Xdefault" ]; then
switch="1"
shift
fi
ver="stable"
branch="master"
if [ "X$1" != "X" ]; then
case "$1" in
stable) ver="stable";;
master) ver="master";;
devel) ver="devel"; branch="devel";;
-h) usage;;
*) ver="$1"; branch="v$1";;
esac
fi
rootdir="$HOME/nim"
bindir="$HOME/bin"
nimdir="Nim-$ver"
getVer() {
exe="$1"
bin/$exe -v 2>&1 |head -n1 |sed 's/[^0-9]*\([0-9.]*\).*/\1/'
}
install() {
exe="$1"
if [ ! -e bin/$exe ]; then return; fi
v="$ver"
if [ $v != "master" -a $v != "devel" ]; then
v=`getVer $exe`
fi
exev="$exe-$v"
if [ -d $bindir ]; then
echo "installing $exev in $bindir"
cd $bindir
rm -f $exev
#cp -a $rootdir/$nimdir/bin/$exe $exev
ln -s $rootdir/$nimdir/bin/$exe $exev
rm -f $exe
ln -s $exev $exe
fi
cd $rootdir/$nimdir
}
realpath2() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}
installAll() {
install nim
install nimble
install nimgrep
install nimsuggest
me0=`basename $0`
#me=`realpath -s $0`
#me=`readlink -f $0`
me=`realpath2 $0`
if [ -d $bindir -a ! -e $bindir/$me0 ]; then
cd $bindir
ln -s $me
cd -
fi
}
if [ $switch = 1 ]; then
cd $rootdir
if [ $ver = "stable" ]; then
nimdir=`ls -1d Nim-[0-9]* |tail -n1`
fi
echo "Setting default Nim to $nimdir"
cd $nimdir
installAll
exit
fi
echo "Installing Nim version '$ver' in directory $rootdir/$nimdir"
if [ ! -e $rootdir ]; then
mkdir $rootdir
fi
cd $rootdir
if [ ! -e $nimdir ]; then
git clone -b $branch https://github.com/nim-lang/Nim.git $nimdir
if [ ! -e $nimdir ]; then
echo "can't clone Nim branch: $branch"
exit 1
fi
fi
cd $nimdir
git checkout $branch
if [ $branch = "master" -o $branch = "devel" ]; then
git pull
fi
if [ -e csources ]; then
cd csources
git pull
cd ..
else
if [ $branch = "master" -o $branch = "devel" ]; then
git clone --depth 1 https://github.com/nim-lang/csources
else
cb="v0.16.0"
case $ver in
0.9.*|0.10.*|0.11.*|0.12.*) cb="v0.9.4";;
0.13.*|0.14.*|0.15.0) cb="v0.13.0";;
0.15.*) cb="v0.15.2";;
0.16.*) cb="v0.16.0";;
esac
git clone -b $cb --depth 1 https://github.com/nim-lang/csources
fi
fi
cd csources && sh build.sh && cd ..
bin/nim c koch
./koch boot -d:release
./koch tools
./koch nimble
if [ $ver = "stable" ]; then
ver=`getVer nim`
nimdir="Nim-$ver"
cd ..
if [ -e $nimdir ]; then
rm -rf $nimdir
fi
mv Nim-stable $nimdir
cd $nimdir
fi
installAll