-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.bash
executable file
·229 lines (214 loc) · 5.19 KB
/
install.bash
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
222
223
224
225
226
227
228
229
#!/bin/bash
# This program and the accompanying materials are made available under the
# terms of the MIT license (X11 license) which accompanies this distribution.
# author: C. Bürger
################################################################################################################ Parse arguments:
old_pwd=`pwd`
supported_systems=( racket guile larceny )
selected_systems=()
supported_libraries=( "$old_pwd"/racr )
supported_libraries+=( $(find "$old_pwd" -type f -name dependencies.txt | sed s/\\/dependencies.txt$// | grep -v /racr$) )
selected_libraries=()
while getopts s:i: opt
do
case $opt in
s)
if [[ " ${supported_systems[@]} " =~ " ${OPTARG} " ]]
then
if which "${OPTARG}" > /dev/null
then
selected_systems+=( "$OPTARG" )
else
echo " !!! ERROR: [$OPTARG] not installed !!!" >&2
exit 2
fi
else
echo " !!! ERROR: Unknown [$OPTARG] Scheme system !!!" >&2
exit 2
fi;;
i)
found=""
for l in ${supported_libraries[@]}
do
if `echo "$l" | grep -q "/${OPTARG}"$`
then
selected_libraries+=( "$l" )
found=true
fi
done
if [ -z "$found" ]
then
echo " !!! ERROR: Unknown [${OPTARG}] library !!!" >&2
exit 2
fi;;
?)
echo "Usage: -s Scheme system (${supported_systems[@]})"
echo " -i Module to install"
exit 2
esac
done
shift $(( OPTIND - 1 ))
if [ -z "$selected_systems" ]
then
for s in ${supported_systems[@]}
do
if which "$s" > /dev/null
then
selected_systems+=( "$s" )
fi
done
if [ -z "$selected_systems" ]
then
echo " !!! ERROR: No Scheme system found !!!" >&2
exit 2
fi
fi
if [ -z "$selected_libraries" ]
then
selected_libraries=${supported_libraries[@]}
fi
####################################################################################################### Define support functions:
read_dependencies(){
mode=initial
local_dir=`dirname "$1"`
local_systems=()
local_libraries=()
local_sources=()
while read line
do
case $mode in
initial)
if [ "$line" = "@systems:" ]
then
mode=systems
continue
fi
local_systems=${selected_systems[@]}
if [ "$line" = "@libraries:" ]
then
mode=libraries
continue
fi
if [ "$line" = "@sources:" ]
then
mode=sources
continue
fi
mode=sources
local_sources+=( "$local_dir/$line" );;
systems)
if [ "$line" = "@libraries:" ]
then
mode=libraries
continue
fi
if [ "$line" = "@sources:" ]
then
mode=sources
continue
fi
if [[ " ${selected_systems[@]} " =~ "$line" ]]
then
local_systems+=( "$line" )
fi
continue;;
libraries)
if [ "$line" = "@sources:" ]
then
mode=sources
continue
fi
local_libraries+=( "$local_dir/$line" );;
sources)
local_sources+=( "$local_dir/$line" );;
esac
done < "$1"
}
############################################################################################################## Install libraries:
if [[ " ${selected_systems[@]} " =~ "racket" ]]
then
echo "=========================================>>> Compile for Racket:"
for l in ${selected_libraries[@]}
do
read_dependencies "$l/dependencies.txt"
if [[ " ${local_systems[@]} " =~ "racket" ]]
then
rm -rf "$l/racket-bin"
mkdir -p "$l/racket-bin/`basename "$l"`"
lib_path=""
for x in ${local_libraries[@]}
do
lib_path+=" ++path $x/racket-bin"
done
for x in ${local_sources[@]}
do
plt-r6rs $lib_path --install --collections "$l/racket-bin" "$x.scm"
done
fi
done
fi
if [[ " ${selected_systems[@]} " =~ "guile" ]]
then
echo "==========================================>>> Compile for Guile:"
for l in ${selected_libraries[@]}
do
read_dependencies "$l/dependencies.txt"
if [[ " ${local_systems[@]} " =~ "guile" ]]
then
l_bin="$l/guile-bin"
l_lib="$l_bin/`basename "$l"`"
rm -rf "$l_bin"
mkdir -p "$l_lib"
lib_path="--load-path=$l_bin"
for x in ${local_libraries[@]}
do
lib_path+=" --load-path=$x/guile-bin"
done
for x in ${local_sources[@]}
do
cp -p "$x.scm" "$l_lib"
x=`basename "$x"`
guild compile $lib_path --output="$l_lib/$x.go" "$l_lib/$x.scm"
done
fi
done
fi
if [[ " ${selected_systems[@]} " =~ "larceny" ]]
then
echo "=========================================>>> Compile for larceny:"
# Create compile script:
cd $old_pwd
echo "#!r6rs" > compile-stale
echo "(import (rnrs) (larceny compiler))" >> compile-stale
echo "(compiler-switches (quote fast-safe))" >> compile-stale # Just for optimisation. Even more aggressive: fast-unsafe
echo "(compile-stale-libraries)" >> compile-stale
# Compile libraries:
for l in ${selected_libraries[@]}
do
read_dependencies "$l/dependencies.txt"
if [[ " ${local_systems[@]} " =~ "larceny" ]]
then
ll=`echo $l | rev | cut -d/ -f1 | rev` # Extract last file part of string
cd $l
rm -rf larceny-bin
mkdir -p larceny-bin/$ll
lib_path=".."
for x in ${local_libraries[@]}
do
lib_path+=":$x/larceny-bin"
done
for f in *.scm
do
cp -p $f larceny-bin/$ll/${f%.*}.sls
done
cd larceny-bin/$ll
cp -p $old_pwd/compile-stale .
larceny --r6rs --path $lib_path --program compile-stale
rm compile-stale
fi
done
# Delete compile script:
cd $old_pwd
rm compile-stale
fi
cd $old_pwd