forked from arturo-lang/arturo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·216 lines (180 loc) · 4.88 KB
/
install
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
#!/usr/bin/env bash
######################################################
# Arturo
# Programming Language + Bytecode VM compiler
# (c) 2019-2022 Yanis Zafirópulos
#
# @file: install
######################################################
# TODO(/install) remove the script if not needed
# let's make sure first that no 3rd-party - or non-3rd-party - tool uses it
# labels: installer, cleanup
source tools/utils.sh
################################################
# FUNCTIONS
################################################
verifyDirectories() {
# create target dirs recursively, if not exists
mkdir -p "$TARGET_DIR"
mkdir -p "$TARGET_LIB"
info "in: $ROOT_DIR"
if [[ ":$PATH:" == *":$TARGET_DIR:"* ]];
:
then
# path was not in path
PATH=$TARGET_DIR:$PATH
fi
}
buildArturo(){
info "version: $(cat version/version) b/$(cat version/build)"
info "config: $CONFIG"
eecho "${GRAY}"
if [ ! $PRINT_LOG ] && [ ! $IS_DEV_BUILD ];
then
nim $COMPILER $FLAGS -o:$BINARY $MAIN 2>/dev/null &
animate_progress
else
nim $COMPILER $FLAGS -o:$BINARY $MAIN
fi
eecho "${CLEAR}"
}
compressBinary(){
info "compressing binary"
if $FOR_WEB; then
if command_exists uglifyjs ;
then
uglifyjs $BINARY -c -m "toplevel,reserved=['A$']" -c -o ${BINARY/.js/.min.js}
fi
else
if ! command_exists upx ;
then
upx -q $BINARY >/dev/null 2>&1
fi
fi
}
installAll(){
cp $BINARY $TARGET_DIR
if $RUN_UNIT_TESTS; then
./tools/tester.art
fi
}
miniBuild(){
MINI_BUILD=true
FLAGS="$FLAGS -d:NOASCIIDECODE \
-d:NOEXAMPLES \
-d:NOGMP \
-d:NOPARSERS \
-d:NOSQLITE \
-d:NOUNZIP \
-d:NOWEBVIEW \
-d:MINI"
}
################################################
# INITIALIZE OPTIONS
################################################
# paths and tools
ROOT_DIR="$HOME/.arturo"
TARGET_DIR="$ROOT_DIR/bin"
TARGET_LIB="$ROOT_DIR/lib"
BINARY="bin/arturo"
MAIN="src/arturo.nim"
COMPILER="c"
# variables
MINI_BUILD=false
COMPRESS=true
PRINT_LOG=false
RUN_UNIT_TESTS=false
FOR_WEB=false
if [ "$(whoami)" = "drkameleon" ]; then IS_DEV_BUILD=true
else IS_DEV_BUILD=false
fi
CONFIG=""
#--warning[UnusedImport]:off\
# check switches
while test $# -gt 0
do
case "$1" in
log)
PRINT_LOG=true;;
dev)
IS_DEV_BUILD=true;;
test)
RUN_UNIT_TESTS=true;;
release)
FLAGS="$FLAGS --passC:'-flto'";;
mini)
miniBuild;;
safe)
FLAGS="$FLAGS -d:SAFE";;
web)
miniBuild
FOR_WEB=true
COMPILER="js"
BINARY="$BINARY.js"
FLAGS="$FLAGS --verbosity:3"
FLAGS="$FLAGS -d:WEB ";;
noasciidecode) FLAGS="$FLAGS -d:NOASCIIDECODE";;
noexamples) FLAGS="$FLAGS -d:NOEXAMPLES";;
nogmp) FLAGS="$FLAGS -d:NOGMP";;
noparsers) FLAGS="$FLAGS -d:NOPARSERS";;
nosqlite) FLAGS="$FLAGS -d:NOSQLITE";;
nounzip) FLAGS="$FLAGS -d:NOUNZIP";;
nowebview) FLAGS="$FLAGS -d:NOWEBVIEW";;
arm)
FLAGS="$FLAGS --cpu:arm";;
arm64)
FLAGS="$FLAGS --cpu:arm64 --gcc.path:/usr/bin"
FLAGS="$FLAGS --gcc.exe:aarch64-linux-gnu-gcc --gcc.linkerexe:aarch64-linux-gnu-gcc";;
verbose)
CONFIG="verbose $CONFIG"
FLAGS="$FLAGS -d:VERBOSE";;
benchmark)
CONFIG="benchmark $CONFIG"
FLAGS="$FLAGS -d:BENCHMARK";;
debug)
COMPRESS=false
CONFIG="debug $CONFIG"
FLAGS="$FLAGS -d:DEBUG --debugger:on --debuginfo --linedir:on";;
profile)
CONFIG="profile $CONFIG"
FLAGS="$FLAGS -d:PROFILE --profiler:on --stackTrace:on";;
*) ;;
esac
shift
done
if $MINI_BUILD; then
CONFIG="@mini $CONFIG"
FLAGS="$FLAGS --opt:size"
else
CONFIG="@full $CONFIG"
FLAGS="$FLAGS --opt:speed"
fi
if $IS_DEV_BUILD; then
awk '{sub(/[[:digit:]]+$/,$NF+1)}1' version/build > version/build_tmp && mv version/build_tmp version/build
git commit -m 'build update' version/build
FLAGS="$FLAGS -d:DEV --listCmd --verbosity:0 --hints:on"
fi
################################################
# MAIN
################################################
showHeader "Installer"
section "Checking environment..."
verifyOS
verifyShell
verifyNim
section "Building..."
buildArturo
if [ $? -eq 0 ];
then
section "Post-processing..."
compressBinary
section "Installing..."
verifyDirectories
installAll
section "Done!"
showFooter
exit 0
else
eecho "The installer failed :(" >&2
exit 1
fi