"Fossies" - the Fresh Open Source Software Archive

Member "otp_src_22.1/lib/crypto/aclocal.m4" (17 Sep 2019, 99277 Bytes) of package /linux/misc/otp_src_22.1.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 dnl
    2 dnl %CopyrightBegin%
    3 dnl
    4 dnl Copyright Ericsson AB 1998-2018. All Rights Reserved.
    5 dnl
    6 dnl Licensed under the Apache License, Version 2.0 (the "License");
    7 dnl you may not use this file except in compliance with the License.
    8 dnl You may obtain a copy of the License at
    9 dnl
   10 dnl     http://www.apache.org/licenses/LICENSE-2.0
   11 dnl
   12 dnl Unless required by applicable law or agreed to in writing, software
   13 dnl distributed under the License is distributed on an "AS IS" BASIS,
   14 dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   15 dnl See the License for the specific language governing permissions and
   16 dnl limitations under the License.
   17 dnl
   18 dnl %CopyrightEnd%
   19 dnl
   20 
   21 dnl
   22 dnl aclocal.m4
   23 dnl
   24 dnl Local macros used in configure.in. The Local Macros which
   25 dnl could/should be part of autoconf are prefixed LM_, macros specific
   26 dnl to the Erlang system are prefixed ERL_.
   27 dnl
   28 
   29 AC_DEFUN(LM_PRECIOUS_VARS,
   30 [
   31 
   32 dnl ERL_TOP
   33 AC_ARG_VAR(ERL_TOP, [Erlang/OTP top source directory])
   34 
   35 dnl Tools
   36 AC_ARG_VAR(CC, [C compiler])
   37 AC_ARG_VAR(CFLAGS, [C compiler flags])
   38 AC_ARG_VAR(STATIC_CFLAGS, [C compiler static flags])
   39 AC_ARG_VAR(CFLAG_RUNTIME_LIBRARY_PATH, [runtime library path linker flag passed via C compiler])
   40 AC_ARG_VAR(CPP, [C/C++ preprocessor])
   41 AC_ARG_VAR(CPPFLAGS, [C/C++ preprocessor flags])
   42 AC_ARG_VAR(CXX, [C++ compiler])
   43 AC_ARG_VAR(CXXFLAGS, [C++ compiler flags])
   44 AC_ARG_VAR(LD, [linker (is often overridden by configure)])
   45 AC_ARG_VAR(LDFLAGS, [linker flags (can be risky to set since LD may be overriden by configure)])
   46 AC_ARG_VAR(LIBS, [libraries])
   47 AC_ARG_VAR(DED_LD, [linker for Dynamic Erlang Drivers (set all DED_LD* variables or none)])
   48 AC_ARG_VAR(DED_LDFLAGS, [linker flags for Dynamic Erlang Drivers (set all DED_LD* variables or none)])
   49 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)])
   50 AC_ARG_VAR(LFS_CFLAGS, [large file support C compiler flags (set all LFS_* variables or none)])
   51 AC_ARG_VAR(LFS_LDFLAGS, [large file support linker flags (set all LFS_* variables or none)])
   52 AC_ARG_VAR(LFS_LIBS, [large file support libraries (set all LFS_* variables or none)])
   53 AC_ARG_VAR(RANLIB, [ranlib])
   54 AC_ARG_VAR(AR, [ar])
   55 AC_ARG_VAR(GETCONF, [getconf])
   56 
   57 dnl Cross system root
   58 AC_ARG_VAR(erl_xcomp_sysroot, [Absolute cross system root path (only used when cross compiling)])
   59 AC_ARG_VAR(erl_xcomp_isysroot, [Absolute cross system root include path (only used when cross compiling)])
   60 
   61 dnl Cross compilation variables
   62 AC_ARG_VAR(erl_xcomp_bigendian, [big endian system: yes|no (only used when cross compiling)])
   63 AC_ARG_VAR(erl_xcomp_double_middle_endian, [double-middle-endian system: yes|no (only used when cross compiling)])
   64 AC_ARG_VAR(erl_xcomp_linux_nptl, [have Native POSIX Thread Library: yes|no (only used when cross compiling)])
   65 AC_ARG_VAR(erl_xcomp_linux_usable_sigusrx, [SIGUSR1 and SIGUSR2 can be used: yes|no (only used when cross compiling)])
   66 AC_ARG_VAR(erl_xcomp_linux_usable_sigaltstack, [have working sigaltstack(): yes|no (only used when cross compiling)])
   67 AC_ARG_VAR(erl_xcomp_poll, [have working poll(): yes|no (only used when cross compiling)])
   68 AC_ARG_VAR(erl_xcomp_kqueue, [have working kqueue(): yes|no (only used when cross compiling)])
   69 AC_ARG_VAR(erl_xcomp_putenv_copy, [putenv() stores key-value copy: yes|no (only used when cross compiling)])
   70 AC_ARG_VAR(erl_xcomp_reliable_fpe, [have reliable floating point exceptions: yes|no (only used when cross compiling)])
   71 AC_ARG_VAR(erl_xcomp_getaddrinfo, [have working getaddrinfo() for both IPv4 and IPv6: yes|no (only used when cross compiling)])
   72 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)])
   73 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)])
   74 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)])
   75 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)])
   76 
   77 ])
   78 
   79 AC_DEFUN(ERL_XCOMP_SYSROOT_INIT,
   80 [
   81 erl_xcomp_without_sysroot=no
   82 if test "$cross_compiling" = "yes"; then
   83     test "$erl_xcomp_sysroot" != "" || erl_xcomp_without_sysroot=yes
   84     test "$erl_xcomp_isysroot" != "" || erl_xcomp_isysroot="$erl_xcomp_sysroot"
   85 else
   86     erl_xcomp_sysroot=
   87     erl_xcomp_isysroot=
   88 fi
   89 ])
   90 
   91 AC_DEFUN(LM_CHECK_GETCONF,
   92 [
   93 if test "$cross_compiling" != "yes"; then
   94     AC_CHECK_PROG([GETCONF], [getconf], [getconf], [false])
   95 else
   96     dnl First check if we got a `<HOST>-getconf' in $PATH
   97     host_getconf="$host_alias-getconf"
   98     AC_CHECK_PROG([GETCONF], [$host_getconf], [$host_getconf], [false])
   99     if test "$GETCONF" = "false" && test "$erl_xcomp_sysroot" != ""; then
  100 	dnl We should perhaps give up if we have'nt found it by now, but at
  101 	dnl least in one Tilera MDE `getconf' under sysroot is a bourne
  102 	dnl shell script which we can use. We try to find `<HOST>-getconf'
  103     	dnl or `getconf' under sysconf, but only under sysconf since
  104 	dnl `getconf' in $PATH is almost guaranteed to be for the build
  105 	dnl machine.
  106 	GETCONF=
  107 	prfx="$erl_xcomp_sysroot"
  108         AC_PATH_TOOL([GETCONF], [getconf], [false],
  109 	             ["$prfx/usr/bin:$prfx/bin:$prfx/usr/local/bin"])
  110     fi
  111 fi
  112 ])
  113 
  114 dnl ----------------------------------------------------------------------
  115 dnl
  116 dnl LM_WINDOWS_ENVIRONMENT
  117 dnl
  118 dnl
  119 dnl Tries to determine thw windows build environment, i.e. 
  120 dnl MIXED_CYGWIN_VC or MIXED_MSYS_VC 
  121 dnl
  122 
  123 AC_DEFUN(LM_WINDOWS_ENVIRONMENT,
  124 [
  125 
  126 if test "X$windows_environment_" != "Xchecked"; then
  127 windows_environment_=checked
  128 MIXED_CYGWIN=no
  129 MIXED_MSYS=no
  130 
  131 AC_MSG_CHECKING(for mixed cygwin or msys and native VC++ environment)
  132 if test "X$host" = "Xwin32" -a "x$GCC" != "xyes"; then
  133 	if test -x /usr/bin/msys-?.0.dll; then
  134 	        CFLAGS="$CFLAGS -O2"
  135 		MIXED_MSYS=yes
  136 		AC_MSG_RESULT([MSYS and VC])
  137 		MIXED_MSYS_VC=yes
  138 		CPPFLAGS="$CPPFLAGS -DERTS_MIXED_MSYS_VC"
  139 	elif test -x /usr/bin/cygpath; then
  140 		CFLAGS="$CFLAGS -O2"
  141 		MIXED_CYGWIN=yes
  142 		AC_MSG_RESULT([Cygwin and VC])
  143 		MIXED_CYGWIN_VC=yes
  144 		CPPFLAGS="$CPPFLAGS -DERTS_MIXED_CYGWIN_VC"
  145 	else		    
  146 		AC_MSG_RESULT([undeterminable])
  147 		AC_MSG_ERROR(Seems to be mixed windows but not with cygwin, cannot handle this!)
  148 	fi
  149 else
  150 	AC_MSG_RESULT([no])
  151 	MIXED_CYGWIN_VC=no
  152 	MIXED_MSYS_VC=no
  153 fi
  154 AC_SUBST(MIXED_CYGWIN_VC)
  155 AC_SUBST(MIXED_MSYS_VC)
  156 
  157 MIXED_VC=no
  158 if test "x$MIXED_MSYS_VC" = "xyes" -o  "x$MIXED_CYGWIN_VC" = "xyes" ; then
  159    MIXED_VC=yes
  160 fi
  161 
  162 AC_SUBST(MIXED_VC)
  163 
  164 if test "x$MIXED_MSYS" != "xyes"; then
  165    AC_MSG_CHECKING(for mixed cygwin and native MinGW environment)
  166    if test "X$host" = "Xwin32" -a "x$GCC" = x"yes"; then
  167 	if test -x /usr/bin/cygpath; then
  168 		CFLAGS="$CFLAGS -O2"
  169 		MIXED_CYGWIN=yes
  170 		AC_MSG_RESULT([yes])
  171 		MIXED_CYGWIN_MINGW=yes
  172 		CPPFLAGS="$CPPFLAGS -DERTS_MIXED_CYGWIN_MINGW"
  173 	else
  174 		AC_MSG_RESULT([undeterminable])
  175 		AC_MSG_ERROR(Seems to be mixed windows but not with cygwin, cannot handle this!)
  176 	fi
  177     else
  178 	AC_MSG_RESULT([no])
  179 	MIXED_CYGWIN_MINGW=no
  180     fi
  181 else
  182 	MIXED_CYGWIN_MINGW=no
  183 fi	
  184 AC_SUBST(MIXED_CYGWIN_MINGW)
  185 
  186 AC_MSG_CHECKING(if we mix cygwin with any native compiler)
  187 if test "X$MIXED_CYGWIN" = "Xyes"; then
  188 	AC_MSG_RESULT([yes])	
  189 else
  190 	AC_MSG_RESULT([no])
  191 fi
  192 
  193 AC_SUBST(MIXED_CYGWIN)
  194 	
  195 AC_MSG_CHECKING(if we mix msys with another native compiler)
  196 if test "X$MIXED_MSYS" = "Xyes" ; then
  197 	AC_MSG_RESULT([yes])	
  198 else
  199 	AC_MSG_RESULT([no])
  200 fi
  201 
  202 AC_SUBST(MIXED_MSYS)
  203 
  204 fi
  205 ])		
  206 	
  207 dnl ----------------------------------------------------------------------
  208 dnl
  209 dnl LM_FIND_EMU_CC
  210 dnl
  211 dnl
  212 dnl Tries fairly hard to find a C compiler that can handle jump tables.
  213 dnl Defines the @EMU_CC@ variable for the makefiles and 
  214 dnl inserts NO_JUMP_TABLE in the header if one cannot be found...
  215 dnl
  216 
  217 AC_DEFUN(LM_FIND_EMU_CC,
  218 	[AC_CACHE_CHECK(for a compiler that handles jumptables,
  219 			ac_cv_prog_emu_cc,
  220 			[
  221 AC_TRY_COMPILE([],[
  222 #if defined(__clang_major__) && __clang_major__ >= 3
  223     /* clang 3.x or later is fine */
  224 #elif defined(__llvm__)
  225 #error "this version of llvm is unable to correctly compile beam_emu.c"
  226 #endif
  227     __label__ lbl1;
  228     __label__ lbl2;
  229     int x = magic();
  230     static void *jtab[2];
  231 
  232     jtab[0] = &&lbl1;
  233     jtab[1] = &&lbl2;
  234     goto *jtab[x];
  235 lbl1:
  236     return 1;
  237 lbl2:
  238     return 2;
  239 ],ac_cv_prog_emu_cc="$CC",ac_cv_prog_emu_cc=no)
  240 
  241 if test "$ac_cv_prog_emu_cc" = no; then
  242 	for ac_progname in emu_cc.sh gcc-4.2 gcc; do
  243   		IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
  244   		ac_dummy="$PATH"
  245   		for ac_dir in $ac_dummy; do
  246     			test -z "$ac_dir" && ac_dir=.
  247     			if test -f "$ac_dir/$ac_progname"; then
  248       				ac_cv_prog_emu_cc="$ac_dir/$ac_progname"
  249       				break
  250     			fi
  251   		done
  252   		IFS="$ac_save_ifs"
  253 		if test "$ac_cv_prog_emu_cc" != no; then
  254 			break
  255 		fi
  256 	done
  257 fi
  258 
  259 if test "$ac_cv_prog_emu_cc" != no; then
  260 	save_CC="$CC"
  261 	save_CFLAGS=$CFLAGS
  262 	save_CPPFLAGS=$CPPFLAGS
  263 	CC="$ac_cv_prog_emu_cc"
  264 	CFLAGS=""
  265 	CPPFLAGS=""
  266 	AC_TRY_COMPILE([],[
  267 #if defined(__clang_major__) && __clang_major__ >= 3
  268     /* clang 3.x or later is fine */
  269 #elif defined(__llvm__)
  270 #error "this version of llvm is unable to correctly compile beam_emu.c"
  271 #endif
  272     	__label__ lbl1;
  273     	__label__ lbl2;
  274     	int x = magic();
  275     	static void *jtab[2];
  276 
  277     	jtab[0] = &&lbl1;
  278     	jtab[1] = &&lbl2;
  279     	goto *jtab[x];
  280 	lbl1:
  281     	return 1;
  282 	lbl2:
  283     	return 2;
  284 	],ac_cv_prog_emu_cc="$CC",ac_cv_prog_emu_cc=no)
  285 	CC=$save_CC
  286 	CFLAGS=$save_CFLAGS
  287 	CPPFLAGS=$save_CPPFLAGS
  288 fi
  289 ])
  290 if test "$ac_cv_prog_emu_cc" = no; then
  291 	AC_DEFINE(NO_JUMP_TABLE,[],[Defined if no found C compiler can handle jump tables])
  292 	EMU_CC="$CC"
  293 else
  294 	EMU_CC="$ac_cv_prog_emu_cc"
  295 fi
  296 AC_SUBST(EMU_CC)
  297 ])		
  298 			
  299 
  300 
  301 dnl ----------------------------------------------------------------------
  302 dnl
  303 dnl LM_PROG_INSTALL_DIR
  304 dnl
  305 dnl This macro may be used by any OTP application.
  306 dnl
  307 dnl Figure out how to create directories with parents.
  308 dnl (In my opinion INSTALL_DIR is a bad name, MKSUBDIRS or something is better)
  309 dnl
  310 dnl We prefer 'install -d', but use 'mkdir -p' if it exists.
  311 dnl If none of these methods works, we give up.
  312 dnl
  313 
  314 
  315 AC_DEFUN(LM_PROG_INSTALL_DIR,
  316 [AC_CACHE_CHECK(how to create a directory including parents,
  317 ac_cv_prog_mkdir_p,
  318 [
  319 temp_name_base=config.$$
  320 temp_name=$temp_name_base/x/y/z
  321 $INSTALL -d $temp_name >/dev/null 2>&1
  322 ac_cv_prog_mkdir_p=none
  323 if test -d $temp_name; then
  324         ac_cv_prog_mkdir_p="$INSTALL -d"
  325 else
  326         mkdir -p $temp_name >/dev/null 2>&1
  327         if test -d $temp_name; then
  328                 ac_cv_prog_mkdir_p="mkdir -p"
  329         fi
  330 fi
  331 rm -fr $temp_name_base           
  332 ])
  333 
  334 case "${ac_cv_prog_mkdir_p}" in
  335   none) AC_MSG_ERROR(don't know how create directories with parents) ;;
  336   *)    INSTALL_DIR="$ac_cv_prog_mkdir_p" AC_SUBST(INSTALL_DIR)     ;;
  337 esac
  338 ])
  339 
  340 
  341 dnl ----------------------------------------------------------------------
  342 dnl
  343 dnl LM_PROG_PERL5
  344 dnl
  345 dnl Try to find perl version 5. If found set PERL to the absolute path
  346 dnl of the program, if not found set PERL to false.
  347 dnl
  348 dnl On some systems /usr/bin/perl is perl 4 and e.g.
  349 dnl /usr/local/bin/perl is perl 5. We try to handle this case by
  350 dnl putting a couple of 
  351 dnl Tries to handle the case that there are two programs called perl
  352 dnl in the path and one of them is perl 5 and the other isn't. 
  353 dnl
  354 AC_DEFUN(LM_PROG_PERL5,
  355 [AC_PATH_PROGS(PERL, perl5 perl, false,
  356    /usr/local/bin:/opt/local/bin:/usr/local/gnu/bin:${PATH})
  357 changequote(, )dnl
  358 dnl[ That bracket is needed to balance the right bracket below
  359 if test "$PERL" = "false" || $PERL -e 'exit ($] >= 5)'; then
  360 changequote([, ])dnl
  361   ac_cv_path_PERL=false
  362   PERL=false
  363 dnl  AC_MSG_WARN(perl version 5 not found)
  364 fi
  365 ])dnl
  366 
  367 
  368 dnl ----------------------------------------------------------------------
  369 dnl
  370 dnl LM_DECL_SO_BSDCOMPAT
  371 dnl
  372 dnl Check if the system has the SO_BSDCOMPAT flag on sockets (linux) 
  373 dnl
  374 AC_DEFUN(LM_DECL_SO_BSDCOMPAT,
  375 [AC_CACHE_CHECK([for SO_BSDCOMPAT declaration], ac_cv_decl_so_bsdcompat,
  376 AC_TRY_COMPILE([#include <sys/socket.h>], [int i = SO_BSDCOMPAT;],
  377                ac_cv_decl_so_bsdcompat=yes,
  378                ac_cv_decl_so_bsdcompat=no))
  379 
  380 case "${ac_cv_decl_so_bsdcompat}" in
  381   "yes" ) AC_DEFINE(HAVE_SO_BSDCOMPAT,[],
  382 		[Define if you have SO_BSDCOMPAT flag on sockets]) ;;
  383   * ) ;;
  384 esac
  385 ])
  386 
  387 
  388 dnl ----------------------------------------------------------------------
  389 dnl
  390 dnl LM_DECL_INADDR_LOOPBACK
  391 dnl
  392 dnl Try to find declaration of INADDR_LOOPBACK, if nowhere provide a default
  393 dnl
  394 
  395 AC_DEFUN(LM_DECL_INADDR_LOOPBACK,
  396 [AC_CACHE_CHECK([for INADDR_LOOPBACK in netinet/in.h],
  397  ac_cv_decl_inaddr_loopback,
  398 [AC_TRY_COMPILE([#include <sys/types.h>
  399 #include <netinet/in.h>], [int i = INADDR_LOOPBACK;],
  400 ac_cv_decl_inaddr_loopback=yes, ac_cv_decl_inaddr_loopback=no)
  401 ])
  402 
  403 if test ${ac_cv_decl_inaddr_loopback} = no; then
  404   AC_CACHE_CHECK([for INADDR_LOOPBACK in rpc/types.h],
  405                    ac_cv_decl_inaddr_loopback_rpc,
  406                    AC_TRY_COMPILE([#include <rpc/types.h>],
  407                                    [int i = INADDR_LOOPBACK;],
  408                                    ac_cv_decl_inaddr_loopback_rpc=yes,
  409                                    ac_cv_decl_inaddr_loopback_rpc=no))
  410 
  411    case "${ac_cv_decl_inaddr_loopback_rpc}" in
  412      "yes" )
  413         AC_DEFINE(DEF_INADDR_LOOPBACK_IN_RPC_TYPES_H,[],
  414 		[Define if you need to include rpc/types.h to get INADDR_LOOPBACK defined]) ;;
  415       * )
  416   	AC_CACHE_CHECK([for INADDR_LOOPBACK in winsock2.h],
  417                    ac_cv_decl_inaddr_loopback_winsock2,
  418                    AC_TRY_COMPILE([#define WIN32_LEAN_AND_MEAN
  419 				   #include <winsock2.h>],
  420                                    [int i = INADDR_LOOPBACK;],
  421                                    ac_cv_decl_inaddr_loopback_winsock2=yes,
  422                                    ac_cv_decl_inaddr_loopback_winsock2=no))
  423 	case "${ac_cv_decl_inaddr_loopback_winsock2}" in
  424      		"yes" )
  425 			AC_DEFINE(DEF_INADDR_LOOPBACK_IN_WINSOCK2_H,[],
  426 				[Define if you need to include winsock2.h to get INADDR_LOOPBACK defined]) ;;
  427 		* )
  428 			# couldn't find it anywhere
  429         		AC_DEFINE(HAVE_NO_INADDR_LOOPBACK,[],
  430 				[Define if you don't have a definition of INADDR_LOOPBACK]) ;;
  431 	esac;;
  432    esac
  433 fi
  434 ])
  435 
  436 
  437 dnl ----------------------------------------------------------------------
  438 dnl
  439 dnl LM_STRUCT_SOCKADDR_SA_LEN
  440 dnl
  441 dnl Check if the sockaddr structure has the field sa_len
  442 dnl
  443 
  444 AC_DEFUN(LM_STRUCT_SOCKADDR_SA_LEN,
  445 [AC_CACHE_CHECK([whether struct sockaddr has sa_len field],
  446                 ac_cv_struct_sockaddr_sa_len,
  447 AC_TRY_COMPILE([#include <sys/types.h>
  448 #include <sys/socket.h>], [struct sockaddr s; s.sa_len = 10;],
  449   ac_cv_struct_sockaddr_sa_len=yes, ac_cv_struct_sockaddr_sa_len=no))
  450 
  451 dnl FIXME convbreak
  452 case ${ac_cv_struct_sockaddr_sa_len} in
  453   "no" ) AC_DEFINE(NO_SA_LEN,[1],[Define if you dont have salen]) ;;
  454   *) ;;
  455 esac
  456 ])
  457 
  458 dnl ----------------------------------------------------------------------
  459 dnl
  460 dnl LM_STRUCT_EXCEPTION
  461 dnl
  462 dnl Check to see whether the system supports the matherr function
  463 dnl and its associated type "struct exception".
  464 dnl
  465 
  466 AC_DEFUN(LM_STRUCT_EXCEPTION,
  467 [AC_CACHE_CHECK([for struct exception (and matherr function)],
  468  ac_cv_struct_exception,
  469 AC_TRY_COMPILE([#include <math.h>],
  470   [struct exception x; x.type = DOMAIN; x.type = SING;],
  471   ac_cv_struct_exception=yes, ac_cv_struct_exception=no))
  472 
  473 case "${ac_cv_struct_exception}" in
  474   "yes" ) AC_DEFINE(USE_MATHERR,[1],[Define if you have matherr() function and struct exception type]) ;;
  475   *  ) ;;
  476 esac
  477 ])
  478 
  479 
  480 dnl ----------------------------------------------------------------------
  481 dnl
  482 dnl LM_SYS_IPV6
  483 dnl
  484 dnl Check for ipv6 support and what the in6_addr structure is called.
  485 dnl (early linux used in_addr6 insted of in6_addr)
  486 dnl
  487 
  488 AC_DEFUN(LM_SYS_IPV6,
  489 [AC_MSG_CHECKING(for IP version 6 support)
  490 AC_CACHE_VAL(ac_cv_sys_ipv6_support,
  491 [ok_so_far=yes
  492  AC_TRY_COMPILE([#include <sys/types.h>
  493 #ifdef __WIN32__
  494 #include <winsock2.h>
  495 #include <ws2tcpip.h>
  496 #else
  497 #include <netinet/in.h>
  498 #endif],
  499    [struct in6_addr a6; struct sockaddr_in6 s6;], ok_so_far=yes, ok_so_far=no)
  500 
  501 if test $ok_so_far = yes; then
  502   ac_cv_sys_ipv6_support=yes
  503 else
  504   AC_TRY_COMPILE([#include <sys/types.h>
  505 #ifdef __WIN32__
  506 #include <winsock2.h>
  507 #include <ws2tcpip.h>
  508 #else
  509 #include <netinet/in.h>
  510 #endif],
  511     [struct in_addr6 a6; struct sockaddr_in6 s6;],
  512     ac_cv_sys_ipv6_support=in_addr6, ac_cv_sys_ipv6_support=no)
  513 fi
  514 ])dnl
  515 
  516 dnl
  517 dnl Have to use old style AC_DEFINE due to BC with old autoconf.
  518 dnl
  519 
  520 case ${ac_cv_sys_ipv6_support} in
  521   yes)
  522     AC_MSG_RESULT(yes)
  523     AC_DEFINE(HAVE_IN6,[1],[Define if ipv6 is present])
  524     ;;
  525   in_addr6)
  526     AC_MSG_RESULT([yes (but I am redefining in_addr6 to in6_addr)])
  527     AC_DEFINE(HAVE_IN6,[1],[Define if ipv6 is present])
  528     AC_DEFINE(HAVE_IN_ADDR6_STRUCT,[],[Early linux used in_addr6 instead of in6_addr, define if you have this])
  529     ;;
  530   *)
  531     AC_MSG_RESULT(no)
  532     ;;
  533 esac
  534 ])
  535 
  536 
  537 dnl ----------------------------------------------------------------------
  538 dnl
  539 dnl LM_SYS_MULTICAST
  540 dnl
  541 dnl Check for multicast support. Only checks for multicast options in
  542 dnl setsockopt(), no check is performed that multicasting actually works.
  543 dnl If options are found defines HAVE_MULTICAST_SUPPORT
  544 dnl
  545 
  546 AC_DEFUN(LM_SYS_MULTICAST,
  547 [AC_CACHE_CHECK([for multicast support], ac_cv_sys_multicast_support,
  548 [AC_EGREP_CPP(^yes$,
  549 [#include <sys/types.h>
  550 #include <sys/socket.h>
  551 #include <netinet/in.h>
  552 #if defined(IP_MULTICAST_TTL) && defined(IP_MULTICAST_LOOP) && defined(IP_MULTICAST_IF) && defined(IP_ADD_MEMBERSHIP) && defined(IP_DROP_MEMBERSHIP)
  553 yes
  554 #endif
  555 ], ac_cv_sys_multicast_support=yes, ac_cv_sys_multicast_support=no)])
  556 if test $ac_cv_sys_multicast_support = yes; then
  557   AC_DEFINE(HAVE_MULTICAST_SUPPORT,[1],
  558 	[Define if setsockopt() accepts multicast options])
  559 fi
  560 ])dnl
  561 
  562 
  563 dnl ----------------------------------------------------------------------
  564 dnl
  565 dnl LM_DECL_SYS_ERRLIST
  566 dnl
  567 dnl Define SYS_ERRLIST_DECLARED if the variable sys_errlist is declared
  568 dnl in a system header file, stdio.h or errno.h.
  569 dnl
  570 
  571 AC_DEFUN(LM_DECL_SYS_ERRLIST,
  572 [AC_CACHE_CHECK([for sys_errlist declaration in stdio.h or errno.h],
  573   ac_cv_decl_sys_errlist,
  574 [AC_TRY_COMPILE([#include <stdio.h>
  575 #include <errno.h>], [char *msg = *(sys_errlist + 1);],
  576   ac_cv_decl_sys_errlist=yes, ac_cv_decl_sys_errlist=no)])
  577 if test $ac_cv_decl_sys_errlist = yes; then
  578   AC_DEFINE(SYS_ERRLIST_DECLARED,[],
  579 	[define if the variable sys_errlist is declared in a system header file])
  580 fi
  581 ])
  582 
  583 
  584 dnl ----------------------------------------------------------------------
  585 dnl
  586 dnl LM_CHECK_FUNC_DECL( funname, declaration [, extra includes 
  587 dnl                     [, action-if-found [, action-if-not-found]]] )
  588 dnl
  589 dnl Checks if the declaration "declaration" of "funname" conflicts
  590 dnl with the header files idea of how the function should be
  591 dnl declared. It is useful on systems which lack prototypes and you
  592 dnl need to provide your own (e.g. when you want to take the address
  593 dnl of a function). The 4'th argument is expanded if conflicting, 
  594 dnl the 5'th argument otherwise
  595 dnl
  596 dnl
  597 
  598 AC_DEFUN(LM_CHECK_FUNC_DECL,
  599 [AC_MSG_CHECKING([for conflicting declaration of $1])
  600 AC_CACHE_VAL(ac_cv_func_decl_$1,
  601 [AC_TRY_COMPILE([#include <stdio.h>
  602 $3],[$2
  603 char *c = (char *)$1;
  604 ], eval "ac_cv_func_decl_$1=no", eval "ac_cv_func_decl_$1=yes")])
  605 if eval "test \"`echo '$ac_cv_func_decl_'$1`\" = yes"; then
  606   AC_MSG_RESULT(yes)
  607   ifelse([$4], , :, [$4])
  608 else
  609   AC_MSG_RESULT(no)
  610 ifelse([$5], , , [$5
  611 ])dnl
  612 fi
  613 ])
  614 
  615 dnl ----------------------------------------------------------------------
  616 dnl
  617 dnl AC_DOUBLE_MIDDLE_ENDIAN
  618 dnl
  619 dnl Checks whether doubles are represented in "middle-endian" format.
  620 dnl Sets ac_cv_double_middle_endian={no,yes,unknown} accordingly,
  621 dnl as well as DOUBLE_MIDDLE_ENDIAN.
  622 dnl
  623 dnl
  624 
  625 AC_DEFUN([AC_C_DOUBLE_MIDDLE_ENDIAN],
  626 [AC_CACHE_CHECK(whether double word ordering is middle-endian, ac_cv_c_double_middle_endian,
  627 [# It does not; compile a test program.
  628 AC_RUN_IFELSE(
  629 [AC_LANG_SOURCE([[#include <stdlib.h>
  630 
  631 int
  632 main(void)
  633 {
  634   int i = 0;
  635   int zero = 0;
  636   int bigendian;
  637   int zero_index = 0;
  638 
  639   union
  640   {
  641     long int l;
  642     char c[sizeof (long int)];
  643   } u;
  644 
  645   /* we'll use the one with 32-bit words */
  646   union
  647   {
  648     double d;
  649     unsigned int c[2];
  650   } vint;
  651 
  652   union
  653   {
  654     double d;
  655     unsigned long c[2];
  656   } vlong;
  657 
  658   union
  659   {
  660     double d;
  661     unsigned short c[2];
  662   } vshort;
  663 
  664 
  665   /* Are we little or big endian?  From Harbison&Steele.  */
  666   u.l = 1;
  667   bigendian = (u.c[sizeof (long int) - 1] == 1);
  668 
  669   zero_index = bigendian ? 1 : 0;
  670 
  671   vint.d = 1.0;
  672   vlong.d = 1.0;
  673   vshort.d = 1.0;
  674 
  675   if (sizeof(unsigned int) == 4)
  676     {
  677       if (vint.c[zero_index] != 0)
  678 	zero = 1;
  679     }
  680   else if (sizeof(unsigned long) == 4)
  681     {
  682       if (vlong.c[zero_index] != 0)
  683 	zero = 1;
  684     }
  685   else if (sizeof(unsigned short) == 4)
  686     {
  687       if (vshort.c[zero_index] != 0)
  688 	zero = 1;
  689     }
  690 
  691   exit (zero);
  692 }
  693 ]])],
  694 	      [ac_cv_c_double_middle_endian=no],
  695 	      [ac_cv_c_double_middle_endian=yes],
  696 	      [ac_cv_c_double_middle=unknown])])
  697 case $ac_cv_c_double_middle_endian in
  698   yes)
  699     m4_default([$1],
  700       [AC_DEFINE([DOUBLE_MIDDLE_ENDIAN], 1,
  701 	[Define to 1 if your processor stores the words in a double in
  702 	 middle-endian format (like some ARMs).])]) ;;
  703   no)
  704     $2 ;;
  705   *)
  706     m4_default([$3],
  707       [AC_MSG_WARN([unknown double endianness
  708 presetting ac_cv_c_double_middle_endian=no (or yes) will help])]) ;;
  709 esac
  710 ])# AC_C_DOUBLE_MIDDLE_ENDIAN
  711 
  712 
  713 AC_DEFUN(ERL_MONOTONIC_CLOCK,
  714 [
  715   if test "$3" = "yes"; then
  716      default_resolution_clock_gettime_monotonic="CLOCK_HIGHRES CLOCK_BOOTTIME CLOCK_MONOTONIC"
  717      low_resolution_clock_gettime_monotonic="CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC_FAST"
  718      high_resolution_clock_gettime_monotonic="CLOCK_MONOTONIC_PRECISE"
  719   else
  720      default_resolution_clock_gettime_monotonic="CLOCK_HIGHRES CLOCK_UPTIME CLOCK_MONOTONIC"
  721      low_resolution_clock_gettime_monotonic="CLOCK_MONOTONIC_COARSE CLOCK_UPTIME_FAST"
  722      high_resolution_clock_gettime_monotonic="CLOCK_UPTIME_PRECISE"
  723   fi
  724 
  725   case "$1" in
  726     high_resolution)
  727 	check_msg="high resolution "
  728 	prefer_resolution_clock_gettime_monotonic="$high_resolution_clock_gettime_monotonic"
  729 	;;
  730     low_resolution)
  731 	check_msg="low resolution "
  732 	prefer_resolution_clock_gettime_monotonic="$low_resolution_clock_gettime_monotonic"
  733 	;;
  734     custom_resolution)
  735 	check_msg="custom resolution "
  736 	prefer_resolution_clock_gettime_monotonic="$2"
  737 	;;
  738     *)
  739 	check_msg="custom "
  740 	prefer_resolution_clock_gettime_monotonic="$2"
  741 	;;
  742   esac
  743 
  744   clock_gettime_lib=""
  745   AC_CHECK_LIB(rt, clock_gettime, [clock_gettime_lib="-lrt"])
  746 
  747   save_LIBS="$LIBS"
  748   LIBS="$LIBS $clock_gettime_lib"
  749 
  750   if test "$LD_MAY_BE_WEAK" != "no"; then
  751      trust_test="#error May not be there due to weak linking"
  752   else
  753      trust_test=""
  754   fi
  755 
  756   AC_CACHE_CHECK([for clock_gettime(CLOCK_MONOTONIC_RAW, _)], erl_cv_clock_gettime_monotonic_raw,
  757   [
  758        AC_TRY_LINK([
  759 #include <time.h>
  760 $trust_test
  761 		      ],
  762 		      [
  763     struct timespec ts;
  764     long long result;
  765     clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
  766     result = ((long long) ts.tv_sec) * 1000000000LL + 
  767     ((long long) ts.tv_nsec);
  768 		      ],
  769 		      erl_cv_clock_gettime_monotonic_raw=yes,
  770 		      erl_cv_clock_gettime_monotonic_raw=no)
  771   ])
  772 
  773   AC_CACHE_CHECK([for clock_gettime() with ${check_msg}monotonic clock type], erl_cv_clock_gettime_monotonic_$1,
  774   [
  775      for clock_type in $prefer_resolution_clock_gettime_monotonic $default_resolution_clock_gettime_monotonic $high_resolution_clock_gettime_monotonic $low_resolution_clock_gettime_monotonic; do
  776        AC_TRY_LINK([
  777 #include <time.h>
  778 $trust_test
  779 		      ],
  780 		      [
  781     struct timespec ts;
  782     long long result;
  783     clock_gettime($clock_type,&ts);
  784     result = ((long long) ts.tv_sec) * 1000000000LL + 
  785     ((long long) ts.tv_nsec);
  786 		      ],
  787 		      erl_cv_clock_gettime_monotonic_$1=$clock_type,
  788 		      erl_cv_clock_gettime_monotonic_$1=no)
  789        test $erl_cv_clock_gettime_monotonic_$1 = no || break
  790      done
  791   ])
  792 
  793   LIBS="$save_LIBS"
  794 
  795   if test "$LD_MAY_BE_WEAK" != "no"; then
  796      check_for_clock_getres=
  797   else
  798      check_for_clock_getres=clock_getres
  799   fi
  800 
  801   AC_CHECK_FUNCS([$check_for_clock_getres clock_get_attributes gethrtime])
  802   
  803   AC_CACHE_CHECK([for mach clock_get_time() with monotonic clock type], erl_cv_mach_clock_get_time_monotonic,
  804   [
  805      AC_TRY_COMPILE([
  806 #include <mach/clock.h>
  807 #include <mach/mach.h>
  808 			],
  809 	 		[
  810     kern_return_t res;
  811     clock_serv_t clk_srv;
  812     mach_timespec_t time_spec;
  813 
  814     host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &clk_srv);
  815     res = clock_get_time(clk_srv, &time_spec);
  816     mach_port_deallocate(mach_task_self(), clk_srv);
  817     			],
  818     			erl_cv_mach_clock_get_time_monotonic=yes,
  819 			erl_cv_mach_clock_get_time_monotonic=no)
  820   ])
  821   
  822   erl_corrected_monotonic_clock=no
  823   case $erl_cv_clock_gettime_monotonic_$1-$ac_cv_func_gethrtime-$erl_cv_mach_clock_get_time_monotonic-$host_os in
  824     *-*-*-win32)
  825       erl_monotonic_clock_func=WindowsAPI
  826       ;;
  827     CLOCK_*-*-*-linux*)
  828       case $erl_cv_clock_gettime_monotonic_$1-$erl_cv_clock_gettime_monotonic_raw in
  829         CLOCK_BOOTTIME-yes|CLOCK_MONOTONIC-yes)
  830 	  erl_corrected_monotonic_clock=yes
  831 	  ;;
  832 	*)
  833 	  # We don't trust CLOCK_MONOTONIC to be NTP
  834 	  # adjusted on linux systems that do not have
  835 	  # CLOCK_MONOTONIC_RAW (although it seems to
  836 	  # be...)
  837 	  ;;
  838       esac
  839       erl_monotonic_clock_func=clock_gettime
  840       ;;
  841     no-no-no-linux*)
  842       erl_monotonic_clock_func=times
  843       ;;
  844     CLOCK_*-*-*-*)
  845       erl_monotonic_clock_func=clock_gettime
  846       ;;
  847     no-yes-*-*)
  848       erl_monotonic_clock_func=gethrtime
  849       ;;
  850     no-no-yes-*)
  851       erl_monotonic_clock_func=mach_clock_get_time
  852       ;;
  853     no-no-no-*)
  854       erl_monotonic_clock_func=none
  855       ;;
  856   esac
  857 
  858   erl_monotonic_clock_low_resolution=no
  859   erl_monotonic_clock_lib=
  860   erl_monotonic_clock_id=
  861   case $erl_monotonic_clock_func in
  862     clock_gettime)
  863       erl_monotonic_clock_id=$erl_cv_clock_gettime_monotonic_$1
  864       for low_res_id in $low_resolution_clock_gettime_monotonic; do
  865       	  if test $erl_monotonic_clock_id = $low_res_id; then
  866 	    erl_monotonic_clock_low_resolution=yes
  867 	    break
  868 	  fi
  869       done
  870       erl_monotonic_clock_lib=$clock_gettime_lib
  871       ;;
  872     mach_clock_get_time)
  873       erl_monotonic_clock_id=SYSTEM_CLOCK
  874       ;;
  875     times)
  876       erl_monotonic_clock_low_resolution=yes
  877       ;;
  878     *)
  879       ;;
  880   esac
  881  
  882 ])
  883 
  884 AC_DEFUN(ERL_WALL_CLOCK,
  885 [
  886   default_resolution_clock_gettime_wall="CLOCK_REALTIME"
  887   low_resolution_clock_gettime_wall="CLOCK_REALTIME_COARSE CLOCK_REALTIME_FAST"
  888   high_resolution_clock_gettime_wall="CLOCK_REALTIME_PRECISE"
  889 
  890   case "$1" in
  891     high_resolution)
  892 	check_msg="high resolution "
  893 	prefer_resolution_clock_gettime_wall="$high_resolution_clock_gettime_wall"
  894 	;;
  895     low_resolution)
  896 	check_msg="low resolution "
  897 	prefer_resolution_clock_gettime_wall="$low_resolution_clock_gettime_wall"
  898 	;;
  899     custom_resolution)
  900 	check_msg="custom resolution "
  901 	prefer_resolution_clock_gettime_wall="$2"
  902 	;;
  903     *)
  904 	check_msg=""
  905 	prefer_resolution_clock_gettime_wall=
  906 	;;
  907   esac
  908 
  909   clock_gettime_lib=""
  910   AC_CHECK_LIB(rt, clock_gettime, [clock_gettime_lib="-lrt"])
  911 
  912   save_LIBS="$LIBS"
  913   LIBS="$LIBS $clock_gettime_lib"
  914 
  915   if test "$LD_MAY_BE_WEAK" != "no"; then
  916      trust_test="#error May not be there due to weak linking"
  917   else
  918      trust_test=""
  919   fi
  920 
  921   AC_CACHE_CHECK([for clock_gettime() with ${check_msg}wall clock type], erl_cv_clock_gettime_wall_$1,
  922   [
  923      for clock_type in $prefer_resolution_clock_gettime_wall $default_resolution_clock_gettime_wall $high_resolution_clock_gettime_wall $low_resolution_clock_gettime_wall; do
  924        AC_TRY_LINK([
  925 #include <time.h>
  926 $trust_test
  927 		      ],
  928 		      [
  929     struct timespec ts;
  930     long long result;
  931     clock_gettime($clock_type,&ts);
  932     result = ((long long) ts.tv_sec) * 1000000000LL + 
  933     ((long long) ts.tv_nsec);
  934 		      ],
  935 		      erl_cv_clock_gettime_wall_$1=$clock_type,
  936 		      erl_cv_clock_gettime_wall_$1=no)
  937        test $erl_cv_clock_gettime_wall_$1 = no || break
  938      done
  939   ])
  940 
  941   LIBS="$save_LIBS"
  942 
  943   if test "$LD_MAY_BE_WEAK" != "no"; then
  944      check_for_clock_getres=
  945   else
  946      check_for_clock_getres=clock_getres
  947   fi
  948 
  949   AC_CHECK_FUNCS([$check_for_clock_getres clock_get_attributes gettimeofday])
  950   
  951   AC_CACHE_CHECK([for mach clock_get_time() with wall clock type], erl_cv_mach_clock_get_time_wall,
  952   [
  953      AC_TRY_COMPILE([
  954 #include <mach/clock.h>
  955 #include <mach/mach.h>
  956 			],
  957 	 		[
  958     kern_return_t res;
  959     clock_serv_t clk_srv;
  960     mach_timespec_t time_spec;
  961 
  962     host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &clk_srv);
  963     res = clock_get_time(clk_srv, &time_spec);
  964     mach_port_deallocate(mach_task_self(), clk_srv);
  965     			],
  966     			erl_cv_mach_clock_get_time_wall=yes,
  967 			erl_cv_mach_clock_get_time_wall=no)
  968   ])
  969 
  970   erl_wall_clock_lib=
  971   erl_wall_clock_low_resolution=no
  972   erl_wall_clock_id=
  973   case $1-$erl_cv_clock_gettime_wall_$1-$erl_cv_mach_clock_get_time_wall-$ac_cv_func_gettimeofday-$host_os in
  974     *-*-*-*-win32)
  975       erl_wall_clock_func=WindowsAPI
  976       erl_wall_clock_low_resolution=yes
  977       ;;
  978     high_resolution-no-yes-*-*)
  979       erl_wall_clock_func=mach_clock_get_time
  980       erl_wall_clock_id=CALENDAR_CLOCK
  981       ;;
  982     *-CLOCK_*-*-*-*)
  983       erl_wall_clock_func=clock_gettime
  984       erl_wall_clock_lib=$clock_gettime_lib
  985       erl_wall_clock_id=$erl_cv_clock_gettime_wall_$1
  986       for low_res_id in $low_resolution_clock_gettime_wall; do
  987       	  if test $erl_wall_clock_id = $low_res_id; then
  988 	    erl_wall_clock_low_resolution=yes
  989 	    break
  990 	  fi
  991       done
  992       ;;
  993     *-no-*-yes-*)
  994       erl_wall_clock_func=gettimeofday
  995       ;;
  996     *)
  997       erl_wall_clock_func=none
  998       ;;
  999   esac
 1000 ])
 1001 
 1002 dnl ----------------------------------------------------------------------
 1003 dnl
 1004 dnl LM_CHECK_THR_LIB
 1005 dnl
 1006 dnl This macro may be used by any OTP application.
 1007 dnl
 1008 dnl LM_CHECK_THR_LIB sets THR_LIBS, THR_DEFS, and THR_LIB_NAME. It also
 1009 dnl checks for some pthread headers which will appear in DEFS or config.h.
 1010 dnl
 1011 
 1012 AC_DEFUN(LM_CHECK_THR_LIB,
 1013 [
 1014 
 1015 NEED_NPTL_PTHREAD_H=no
 1016 
 1017 dnl win32?
 1018 AC_MSG_CHECKING([for native win32 threads])
 1019 if test "X$host_os" = "Xwin32"; then
 1020     AC_MSG_RESULT(yes)
 1021     THR_DEFS="-DWIN32_THREADS"
 1022     THR_LIBS=
 1023     THR_LIB_NAME=win32_threads
 1024     THR_LIB_TYPE=win32_threads
 1025 else
 1026     AC_MSG_RESULT(no)
 1027     THR_DEFS=
 1028     THR_LIBS=
 1029     THR_LIB_NAME=
 1030     THR_LIB_TYPE=posix_unknown
 1031 
 1032 dnl Try to find POSIX threads
 1033 
 1034 dnl The usual pthread lib...
 1035     AC_CHECK_LIB(pthread, pthread_create, THR_LIBS="-lpthread")
 1036 
 1037 dnl Very old versions of FreeBSD have pthreads in special c library, c_r...
 1038     if test "x$THR_LIBS" = "x"; then
 1039 	AC_CHECK_LIB(c_r, pthread_create, THR_LIBS="-lc_r")
 1040     fi
 1041 
 1042 dnl QNX has pthreads in standard C library
 1043     if test "x$THR_LIBS" = "x"; then
 1044 	AC_CHECK_FUNC(pthread_create, THR_LIBS="none_needed")
 1045     fi
 1046 
 1047 dnl On ofs1 the '-pthread' switch should be used
 1048     if test "x$THR_LIBS" = "x"; then
 1049 	AC_MSG_CHECKING([if the '-pthread' switch can be used])
 1050 	saved_cflags=$CFLAGS
 1051 	CFLAGS="$CFLAGS -pthread"
 1052 	AC_TRY_LINK([#include <pthread.h>],
 1053 		    pthread_create((void*)0,(void*)0,(void*)0,(void*)0);,
 1054 		    [THR_DEFS="-pthread"
 1055 		     THR_LIBS="-pthread"])
 1056 	CFLAGS=$saved_cflags
 1057 	if test "x$THR_LIBS" != "x"; then
 1058 	    AC_MSG_RESULT(yes)
 1059 	else
 1060 	    AC_MSG_RESULT(no)
 1061 	fi
 1062     fi
 1063 
 1064     if test "x$THR_LIBS" != "x"; then
 1065 	THR_DEFS="$THR_DEFS -D_THREAD_SAFE -D_REENTRANT -DPOSIX_THREADS"
 1066 	THR_LIB_NAME=pthread
 1067 	if test "x$THR_LIBS" = "xnone_needed"; then
 1068 	    THR_LIBS=
 1069 	fi
 1070 	case $host_os in
 1071 	    solaris*)
 1072 		THR_DEFS="$THR_DEFS -D_POSIX_PTHREAD_SEMANTICS" ;;
 1073 	    linux*)
 1074 		THR_DEFS="$THR_DEFS -D_POSIX_THREAD_SAFE_FUNCTIONS"
 1075 
 1076 		LM_CHECK_GETCONF
 1077 		AC_MSG_CHECKING(for Native POSIX Thread Library)
 1078 		libpthr_vsn=`$GETCONF GNU_LIBPTHREAD_VERSION 2>/dev/null`
 1079 		if test $? -eq 0; then
 1080 		    case "$libpthr_vsn" in
 1081 			*nptl*|*NPTL*) nptl=yes;;
 1082 			*) nptl=no;;
 1083 		    esac
 1084 		elif test "$cross_compiling" = "yes"; then
 1085 		    case "$erl_xcomp_linux_nptl" in
 1086 			"") nptl=cross;;
 1087 			yes|no) nptl=$erl_xcomp_linux_nptl;;
 1088 			*) AC_MSG_ERROR([Bad erl_xcomp_linux_nptl value: $erl_xcomp_linux_nptl]);;
 1089 		    esac
 1090 		else
 1091 		    nptl=no
 1092 		fi
 1093 		AC_MSG_RESULT($nptl)
 1094 		if test $nptl = cross; then
 1095 		    nptl=yes
 1096 		    AC_MSG_WARN([result yes guessed because of cross compilation])
 1097 		fi
 1098 		if test $nptl = yes; then
 1099 		    THR_LIB_TYPE=posix_nptl
 1100 		    need_nptl_incldir=no
 1101 		    AC_CHECK_HEADER(nptl/pthread.h,
 1102 				    [need_nptl_incldir=yes
 1103 				     NEED_NPTL_PTHREAD_H=yes])
 1104 		    if test $need_nptl_incldir = yes; then
 1105 			# Ahh...
 1106 			nptl_path="$C_INCLUDE_PATH:$CPATH"
 1107 			if test X$cross_compiling != Xyes; then
 1108 			    nptl_path="$nptl_path:/usr/local/include:/usr/include"
 1109 			else
 1110 			    IROOT="$erl_xcomp_isysroot"
 1111 			    test "$IROOT" != "" || IROOT="$erl_xcomp_sysroot"
 1112 			    test "$IROOT" != "" || AC_MSG_ERROR([Don't know where to search for includes! Please set erl_xcomp_isysroot])
 1113 			    nptl_path="$nptl_path:$IROOT/usr/local/include:$IROOT/usr/include"
 1114 			fi
 1115 			nptl_ws_path=
 1116 			save_ifs="$IFS"; IFS=":"
 1117 			for dir in $nptl_path; do
 1118 			    if test "x$dir" != "x"; then
 1119 				nptl_ws_path="$nptl_ws_path $dir"
 1120 			    fi
 1121 			done
 1122 			IFS=$save_ifs
 1123 			nptl_incldir=
 1124 			for dir in $nptl_ws_path; do
 1125 		            AC_CHECK_HEADER($dir/nptl/pthread.h,
 1126 					    nptl_incldir=$dir/nptl)
 1127 			    if test "x$nptl_incldir" != "x"; then
 1128 				THR_DEFS="$THR_DEFS -isystem $nptl_incldir"
 1129 				break
 1130 			    fi
 1131 			done
 1132 			if test "x$nptl_incldir" = "x"; then
 1133 			    AC_MSG_ERROR(Failed to locate nptl system include directory)
 1134 			fi
 1135 		    fi
 1136 		fi
 1137 		;;
 1138 	    *) ;;
 1139 	esac
 1140 
 1141 	dnl We sometimes need THR_DEFS in order to find certain headers
 1142 	dnl (at least for pthread.h on osf1).
 1143 	saved_cppflags=$CPPFLAGS
 1144 	CPPFLAGS="$CPPFLAGS $THR_DEFS"
 1145 
 1146 	dnl
 1147 	dnl Check for headers
 1148 	dnl
 1149 
 1150 	AC_CHECK_HEADER(pthread.h,
 1151 			AC_DEFINE(HAVE_PTHREAD_H, 1, \
 1152 [Define if you have the <pthread.h> header file.]))
 1153 
 1154 	dnl Some Linuxes have <pthread/mit/pthread.h> instead of <pthread.h>
 1155 	AC_CHECK_HEADER(pthread/mit/pthread.h, \
 1156 			AC_DEFINE(HAVE_MIT_PTHREAD_H, 1, \
 1157 [Define if the pthread.h header file is in pthread/mit directory.]))
 1158 
 1159 	dnl restore CPPFLAGS
 1160 	CPPFLAGS=$saved_cppflags
 1161 
 1162     fi
 1163 fi
 1164 
 1165 ])
 1166 
 1167 AC_DEFUN(ERL_INTERNAL_LIBS,
 1168 [
 1169 
 1170 ERTS_INTERNAL_X_LIBS=
 1171 
 1172 AC_CHECK_LIB(kstat, kstat_open,
 1173 [AC_DEFINE(HAVE_KSTAT, 1, [Define if you have kstat])
 1174 ERTS_INTERNAL_X_LIBS="$ERTS_INTERNAL_X_LIBS -lkstat"])
 1175 
 1176 AC_SUBST(ERTS_INTERNAL_X_LIBS)
 1177 
 1178 ])
 1179 
 1180 AC_DEFUN(ETHR_CHK_GCC_ATOMIC_OP__,
 1181 [
 1182     # $1 - atomic_op
 1183 
 1184     for atomic_bit_size in 32 64 128; do
 1185 	case $atomic_bit_size in
 1186 	    32) gcc_atomic_type="$gcc_atomic_type32";;
 1187 	    64) gcc_atomic_type="$gcc_atomic_type64";;
 1188 	    128) gcc_atomic_type="$gcc_atomic_type128";;
 1189 	esac
 1190 	gcc_atomic_lockfree="int x[[(2*__atomic_always_lock_free(sizeof($gcc_atomic_type), 0))-1]]"
 1191 	case $1 in
 1192 	    __sync_add_and_fetch | __sync_fetch_and_and | __sync_fetch_and_or)
 1193 		atomic_call="volatile $gcc_atomic_type var; $gcc_atomic_type res = $1(&var, ($gcc_atomic_type) 0);"
 1194 		;;
 1195 	    __sync_val_compare_and_swap)
 1196 		atomic_call="volatile $gcc_atomic_type var; $gcc_atomic_type res = $1(&var, ($gcc_atomic_type) 0, ($gcc_atomic_type) 0);"
 1197 		;;
 1198 	    __atomic_store_n)
 1199 		atomic_call="$gcc_atomic_lockfree; volatile $gcc_atomic_type var; $1(&var, ($gcc_atomic_type) 0, __ATOMIC_RELAXED); $1(&var, ($gcc_atomic_type) 0, __ATOMIC_RELEASE);"
 1200 		;;
 1201 	    __atomic_load_n)
 1202 		atomic_call="$gcc_atomic_lockfree; volatile $gcc_atomic_type var; $gcc_atomic_type res = $1(&var, __ATOMIC_RELAXED); res = $1(&var, __ATOMIC_ACQUIRE);"
 1203 		;;
 1204 	    __atomic_add_fetch| __atomic_fetch_and | __atomic_fetch_or)
 1205 		atomic_call="$gcc_atomic_lockfree; volatile $gcc_atomic_type var; $gcc_atomic_type res = $1(&var, ($gcc_atomic_type) 0, __ATOMIC_RELAXED); res = $1(&var, ($gcc_atomic_type) 0, __ATOMIC_ACQUIRE); res = $1(&var, ($gcc_atomic_type) 0, __ATOMIC_RELEASE);"
 1206 		;;
 1207 	    __atomic_compare_exchange_n)
 1208 		atomic_call="$gcc_atomic_lockfree; volatile $gcc_atomic_type var; $gcc_atomic_type val; int res = $1(&var, &val, ($gcc_atomic_type) 0, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED); res = $1(&var, &val, ($gcc_atomic_type) 0, 0, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);"
 1209 		;;
 1210 	    *)
 1211 		AC_MSG_ERROR([Internal error: missing implementation for $1])
 1212 		;;
 1213 	esac
 1214 	eval atomic${atomic_bit_size}_call=\"$atomic_call\"
 1215     done
 1216     
 1217     AC_CACHE_CHECK([for 32-bit $1()], ethr_cv_32bit_$1,
 1218 		   [
 1219 		       ethr_cv_32bit_$1=no
 1220 		       AC_TRY_LINK([], [$atomic32_call], [ethr_cv_32bit_$1=yes])
 1221 		   ])
 1222     AC_CACHE_CHECK([for 64-bit $1()], ethr_cv_64bit_$1,
 1223 		   [
 1224 		       ethr_cv_64bit_$1=no
 1225 		       AC_TRY_LINK([], [$atomic64_call], [ethr_cv_64bit_$1=yes])
 1226 		   ])
 1227     AC_CACHE_CHECK([for 128-bit $1()], ethr_cv_128bit_$1,
 1228 		   [
 1229 		       ethr_cv_128bit_$1=no
 1230 		       AC_TRY_LINK([], [$atomic128_call], [ethr_cv_128bit_$1=yes])
 1231 		   ])
 1232 
 1233 	case $ethr_cv_128bit_$1-$ethr_cv_64bit_$1-$ethr_cv_32bit_$1 in
 1234 	    no-no-no)
 1235 		have_atomic_ops=0;;
 1236 	    no-no-yes)
 1237 		have_atomic_ops=4;;
 1238 	    no-yes-no)
 1239 		have_atomic_ops=8;;
 1240 	    no-yes-yes)
 1241 		have_atomic_ops=12;;
 1242 	    yes-no-no)
 1243 		have_atomic_ops=16;;
 1244 	    yes-no-yes)
 1245 		have_atomic_ops=20;;
 1246 	    yes-yes-no)
 1247 		have_atomic_ops=24;;
 1248 	    yes-yes-yes)
 1249 		have_atomic_ops=28;;
 1250 	esac
 1251 	AC_DEFINE_UNQUOTED([ETHR_HAVE_$1], [$have_atomic_ops], [Define as a bitmask corresponding to the word sizes that $1() can handle on your system])
 1252 ])
 1253 
 1254 AC_DEFUN(ETHR_CHK_IF_NOOP,
 1255 [
 1256    ethr_test_filename="chk_if_$1$3_noop_config1test.$$"
 1257    cat > "${ethr_test_filename}.c" <<EOF
 1258 int
 1259 my_test(void)
 1260 {
 1261     $1$2;
 1262     return 0;
 1263 }
 1264 EOF
 1265    $CC -O3 $ETHR_DEFS -c "${ethr_test_filename}.c" -o "${ethr_test_filename}1.o"
 1266    cat > "${ethr_test_filename}.c" <<EOF
 1267 int
 1268 my_test(void)
 1269 {
 1270     ;
 1271     return 0;
 1272 }
 1273 EOF
 1274    $CC -O3 $ETHR_DEFS -c "${ethr_test_filename}.c" -o "${ethr_test_filename}2.o"
 1275    if diff "${ethr_test_filename}1.o" "${ethr_test_filename}2.o" >/dev/null 2>&1; then
 1276       ethr_$1$3_noop=yes
 1277    else
 1278       ethr_$1$3_noop=no
 1279    fi
 1280    rm -f "${ethr_test_filename}.c" "${ethr_test_filename}1.o"  "${ethr_test_filename}2.o" 
 1281 ])
 1282 
 1283 AC_DEFUN(ETHR_CHK_GCC_ATOMIC_OPS,
 1284 [
 1285     AC_CHECK_SIZEOF(short)
 1286     AC_CHECK_SIZEOF(int)
 1287     AC_CHECK_SIZEOF(long)
 1288     AC_CHECK_SIZEOF(long long)
 1289     AC_CHECK_SIZEOF(__int128_t)
 1290 
 1291     if test "$ac_cv_sizeof_short" = "4"; then
 1292 	gcc_atomic_type32="short"
 1293     elif test "$ac_cv_sizeof_int" = "4"; then
 1294 	gcc_atomic_type32="int"
 1295     elif test "$ac_cv_sizeof_long" = "4"; then
 1296 	gcc_atomic_type32="long"
 1297     else
 1298 	AC_MSG_ERROR([No 32-bit type found])
 1299     fi
 1300 
 1301     if test "$ac_cv_sizeof_int" = "8"; then
 1302 	gcc_atomic_type64="int"
 1303     elif test "$ac_cv_sizeof_long" = "8"; then
 1304 	gcc_atomic_type64="long"
 1305     elif test "$ac_cv_sizeof_long_long" = "8"; then
 1306 	gcc_atomic_type64="long long"
 1307     else
 1308 	AC_MSG_ERROR([No 64-bit type found])
 1309     fi
 1310 
 1311     if test "$ac_cv_sizeof___int128_t" = "16"; then
 1312 	gcc_atomic_type128="__int128_t"
 1313     else
 1314 	gcc_atomic_type128="#error "	
 1315     fi
 1316     AC_CACHE_CHECK([for a working __sync_synchronize()], ethr_cv___sync_synchronize,
 1317 		   [
 1318 		       ethr_cv___sync_synchronize=no
 1319 		       AC_TRY_LINK([],
 1320 				   [ __sync_synchronize(); ],
 1321 				   [ethr_cv___sync_synchronize=yes])
 1322 		       if test $ethr_cv___sync_synchronize = yes; then
 1323 			   #
 1324 			   # Old gcc versions on at least x86 have a buggy
 1325 			   # __sync_synchronize() which does not emit a
 1326 			   # memory barrier. We try to detect this by
 1327 			   # compiling to assembly with and without
 1328 			   # __sync_synchronize() and compare the results.
 1329 			   #
 1330 			   ETHR_CHK_IF_NOOP(__sync_synchronize, [()], [])
 1331 			   if test $ethr___sync_synchronize_noop = yes; then
 1332 			      # Got a buggy implementation of
 1333 			      # __sync_synchronize...
 1334 			      ethr_cv___sync_synchronize="no; buggy implementation"
 1335 			   fi
 1336 		       fi
 1337 		   ])
 1338 
 1339     if test "$ethr_cv___sync_synchronize" = "yes"; then
 1340 	have_sync_synchronize_value="~0"
 1341     else
 1342 	have_sync_synchronize_value="0"
 1343     fi
 1344     AC_DEFINE_UNQUOTED([ETHR_HAVE___sync_synchronize], [$have_sync_synchronize_value], [Define as a bitmask corresponding to the word sizes that __sync_synchronize() can handle on your system])
 1345 
 1346     ETHR_CHK_GCC_ATOMIC_OP__(__sync_add_and_fetch)
 1347     ETHR_CHK_GCC_ATOMIC_OP__(__sync_fetch_and_and)
 1348     ETHR_CHK_GCC_ATOMIC_OP__(__sync_fetch_and_or)
 1349     ETHR_CHK_GCC_ATOMIC_OP__(__sync_val_compare_and_swap)
 1350 
 1351     ETHR_CHK_GCC_ATOMIC_OP__(__atomic_store_n)
 1352     ETHR_CHK_GCC_ATOMIC_OP__(__atomic_load_n)
 1353     ETHR_CHK_GCC_ATOMIC_OP__(__atomic_add_fetch)
 1354     ETHR_CHK_GCC_ATOMIC_OP__(__atomic_fetch_and)
 1355     ETHR_CHK_GCC_ATOMIC_OP__(__atomic_fetch_or)
 1356     ETHR_CHK_GCC_ATOMIC_OP__(__atomic_compare_exchange_n)
 1357 
 1358     ethr_have_gcc_native_atomics=no
 1359     ethr_arm_dbm_instr_val=0
 1360     case "$GCC-$host_cpu" in
 1361 	yes-arm*)
 1362 	    AC_CACHE_CHECK([for ARM DMB instruction], ethr_cv_arm_dbm_instr,
 1363 			   [
 1364 				ethr_cv_arm_dbm_instr=no
 1365 				AC_TRY_LINK([],
 1366 					    [
 1367 						__asm__ __volatile__("dmb sy" : : : "memory");
 1368 						__asm__ __volatile__("dmb st" : : : "memory");
 1369 					    ],
 1370 					    [ethr_cv_arm_dbm_instr=yes])
 1371 			   ])
 1372 	    if test $ethr_cv_arm_dbm_instr = yes; then
 1373 		ethr_arm_dbm_instr_val=1
 1374 		test $ethr_cv_64bit___atomic_compare_exchange_n = yes &&
 1375 		    ethr_have_gcc_native_atomics=yes
 1376 	    fi;;
 1377 	*)
 1378 	    ;;
 1379     esac
 1380     AC_DEFINE_UNQUOTED([ETHR_HAVE_GCC_ASM_ARM_DMB_INSTRUCTION], [$ethr_arm_dbm_instr_val], [Define as a boolean indicating whether you have a gcc compatible compiler capable of generating the ARM DMB instruction, and are compiling for an ARM processor with ARM DMB instruction support, or not])
 1381     test $ethr_cv_32bit___sync_val_compare_and_swap = yes &&
 1382     	ethr_have_gcc_native_atomics=yes
 1383     test $ethr_cv_64bit___sync_val_compare_and_swap = yes &&
 1384     	ethr_have_gcc_native_atomics=yes
 1385     if test "$ethr_cv___sync_synchronize" = "yes"; then
 1386     	test $ethr_cv_64bit___atomic_compare_exchange_n = yes &&
 1387     	    ethr_have_gcc_native_atomics=yes
 1388     	test $ethr_cv_32bit___atomic_compare_exchange_n = yes &&
 1389     	    ethr_have_gcc_native_atomics=yes
 1390     fi
 1391     ethr_have_gcc_atomic_builtins=0
 1392     if test $ethr_have_gcc_native_atomics = yes; then
 1393        ethr_native_atomic_implementation=gcc_sync
 1394        test $ethr_cv_32bit___atomic_compare_exchange_n = yes && ethr_have_gcc_atomic_builtins=1
 1395        test $ethr_cv_64bit___atomic_compare_exchange_n = yes && ethr_have_gcc_atomic_builtins=1
 1396        test $ethr_have_gcc_atomic_builtins = 1 && ethr_native_atomic_implementation=gcc_atomic_sync
 1397     fi
 1398     AC_DEFINE_UNQUOTED([ETHR_HAVE_GCC___ATOMIC_BUILTINS], [$ethr_have_gcc_atomic_builtins], [Define as a boolean indicating whether you have a gcc __atomic builtins or not])
 1399     test $ethr_have_gcc_native_atomics = yes && ethr_have_native_atomics=yes
 1400 ])
 1401 
 1402 AC_DEFUN(ETHR_CHK_INTERLOCKED,
 1403 [
 1404     ilckd="$1"
 1405     AC_MSG_CHECKING([for ${ilckd}()])
 1406     case "$2" in
 1407 	"1") ilckd_call="${ilckd}(var);";;
 1408 	"2") ilckd_call="${ilckd}(var, ($3) 0);";;
 1409 	"3") ilckd_call="${ilckd}(var, ($3) 0, ($3) 0);";;
 1410 	"4") ilckd_call="${ilckd}(var, ($3) 0, ($3) 0, arr);";;
 1411     esac
 1412     have_interlocked_op=no
 1413     AC_TRY_LINK(
 1414 	[
 1415 	#define WIN32_LEAN_AND_MEAN
 1416 	#include <windows.h>
 1417 	#include <intrin.h>
 1418 	],
 1419 	[
 1420 	    volatile $3 *var;
 1421 	    volatile $3 arr[2];
 1422 
 1423 	    $ilckd_call
 1424 	    return 0;
 1425 	],
 1426 	[have_interlocked_op=yes])
 1427     test $have_interlocked_op = yes && $4
 1428     AC_MSG_RESULT([$have_interlocked_op])
 1429 ])
 1430 
 1431 dnl ----------------------------------------------------------------------
 1432 dnl
 1433 dnl ERL_FIND_ETHR_LIB
 1434 dnl
 1435 dnl NOTE! This macro may be changed at any time! Should *only* be used by
 1436 dnl       ERTS!
 1437 dnl
 1438 dnl Find a thread library to use. Sets ETHR_LIBS to libraries to link
 1439 dnl with, ETHR_X_LIBS to extra libraries to link with (same as ETHR_LIBS
 1440 dnl except that the ethread lib itself is not included), ETHR_DEFS to
 1441 dnl defines to compile with, ETHR_THR_LIB_BASE to the name of the
 1442 dnl thread library which the ethread library is based on, and ETHR_LIB_NAME
 1443 dnl to the name of the library where the ethread implementation is located.
 1444 dnl  ERL_FIND_ETHR_LIB currently searches for 'pthreads', and
 1445 dnl 'win32_threads'. If no thread library was found ETHR_LIBS, ETHR_X_LIBS,
 1446 dnl ETHR_DEFS, ETHR_THR_LIB_BASE, and ETHR_LIB_NAME are all set to the
 1447 dnl empty string.
 1448 dnl
 1449 
 1450 AC_DEFUN(ERL_FIND_ETHR_LIB,
 1451 [
 1452 
 1453 AC_ARG_ENABLE(native-ethr-impls,
 1454 	      AS_HELP_STRING([--disable-native-ethr-impls],
 1455                              [disable native ethread implementations]),
 1456 [ case "$enableval" in
 1457     no) disable_native_ethr_impls=yes ;;
 1458     *)  disable_native_ethr_impls=no ;;
 1459   esac ], disable_native_ethr_impls=no)
 1460 
 1461 test "X$disable_native_ethr_impls" = "Xyes" &&
 1462   AC_DEFINE(ETHR_DISABLE_NATIVE_IMPLS, 1, [Define if you want to disable native ethread implementations])
 1463 
 1464 AC_ARG_ENABLE(x86-out-of-order,
 1465 	      AS_HELP_STRING([--enable-x86-out-of-order],
 1466                              [enable x86/x84_64 out of order support (default disabled)]))
 1467 
 1468 AC_ARG_ENABLE(prefer-gcc-native-ethr-impls,
 1469 	      AS_HELP_STRING([--enable-prefer-gcc-native-ethr-impls],
 1470 			     [prefer gcc native ethread implementations]),
 1471 [ case "$enableval" in
 1472     yes) enable_prefer_gcc_native_ethr_impls=yes ;;
 1473     *)  enable_prefer_gcc_native_ethr_impls=no ;;
 1474   esac ], enable_prefer_gcc_native_ethr_impls=no)
 1475 
 1476 test $enable_prefer_gcc_native_ethr_impls = yes &&
 1477   AC_DEFINE(ETHR_PREFER_GCC_NATIVE_IMPLS, 1, [Define if you prefer gcc native ethread implementations])
 1478 
 1479 AC_ARG_ENABLE(trust-gcc-atomic-builtins-memory-barriers,
 1480 	      AS_HELP_STRING([--enable-trust-gcc-atomic-builtins-memory-barriers],
 1481 			     [trust gcc atomic builtins memory barriers]),
 1482 [ case "$enableval" in
 1483     yes) trust_gcc_atomic_builtins_mbs=1 ;;
 1484     *) trust_gcc_atomic_builtins_mbs=0 ;;
 1485   esac ], trust_gcc_atomic_builtins_mbs=0)
 1486 
 1487 AC_DEFINE_UNQUOTED(ETHR_TRUST_GCC_ATOMIC_BUILTINS_MEMORY_BARRIERS, [$trust_gcc_atomic_builtins_mbs], [Define as a boolean indicating whether you trust gcc's __atomic_* builtins memory barrier implementations, or not])
 1488 
 1489 AC_ARG_WITH(libatomic_ops,
 1490 	    AS_HELP_STRING([--with-libatomic_ops=PATH],
 1491 			   [specify and prefer usage of libatomic_ops in the ethread library]))
 1492 
 1493 AC_ARG_WITH(with_sparc_memory_order,
 1494 	    AS_HELP_STRING([--with-sparc-memory-order=TSO|PSO|RMO],
 1495 			   [specify sparc memory order (defaults to RMO)]))
 1496 
 1497 LM_CHECK_THR_LIB
 1498 ERL_INTERNAL_LIBS
 1499 
 1500 ERL_MONOTONIC_CLOCK(try_find_pthread_compatible, CLOCK_HIGHRES CLOCK_MONOTONIC, no)
 1501 
 1502 case $erl_monotonic_clock_func in
 1503   clock_gettime)
 1504     AC_DEFINE(ETHR_HAVE_CLOCK_GETTIME_MONOTONIC, [1], [Define if you have a clock_gettime() with a monotonic clock])
 1505     ;;
 1506   mach_clock_get_time)
 1507     AC_DEFINE(ETHR_HAVE_MACH_CLOCK_GET_TIME, [1], [Define if you have a mach clock_get_time() with a monotonic clock])
 1508     ;;
 1509   gethrtime)
 1510     AC_DEFINE(ETHR_HAVE_GETHRTIME, [1], [Define if you have a monotonic gethrtime()])
 1511     ;;
 1512   *)
 1513     ;;
 1514 esac
 1515 
 1516 if test "x$erl_monotonic_clock_id" != "x"; then
 1517     AC_DEFINE_UNQUOTED(ETHR_MONOTONIC_CLOCK_ID, [$erl_monotonic_clock_id], [Define to the monotonic clock id to use])
 1518 fi
 1519 
 1520 ethr_native_atomic_implementation=none
 1521 ethr_have_native_atomics=no
 1522 ethr_have_native_spinlock=no
 1523 ETHR_THR_LIB_BASE="$THR_LIB_NAME"
 1524 ETHR_THR_LIB_BASE_TYPE="$THR_LIB_TYPE"
 1525 ETHR_DEFS="$THR_DEFS"
 1526 ETHR_X_LIBS="$THR_LIBS $ERTS_INTERNAL_X_LIBS $erl_monotonic_clock_lib"
 1527 ETHR_LIBS=
 1528 ETHR_LIB_NAME=
 1529 
 1530 ethr_modified_default_stack_size=
 1531 
 1532 AC_ARG_WITH(threadnames,
 1533 AS_HELP_STRING([--with-threadnames], [use pthread_setname to set the thread names (default)])
 1534 AS_HELP_STRING([--without-threadnames],
 1535                [do not set any thread names]),
 1536 [],
 1537 [with_threadnames=yes])
 1538 
 1539 dnl Name of lib where ethread implementation is located
 1540 ethr_lib_name=ethread
 1541 
 1542 case "$THR_LIB_NAME" in
 1543 
 1544     win32_threads)
 1545 	ETHR_THR_LIB_BASE_DIR=win
 1546 	# * _WIN32_WINNT >= 0x0400 is needed for
 1547 	#   TryEnterCriticalSection
 1548 	# * _WIN32_WINNT >= 0x0403 is needed for
 1549 	#   InitializeCriticalSectionAndSpinCount
 1550 	# The ethread lib will refuse to build if _WIN32_WINNT < 0x0403.
 1551 	#
 1552 	# -D_WIN32_WINNT should have been defined in $CPPFLAGS; fetch it
 1553 	# and save it in ETHR_DEFS.
 1554 	found_win32_winnt=no
 1555 	for cppflag in $CPPFLAGS; do
 1556 	    case $cppflag in
 1557 		-DWINVER*)
 1558 		    ETHR_DEFS="$ETHR_DEFS $cppflag"
 1559 		    ;;
 1560 		-D_WIN32_WINNT*)
 1561 		    ETHR_DEFS="$ETHR_DEFS $cppflag"
 1562 		    found_win32_winnt=yes
 1563 		    ;;
 1564 		*)
 1565 		    ;;
 1566 	    esac
 1567         done
 1568         if test $found_win32_winnt = no; then
 1569 	    AC_MSG_ERROR([-D_WIN32_WINNT missing in CPPFLAGS])
 1570         fi
 1571 
 1572 	AC_DEFINE(ETHR_WIN32_THREADS, 1, [Define if you have win32 threads])
 1573 
 1574 	if test "X$disable_native_ethr_impls" = "Xyes"; then
 1575 	    have_interlocked_op=no
 1576 	    ethr_have_native_atomics=no
 1577 	else
 1578 	    ETHR_CHK_INTERLOCKED([_InterlockedDecrement], [1], [long], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDDECREMENT, 1, [Define if you have _InterlockedDecrement()]))
 1579 	    ETHR_CHK_INTERLOCKED([_InterlockedDecrement_rel], [1], [long], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDDECREMENT_REL, 1, [Define if you have _InterlockedDecrement_rel()]))
 1580 	    ETHR_CHK_INTERLOCKED([_InterlockedIncrement], [1], [long], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDINCREMENT, 1, [Define if you have _InterlockedIncrement()]))
 1581 	    ETHR_CHK_INTERLOCKED([_InterlockedIncrement_acq], [1], [long], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDINCREMENT_ACQ, 1, [Define if you have _InterlockedIncrement_acq()]))
 1582 	    ETHR_CHK_INTERLOCKED([_InterlockedExchangeAdd], [2], [long], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDEXCHANGEADD, 1, [Define if you have _InterlockedExchangeAdd()]))
 1583 	    ETHR_CHK_INTERLOCKED([_InterlockedExchangeAdd_acq], [2], [long], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDEXCHANGEADD_ACQ, 1, [Define if you have _InterlockedExchangeAdd_acq()]))
 1584 	    ETHR_CHK_INTERLOCKED([_InterlockedAnd], [2], [long], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDAND, 1, [Define if you have _InterlockedAnd()]))
 1585 	    ETHR_CHK_INTERLOCKED([_InterlockedOr], [2], [long], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDOR, 1, [Define if you have _InterlockedOr()]))
 1586 	    ETHR_CHK_INTERLOCKED([_InterlockedExchange], [2], [long], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDEXCHANGE, 1, [Define if you have _InterlockedExchange()]))
 1587 	    ETHR_CHK_INTERLOCKED([_InterlockedCompareExchange], [3], [long], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDCOMPAREEXCHANGE, 1, [Define if you have _InterlockedCompareExchange()]))
 1588 	    test "$have_interlocked_op" = "yes" && ethr_have_native_atomics=yes
 1589 	    ETHR_CHK_INTERLOCKED([_InterlockedCompareExchange_acq], [3], [long], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDCOMPAREEXCHANGE_ACQ, 1, [Define if you have _InterlockedCompareExchange_acq()]))
 1590 	    test "$have_interlocked_op" = "yes" && ethr_have_native_atomics=yes
 1591 	    ETHR_CHK_INTERLOCKED([_InterlockedCompareExchange_rel], [3], [long], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDCOMPAREEXCHANGE_REL, 1, [Define if you have _InterlockedCompareExchange_rel()]))
 1592 	    test "$have_interlocked_op" = "yes" && ethr_have_native_atomics=yes
 1593 
 1594 	    ETHR_CHK_INTERLOCKED([_InterlockedDecrement64], [1], [__int64], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDDECREMENT64, 1, [Define if you have _InterlockedDecrement64()]))
 1595 	    ETHR_CHK_INTERLOCKED([_InterlockedDecrement64_rel], [1], [__int64], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDDECREMENT64_REL, 1, [Define if you have _InterlockedDecrement64_rel()]))
 1596 	    ETHR_CHK_INTERLOCKED([_InterlockedIncrement64], [1], [__int64], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDINCREMENT64, 1, [Define if you have _InterlockedIncrement64()]))
 1597 	    ETHR_CHK_INTERLOCKED([_InterlockedIncrement64_acq], [1], [__int64], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDINCREMENT64_ACQ, 1, [Define if you have _InterlockedIncrement64_acq()]))
 1598 	    ETHR_CHK_INTERLOCKED([_InterlockedExchangeAdd64], [2], [__int64], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDEXCHANGEADD64, 1, [Define if you have _InterlockedExchangeAdd64()]))
 1599 	    ETHR_CHK_INTERLOCKED([_InterlockedExchangeAdd64_acq], [2], [__int64], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDEXCHANGEADD64_ACQ, 1, [Define if you have _InterlockedExchangeAdd64_acq()]))
 1600 	    ETHR_CHK_INTERLOCKED([_InterlockedAnd64], [2], [__int64], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDAND64, 1, [Define if you have _InterlockedAnd64()]))
 1601 	    ETHR_CHK_INTERLOCKED([_InterlockedOr64], [2], [__int64], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDOR64, 1, [Define if you have _InterlockedOr64()]))
 1602 	    ETHR_CHK_INTERLOCKED([_InterlockedExchange64], [2], [__int64], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDEXCHANGE64, 1, [Define if you have _InterlockedExchange64()]))
 1603 	    ETHR_CHK_INTERLOCKED([_InterlockedCompareExchange64], [3], [__int64], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDCOMPAREEXCHANGE64, 1, [Define if you have _InterlockedCompareExchange64()]))
 1604 	    test "$have_interlocked_op" = "yes" && ethr_have_native_atomics=yes
 1605 	    ETHR_CHK_INTERLOCKED([_InterlockedCompareExchange64_acq], [3], [__int64], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDCOMPAREEXCHANGE64_ACQ, 1, [Define if you have _InterlockedCompareExchange64_acq()]))
 1606 	    test "$have_interlocked_op" = "yes" && ethr_have_native_atomics=yes
 1607 	    ETHR_CHK_INTERLOCKED([_InterlockedCompareExchange64_rel], [3], [__int64], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDCOMPAREEXCHANGE64_REL, 1, [Define if you have _InterlockedCompareExchange64_rel()]))
 1608 	    test "$have_interlocked_op" = "yes" && ethr_have_native_atomics=yes
 1609 
 1610 	    ETHR_CHK_INTERLOCKED([_InterlockedCompareExchange128], [4], [__int64], AC_DEFINE_UNQUOTED(ETHR_HAVE__INTERLOCKEDCOMPAREEXCHANGE128, 1, [Define if you have _InterlockedCompareExchange128()]))
 1611 	fi
 1612 	if test "$ethr_have_native_atomics" = "yes"; then
 1613 	   ethr_native_atomic_implementation=windows
 1614 	   ethr_have_native_spinlock=yes
 1615 	fi
 1616 	;;
 1617 
 1618     pthread)
 1619 	ETHR_THR_LIB_BASE_DIR=pthread
 1620 	AC_DEFINE(ETHR_PTHREADS, 1, [Define if you have pthreads])
 1621 	case $host_os in
 1622 	    openbsd*)
 1623 		# The default stack size is insufficient for our needs
 1624 		# on OpenBSD. We increase it to 256 kilo words.
 1625 		ethr_modified_default_stack_size=256;;
 1626 	    linux*)
 1627 		ETHR_DEFS="$ETHR_DEFS -D_GNU_SOURCE"
 1628 
 1629 		if test	X$cross_compiling = Xyes; then
 1630 		    case X$erl_xcomp_linux_usable_sigusrx in
 1631 			X) usable_sigusrx=cross;;
 1632 			Xyes|Xno) usable_sigusrx=$erl_xcomp_linux_usable_sigusrx;;
 1633 			*) AC_MSG_ERROR([Bad erl_xcomp_linux_usable_sigusrx value: $erl_xcomp_linux_usable_sigusrx]);;
 1634 		    esac
 1635 		    case X$erl_xcomp_linux_usable_sigaltstack in
 1636 			X) usable_sigaltstack=cross;;
 1637 			Xyes|Xno) usable_sigaltstack=$erl_xcomp_linux_usable_sigaltstack;;
 1638 			*) AC_MSG_ERROR([Bad erl_xcomp_linux_usable_sigaltstack value: $erl_xcomp_linux_usable_sigaltstack]);;
 1639 		    esac
 1640 		else
 1641 		    # FIXME: Test for actual problems instead of kernel versions
 1642 		    linux_kernel_vsn_=`uname -r`
 1643 		    case $linux_kernel_vsn_ in
 1644 			[[0-1]].*|2.[[0-1]]|2.[[0-1]].*)
 1645 			    usable_sigusrx=no
 1646 			    usable_sigaltstack=no;;
 1647 			2.[[2-3]]|2.[[2-3]].*)
 1648 			    usable_sigusrx=yes
 1649 			    usable_sigaltstack=no;;
 1650 		    	*)
 1651 			    usable_sigusrx=yes
 1652 			    usable_sigaltstack=yes;;
 1653 		    esac
 1654 		fi
 1655 
 1656 		AC_MSG_CHECKING(if SIGUSR1 and SIGUSR2 can be used)
 1657 		AC_MSG_RESULT($usable_sigusrx)
 1658 		if test $usable_sigusrx = cross; then
 1659 		    usable_sigusrx=yes
 1660 		    AC_MSG_WARN([result yes guessed because of cross compilation])
 1661 		fi
 1662 		if test $usable_sigusrx = no; then
 1663 		    ETHR_DEFS="$ETHR_DEFS -DETHR_UNUSABLE_SIGUSRX"
 1664 		fi
 1665 
 1666 		AC_MSG_CHECKING(if sigaltstack can be used)
 1667 		AC_MSG_RESULT($usable_sigaltstack)
 1668 		if test $usable_sigaltstack = cross; then
 1669 		    usable_sigaltstack=yes
 1670 		    AC_MSG_WARN([result yes guessed because of cross compilation])
 1671 		fi
 1672 		if test $usable_sigaltstack = no; then
 1673 		    ETHR_DEFS="$ETHR_DEFS -DETHR_UNUSABLE_SIGALTSTACK"
 1674 		fi
 1675 		;;
 1676 	    *) ;;
 1677 	esac
 1678 
 1679 	dnl We sometimes need ETHR_DEFS in order to find certain headers
 1680 	dnl (at least for pthread.h on osf1).
 1681 	saved_cppflags="$CPPFLAGS"
 1682 	CPPFLAGS="$CPPFLAGS $ETHR_DEFS"
 1683 
 1684 	dnl We need the thread library in order to find some functions
 1685 	saved_libs="$LIBS"
 1686 	LIBS="$LIBS $ETHR_X_LIBS"
 1687 
 1688 	dnl
 1689 	dnl Check for headers
 1690 	dnl
 1691 	AC_CHECK_HEADER(pthread.h, \
 1692 			AC_DEFINE(ETHR_HAVE_PTHREAD_H, 1, \
 1693 [Define if you have the <pthread.h> header file.]))
 1694 
 1695 	dnl Some Linuxes have <pthread/mit/pthread.h> instead of <pthread.h>
 1696 	AC_CHECK_HEADER(pthread/mit/pthread.h, \
 1697 			AC_DEFINE(ETHR_HAVE_MIT_PTHREAD_H, 1, \
 1698 [Define if the pthread.h header file is in pthread/mit directory.]))
 1699 
 1700 	if test $NEED_NPTL_PTHREAD_H = yes; then
 1701 	    AC_DEFINE(ETHR_NEED_NPTL_PTHREAD_H, 1, \
 1702 [Define if you need the <nptl/pthread.h> header file.])
 1703 	fi
 1704 
 1705 	AC_CHECK_HEADER(sched.h, \
 1706 			AC_DEFINE(ETHR_HAVE_SCHED_H, 1, \
 1707 [Define if you have the <sched.h> header file.]))
 1708 
 1709 	AC_CHECK_HEADER(sys/time.h, \
 1710 			AC_DEFINE(ETHR_HAVE_SYS_TIME_H, 1, \
 1711 [Define if you have the <sys/time.h> header file.]))
 1712 
 1713 	AC_TRY_COMPILE([#include <time.h>
 1714 			#include <sys/time.h>], 
 1715 			[struct timeval *tv; return 0;],
 1716 			AC_DEFINE(ETHR_TIME_WITH_SYS_TIME, 1, \
 1717 [Define if you can safely include both <sys/time.h> and <time.h>.]))
 1718 
 1719 	AC_MSG_CHECKING([for usable PTHREAD_STACK_MIN])
 1720 	pthread_stack_min=no
 1721 	AC_TRY_COMPILE([
 1722 #include <limits.h>
 1723 #if defined(ETHR_NEED_NPTL_PTHREAD_H)
 1724 #include <nptl/pthread.h>
 1725 #elif defined(ETHR_HAVE_MIT_PTHREAD_H)
 1726 #include <pthread/mit/pthread.h>
 1727 #elif defined(ETHR_HAVE_PTHREAD_H)
 1728 #include <pthread.h>
 1729 #endif
 1730 			], 
 1731 			[return PTHREAD_STACK_MIN;],
 1732 			[pthread_stack_min=yes])
 1733 
 1734 	AC_MSG_RESULT([$pthread_stack_min])
 1735 	test $pthread_stack_min != yes || {
 1736 	     AC_DEFINE(ETHR_HAVE_USABLE_PTHREAD_STACK_MIN, 1, [Define if you can use PTHREAD_STACK_MIN])
 1737 	}
 1738 
 1739 	dnl
 1740 	dnl Check for functions
 1741 	dnl
 1742 	AC_CHECK_FUNC(pthread_spin_lock, \
 1743 			[ethr_have_native_spinlock=yes \
 1744 			 AC_DEFINE(ETHR_HAVE_PTHREAD_SPIN_LOCK, 1, \
 1745 [Define if you have the pthread_spin_lock function.])])
 1746 
 1747 	have_sched_yield=no
 1748 	have_librt_sched_yield=no
 1749 	AC_CHECK_FUNC(sched_yield, [have_sched_yield=yes])
 1750 	if test $have_sched_yield = no; then
 1751 	    AC_CHECK_LIB(rt, sched_yield,
 1752 			 [have_librt_sched_yield=yes
 1753 			  ETHR_X_LIBS="$ETHR_X_LIBS -lrt"])
 1754 	fi
 1755 	if test $have_sched_yield = yes || test $have_librt_sched_yield = yes; then
 1756 	    AC_DEFINE(ETHR_HAVE_SCHED_YIELD, 1, [Define if you have the sched_yield() function.])
 1757 	    AC_MSG_CHECKING([whether sched_yield() returns an int])
 1758 	    sched_yield_ret_int=no
 1759 	    AC_TRY_LINK([
 1760 				#ifdef ETHR_HAVE_SCHED_H
 1761 				#include <sched.h>
 1762 				#endif
 1763 			   ],
 1764 			   [int sched_yield();],
 1765 			   [sched_yield_ret_int=yes])
 1766 	    AC_MSG_RESULT([$sched_yield_ret_int])
 1767 	    if test $sched_yield_ret_int = yes; then
 1768 		AC_DEFINE(ETHR_SCHED_YIELD_RET_INT, 1, [Define if sched_yield() returns an int.])
 1769 	    fi
 1770 	fi
 1771 
 1772 	have_pthread_yield=no
 1773 	AC_CHECK_FUNC(pthread_yield, [have_pthread_yield=yes])
 1774 	if test $have_pthread_yield = yes; then
 1775 	    AC_DEFINE(ETHR_HAVE_PTHREAD_YIELD, 1, [Define if you have the pthread_yield() function.])
 1776 	    AC_MSG_CHECKING([whether pthread_yield() returns an int])
 1777 	    pthread_yield_ret_int=no
 1778 	    AC_TRY_LINK([
 1779 				#if defined(ETHR_NEED_NPTL_PTHREAD_H)
 1780 				#include <nptl/pthread.h>
 1781 				#elif defined(ETHR_HAVE_MIT_PTHREAD_H)
 1782 				#include <pthread/mit/pthread.h>
 1783 				#elif defined(ETHR_HAVE_PTHREAD_H)
 1784 				#include <pthread.h>
 1785 				#endif
 1786 			   ],
 1787 			   [int pthread_yield();],
 1788 			   [pthread_yield_ret_int=yes])
 1789 	    AC_MSG_RESULT([$pthread_yield_ret_int])
 1790 	    if test $pthread_yield_ret_int = yes; then
 1791 		AC_DEFINE(ETHR_PTHREAD_YIELD_RET_INT, 1, [Define if pthread_yield() returns an int.])
 1792 	    fi
 1793 	fi
 1794 
 1795 	have_pthread_rwlock_init=no
 1796 	AC_CHECK_FUNC(pthread_rwlock_init, [have_pthread_rwlock_init=yes])
 1797 	if test $have_pthread_rwlock_init = yes; then
 1798 
 1799 	    ethr_have_pthread_rwlockattr_setkind_np=no
 1800 	    AC_CHECK_FUNC(pthread_rwlockattr_setkind_np,
 1801 			  [ethr_have_pthread_rwlockattr_setkind_np=yes])
 1802 
 1803 	    if test $ethr_have_pthread_rwlockattr_setkind_np = yes; then
 1804 		AC_DEFINE(ETHR_HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP, 1, \
 1805 [Define if you have the pthread_rwlockattr_setkind_np() function.])
 1806 
 1807 		AC_MSG_CHECKING([for PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP])
 1808 		ethr_pthread_rwlock_writer_nonrecursive_initializer_np=no
 1809 		AC_TRY_LINK([
 1810 				#if defined(ETHR_NEED_NPTL_PTHREAD_H)
 1811 				#include <nptl/pthread.h>
 1812 				#elif defined(ETHR_HAVE_MIT_PTHREAD_H)
 1813 				#include <pthread/mit/pthread.h>
 1814 				#elif defined(ETHR_HAVE_PTHREAD_H)
 1815 				#include <pthread.h>
 1816 				#endif
 1817 			    ],
 1818 			    [
 1819 				pthread_rwlockattr_t *attr;
 1820 				return pthread_rwlockattr_setkind_np(attr,
 1821 				    PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
 1822 			    ],
 1823 			    [ethr_pthread_rwlock_writer_nonrecursive_initializer_np=yes])
 1824 		AC_MSG_RESULT([$ethr_pthread_rwlock_writer_nonrecursive_initializer_np])
 1825 		if test $ethr_pthread_rwlock_writer_nonrecursive_initializer_np = yes; then
 1826 		    AC_DEFINE(ETHR_HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, 1, \
 1827 [Define if you have the PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP rwlock attribute.])
 1828 		fi
 1829 	    fi
 1830 	fi
 1831 
 1832 	if test "$force_pthread_rwlocks" = "yes"; then
 1833 
 1834 	    AC_DEFINE(ETHR_FORCE_PTHREAD_RWLOCK, 1, \
 1835 [Define if you want to force usage of pthread rwlocks])
 1836 
 1837 	    if test $have_pthread_rwlock_init = yes; then
 1838 		AC_MSG_WARN([Forced usage of pthread rwlocks. Note that this implementation may suffer from starvation issues.])
 1839 	    else
 1840 		AC_MSG_ERROR([User forced usage of pthread rwlock, but no such implementation was found])
 1841 	    fi
 1842 	fi
 1843 
 1844 	AC_CHECK_FUNC(pthread_attr_setguardsize, \
 1845 			AC_DEFINE(ETHR_HAVE_PTHREAD_ATTR_SETGUARDSIZE, 1, \
 1846 [Define if you have the pthread_attr_setguardsize function.]))
 1847 
 1848 	if test "x$erl_monotonic_clock_id" != "x"; then
 1849 	  AC_MSG_CHECKING(whether pthread_cond_timedwait() can use the monotonic clock $erl_monotonic_clock_id for timeout)
 1850 	  pthread_cond_timedwait_monotonic=no
 1851 	  AC_TRY_LINK([
 1852 			#if defined(ETHR_NEED_NPTL_PTHREAD_H)
 1853 			#  include <nptl/pthread.h>
 1854 			#elif defined(ETHR_HAVE_MIT_PTHREAD_H)
 1855 			#  include <pthread/mit/pthread.h>
 1856 			#elif defined(ETHR_HAVE_PTHREAD_H)
 1857 			#  include <pthread.h>
 1858 			#endif
 1859 			#ifdef ETHR_TIME_WITH_SYS_TIME
 1860 			#  include <time.h>
 1861 			#  include <sys/time.h>
 1862 			#else
 1863 			#  ifdef ETHR_HAVE_SYS_TIME_H
 1864 			#    include <sys/time.h>
 1865 			#  else
 1866 			#    include <time.h>
 1867 			#  endif
 1868 			#endif
 1869 			#if defined(ETHR_HAVE_MACH_CLOCK_GET_TIME)
 1870 			#  include <mach/clock.h>
 1871 			#  include <mach/mach.h>
 1872 			#endif
 1873 			], 
 1874 			[
 1875 			int res;
 1876 			pthread_condattr_t attr;
 1877 			pthread_cond_t cond;
 1878 			struct timespec cond_timeout;
 1879 			pthread_mutex_t mutex;
 1880 			res = pthread_condattr_init(&attr);
 1881 			res = pthread_condattr_setclock(&attr, ETHR_MONOTONIC_CLOCK_ID);
 1882 			res = pthread_cond_init(&cond, &attr);
 1883 			res = pthread_cond_timedwait(&cond, &mutex, &cond_timeout);
 1884 			],
 1885 			[pthread_cond_timedwait_monotonic=yes])
 1886 	  AC_MSG_RESULT([$pthread_cond_timedwait_monotonic])
 1887 	  if test $pthread_cond_timedwait_monotonic = yes; then
 1888 	    AC_DEFINE(ETHR_HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC, [1], [Define if pthread_cond_timedwait() can be used with a monotonic clock])
 1889 	  fi
 1890 	fi
 1891 
 1892 	linux_futex=no
 1893 	AC_MSG_CHECKING([for Linux futexes])
 1894 	AC_TRY_LINK([
 1895 			#include <sys/syscall.h>
 1896 			#include <unistd.h>
 1897 			#include <linux/futex.h>
 1898 			#include <sys/time.h>
 1899 		    ],
 1900 		    [
 1901 			int i = 1;
 1902 			syscall(__NR_futex, (void *) &i, FUTEX_WAKE, 1,
 1903 				(void*)0,(void*)0, 0);
 1904 			syscall(__NR_futex, (void *) &i, FUTEX_WAIT, 0,
 1905 				(void*)0,(void*)0, 0);
 1906 			return 0;
 1907 		    ],
 1908 		    linux_futex=yes)
 1909 	AC_MSG_RESULT([$linux_futex])
 1910 	test $linux_futex = yes && AC_DEFINE(ETHR_HAVE_LINUX_FUTEX, 1, [Define if you have a linux futex implementation.])
 1911 
 1912 	pthread_setname=no
 1913 	AC_MSG_CHECKING([for pthread_setname_np])
 1914 	old_CFLAGS=$CFLAGS
 1915 	CFLAGS="$CFLAGS -Werror"
 1916 	AC_TRY_LINK([#define __USE_GNU
 1917                      #include <pthread.h>],
 1918                     [pthread_setname_np(pthread_self(), "name");],
 1919                     pthread_setname=linux)
 1920 	AC_TRY_LINK([#define __USE_GNU
 1921                      #include <pthread.h>],
 1922                     [pthread_set_name_np(pthread_self(), "name");],
 1923                     pthread_setname=bsd)
 1924 	AC_TRY_LINK([#define _DARWIN_C_SOURCE
 1925                      #include <pthread.h>],
 1926                     [pthread_setname_np("name");],
 1927                     pthread_setname=darwin)
 1928         AC_MSG_RESULT([$pthread_setname])
 1929         case $with_threadnames-$pthread_setname in
 1930              yes-linux) AC_DEFINE(ETHR_HAVE_PTHREAD_SETNAME_NP_2, 1,
 1931                           [Define if you have linux style pthread_setname_np]);;
 1932              yes-bsd) AC_DEFINE(ETHR_HAVE_PTHREAD_SET_NAME_NP_2, 1,
 1933                           [Define if you have bsd style pthread_set_name_np]);;
 1934              yes-darwin) AC_DEFINE(ETHR_HAVE_PTHREAD_SETNAME_NP_1, 1,
 1935                           [Define if you have darwin style pthread_setname_np]);;
 1936              *) ;;
 1937 	esac
 1938 
 1939 	pthread_getname=no
 1940 	AC_MSG_CHECKING([for pthread_getname_np])
 1941 	AC_TRY_LINK([#define __USE_GNU
 1942                      #define _DARWIN_C_SOURCE
 1943                      #include <pthread.h>],
 1944                     [char buff[256]; pthread_getname_np(pthread_self(), buff, 256);],
 1945                     pthread_getname=linux)
 1946 	AC_TRY_LINK([#define __USE_GNU
 1947                      #define _DARWIN_C_SOURCE
 1948                      #include <pthread.h>],
 1949                     [char buff[256]; pthread_getname_np(pthread_self(), buff);],
 1950                     pthread_getname=ibm)
 1951         AC_MSG_RESULT([$pthread_getname])
 1952         case $pthread_getname in
 1953              linux) AC_DEFINE(ETHR_HAVE_PTHREAD_GETNAME_NP_3, 1,
 1954                           [Define if you have linux style pthread_getname_np]);;
 1955              ibm) AC_DEFINE(ETHR_HAVE_PTHREAD_GETNAME_NP_2, 1,
 1956                           [Define if you have ibm style pthread_getname_np]);;
 1957              *) ;;
 1958 	esac
 1959 	CFLAGS=$old_CFLAGS
 1960 
 1961 	if test "X$disable_native_ethr_impls" = "Xyes"; then
 1962 	    ethr_have_native_atomics=no
 1963 	else
 1964 
 1965 	    ETHR_CHK_GCC_ATOMIC_OPS([])
 1966 
 1967 	    AC_MSG_CHECKING([for a usable libatomic_ops implementation])
 1968 	    case "x$with_libatomic_ops" in
 1969 	        xno | xyes | x)
 1970 	    	    libatomic_ops_include=
 1971 	    	    ;;
 1972 	        *)
 1973 	    	    if test -d "${with_libatomic_ops}/include"; then
 1974 	    	        libatomic_ops_include="-I$with_libatomic_ops/include"
 1975 	    	        CPPFLAGS="$CPPFLAGS $libatomic_ops_include"
 1976 	    	    else
 1977 	    	        AC_MSG_ERROR([libatomic_ops include directory $with_libatomic_ops/include not found])
 1978 	    	    fi;;
 1979 	    esac
 1980 	    ethr_have_libatomic_ops=no
 1981 	    AC_TRY_LINK([#include "atomic_ops.h"],
 1982 	    	        [
 1983 	    	    	    volatile AO_t x;
 1984 	    	    	    AO_t y;
 1985 	    	    	    int z;
 1986 
 1987 	    	    	    AO_nop_full();
 1988 #if defined(AO_HAVE_store)
 1989 	    	    	    AO_store(&x, (AO_t) 0);
 1990 #elif defined(AO_HAVE_store_release)
 1991 	    	    	    AO_store_release(&x, (AO_t) 0);
 1992 #else
 1993 #error No store
 1994 #endif
 1995 #if defined(AO_HAVE_load)
 1996 	    	    	    z = AO_load(&x);
 1997 #elif defined(AO_HAVE_load_acquire)
 1998 	    	    	    z = AO_load_acquire(&x);
 1999 #else
 2000 #error No load
 2001 #endif
 2002 #if defined(AO_HAVE_compare_and_swap_full)
 2003 	    	    	    z = AO_compare_and_swap_full(&x, (AO_t) 0, (AO_t) 1);
 2004 #elif defined(AO_HAVE_compare_and_swap_release)
 2005 	    	    	    z = AO_compare_and_swap_release(&x, (AO_t) 0, (AO_t) 1);
 2006 #elif defined(AO_HAVE_compare_and_swap_acquire)
 2007 	    	    	    z = AO_compare_and_swap_acquire(&x, (AO_t) 0, (AO_t) 1);
 2008 #elif defined(AO_HAVE_compare_and_swap)
 2009 	    	    	    z = AO_compare_and_swap(&x, (AO_t) 0, (AO_t) 1);
 2010 #else
 2011 #error No compare_and_swap
 2012 #endif
 2013 	    	        ],
 2014 	    	        [ethr_have_native_atomics=yes
 2015 			 ethr_native_atomic_implementation=libatomic_ops
 2016 	    	         ethr_have_libatomic_ops=yes])
 2017 	    AC_MSG_RESULT([$ethr_have_libatomic_ops])
 2018 	    if test $ethr_have_libatomic_ops = yes; then
 2019 	        AC_CHECK_SIZEOF(AO_t, ,
 2020 	    	    	        [
 2021 	    	    	    	    #include <stdio.h>
 2022 	    	    	    	    #include "atomic_ops.h"
 2023 	    	    	        ])
 2024 	        AC_DEFINE_UNQUOTED(ETHR_SIZEOF_AO_T, $ac_cv_sizeof_AO_t, [Define to the size of AO_t if libatomic_ops is used])
 2025 
 2026 	        AC_DEFINE(ETHR_HAVE_LIBATOMIC_OPS, 1, [Define if you have libatomic_ops atomic operations])
 2027 	        if test "x$with_libatomic_ops" != "xno" && test "x$with_libatomic_ops" != "x"; then
 2028 	    	    AC_DEFINE(ETHR_PREFER_LIBATOMIC_OPS_NATIVE_IMPLS, 1, [Define if you prefer libatomic_ops native ethread implementations])
 2029 	        fi
 2030 	        ETHR_DEFS="$ETHR_DEFS $libatomic_ops_include"
 2031 	    elif test "x$with_libatomic_ops" != "xno" && test "x$with_libatomic_ops" != "x"; then
 2032 	        AC_MSG_ERROR([No usable libatomic_ops implementation found])
 2033 	    fi
 2034 
 2035 	    case "$host_cpu" in
 2036 	      sparc | sun4u | sparc64 | sun4v)
 2037 	    	    case "$with_sparc_memory_order" in
 2038 	    	        "TSO")
 2039 	    	    	    AC_DEFINE(ETHR_SPARC_TSO, 1, [Define if only run in Sparc TSO mode]);;
 2040 	    	        "PSO")
 2041 	    	    	    AC_DEFINE(ETHR_SPARC_PSO, 1, [Define if only run in Sparc PSO, or TSO mode]);;
 2042 	    	        "RMO"|"")
 2043 	    	    	    AC_DEFINE(ETHR_SPARC_RMO, 1, [Define if run in Sparc RMO, PSO, or TSO mode]);;
 2044 	    	        *)
 2045 	    	    	    AC_MSG_ERROR([Unsupported Sparc memory order: $with_sparc_memory_order]);;
 2046 	    	    esac
 2047 		    ethr_native_atomic_implementation=ethread
 2048 	    	    ethr_have_native_atomics=yes;; 
 2049 	      i86pc | i*86 | x86_64 | amd64)
 2050 	    	    if test "$enable_x86_out_of_order" = "yes"; then
 2051 	    	    	    AC_DEFINE(ETHR_X86_OUT_OF_ORDER, 1, [Define if x86/x86_64 out of order instructions should be synchronized])
 2052 	    	    fi
 2053 		    ethr_native_atomic_implementation=ethread
 2054 	    	    ethr_have_native_atomics=yes;;
 2055 	      macppc | ppc | powerpc | "Power Macintosh")
 2056 	      	    ethr_native_atomic_implementation=ethread
 2057 	    	    ethr_have_native_atomics=yes;;
 2058 	      tile)
 2059 	            ethr_native_atomic_implementation=ethread
 2060 	    	    ethr_have_native_atomics=yes;;
 2061 	      *)
 2062 	    	    ;;
 2063 	    esac
 2064 
 2065 	fi
 2066 
 2067 	test ethr_have_native_atomics = "yes" && ethr_have_native_spinlock=yes
 2068 
 2069 	dnl Restore LIBS
 2070 	LIBS=$saved_libs
 2071 	dnl restore CPPFLAGS
 2072 	CPPFLAGS=$saved_cppflags
 2073 
 2074 	;;
 2075     *)
 2076 	;;
 2077 esac
 2078 
 2079 AC_MSG_CHECKING([whether default stack size should be modified])
 2080 if test "x$ethr_modified_default_stack_size" != "x"; then
 2081 	AC_DEFINE_UNQUOTED(ETHR_MODIFIED_DEFAULT_STACK_SIZE, $ethr_modified_default_stack_size, [Define if you want to modify the default stack size])
 2082 	AC_MSG_RESULT([yes; to $ethr_modified_default_stack_size kilo words])
 2083 else
 2084 	AC_MSG_RESULT([no])
 2085 fi
 2086 
 2087 if test "x$ETHR_THR_LIB_BASE" != "x"; then
 2088 	ETHR_DEFS="-DUSE_THREADS $ETHR_DEFS"
 2089 	ETHR_LIBS="-l$ethr_lib_name -lerts_internal_r $ETHR_X_LIBS"
 2090 	ETHR_LIB_NAME=$ethr_lib_name
 2091 fi
 2092 
 2093 AC_CHECK_SIZEOF(void *)
 2094 AC_DEFINE_UNQUOTED(ETHR_SIZEOF_PTR, $ac_cv_sizeof_void_p, [Define to the size of pointers])
 2095 
 2096 AC_CHECK_SIZEOF(int)
 2097 AC_DEFINE_UNQUOTED(ETHR_SIZEOF_INT, $ac_cv_sizeof_int, [Define to the size of int])
 2098 AC_CHECK_SIZEOF(long)
 2099 AC_DEFINE_UNQUOTED(ETHR_SIZEOF_LONG, $ac_cv_sizeof_long, [Define to the size of long])
 2100 AC_CHECK_SIZEOF(long long)
 2101 AC_DEFINE_UNQUOTED(ETHR_SIZEOF_LONG_LONG, $ac_cv_sizeof_long_long, [Define to the size of long long])
 2102 AC_CHECK_SIZEOF(__int64)
 2103 AC_DEFINE_UNQUOTED(ETHR_SIZEOF___INT64, $ac_cv_sizeof___int64, [Define to the size of __int64])
 2104 AC_CHECK_SIZEOF(__int128_t)
 2105 AC_DEFINE_UNQUOTED(ETHR_SIZEOF___INT128_T, $ac_cv_sizeof___int128_t, [Define to the size of __int128_t])
 2106 
 2107 
 2108 case X$erl_xcomp_bigendian in
 2109     X) ;;
 2110     Xyes|Xno) ac_cv_c_bigendian=$erl_xcomp_bigendian;;
 2111     *) AC_MSG_ERROR([Bad erl_xcomp_bigendian value: $erl_xcomp_bigendian]);;
 2112 esac
 2113 
 2114 AC_C_BIGENDIAN
 2115 
 2116 if test "$ac_cv_c_bigendian" = "yes"; then
 2117     AC_DEFINE(ETHR_BIGENDIAN, 1, [Define if bigendian])
 2118 fi
 2119 
 2120 case X$erl_xcomp_double_middle_endian in
 2121     X) ;;
 2122     Xyes|Xno|Xunknown) ac_cv_c_double_middle_endian=$erl_xcomp_double_middle_endian;;
 2123     *) AC_MSG_ERROR([Bad erl_xcomp_double_middle_endian value: $erl_xcomp_double_middle_endian]);;
 2124 esac
 2125 
 2126 AC_C_DOUBLE_MIDDLE_ENDIAN
 2127 
 2128 ETHR_X86_SSE2_ASM=no
 2129 case "$GCC-$ac_cv_sizeof_void_p-$host_cpu" in
 2130   yes-4-i86pc | yes-4-i*86 | yes-4-x86_64 | yes-4-amd64)
 2131     AC_MSG_CHECKING([for gcc sse2 asm support])
 2132     save_CFLAGS="$CFLAGS"
 2133     CFLAGS="$CFLAGS -msse2"
 2134     gcc_sse2_asm=no
 2135     AC_TRY_COMPILE([],
 2136 	[
 2137 		long long x, *y;
 2138 		__asm__ __volatile__("movq %1, %0\n\t" : "=x"(x) : "m"(*y) : "memory");
 2139 	],
 2140 	[gcc_sse2_asm=yes])
 2141     CFLAGS="$save_CFLAGS"
 2142     AC_MSG_RESULT([$gcc_sse2_asm])
 2143     if test "$gcc_sse2_asm" = "yes"; then
 2144       AC_DEFINE(ETHR_GCC_HAVE_SSE2_ASM_SUPPORT, 1, [Define if you use a gcc that supports -msse2 and understand sse2 specific asm statements])
 2145       ETHR_X86_SSE2_ASM=yes
 2146     fi
 2147     ;;
 2148   *)
 2149     ;;
 2150 esac
 2151 
 2152 case "$GCC-$host_cpu" in
 2153   yes-i86pc | yes-i*86 | yes-x86_64 | yes-amd64)
 2154 
 2155     if test $ac_cv_sizeof_void_p = 4; then
 2156        dw_cmpxchg="cmpxchg8b"
 2157     else
 2158        dw_cmpxchg="cmpxchg16b"
 2159     fi
 2160 
 2161     gcc_dw_cmpxchg_asm=no
 2162     gcc_pic_dw_cmpxchg_asm=no
 2163     gcc_cflags_pic=no
 2164     gcc_cmpxchg8b_pic_no_clobber_ebx=no
 2165     gcc_cmpxchg8b_pic_no_clobber_ebx_register_shortage=no
 2166 
 2167     save_CFLAGS="$CFLAGS"
 2168 
 2169     # Check if it works out of the box using passed CFLAGS
 2170     # and with -fPIC added to CFLAGS if the passed CFLAGS
 2171     # doesn't trigger position independent code
 2172     pic_cmpxchg=unknown
 2173     while true; do
 2174 
 2175         case $pic_cmpxchg in
 2176 	  yes) pic_text="pic ";;
 2177 	  *) pic_text="";;
 2178 	esac
 2179 
 2180 	AC_MSG_CHECKING([for gcc $pic_text$dw_cmpxchg plain asm support])    
 2181 
 2182 	plain_cmpxchg=no
 2183     	AC_TRY_COMPILE([],
 2184 	[
 2185     char xchgd;
 2186     long new[2], xchg[2], *p;		  
 2187     __asm__ __volatile__(
 2188 #if ETHR_SIZEOF_PTR == 4
 2189 	"lock; cmpxchg8b %0\n\t"
 2190 #else
 2191 	"lock; cmpxchg16b %0\n\t"
 2192 #endif
 2193 	"setz %3\n\t"
 2194 	: "=m"(*p), "=d"(xchg[1]), "=a"(xchg[0]), "=q"(xchgd)
 2195 	: "m"(*p), "1"(xchg[1]), "2"(xchg[0]), "c"(new[1]), "b"(new[0])
 2196 	: "cc", "memory");
 2197 	],
 2198 	[plain_cmpxchg=yes])
 2199 
 2200 	AC_MSG_RESULT([$plain_cmpxchg])
 2201 
 2202 	if test $pic_cmpxchg = yes; then
 2203 	   gcc_pic_dw_cmpxchg_asm=$plain_cmpxchg
 2204 	   break
 2205 	fi
 2206 
 2207 	gcc_dw_cmpxchg_asm=$plain_cmpxchg
 2208 
 2209     	# If not already compiling to position independent
 2210 	# code add -fPIC to CFLAGS and do it again. This
 2211 	# since we want also want to know how to compile
 2212 	# to position independent code since this might
 2213 	# cause problems with the use of the EBX register
 2214 	# as input to the asm on 32-bit x86 and old gcc
 2215 	# compilers (gcc vsn < 5).
 2216 
 2217     	AC_TRY_COMPILE([],
 2218 	[
 2219 #if !defined(__PIC__) || !__PIC__
 2220 #  error no pic
 2221 #endif
 2222 	],
 2223 	[pic_cmpxchg=yes
 2224 	 gcc_cflags_pic=yes],
 2225 	[pic_cmpxchg=no])
 2226 
 2227 	if test $pic_cmpxchg = yes; then
 2228 	   gcc_pic_dw_cmpxchg_asm=$gcc_dw_cmpxchg_asm
 2229 	   break
 2230 	fi
 2231 
 2232 	CFLAGS="$save_CFLAGS -fPIC"
 2233 	pic_cmpxchg=yes
 2234 
 2235     done
 2236 
 2237     if test $gcc_pic_dw_cmpxchg_asm = no && test $ac_cv_sizeof_void_p = 4; then
 2238 
 2239       AC_MSG_CHECKING([for gcc pic cmpxchg8b asm support with EBX workaround])
 2240 
 2241       # Check if we can work around it by managing the ebx
 2242       # register explicitly in the asm...
 2243 
 2244       AC_TRY_COMPILE([],
 2245 	[
 2246     char xchgd;
 2247     long new[2], xchg[2], *p;		  
 2248     __asm__ __volatile__(
 2249 	"pushl %%ebx\n\t"
 2250 	"movl %8, %%ebx\n\t"
 2251 	"lock; cmpxchg8b %0\n\t"
 2252 	"setz %3\n\t"
 2253 	"popl %%ebx\n\t"
 2254 	: "=m"(*p), "=d"(xchg[1]), "=a"(xchg[0]), "=q"(xchgd)
 2255 	: "m"(*p), "1"(xchg[1]), "2"(xchg[0]), "c"(new[1]), "r"(new[0])
 2256 	: "cc", "memory");
 2257 	],
 2258 	[gcc_pic_dw_cmpxchg_asm=yes
 2259 	 gcc_cmpxchg8b_pic_no_clobber_ebx=yes])     
 2260 
 2261       AC_MSG_RESULT([$gcc_pic_dw_cmpxchg_asm])
 2262 
 2263       if test $gcc_pic_dw_cmpxchg_asm = no; then
 2264 
 2265       	AC_MSG_CHECKING([for gcc pic cmpxchg8b asm support with EBX and register shortage workarounds])
 2266         # If no optimization is enabled we sometimes get a
 2267 	# register shortage. Check if we can work around
 2268 	# this...
 2269 
 2270       	AC_TRY_COMPILE([],
 2271 	  [
 2272       char xchgd;
 2273       long new[2], xchg[2], *p;
 2274       __asm__ __volatile__(
 2275 	"pushl %%ebx\n\t"
 2276 	"movl (%7), %%ebx\n\t"
 2277 	"movl 4(%7), %%ecx\n\t"
 2278 	"lock; cmpxchg8b %0\n\t"
 2279 	"setz %3\n\t"
 2280 	"popl %%ebx\n\t"
 2281 	: "=m"(*p), "=d"(xchg[1]), "=a"(xchg[0]), "=c"(xchgd)
 2282 	: "m"(*p), "1"(xchg[1]), "2"(xchg[0]), "r"(new)
 2283 	: "cc", "memory");
 2284 
 2285 	],
 2286 	[gcc_pic_dw_cmpxchg_asm=yes
 2287 	 gcc_cmpxchg8b_pic_no_clobber_ebx=yes
 2288 	 gcc_cmpxchg8b_pic_no_clobber_ebx_register_shortage=yes])
 2289 
 2290         AC_MSG_RESULT([$gcc_pic_dw_cmpxchg_asm])
 2291       fi
 2292 
 2293       if test $gcc_cflags_pic = yes; then
 2294         gcc_dw_cmpxchg_asm=$gcc_pic_dw_cmpxchg_asm
 2295       fi
 2296  
 2297    fi
 2298 
 2299     CFLAGS="$save_CFLAGS"
 2300 
 2301     if test "$gcc_cmpxchg8b_pic_no_clobber_ebx" = "yes"; then
 2302       AC_DEFINE(ETHR_CMPXCHG8B_PIC_NO_CLOBBER_EBX, 1, [Define if gcc wont let you clobber ebx with cmpxchg8b and position independent code])
 2303     fi
 2304     if test "$gcc_cmpxchg8b_pic_no_clobber_ebx_register_shortage" = "yes"; then
 2305       AC_DEFINE(ETHR_CMPXCHG8B_REGISTER_SHORTAGE, 1, [Define if you get a register shortage with cmpxchg8b and position independent code])
 2306     fi
 2307     if test "$gcc_dw_cmpxchg_asm" = "yes"; then
 2308       AC_DEFINE(ETHR_GCC_HAVE_DW_CMPXCHG_ASM_SUPPORT, 1, [Define if you use a gcc that supports the double word cmpxchg instruction])
 2309     fi;;
 2310   *)
 2311     ;;
 2312 esac
 2313 
 2314 AC_DEFINE(ETHR_HAVE_ETHREAD_DEFINES, 1, \
 2315 [Define if you have all ethread defines])
 2316 
 2317 AC_SUBST(ETHR_X_LIBS)
 2318 AC_SUBST(ETHR_LIBS)
 2319 AC_SUBST(ETHR_LIB_NAME)
 2320 AC_SUBST(ETHR_DEFS)
 2321 AC_SUBST(ETHR_THR_LIB_BASE)
 2322 AC_SUBST(ETHR_THR_LIB_BASE_DIR)
 2323 AC_SUBST(ETHR_X86_SSE2_ASM)
 2324 
 2325 ])
 2326 
 2327 
 2328 dnl ----------------------------------------------------------------------
 2329 dnl
 2330 dnl ERL_TIME_CORRECTION
 2331 dnl
 2332 dnl Check for primitives that can be used for implementing
 2333 dnl erts_os_monotonic_time() and erts_os_system_time()
 2334 dnl
 2335 
 2336 AC_DEFUN(ERL_TIME_CORRECTION,
 2337 [
 2338 
 2339 AC_ARG_WITH(clock-resolution,
 2340 AS_HELP_STRING([--with-clock-resolution=high|low|default],
 2341                [specify wanted clock resolution]))
 2342 
 2343 AC_ARG_WITH(clock-gettime-realtime-id,
 2344 AS_HELP_STRING([--with-clock-gettime-realtime-id=CLOCKID],
 2345                [specify clock id to use with clock_gettime() for realtime time)]))
 2346 
 2347 AC_ARG_WITH(clock-gettime-monotonic-id,
 2348 AS_HELP_STRING([--with-clock-gettime-monotonic-id=CLOCKID],
 2349                [specify clock id to use with clock_gettime() for monotonic time)]))
 2350 
 2351 AC_ARG_ENABLE(prefer-elapsed-monotonic-time-during-suspend,
 2352 AS_HELP_STRING([--enable-prefer-elapsed-monotonic-time-during-suspend],
 2353                [Prefer an OS monotonic time source with elapsed time during suspend])
 2354 AS_HELP_STRING([--disable-prefer-elapsed-monotonic-time-during-suspend],
 2355                [Do not prefer an OS monotonic time source with elapsed time during suspend]),
 2356 [ case "$enableval" in
 2357     yes) prefer_elapsed_monotonic_time_during_suspend=yes ;;
 2358     *)  prefer_elapsed_monotonic_time_during_suspend=no ;;
 2359   esac ], prefer_elapsed_monotonic_time_during_suspend=no)
 2360 
 2361 AC_ARG_ENABLE(gettimeofday-as-os-system-time,
 2362 	      AS_HELP_STRING([--enable-gettimeofday-as-os-system-time],
 2363                              [Force usage of gettimeofday() for OS system time]),
 2364 [ case "$enableval" in
 2365     yes) force_gettimeofday_os_system_time=yes ;;
 2366     *)  force_gettimeofday_os_system_time=no ;;
 2367   esac ], force_gettimeofday_os_system_time=no)
 2368 
 2369 case "$with_clock_resolution" in
 2370    ""|no|yes)
 2371      with_clock_resolution=default;;
 2372    high|low|default)
 2373      ;;
 2374    *)
 2375      AC_MSG_ERROR([Invalid wanted clock resolution: $with_clock_resolution])
 2376      ;;
 2377 esac
 2378 
 2379 if test "$force_gettimeofday_os_system_time" = "yes"; then
 2380 
 2381   AC_CHECK_FUNCS([gettimeofday])
 2382   if test "$ac_cv_func_gettimeofday" = "yes"; then
 2383     AC_DEFINE(OS_SYSTEM_TIME_GETTIMEOFDAY,  [1], [Define if you want to implement erts_os_system_time() using gettimeofday()])
 2384   else
 2385     AC_MSG_ERROR([No gettimeofday() available])
 2386   fi
 2387 
 2388 else # $force_gettimeofday_os_system_time != yes
 2389 
 2390 case "$with_clock_gettime_realtime_id" in
 2391    ""|no)
 2392      with_clock_gettime_realtime_id=no
 2393      ;;
 2394    CLOCK_*CPUTIME*)
 2395      AC_MSG_ERROR([Invalid clock_gettime() realtime clock id: Refusing to use the cputime clock id $with_clock_gettime_realtime_id as realtime clock id])
 2396      ;;
 2397    CLOCK_MONOTONIC*|CLOCK_BOOTTIME*|CLOCK_UPTIME*|CLOCK_HIGHRES*)
 2398      AC_MSG_ERROR([Invalid clock_gettime() realtime clock id: Refusing to use the monotonic clock id $with_clock_gettime_realtime_id as realtime clock id])
 2399      ;;
 2400    CLOCK_*)
 2401      ;;
 2402    *)
 2403      AC_MSG_ERROR([Invalid clock_gettime() clock id: $with_clock_gettime_realtime_id])
 2404      ;;
 2405 esac
 2406 
 2407 case "$with_clock_resolution-$with_clock_gettime_realtime_id" in
 2408   high-no)
 2409 	ERL_WALL_CLOCK(high_resolution);;
 2410   low-no)
 2411 	ERL_WALL_CLOCK(low_resolution);;
 2412   default-no)
 2413 	ERL_WALL_CLOCK(default_resolution);;
 2414   *)
 2415 	ERL_WALL_CLOCK(custom_resolution, $with_clock_gettime_realtime_id);;
 2416 esac
 2417 
 2418 case "$erl_wall_clock_func-$erl_wall_clock_id-$with_clock_gettime_realtime_id" in
 2419   *-*-no)
 2420     ;;
 2421   clock_gettime-$with_clock_gettime_realtime_id-$with_clock_gettime_realtime_id)
 2422     ;;
 2423   *)
 2424     AC_MSG_ERROR([$with_clock_gettime_realtime_id as clock id to clock_gettime() doesn't compile])
 2425     ;;
 2426 esac
 2427 
 2428 case $erl_wall_clock_func in
 2429   none)
 2430     AC_MSG_ERROR([No wall clock source found])
 2431     ;;
 2432   mach_clock_get_time)
 2433     AC_DEFINE(OS_SYSTEM_TIME_USING_MACH_CLOCK_GET_TIME, [1], [Define if you want to implement erts_os_system_time() using mach clock_get_time()])
 2434     ;;
 2435   clock_gettime)
 2436     AC_DEFINE(OS_SYSTEM_TIME_USING_CLOCK_GETTIME, [1], [Define if you want to implement erts_os_system_time() using clock_gettime()])
 2437     ;;
 2438   gettimeofday)
 2439     AC_DEFINE(OS_SYSTEM_TIME_GETTIMEOFDAY,  [1], [Define if you want to implement erts_os_system_time() using gettimeofday()])
 2440     ;;
 2441   *)
 2442     ;;
 2443 esac
 2444 
 2445 if test "x$erl_wall_clock_id" != "x"; then
 2446     AC_DEFINE_UNQUOTED(WALL_CLOCK_ID_STR, ["$erl_wall_clock_id"], [Define as a string of wall clock id to use])
 2447     AC_DEFINE_UNQUOTED(WALL_CLOCK_ID, [$erl_wall_clock_id], [Define to wall clock id to use])
 2448 fi
 2449 
 2450 fi # $force_gettimeofday_os_system_time != yes
 2451 
 2452 case "$with_clock_gettime_monotonic_id" in
 2453    ""|no)
 2454      with_clock_gettime_monotonic_id=no
 2455      ;;
 2456    CLOCK_*CPUTIME*)
 2457      AC_MSG_ERROR([Invalid clock_gettime() monotonic clock id: Refusing to use the cputime clock id $with_clock_gettime_monotonic_id as monotonic clock id])
 2458      ;;
 2459    CLOCK_REALTIME*|CLOCK_TAI*)
 2460      AC_MSG_ERROR([Invalid clock_gettime() monotonic clock id: Refusing to use the realtime clock id $with_clock_gettime_monotonic_id as monotonic clock id])
 2461      ;;
 2462    CLOCK_*)
 2463      ;;
 2464    *)
 2465      AC_MSG_ERROR([Invalid clock_gettime() clock id: $with_clock_gettime_monotonic_id])
 2466      ;;
 2467 esac
 2468 
 2469 case "$with_clock_resolution-$with_clock_gettime_monotonic_id" in
 2470   high-no)
 2471 	ERL_MONOTONIC_CLOCK(high_resolution, undefined, $prefer_elapsed_monotonic_time_during_suspend);;
 2472   low-no)
 2473 	ERL_MONOTONIC_CLOCK(low_resolution, undefined, $prefer_elapsed_monotonic_time_during_suspend);;
 2474   default-no)
 2475 	ERL_MONOTONIC_CLOCK(default_resolution, undefined, $prefer_elapsed_monotonic_time_during_suspend);;
 2476   *)
 2477 	ERL_MONOTONIC_CLOCK(custom_resolution, $with_clock_gettime_monotonic_id, $prefer_elapsed_monotonic_time_during_suspend);;
 2478 esac
 2479 
 2480 case "$erl_monotonic_clock_func-$erl_monotonic_clock_id-$with_clock_gettime_monotonic_id" in
 2481   *-*-no)
 2482     ;;
 2483   clock_gettime-$with_clock_gettime_monotonic_id-$with_clock_gettime_monotonic_id)
 2484     ;;
 2485   *)
 2486     AC_MSG_ERROR([$with_clock_gettime_monotonic_id as clock id to clock_gettime() doesn't compile])
 2487     ;;
 2488 esac
 2489 
 2490 case $erl_monotonic_clock_func in
 2491   times)
 2492     AC_DEFINE(OS_MONOTONIC_TIME_USING_TIMES, [1], [Define if you want to implement erts_os_monotonic_time() using times()])
 2493     ;;
 2494   mach_clock_get_time)
 2495     AC_DEFINE(OS_MONOTONIC_TIME_USING_MACH_CLOCK_GET_TIME, [1], [Define if you want to implement erts_os_monotonic_time() using mach clock_get_time()])
 2496     ;;
 2497   clock_gettime)
 2498     AC_DEFINE(OS_MONOTONIC_TIME_USING_CLOCK_GETTIME, [1], [Define if you want to implement erts_os_monotonic_time() using clock_gettime()])
 2499     ;;
 2500   gethrtime)
 2501     AC_DEFINE(OS_MONOTONIC_TIME_USING_GETHRTIME,  [1], [Define if you want to implement erts_os_monotonic_time() using gethrtime()])
 2502     ;;
 2503   *)
 2504     ;;
 2505 esac
 2506 
 2507 if test $erl_corrected_monotonic_clock = yes; then
 2508   AC_DEFINE(ERTS_HAVE_CORRECTED_OS_MONOTONIC_TIME, [1], [Define if OS monotonic clock is corrected])
 2509 fi
 2510 
 2511 if test $erl_monotonic_clock_low_resolution = yes; then
 2512   AC_DEFINE(ERTS_HAVE_LOW_RESOLUTION_OS_MONOTONIC_LOW, [1], [Define if you have a low resolution OS monotonic clock])
 2513 fi
 2514 
 2515 xrtlib=
 2516 if test "$erl_monotonic_clock_lib" != ""; then
 2517    xrtlib="$erl_monotonic_clock_lib"
 2518 fi
 2519 if test "$erl_wall_clock_lib" != ""; then
 2520    xrtlib="$erl_wall_clock_lib"
 2521 fi
 2522 if test "x$erl_monotonic_clock_id" != "x"; then
 2523     AC_DEFINE_UNQUOTED(MONOTONIC_CLOCK_ID_STR, ["$erl_monotonic_clock_id"], [Define as a string of monotonic clock id to use])
 2524     AC_DEFINE_UNQUOTED(MONOTONIC_CLOCK_ID, [$erl_monotonic_clock_id], [Define to monotonic clock id to use])
 2525 fi
 2526 
 2527 if test $erl_cv_clock_gettime_monotonic_raw = yes; then
 2528   AC_DEFINE(HAVE_CLOCK_GETTIME_MONOTONIC_RAW, [1], [Define if you have clock_gettime(CLOCK_MONOTONIC_RAW, _)])
 2529 fi
 2530 
 2531 ERL_MONOTONIC_CLOCK(high_resolution, undefined, no)
 2532 
 2533 case $$erl_monotonic_clock_low_resolution-$erl_monotonic_clock_func in
 2534   no-mach_clock_get_time)
 2535     monotonic_hrtime=yes    
 2536     AC_DEFINE(SYS_HRTIME_USING_MACH_CLOCK_GET_TIME, [1], [Define if you want to implement erts_os_hrtime() using mach clock_get_time()])
 2537     ;;
 2538   no-clock_gettime)
 2539     monotonic_hrtime=yes
 2540     AC_DEFINE(SYS_HRTIME_USING_CLOCK_GETTIME, [1], [Define if you want to implement erts_os_hrtime() using clock_gettime()])
 2541     ;;
 2542   no-gethrtime)
 2543     monotonic_hrtime=yes
 2544     AC_DEFINE(SYS_HRTIME_USING_GETHRTIME,  [1], [Define if you want to implement erts_os_hrtime() using gethrtime()])
 2545     ;;
 2546   *)
 2547     monotonic_hrtime=no
 2548     ;;
 2549 esac
 2550 
 2551 if test $monotonic_hrtime = yes; then
 2552     AC_DEFINE(HAVE_MONOTONIC_ERTS_SYS_HRTIME, [1], [Define if you have a monotonic erts_os_hrtime() implementation])
 2553 fi
 2554 
 2555 if test "x$erl_monotonic_clock_id" != "x"; then
 2556     AC_DEFINE_UNQUOTED(HRTIME_CLOCK_ID_STR, ["$erl_monotonic_clock_id"], [Define as a string of monotonic clock id to use])
 2557     AC_DEFINE_UNQUOTED(HRTIME_CLOCK_ID, [$erl_monotonic_clock_id], [Define to monotonic clock id to use])
 2558 fi
 2559 
 2560 
 2561 dnl
 2562 dnl Check if gethrvtime is working, and if to use procfs ioctl
 2563 dnl or (yet to be written) write to the procfs ctl file.
 2564 dnl
 2565 
 2566 AC_MSG_CHECKING([if gethrvtime works and how to use it])
 2567 AC_TRY_RUN([
 2568 /* gethrvtime procfs ioctl test */
 2569 /* These need to be undef:ed to not break activation of
 2570  * micro level process accounting on /proc/self 
 2571  */
 2572 #ifdef _LARGEFILE_SOURCE
 2573 #  undef _LARGEFILE_SOURCE
 2574 #endif
 2575 #ifdef _FILE_OFFSET_BITS
 2576 #  undef _FILE_OFFSET_BITS
 2577 #endif
 2578 #include <stdlib.h>
 2579 #include <unistd.h>
 2580 #include <string.h>
 2581 #include <stdio.h>
 2582 #include <sys/time.h>
 2583 #include <sys/types.h>
 2584 #include <sys/stat.h>
 2585 #include <sys/signal.h>
 2586 #include <sys/fault.h>
 2587 #include <sys/syscall.h>
 2588 #include <sys/procfs.h>
 2589 #include <fcntl.h>
 2590 
 2591 int main() {
 2592     long msacct = PR_MSACCT;
 2593     int fd;
 2594     long long start, stop;
 2595     int i;
 2596     pid_t pid = getpid();
 2597     char proc_self[30] = "/proc/";
 2598 
 2599     sprintf(proc_self+strlen(proc_self), "%lu", (unsigned long) pid);
 2600     if ( (fd = open(proc_self, O_WRONLY)) == -1)
 2601 	exit(1);
 2602     if (ioctl(fd, PIOCSET, &msacct) < 0)
 2603 	exit(2);
 2604     if (close(fd) < 0)
 2605 	exit(3);
 2606     start = gethrvtime();
 2607     for (i = 0; i < 100; i++)
 2608 	stop = gethrvtime();
 2609     if (start == 0)
 2610 	exit(4);
 2611     if (start == stop)
 2612 	exit(5);
 2613     exit(0); return 0;
 2614 }
 2615 ],
 2616 erl_gethrvtime=procfs_ioctl,
 2617 erl_gethrvtime=false,
 2618 [
 2619 case X$erl_xcomp_gethrvtime_procfs_ioctl in
 2620     X)
 2621 	erl_gethrvtime=cross;;
 2622     Xyes|Xno)
 2623 	if test $erl_xcomp_gethrvtime_procfs_ioctl = yes; then
 2624 	    erl_gethrvtime=procfs_ioctl
 2625 	else
 2626 	    erl_gethrvtime=false
 2627 	fi;;
 2628     *)
 2629 	AC_MSG_ERROR([Bad erl_xcomp_gethrvtime_procfs_ioctl value: $erl_xcomp_gethrvtime_procfs_ioctl]);;
 2630 esac
 2631 ])
 2632 
 2633 LIBRT=$xrtlib
 2634 case $erl_gethrvtime in
 2635   procfs_ioctl)
 2636 	AC_DEFINE(HAVE_GETHRVTIME_PROCFS_IOCTL,[1],
 2637 		[define if gethrvtime() works and uses ioctl() to /proc/self])
 2638 	AC_MSG_RESULT(uses ioctl to procfs)
 2639 	;;
 2640   *)
 2641 	if test $erl_gethrvtime = cross; then
 2642 	    erl_gethrvtime=false
 2643 	    AC_MSG_RESULT(cross)
 2644 	    AC_MSG_WARN([result 'not working' guessed because of cross compilation])
 2645 	else
 2646 	    AC_MSG_RESULT(not working)
 2647 	fi
 2648 
 2649 	dnl
 2650 	dnl Check if clock_gettime (linux) is working
 2651 	dnl
 2652 
 2653 	AC_MSG_CHECKING([if clock_gettime can be used to get thread CPU time])
 2654 	save_libs=$LIBS
 2655 	LIBS="-lrt"
 2656 	AC_TRY_RUN([
 2657 	#include <stdlib.h>
 2658 	#include <unistd.h>
 2659 	#include <string.h>
 2660 	#include <stdio.h>
 2661 	#include <time.h>
 2662 	int main() {
 2663 	    long long start, stop;
 2664 	    int i;
 2665 	    struct timespec tp;
 2666 
 2667 	    if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp) < 0)
 2668 	      exit(1);
 2669 	    start = ((long long)tp.tv_sec * 1000000000LL) + (long long)tp.tv_nsec;
 2670 	    for (i = 0; i < 100; i++)
 2671 	      clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp);
 2672 	    stop = ((long long)tp.tv_sec * 1000000000LL) + (long long)tp.tv_nsec;
 2673 	    if (start == 0)
 2674 	      exit(4);
 2675 	    if (start == stop)
 2676 	      exit(5);
 2677 	    exit(0); return 0;
 2678 	  }
 2679 	],
 2680 	erl_clock_gettime_cpu_time=yes,
 2681 	erl_clock_gettime_cpu_time=no,
 2682 	[
 2683 	case X$erl_xcomp_clock_gettime_cpu_time in
 2684 	    X) erl_clock_gettime_cpu_time=cross;;
 2685 	    Xyes|Xno) erl_clock_gettime_cpu_time=$erl_xcomp_clock_gettime_cpu_time;;
 2686 	    *) AC_MSG_ERROR([Bad erl_xcomp_clock_gettime_cpu_time value: $erl_xcomp_clock_gettime_cpu_time]);;
 2687 	esac
 2688 	])
 2689 	LIBS=$save_libs
 2690 	AC_MSG_RESULT($erl_clock_gettime_cpu_time)
 2691 	case $erl_clock_gettime_cpu_time in
 2692 		yes)
 2693 			AC_DEFINE(HAVE_CLOCK_GETTIME_CPU_TIME,[],
 2694 				  [define if clock_gettime() works for getting thread time])
 2695 			LIBRT=-lrt
 2696 			;;
 2697 		cross)
 2698 			erl_clock_gettime_cpu_time=no
 2699 			AC_MSG_WARN([result no guessed because of cross compilation])
 2700 			;;
 2701 		*)
 2702 			;;
 2703 	esac
 2704 	;;
 2705 esac
 2706 AC_SUBST(LIBRT)
 2707 ])dnl
 2708 
 2709 dnl ----------------------------------------------------------------------
 2710 dnl
 2711 dnl LM_TRY_ENABLE_CFLAG
 2712 dnl
 2713 dnl
 2714 dnl Tries a CFLAG and sees if it can be enabled without compiler errors
 2715 dnl $1: textual cflag to add
 2716 dnl $2: variable to store the modified CFLAG in
 2717 dnl Usage example LM_TRY_ENABLE_CFLAG([-Werror=return-type], [CFLAGS])
 2718 dnl
 2719 dnl
 2720 AC_DEFUN([LM_TRY_ENABLE_CFLAG], [
 2721     AC_MSG_CHECKING([if we can add $1 to $2 (via CFLAGS)])
 2722     saved_CFLAGS=$CFLAGS;
 2723     CFLAGS="$1 $$2";
 2724     AC_TRY_COMPILE([],[return 0;],can_enable_flag=true,can_enable_flag=false)
 2725     CFLAGS=$saved_CFLAGS;
 2726     if test "X$can_enable_flag" = "Xtrue"; then
 2727         AC_MSG_RESULT([yes])
 2728         AS_VAR_SET($2, "$1 $$2")
 2729     else
 2730         AC_MSG_RESULT([no])
 2731     fi
 2732 ])
 2733 
 2734 AC_DEFUN([LM_CHECK_ENABLE_CFLAG], [
 2735     AC_MSG_CHECKING([whether $CC accepts $1...])
 2736     saved_CFLAGS=$CFLAGS;
 2737     CFLAGS="$1 $CFLAGS";
 2738     AC_TRY_COMPILE([],[return 0;],can_enable_flag=true,can_enable_flag=false)
 2739     CFLAGS=$saved_CFLAGS;
 2740     if test "X$can_enable_flag" = "Xtrue"; then
 2741         AS_VAR_SET($2, true)
 2742         AC_MSG_RESULT([yes])
 2743     else
 2744         AS_VAR_SET($2, false)
 2745         AC_MSG_RESULT([no])
 2746     fi
 2747 ])
 2748 
 2749 dnl ERL_TRY_LINK_JAVA(CLASSES, FUNCTION-BODY
 2750 dnl                   [ACTION_IF_FOUND [, ACTION-IF-NOT-FOUND]])
 2751 dnl Freely inspired by AC_TRY_LINK. (Maybe better to create a 
 2752 dnl AC_LANG_JAVA instead...)
 2753 AC_DEFUN(ERL_TRY_LINK_JAVA,
 2754 [java_link='$JAVAC conftest.java 1>&AC_FD_CC'
 2755 changequote(, )dnl
 2756 cat > conftest.java <<EOF
 2757 $1
 2758 class conftest { public static void main(String[] args) {
 2759    $2
 2760    ; return; }}
 2761 EOF
 2762 changequote([, ])dnl
 2763 if AC_TRY_EVAL(java_link) && test -s conftest.class; then
 2764    ifelse([$3], , :, [rm -rf conftest*
 2765    $3])
 2766 else
 2767    echo "configure: failed program was:" 1>&AC_FD_CC
 2768    cat conftest.java 1>&AC_FD_CC
 2769    echo "configure: PATH was $PATH" 1>&AC_FD_CC
 2770 ifelse([$4], , , [  rm -rf conftest*
 2771   $4
 2772 ])dnl
 2773 fi
 2774 rm -f conftest*])
 2775 #define UNSAFE_MASK  0xc0000000 /* Mask for bits that must be constant */
 2776 
 2777 
 2778 dnl ----------------------------------------------------------------------
 2779 dnl
 2780 dnl LM_HARDWARE_ARCH
 2781 dnl
 2782 dnl Determine target hardware in ARCH
 2783 dnl
 2784 AC_DEFUN([LM_HARDWARE_ARCH], [
 2785     AC_MSG_CHECKING([target hardware architecture])
 2786     if test "x$host_alias" != "x" -a "x$host_cpu" != "x"; then
 2787         chk_arch_=$host_cpu
 2788     else
 2789         chk_arch_=`uname -m`
 2790     fi
 2791 
 2792     case $chk_arch_ in
 2793     sun4u)	ARCH=ultrasparc;;
 2794     sparc64)	ARCH=sparc64;;
 2795     sun4v)	ARCH=ultrasparc;;
 2796     i86pc)	ARCH=x86;;
 2797     i386)	ARCH=x86;;
 2798     i486)	ARCH=x86;;
 2799     i586)	ARCH=x86;;
 2800     i686)	ARCH=x86;;
 2801     x86_64)	ARCH=amd64;;
 2802     amd64)	ARCH=amd64;;
 2803     macppc)	ARCH=ppc;;
 2804     powerpc)	ARCH=ppc;;
 2805     ppc)	ARCH=ppc;;
 2806     ppc64)	ARCH=ppc64;;
 2807     ppc64le)	ARCH=ppc64le;;
 2808     "Power Macintosh")	ARCH=ppc;;
 2809     armv5b)	ARCH=arm;;
 2810     armv5teb)	ARCH=arm;;
 2811     armv5tel)	ARCH=arm;;
 2812     armv5tejl)	ARCH=arm;;
 2813     armv6l)	ARCH=arm;;
 2814     armv6hl)	ARCH=arm;;
 2815     armv7l)	ARCH=arm;;
 2816     armv7hl)	ARCH=arm;;
 2817     tile)	ARCH=tile;;
 2818     e2k)        ARCH=e2k;;
 2819     *)	 	ARCH=noarch;;
 2820     esac
 2821     AC_MSG_RESULT($ARCH)
 2822 
 2823     dnl
 2824     dnl Convert between x86 and amd64 based on the compiler's mode.
 2825     dnl Ditto between ultrasparc and sparc64.
 2826     dnl
 2827     AC_MSG_CHECKING(whether compilation mode forces ARCH adjustment)
 2828     case "$ARCH-$ac_cv_sizeof_void_p" in
 2829     x86-8)
 2830 	AC_MSG_RESULT(yes: adjusting ARCH=x86 to ARCH=amd64)
 2831 	ARCH=amd64
 2832 	;;
 2833     amd64-4)
 2834 	AC_MSG_RESULT(yes: adjusting ARCH=amd64 to ARCH=x86)
 2835 	ARCH=x86
 2836 	;;
 2837     ultrasparc-8)
 2838 	AC_MSG_RESULT(yes: adjusting ARCH=ultrasparc to ARCH=sparc64)
 2839 	ARCH=sparc64
 2840 	;;
 2841     sparc64-4)
 2842 	AC_MSG_RESULT(yes: adjusting ARCH=sparc64 to ARCH=ultrasparc)
 2843 	ARCH=ultrasparc
 2844 	;;
 2845     ppc64-4)
 2846 	AC_MSG_RESULT(yes: adjusting ARCH=ppc64 to ARCH=ppc)
 2847 	ARCH=ppc
 2848 	;;
 2849     ppc-8)
 2850 	AC_MSG_RESULT(yes: adjusting ARCH=ppc to ARCH=ppc64)
 2851 	ARCH=ppc64
 2852 	;;
 2853     arm-8)
 2854 	AC_MSG_RESULT(yes: adjusting ARCH=arm to ARCH=noarch)
 2855 	ARCH=noarch
 2856 	;;
 2857     *)
 2858 	AC_MSG_RESULT(no: ARCH is $ARCH)
 2859 	;;
 2860     esac
 2861 
 2862     AC_SUBST(ARCH)
 2863 ])
 2864 
 2865 dnl
 2866 dnl--------------------------------------------------------------------
 2867 dnl Dynamic Erlang Drivers
 2868 dnl
 2869 dnl Linking to produce dynamic Erlang drivers to be loaded by Erlang's
 2870 dnl Dynamic Driver Loader and Linker (DDLL). Below the prefix DED is an
 2871 dnl abbreviation for `Dynamic Erlang Driver'.
 2872 dnl
 2873 dnl For DED we need something quite sloppy, which allows undefined references 
 2874 dnl (notably driver functions) in the resulting shared library. 
 2875 dnl Example of Makefile rule (and settings of macros):
 2876 dnl
 2877 dnl LIBS = @LIBS@
 2878 dnl LD = @DED_LD@
 2879 dnl LDFLAGS = @DED_LDFLAGS@
 2880 dnl soname = @ldsoname@
 2881 dnl
 2882 dnl my_drv.so:   my_drv.o my_utils.o
 2883 dnl              $(LD) $(LDFLAGS) $(soname) $@ -o $@ $^ -lc $(LIBS)
 2884 dnl
 2885 dnl--------------------------------------------------------------------
 2886 dnl
 2887 
 2888 AC_DEFUN(ERL_DED,
 2889 	[
 2890 
 2891 USER_LD=$LD
 2892 USER_LDFLAGS="$LDFLAGS"
 2893 
 2894 LM_CHECK_THR_LIB
 2895 
 2896 DED_CC=$CC
 2897 DED_GCC=$GCC
 2898 
 2899 DED_CFLAGS=
 2900 DED_OSTYPE=unix
 2901 case $host_os in
 2902      linux*)
 2903 	DED_CFLAGS="-D_GNU_SOURCE" ;;
 2904      win32)
 2905 	DED_CFLAGS="-D_WIN32_WINNT=0x0600 -DWINVER=0x0600"
 2906         DED_OSTYPE=win32 ;;
 2907      *)
 2908         ;;
 2909 esac
 2910 
 2911 
 2912 DED_WARN_FLAGS="-Wall -Wstrict-prototypes"
 2913 case "$host_cpu" in
 2914   tile*)
 2915     # tile-gcc is a bit stricter with -Wmissing-prototypes than other gccs,
 2916     # and too strict for our taste.
 2917     ;;
 2918   *)
 2919     DED_WARN_FLAGS="$DED_WARN_FLAGS -Wmissing-prototypes";;
 2920 esac
 2921   
 2922 LM_TRY_ENABLE_CFLAG([-Wdeclaration-after-statement], [DED_WARN_FLAGS])
 2923 
 2924 LM_TRY_ENABLE_CFLAG([-Werror=return-type], [DED_WERRORFLAGS])
 2925 LM_TRY_ENABLE_CFLAG([-Werror=implicit], [DED_WERRORFLAGS])
 2926 LM_TRY_ENABLE_CFLAG([-Werror=undef], [DED_WERRORFLAGS])
 2927 
 2928 DED_SYS_INCLUDE="-I${ERL_TOP}/erts/emulator/beam -I${ERL_TOP}/erts/include -I${ERL_TOP}/erts/include/$host -I${ERL_TOP}/erts/include/internal -I${ERL_TOP}/erts/include/internal/$host -I${ERL_TOP}/erts/emulator/sys/$DED_OSTYPE -I${ERL_TOP}/erts/emulator/sys/common"
 2929 DED_INCLUDE=$DED_SYS_INCLUDE
 2930 
 2931 if test "$THR_DEFS" = ""; then
 2932     DED_THR_DEFS="-D_THREAD_SAFE -D_REENTRANT"
 2933 else
 2934     DED_THR_DEFS="$THR_DEFS"
 2935 fi
 2936 # DED_EMU_THR_DEFS=$EMU_THR_DEFS
 2937 DED_CFLAGS="$CFLAGS $CPPFLAGS $DED_CFLAGS"
 2938 if test "x$GCC" = xyes; then
 2939     DED_STATIC_CFLAGS="$DED_CFLAGS"
 2940     DED_CFLAGS="$DED_CFLAGS -fPIC"
 2941 fi
 2942 
 2943 DED_EXT=so
 2944 case $host_os in
 2945     win32) DED_EXT=dll;;
 2946     darwin*)
 2947 	DED_CFLAGS="$DED_CFLAGS -fno-common"
 2948 	DED_STATIC_CFLAGS="$DED_STATIC_CFLAGS -fno-common";;
 2949     *)
 2950 	;;
 2951 esac
 2952 
 2953 DED_STATIC_CFLAGS="$DED_STATIC_CFLAGS -DSTATIC_ERLANG_NIF -DSTATIC_ERLANG_DRIVER"
 2954 
 2955 if test "$CFLAG_RUNTIME_LIBRARY_PATH" = ""; then
 2956 
 2957   CFLAG_RUNTIME_LIBRARY_PATH="-Wl,-R"
 2958   case $host_os in
 2959     darwin*)
 2960 	CFLAG_RUNTIME_LIBRARY_PATH=
 2961 	;;
 2962     win32)
 2963 	CFLAG_RUNTIME_LIBRARY_PATH=
 2964 	;;
 2965     osf*)
 2966 	CFLAG_RUNTIME_LIBRARY_PATH="-Wl,-rpath,"
 2967 	;;
 2968     *)
 2969 	;;
 2970   esac
 2971 
 2972 fi
 2973 
 2974 # If DED_LD is set in environment, we expect all DED_LD* variables
 2975 # to be specified (cross compiling)
 2976 if test "x$DED_LD" = "x"; then
 2977 
 2978 DED_LD_FLAG_RUNTIME_LIBRARY_PATH="-R"
 2979 case $host_os in
 2980 	win32)
 2981 		DED_LD="ld.sh"
 2982 		DED_LDFLAGS="-dll"
 2983 		DED_LD_FLAG_RUNTIME_LIBRARY_PATH=
 2984 	;;
 2985 	solaris2*|sysv4*)
 2986 		DED_LDFLAGS="-G"
 2987 		if test X${enable_m64_build} = Xyes; then
 2988 			DED_LDFLAGS="-64 $DED_LDFLAGS"
 2989 		fi
 2990 	;;
 2991 	aix4*)
 2992 		DED_LDFLAGS="-G -bnoentry -bexpall"
 2993 	;;
 2994 	freebsd2*)
 2995 		# Non-ELF GNU linker
 2996 		DED_LDFLAGS="-Bshareable"
 2997 	;;
 2998 	darwin*)
 2999 		# Mach-O linker: a shared lib and a loadable
 3000 		# object file is not the same thing.
 3001 		DED_LDFLAGS="-bundle -bundle_loader ${ERL_TOP}/bin/$host/beam.smp"
 3002 		if test X${enable_m64_build} = Xyes; then
 3003 		  DED_LDFLAGS="-m64 $DED_LDFLAGS"
 3004 		else
 3005 		  if test X${enable_m32_build} = Xyes; then
 3006 		    DED_LDFLAGS="-m32 $DED_LDFLAGS"
 3007 		  else
 3008 		    AC_CHECK_SIZEOF(void *)
 3009 		    case "$ac_cv_sizeof_void_p" in
 3010 		      8)
 3011 			DED_LDFLAGS="-m64 $DED_LDFLAGS";;
 3012 		      *)
 3013 		        ;;
 3014 		    esac
 3015 		  fi
 3016 		fi
 3017 		DED_LD="$CC"
 3018 		DED_LD_FLAG_RUNTIME_LIBRARY_PATH="$CFLAG_RUNTIME_LIBRARY_PATH"
 3019 	;;
 3020 	linux*)
 3021 		DED_LD="$CC"
 3022 		DED_LD_FLAG_RUNTIME_LIBRARY_PATH="$CFLAG_RUNTIME_LIBRARY_PATH"
 3023 		DED_LDFLAGS="-shared -Wl,-Bsymbolic"
 3024 		if test X${enable_m64_build} = Xyes; then
 3025 			DED_LDFLAGS="-m64 $DED_LDFLAGS"
 3026 		fi;
 3027 		if test X${enable_m32_build} = Xyes; then
 3028 			DED_LDFLAGS="-m32 $DED_LDFLAGS"
 3029 		fi
 3030 	;;	
 3031 	freebsd*)
 3032 		DED_LD="$CC"
 3033 		DED_LD_FLAG_RUNTIME_LIBRARY_PATH="$CFLAG_RUNTIME_LIBRARY_PATH"
 3034 		DED_LDFLAGS="-shared"
 3035 		if test X${enable_m64_build} = Xyes; then
 3036 			DED_LDFLAGS="-m64 $DED_LDFLAGS"
 3037 		fi;
 3038 		if test X${enable_m32_build} = Xyes; then
 3039 			DED_LDFLAGS="-m32 $DED_LDFLAGS"
 3040 		fi
 3041 	;;	
 3042 	openbsd*)
 3043 		DED_LD="$CC"
 3044 		DED_LD_FLAG_RUNTIME_LIBRARY_PATH="$CFLAG_RUNTIME_LIBRARY_PATH"
 3045 		DED_LDFLAGS="-shared"
 3046 	;;
 3047 	osf*)
 3048 		# NOTE! Whitespace after -rpath is important.
 3049 		DED_LD_FLAG_RUNTIME_LIBRARY_PATH="-rpath "
 3050 		DED_LDFLAGS="-shared -expect_unresolved '*'"
 3051 	;;
 3052 	*)
 3053 		# assume GNU linker and ELF
 3054 		DED_LDFLAGS="-shared"
 3055 		# GNU linker has no option for 64bit build, should not propagate -m64
 3056 	;;
 3057 esac
 3058 
 3059 if test "$DED_LD" = "" && test "$USER_LD" != ""; then
 3060     DED_LD="$USER_LD"
 3061     DED_LDFLAGS="$USER_LDFLAGS $DED_LDFLAGS"
 3062 fi
 3063 
 3064 DED_LIBS=$LIBS
 3065 
 3066 fi # "x$DED_LD" = "x"
 3067 
 3068 AC_CHECK_TOOL(DED_LD, ld, false)
 3069 test "$DED_LD" != "false" || AC_MSG_ERROR([No linker found])
 3070 
 3071 AC_MSG_CHECKING(for static compiler flags)
 3072 DED_STATIC_CFLAGS="$DED_WERRORFLAGS $DED_WFLAGS $DED_THR_DEFS $DED_STATIC_CFLAGS"
 3073 AC_MSG_RESULT([$DED_STATIC_CFLAGS])
 3074 AC_MSG_CHECKING(for basic compiler flags for loadable drivers)
 3075 DED_BASIC_CFLAGS=$DED_CFLAGS
 3076 AC_MSG_RESULT([$DED_CFLAGS])
 3077 AC_MSG_CHECKING(for compiler flags for loadable drivers)
 3078 DED_CFLAGS="$DED_WERRORFLAGS $DED_WARN_FLAGS $DED_THR_DEFS $DED_CFLAGS"
 3079 AC_MSG_RESULT([$DED_CFLAGS])
 3080 AC_MSG_CHECKING(for linker for loadable drivers)
 3081 AC_MSG_RESULT([$DED_LD])
 3082 AC_MSG_CHECKING(for linker flags for loadable drivers)
 3083 AC_MSG_RESULT([$DED_LDFLAGS])
 3084 AC_MSG_CHECKING(for 'runtime library path' linker flag)
 3085 if test "x$DED_LD_FLAG_RUNTIME_LIBRARY_PATH" != "x"; then
 3086 	AC_MSG_RESULT([$DED_LD_FLAG_RUNTIME_LIBRARY_PATH])
 3087 else
 3088 	AC_MSG_RESULT([not found])
 3089 fi
 3090 
 3091 AC_SUBST(DED_CC)
 3092 AC_SUBST(DED_GCC)
 3093 AC_SUBST(DED_EXT)
 3094 AC_SUBST(DED_SYS_INCLUDE)
 3095 AC_SUBST(DED_INCLUDE)
 3096 AC_SUBST(DED_BASIC_CFLAGS)
 3097 AC_SUBST(DED_CFLAGS)
 3098 AC_SUBST(DED_STATIC_CFLAGS)
 3099 AC_SUBST(DED_WARN_FLAGS)
 3100 AC_SUBST(DED_WERRORFLAGS)
 3101 AC_SUBST(DED_LD)
 3102 AC_SUBST(DED_LDFLAGS)
 3103 AC_SUBST(DED_LD_FLAG_RUNTIME_LIBRARY_PATH)
 3104 AC_SUBST(DED_LIBS)
 3105 AC_SUBST(DED_THR_DEFS)
 3106 AC_SUBST(DED_OSTYPE)
 3107 
 3108 ])