-
Notifications
You must be signed in to change notification settings - Fork 6
/
installNim
executable file
·221 lines (199 loc) · 4.6 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/bash
pwd="$PWD"
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. 2.2.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 installation location can be set with the environment variable"
echo " NIMDIR (default '\$HOME/nim')"
echo "This directory will be created if it does not already exist."
echo "It will also create symlinks from the directory sepcified in"
echo " BINDIR (default '\$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="version-2-0"
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
testWrite() {
tmpf="$1/.tmpfile.installNim"
if touch $tmpf; then
rm $tmpf
exit 0
fi
exit -1
}
# find user bin directory
bindir="$HOME/bin"
while read -r p; do
#echo $p
if [ `expr $p : ${HOME}` -ne 0 ]; then
if [ -d $p -a -w $p ]; then
#tmpf=$p/.tmpfile.installNim
#if touch $tmpf; then
#rm $tmpf
bindir=$p
break
fi
fi
done <<<"$(echo "$PATH" |tr ':' '\n')"
if [ "X$BINDIR" != "X" ]; then
bindir="$BINDIR"
fi
echo $bindir
topdir=`dirname "$bindir"`
rootdir="$topdir/nim"
if [ ! -d $topdir -o ! -w $topdir ]; then
rootdir="$bindir/nim"
fi
if [ "X$NIMDIR" != "X" ]; then
rootdir="$NIMDIR"
fi
echo $rootdir
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="v2"
# 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";;
# 0.17.*) cb="v0.17.0";;
# 0.18.*) cb="v0.18.0";;
# 0.19.*) cb="v0.19.0";;
# 0.*|1.0.*|1.1.*|1.2.*|1.3.*|1.4.*) cb="v0.20.0";;
# 1.5.*|1.6.*) cb="v1";;
# esac
# echo "Installing csources '$cb'"
# case $cb in
# v2)
# git clone --depth 1 https://github.com/nim-lang/csources_v2
# ln -s csources_v2 csources;;
# v1)
# git clone --depth 1 https://github.com/nim-lang/csources_v1
# ln -s csources_v1 csources;;
# *)
# git clone -b $cb --depth 1 https://github.com/nim-lang/csources;;
# esac
# fi
#fi
#cd csources && sh build.sh && cd ..
#bin/nim c koch
#./koch boot -d:release
#./koch tools
#./koch nimble
echo "Running build_all.sh"
./build_all.sh 2>&1 |tee build.log
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