forked from gracelang/minigrace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·282 lines (259 loc) · 5.75 KB
/
configure
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
#!/usr/bin/env bash
export unset CDPATH
DISTRIB=tree
PLATFORM=$(uname)
PREFIX="/usr"
LDFLAGS=
UNICODE_LDFLAGS=
OTHER_MODULES=
INCLUDE_PATH='$(PREFIX)/include'
MODULE_PATH='$(PREFIX)/lib/grace/modules'
OBJECT_PATH='$(PREFIX)/lib/grace'
other_modules=(
mirrors
)
ADVISE_END=
advise() {
why=$1
ADVISE_END=$why
echo
echo "Problem configuring $why."
if [ -e "environ-$PLATFORM" ]
then
echo
echo Running the environ-$PLATFORM script may help to diagnose or
echo solve this problem.
echo
if ! [ "$IN_ENVIRON_SCRIPT" ]
then
echo Re-running configure inside environ-$PLATFORM.
echo
if ./environ-$PLATFORM ./configure
then
echo
echo As configure succeeded, launching a suitable environment
echo in which to run other programs. To obtain this environment
echo in future, run ./environ-$PLATFORM.
echo
exec ./environ-$PLATFORM
fi
exit $?
fi
fi
}
fail() {
advise "$@"
echo Failed.
exit 1
}
while [ $# -gt 0 ]
do
if [ "$1" = "--prefix" ]
then
PREFIX=`readlink -f $2`
shift
elif [ "$1" = "--static" ]
then
STATIC=y
elif [ "$1" = "--includedir" ]
then
INCLUDE_PATH=`readlink -f $2` #convert the potentially relative path to absolute before storing it
shift
elif [ "$1" = "--libdir" ]
then
MODULE_PATH=`readlink -f $2`/grace/modules
OBJECT_PATH=`readlink -f $2`/grace
shift
elif [ "$1" = "--objectpath" ]
then
OBJECT_PATH=`readlink -f $2`
shift
elif [ "$1" = "--help" ]
then
echo "Available flags:"
echo " --prefix <path>"
echo " --static {tarball only}"
echo " --includedir <path>"
echo " --libdir <path>"
echo " --objectpath <path>"
exit 0
else
echo "Unknown argument '$1'."
exit 1
fi
shift
done
if [ "$INCLUDE_PATH" = "" ]
then
INCLUDE_PATH="$PREFIX/include" #These are the defaults, relative to PREFIX
fi
if [ "$MODULE_PATH" = "" ]
then
MODULE_PATH="$PREFIX/lib/grace/modules"
fi
if [ "$OBJECT_PATH" = "" ]
then
OBJECT_PATH=`dirname $MODULE_PATH`
fi
checkcurl() {
echo -n "Checking for libcurl... "
cat <<EOT > configure-$$-tmp.c
#include <curl/curl.h>
int main(int argc, char **argv) {
CURL *handle = curl_easy_init();
return 0;
}
EOT
if gcc -o configure-$$-tmp configure-$$-tmp.c -lcurl
then
other_modules=${other_modules:+"${other_modules[@]}"}
echo yes
else
echo no
fi
rm -f configure-$$-tmp*
}
UNICODE_MODULE=unicode.gso
if grep -qi CYGWIN <<<"$PLATFORM"
then
STATIC=y
fi
if [ "$STATIC" ]
then
UNICODE_MODULE=unicode.gcn
STATIC_MODULES="unicode.gcn unixFilePath.gcn"
for mod in ${other_modules[@]}
do
OTHER_MODULES=(${OTHER_MODULES:+"${OTHER_MODULES[@]}"} $mod.gcn)
done
if [ -e minigrace.c ]
then
echo "Patching minigrace.c for static build..."
sed -i "" 's/dlmodule("unicode")/module_unicode_init()/' minigrace.c
fi
else
STATIC_MODULES=unixFilePath.gcn
checkcurl
for mod in ${other_modules[@]}
do
OTHER_MODULES=(${OTHER_MODULES:+"${OTHER_MODULES[@]}"} $mod.gso)
done
fi
echo -n "Locating linker... "
LD_PATH=$(which ld 2>/dev/null)
if [ "$LD_PATH" ]
then
echo $LD_PATH
else
echo "none."
fail "linker"
fi
echo -n "Checking linker... "
case "$(ld -v 2>&1)" in
"GNU ld"*)
GNU_LD=1
echo GNU LD.
LDFLAGS="-Wl,--export-dynamic"
;;
*PROJECT:ld*)
LLVM_LD=1
echo LLVM LD.
UNICODE_LDFLAGS="-Wl,-undefined -Wl,dynamic_lookup"
;;
*llvm*)
LLVM_LD=1
echo LLVM LD.
UNICODE_LDFLAGS="-Wl,-undefined -Wl,dynamic_lookup"
;;
*)
echo unknown.
;;
esac
echo -n "Checking for -ldl... "
if ld -o /dev/null -ldl >/dev/null 2>&1
then
echo yes.
LDFLAGS="$LDFLAGS -ldl"
else
echo no.
fi
echo -n "Locating GNU make... "
GMAKE_PATH=$(which gmake 2>/dev/null)
if [ "$GMAKE_PATH" ]
then
echo $GMAKE_PATH
else
GMAKE_PATH=$(which make 2>/dev/null)
if [ "$GMAKE_PATH" ]
then
echo $GMAKE_PATH
else
echo "none."
advise "GNU make"
fi
fi
MK=make
if gmake -v 2>&1 | grep -q GNU
then
MK=gmake
elif make -v 2>&1 | grep -q GNU
then
MK=make
else
echo "This software requires GNU make to build."
echo "Substitute the path to your GNU make below."
fi
echo -n "Locating gcc... "
GCC_PATH=$(which gcc 2>/dev/null)
if [ "$GCC_PATH" ]
then
echo $GCC_PATH
else
echo "none."
fail "gcc"
fi
echo -n "Checking GCC search paths... "
cat <<EOT >> configure-$$-tmp.c
#include <setjmp.h>
int main() {
return 0;
}
EOT
if ! gcc -o configure-$$-tmp configure-$$-tmp.c
then
fail "gcc"
else
echo "OK."
fi
rm -f configure-$$-tmp*
if [ "$DISTRIB" = "tarball" ]
then
echo "Run '$MK' to build, and '$MK selfhost' to have it compile itself."
else
echo "Run '$MK' to build."
fi
STUBS=$(cd stubs; ls *.grace | tr \\n ' ')
LIBRARY_MODULES=$(cd modules; ls *.grace | grep -v Test | tr \\n ' ')
ICONS=$(cd js; ls *.png | tr \\n ' ')
cat <<EOT > Makefile.conf
PREFIX ?= $PREFIX
LDFLAGS = $LDFLAGS -lm
UNICODE_LDFLAGS = $UNICODE_LDFLAGS
UNICODE_MODULE = $UNICODE_MODULE
STATIC_MODULES = $STATIC_MODULES
OTHER_MODULES = ${OTHER_MODULES[@]}
STUBS = $STUBS
LIBRARY_MODULES = $LIBRARY_MODULES
ICONS = $ICONS
INCLUDE_PATH = $INCLUDE_PATH
MODULE_PATH = $MODULE_PATH
OBJECT_PATH = $OBJECT_PATH
EOT
if [ "$ADVISE_END" ]
then
echo configure encountered a non-fatal configuration problem.
advise "$ADVISE_END"
echo
echo This issue did not cause configure to fail, but you may wish to
echo investigate it.
fi