-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathINSTALL.sh
executable file
·305 lines (257 loc) · 7.63 KB
/
INSTALL.sh
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#! /bin/sh
# CaGe install script, version 1.1
# Sebastian Lisken
# requires standard shell with 'expr' command.
### helper functions #################################################
error_exit ()
{
echo ""
echo "$1"
echo ""
exit 1
}
find_cmd ()
{
found=""
for cmd
do
t="` type $cmd 2>&- `"
if found="` expr \"$t\" : \"^$cmd is \(.*\)$\" 2>&- `"
then break
fi
done
test -n "$found" && echo "$found"
}
find_cmds ()
{
value=0
for cmd
do
find_cmd "$cmd" >/dev/null || { echo "$cmd"; value=1; }
done
return $value
}
parent ()
{
if parent="` expr \"$1\" : '^\(.*[^/]\)//*[^/][^/]*/*$' 2>&- `"
then echo "$parent"
elif expr "$1" : '^/' 2>&- >/dev/null
then echo "/"
else echo "."
fi
}
is_javadir ()
{
javadir="` parent \"$1\" `"
[ -x "$javadir/bin/$java_cmd" ] && [ ! -d "$javadir/bin/$java_cmd" ] && [ -r "$javadir/include/jni.h" ]
}
exec 0</dev/tty 1>/dev/tty 2>>/dev/tty
### Welcome message ##################################################
eval clear 2>&- || echo ""
echo ""
echo "C a G e -- Chemical & abstract Graph environment"
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo ""
### find out how to invoke echo with backslash escapes ###############
if [ -z "` echo '\c' `" ]
then esc=""
elif [ -z "` echo -e '\c' `" ]
then esc="-e"
else error_exit "Can't get 'echo' escapes to work - aborted."
fi
### see if 'read' has an '-e' option (read with completion) ##########
if echo . | eval "read -e test" 2>/dev/null
then with_completion="-e"
else with_completion=""
fi
### find a C compiler ################################################
echo ""
echo "* Looking for a C compiler ..."
if CC="` find_cmd gcc cc `"
then echo " Ok, using '$CC'."
else echo " None found. Make sure a C compiler ('cc' or 'gcc') is in your path."
error_exit "- Installation aborted."
fi
echo ""
export CC
### find other commands that we will need ############################
echo ""
echo "* Looking for commands: 'unzip', 'make', 'mkdir', 'chmod', 'find' ..."
if missing=` find_cmds unzip make mkdir chmod find `
then echo " All found."
else echo " Command(s) not found in your path: " $missing
error_exit "- Installation aborted."
fi
echo ""
### find the "bin" directory of a Java installation ##################
echo ""
echo "* Looking for a Java installation ..."
java_cmd="java"
javadirs=0
nl="
"
space=" "
javadirlist=""
javadirlist_get ()
{
num="$1"
expr "$nl$javadirlist" : ".*$nl[ ]*$num: \([^$nl]*\)"
}
add_to_javadirlist ()
{
dirlist="$1"
dirsep="$2"
get_parents="$3"
while dir="` expr \"$dirlist\" : \"^\([^$dirsep]*\)\" 2>&- `"
do
test "$get_parents" && dir="` parent \"$dir\" `"
test -z "$dir" && dir=.
if is_javadir "$dir"
then javadirs=` expr $javadirs + 1 `
javadirlist="$javadirlist $javadirs: $dir$nl"
# javadirlist="$javadirlist` expr substr ' ' '(' length $javadirs ')' 3 `$javadirs: $dir$nl"
fi
dirlist="` expr \"$dirlist\" : \"^[^$dirsep]*$dirsep\(.*\)$\" 2>&- `"
done
}
prepare_javadirlist_prompt ()
{
echo ""
if [ -z "$javadirlist" ]
then echo " None found. Enter a directory that contains the '$java_cmd' command."
prompt="directory: "
else if [ $javadirs -eq 1 ]
then directories_seem="directory seems"
choose_one="Choose it (enter 1)"
else directories_seem="directories seem"
choose_one="Choose one (enter its number)"
fi
echo " The following $directories_seem to be part of a Java installation."
echo " $choose_one or enter the path of another such directory."
prompt="number or directory: "
fi
echo " Enter '?' for a full search, '-' to exit."
}
#Check if command exists
if [ -f /usr/libexec/java_home ] && `/usr/libexec/java_home &> /dev/null`
then
#this is the correct javadir, add it to the PATH variable
homedir_mac=`/usr/libexec/java_home`/bin/:
else
#add empty dir to PATH
homedir_mac=''
fi
add_to_javadirlist "$PATH:$homedir_mac" ":"
prepare_javadirlist_prompt
choice=""
while [ -z "$choice" ]
do
echo ""
test -n "$javadirlist" && echo "$nl$javadirlist"
echo ""
echo $esc "$prompt\c"
read $with_completion choice
numeric="` expr \"$choice\" : '^\([1-9][0-9]*\)$' 2>&- `"
if [ "$choice" = "-" ]
then error_exit "- Installation cancelled."
elif [ "$choice" = "?" ]
then choice=""
echo ""
echo " Enter a list of directories to start searching from (space-separated)."
echo " An empty response cancels the search. You may use '/' to start a full"
echo " search. Some good start points are:"
echo ""
echo " /usr/lib/jvm (Linux)"
echo " /System /Libraries (Mac OS X)"
echo ""
echo $esc " start points: \c"
read $with_completion points
points="` expr \"$points\" : \"[$space]*\(.*[^$space]\)[$space]*$\" `"
test -z "$points" && continue
echo ""
echo ""
additional=""
test $javadirs -gt 0 && additional=" additional"
echo " Searching for$additional java directories ..."
add_to_javadirlist "` find $points \( -type f -o -type l \) -name "$java_cmd" -perm -ugo=x -print 2>/dev/null `" "$nl" true
prepare_javadirlist_prompt
elif [ "$numeric" ] && [ $choice -le $javadirs ]
then javadir="` javadirlist_get \"$choice\" `"
javadir="` parent \"$javadir\" `"
nonumber=""
elif is_javadir "$choice"
then nonumber=true
else echo ""
echo $esc " Sorry, your answer was incorrect. \c"
if [ $javadirs -eq 0 ] || [ -z "$numeric" ]
then echo "The directory must contain a '$java_cmd'"
echo " command and a \"sibling\" directory called 'include' containing 'jni.h'."
fi
echo " Try again or enter '?' for a full search, '-' to exit."
choice=""
fi
done
javadir="` cd \"$javadir\"; pwd `"
echo ""
echo " Ok."
echo ""
### found java installation in $javadir (bin/java and include/) ######
### find directory for native libraries ##############################
echo "echo '$javadir'" > javadir
sysname=` sh ./java -cp sysinfo.jar util.SysInfo os.name `
test -z "$sysname" && error_exit "- Can't determine system name ('java -cp sysinfo.jar util.SysInfo os.name') - aborted."
### find include files for native compilation ########################
include_other_dir=""
other_include="jni_md.h"
if [ ! -r "$javadir/include/$other_include" ]
then other_found=` echo "$javadir/include"/*/"$other_include" `
if [ "$other_found" != "$javadir/include/*/$other_include" ]
then include_other_dir=" -I` expr \"$other_found\" : \"^\([^ ]*\)/$other_include\" 2>&- `"
else echo " Warning: can't find include file '$other_include'."
echo " Making of native libraries might fail. Press Return."
read
fi
fi
echo ""
echo "* extracting C sources ..."
unzip -q CaGe-C.zip || error_exit "- 'unzip' failure, aborting."
#echo " Ok."
#echo ""
echo ""
echo "* Precomputing data in the background ..."
echo ""
(
cd PreCompute &&
make
make compute &
) || error_exit "- 'make' failure, aborting."
echo ""
echo " Ok."
echo ""
echo ""
echo "* Making generators and embedders ..."
echo ""
(
cd Generators &&
make
) || error_exit "- 'make' failure, aborting."
echo ""
echo " Ok."
echo ""
echo ""
echo "* Making native libraries ..."
echo ""
(
cd Native/src &&
mkdir -p ../$sysname &&
CPPFLAGS="$CPPFLAGS -I$javadir/include$include_other_dir -w" make "$sysname"
) || error_exit "- 'make' failure, aborting."
echo ""
echo " Ok."
echo ""
chmod u+x cage.sh
echo ""
echo "+ Installation successful - congratulations!"
echo " CaGe is started by the 'cage.sh' command."
echo " The file 'CaGe.ini' contains some options and comments."
echo ""