4
dnl Copyright Ericsson AB 1998-2010. All Rights Reserved.
6
dnl The contents of this file are subject to the Erlang Public License,
7
dnl Version 1.1, (the "License"); you may not use this file except in
8
dnl compliance with the License. You should have received a copy of the
9
dnl Erlang Public License along with this software. If not, it can be
10
dnl retrieved online at http://www.erlang.org/.
12
dnl Software distributed under the License is distributed on an "AS IS"
13
dnl basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
dnl the License for the specific language governing rights and limitations
15
dnl under the License.
23
dnl Local macros used in configure.in. The Local Macros which
24
dnl could/should be part of autoconf are prefixed LM_, macros specific
25
dnl to the Erlang system are prefixed ERL_.
28
AC_DEFUN(LM_PRECIOUS_VARS,
32
AC_ARG_VAR(ERL_TOP, [Erlang/OTP top source directory])
35
AC_ARG_VAR(CC, [C compiler])
36
AC_ARG_VAR(CFLAGS, [C compiler flags])
37
AC_ARG_VAR(STATIC_CFLAGS, [C compiler static flags])
38
AC_ARG_VAR(CFLAG_RUNTIME_LIBRARY_PATH, [runtime library path linker flag passed via C compiler])
39
AC_ARG_VAR(CPP, [C/C++ preprocessor])
40
AC_ARG_VAR(CPPFLAGS, [C/C++ preprocessor flags])
41
AC_ARG_VAR(CXX, [C++ compiler])
42
AC_ARG_VAR(CXXFLAGS, [C++ compiler flags])
43
AC_ARG_VAR(LD, [linker (is often overridden by configure)])
44
AC_ARG_VAR(LDFLAGS, [linker flags (can be risky to set since LD may be overriden by configure)])
45
AC_ARG_VAR(LIBS, [libraries])
46
AC_ARG_VAR(DED_LD, [linker for Dynamic Erlang Drivers (set all DED_LD* variables or none)])
47
AC_ARG_VAR(DED_LDFLAGS, [linker flags for Dynamic Erlang Drivers (set all DED_LD* variables or none)])
48
AC_ARG_VAR(DED_LD_FLAG_RUNTIME_LIBRARY_PATH, [runtime library path linker flag for Dynamic Erlang Drivers (set all DED_LD* variables or none)])
49
AC_ARG_VAR(LFS_CFLAGS, [large file support C compiler flags (set all LFS_* variables or none)])
50
AC_ARG_VAR(LFS_LDFLAGS, [large file support linker flags (set all LFS_* variables or none)])
51
AC_ARG_VAR(LFS_LIBS, [large file support libraries (set all LFS_* variables or none)])
52
AC_ARG_VAR(RANLIB, [ranlib])
54
AC_ARG_VAR(GETCONF, [getconf])
57
AC_ARG_VAR(erl_xcomp_sysroot, [Absolute cross system root path (only used when cross compiling)])
58
AC_ARG_VAR(erl_xcomp_isysroot, [Absolute cross system root include path (only used when cross compiling)])
60
dnl Cross compilation variables
61
AC_ARG_VAR(erl_xcomp_bigendian, [big endian system: yes|no (only used when cross compiling)])
62
AC_ARG_VAR(erl_xcomp_linux_clock_gettime_correction, [clock_gettime() can be used for time correction: yes|no (only used when cross compiling)])
63
AC_ARG_VAR(erl_xcomp_linux_nptl, [have Native POSIX Thread Library: yes|no (only used when cross compiling)])
64
AC_ARG_VAR(erl_xcomp_linux_usable_sigusrx, [SIGUSR1 and SIGUSR2 can be used: yes|no (only used when cross compiling)])
65
AC_ARG_VAR(erl_xcomp_linux_usable_sigaltstack, [have working sigaltstack(): yes|no (only used when cross compiling)])
66
AC_ARG_VAR(erl_xcomp_poll, [have working poll(): yes|no (only used when cross compiling)])
67
AC_ARG_VAR(erl_xcomp_kqueue, [have working kqueue(): yes|no (only used when cross compiling)])
68
AC_ARG_VAR(erl_xcomp_putenv_copy, [putenv() stores key-value copy: yes|no (only used when cross compiling)])
69
AC_ARG_VAR(erl_xcomp_reliable_fpe, [have reliable floating point exceptions: yes|no (only used when cross compiling)])
70
AC_ARG_VAR(erl_xcomp_getaddrinfo, [have working getaddrinfo() for both IPv4 and IPv6: yes|no (only used when cross compiling)])
71
AC_ARG_VAR(erl_xcomp_gethrvtime_procfs_ioctl, [have working gethrvtime() which can be used with procfs ioctl(): yes|no (only used when cross compiling)])
72
AC_ARG_VAR(erl_xcomp_clock_gettime_cpu_time, [clock_gettime() can be used for retrieving process CPU time: yes|no (only used when cross compiling)])
73
AC_ARG_VAR(erl_xcomp_after_morecore_hook, [__after_morecore_hook can track malloc()s core memory usage: yes|no (only used when cross compiling)])
74
AC_ARG_VAR(erl_xcomp_dlsym_brk_wrappers, [dlsym(RTLD_NEXT, _) brk wrappers can track malloc()s core memory usage: yes|no (only used when cross compiling)])
78
AC_DEFUN(ERL_XCOMP_SYSROOT_INIT,
80
erl_xcomp_without_sysroot=no
81
if test "$cross_compiling" = "yes"; then
82
test "$erl_xcomp_sysroot" != "" || erl_xcomp_without_sysroot=yes
83
test "$erl_xcomp_isysroot" != "" || erl_xcomp_isysroot="$erl_xcomp_sysroot"
90
AC_DEFUN(LM_CHECK_GETCONF,
92
if test "$cross_compiling" != "yes"; then
93
AC_CHECK_PROG([GETCONF], [getconf], [getconf], [false])
95
dnl First check if we got a `<HOST>-getconf' in $PATH
96
host_getconf="$host_alias-getconf"
97
AC_CHECK_PROG([GETCONF], [$host_getconf], [$host_getconf], [false])
98
if test "$GETCONF" = "false" && test "$erl_xcomp_sysroot" != ""; then
99
dnl We should perhaps give up if we have'nt found it by now, but at
100
dnl least in one Tilera MDE `getconf' under sysroot is a bourne
101
dnl shell script which we can use. We try to find `<HOST>-getconf'
102
dnl or `getconf' under sysconf, but only under sysconf since
103
dnl `getconf' in $PATH is almost guaranteed to be for the build
106
prfx="$erl_xcomp_sysroot"
107
AC_PATH_TOOL([GETCONF], [getconf], [false],
108
["$prfx/usr/bin:$prfx/bin:$prfx/usr/local/bin"])
113
dnl ----------------------------------------------------------------------
118
dnl Tries fairly hard to find a C compiler that can handle jump tables.
119
dnl Defines the @EMU_CC@ variable for the makefiles and
120
dnl inserts NO_JUMP_TABLE in the header if one cannot be found...
123
AC_DEFUN(LM_FIND_EMU_CC,
124
[AC_CACHE_CHECK(for a compiler that handles jumptables,
131
static void *jtab[2];
140
],ac_cv_prog_emu_cc=$CC,ac_cv_prog_emu_cc=no)
142
if test $ac_cv_prog_emu_cc = no; then
143
for ac_progname in emu_cc.sh gcc; do
144
IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
146
for ac_dir in $ac_dummy; do
147
test -z "$ac_dir" && ac_dir=.
148
if test -f $ac_dir/$ac_progname; then
149
ac_cv_prog_emu_cc=$ac_dir/$ac_progname
154
if test $ac_cv_prog_emu_cc != no; then
160
if test $ac_cv_prog_emu_cc != no; then
163
save_CPPFLAGS=$CPPFLAGS
164
CC=$ac_cv_prog_emu_cc
171
static void *jtab[2];
180
],ac_cv_prog_emu_cc=$CC,ac_cv_prog_emu_cc=no)
183
CPPFLAGS=$save_CPPFLAGS
186
if test $ac_cv_prog_emu_cc = no; then
187
AC_DEFINE(NO_JUMP_TABLE,[],[Defined if no found C compiler can handle jump tables])
190
EMU_CC=$ac_cv_prog_emu_cc
197
dnl ----------------------------------------------------------------------
199
dnl LM_PROG_INSTALL_DIR
201
dnl This macro may be used by any OTP application.
203
dnl Figure out how to create directories with parents.
204
dnl (In my opinion INSTALL_DIR is a bad name, MKSUBDIRS or something is better)
206
dnl We prefer 'install -d', but use 'mkdir -p' if it exists.
207
dnl If none of these methods works, we give up.
211
AC_DEFUN(LM_PROG_INSTALL_DIR,
212
[AC_CACHE_CHECK(how to create a directory including parents,
215
temp_name_base=config.$$
216
temp_name=$temp_name_base/x/y/z
217
$INSTALL -d $temp_name >/dev/null 2>&1
218
ac_cv_prog_mkdir_p=none
219
if test -d $temp_name; then
220
ac_cv_prog_mkdir_p="$INSTALL -d"
222
mkdir -p $temp_name >/dev/null 2>&1
223
if test -d $temp_name; then
224
ac_cv_prog_mkdir_p="mkdir -p"
227
rm -fr $temp_name_base
230
case "${ac_cv_prog_mkdir_p}" in
231
none) AC_MSG_ERROR(don't know how create directories with parents) ;;
232
*) INSTALL_DIR="$ac_cv_prog_mkdir_p" AC_SUBST(INSTALL_DIR) ;;
237
dnl ----------------------------------------------------------------------
241
dnl Try to find perl version 5. If found set PERL to the absolute path
242
dnl of the program, if not found set PERL to false.
244
dnl On some systems /usr/bin/perl is perl 4 and e.g.
245
dnl /usr/local/bin/perl is perl 5. We try to handle this case by
246
dnl putting a couple of
247
dnl Tries to handle the case that there are two programs called perl
248
dnl in the path and one of them is perl 5 and the other isn't.
250
AC_DEFUN(LM_PROG_PERL5,
251
[AC_PATH_PROGS(PERL, perl5 perl, false,
252
/usr/local/bin:/opt/local/bin:/usr/local/gnu/bin:${PATH})
254
dnl[ That bracket is needed to balance the right bracket below
255
if test "$PERL" = "false" || $PERL -e 'exit ($] >= 5)'; then
257
ac_cv_path_PERL=false
259
dnl AC_MSG_WARN(perl version 5 not found)
264
dnl ----------------------------------------------------------------------
266
dnl LM_DECL_SO_BSDCOMPAT
268
dnl Check if the system has the SO_BSDCOMPAT flag on sockets (linux)
270
AC_DEFUN(LM_DECL_SO_BSDCOMPAT,
271
[AC_CACHE_CHECK([for SO_BSDCOMPAT declaration], ac_cv_decl_so_bsdcompat,
272
AC_TRY_COMPILE([#include <sys/socket.h>], [int i = SO_BSDCOMPAT;],
273
ac_cv_decl_so_bsdcompat=yes,
274
ac_cv_decl_so_bsdcompat=no))
276
case "${ac_cv_decl_so_bsdcompat}" in
277
"yes" ) AC_DEFINE(HAVE_SO_BSDCOMPAT,[],
278
[Define if you have SO_BSDCOMPAT flag on sockets]) ;;
284
dnl ----------------------------------------------------------------------
286
dnl LM_DECL_INADDR_LOOPBACK
288
dnl Try to find declaration of INADDR_LOOPBACK, if nowhere provide a default
291
AC_DEFUN(LM_DECL_INADDR_LOOPBACK,
292
[AC_CACHE_CHECK([for INADDR_LOOPBACK in netinet/in.h],
293
ac_cv_decl_inaddr_loopback,
294
[AC_TRY_COMPILE([#include <sys/types.h>
295
#include <netinet/in.h>], [int i = INADDR_LOOPBACK;],
296
ac_cv_decl_inaddr_loopback=yes, ac_cv_decl_inaddr_loopback=no)
299
if test ${ac_cv_decl_inaddr_loopback} = no; then
300
AC_CACHE_CHECK([for INADDR_LOOPBACK in rpc/types.h],
301
ac_cv_decl_inaddr_loopback_rpc,
302
AC_TRY_COMPILE([#include <rpc/types.h>],
303
[int i = INADDR_LOOPBACK;],
304
ac_cv_decl_inaddr_loopback_rpc=yes,
305
ac_cv_decl_inaddr_loopback_rpc=no))
307
case "${ac_cv_decl_inaddr_loopback_rpc}" in
309
AC_DEFINE(DEF_INADDR_LOOPBACK_IN_RPC_TYPES_H,[],
310
[Define if you need to include rpc/types.h to get INADDR_LOOPBACK defined]) ;;
312
AC_CACHE_CHECK([for INADDR_LOOPBACK in winsock2.h],
313
ac_cv_decl_inaddr_loopback_winsock2,
314
AC_TRY_COMPILE([#define WIN32_LEAN_AND_MEAN
315
#include <winsock2.h>],
316
[int i = INADDR_LOOPBACK;],
317
ac_cv_decl_inaddr_loopback_winsock2=yes,
318
ac_cv_decl_inaddr_loopback_winsock2=no))
319
case "${ac_cv_decl_inaddr_loopback_winsock2}" in
321
AC_DEFINE(DEF_INADDR_LOOPBACK_IN_WINSOCK2_H,[],
322
[Define if you need to include winsock2.h to get INADDR_LOOPBACK defined]) ;;
324
# couldn't find it anywhere
325
AC_DEFINE(HAVE_NO_INADDR_LOOPBACK,[],
326
[Define if you don't have a definition of INADDR_LOOPBACK]) ;;
333
dnl ----------------------------------------------------------------------
335
dnl LM_STRUCT_SOCKADDR_SA_LEN
337
dnl Check if the sockaddr structure has the field sa_len
340
AC_DEFUN(LM_STRUCT_SOCKADDR_SA_LEN,
341
[AC_CACHE_CHECK([whether struct sockaddr has sa_len field],
342
ac_cv_struct_sockaddr_sa_len,
343
AC_TRY_COMPILE([#include <sys/types.h>
344
#include <sys/socket.h>], [struct sockaddr s; s.sa_len = 10;],
345
ac_cv_struct_sockaddr_sa_len=yes, ac_cv_struct_sockaddr_sa_len=no))
348
case ${ac_cv_struct_sockaddr_sa_len} in
349
"no" ) AC_DEFINE(NO_SA_LEN,[1],[Define if you dont have salen]) ;;
354
dnl ----------------------------------------------------------------------
356
dnl LM_STRUCT_EXCEPTION
358
dnl Check to see whether the system supports the matherr function
359
dnl and its associated type "struct exception".
362
AC_DEFUN(LM_STRUCT_EXCEPTION,
363
[AC_CACHE_CHECK([for struct exception (and matherr function)],
364
ac_cv_struct_exception,
365
AC_TRY_COMPILE([#include <math.h>],
366
[struct exception x; x.type = DOMAIN; x.type = SING;],
367
ac_cv_struct_exception=yes, ac_cv_struct_exception=no))
369
case "${ac_cv_struct_exception}" in
370
"yes" ) AC_DEFINE(USE_MATHERR,[1],[Define if you have matherr() function and struct exception type]) ;;
376
dnl ----------------------------------------------------------------------
380
dnl Check for ipv6 support and what the in6_addr structure is called.
381
dnl (early linux used in_addr6 insted of in6_addr)
384
AC_DEFUN(LM_SYS_IPV6,
385
[AC_MSG_CHECKING(for IP version 6 support)
386
AC_CACHE_VAL(ac_cv_sys_ipv6_support,
388
AC_TRY_COMPILE([#include <sys/types.h>
390
#include <winsock2.h>
391
#include <ws2tcpip.h>
393
#include <netinet/in.h>
395
[struct in6_addr a6; struct sockaddr_in6 s6;], ok_so_far=yes, ok_so_far=no)
397
if test $ok_so_far = yes; then
398
ac_cv_sys_ipv6_support=yes
400
AC_TRY_COMPILE([#include <sys/types.h>
402
#include <winsock2.h>
403
#include <ws2tcpip.h>
405
#include <netinet/in.h>
407
[struct in_addr6 a6; struct sockaddr_in6 s6;],
408
ac_cv_sys_ipv6_support=in_addr6, ac_cv_sys_ipv6_support=no)
413
dnl Have to use old style AC_DEFINE due to BC with old autoconf.
416
case ${ac_cv_sys_ipv6_support} in
419
AC_DEFINE(HAVE_IN6,[1],[Define if ipv6 is present])
422
AC_MSG_RESULT([yes (but I am redefining in_addr6 to in6_addr)])
423
AC_DEFINE(HAVE_IN6,[1],[Define if ipv6 is present])
424
AC_DEFINE(HAVE_IN_ADDR6_STRUCT,[],[Early linux used in_addr6 instead of in6_addr, define if you have this])
433
dnl ----------------------------------------------------------------------
437
dnl Check for multicast support. Only checks for multicast options in
438
dnl setsockopt(), no check is performed that multicasting actually works.
439
dnl If options are found defines HAVE_MULTICAST_SUPPORT
442
AC_DEFUN(LM_SYS_MULTICAST,
443
[AC_CACHE_CHECK([for multicast support], ac_cv_sys_multicast_support,
445
[#include <sys/types.h>
446
#include <sys/socket.h>
447
#include <netinet/in.h>
448
#if defined(IP_MULTICAST_TTL) && defined(IP_MULTICAST_LOOP) && defined(IP_MULTICAST_IF) && defined(IP_ADD_MEMBERSHIP) && defined(IP_DROP_MEMBERSHIP)
451
], ac_cv_sys_multicast_support=yes, ac_cv_sys_multicast_support=no)])
452
if test $ac_cv_sys_multicast_support = yes; then
453
AC_DEFINE(HAVE_MULTICAST_SUPPORT,[1],
454
[Define if setsockopt() accepts multicast options])
459
dnl ----------------------------------------------------------------------
461
dnl LM_DECL_SYS_ERRLIST
463
dnl Define SYS_ERRLIST_DECLARED if the variable sys_errlist is declared
464
dnl in a system header file, stdio.h or errno.h.
467
AC_DEFUN(LM_DECL_SYS_ERRLIST,
468
[AC_CACHE_CHECK([for sys_errlist declaration in stdio.h or errno.h],
469
ac_cv_decl_sys_errlist,
470
[AC_TRY_COMPILE([#include <stdio.h>
471
#include <errno.h>], [char *msg = *(sys_errlist + 1);],
472
ac_cv_decl_sys_errlist=yes, ac_cv_decl_sys_errlist=no)])
473
if test $ac_cv_decl_sys_errlist = yes; then
474
AC_DEFINE(SYS_ERRLIST_DECLARED,[],
475
[define if the variable sys_errlist is declared in a system header file])
480
dnl ----------------------------------------------------------------------
482
dnl LM_CHECK_FUNC_DECL( funname, declaration [, extra includes
483
dnl [, action-if-found [, action-if-not-found]]] )
485
dnl Checks if the declaration "declaration" of "funname" conflicts
486
dnl with the header files idea of how the function should be
487
dnl declared. It is useful on systems which lack prototypes and you
488
dnl need to provide your own (e.g. when you want to take the address
489
dnl of a function). The 4'th argument is expanded if conflicting,
490
dnl the 5'th argument otherwise
494
AC_DEFUN(LM_CHECK_FUNC_DECL,
495
[AC_MSG_CHECKING([for conflicting declaration of $1])
496
AC_CACHE_VAL(ac_cv_func_decl_$1,
497
[AC_TRY_COMPILE([#include <stdio.h>
499
char *c = (char *)$1;
500
], eval "ac_cv_func_decl_$1=no", eval "ac_cv_func_decl_$1=yes")])
501
if eval "test \"`echo '$ac_cv_func_decl_'$1`\" = yes"; then
503
ifelse([$4], , :, [$4])
512
dnl ----------------------------------------------------------------------
516
dnl This macro may be used by any OTP application.
518
dnl LM_CHECK_THR_LIB sets THR_LIBS, THR_DEFS, and THR_LIB_NAME. It also
519
dnl checks for some pthread headers which will appear in DEFS or config.h.
522
AC_DEFUN(LM_CHECK_THR_LIB,
525
NEED_NPTL_PTHREAD_H=no
528
AC_MSG_CHECKING([for native win32 threads])
529
if test "X$host_os" = "Xwin32"; then
531
THR_DEFS="-DWIN32_THREADS"
533
THR_LIB_NAME=win32_threads
534
THR_LIB_TYPE=win32_threads
540
THR_LIB_TYPE=posix_unknown
542
dnl Try to find POSIX threads
544
dnl The usual pthread lib...
545
AC_CHECK_LIB(pthread, pthread_create, THR_LIBS="-lpthread")
547
dnl FreeBSD has pthreads in special c library, c_r...
548
if test "x$THR_LIBS" = "x"; then
549
AC_CHECK_LIB(c_r, pthread_create, THR_LIBS="-lc_r")
552
dnl On ofs1 the '-pthread' switch should be used
553
if test "x$THR_LIBS" = "x"; then
554
AC_MSG_CHECKING([if the '-pthread' switch can be used])
556
CFLAGS="$CFLAGS -pthread"
557
AC_TRY_LINK([#include <pthread.h>],
558
pthread_create((void*)0,(void*)0,(void*)0,(void*)0);,
560
THR_LIBS="-pthread"])
562
if test "x$THR_LIBS" != "x"; then
569
if test "x$THR_LIBS" != "x"; then
570
THR_DEFS="$THR_DEFS -D_THREAD_SAFE -D_REENTRANT -DPOSIX_THREADS"
574
THR_DEFS="$THR_DEFS -D_POSIX_PTHREAD_SEMANTICS" ;;
576
THR_DEFS="$THR_DEFS -D_POSIX_THREAD_SAFE_FUNCTIONS"
579
AC_MSG_CHECKING(for Native POSIX Thread Library)
580
libpthr_vsn=`$GETCONF GNU_LIBPTHREAD_VERSION 2>/dev/null`
581
if test $? -eq 0; then
582
case "$libpthr_vsn" in
583
*nptl*|*NPTL*) nptl=yes;;
586
elif test "$cross_compiling" = "yes"; then
587
case "$erl_xcomp_linux_nptl" in
589
yes|no) nptl=$erl_xcomp_linux_nptl;;
590
*) AC_MSG_ERROR([Bad erl_xcomp_linux_nptl value: $erl_xcomp_linux_nptl]);;
596
if test $nptl = cross; then
598
AC_MSG_WARN([result yes guessed because of cross compilation])
600
if test $nptl = yes; then
601
THR_LIB_TYPE=posix_nptl
603
AC_CHECK_HEADER(nptl/pthread.h,
604
[need_nptl_incldir=yes
605
NEED_NPTL_PTHREAD_H=yes])
606
if test $need_nptl_incldir = yes; then
608
nptl_path="$C_INCLUDE_PATH:$CPATH"
609
if test X$cross_compiling != Xyes; then
610
nptl_path="$nptl_path:/usr/local/include:/usr/include"
612
IROOT="$erl_xcomp_isysroot"
613
test "$IROOT" != "" || IROOT="$erl_xcomp_sysroot"
614
test "$IROOT" != "" || AC_MSG_ERROR([Don't know where to search for includes! Please set erl_xcomp_isysroot])
615
nptl_path="$nptl_path:$IROOT/usr/local/include:$IROOT/usr/include"
618
save_ifs="$IFS"; IFS=":"
619
for dir in $nptl_path; do
620
if test "x$dir" != "x"; then
621
nptl_ws_path="$nptl_ws_path $dir"
626
for dir in $nptl_ws_path; do
627
AC_CHECK_HEADER($dir/nptl/pthread.h,
628
nptl_incldir=$dir/nptl)
629
if test "x$nptl_incldir" != "x"; then
630
THR_DEFS="$THR_DEFS -isystem $nptl_incldir"
634
if test "x$nptl_incldir" = "x"; then
635
AC_MSG_ERROR(Failed to locate nptl system include directory)
643
dnl We sometimes need THR_DEFS in order to find certain headers
644
dnl (at least for pthread.h on osf1).
645
saved_cppflags=$CPPFLAGS
646
CPPFLAGS="$CPPFLAGS $THR_DEFS"
649
dnl Check for headers
652
AC_CHECK_HEADER(pthread.h,
653
AC_DEFINE(HAVE_PTHREAD_H, 1, \
654
[Define if you have the <pthread.h> header file.]))
656
dnl Some Linuxes have <pthread/mit/pthread.h> instead of <pthread.h>
657
AC_CHECK_HEADER(pthread/mit/pthread.h, \
658
AC_DEFINE(HAVE_MIT_PTHREAD_H, 1, \
659
[Define if the pthread.h header file is in pthread/mit directory.]))
662
CPPFLAGS=$saved_cppflags
669
AC_DEFUN(ERL_INTERNAL_LIBS,
672
ERTS_INTERNAL_X_LIBS=
674
AC_CHECK_LIB(kstat, kstat_open,
675
[AC_DEFINE(HAVE_KSTAT, 1, [Define if you have kstat])
676
ERTS_INTERNAL_X_LIBS="$ERTS_INTERNAL_X_LIBS -lkstat"])
678
AC_SUBST(ERTS_INTERNAL_X_LIBS)
682
dnl ----------------------------------------------------------------------
684
dnl ERL_FIND_ETHR_LIB
686
dnl NOTE! This macro may be changed at any time! Should *only* be used by
689
dnl Find a thread library to use. Sets ETHR_LIBS to libraries to link
690
dnl with, ETHR_X_LIBS to extra libraries to link with (same as ETHR_LIBS
691
dnl except that the ethread lib itself is not included), ETHR_DEFS to
692
dnl defines to compile with, ETHR_THR_LIB_BASE to the name of the
693
dnl thread library which the ethread library is based on, and ETHR_LIB_NAME
694
dnl to the name of the library where the ethread implementation is located.
695
dnl ERL_FIND_ETHR_LIB currently searches for 'pthreads', and
696
dnl 'win32_threads'. If no thread library was found ETHR_LIBS, ETHR_X_LIBS,
697
dnl ETHR_DEFS, ETHR_THR_LIB_BASE, and ETHR_LIB_NAME are all set to the
701
AC_DEFUN(ERL_FIND_ETHR_LIB,
707
ethr_have_native_atomics=no
708
ethr_have_native_spinlock=no
709
ETHR_THR_LIB_BASE="$THR_LIB_NAME"
710
ETHR_THR_LIB_BASE_TYPE="$THR_LIB_TYPE"
711
ETHR_DEFS="$THR_DEFS"
712
ETHR_X_LIBS="$THR_LIBS $ERTS_INTERNAL_X_LIBS"
716
ethr_modified_default_stack_size=
718
dnl Name of lib where ethread implementation is located
719
ethr_lib_name=ethread
721
case "$THR_LIB_NAME" in
724
ETHR_THR_LIB_BASE_DIR=win
725
# * _WIN32_WINNT >= 0x0400 is needed for
726
# TryEnterCriticalSection
727
# * _WIN32_WINNT >= 0x0403 is needed for
728
# InitializeCriticalSectionAndSpinCount
729
# The ethread lib will refuse to build if _WIN32_WINNT < 0x0403.
731
# -D_WIN32_WINNT should have been defined in $CPPFLAGS; fetch it
732
# and save it in ETHR_DEFS.
734
for cppflag in $CPPFLAGS; do
737
ETHR_DEFS="$ETHR_DEFS $cppflag"
740
ETHR_DEFS="$ETHR_DEFS $cppflag"
741
found_win32_winnt=yes
747
if test $found_win32_winnt = no; then
748
AC_MSG_ERROR([-D_WIN32_WINNT missing in CPPFLAGS])
751
AC_DEFINE(ETHR_WIN32_THREADS, 1, [Define if you have win32 threads])
754
AC_MSG_CHECKING([for _InterlockedCompareExchange64()])
756
#define WIN32_LEAN_AND_MEAN
760
volatile __int64 *var;
761
_InterlockedCompareExchange64(var, (__int64) 1, (__int64) 0);
765
AC_MSG_RESULT([$have_ilckd])
766
test $have_ilckd = yes && AC_DEFINE(ETHR_HAVE__INTERLOCKEDCOMPAREEXCHANGE64, 1, [Define if you have _InterlockedCompareExchange64()])
768
AC_CHECK_SIZEOF(void *)
769
case "$ac_cv_sizeof_void_p-$have_ilckd" in
771
ethr_have_native_atomics=no
772
ethr_have_native_spinlock=no;;
774
ethr_have_native_atomics=yes
775
ethr_have_native_spinlock=yes;;
779
AC_MSG_CHECKING([for _InterlockedDecrement64()])
781
#define WIN32_LEAN_AND_MEAN
785
volatile __int64 *var;
786
_InterlockedDecrement64(var);
790
AC_MSG_RESULT([$have_ilckd])
791
test $have_ilckd = yes && AC_DEFINE(ETHR_HAVE__INTERLOCKEDDECREMENT64, 1, [Define if you have _InterlockedDecrement64()])
794
AC_MSG_CHECKING([for _InterlockedIncrement64()])
796
#define WIN32_LEAN_AND_MEAN
800
volatile __int64 *var;
801
_InterlockedIncrement64(var);
805
AC_MSG_RESULT([$have_ilckd])
806
test $have_ilckd = yes && AC_DEFINE(ETHR_HAVE__INTERLOCKEDINCREMENT64, 1, [Define if you have _InterlockedIncrement64()])
809
AC_MSG_CHECKING([for _InterlockedExchangeAdd64()])
811
#define WIN32_LEAN_AND_MEAN
815
volatile __int64 *var;
816
_InterlockedExchangeAdd64(var, (__int64) 1);
820
AC_MSG_RESULT([$have_ilckd])
821
test $have_ilckd = yes && AC_DEFINE(ETHR_HAVE__INTERLOCKEDEXCHANGEADD64, 1, [Define if you have _InterlockedExchangeAdd64()])
824
AC_MSG_CHECKING([for _InterlockedExchange64()])
826
#define WIN32_LEAN_AND_MEAN
830
volatile __int64 *var;
831
_InterlockedExchange64(var, (__int64) 1);
835
AC_MSG_RESULT([$have_ilckd])
836
test $have_ilckd = yes && AC_DEFINE(ETHR_HAVE__INTERLOCKEDEXCHANGE64, 1, [Define if you have _InterlockedExchange64()])
839
AC_MSG_CHECKING([for _InterlockedAnd64()])
841
#define WIN32_LEAN_AND_MEAN
845
volatile __int64 *var;
846
_InterlockedAnd64(var, (__int64) 1);
850
AC_MSG_RESULT([$have_ilckd])
851
test $have_ilckd = yes && AC_DEFINE(ETHR_HAVE__INTERLOCKEDAND64, 1, [Define if you have _InterlockedAnd64()])
854
AC_MSG_CHECKING([for _InterlockedOr64()])
856
#define WIN32_LEAN_AND_MEAN
860
volatile __int64 *var;
861
_InterlockedOr64(var, (__int64) 1);
865
AC_MSG_RESULT([$have_ilckd])
866
test $have_ilckd = yes && AC_DEFINE(ETHR_HAVE__INTERLOCKEDOR64, 1, [Define if you have _InterlockedOr64()])
871
ETHR_THR_LIB_BASE_DIR=pthread
872
AC_DEFINE(ETHR_PTHREADS, 1, [Define if you have pthreads])
875
# The default stack size is insufficient for our needs
876
# on OpenBSD. We increase it to 256 kilo words.
877
ethr_modified_default_stack_size=256;;
879
ETHR_DEFS="$ETHR_DEFS -D_GNU_SOURCE"
881
if test X$cross_compiling = Xyes; then
882
case X$erl_xcomp_linux_usable_sigusrx in
883
X) usable_sigusrx=cross;;
884
Xyes|Xno) usable_sigusrx=$erl_xcomp_linux_usable_sigusrx;;
885
*) AC_MSG_ERROR([Bad erl_xcomp_linux_usable_sigusrx value: $erl_xcomp_linux_usable_sigusrx]);;
887
case X$erl_xcomp_linux_usable_sigaltstack in
888
X) usable_sigaltstack=cross;;
889
Xyes|Xno) usable_sigaltstack=$erl_xcomp_linux_usable_sigaltstack;;
890
*) AC_MSG_ERROR([Bad erl_xcomp_linux_usable_sigaltstack value: $erl_xcomp_linux_usable_sigaltstack]);;
893
# FIXME: Test for actual problems instead of kernel versions
894
linux_kernel_vsn_=`uname -r`
895
case $linux_kernel_vsn_ in
896
[[0-1]].*|2.[[0-1]]|2.[[0-1]].*)
898
usable_sigaltstack=no;;
899
2.[[2-3]]|2.[[2-3]].*)
901
usable_sigaltstack=no;;
904
usable_sigaltstack=yes;;
908
AC_MSG_CHECKING(if SIGUSR1 and SIGUSR2 can be used)
909
AC_MSG_RESULT($usable_sigusrx)
910
if test $usable_sigusrx = cross; then
912
AC_MSG_WARN([result yes guessed because of cross compilation])
914
if test $usable_sigusrx = no; then
915
ETHR_DEFS="$ETHR_DEFS -DETHR_UNUSABLE_SIGUSRX"
918
AC_MSG_CHECKING(if sigaltstack can be used)
919
AC_MSG_RESULT($usable_sigaltstack)
920
if test $usable_sigaltstack = cross; then
921
usable_sigaltstack=yes
922
AC_MSG_WARN([result yes guessed because of cross compilation])
924
if test $usable_sigaltstack = no; then
925
ETHR_DEFS="$ETHR_DEFS -DETHR_UNUSABLE_SIGALTSTACK"
931
dnl We sometimes need ETHR_DEFS in order to find certain headers
932
dnl (at least for pthread.h on osf1).
933
saved_cppflags="$CPPFLAGS"
934
CPPFLAGS="$CPPFLAGS $ETHR_DEFS"
936
dnl We need the thread library in order to find some functions
938
LIBS="$LIBS $ETHR_X_LIBS"
941
dnl Check for headers
944
AC_CHECK_HEADER(pthread.h, \
945
AC_DEFINE(ETHR_HAVE_PTHREAD_H, 1, \
946
[Define if you have the <pthread.h> header file.]))
948
dnl Some Linuxes have <pthread/mit/pthread.h> instead of <pthread.h>
949
AC_CHECK_HEADER(pthread/mit/pthread.h, \
950
AC_DEFINE(ETHR_HAVE_MIT_PTHREAD_H, 1, \
951
[Define if the pthread.h header file is in pthread/mit directory.]))
953
if test $NEED_NPTL_PTHREAD_H = yes; then
954
AC_DEFINE(ETHR_NEED_NPTL_PTHREAD_H, 1, \
955
[Define if you need the <nptl/pthread.h> header file.])
958
AC_CHECK_HEADER(sched.h, \
959
AC_DEFINE(ETHR_HAVE_SCHED_H, 1, \
960
[Define if you have the <sched.h> header file.]))
962
AC_CHECK_HEADER(sys/time.h, \
963
AC_DEFINE(ETHR_HAVE_SYS_TIME_H, 1, \
964
[Define if you have the <sys/time.h> header file.]))
966
AC_TRY_COMPILE([#include <time.h>
967
#include <sys/time.h>],
968
[struct timeval *tv; return 0;],
969
AC_DEFINE(ETHR_TIME_WITH_SYS_TIME, 1, \
970
[Define if you can safely include both <sys/time.h> and <time.h>.]))
974
dnl Check for functions
977
AC_CHECK_FUNC(pthread_spin_lock, \
978
[ethr_have_native_spinlock=yes \
979
AC_DEFINE(ETHR_HAVE_PTHREAD_SPIN_LOCK, 1, \
980
[Define if you have the pthread_spin_lock function.])])
983
have_librt_sched_yield=no
984
AC_CHECK_FUNC(sched_yield, [have_sched_yield=yes])
985
if test $have_sched_yield = no; then
986
AC_CHECK_LIB(rt, sched_yield,
987
[have_librt_sched_yield=yes
988
ETHR_X_LIBS="$ETHR_X_LIBS -lrt"])
990
if test $have_sched_yield = yes || test $have_librt_sched_yield = yes; then
991
AC_DEFINE(ETHR_HAVE_SCHED_YIELD, 1, [Define if you have the sched_yield() function.])
992
AC_MSG_CHECKING([whether sched_yield() returns an int])
993
sched_yield_ret_int=no
995
#ifdef ETHR_HAVE_SCHED_H
999
[int sched_yield();],
1000
[sched_yield_ret_int=yes])
1001
AC_MSG_RESULT([$sched_yield_ret_int])
1002
if test $sched_yield_ret_int = yes; then
1003
AC_DEFINE(ETHR_SCHED_YIELD_RET_INT, 1, [Define if sched_yield() returns an int.])
1007
have_pthread_yield=no
1008
AC_CHECK_FUNC(pthread_yield, [have_pthread_yield=yes])
1009
if test $have_pthread_yield = yes; then
1010
AC_DEFINE(ETHR_HAVE_PTHREAD_YIELD, 1, [Define if you have the pthread_yield() function.])
1011
AC_MSG_CHECKING([whether pthread_yield() returns an int])
1012
pthread_yield_ret_int=no
1014
#if defined(ETHR_NEED_NPTL_PTHREAD_H)
1015
#include <nptl/pthread.h>
1016
#elif defined(ETHR_HAVE_MIT_PTHREAD_H)
1017
#include <pthread/mit/pthread.h>
1018
#elif defined(ETHR_HAVE_PTHREAD_H)
1019
#include <pthread.h>
1022
[int pthread_yield();],
1023
[pthread_yield_ret_int=yes])
1024
AC_MSG_RESULT([$pthread_yield_ret_int])
1025
if test $pthread_yield_ret_int = yes; then
1026
AC_DEFINE(ETHR_PTHREAD_YIELD_RET_INT, 1, [Define if pthread_yield() returns an int.])
1030
have_pthread_rwlock_init=no
1031
AC_CHECK_FUNC(pthread_rwlock_init, [have_pthread_rwlock_init=yes])
1032
if test $have_pthread_rwlock_init = yes; then
1034
ethr_have_pthread_rwlockattr_setkind_np=no
1035
AC_CHECK_FUNC(pthread_rwlockattr_setkind_np,
1036
[ethr_have_pthread_rwlockattr_setkind_np=yes])
1038
if test $ethr_have_pthread_rwlockattr_setkind_np = yes; then
1039
AC_DEFINE(ETHR_HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP, 1, \
1040
[Define if you have the pthread_rwlockattr_setkind_np() function.])
1042
AC_MSG_CHECKING([for PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP])
1043
ethr_pthread_rwlock_writer_nonrecursive_initializer_np=no
1045
#if defined(ETHR_NEED_NPTL_PTHREAD_H)
1046
#include <nptl/pthread.h>
1047
#elif defined(ETHR_HAVE_MIT_PTHREAD_H)
1048
#include <pthread/mit/pthread.h>
1049
#elif defined(ETHR_HAVE_PTHREAD_H)
1050
#include <pthread.h>
1054
pthread_rwlockattr_t *attr;
1055
return pthread_rwlockattr_setkind_np(attr,
1056
PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
1058
[ethr_pthread_rwlock_writer_nonrecursive_initializer_np=yes])
1059
AC_MSG_RESULT([$ethr_pthread_rwlock_writer_nonrecursive_initializer_np])
1060
if test $ethr_pthread_rwlock_writer_nonrecursive_initializer_np = yes; then
1061
AC_DEFINE(ETHR_HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, 1, \
1062
[Define if you have the PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP rwlock attribute.])
1067
if test "$force_pthread_rwlocks" = "yes"; then
1069
AC_DEFINE(ETHR_FORCE_PTHREAD_RWLOCK, 1, \
1070
[Define if you want to force usage of pthread rwlocks])
1072
if test $have_pthread_rwlock_init = yes; then
1073
AC_MSG_WARN([Forced usage of pthread rwlocks. Note that this implementation may suffer from starvation issues.])
1075
AC_MSG_ERROR([User forced usage of pthread rwlock, but no such implementation was found])
1079
AC_CHECK_FUNC(pthread_attr_setguardsize, \
1080
AC_DEFINE(ETHR_HAVE_PTHREAD_ATTR_SETGUARDSIZE, 1, \
1081
[Define if you have the pthread_attr_setguardsize function.]))
1084
AC_MSG_CHECKING([for Linux futexes])
1086
#include <sys/syscall.h>
1088
#include <linux/futex.h>
1089
#include <sys/time.h>
1093
syscall(__NR_futex, (void *) &i, FUTEX_WAKE, 1,
1094
(void*)0,(void*)0, 0);
1095
syscall(__NR_futex, (void *) &i, FUTEX_WAIT, 0,
1096
(void*)0,(void*)0, 0);
1100
AC_MSG_RESULT([$linux_futex])
1101
test $linux_futex = yes && AC_DEFINE(ETHR_HAVE_LINUX_FUTEX, 1, [Define if you have a linux futex implementation.])
1103
AC_MSG_CHECKING([for GCC atomic operations])
1104
ethr_have_gcc_atomic_ops=no
1109
res = __sync_val_compare_and_swap(&val, (long) 1, (long) 0);
1110
res = __sync_add_and_fetch(&val, (long) 1);
1111
res = __sync_sub_and_fetch(&val, (long) 1);
1112
res = __sync_fetch_and_and(&val, (long) 1);
1113
res = __sync_fetch_and_or(&val, (long) 1);
1115
[ethr_have_native_atomics=yes
1116
ethr_have_gcc_atomic_ops=yes])
1117
AC_MSG_RESULT([$ethr_have_gcc_atomic_ops])
1118
test $ethr_have_gcc_atomic_ops = yes && AC_DEFINE(ETHR_HAVE_GCC_ATOMIC_OPS, 1, [Define if you have gcc atomic operations])
1121
sun4u | sparc64 | sun4v)
1122
ethr_have_native_atomics=yes;;
1123
i86pc | i*86 | x86_64 | amd64)
1124
ethr_have_native_atomics=yes;;
1125
macppc | ppc | "Power Macintosh")
1126
ethr_have_native_atomics=yes;;
1128
ethr_have_native_atomics=yes;;
1133
AC_MSG_CHECKING([for a usable libatomic_ops implementation])
1134
case "x$with_libatomic_ops" in
1136
libatomic_ops_include=
1139
if test -d "${with_libatomic_ops}/include"; then
1140
libatomic_ops_include="-I$with_libatomic_ops/include"
1141
CPPFLAGS="$CPPFLAGS $libatomic_ops_include"
1143
AC_MSG_ERROR([libatomic_ops include directory $with_libatomic_ops/include not found])
1146
ethr_have_libatomic_ops=no
1147
AC_TRY_LINK([#include "atomic_ops.h"],
1154
AO_store(&x, (AO_t) 0);
1156
z = AO_compare_and_swap(&x, (AO_t) 0, (AO_t) 1);
1158
[ethr_have_native_atomics=yes
1159
ethr_have_libatomic_ops=yes])
1160
AC_MSG_RESULT([$ethr_have_libatomic_ops])
1161
if test $ethr_have_libatomic_ops = yes; then
1162
AC_CHECK_SIZEOF(AO_t, ,
1165
#include "atomic_ops.h"
1167
AC_DEFINE_UNQUOTED(ETHR_SIZEOF_AO_T, $ac_cv_sizeof_AO_t, [Define to the size of AO_t if libatomic_ops is used])
1169
AC_DEFINE(ETHR_HAVE_LIBATOMIC_OPS, 1, [Define if you have libatomic_ops atomic operations])
1170
if test "x$with_libatomic_ops" != "xno" && test "x$with_libatomic_ops" != "x"; then
1171
AC_DEFINE(ETHR_PREFER_LIBATOMIC_OPS_NATIVE_IMPLS, 1, [Define if you prefer libatomic_ops native ethread implementations])
1173
ETHR_DEFS="$ETHR_DEFS $libatomic_ops_include"
1174
elif test "x$with_libatomic_ops" != "xno" && test "x$with_libatomic_ops" != "x"; then
1175
AC_MSG_ERROR([No usable libatomic_ops implementation found])
1180
dnl restore CPPFLAGS
1181
CPPFLAGS=$saved_cppflags
1188
AC_MSG_CHECKING([whether default stack size should be modified])
1189
if test "x$ethr_modified_default_stack_size" != "x"; then
1190
AC_DEFINE_UNQUOTED(ETHR_MODIFIED_DEFAULT_STACK_SIZE, $ethr_modified_default_stack_size, [Define if you want to modify the default stack size])
1191
AC_MSG_RESULT([yes; to $ethr_modified_default_stack_size kilo words])
1196
if test "x$ETHR_THR_LIB_BASE" != "x"; then
1197
ETHR_DEFS="-DUSE_THREADS $ETHR_DEFS"
1198
ETHR_LIBS="-l$ethr_lib_name -lerts_internal_r $ETHR_X_LIBS"
1199
ETHR_LIB_NAME=$ethr_lib_name
1202
AC_CHECK_SIZEOF(void *)
1203
AC_DEFINE_UNQUOTED(ETHR_SIZEOF_PTR, $ac_cv_sizeof_void_p, [Define to the size of pointers])
1205
AC_CHECK_SIZEOF(int)
1206
AC_DEFINE_UNQUOTED(ETHR_SIZEOF_INT, $ac_cv_sizeof_int, [Define to the size of int])
1207
AC_CHECK_SIZEOF(long)
1208
AC_DEFINE_UNQUOTED(ETHR_SIZEOF_LONG, $ac_cv_sizeof_long, [Define to the size of long])
1209
AC_CHECK_SIZEOF(long long)
1210
AC_DEFINE_UNQUOTED(ETHR_SIZEOF_LONG_LONG, $ac_cv_sizeof_long_long, [Define to the size of long long])
1211
AC_CHECK_SIZEOF(__int64)
1212
AC_DEFINE_UNQUOTED(ETHR_SIZEOF___INT64, $ac_cv_sizeof___int64, [Define to the size of __int64])
1215
case X$erl_xcomp_bigendian in
1217
Xyes|Xno) ac_cv_c_bigendian=$erl_xcomp_bigendian;;
1218
*) AC_MSG_ERROR([Bad erl_xcomp_bigendian value: $erl_xcomp_bigendian]);;
1223
if test "$ac_cv_c_bigendian" = "yes"; then
1224
AC_DEFINE(ETHR_BIGENDIAN, 1, [Define if bigendian])
1227
AC_ARG_ENABLE(native-ethr-impls,
1228
AS_HELP_STRING([--disable-native-ethr-impls],
1229
[disable native ethread implementations]),
1230
[ case "$enableval" in
1231
no) disable_native_ethr_impls=yes ;;
1232
*) disable_native_ethr_impls=no ;;
1233
esac ], disable_native_ethr_impls=no)
1235
test "X$disable_native_ethr_impls" = "Xyes" &&
1236
AC_DEFINE(ETHR_DISABLE_NATIVE_IMPLS, 1, [Define if you want to disable native ethread implementations])
1238
AC_ARG_ENABLE(prefer-gcc-native-ethr-impls,
1239
AS_HELP_STRING([--enable-prefer-gcc-native-ethr-impls],
1240
[prefer gcc native ethread implementations]),
1241
[ case "$enableval" in
1242
yes) enable_prefer_gcc_native_ethr_impls=yes ;;
1243
*) enable_prefer_gcc_native_ethr_impls=no ;;
1244
esac ], enable_prefer_gcc_native_ethr_impls=no)
1246
test $enable_prefer_gcc_native_ethr_impls = yes &&
1247
AC_DEFINE(ETHR_PREFER_GCC_NATIVE_IMPLS, 1, [Define if you prefer gcc native ethread implementations])
1249
AC_ARG_WITH(libatomic_ops,
1250
AS_HELP_STRING([--with-libatomic_ops=PATH],
1251
[specify and prefer usage of libatomic_ops in the ethread library]))
1253
AC_ARG_ENABLE(ethread-pre-pentium4-compatibility,
1254
AS_HELP_STRING([--enable-ethread-pre-pentium4-compatibility],
1255
[enable compatibility with x86 processors before pentium 4 (back to 486) in the ethread library]),
1257
case "$enable_ethread_pre_pentium4_compatibility" in
1259
*) enable_ethread_pre_pentium4_compatibility=check;;
1262
[enable_ethread_pre_pentium4_compatibility=check])
1264
test "$cross_compiling" != "yes" || enable_ethread_pre_pentium4_compatibility=no
1266
case "$enable_ethread_pre_pentium4_compatibility-$host_cpu" in
1267
check-i86pc | check-i*86)
1268
AC_MSG_CHECKING([whether pre pentium 4 compatibility should forced])
1270
#if defined(__GNUC__)
1271
# if defined(ETHR_PREFER_LIBATOMIC_OPS_NATIVE_IMPLS)
1272
# define CHECK_LIBATOMIC_OPS__
1274
# define CHECK_GCC_ASM__
1276
#elif defined(ETHR_HAVE_LIBATOMIC_OPS)
1277
# define CHECK_LIBATOMIC_OPS__
1279
#if defined(CHECK_LIBATOMIC_OPS__)
1280
#include "atomic_ops.h"
1284
#if defined(CHECK_GCC_ASM__)
1285
__asm__ __volatile__("mfence" : : : "memory");
1286
#elif defined(CHECK_LIBATOMIC_OPS__)
1292
[enable_ethread_pre_pentium4_compatibility=no],
1293
[enable_ethread_pre_pentium4_compatibility=yes],
1294
[enable_ethread_pre_pentium4_compatibility=no])
1295
AC_MSG_RESULT([$enable_ethread_pre_pentium4_compatibility]);;
1300
test $enable_ethread_pre_pentium4_compatibility = yes &&
1301
AC_DEFINE(ETHR_PRE_PENTIUM4_COMPAT, 1, [Define if you want compatibilty with x86 processors before pentium4.])
1303
AC_DEFINE(ETHR_HAVE_ETHREAD_DEFINES, 1, \
1304
[Define if you have all ethread defines])
1306
AC_SUBST(ETHR_X_LIBS)
1308
AC_SUBST(ETHR_LIB_NAME)
1310
AC_SUBST(ETHR_THR_LIB_BASE)
1311
AC_SUBST(ETHR_THR_LIB_BASE_DIR)
1317
dnl ----------------------------------------------------------------------
1319
dnl ERL_TIME_CORRECTION
1321
dnl In the presence of a high resolution realtime timer Erlang can adapt
1322
dnl its view of time relative to this timer. On solaris such a timer is
1323
dnl available with the syscall gethrtime(). On other OS's a fallback
1324
dnl solution using times() is implemented. (However on e.g. FreeBSD times()
1325
dnl is implemented using gettimeofday so it doesn't make much sense to
1326
dnl use it there...) On second thought, it seems to be safer to do it the
1327
dnl other way around. I.e. only use times() on OS's where we know it will
1331
AC_DEFUN(ERL_TIME_CORRECTION,
1332
[if test x$ac_cv_func_gethrtime = x; then
1333
AC_CHECK_FUNC(gethrtime)
1335
if test x$clock_gettime_correction = xunknown; then
1336
AC_TRY_COMPILE([#include <time.h>],
1337
[struct timespec ts;
1339
clock_gettime(CLOCK_MONOTONIC,&ts);
1340
result = ((long long) ts.tv_sec) * 1000000000LL +
1341
((long long) ts.tv_nsec);],
1342
clock_gettime_compiles=yes,
1343
clock_gettime_compiles=no)
1345
clock_gettime_compiles=no
1349
AC_CACHE_CHECK([how to correct for time adjustments], erl_cv_time_correction,
1351
case $clock_gettime_correction in
1353
erl_cv_time_correction=clock_gettime;;
1355
case $ac_cv_func_gethrtime in
1357
erl_cv_time_correction=hrtime ;;
1361
case $clock_gettime_correction in
1363
if test x$clock_gettime_compiles = xyes; then
1364
if test X$cross_compiling != Xyes; then
1365
linux_kernel_vsn_=`uname -r`
1366
case $linux_kernel_vsn_ in
1367
[[0-1]].*|2.[[0-5]]|2.[[0-5]].*)
1368
erl_cv_time_correction=times ;;
1370
erl_cv_time_correction=clock_gettime;;
1373
case X$erl_xcomp_linux_clock_gettime_correction in
1375
erl_cv_time_correction=cross;;
1377
if test $erl_xcomp_linux_clock_gettime_correction = yes; then
1378
erl_cv_time_correction=clock_gettime
1380
erl_cv_time_correction=times
1383
AC_MSG_ERROR([Bad erl_xcomp_linux_clock_gettime_correction value: $erl_xcomp_linux_clock_gettime_correction]);;
1387
erl_cv_time_correction=times
1391
erl_cv_time_correction=times ;;
1395
erl_cv_time_correction=none ;;
1404
case $erl_cv_time_correction in
1406
AC_DEFINE(CORRECT_USING_TIMES,[],
1407
[Define if you do not have a high-res. timer & want to use times() instead])
1409
clock_gettime|cross)
1410
if test $erl_cv_time_correction = cross; then
1411
erl_cv_time_correction=clock_gettime
1412
AC_MSG_WARN([result clock_gettime guessed because of cross compilation])
1415
AC_DEFINE(GETHRTIME_WITH_CLOCK_GETTIME,[1],
1416
[Define if you want to use clock_gettime to simulate gethrtime])
1420
dnl Check if gethrvtime is working, and if to use procfs ioctl
1421
dnl or (yet to be written) write to the procfs ctl file.
1424
AC_MSG_CHECKING([if gethrvtime works and how to use it])
1426
/* gethrvtime procfs ioctl test */
1427
/* These need to be undef:ed to not break activation of
1428
* micro level process accounting on /proc/self
1430
#ifdef _LARGEFILE_SOURCE
1431
# undef _LARGEFILE_SOURCE
1433
#ifdef _FILE_OFFSET_BITS
1434
# undef _FILE_OFFSET_BITS
1440
#include <sys/time.h>
1441
#include <sys/types.h>
1442
#include <sys/stat.h>
1443
#include <sys/signal.h>
1444
#include <sys/fault.h>
1445
#include <sys/syscall.h>
1446
#include <sys/procfs.h>
1450
long msacct = PR_MSACCT;
1452
long long start, stop;
1454
pid_t pid = getpid();
1455
char proc_self[30] = "/proc/";
1457
sprintf(proc_self+strlen(proc_self), "%lu", (unsigned long) pid);
1458
if ( (fd = open(proc_self, O_WRONLY)) == -1)
1460
if (ioctl(fd, PIOCSET, &msacct) < 0)
1464
start = gethrvtime();
1465
for (i = 0; i < 100; i++)
1466
stop = gethrvtime();
1474
erl_gethrvtime=procfs_ioctl,
1475
erl_gethrvtime=false,
1477
case X$erl_xcomp_gethrvtime_procfs_ioctl in
1479
erl_gethrvtime=cross;;
1481
if test $erl_xcomp_gethrvtime_procfs_ioctl = yes; then
1482
erl_gethrvtime=procfs_ioctl
1484
erl_gethrvtime=false
1487
AC_MSG_ERROR([Bad erl_xcomp_gethrvtime_procfs_ioctl value: $erl_xcomp_gethrvtime_procfs_ioctl]);;
1491
case $erl_gethrvtime in
1493
AC_DEFINE(HAVE_GETHRVTIME_PROCFS_IOCTL,[1],
1494
[define if gethrvtime() works and uses ioctl() to /proc/self])
1495
AC_MSG_RESULT(uses ioctl to procfs)
1498
if test $erl_gethrvtime = cross; then
1499
erl_gethrvtime=false
1500
AC_MSG_RESULT(cross)
1501
AC_MSG_WARN([result 'not working' guessed because of cross compilation])
1503
AC_MSG_RESULT(not working)
1507
dnl Check if clock_gettime (linux) is working
1510
AC_MSG_CHECKING([if clock_gettime can be used to get process CPU time])
1520
long long start, stop;
1524
if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp) < 0)
1526
start = ((long long)tp.tv_sec * 1000000000LL) + (long long)tp.tv_nsec;
1527
for (i = 0; i < 100; i++)
1528
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp);
1529
stop = ((long long)tp.tv_sec * 1000000000LL) + (long long)tp.tv_nsec;
1537
erl_clock_gettime=yes,
1538
erl_clock_gettime=no,
1540
case X$erl_xcomp_clock_gettime_cpu_time in
1541
X) erl_clock_gettime=cross;;
1542
Xyes|Xno) erl_clock_gettime=$erl_xcomp_clock_gettime_cpu_time;;
1543
*) AC_MSG_ERROR([Bad erl_xcomp_clock_gettime_cpu_time value: $erl_xcomp_clock_gettime_cpu_time]);;
1549
AC_MSG_RESULT([no; not stable])
1553
AC_MSG_RESULT($erl_clock_gettime)
1554
case $erl_clock_gettime in
1556
AC_DEFINE(HAVE_CLOCK_GETTIME,[],
1557
[define if clock_gettime() works for getting process time])
1561
erl_clock_gettime=no
1562
AC_MSG_WARN([result no guessed because of cross compilation])
1576
dnl ERL_TRY_LINK_JAVA(CLASSES, FUNCTION-BODY
1577
dnl [ACTION_IF_FOUND [, ACTION-IF-NOT-FOUND]])
1578
dnl Freely inspired by AC_TRY_LINK. (Maybe better to create a
1579
dnl AC_LANG_JAVA instead...)
1580
AC_DEFUN(ERL_TRY_LINK_JAVA,
1581
[java_link='$JAVAC conftest.java 1>&AC_FD_CC'
1582
changequote(�, �)dnl
1583
cat > conftest.java <<EOF
1585
class conftest { public static void main(String[] args) {
1589
changequote([, ])dnl
1590
if AC_TRY_EVAL(java_link) && test -s conftest.class; then
1591
ifelse([$3], , :, [rm -rf conftest*
1594
echo "configure: failed program was:" 1>&AC_FD_CC
1595
cat conftest.java 1>&AC_FD_CC
1596
echo "configure: PATH was $PATH" 1>&AC_FD_CC
1597
ifelse([$4], , , [ rm -rf conftest*
1602
#define UNSAFE_MASK 0xc0000000 /* Mask for bits that must be constant */