forked from smlsharp/smlsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.ac
521 lines (453 loc) · 11.2 KB
/
configure.ac
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
# -*- Autoconf -*-
AC_PREREQ(2.61)
AC_INIT(smlsharp)
AC_CONFIG_SRCDIR([src/compiler/toplevel2/main/Top.sml])
AC_CONFIG_HEADER([config.h])
AC_CANONICAL_TARGET
AC_ARG_PROGRAM
# Checks for programs.
AC_PROG_CC
AC_LANG(C)
AC_PROG_CXX
AC_PROG_CXXCPP
AC_MSG_CHECKING([for gcc version])
version=`$CC -dumpversion 2> /dev/null || echo \*`
AC_MSG_RESULT([$version])
case "$version" in
[[0-3]].*|4.[[01]].*)
AC_MSG_ERROR([GCC 4.2 or later is required])
;;
esac
AC_PROG_MAKE_SET
AC_PROG_INSTALL
AC_PATH_PROG(FIND, find)
AC_PROG_RANLIB
AC_CHECK_TOOL(LD, ld)
AC_CHECK_TOOL(AR, ar)
#AC_CHECK_TOOL(WINDRES, windres)
#AC_PATH_PROG(DOXYGEN, doxygen)
: ${SMLFLAGS=-O2}
AC_SUBST(SMLFLAGS)
RUNTIME_DEFS=
AC_SUBST(RUNTIME_DEFS)
LIBEXT='a'
DLLEXT='so'
ASMEXT='s'
OBJEXT='o'
EXEEXT=
A_OUT='a.out'
RDYNAMIC_LDFLAGS=
RUNLOOP_DLDFLAGS=
EXTRA_OPTIONS=
AC_SUBST(LIBEXT)
AC_SUBST(DLLEXT)
AC_SUBST(ASMEXT)
AC_SUBST(OBJEXT)
AC_SUBST(EXEEXT)
AC_SUBST(A_OUT)
AC_SUBST(RDYNAMIC_LDFLAGS)
AC_SUBST(RUNLOOP_DLDFLAGS)
AC_SUBST(EXTRA_OPTIONS)
case "$host_os" in
# *cygwin*)
# DLLEXT='dll'
# EXEEXT=.exe
# A_OUT=a.exe
#AC_CHECK_TOOL(DLLTOOL, dlltool, :)
#AC_PATH_PROG(CYGPATH, cygpath)
#if test "x$CYGPATH" = "x"; then
# case "$host_os" in
# *cygwin*)
# AC_MSG_ERROR([cygpath is not found.])
# ;;
# esac
#fi
#AC_SUBST(CYGPATH)
#if test "x$WINDRES" != "x"; then
# RESOURCE_TYPE=rc
#fi
#AC_SUBST(RESOURCE_TYPE)
*mingw*)
DLLEXT='dll'
EXEEXT=.exe
A_OUT=a.exe
RDYNAMIC_LDFLAGS='-Wl,-Wl\\,--export-all-symbols -Wl,-Wl\\,--out-implib=src/compiler/smlsharp.lib'
RUNLOOP_DLDFLAGS='-shared -Wl,--enable-auto-import,--enable-stdcall-fixup'
;;
*darwin*)
LIBEXT='a'
DLLEXT='dylib'
RDYNAMIC_LDFLAGS=
RUNLOOP_DLDFLAGS='-dynamiclib -Wl,-undefined,dynamic_lookup,-flat_namespace'
;;
*linux*)
RDYNAMIC_LDFLAGS=-Wl,-rdynamic
RUNLOOP_DLDFLAGS=-shared
;;
esac
if test "x$RDYNAMIC_LDFLAGS" = "x" && test "x$RUNLOOP_DLDFLAGS" = "x"; then
AC_MSG_WARN(settings for dynamic linking is not specified. interactive mode may not work.)
RDYNAMIC_LDFLAGS=
RUNLOOP_DLDFLAGS=-shared
fi
case "$target_os" in
*mingw*)
HOST_OS_TYPE=Mingw
CMDLINE_MAXLEN='SOME 2047'
;;
*)
HOST_OS_TYPE=Unix
CMDLINE_MAXLEN='NONE'
;;
esac
AC_SUBST(HOST_OS_TYPE)
AC_SUBST(CMDLINE_MAXLEN)
# FIXME: check how to make a static library
# -------- Checks for LLVM --------
LLVM_PATH=$PATH
AC_ARG_WITH(llvm,
AS_HELP_STRING([--with-llvm],
[specify llvm directory]),
[ case "x$withval" in
no) ;;
yes) ;;
*) LLVM_PATH="$withval/bin:$LLVM_PATH" ;;
esac
])
AC_PATH_PROG(LLVM_CONFIG, llvm-config, [], $LLVM_PATH)
if test "x$LLVM_CONFIG" = "x"; then
AC_MSG_ERROR([llvm-config is not found.])
fi
AC_MSG_CHECKING([for llvm version])
ver=`$LLVM_CONFIG --version`
AC_MSG_RESULT($ver)
case "$ver" in
[[0-2]]*|3.[[0-3]]*)
AC_MSG_ERROR([llvm version 3.4 is required])
;;
3.4)
;;
*)
AC_MSG_WARN([LLVM later than 3.4 is found. Since SML[#] is written for LLVM 3.4, build will fail due to library incompatibility.])
;;
esac
AC_DEFUN(LLVM_FLAG, [
AC_MSG_CHECKING([for $1 for llvm])
LLVM_$1=`$[]LLVM_CONFIG --$2`
if test "$[]?" = "0"; then :; else AC_MSG_ERROR([failed]); fi
AC_MSG_RESULT($[]LLVM_$1)
AC_SUBST(LLVM_$1)
])
LLVM_FLAG(CXXFLAGS, cxxflags)
LLVM_FLAG(CPPFLAGS, cppflags)
LLVM_FLAG(LDFLAGS, ldflags)
LLVM_FLAG(LIBS, libs)
LLVM_SMLSHARP_LDFLAGS="-c++"
AC_SUBST(LLVM_SMLSHARP_LDFLAGS)
ldflags=
for i in $LLVM_LDFLAGS; do
case "$i" in
-L*)
LLVM_SMLSHARP_LDFLAGS="$LLVM_SMLSHARP_LDFLAGS $i"
ldflags="$ldflags $i"
;;
-l*)
LLVM_LIBS="$LLVM_LIBS $i"
;;
*)
LLVM_SMLSHARP_LDFLAGS="$LLVM_SMLSHARP_LDFLAGS -Wl,$i"
ldflags="$ldflags $i"
;;
esac
done
LLVM_LDFLAGS=$ldflags
orig_CPPFLAGS=$CPPFLAGS
CPPFLAGS=$LLVM_CPPFLAGS
AC_CHECK_DECLS([LLVM_NATIVE_TARGET],,
[ AC_MSG_ERROR([LLVM_NATIVE_TARGET is not defined])],
[#include <llvm/Config/llvm-config.h>])
CPPFLAGS=$orig_CPPFLAGS
# -------- Checks for SML compiler --------
SMLSHARP_STAGE0=
AC_SUBST(SMLSHARP_STAGE0)
SMLSHARP_STAGE1=./minismlsharp
AC_SUBST(SMLSHARP_STAGE1)
INCLUDE_STAGE1='# '
AC_SUBST(INCLUDE_STAGE1)
AC_ARG_WITH(stage0,
AS_HELP_STRING([--with-stage0],
[bootstrap with existing smlsharp command (may not work)]),
[
if test "x$withval" != "xno"; then
SML_PATH=$PATH
if test "x$withval" != "xyes"; then
SML_PATH="$withval/bin:$SML_PATH"
fi
AC_DEFUN(SMLSHARP_PROG, [
AC_PATH_PROG($1, $2, [], $SML_PATH)
if test "x$[]$1" = "x"; then
AC_MSG_ERROR([$2 is not found])
fi
])
SMLSHARP_PROG(SMLSHARP_STAGE0, smlsharp)
SMLSHARP_PROG(SMLFORMAT_STAGE0, smlformat)
SMLSHARP_PROG(SMLYACC_STAGE0, smlyacc)
SMLSHARP_PROG(SMLLEX_STAGE0, smllex)
INCLUDE_STAGE1=
SMLSHARP_STAGE1=./stage1
fi
])
if test "x$SMLSHARP_STAGE1" = "x./minismlsharp"; then
AC_PATH_PROG(XZ, xz)
if test "x$XZ" = "x"; then
AC_MSG_ERROR([xz is required to build smlsharp.])
fi
fi
# -------- Checks for multithreading --------
AC_ARG_ENABLE(thread,
AS_HELP_STRING([--enable-thread],
[enable experimental native thread support [[default=no]]]),
[
if test "x$enableval" != "xno"; then
RUNTIME_DEFS="$RUNTIME_DEFS -DMULTITHREAD"
SMLFLAGS="$SMLFLAGS -dinsertCheckGC=yes"
EXTRA_OPTIONS="$EXTRA_OPTIONS insertCheckGC=yes"
fi
])
# -------- Checks for native compile --------
TARGET_TRIPLE="$target"
AC_SUBST(TARGET_TRIPLE)
MINISMLSHARP_PRECOMPILED=
AC_SUBST(MINISMLSHARP_PRECOMPILED)
case "$TARGET_TRIPLE" in
x86_64-*-linux*)
TARGET_TRIPLE=`echo "$TARGET_TRIPLE" | sed 's,^x86_64,i686,'`
;;
esac
AC_MSG_CHECKING([whether target platform is supported])
case "$TARGET_TRIPLE" in
i[[3456]]86-*)
AC_MSG_RESULT([yes])
RUNTIME_DEFS="$RUNTIME_DEFS -DHOST_CPU_i386 -DMAXALIGN=16"
MINISMLSHARP_PRECOMPILED=x86
;;
*)
AC_MSG_RESULT([no])
AC_MSG_ERROR([target $TARGET_TRIPLE is not supported.])
;;
esac
PIC_DEFAULT=false
AC_SUBST(PIC_DEFAULT)
case "$TARGET_TRIPLE" in
*darwin*)
PIC_DEFAULT=true
;;
esac
# -------- Extra switches for developers --------
SNAPDATE_RULE_='# '
if test -f "$srcdir/../.hg/dirstate"; then
if test ! -f "$srcdir/RELEASE_DATE" \
|| grep '[[a-f]]' "$srcdir/RELEASE_DATE" > /dev/null 2>&1; then
SNAPDATE_RULE_=
fi
fi
AC_SUBST(SNAPDATE_RULE_)
HEAPIMPL=bitmap
AC_SUBST(HEAPIMPL)
AC_ARG_ENABLE(heapimpl,
AS_HELP_STRING([--enable-heapimpl],
[select heap management algorithm [[default=bitmap]]]),
[ HEAPIMPL=$enableval ])
AC_MSG_CHECKING([for heap management algorithm])
AC_MSG_RESULT([$HEAPIMPL])
if test ! -f "$srcdir/src/runtime/heap_$HEAPIMPL.c"; then
AC_MSG_ERROR([heap implementation \`$HEAPIMPL' is not available.])
fi
# -------- Checks for Libraries --------
AC_CHECK_LIB(m, sqrt)
AC_CHECK_LIB(socket, socket)
AC_CHECK_LIB(gmp, __gmpz_init,
[], [ AC_MSG_ERROR([GMP library is not found]) ])
AC_CHECK_LIB(dl, dlopen)
#AC_CHECK_LIB(dld, shl_load) # for HP-UX
## cygwin has dlopen in libcygwin.dll.
if test "x$ac_cv_lib_dl_dlopen" = "xno"; then
case "$target_os" in
*cygwin*)
AC_SEARCH_LIBS(dlopen, [dl],
[ ac_cv_lib_dl_dlopen=yes; echo "#define HAVE_LIBDL 1" >> confdefs.h ])
;;
*)
;;
esac
fi
AC_ARG_WITH(rt,
AS_HELP_STRING([--with-rt],[try to use clock_gettime for benchmark]),
[
if test "x$withval" != "xno"; then
AC_CHECK_LIB(rt, clock_gettime)
fi
])
if test "x$enable_thread" = "xyes"; then
AC_CHECK_LIB(pthread, pthread_create)
if test "x$ac_cv_lib_pthread_pthread_create" = "xno"; then
AC_MSG_ERROR([pthread library is not found.])
fi
fi
case "$target_os" in
*mingw*)
AC_DEFINE(MINGW32, 1, [Define if your system is Windows])
;;
esac
# FIXME: check for method for dynamic linking.
# check whether C++ is available as well as C
AC_LANG_PUSH(C++)
AC_MSG_CHECKING([whether C++ linker is available])
AC_LINK_IFELSE([AC_LANG_CALL([], [__gmpz_init])],
[ AC_MSG_RESULT(yes) ],
[ AC_MSG_RESULT(no)
AC_MSG_ERROR([failed to link libraries by $CXX.]) ])
AC_LANG_POP(C++)
# -------- Checks for Header Files --------
AC_DEFUN(REQUIRED_HEADER, [
AC_CHECK_HEADER($1, [], [
AC_MSG_ERROR([required header file <$1> is not found.])
])])
# C99 headers
REQUIRED_HEADER(assert.h)
REQUIRED_HEADER(ctype.h)
REQUIRED_HEADER(dirent.h)
REQUIRED_HEADER(errno.h)
REQUIRED_HEADER(limits.h)
REQUIRED_HEADER(math.h)
REQUIRED_HEADER(setjmp.h)
REQUIRED_HEADER(stdarg.h)
REQUIRED_HEADER(stddef.h)
REQUIRED_HEADER(stdint.h)
REQUIRED_HEADER(stdio.h)
REQUIRED_HEADER(stdlib.h)
REQUIRED_HEADER(string.h)
REQUIRED_HEADER(time.h)
# POSIX headers
REQUIRED_HEADER(unistd.h)
REQUIRED_HEADER(fcntl.h)
REQUIRED_HEADER(sys/time.h)
REQUIRED_HEADER(sys/stat.h)
if test "x$enable_thread" = "xyes"; then
REQUIRED_HEADER(pthread.h)
fi
REQUIRED_HEADER(signal.h)
case "$target_os" in
*mingw*)
# mingw does not have sigaction.
;;
*)
AC_CHECK_FUNCS([sigaction sigprocmask], [], [
AC_ERROR([POSIX signal functions are not found.])
])
;;
esac
# auxiliary libraries
REQUIRED_HEADER(gmp.h)
case "$target_os" in
*mingw*)
REQUIRED_HEADER(windows.h)
;;
esac
# for dlopen etc.
AC_CHECK_HEADERS(dlfcn.h)
# for poll
AC_CHECK_HEADERS(poll.h)
# for mmap
AC_CHECK_HEADERS(sys/mman.h)
AC_CHECK_HEADERS(sys/types.h)
# for fpclassify
AC_CHECK_HEADERS(float.h)
# for fpclass
AC_CHECK_HEADERS(ieeefp.h)
# for getrusage
AC_CHECK_HEADERS(sys/resource.h)
# for fesetround, fegetround
AC_CHECK_HEADERS(fenv.h)
# for times
AC_CHECK_HEADERS(sys/times.h)
# for utime
AC_CHECK_HEADERS(utime.h)
AC_CHECK_HEADERS([strings.h sys/socket.h])
# -------- check for C language --------
AC_C_CONST
AC_C_INLINE
AC_C_VOLATILE
AC_TYPE_SIZE_T
#AC_TYPE_SIGNAL
#AC_CHECK_SIZEOF(int)
#AC_CHECK_SIZEOF(short)
#AC_CHECK_SIZEOF(long)
#AC_CHECK_SIZEOF(void*)
#AC_CHECK_SIZEOF(float)
#AC_CHECK_SIZEOF(double)
AC_C_BIGENDIAN([
AC_DEFINE(WORDS_BIGENDIAN, [1], [Define if your processor is big endian])
])
AC_SUBST(BYTE_ORDER)
# -------- check for C functions --------
#AC_FUNC_FORK
#AC_FUNC_MALLOC
#AC_FUNC_REALLOC
AC_CHECK_FUNCS([ \
ceilf \
clock_gettime \
copysign \
copysignf \
dlopen \
fegetround \
fesetround \
finite \
floorf \
fpclass \
frexpf \
getrusage \
gettimeofday \
ldexpf \
mkstemp \
mmap \
modf \
modff \
nextafter \
nextafterf \
poll \
readlink \
roundf \
select \
sleep \
socket \
strptime \
times \
utime \
utimes \
])
AC_CHECK_DECLS([CLOCK_PROCESS_CPUTIME_ID],,,[#include <time.h>])
AC_CHECK_DECLS([fpclassify, isinf, isnan, isnormal, signbit],,,
[#include <math.h>])
# FreeBSD does not define fegetround/fesetround as library functions,
# but as inline functions in fenv.h.
if test "x$ac_cv_func_fegetround" = "xno"; then
AC_CHECK_DECLS([fegetround],,,[#include <fenv.h>])
fi
if test "x$ac_cv_func_fesetround" = "xno"; then
AC_CHECK_DECLS([fesetround],,,[#include <fenv.h>])
fi
# -------- Finale --------
AC_CONFIG_FILES([stamp-h config.mk src/config.mk Makefile],
[echo timestamp > stamp-h])
AC_OUTPUT
if test "x$no_create" != "xyes" && test "x$srcdir" != "x."; then
(cd "$srcdir" && $FIND precompiled src -type d) | while read i; do
AS_ECHO "creating directory $i"
mkdir "$i"
done
for i in src/builtin.smi; do
AS_ECHO "copying file $i"
cp $srcdir/$i $i
done
fi