1dnl Process this file with autoconf to produce a configure script. -*-m4-*-
2
3dnl %CopyrightBegin%
4dnl
5dnl Copyright Ericsson AB 1997-2020. All Rights Reserved.
6dnl
7dnl Licensed under the Apache License, Version 2.0 (the "License");
8dnl you may not use this file except in compliance with the License.
9dnl You may obtain a copy of the License at
10dnl
11dnl     http://www.apache.org/licenses/LICENSE-2.0
12dnl
13dnl Unless required by applicable law or agreed to in writing, software
14dnl distributed under the License is distributed on an "AS IS" BASIS,
15dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16dnl See the License for the specific language governing permissions and
17dnl limitations under the License.
18dnl
19dnl %CopyrightEnd%
20
21dnl The string "FIXME convbreak" means that there is a break of
22dnl autoconf convention that should be cleaned up.
23
24AC_INIT(vsn.mk)
25AC_PREREQ(2.59)
26
27LM_PRECIOUS_VARS
28
29dnl How to set srcdir absolute is taken from the GNU Emacs distribution
30#### Make srcdir absolute, if it isn't already.  It's important to
31#### avoid running the path through pwd unnecessary, since pwd can
32#### give you automounter prefixes, which can go away.
33case "${srcdir}" in
34  /* ) ;;
35  . )
36    ## We may be able to use the $PWD environment variable to make this
37    ## absolute.  But sometimes PWD is inaccurate.
38    ## Make sure CDPATH doesn't affect cd (in case PWD is relative).
39    CDPATH=
40    if test "${PWD}" != "" && test "`(cd ${PWD} ; sh -c pwd)`" = "`pwd`"  ;
41    then
42      srcdir="$PWD"
43    else
44      srcdir="`(cd ${srcdir}; pwd)`"
45    fi
46  ;;
47  *  ) srcdir="`(cd ${srcdir}; pwd)`" ;;
48esac
49
50## Now, make sure that ERL_TOP is set and is the same as srcdir
51##
52if test -z "$ERL_TOP" || test ! -d $ERL_TOP ; then
53  AC_MSG_ERROR(You need to set the environment variable ERL_TOP!)
54fi
55if test x"${ERL_TOP}/erts" != x"$srcdir"; then
56  AC_MSG_ERROR([You need to run configure with argument --srcdir=${ERL_TOP}/erts])
57fi
58erl_top=${ERL_TOP}
59
60# echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
61# echo X
62# echo "X srcdir  = $srcdir"
63# echo "X ERL_TOP = $ERL_TOP"
64# echo X
65# echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
66
67AC_CONFIG_AUX_DIRS($srcdir/autoconf)
68
69dnl ----------------------------------------------------------------------
70dnl Figure out what system we are running on.
71dnl ----------------------------------------------------------------------
72
73#
74# To configure for free source run ./configure --host=free_source
75#
76dnl
77dnl AC_CANONICAL_HOST does not like free_source as a host specification,
78dnl so we make a little special case.
79dnl
80if test "X$host" != "Xfree_source" -a "X$host" != "Xwin32"; then
81    AC_CANONICAL_HOST
82else
83    host_os=$host
84fi
85
86if test "$cross_compiling" = "yes"; then
87    CROSS_COMPILING=yes
88else
89    CROSS_COMPILING=no
90fi
91AC_SUBST(CROSS_COMPILING)
92
93ERL_XCOMP_SYSROOT_INIT
94
95AC_ISC_POSIX
96
97AC_CONFIG_HEADER($host/config.h:config.h.in include/internal/$host/ethread_header_config.h:include/internal/ethread_header_config.h.in include/$host/erl_int_sizes_config.h:include/erl_int_sizes_config.h.in)
98dnl ----------------------------------------------------------------------
99dnl Optional features.
100dnl ----------------------------------------------------------------------
101ENABLE_ALLOC_TYPE_VARS=
102AC_SUBST(ENABLE_ALLOC_TYPE_VARS)
103
104AC_ARG_ENABLE(bootstrap-only,
105AS_HELP_STRING([--enable-bootstrap-only],
106               [enable bootstrap only configuration]),
107[ if test "X$enableval" = "Xyes"; then
108	# Disable stuff not necessary in a bootstrap only system in order
109	# to speed up things by reducing the amount of stuff needing to be
110	# built...
111	with_termcap=no
112	with_ssl=no
113	with_ssl_zlib=no
114	enable_hipe=no
115	enable_sctp=no
116  fi
117])
118
119AC_ARG_ENABLE(dirty-schedulers-test,
120AS_HELP_STRING([--enable-dirty-schedulers-test], [enable dirty scheduler test (for debugging purposes)]),
121[ case "$enableval" in
122    yes)  enable_dirty_schedulers_test=yes ;;
123    *) enable_dirty_schedulers_test=no ;;
124  esac ], enable_dirty_schedulers_test=no)
125
126AC_ARG_ENABLE(smp-require-native-atomics,
127	      AS_HELP_STRING([--disable-smp-require-native-atomics],
128                             [disable the SMP requirement of a native atomic implementation]),
129[ case "$enableval" in
130    no) smp_require_native_atomics=no ;;
131    *)  smp_require_native_atomics=yes ;;
132  esac ], smp_require_native_atomics=yes)
133
134AC_ARG_WITH(termcap,
135AS_HELP_STRING([--with-termcap], [use termcap (default)])
136AS_HELP_STRING([--without-termcap],
137               [do not use any termcap libraries (ncurses,curses,termcap,termlib)]),
138[],
139[with_termcap=yes])
140
141AC_ARG_ENABLE(lock-checking,
142AS_HELP_STRING([--enable-lock-checking], [enable lock checking]),
143[ case "$enableval" in
144    no) enable_lock_check=no ;;
145    *)  enable_lock_check=yes ;;
146  esac
147],
148  enable_lock_check=no)
149
150AC_ARG_ENABLE(lock-counter,
151AS_HELP_STRING([--enable-lock-counter], [enable lock counters]),
152[ case "$enableval" in
153    no) enable_lock_count=no ;;
154    *)  enable_lock_count=yes ;;
155  esac ], enable_lock_count=no)
156
157AC_ARG_ENABLE(kernel-poll,
158AS_HELP_STRING([--enable-kernel-poll], [enable kernel poll support])
159AS_HELP_STRING([--disable-kernel-poll], [disable kernel poll support]),
160[ case "$enableval" in
161    no) enable_kernel_poll=no ;;
162    *)  enable_kernel_poll=yes ;;
163  esac ], enable_kernel_poll=unknown)
164
165
166AC_ARG_ENABLE(sctp,
167AS_HELP_STRING([--enable-sctp], [enable sctp support (default)
168to on demand load the SCTP library in runtime if needed])
169AS_HELP_STRING([--enable-sctp=lib], [enable sctp support
170to link against the SCTP library])
171AS_HELP_STRING([--disable-sctp], [disable sctp support]),
172[ case "x$enableval" in
173      xno|xyes|xlib|x)
174          ;;
175      x*)
176          AC_MSG_ERROR("invalid value --enable-sctp=$enableval")
177          ;;
178  esac ])
179
180AC_ARG_ENABLE(hipe,
181AS_HELP_STRING([--enable-hipe], [enable hipe support])
182AS_HELP_STRING([--disable-hipe], [disable hipe support]))
183
184AC_ARG_ENABLE(native-libs,
185AS_HELP_STRING([--enable-native-libs],
186               [compile Erlang libraries to native code]))
187
188AC_ARG_ENABLE(fp-exceptions,
189AS_HELP_STRING([--enable-fp-exceptions],
190               [use hardware floating point exceptions (default if hipe enabled)]),
191[ case "$enableval" in
192    no) enable_fp_exceptions=no ;;
193    *)  enable_fp_exceptions=yes ;;
194  esac
195],enable_fp_exceptions=auto)
196
197AC_ARG_ENABLE(m64-build,
198AS_HELP_STRING([--enable-m64-build],
199               [build 64bit binaries using the -m64 flag to (g)cc]),
200[ case "$enableval" in
201    no) enable_m64_build=no ;;
202    *)  enable_m64_build=yes ;;
203  esac
204],enable_m64_build=no)
205
206AC_ARG_ENABLE(m32-build,
207AS_HELP_STRING([--enable-m32-build],
208               [build 32bit binaries using the -m32 flag to (g)cc]),
209[ case "$enableval" in
210    no) enable_m32_build=no ;;
211    *)	enable_m32_build=yes ;;
212  esac
213],enable_m32_build=no)
214
215AC_ARG_WITH(dynamic-trace,
216AS_HELP_STRING([--with-dynamic-trace={dtrace|lttng|systemtap}],
217	       [specify use of dynamic trace framework, dtrace, lttng or systemtap])
218AS_HELP_STRING([--without-dynamic-trace],
219               [don't enable any dynamic tracing (default)]))
220
221if test X"$with_dynamic_trace" = X""; then
222   with_dynamic_trace=no
223fi
224
225case "$with_dynamic_trace" in
226     no) DYNAMIC_TRACE_FRAMEWORK=;;
227     lttng)
228            AC_DEFINE(USE_LTTNG,[1],
229                      [Define if you want to use lttng for dynamic tracing])
230            DYNAMIC_TRACE_FRAMEWORK=lttng;;
231     dtrace)
232	    AC_DEFINE(USE_DTRACE,[1],
233		[Define if you want to use dtrace for dynamic tracing])
234     	     DYNAMIC_TRACE_FRAMEWORK=dtrace;;
235     systemtap)
236	    AC_DEFINE(USE_SYSTEMTAP,[1],
237		[Define if you want to use systemtap for dynamic tracing])
238	    DYNAMIC_TRACE_FRAMEWORK=systemtap;;
239     *)
240     	    AC_MSG_ERROR(Unknown dynamic tracing framework specified with --with-dynamic-trace!);;
241esac
242
243if test X"$DYNAMIC_TRACE_FRAMEWORK" != X""; then
244   AC_DEFINE(USE_DYNAMIC_TRACE,[1],
245		[Define if you want to use dynamic tracing])
246fi
247
248AC_ARG_ENABLE(vm-probes,
249AS_HELP_STRING([--enable-vm-probes],
250               [add dynamic trace probes to the Beam VM (only possible if --with-dynamic-trace is enabled, and then default)]),
251	       [ case "$enableval" in
252    	       	 no) use_vm_probes=no ;;
253    		 *)
254			if  test X"$DYNAMIC_TRACE_FRAMEWORK" != X""; then
255		 	    use_vm_probes=yes ;
256			else
257			    AC_MSG_ERROR(Can not enable VM probes without any dynamic tracing framework!);
258			fi;;
259  		 esac ], if  test X"$DYNAMIC_TRACE_FRAMEWORK" != X""; then
260		 	    use_vm_probes=yes ;
261			else
262			    use_vm_probes=no
263			fi)
264
265AC_SUBST(USE_VM_PROBES)
266if test X"$DYNAMIC_TRACE_FRAMEWORK" != X"lttng"; then
267    if test X"$use_vm_probes" = X"yes"; then
268        USE_VM_PROBES=yes
269        AC_DEFINE(USE_VM_PROBES,[1],
270                  [Define to enable VM dynamic trace probes])
271    fi
272fi
273
274AC_ARG_WITH(assumed-cache-line-size,
275AS_HELP_STRING([--with-assumed-cache-line-size=SIZE],
276               [specify assumed cache line size in bytes (valid values are powers of two between and including 16 and 8192; default is 64)]))
277
278dnl Require the assumed cache-line size to be a power of two between 16 and 8192
279case "$with_assumed_cache_line_size" in
280     ""|no|yes)
281	with_assumed_cache_line_size=64;;
282     16|32|64|128|256|512|1024|2048|4096|8192)
283	;;
284     *)
285	AC_MSG_ERROR([Invalid assumed cache-line size of $with_assumed_cache_line_size bytes])
286	;;
287esac
288
289AC_DEFINE_UNQUOTED(ASSUMED_CACHE_LINE_SIZE,
290		   $with_assumed_cache_line_size,
291		   [Assumed cache-line size (in bytes)])
292
293AC_ARG_ENABLE(systemd,
294AS_HELP_STRING([--enable-systemd], [enable systemd support in epmd]),
295[],
296[enable_systemd=no])
297
298AC_ARG_ENABLE(saved-compile-time,
299AS_HELP_STRING([--disable-saved-compile-time], [disable saved compile time]),
300[ case "$enableval" in
301    no) save_compile_time=0 ;;
302    *)  save_compile_time=1 ;;
303  esac ], save_compile_time=1)
304
305AC_DEFINE_UNQUOTED(ERTS_SAVED_COMPILE_TIME, $save_compile_time, [Save compile time?])
306
307AC_ARG_WITH(microstate-accounting,
308AS_HELP_STRING([--with-microstate-accounting={yes|extra}],
309               [enable microstate account, possibly with extra detailed states])
310AS_HELP_STRING([--without-microstate-accounting],
311               [don't enable microstate accounting]),
312[],[with_microstate_accounting=yes])
313
314case "$with_microstate_accounting" in
315    yes) AC_DEFINE(ERTS_ENABLE_MSACC,[1],
316		[Define as 1 if you want to enable microstate accounting, 2 if you want extra states]) ;;
317    extra) AC_DEFINE(ERTS_ENABLE_MSACC,[2],
318		[Define as 1 if you want to enable microstate accounting, 2 if you want extra states]) ;;
319    *) ;;
320esac
321
322dnl Magic test for clearcase.
323OTP_RELEASE=
324if test "${ERLANG_COMMERCIAL_BUILD}" != ""; then
325	OTP_EXTRA_FLAGS=-DOTP_RELEASE
326	OTP_RELEASE=yes
327else
328	OTP_EXTRA_FLAGS=
329fi
330AC_SUBST(OTP_RELEASE)
331
332AC_MSG_CHECKING([OTP release])
333[SYSTEM_VSN=`cat $ERL_TOP/OTP_VERSION | sed "s|\([0-9]*\).*|\1|"`]
334AC_MSG_RESULT([$SYSTEM_VSN])
335AC_SUBST(SYSTEM_VSN)
336
337AC_MSG_CHECKING([OTP version])
338[OTP_VERSION=`cat $ERL_TOP/OTP_VERSION`]
339AC_MSG_RESULT([$OTP_VERSION])
340AC_SUBST(OTP_VERSION)
341
342if test X${enable_m64_build} = Xyes; then
343	case $CFLAGS in
344		*-m64*)
345			;;
346		*)
347			CFLAGS="-m64 $CFLAGS"
348			;;
349	esac
350else
351	if test X${enable_m32_build} = Xyes;
352	then
353		case $CFLAGS in
354		    *-m32*)
355			    ;;
356		    *)
357			    CFLAGS="-m32 $CFLAGS"
358			    ;;
359		esac ;
360	fi
361fi
362
363AC_ARG_ENABLE(static-nifs,
364AS_HELP_STRING([--enable-static-nifs], [link nifs statically. If yes then all nifs in all Erlang/OTP applications will be statically linked into the main binary. It is also possible to give a list of nifs that should be linked statically. The list should be a comma separated and contain the absolute path to a .a archive for each nif that is to be statically linked. The name of the .a archive has to be the same as the name of the nif. Note that you have to link any external dependencies that the nifs have to the main binary, so for the crypto nif you want to pass LIBS=-lcrypto to configure.]),
365	       STATIC_NIFS="$enableval",
366	       STATIC_NIFS=no)
367AC_SUBST(STATIC_NIFS)
368
369AC_ARG_ENABLE(static-drivers,
370AS_HELP_STRING([--enable-static-drivers], [comma separated list of linked-in drivers to link statically with the main binary. The list should contain the absolute path to a .a archive for each driver that is to be statically linked. The name of the .a archive has to be the same as the name of the driver.]),
371	       STATIC_DRIVERS="$enableval",
372	       STATIC_DRIVERS=no)
373AC_SUBST(STATIC_DRIVERS)
374
375AC_ARG_WITH(ets-write-concurrency-locks,
376AS_HELP_STRING([--with-ets-write-concurrency-locks={8|16|32|64|128|256}],
377               [specify how many locks the write_concurrency option for ets should use.])
378AS_HELP_STRING([--without-ets-write-concurrency-locks],
379               [use the default number of write_concurrency locks (default)]))
380
381if test X"$with_ets_write_concurrency_locks" != X""; then
382   AC_DEFINE_UNQUOTED(ERTS_DB_HASH_LOCK_CNT,$with_ets_write_concurrency_locks,
383		      [Define to override the default number of write_concurrency locks])
384fi
385
386AC_ARG_WITH(spectre-mitigation,
387    AS_HELP_STRING([--with-spectre-mitigation={yes|incomplete}],
388                   [enable spectre mitigation, either fully or with mitigations
389                    disabled in a handful places like the interpreter])
390    AS_HELP_STRING([--without-spectre-mitigation],
391                   [build without spectre mitigation]),
392    [],[with_spectre_mitigation=no])
393
394case "$with_spectre_mitigation" in
395    no) ;;
396    yes) ;;
397    incomplete) ;;
398    *) AC_MSG_ERROR([Invalid spectre mitigation setting]) ;;
399esac
400
401i_noretpoline_attr=""
402
403if test X"$with_spectre_mitigation" != X"no"; then
404    CFLAGS="$CFLAGS -mindirect-branch=thunk"
405
406    AC_MSG_CHECKING([for spectre mitigation])
407    AC_COMPILE_IFELSE(
408        [AC_LANG_PROGRAM([],[return 0;])],
409        [AC_MSG_RESULT([yes])],
410        [AC_MSG_ERROR([no])])
411
412    if test X"$with_spectre_mitigation" = X"incomplete"; then
413        # gcc and clang support this attribute if they're recent enough. Note
414        # that we must compile with -Werror to check for actual support as they
415        # warn rather than error out on unsupported attributes.
416
417        i_noretpoline_attr='__attribute__((__indirect_branch__("keep")))'
418        i_preserve_cflags="$CFLAGS"
419        CFLAGS="$CFLAGS -Werror"
420
421        AC_MSG_CHECKING([whether spectre mitigation can be disabled on a per-function basis])
422        AC_COMPILE_IFELSE(
423            [AC_LANG_PROGRAM([$i_noretpoline_attr],[return 0;])],
424            [AC_MSG_RESULT([yes])],
425            [AC_MSG_ERROR([no])])
426
427        CFLAGS="$i_preserve_cflags"
428    fi
429fi
430
431AC_DEFINE_UNQUOTED(ERTS_NO_RETPOLINE, $i_noretpoline_attr,
432                   [Per-function attribute for disabling retpoline. This is
433                    *only* defined when --with-spectre-mitigation=incomplete
434                    and has no effects otherwise])
435
436dnl ----------------------------------------------------------------------
437dnl Checks for programs.
438dnl ----------------------------------------------------------------------
439
440AC_PROG_CC
441AC_SUBST(GCC)
442
443dnl ---------------------------------------------------------------------
444dnl Special stuff regarding CFLAGS and details in the environment...
445dnl ---------------------------------------------------------------------
446
447dnl NOTE: CPPFLAGS will be included in CFLAGS at the end
448case $host_os in
449    linux*) CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE";;
450    aix*|os400*)
451        # * _ALL_SOURCE: Required to get the winsize structure for TIOCSWINSZ.
452        # * _LINUX_SOURCE_COMPAT: Not required, but makes some libc functions
453        # behave closer to glibc assumptions.
454        CPPFLAGS="$CPPFLAGS -D_ALL_SOURCE -D_LINUX_SOURCE_COMPAT"
455        ;;
456    win32)
457	# The ethread library requires _WIN32_WINNT of at least 0x0403.
458	# -D_WIN32_WINNT=* from CPPFLAGS is saved in ETHR_DEFS.
459	CPPFLAGS="$CPPFLAGS -D_WIN32_WINNT=0x0600 -DWINVER=0x0600"
460	;;
461    *)
462	;;
463esac
464
465
466LM_WINDOWS_ENVIRONMENT
467
468dnl
469dnl Flags to the C compiler
470dnl
471dnl Make sure we find config.h
472dnl
473
474ERTS_CONFIG_H_IDIR="-I${ERL_TOP}/erts/$host"
475AC_SUBST(ERTS_CONFIG_H_IDIR)
476
477extra_flags="$ERTS_CONFIG_H_IDIR $OTP_EXTRA_FLAGS"
478CFLAGS="$CFLAGS $extra_flags"
479DEBUG_CFLAGS="-g $CPPFLAGS $extra_flags $DEBUG_CFLAGS"
480DEBUG_FLAGS=-g
481
482dnl
483dnl Adjust DEBUG_CFLAGS to match CFLAGS in terms of -m
484dnl
485
486case $CFLAGS in
487	*-m64*)
488		case $DEBUG_CFLAGS in
489			*-m64*)
490				;;
491			*)
492				DEBUG_CFLAGS="-m64 $DEBUG_CFLAGS"
493				;;
494		esac
495		;;
496	*-m32*)
497		case $DEBUG_CFLAGS in
498			*-m32*)
499				;;
500			*)
501				DEBUG_CFLAGS="-m32 $DEBUG_CFLAGS"
502				;;
503		esac
504		;;
505	*)
506		;;
507esac
508
509lfs_conf=ok
510lfs_source=none
511if test "${LFS_CFLAGS+set}" = "set" || \
512   test "${LFS_LDFLAGS+set}" = "set" || \
513   test "${LFS_LIBS+set}" = "set"; then
514    lfs_source=user
515else
516   LM_CHECK_GETCONF
517   test "$GETCONF" = "false" || lfs_source=getconf
518fi
519
520if test "$lfs_source" = "none"; then
521    AC_MSG_WARN([Do not know how to check for large file support flags; no getconf is available])
522else
523    for var in CFLAGS LDFLAGS LIBS; do
524	AC_MSG_CHECKING([for large file support $var])
525	if test $lfs_source = user; then
526	    eval "lfs_val=\"\$LFS_$var\""
527	else
528	    eval "lfs_var=LFS_$var"
529	    lfs_val=`$GETCONF $lfs_var 2>/dev/null` || lfs_conf=failed
530	    if test $lfs_conf = failed; then
531		AC_MSG_RESULT([failed])
532		break
533	    fi
534	    eval "$lfs_var=\"$lfs_val\""
535	fi
536	test "$lfs_val" != "" || lfs_val=none
537	AC_MSG_RESULT([$lfs_val])
538    done
539    if test $lfs_conf = failed; then
540	AC_MSG_WARN([Check for large file support flags failed; $GETCONF failed])
541    else
542	CFLAGS="$CFLAGS $LFS_CFLAGS"
543	DEBUG_CFLAGS="$DEBUG_CFLAGS $LFS_CFLAGS"
544	LDFLAGS="$LDFLAGS $LFS_LDFLAGS"
545	LIBS="$LIBS $LFS_LIBS"
546    fi
547fi
548
549if test "x$GCC" = xyes; then
550  # Treat certain GCC warnings as errors
551  LM_TRY_ENABLE_CFLAG([-Werror=return-type], [WERRORFLAGS])
552  LM_TRY_ENABLE_CFLAG([-Werror=implicit], [WERRORFLAGS])
553  LM_TRY_ENABLE_CFLAG([-Werror=undef], [WERRORFLAGS])
554
555  # until the emulator can handle this, I suggest we turn it off!
556  #WFLAGS="-Wall -Wshadow -Wcast-qual -Wmissing-declarations"
557  WFLAGS="-Wall -Wstrict-prototypes"
558
559  case "$host_cpu" in
560    tile*)
561      # tile-gcc is a bit stricter with -Wmissing-prototypes than other gccs,
562      # and too strict for our taste.
563      ;;
564    *)
565      WFLAGS="$WFLAGS -Wmissing-prototypes";;
566  esac
567
568  saved_CFLAGS=$CFLAGS
569  CFLAGS="$CFLAGS -Wdeclaration-after-statement"
570  AC_TRY_COMPILE([],[;], warn_decl_after_st=true, warn_decl_after_st=false)
571  if test "X$warn_decl_after_st" = "Xtrue"; then
572    WFLAGS="$WFLAGS -Wdeclaration-after-statement"
573  fi
574  CFLAGS=$saved_CFLAGS
575
576  # Use -fno-common for gcc, that is link error if multiple definitions of
577  # global variables are encountered. This is ISO C compliant.
578  # Until version 10, gcc has had -fcommon as default, which allows and merges
579  # such dubious duplicates.
580  LM_TRY_ENABLE_CFLAG([-fno-common], [CFLAGS])
581else
582  WFLAGS=""
583  WERRORFLAGS=""
584fi
585
586AC_MSG_CHECKING([C99 support])
587
588AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[
589#if __STDC_VERSION__ < 199901L
590  #error "Not C99"
591#endif])],
592  [AC_MSG_RESULT([yes])],
593    [AC_MSG_RESULT([no])
594     CFLAGS="-std=gnu99 $CFLAGS"
595     DEBUG_CFLAGS="-std=gnu99 $DEBUG_CFLAGS"])
596
597AC_MSG_CHECKING([CFLAGS for -O switch])
598case "$CFLAGS" in
599     *-O*) AC_MSG_RESULT([yes]) ;;
600     *)
601       AC_MSG_ERROR([
602  CFLAGS must contain a -O flag. If you need to edit the CFLAGS you probably
603  also want to add the default CFLAGS. The default CFLAGS are "-O2 -g".
604  If you want to build erts without any optimization, pass -O0 to CFLAGS.]) ;;
605esac
606
607dnl DEBUG_FLAGS is obsolete (I hope)
608AC_SUBST(DEBUG_FLAGS)
609AC_SUBST(DEBUG_CFLAGS)
610AC_SUBST(WFLAGS)
611AC_SUBST(WERRORFLAGS)
612
613## Check if we can do profile guided optimization of beam_emu
614LM_CHECK_ENABLE_CFLAG([-fprofile-generate -Werror],[PROFILE_GENERATE])
615LM_CHECK_ENABLE_CFLAG([-fprofile-use -Werror],[PROFILE_USE])
616LM_CHECK_ENABLE_CFLAG([-fprofile-use -fprofile-correction -Werror],[PROFILE_CORRECTION])
617
618if test "X$PROFILE_CORRECTION" = "Xtrue"; then
619   saved_CFLAGS=$CFLAGS
620   saved_LDFLAGS=$LDFLAGS
621   CFLAGS="-fprofile-generate $saved_CFLAGS"
622   LDFLAGS="-fprofile-generate $saved_LDFLAGS"
623   AC_MSG_CHECKING([whether $CC links with -fprofile-generate])
624   AC_LINK_IFELSE([AC_LANG_PROGRAM([],[return 0;])],
625        [AC_MSG_RESULT([yes])
626         PROFILE_GENERATE=true],
627        [AC_MSG_RESULT([no])
628         PROFILE_GENERATE=false])
629   CFLAGS=$saved_CFLAGS
630   LDFLAGS=$saved_LDFLAGS
631fi
632
633## Check if this is clang
634LM_CHECK_ENABLE_CFLAG([-fprofile-instr-generate -Werror],[PROFILE_INSTR_GENERATE])
635if test "X$PROFILE_INSTR_GENERATE" = "Xtrue"; then
636   # It was clang, now we also have to check if we have llvm-profdata and that
637   # we can link programs with -fprofile-instr-use
638   saved_CFLAGS=$CFLAGS;
639   CFLAGS="-fprofile-instr-generate -Werror $saved_CFLAGS"
640   AC_RUN_IFELSE([AC_LANG_PROGRAM([],[])],
641     [AC_PATH_PROG([LLVM_PROFDATA], [llvm-profdata],[],[$PATH:/Library/Developer/CommandLineTools/usr/bin])
642      AC_CHECK_PROGS([XCRUN], [xcrun])
643      if test "X$XCRUN" != "X" -a "X$LLVM_PROFDATA" = "X"; then
644        AC_MSG_CHECKING([for $XCRUN $LLVM_PROFDATA])
645        if $XCRUN $LLVM_PROFDATA --help 2>& AS_MESSAGE_LOG_FD >& AS_MESSAGE_LOG_FD; then
646          LLVM_PROFDATA="$XCRUN $LLVM_PROFDATA"
647          AC_MSG_RESULT([yes])
648        else
649          AC_MSG_RESULT([no])
650        fi
651      fi
652      AC_SUBST(LLVM_PROFDATA)
653      if test "X$LLVM_PROFDATA" != "X"; then
654        CFLAGS="-fprofile-instr-use=default.profdata $saved_CFLAGS";
655        $LLVM_PROFDATA merge -output=default.profdata *.profraw;
656        AC_MSG_CHECKING([whether $CC accepts -fprofile-instr-use=default.profdata -Werror])
657        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[return 0;])],
658          [AC_MSG_RESULT([yes])
659           PROFILE_INSTR_USE=true],
660          [AC_MSG_RESULT([no])
661           PROFILE_INSTR_USE=false])
662        rm -f default.profdata
663      fi],
664     [],
665     [AC_MSG_NOTICE([Disabling PGO when cross-compiling])])
666   rm -f *.profraw
667   CFLAGS=$saved_CFLAGS;
668fi
669
670AC_ARG_ENABLE(pgo,
671AS_HELP_STRING([--enable-pgo],
672               [build erts using PGO (profile guided optimization)]),
673[ case "$enableval" in
674    no) enable_pgo=no ;;
675    *)	enable_pgo=yes ;;
676  esac
677],enable_pgo=default)
678
679USE_PGO=false
680AC_MSG_CHECKING([whether to do PGO of erts])
681if test $enable_pgo = no; then
682  AC_MSG_RESULT([no, disabled by user])
683elif test $CROSS_COMPILING = yes; then
684  if test $enable_pgo = yes; then
685    AC_MSG_ERROR(cannot use PGO when cross-compiling)
686  else
687    AC_MSG_RESULT([no, cross compiling])
688  fi
689elif test "X$host" = "Xwin32"; then
690  AC_MSG_RESULT([no, not supported in windows])
691elif test "X$PROFILE_GENERATE" = "Xtrue" -a "X$PROFILE_USE" = "Xtrue" -a "X$PROFILE_CORRECTION" = "Xtrue"; then
692  ## We need -fprofile-generate and -fprofile-correction support to use PGO with
693  ## gcc as multiple threads run within the executed object files
694  USE_PGO=true
695  PROFILE_COMPILER=gcc
696  AC_MSG_RESULT([yes, using -fprofile-generate -fprofile-correction])
697elif test "X$PROFILE_INSTR_GENERATE" = "Xtrue" -a "X$PROFILE_INSTR_USE" = "Xtrue"; then
698  USE_PGO=true
699  PROFILE_COMPILER=clang
700  AC_MSG_RESULT([yes, using -fprofile-instr-generate])
701else
702  if test $enable_pgo = yes; then
703    AC_MSG_ERROR(cannot use PGO with this compiler)
704  else
705    AC_MSG_RESULT([no])
706  fi
707fi
708
709AC_SUBST(USE_PGO)
710AC_SUBST(PROFILE_COMPILER)
711
712AC_CHECK_SIZEOF(void *) # Needed for ARCH and smp checks below
713if test "x$ac_cv_sizeof_void_p" = x8; then
714  AC_SUBST(EXTERNAL_WORD_SIZE, 64)
715else
716  AC_SUBST(EXTERNAL_WORD_SIZE, 32)
717fi
718
719dnl
720dnl Figure out operating system and cpu architecture
721dnl
722
723if test "x$host_alias" != "x"; then
724    chk_opsys_=$host_os
725else
726    chk_opsys_=`uname -s`
727    if test "x$chk_opsys_" = "xSunOS"; then
728	chk_opsys_=$chk_opsys_`uname -r`
729    fi
730fi
731case $chk_opsys_ in
732    win32)			OPSYS=win32;;
733    solaris2.*|SunOS5.*)	OPSYS=sol2;;
734    linux*|Linux)		OPSYS=linux;;
735    darwin|Darwin)		OPSYS=darwin;;
736    freebsd|FreeBSD)		OPSYS=freebsd;;
737    *)				OPSYS=noopsys
738esac
739
740AC_SUBST(OPSYS)
741
742LM_HARDWARE_ARCH
743
744dnl Check consistency of os and darwin-switches
745
746
747dnl Take care of LDFLAGS on darwin, and disable common_test as it
748dnl has a build/configure system re rx-lib that is not compatible
749dnl First remove common_tests skip file.
750
751dnl Adjust LDFLAGS to allow 64bit linkage on DARWIN
752case $ARCH-$OPSYS in
753	amd64-darwin*|arm64-darwin*)
754		AC_MSG_NOTICE([Adjusting LDFLAGS to cope with 64bit Darwin])
755		case $LDFLAGS in
756			*-m64*)
757				;;
758			*)
759				LDFLAGS="-m64 $LDFLAGS"
760			;;
761		esac
762		;;
763	*-darwin*)
764		case $LDFLAGS in
765			*-m32*)
766				;;
767			*)
768				LDFLAGS="-m32 $LDFLAGS"
769				;;
770		esac
771		;;
772	*)
773		if test X${enable_m64_build} = Xyes; then
774			AC_MSG_NOTICE([Adjusting LDFLAGS to use -m64])
775			case $LDFLAGS in
776				*-m64*)
777					;;
778				*)
779					LDFLAGS="-m64 $LDFLAGS"
780				;;
781			esac
782		fi;
783		if test X${enable_m32_build} = Xyes; then
784			AC_MSG_NOTICE([Adjusting LDFLAGS to use -m32]) ;
785			case $LDFLAGS in
786				*-m32*)
787					;;
788				*)
789					LDFLAGS="-m32 $LDFLAGS"
790				;;
791			esac ;
792		fi
793		;;
794esac
795
796AC_MSG_CHECKING(if VM has to be linked with Carbon framework)
797case $ARCH-$OPSYS in
798	*-darwin*)
799  		LIBCARBON="-framework Carbon -framework Cocoa"
800		AC_MSG_RESULT([yes])
801		;;
802	*)
803		LIBCARBON=
804		AC_MSG_RESULT([no])
805		;;
806esac
807
808AC_SUBST(LIBCARBON)
809
810_search_path=/bin:/usr/bin:/usr/local/bin:$PATH
811
812AC_PATH_PROG(MKDIR, mkdir, false, $_search_path)
813if test "$ac_cv_path_MKDIR" = false; then
814  AC_MSG_ERROR([No 'mkdir' command found])
815fi
816
817AC_PATH_PROG(CP, cp, false, $_search_path)
818if test "$ac_cv_path_CP" = false; then
819  AC_MSG_ERROR([No 'cp' command found])
820fi
821
822_search_path=
823
824
825# Remove old configuration information.
826# Next line should be before first output to CONN_INFO. So this is
827# just the right place.
828rm -f "$ERL_TOP/erts/CONF_INFO"
829
830dnl Check if we should/can build a sharing-preserving emulator
831AC_MSG_CHECKING(if we are building a sharing-preserving emulator)
832if test "$enable_sharing_preserving" = "yes"; then
833        AC_DEFINE(SHCOPY, [1],
834		  [Define if building a sharing-preserving emulator])
835	AC_MSG_RESULT([yes])
836else
837	AC_MSG_RESULT([no])
838fi
839
840
841dnl some tests below will call this if we haven't already - and autoconf
842dnl can't handle those tests being done conditionally at runtime
843AC_PROG_CPP
844
845AC_PROG_RANLIB
846
847AC_PROG_YACC
848LM_PROG_PERL5
849if test "$ac_cv_path_PERL" = false; then
850  AC_MSG_ERROR([Perl version 5 is required to build the emulator!])
851fi
852AC_PROG_LN_S
853
854
855AC_CHECK_TOOL([AR], [ar], [false])
856if test "$ac_cv_prog_AR" = false; then
857  AC_MSG_ERROR([No 'ar' command found in PATH])
858fi
859
860#
861# Get programs needed for building the documentation
862#
863
864## Delete previous failed configure results
865if test -f doc/CONF_INFO; then
866   rm -f doc/CONF_INFO
867fi
868
869AC_CHECK_PROGS(XSLTPROC, xsltproc)
870if test -z "$XSLTPROC"; then
871  echo "xsltproc" >> doc/CONF_INFO
872  AC_MSG_WARN([No 'xsltproc' command found: the documentation cannot be built])
873fi
874
875AC_CHECK_PROGS(FOP, fop)
876if test -z "$FOP"; then
877  FOP="$ERL_TOP/make/fakefop"
878  echo "fop" >> doc/CONF_INFO
879  AC_MSG_WARN([No 'fop' command found: going to generate placeholder PDF files])
880fi
881
882AC_CHECK_PROGS(XMLLINT, xmllint)
883if test -z "$XMLLINT"; then
884  echo "xmllint" >> doc/CONF_INFO
885  AC_MSG_WARN([No 'xmllint' command found: can't run the xmllint target for the documentation])
886fi
887
888dnl
889dnl We can live with Solaris /usr/ucb/install
890dnl
891case $host in
892  *-*-solaris*|free_source)
893    if test -x /usr/ucb/install; then
894      INSTALL="/usr/ucb/install -c"
895    fi
896    ;;
897  *)
898    ;;
899esac
900AC_PROG_INSTALL
901LM_PROG_INSTALL_DIR
902
903case $host_os in
904	darwin*)
905		dnl Need to preserve modification time on archives;
906		dnl otherwise, ranlib has to be run on archives
907		dnl again after installation.
908		INSTALL_DATA="$INSTALL_DATA -p";;
909	*)
910		;;
911esac
912
913dnl
914dnl Fix for Tilera install permissions
915dnl
916
917case $build in
918	*tile*)
919		INSTALL_PROGRAM="$INSTALL_PROGRAM -m755"
920		INSTALL_SCRIPT="$INSTALL_SCRIPT -m755"
921		;;
922	*)
923		;;
924esac
925
926dnl ----------------------------------------------------------------------
927dnl Misc. things (some of them should go away)
928dnl ----------------------------------------------------------------------
929
930dnl
931dnl An attempt to allow cross compiling. This is not the right way,
932dnl nor does it work currently. Some makefiles still needs these
933dnl variables, so we leave them in for now.
934dnl
935HCC='$(CC)'         AC_SUBST(HCC)
936HCFLAGS=""          AC_SUBST(HCFLAGS)
937HCFLAGS="$HCFLAGS -I${ERL_TOP}/erts/$host"
938
939dnl We want to use $(CC) as linker for the emulator regardless of
940dnl what the user say. This might not be the right way to do it, but
941dnl for now that is the way we do it.
942LD='$(CC)'
943LD_MAY_BE_WEAK=no
944AC_SUBST(LD)
945
946dnl Check for cygwin and object/exe files extension
947dnl AC_CYGWIN is deprecated
948AC_EXEEXT
949AC_OBJEXT
950
951dnl This is the os flavour, should be unix or win32
952case $host in
953   win32)
954      ERLANG_OSTYPE=win32 ;;
955   *)
956      ERLANG_OSTYPE=unix ;;
957esac
958
959AC_SUBST(ERLANG_OSTYPE)
960
961# Check how to export functions from the emulator executable, needed
962# when dynamically loaded drivers are loaded (so that they can find
963# emulator functions).
964# OS'es with ELF executables using the GNU linker (Linux and recent *BSD,
965# in rare cases Solaris) typically need '-Wl,-export-dynamic' (i.e. pass
966# -export-dynamic to the linker - also known as -rdynamic and some other
967# variants); some sysVr4 system(s) instead need(s) '-Wl,-Bexport'.
968# AIX 4.x (perhaps only for x>=2) wants -Wl,-bexpall,-brtl and doesn't
969# reliably return an error for others, thus we separate it out.
970# Otherwise we assume that if the linker accepts the flag, it is needed.
971AC_MSG_CHECKING(for extra flags needed to export symbols)
972DEXPORT=""
973case $host_os in
974	aix*|os400*)
975		DEXPORT=-Wl,-bexpall,-brtl
976	;;
977	bsdi*)
978    		DEXPORT="-rdynamic "
979    	;;
980	win32)
981    		DEXPORT=""
982    	;;
983	*)
984		save_ldflags="$LDFLAGS"
985		LDFLAGS=-Wl,-export-dynamic
986		AC_TRY_LINK(,,[DEXPORT=-Wl,-export-dynamic], [
987			LDFLAGS=-Wl,-Bexport
988			AC_TRY_LINK(,,[DEXPORT=-Wl,-Bexport],
989				AC_MSG_RESULT(none))])
990		LDFLAGS="$save_ldflags"
991	;;
992esac
993AC_SUBST(DEXPORT)
994case "x$DEXPORT" in
995	"x")
996		AC_MSG_RESULT([none]);;
997	*)
998		AC_MSG_RESULT([$DEXPORT]);;
999esac
1000
1001# Check for Solaris/ultrasparc /dev/perfmon interface
1002# (also needs gcc specific asm instructions)
1003case "${host}:${GCC}" in
1004  sparc-*-solaris*:yes)
1005    AC_DEFINE(HAVE_SOLARIS_SPARC_PERFMON,[1],
1006	[define if you have the Solaris/ultrasparc /dev/perfmon interface])
1007    ;;
1008  *)
1009    ;;
1010esac
1011
1012
1013case $host_os in
1014        darwin19*)
1015	    # Disable stack checking to avoid crashing with a segment fault
1016	    # in macOS Catalina.
1017	    AC_MSG_NOTICE([Turning off stack check on macOS 10.15 (Catalina)])
1018	    CFLAGS="-fno-stack-check $CFLAGS"
1019	    ;;
1020        *)
1021	    ;;
1022esac
1023
1024
1025dnl ----------------------------------------------------------------------
1026dnl Checks for libraries.
1027dnl ----------------------------------------------------------------------
1028
1029AC_CHECK_LIB(m, sin)
1030AC_CHECK_LIB(dl, dlopen)
1031AC_CHECK_LIB(inet, main)
1032AC_CHECK_LIB(util, openpty)
1033
1034dnl Try to find a thread library.
1035dnl
1036dnl ETHR_LIB_NAME, ETHR_LIBS, ETHR_X_LIBS, ETHR_THR_LIB_BASE and ETHR_DEFS
1037dnl are set by ERL_FIND_ETHR_LIB
1038ERL_FIND_ETHR_LIB
1039
1040if test "X$ETHR_LIB_NAME" = "X"; then
1041   AC_MSG_ERROR([cannot build emulator since no thread library was found])
1042fi
1043
1044TYPES=opt
1045
1046DIRTY_SCHEDULER_TEST=$enable_dirty_schedulers_test
1047AC_SUBST(DIRTY_SCHEDULER_TEST)
1048test $DIRTY_SCHEDULER_TEST != yes || {
1049    test -f "$ERL_TOP/erts/CONF_INFO" || echo "" > "$ERL_TOP/erts/CONF_INFO"
1050    cat >> $ERL_TOP/erts/CONF_INFO <<EOF
1051
1052                 WARNING:
1053                   Dirty Scheduler Test has been enabled. This
1054                   feature is for debugging purposes only.
1055                   Poor performance as well as strange system
1056                   characteristics is expected!
1057
1058EOF
1059}
1060
1061test "X$smp_require_native_atomics" = "Xyes" &&
1062     AC_DEFINE(ETHR_SMP_REQUIRE_NATIVE_IMPLS, 1, [Define if you want to enable check for native ethread implementations])
1063
1064case "$ethr_have_native_atomics-$smp_require_native_atomics-$ethr_have_native_spinlock" in
1065  yes-*)
1066	if test "$ethr_native_atomic_implementation" = "gcc_sync"; then
1067	    test -f "$ERL_TOP/erts/CONF_INFO" ||
1068		echo "" > "$ERL_TOP/erts/CONF_INFO"
1069	    cat >> $ERL_TOP/erts/CONF_INFO <<EOF
1070
1071                 WARNING:
1072                   Only gcc's __sync_* builtins available for
1073                   atomic memory access. This will cause lots
1074                   of expensive and unnecessary memory barrier
1075                   instructions to be issued which will make
1076                   the performance of the runtime system
1077                   suffer. You are *strongly* advised to
1078                   upgrade to a gcc version that supports the
1079                   __atomic_* builtins (at least gcc version
1080                   4.7) or build with libatomic_ops. See the
1081                   "Atomic Memory Operations and the VM"
1082		   chapter of \$ERL_TOP/HOWTO/INSTALL.md for
1083                   more information.
1084
1085EOF
1086	fi
1087	;;
1088
1089  no-yes-*)
1090	AC_MSG_ERROR([No native atomic implementation found. See the \"Atomic Memory Operations and the VM\" chapter of \$ERL_TOP/HOWTO/INSTALL.md for more information.])
1091	;;
1092
1093  no-no-yes)
1094
1095	test -f "$ERL_TOP/erts/CONF_INFO" ||
1096	    echo "" > "$ERL_TOP/erts/CONF_INFO"
1097	cat >> $ERL_TOP/erts/CONF_INFO <<EOF
1098
1099                 No native atomic implementation available.
1100                 Fallbacks implemented using spinlocks will be
1101                 used. Note that the performance of the SMP
1102                 runtime system will suffer immensely due to
1103		 this.
1104
1105EOF
1106	;;
1107
1108  no-no-no)
1109	test -f "$ERL_TOP/erts/CONF_INFO" ||
1110	    echo "" > "$ERL_TOP/erts/CONF_INFO"
1111	cat >> "$ERL_TOP/erts/CONF_INFO" <<EOF
1112
1113                 No native atomic implementation, nor no native
1114                 spinlock implementation available. Fallbacks
1115                 implemented using mutexes will be used. Note
1116                 that the performance of the SMP runtime system
1117                 will suffer immensely due to this.
1118
1119EOF
1120	;;
1121
1122esac
1123AC_SUBST(TYPES)
1124
1125AC_CHECK_FUNCS([posix_fadvise closefrom])
1126AC_CHECK_HEADERS([linux/falloc.h])
1127dnl * Old glibcs have broken fallocate64(). Make sure not to use it.
1128AC_CACHE_CHECK([whether fallocate() works],i_cv_fallocate_works,[
1129    AC_TRY_LINK([
1130        #include <stdio.h>
1131        #include <stdlib.h>
1132        #include <fcntl.h>
1133        #include <unistd.h>
1134	#include <fcntl.h>
1135	#include <linux/falloc.h>
1136	],
1137        [
1138	int fd = creat("conftest.temp", 0600);
1139        fallocate(fd, FALLOC_FL_KEEP_SIZE,(off_t)  1024,(off_t)  1024);
1140    	], i_cv_fallocate_works=yes, i_cv_fallocate_works=no)
1141])
1142if test $i_cv_fallocate_works = yes; then
1143   AC_DEFINE(HAVE_FALLOCATE, 1, Define if you have a working fallocate())
1144fi
1145
1146dnl * Old glibcs have broken posix_fallocate(). Make sure not to use it.
1147dnl * It may also be broken in AIX.
1148AC_CACHE_CHECK([whether posix_fallocate() works],i_cv_posix_fallocate_works,[
1149    AC_TRY_RUN([
1150        #if !defined(__sun) && !defined(__sun__)
1151        #define _XOPEN_SOURCE 600
1152        #endif
1153        #include <stdio.h>
1154        #include <stdlib.h>
1155        #include <fcntl.h>
1156        #include <unistd.h>
1157        #if defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 7))
1158            possibly broken posix_fallocate
1159        #endif
1160        int main() {
1161            int fd = creat("conftest.temp", 0600);
1162            int ret;
1163            if (-1 == fd) {
1164               perror("creat()");
1165               return 2;
1166            }
1167            ret = posix_fallocate(fd, 1024, 1024) < 0 ? 1 : 0;
1168            unlink("conftest.temp");
1169            return ret;
1170        }
1171    ], [
1172        i_cv_posix_fallocate_works=yes
1173    ], [
1174        i_cv_posix_fallocate_works=no
1175    ], [
1176        i_cv_posix_fallocate_works=no
1177    ])
1178])
1179if test $i_cv_posix_fallocate_works = yes; then
1180   AC_DEFINE(HAVE_POSIX_FALLOCATE,, Define if you have a working posix_fallocate())
1181fi
1182
1183#
1184# EMU_THR_LIB_NAME, EMU_THR_LIBS, EMU_THR_X_LIBS, and EMU_THR_DEFS is
1185# used by the emulator, and can (but should not) be used by applications
1186# that only require thread support when the emulator has thread support.
1187# Other applications should use ETHR_LIB_NAME, ETHR_LIBS, ETHR_X_LIBS,
1188# and ETHR_DEFS.
1189#
1190
1191EMU_THR_LIB_NAME=
1192EMU_THR_X_LIBS=
1193EMU_THR_LIBS=
1194EMU_THR_DEFS=
1195
1196# Threads enabled for emulator
1197EMU_THR_LIB_NAME=$ETHR_LIB_NAME
1198EMU_THR_X_LIBS=$ETHR_X_LIBS
1199EMU_THR_LIBS=$ETHR_LIBS
1200EMU_THR_DEFS=$ETHR_DEFS
1201ENABLE_ALLOC_TYPE_VARS="$ENABLE_ALLOC_TYPE_VARS threads"
1202AC_MSG_CHECKING(whether lock checking should be enabled)
1203AC_MSG_RESULT($enable_lock_check)
1204if test "x$enable_lock_check" != "xno"; then
1205    EMU_THR_DEFS="$EMU_THR_DEFS -DERTS_ENABLE_LOCK_CHECK"
1206fi
1207
1208AC_MSG_CHECKING(whether lock counters should be enabled)
1209AC_MSG_RESULT($enable_lock_count)
1210if test "x$enable_lock_count" != "xno"; then
1211    TYPES="$TYPES lcnt"
1212fi
1213
1214case $host_os in
1215    linux*)
1216	AC_MSG_CHECKING([whether dlopen() needs to be called before first call to dlerror()])
1217	if test "x$ETHR_THR_LIB_BASE_TYPE" != "xposix_nptl"; then
1218	    AC_DEFINE(ERTS_NEED_DLOPEN_BEFORE_DLERROR,[1],
1219		[Define if dlopen() needs to be called before first call to dlerror()])
1220		AC_MSG_RESULT(yes)
1221	else
1222		AC_MSG_RESULT(no)
1223	fi
1224	;;
1225    *)
1226	;;
1227esac
1228
1229# Remove -D_WIN32_WINNT*, -DWINVER* and -D_GNU_SOURCE from EMU_THR_DEFS
1230# (defined in CFLAGS). Note that we want to keep these flags
1231# in ETHR_DEFS, but not in EMU_THR_DEFS.
1232new_emu_thr_defs=
1233for thr_def in $EMU_THR_DEFS; do
1234    case $thr_def in
1235	-D_GNU_SOURCE*|-D_WIN32_WINNT*|-DWINVER*)
1236	    ;;
1237	*)
1238	    new_emu_thr_defs="$new_emu_thr_defs $thr_def"
1239	    ;;
1240    esac
1241done
1242EMU_THR_DEFS=$new_emu_thr_defs
1243
1244AC_SUBST(EMU_THR_LIB_NAME)
1245AC_SUBST(EMU_THR_X_LIBS)
1246AC_SUBST(EMU_THR_LIBS)
1247AC_SUBST(EMU_THR_DEFS)
1248
1249if test "x$enable_lock_check" = "xno"; then
1250    EMU_LOCK_CHECKING=no
1251else
1252    EMU_LOCK_CHECKING=yes
1253fi
1254
1255AC_SUBST(EMU_LOCK_CHECKING)
1256
1257ERL_INTERNAL_LIBS
1258
1259dnl THR_LIBS and THR_DEFS are only used by odbc
1260THR_LIBS=$ETHR_X_LIBS
1261THR_DEFS=$ETHR_DEFS
1262
1263AC_SUBST(THR_LIBS)
1264AC_SUBST(THR_DEFS)
1265
1266dnl ----------------------------------------------------------------------
1267dnl Try to figure out where to get the termcap functions from.
1268dnl We use tgetent(), tgetflag(), tgetnum(), tgetstr() and tputs()
1269dnl ----------------------------------------------------------------------
1270
1271TERMCAP_LIB=
1272
1273if test "x$with_termcap" != "xno" &&
1274   test "X$host" != "Xwin32"; then
1275    # try these libs
1276    termcap_libs="tinfo ncurses curses termcap termlib"
1277
1278    for termcap_lib in $termcap_libs; do
1279	AC_CHECK_LIB($termcap_lib, tgetent, TERMCAP_LIB="-l$termcap_lib")
1280	if test "x$TERMCAP_LIB" != "x"; then
1281	    break
1282	fi
1283    done
1284
1285    if test "x$TERMCAP_LIB" = "x"; then
1286	AC_MSG_ERROR([No curses library functions found])
1287    fi
1288fi
1289
1290AC_SUBST(TERMCAP_LIB)
1291
1292if test "x$TERMCAP_LIB" != "x"; then
1293
1294	AC_DEFINE(HAVE_TERMCAP, 1, [Define if termcap functions exists])
1295fi
1296
1297if test "X$host" != "Xwin32"; then
1298    AC_MSG_CHECKING(for wcwidth)
1299    AC_TRY_LINK([#include <wchar.h>], [wcwidth(0);],
1300                have_wcwidth=yes, have_wcwidth=no)
1301    if test $have_wcwidth = yes; then
1302        AC_MSG_RESULT([yes])
1303        AC_DEFINE(HAVE_WCWIDTH, [1],
1304                  [Define to 1 if you have a `wcwidth' function.])
1305    fi
1306fi
1307
1308dnl -------------
1309dnl zlib
1310dnl -------------
1311
1312AC_ARG_ENABLE(builtin-zlib,
1313  AS_HELP_STRING([--enable-builtin-zlib],
1314                 [force use of our own built-in zlib]),
1315  [ case "$enableval" in
1316      no) enable_builtin_zlib=no ;;
1317      *)  enable_builtin_zlib=yes ;;
1318    esac ], enable_builtin_zlib=no)
1319
1320Z_LIB=
1321
1322if test "x$enable_builtin_zlib" = "xyes"; then
1323  AC_DEFINE(HAVE_ZLIB_INFLATEGETDICTIONARY, 1,
1324            [Define if your zlib version defines inflateGetDictionary.])
1325  AC_MSG_NOTICE([Using our own built-in zlib source])
1326else
1327AC_MSG_CHECKING(for zlib 1.2.5 or higher)
1328zlib_save_LIBS=$LIBS
1329LIBS="-lz $LIBS"
1330AC_LINK_IFELSE(
1331 [AC_LANG_PROGRAM([[
1332#include "zlib.h"
1333]],[[
1334#if ZLIB_VERNUM >= 0x1250
1335  Bytef s[1];
1336  s[0] = 0;
1337  (void) adler32((uLong)0, s, 1);
1338#else
1339#error "No zlib 1.2.5 or higher found"
1340error
1341#endif
1342]])],
1343[
1344 Z_LIB="-lz"
1345 AC_DEFINE(HAVE_LIBZ, 1, [Define to 1 if you have the `z' library (-lz).])
1346 AC_MSG_RESULT(yes)
1347],[
1348 AC_MSG_RESULT(no)
1349])
1350
1351if test "$Z_LIB" != ""; then
1352  AC_MSG_CHECKING(for zlib inflateGetDictionary presence)
1353  AC_SEARCH_LIBS(inflateGetDictionary, [z],
1354                 AC_DEFINE(HAVE_ZLIB_INFLATEGETDICTIONARY, 1,
1355                           [Define if your zlib version defines inflateGetDictionary.]))
1356fi
1357
1358LIBS=$zlib_save_LIBS
1359
1360fi
1361AC_SUBST(Z_LIB)
1362
1363
1364dnl -------------
1365dnl esock
1366dnl -------------
1367
1368AC_ARG_ENABLE(esock,
1369AS_HELP_STRING([--enable-esock], [enable builtin experimental socket (as a nif) support (default)])
1370AS_HELP_STRING([--disable-esock], [disable builtin experimental socket (as a nif) support]))
1371
1372dnl Default value
1373USE_ESOCK=yes
1374
1375if test "x$enable_esock" = "xyes"; then
1376    USE_ESOCK=yes
1377else
1378    if test "x$enable_esock" = "xno"; then
1379        USE_ESOCK=no
1380    fi
1381fi
1382
1383if test "x$USE_ESOCK" = "xyes"; then
1384    if test "x$USE_ESOCK" = "xyes"; then
1385        AC_CHECK_FUNCS([localtime_r strftime])
1386    fi
1387fi
1388
1389AC_SUBST(USE_ESOCK)
1390
1391
1392dnl *** ESOCK_USE_RCVSNDTIMEO ***
1393
1394AC_ARG_ENABLE(esock_use_rcvsndtimeo,
1395AS_HELP_STRING([--enable-esock-rcvsndtimeo], [enable use of the option(s) rcvtimeo and sndtimeo])
1396AS_HELP_STRING([--disable-esock-rcvsndtimeo], [disable use of the option(s) rcvtimeo and sndtimeo (default)]))
1397
1398if test "x$enable_esock_rcvsndtimeo" = "xyes"; then
1399    AC_DEFINE(ESOCK_USE_RCVSNDTIMEO, [1], [Use SO_[RCV|SND]TMIEO])
1400fi
1401
1402
1403dnl *** ESOCK_COUNTER_SIZE ***
1404
1405AC_ARG_WITH(esock-counter-size,
1406AS_HELP_STRING([--with-esock-counter-size=SZ],
1407               [Size of the esock counters, in number of bits: 16 | 24 | 32 | 48 | 64; default is 64]),
1408[],
1409[with_esock_counter_size=64])
1410
1411case "$with_esock_counter_size" in
1412     16)
1413	AC_DEFINE(ESOCK_COUNTER_SIZE, [16], [ESOCK counter size])
1414	;;
1415     24)
1416	AC_DEFINE(ESOCK_COUNTER_SIZE, [24], [ESOCK counter size])
1417	;;
1418     32)
1419	AC_DEFINE(ESOCK_COUNTER_SIZE, [32], [ESOCK counter size])
1420	;;
1421     48)
1422	AC_DEFINE(ESOCK_COUNTER_SIZE, [48], [ESOCK counter size])
1423	;;
1424     64)
1425	AC_DEFINE(ESOCK_COUNTER_SIZE, [64], [ESOCK counter size])
1426	;;
1427     *)
1428	AC_MSG_WARN([Invalid esock counter size ($with_esock_counter_size), using default (64)])
1429	AC_DEFINE(ESOCK_COUNTER_SIZE, [64], [ESOCK counter size])
1430	dnl with_esock_counter_size=64
1431	;;
1432esac
1433dnl ESOCK_COUNTER_SIZE=$with_esock_counter_size
1434
1435dnl We don't actually (currently) use this in erlang
1436dnl AC_SUBST(ESOCK_COUNTER_SIZE)
1437
1438dnl Checks for the net nif
1439AC_CHECK_FUNC([if_nametoindex],
1440              [AC_DEFINE(HAVE_IF_NAMETOINDEX, [1],
1441	                 [Define as 1 if function exists])]
1442	      [])
1443AC_CHECK_FUNC([if_indextoname],
1444              [AC_DEFINE(HAVE_IF_INDEXTONAME, [1],
1445	                 [Define as 1 if function exists])],
1446	      [])
1447AC_CHECK_FUNC([if_nameindex],
1448              [AC_DEFINE(HAVE_IF_NAMEINDEX, [1],
1449	                 [Define as 1 if function exists])],
1450	      [])
1451AC_CHECK_FUNC([if_freenameindex],
1452              [AC_DEFINE(HAVE_IF_FREENAMEINDEX, [1],
1453	                 [Define as 1 if function exists])]
1454	      [])
1455AC_CHECK_FUNC([gethostname],
1456              [AC_DEFINE(HAVE_GETHOSTNAME, [1],
1457	                 [Define as 1 if function exists])]
1458	      [])
1459
1460
1461dnl *** ESOCK_USE_SOCKET_REGISTRY ***
1462dnl At this time we *enable* use of the socket regstry by default
1463dnl since we want to be able to have as much debug info as possible.
1464
1465AC_ARG_ENABLE(esock_use_socket_registry,
1466AS_HELP_STRING([--enable-esock-socket-registry], [enable use of the socket registry by default (default)])
1467AS_HELP_STRING([--disable-esock-socket-registry], [disable use of the socket registry by default]))
1468
1469if test "x$enable_esock_socket_registry" = "xyes"; then
1470    AC_DEFINE(ESOCK_USE_SOCKET_REGISTRY, [1], [Use socket registry by default])
1471else
1472    if test "x$disable_esock_socket_registry" = "xyes"; then
1473        AC_DEFINE(ESOCK_USE_SOCKET_REGISTRY, [0], [Don't use socket registry by default])
1474    else
1475        # TEMPORARY default (enabled)
1476        AC_DEFINE(ESOCK_USE_SOCKET_REGISTRY, [1], [Use socket registry by default])
1477    fi
1478fi
1479
1480
1481
1482dnl
1483dnl This test kindly borrowed from Tcl
1484dnl
1485#--------------------------------------------------------------------
1486#	Check for the existence of the -lsocket and -lnsl libraries.
1487#	The order here is important, so that they end up in the right
1488#	order in the command line generated by make.  Here are some
1489#	special considerations:
1490#	1. Use "connect" and "accept" to check for -lsocket, and
1491#	   "gethostbyname" to check for -lnsl.
1492#	2. Use each function name only once:  can't redo a check because
1493#	   autoconf caches the results of the last check and won't redo it.
1494#	3. Use -lnsl and -lsocket only if they supply procedures that
1495#	   aren't already present in the normal libraries.  This is because
1496#	   IRIX 5.2 has libraries, but they aren't needed and they're
1497#	   bogus:  they goof up name resolution if used.
1498#	4. On some SVR4 systems, can't use -lsocket without -lnsl too.
1499#	   To get around this problem, check for both libraries together
1500#	   if -lsocket doesn't work by itself.
1501#--------------------------------------------------------------------
1502
1503tk_oldLibs=$LIBS
1504erl_checkBoth=0
1505SOCKET_LIBS=""
1506AC_CHECK_FUNC(connect, erl_checkSocket=0, erl_checkSocket=1)
1507if test "$erl_checkSocket" = 1; then
1508    AC_CHECK_LIB(socket, main, SOCKET_LIBS="-lsocket", erl_checkBoth=1)
1509fi
1510
1511if test "$erl_checkBoth" = 1; then
1512    LIBS="$LIBS -lsocket -lnsl"
1513    AC_CHECK_FUNC(accept, SOCKET_LIBS="-lsocket -lnsl")
1514fi
1515
1516LIBS="$tk_oldLibs $SOCKET_LIBS"
1517AC_CHECK_FUNC(gethostbyname, , AC_CHECK_LIB(nsl, main, [SOCKET_LIBS="$SOCKET_LIBS -lnsl"]))
1518AC_CHECK_FUNC(gethostbyname_r,have_gethostbyname_r=yes)
1519
1520LIBS="$tk_oldLibs $SOCKET_LIBS"
1521
1522AC_SUBST(SOCKET_LIBS)
1523
1524dnl
1525dnl These gethostbyname thingies use old style AC_DEFINE for BC with ancient
1526dnl autoconf...
1527dnl
1528
1529if test "$have_gethostbyname_r" = yes; then
1530	# OK, so we have gethostbyname_r() - but do we know how to call it...?
1531	# (if not, HAVE_GETHOSTBYNAME_R will not be defined at all)
1532	case $host_os in
1533		solaris2*)
1534			AC_DEFINE(HAVE_GETHOSTBYNAME_R, GHBN_R_SOLARIS,
1535				[Define to flavour of gethostbyname_r])
1536		;;
1537		aix*|os400*)
1538			# AIX version also needs "struct hostent_data" defn
1539			AC_TRY_COMPILE([#include <netdb.h>],
1540				[struct hostent_data hd;],
1541				AC_DEFINE(HAVE_GETHOSTBYNAME_R, GHBN_R_AIX,
1542				    [Define to flavour of gethostbyname_r]))
1543		;;
1544		*)
1545			AC_EGREP_CPP(^yes$,[
1546#include <stdio.h>
1547#ifdef __GLIBC__
1548yes
1549#endif
1550			  ], AC_DEFINE(HAVE_GETHOSTBYNAME_R, GHBN_R_GLIBC,
1551				[Define to flavour of gethostbyname_r]))
1552		;;
1553	esac
1554fi
1555
1556AC_MSG_CHECKING(for working posix_openpt implementation)
1557AC_TRY_LINK([
1558#define _XOPEN_SOURCE 600
1559#include <stdlib.h>
1560#include <fcntl.h>
1561],
1562[
1563    int mfd = posix_openpt(O_RDWR);
1564    ptsname(mfd);
1565    grantpt(mfd);
1566    unlockpt(mfd);
1567    return mfd;
1568], working_posix_openpt=yes, working_posix_openpt=no)
1569
1570if test "X$working_posix_openpt" = "Xyes"; then
1571    AC_DEFINE(HAVE_WORKING_POSIX_OPENPT, [1],
1572	      [Define if you have a working posix_openpt implementation])
1573    AC_MSG_RESULT(yes)
1574else
1575    AC_MSG_RESULT(no)
1576fi
1577
1578dnl Check for usage of sockaddr_in in netdb.h
1579dnl somewhat ugly check, I check for presence of the string and that
1580dnl compilation works. If either fails I assume it's not needed.
1581dnl Seems only to be needed on a patched version of solaris2.5.1, with
1582dnl netdb.h  version  1.18.
1583AC_MSG_CHECKING([if netdb.h requires netinet/in.h to be previously included])
1584AC_EGREP_CPP(sockaddr_in,
1585	     [#include <netdb.h>],
1586	     AC_TRY_COMPILE([#include <netinet/in.h>
1587			     #include <netdb.h>],
1588			    [return 0;],
1589			    need_in_h=yes,
1590                            need_in_h=no),
1591             need_in_h=no)
1592
1593if test $need_in_h = yes; then
1594	AC_DEFINE(NETDB_H_NEEDS_IN_H,[1],
1595		[Define if netdb.h needs struct sockaddr_in ans in.h CAN be included before])
1596	AC_MSG_RESULT(yes)
1597else
1598	AC_MSG_RESULT(no)
1599fi
1600
1601dnl Check for type socklen_t
1602dnl
1603AC_MSG_CHECKING([for socklen_t])
1604AC_TRY_COMPILE( [#include <sys/socket.h>],
1605		[socklen_t test;],
1606		have_socklen_t=yes,
1607                have_socklen_t=no),
1608
1609if test $have_socklen_t = yes; then
1610	AC_DEFINE(HAVE_SOCKLEN_T,[1],[Define if we have socklen_t])
1611	AC_MSG_RESULT(yes)
1612else
1613	AC_MSG_RESULT(no)
1614fi
1615
1616
1617dnl h_errno isn't always declared in netdb.h, and with some definitions
1618dnl (e.g. function call for thread-safe) a simple 'extern int' may conflict
1619dnl (we do assume that h_errno exists at all...)
1620AC_CACHE_CHECK([for h_errno declaration in netdb.h],
1621  ac_cv_decl_h_errno,
1622[AC_TRY_COMPILE([#include <netdb.h>], [int err = h_errno;],
1623  ac_cv_decl_h_errno=yes, ac_cv_decl_h_errno=no)])
1624if test $ac_cv_decl_h_errno = yes; then
1625  AC_DEFINE(H_ERRNO_DECLARED,[1],
1626	[define if h_errno is declared (in some way) in a system header file])
1627fi
1628
1629
1630dnl ----------------------------------------------------------------------
1631dnl Checks for header files.
1632dnl ----------------------------------------------------------------------
1633
1634dnl We sometimes need EMU_THR_DEFS in order to find certain headers.
1635saved_cppflags=$CPPFLAGS
1636CPPFLAGS="$CPPFLAGS $EMU_THR_DEFS"
1637
1638AC_HEADER_DIRENT
1639AC_HEADER_STDC
1640AC_HEADER_SYS_WAIT
1641AC_HEADER_TIME
1642
1643dnl Interactive UX needs <net/errno.h> for socket related error codes.
1644dnl Some Linuxes needs <sys/socketio.h> instead of <sys/sockio.h>
1645dnl
1646AC_CHECK_HEADERS(fcntl.h limits.h unistd.h syslog.h dlfcn.h ieeefp.h \
1647                 sys/types.h sys/stropts.h sys/sysctl.h \
1648                 sys/ioctl.h sys/time.h sys/uio.h sys/mman.h \
1649                 sys/socket.h sys/sockio.h sys/socketio.h \
1650                 net/errno.h malloc.h arpa/nameser.h libdlpi.h \
1651		 pty.h util.h libutil.h utmp.h langinfo.h poll.h sdkddkver.h)
1652
1653AC_CHECK_MEMBERS([struct ifreq.ifr_hwaddr], [], [],
1654	[#ifdef __WIN32__
1655	 #else
1656	 #include <net/if.h>
1657	 #endif
1658	])
1659
1660AC_CHECK_MEMBERS([struct ifreq.ifr_enaddr], [], [],
1661	[#ifdef __WIN32__
1662	 #else
1663	 #include <net/if.h>
1664	 #endif
1665	])
1666
1667dnl ----------------------------------------------------------------------
1668dnl  Check the availability of systemd
1669dnl ----------------------------------------------------------------------
1670if test x"$enable_systemd" != x"no"; then
1671
1672systemd_daemon_save_LIBS=$LIBS
1673LIBS=
1674AC_SEARCH_LIBS(sd_listen_fds,[systemd systemd-daemon],
1675  [have_sd_listen_fds=yes],[have_sd_listen_fds=no],$systemd_daemon_save_LIBS)
1676AC_SEARCH_LIBS(sd_notify,[systemd systemd-daemon],
1677  [have_sd_notify=yes],[have_sd_notify=no],$systemd_daemon_save_LIBS)
1678AC_CHECK_HEADERS(systemd/sd-daemon.h,
1679  [have_systemd_sd_daemon_h=yes],[have_systemd_sd_daemon_h=no])
1680
1681if test x"$have_sd_listen_fds" = x"yes" && \
1682   test x"$have_sd_notify" = x"yes" && \
1683   test x"$have_systemd_sd_daemon_h" = x"yes"; then
1684  AC_DEFINE([HAVE_SYSTEMD_DAEMON],[1],[Define if you have systemd daemon])
1685  SYSTEMD_DAEMON_LIBS=$LIBS
1686elif test x"$enable_systemd" = x"yes"; then
1687  AC_MSG_FAILURE([--enable-systemd was given, but test for systemd failed])
1688fi
1689LIBS=$systemd_daemon_save_LIBS
1690fi
1691AC_SUBST(SYSTEMD_DAEMON_LIBS)
1692
1693
1694dnl ----------------------------------------------------------------------
1695dnl Check the availability for libdlpi
1696dnl ----------------------------------------------------------------------
1697AC_CHECK_LIB(dlpi, dlpi_open)
1698if test x"$ac_cv_lib_dlpi_dlpi_open" = x"no"; then
1699   unset -v ac_cv_lib_dlpi_dlpi_open
1700   dnl Try again now with -L/lib (or ditto 64) as argument to linker since
1701   dnl gcc makes /usr/ccs/bin/ld ignore the crle configured linker default paths
1702   dnl typically causing dlpi not being found on Solaris et.al
1703   save_ldflags="$LDFLAGS"
1704   try_dlpi_lib=/lib
1705   if test x"$ac_cv_sizeof_void_p" = x"8"; then
1706      if test -d /lib64; then
1707	 try_dlpi_lib=/lib64
1708      elif test -d /lib/64; then
1709	 try_dlpi_lib=/lib/64
1710      fi
1711   fi
1712   if test ! -f "$try_dlpi_lib/libdlpi.so" && \
1713      test -f "$try_dlpi_lib/libdlpi.so.1"
1714   then
1715      dnl It looks like there is a missing symlink
1716      dnl - let's be helpful and notify the user
1717      dnl NOTE this help is far from perfect e.g if there would be no
1718      dnl *.so.1 but a *.so.1.123 or *.so.2 this will be no help
1719      AC_MSG_ERROR(
1720	[Your OS installation is missing a symbolic link.
1721	Maybe it lacks some development package(s)...
1722	It can anyhow be fixed with the following command:
1723	# ln -s libdlpi.so.1 $try_dlpi_lib/libdlpi.so
1724	])
1725   fi
1726   LDFLAGS="-L$try_dlpi_lib -R$try_dlpi_lib $LDFLAGS"
1727   unset -v try_dlpi_lib
1728   AC_MSG_NOTICE([Extending the search to include /lib])
1729   AC_CHECK_LIB(dlpi, dlpi_open)
1730   if test x"$ac_cv_lib_dlpi_dlpi_open" = x"no"; then
1731      LDFLAGS="$save_ldflags"
1732   fi
1733   unset -v save_ldflags
1734fi
1735
1736AC_CHECK_HEADER(sys/resource.h,
1737	[AC_DEFINE(HAVE_SYS_RESOURCE_H, 1,
1738		[Define to 1 if you have the <sys/resource.h> header file])
1739	 AC_CHECK_DECLS([getrlimit, setrlimit, RLIMIT_STACK],
1740		[],[],
1741		[#include <sys/resource.h>])],
1742	[],[])
1743
1744AC_CHECK_FUNCS([getrusage])
1745
1746dnl Check if we have kernel poll support
1747have_kernel_poll=no
1748AC_CHECK_HEADER(sys/event.h, have_kernel_poll=kqueue)
1749AC_CHECK_HEADER(sys/epoll.h, have_kernel_poll=epoll)
1750AC_CHECK_HEADER(sys/devpoll.h, have_kernel_poll=/dev/poll)
1751
1752dnl Check if we have timerfds to be used for high accuracy
1753dnl epoll_wait timeouts
1754AC_CHECK_HEADERS([sys/timerfd.h])
1755
1756dnl Check if we have the header file 'netpacket/packat.h' in which
1757dnl type 'struct sockaddr_ll' is defined.
1758AC_CHECK_HEADERS([netpacket/packet.h],
1759	have_netpacket_packet_h=yes,
1760	have_netpacket_packet_h=no)
1761
1762dnl Check for kernel SCTP support
1763AC_SUBST(LIBSCTP)
1764if test "x$enable_sctp" != "xno" ; then
1765    AC_CHECK_HEADER(netinet/sctp.h,
1766        [LIBSCTP=libsctp.so.1
1767	 AC_DEFINE(HAVE_SCTP_H, [1],
1768            [Define to 1 if you have the <netinet/sctp.h> header file])],
1769	[],
1770	[#if HAVE_SYS_SOCKET_H
1771	 #include <sys/socket.h>
1772	 #endif
1773	])
1774fi
1775
1776if test x"$ac_cv_header_netinet_sctp_h" = x"yes"; then
1777    AS_IF([test "x$enable_sctp" = "xlib"],
1778        AC_CHECK_LIB(sctp, sctp_bindx))
1779    AC_CHECK_FUNCS([sctp_bindx sctp_peeloff sctp_getladdrs sctp_freeladdrs sctp_getpaddrs sctp_freepaddrs])
1780        AC_CHECK_MEMBERS([struct sctp_accoc_value.assoc_id], [], [],
1781        [#if HAVE_SYS_SOCKET_H
1782         #include <sys/socket.h>
1783         #endif
1784         #include <netinet/sctp.h>
1785        ])
1786    AC_CHECK_DECLS([SCTP_UNORDERED, SCTP_ADDR_OVER, SCTP_ABORT,
1787                    SCTP_EOF, SCTP_SENDALL, SCTP_ADDR_CONFIRMED,
1788		    SCTP_DELAYED_ACK_TIME,
1789		    SCTP_EMPTY, SCTP_UNCONFIRMED,
1790		    SCTP_CLOSED, SCTPS_IDLE,
1791		    SCTP_BOUND, SCTPS_BOUND,
1792		    SCTP_LISTEN, SCTPS_LISTEN,
1793		    SCTP_COOKIE_WAIT, SCTPS_COOKIE_WAIT,
1794		    SCTP_COOKIE_ECHOED, SCTPS_COOKIE_ECHOED,
1795		    SCTP_ESTABLISHED, SCTPS_ESTABLISHED,
1796		    SCTP_SHUTDOWN_PENDING, SCTPS_SHUTDOWN_PENDING,
1797		    SCTP_SHUTDOWN_SENT, SCTPS_SHUTDOWN_SENT,
1798		    SCTP_SHUTDOWN_RECEIVED, SCTPS_SHUTDOWN_RECEIVED,
1799		    SCTP_SHUTDOWN_ACK_SENT, SCTPS_SHUTDOWN_ACK_SENT], [], [],
1800        [#if HAVE_SYS_SOCKET_H
1801         #include <sys/socket.h>
1802         #endif
1803         #include <netinet/sctp.h>
1804        ])
1805    AC_CHECK_MEMBERS([struct sctp_paddrparams.spp_pathmtu,
1806                      struct sctp_paddrparams.spp_sackdelay,
1807                      struct sctp_paddrparams.spp_flags,
1808                      struct sctp_remote_error.sre_data,
1809                      struct sctp_send_failed.ssf_data,
1810                      struct sctp_event_subscribe.sctp_authentication_event,
1811                      struct sctp_event_subscribe.sctp_sender_dry_event], [], [],
1812        [#if HAVE_SYS_SOCKET_H
1813         #include <sys/socket.h>
1814         #endif
1815         #include <netinet/sctp.h>
1816        ])
1817fi
1818
1819dnl Check for setns
1820AC_CHECK_HEADERS(sched.h setns.h)
1821AC_CHECK_FUNCS([setns])
1822
1823dnl Check for linux/errqueue
1824AC_CHECK_HEADERS(linux/errqueue.h)
1825
1826HAVE_VALGRIND=no
1827AC_CHECK_HEADER(valgrind/valgrind.h, HAVE_VALGRIND=yes)
1828AC_SUBST(HAVE_VALGRIND)
1829
1830LM_DECL_SO_BSDCOMPAT
1831LM_DECL_INADDR_LOOPBACK
1832LM_DECL_SYS_ERRLIST
1833
1834AC_CACHE_CHECK([if windows.h includes winsock2.h],
1835		erts_cv_windows_h_includes_winsock2_h,
1836		AC_TRY_COMPILE([#include <windows.h>
1837				],
1838			       [#ifndef _WINSOCK2API_
1839				#error winsock2.h not included
1840				#endif
1841				int i = 1;
1842				],
1843			       erts_cv_windows_h_includes_winsock2_h=yes,
1844			       erts_cv_windows_h_includes_winsock2_h=no))
1845if test $erts_cv_windows_h_includes_winsock2_h = yes; then
1846	AC_DEFINE(WINDOWS_H_INCLUDES_WINSOCK2_H, 1, \
1847[Define if windows.h includes winsock2.h])
1848fi
1849
1850dnl restore CPPFLAGS
1851CPPFLAGS=$saved_cppflags
1852
1853dnl ----------------------------------------------------------------------
1854dnl Checks for typedefs, structures, and compiler characteristics.
1855dnl ----------------------------------------------------------------------
1856
1857AC_C_CONST
1858AC_TYPE_SIGNAL
1859AC_TYPE_OFF_T
1860AC_TYPE_PID_T
1861AC_TYPE_SIZE_T
1862
1863AC_STRUCT_TM
1864LM_STRUCT_SOCKADDR_SA_LEN
1865LM_STRUCT_EXCEPTION
1866
1867AC_CHECK_SIZEOF(char, 1)
1868AC_CHECK_SIZEOF(short)
1869AC_CHECK_SIZEOF(int)
1870AC_CHECK_SIZEOF(long)
1871AC_CHECK_SIZEOF(void *)
1872AC_CHECK_SIZEOF(long long)
1873AC_CHECK_SIZEOF(size_t)
1874AC_CHECK_SIZEOF(off_t)
1875AC_CHECK_SIZEOF(time_t)
1876AC_CHECK_SIZEOF(suseconds_t)
1877
1878BITS64=
1879
1880if test $ac_cv_sizeof_void_p = 8; then
1881  BITS64=yes
1882fi
1883AC_SUBST(BITS64)
1884
1885AC_MSG_CHECKING([for C compiler 'restrict' support])
1886restrict_keyword=""
1887for x in restrict __restrict; do
1888    AC_TRY_COMPILE([int * $x foo(int * $x arg);
1889		    int * $x foo(int * $x arg)
1890		        { int * $x var=arg; return var;}
1891		   ],[],
1892		   [restrict_keyword=$x],[])
1893    if test "x$restrict_keyword" != "x"; then
1894	break
1895    fi
1896done
1897AC_DEFINE_UNQUOTED(ERTS_RESTRICT,[$restrict_keyword],[Type qualifier restrict])
1898if test "x$restrict_keyword" != "x"; then
1899   AC_MSG_RESULT(yes)
1900else
1901   AC_MSG_RESULT(no)
1902fi
1903
1904if test "x$ac_compiler_gnu" = "xyes"; then
1905AC_MSG_CHECKING([if we should add -fno-tree-copyrename to CFLAGS for computed gotos to work properly])
1906## tree-copyrename was broken in gcc 4.3 and then removed in gcc 6
1907AC_TRY_COMPILE([],[
1908		#if (__GNUC__ > 4 && __GNUC__ < 6)  || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
1909			;
1910			#else
1911			#error old and ok
1912			#endif
1913			],
1914			no_tree_copyrename=yes,
1915			no_tree_copyrename=no)
1916
1917if test "x$no_tree_copyrename" = "xyes"; then
1918	CFLAGS="$CFLAGS -fno-tree-copyrename"
1919	AC_MSG_RESULT(yes, adjusting CFLAGS)
1920else
1921	AC_MSG_RESULT(no)
1922fi
1923
1924AC_MSG_CHECKING([for broken gcc-4.3.0 compiler])
1925AC_TRY_RUN([
1926/* pr36339.c */
1927extern void abort (void);
1928
1929typedef unsigned long my_uintptr_t;
1930
1931int check_a(my_uintptr_t tagged_ptr);
1932
1933int __attribute__((noinline)) try_a(my_uintptr_t x)
1934{
1935  my_uintptr_t heap[2];
1936  my_uintptr_t *hp = heap;
1937
1938  hp[0] = x;
1939  hp[1] = 0;
1940  return check_a((my_uintptr_t)(void*)((char*)hp + 1));
1941}
1942
1943int __attribute__((noinline)) check_a(my_uintptr_t tagged_ptr)
1944{
1945  my_uintptr_t *hp = (my_uintptr_t*)(void*)((char*)tagged_ptr - 1);
1946
1947  if (hp[0] == 42 && hp[1] == 0)
1948    return 0;
1949  return -1;
1950}
1951
1952int main(void)
1953{
1954  if (try_a(42) < 0)
1955    abort ();
1956  return 0;
1957}
1958], gcc_4_3_0_bug=no, gcc_4_3_0_bug=yes, gcc_4_3_0_bug=cross)
1959
1960case $gcc_4_3_0_bug in
1961	yes|no)
1962		gcc_4_3_0_bug_result=$gcc_4_3_0_bug;;
1963	cross)
1964		gcc_dumped_vsn=`$CC -dumpversion 2>/dev/null`
1965		case gcc-$gcc_dumped_vsn in
1966			gcc-4.3.0) gcc_4_3_0_bug=yes;;
1967			*) gcc_4_3_0_bug=no;;
1968		esac
1969		gcc_4_3_0_bug_result="$gcc_4_3_0_bug; could not run test since cross compiling, checked version number ($gcc_dumped_vsn) instead";;
1970esac
1971
1972AC_MSG_RESULT([$gcc_4_3_0_bug_result])
1973if test $gcc_4_3_0_bug = yes; then
1974	AC_MSG_ERROR([This gcc miscompiles the Erlang runtime system; please use a different version])
1975fi
1976
1977fi
1978
1979case X$erl_xcomp_bigendian in
1980    X) ;;
1981    Xyes|Xno) ac_cv_c_bigendian=$erl_xcomp_bigendian;;
1982    *) AC_MSG_ERROR([Bad erl_xcomp_bigendian value: $erl_xcomp_bigendian]);;
1983esac
1984
1985AC_C_BIGENDIAN(
1986	[
1987	 AC_DEFINE([WORDS_BIGENDIAN], [1], [Define if big-endian])
1988	 AC_DEFINE([ERTS_ENDIANNESS], [1], [Define > 0 if big-endian < 0 if little-endian, or 0 if unknown])
1989	],
1990	[
1991	 AC_DEFINE([ERTS_ENDIANNESS], [-1], [Define > 0 if big-endian < 0 if little-endian, or 0 if unknown])
1992	],
1993	[
1994	  case "$erl_xcomp_bigendian" in
1995	    yes)
1996	     AC_DEFINE([ERTS_ENDIANNESS], [1], [Define > 0 if big-endian < 0 if little-endian, or 0 if unknown]);;
1997	    no)
1998	     AC_DEFINE([ERTS_ENDIANNESS], [-1], [Define > 0 if big-endian < 0 if little-endian, or 0 if unknown]);;
1999	    *)
2000	     AC_DEFINE([ERTS_ENDIANNESS], [0], [Define > 0 if big-endian < 0 if little-endian, or 0 if unknown]);;
2001	  esac
2002	])
2003
2004AC_C_DOUBLE_MIDDLE_ENDIAN
2005
2006dnl fdatasync syscall (Unix only)
2007AC_CHECK_FUNCS([fdatasync])
2008
2009dnl Find which C libraries are required to use fdatasync
2010dnl TODO: Remove check once SunOS >= 5.11 is required by erts.
2011dnl       fdatasync requires linking against -lrt on SunOS <= 5.10.
2012dnl       OpenSolaris 2009.06 is SunOS 5.11 and does not require -lrt.
2013AC_SEARCH_LIBS(fdatasync, [rt])
2014
2015
2016dnl sendfile syscall
2017case $host_os in
2018    linux*|freebsd*|dragonfly*|darwin*)
2019		AC_CHECK_FUNCS([sendfile])
2020		;;
2021    solaris*)
2022		AC_SEARCH_LIBS(sendfilev, sendfile,
2023			AC_DEFINE([HAVE_SENDFILEV],[1],
2024		           [Define to 1 if you have the `sendfilev' function.]))
2025		;;
2026    win32)
2027		LIBS="$LIBS -lmswsock"
2028		;;
2029    *)
2030		;;
2031esac
2032
2033dnl ----------------------------------------------------------------------
2034dnl Checks for library functions.
2035dnl ----------------------------------------------------------------------
2036
2037dnl We may need the thread library and thread flags in order to find right stuff
2038saved_cppflags=$CPPFLAGS
2039CPPFLAGS="$CPPFLAGS $EMU_THR_DEFS"
2040saved_libs=$LIBS
2041LIBS="$LIBS $EMU_THR_X_LIBS"
2042
2043dnl Check if we have these, in which case we'll try to build
2044dnl inet_gethost with ipv6 support.
2045AC_CHECK_HEADERS(windows.h)
2046AC_CHECK_HEADERS(winsock2.h)
2047AC_CHECK_HEADERS(ws2tcpip.h,[],[],[
2048#ifdef HAVE_WINSOCK2_H
2049#include <winsock2.h>
2050#endif
2051#ifdef HAVE_WINDOWS_H
2052#include <windows.h>
2053#endif
2054])
2055dnl AC_CHECK_FUNC(getaddrinfo, have_getaddrinfo=yes, have_getaddrinfo=no)
2056AC_MSG_CHECKING(for getaddrinfo)
2057AC_TRY_LINK([
2058#include <stdlib.h>
2059#include <string.h>
2060#ifdef HAVE_WINSOCK2_H
2061#include <winsock2.h>
2062#endif
2063#ifdef HAVE_WINDOWS_H
2064#include <windows.h>
2065#endif
2066#ifdef HAVE_WS2TCPIP_H
2067#include <ws2tcpip.h>
2068#endif
2069#ifndef __WIN32__
2070#include <sys/socket.h>
2071#include <netdb.h>
2072#endif
2073],
2074[
2075getaddrinfo("","",NULL,NULL);
2076],have_getaddrinfo=yes, have_getaddrinfo=no)
2077if test $have_getaddrinfo = yes; then
2078        AC_MSG_RESULT([yes])
2079        AC_MSG_CHECKING([whether getaddrinfo accepts enough flags])
2080        AC_TRY_LINK([
2081#include <stdlib.h>
2082#include <string.h>
2083#ifdef HAVE_WINSOCK2_H
2084#include <winsock2.h>
2085#endif
2086#ifdef HAVE_WINDOWS_H
2087#include <windows.h>
2088#endif
2089#ifdef HAVE_WS2TCPIP_H
2090#include <ws2tcpip.h>
2091#endif
2092#ifndef __WIN32__
2093#include <sys/socket.h>
2094#include <netdb.h>
2095#endif
2096],
2097[
2098    struct addrinfo hints, *ai;
2099    memset(&hints, 0, sizeof(hints));
2100    hints.ai_flags = AI_CANONNAME;
2101    hints.ai_socktype = SOCK_STREAM;
2102    hints.ai_family = AF_INET6;
2103    if (getaddrinfo("::", NULL, &hints, &ai) == 0) {
2104	freeaddrinfo(ai);
2105	exit(0);
2106    } else {
2107	exit(1);
2108    }
2109],, have_getaddrinfo=no)
2110	AC_MSG_RESULT($have_getaddrinfo)
2111	case $have_getaddrinfo in
2112	    yes)
2113		AC_DEFINE(HAVE_GETADDRINFO, [1],
2114		          [Define to 1 if you have a good `getaddrinfo' function.]);;
2115	    *) ;;
2116	esac
2117else
2118    AC_MSG_RESULT([no])
2119fi
2120AC_MSG_CHECKING(for getnameinfo)
2121AC_TRY_LINK([
2122#include <stdlib.h>
2123#include <string.h>
2124#ifdef HAVE_WINSOCK2_H
2125#include <winsock2.h>
2126#endif
2127#ifdef HAVE_WINDOWS_H
2128#include <windows.h>
2129#endif
2130#ifdef HAVE_WS2TCPIP_H
2131#include <ws2tcpip.h>
2132#endif
2133#ifndef __WIN32__
2134#include <sys/socket.h>
2135#include <netdb.h>
2136#endif
2137],
2138[
2139getnameinfo(NULL,0,NULL,0,NULL,0,0);
2140],have_getnameinfo=yes, have_getnameinfo=no)
2141if test $have_getnameinfo = yes; then
2142        AC_MSG_RESULT([yes])
2143	AC_DEFINE(HAVE_GETNAMEINFO, [1],
2144		  [Define to 1 if you have a good `getnameinfo' function.])
2145else
2146	AC_MSG_RESULT([no])
2147fi
2148
2149
2150AC_CHECK_FUNCS([getipnodebyname getipnodebyaddr gethostbyname2])
2151
2152AC_CHECK_FUNCS([ieee_handler fpsetmask finite isnan isinf res_gethostbyname dlopen \
2153		pread pwrite memmove strerror strerror_r strncasecmp \
2154		gethrtime localtime_r gmtime_r mprotect madvise posix_madvise \
2155		mmap mremap memcpy mallopt sbrk _sbrk __sbrk brk _brk __brk \
2156		flockfile fstat strlcpy strlcat setsid posix2time time2posix \
2157		setlocale nl_langinfo poll mlockall ppoll vsyslog])
2158
2159## We have a special check for inet_pton as AC_CHECK_FUCNS does not work
2160## on windows 32-bit as there a macro is used to rename the symbol...
2161AC_MSG_CHECKING([for inet_pton])
2162AC_TRY_LINK([
2163#ifdef WIN32
2164#include <ws2tcpip.h>
2165#else
2166#include <arpa/inet.h>
2167#endif
2168],[inet_pton(2,"",(void*)0)], have_inet_pton=yes, have_inet_pton=no)
2169
2170if test $have_inet_pton = yes; then
2171    AC_DEFINE(HAVE_INET_PTON,[1],
2172              [Define to 1 if you have the `inet_pton' function.])
2173    AC_MSG_RESULT(yes)
2174else
2175    AC_MSG_RESULT(no)
2176fi
2177
2178AC_MSG_CHECKING([for isfinite])
2179AC_TRY_LINK([#include <math.h>],
2180            [isfinite(0);], have_isfinite=yes, have_isfinite=no)
2181
2182if test $have_isfinite = yes; then
2183    AC_DEFINE(HAVE_ISFINITE,[1],
2184              [Define to 1 if you have the `isfinite' function.])
2185    AC_MSG_RESULT(yes)
2186else
2187    AC_MSG_RESULT(no)
2188fi
2189
2190case X$erl_xcomp_posix_memalign in
2191     Xno) ;;
2192     Xyes) have_posix_memalign=yes ;;
2193     *)
2194	AC_CHECK_FUNC(
2195		[posix_memalign],
2196                [if test "$cross_compiling" != yes; then
2197AC_TRY_RUN([
2198#include <stdlib.h>
2199int main(void) {
2200    void *ptr = NULL;
2201    int error;
2202    size_t alignment = 0x40000, size = 0x20028;
2203    if ((error = posix_memalign(&ptr, alignment, size)) != 0 || ptr == NULL)
2204      return error;
2205    return 0;
2206}
2207],have_posix_memalign=yes
2208)
2209		 else
2210			have_posix_memalign=yes
2211		 fi]);;
2212esac
2213
2214if test "$have_posix_memalign" = "yes"; then
2215   AC_DEFINE(HAVE_POSIX_MEMALIGN,[1],
2216	     [Define to 1 if you have the `posix_memalign' function.])
2217fi
2218
2219
2220dnl writev on OS X snow leopard is broken for files > 4GB
2221case $host_os in
2222        darwin10.8.0)
2223	    AC_MSG_CHECKING([for writev])
2224	    AC_MSG_RESULT(no, not stable on OS X Snow Leopard) ;;
2225        *)
2226	    AC_CHECK_FUNCS([writev]) ;;
2227esac
2228
2229AC_CHECK_DECLS([posix2time, time2posix],,,[#include <time.h>])
2230
2231AC_FUNC_VPRINTF
2232
2233dnl The AC_DEFINEs are necessary for autoheader to work. :-(
2234dnl for gzio
2235LM_CHECK_FUNC_DECL(fread, [extern int fread();],,
2236                   AC_DEFINE(HAVE_CONFLICTING_FREAD_DECLARATION,[1],[Define if you have a decl of fread that conflicts with int fread]))
2237
2238dnl Checking with TRY_LINK since putc_unlocked might be (probably is) a macro
2239AC_CACHE_CHECK([for putc_unlocked],
2240	erts_cv_putc_unlocked,
2241	AC_TRY_LINK([#include <stdio.h>],
2242		[int res = putc_unlocked('x',stdout);],
2243		erts_cv_putc_unlocked=yes,
2244             	erts_cv_putc_unlocked=no))
2245if test $erts_cv_putc_unlocked = yes; then
2246	AC_DEFINE(HAVE_PUTC_UNLOCKED, 1, [Define if you have putc_unlocked])
2247fi
2248
2249dnl Checking with TRY_LINK since fwrite_unlocked might be a macro
2250AC_CACHE_CHECK([for fwrite_unlocked],
2251	erts_cv_fwrite_unlocked,
2252	AC_TRY_LINK([#include <stdio.h>],
2253		[size_t res = fwrite_unlocked(NULL,sizeof(char),0,stdout);],
2254		erts_cv_fwrite_unlocked=yes,
2255             	erts_cv_fwrite_unlocked=no))
2256if test $erts_cv_fwrite_unlocked = yes; then
2257	AC_DEFINE(HAVE_FWRITE_UNLOCKED, 1, [Define if you have fwrite_unlocked])
2258fi
2259
2260dnl Need by run_erl.
2261AC_CHECK_FUNCS([openpty])
2262
2263AC_CHECK_HEADERS(net/if_dl.h ifaddrs.h netpacket/packet.h sys/un.h)
2264AC_CHECK_FUNCS([getifaddrs])
2265
2266dnl Checks for variables in6addr_any and in6addr_loopback,
2267dnl
2268dnl They normally declared by netinet/in.h, according to POSIX,
2269dnl but not on Windows 7 (Windows SDK 7.1).  I would have liked
2270dnl to just write AC_CHECK_DECL([in6addr_any], ...) but if doing so,
2271dnl the configure check fails erroneously on Linux with the error
2272dnl "cannot convert to a pointer type", on a line looking like
2273dnl "char *p = (char *) in6addr_any;", so work around that
2274dnl with some more code.
2275AC_CACHE_CHECK(
2276    [whether in6addr_any is declared],
2277    [erts_cv_have_in6addr_any],
2278    [AC_LINK_IFELSE(
2279	[AC_LANG_PROGRAM(
2280	    [[
2281		#include <sys/types.h>
2282		#include <sys/socket.h>
2283		#include <netinet/in.h>
2284		#include <stdio.h>
2285	    ]],
2286	    [[printf("%d", in6addr_any.s6_addr[16]);]]
2287	)],
2288	[erts_cv_have_in6addr_any=yes],
2289	[erts_cv_have_in6addr_any=no]
2290    )]
2291)
2292
2293case "$erts_cv_have_in6addr_any" in
2294 yes)
2295   AC_DEFINE([HAVE_IN6ADDR_ANY], [1],
2296             [Define to 1 if you have the variable in6addr_any declared.])
2297esac
2298
2299AC_CACHE_CHECK(
2300    [whether in6addr_loopback is declared],
2301    [erts_cv_have_in6addr_loopback],
2302    [AC_LINK_IFELSE(
2303	[AC_LANG_PROGRAM(
2304	    [[
2305		#include <sys/types.h>
2306		#include <sys/socket.h>
2307		#include <netinet/in.h>
2308		#include <stdio.h>
2309	    ]],
2310	    [[printf("%d", in6addr_loopback.s6_addr[16]);]]
2311	)],
2312	[erts_cv_have_in6addr_loopback=yes],
2313	[erts_cv_have_in6addr_loopback=no]
2314    )]
2315)
2316
2317case "$erts_cv_have_in6addr_loopback" in
2318 yes)
2319   AC_DEFINE([HAVE_IN6ADDR_LOOPBACK], [1],
2320             [Define to 1 if you have the variable in6addr_loopback declared.])
2321esac
2322
2323AC_CHECK_DECLS([IN6ADDR_ANY_INIT, IN6ADDR_LOOPBACK_INIT, IPV6_V6ONLY], [], [],
2324	       [
2325		#include <sys/types.h>
2326		#include <sys/socket.h>
2327		#include <netinet/in.h>
2328	       ])
2329
2330dnl ----------------------------------------------------------------------
2331dnl Checks for features/quirks in the system that affects Erlang.
2332dnl ----------------------------------------------------------------------
2333
2334AC_MSG_CHECKING([for sched_getaffinity/sched_setaffinity])
2335AC_TRY_LINK([#include <sched.h>],
2336[
2337#ifndef CPU_SETSIZE
2338#error no CPU_SETSIZE
2339#endif
2340	int res;
2341	cpu_set_t cpuset;
2342	CPU_ZERO(&cpuset);
2343	CPU_SET(1, &cpuset);
2344	res = sched_setaffinity(0, sizeof(cpu_set_t), &cpuset);
2345	res = sched_getaffinity(0, sizeof(cpu_set_t), &cpuset);
2346	res = CPU_ISSET(1, &cpuset);
2347	CPU_CLR(1, &cpuset);
2348],
2349		sched_xetaffinity=yes,
2350		sched_xetaffinity=no)
2351AC_MSG_RESULT([$sched_xetaffinity])
2352if test $sched_xetaffinity = yes; then
2353	AC_DEFINE(HAVE_SCHED_xETAFFINITY, 1, [Define if you have sched_getaffinity/sched_setaffinity])
2354fi
2355
2356
2357AC_MSG_CHECKING([for pset functionality])
2358AC_TRY_LINK([#include <sys/pset.h>],
2359[
2360	int res;
2361	psetid_t id = PS_MYID;
2362	int type = PS_PRIVATE;
2363	uint_t numcpus = 1024;
2364	processorid_t cpulist[1024];
2365
2366	res = pset_info(id, &type, &numcpus, &cpulist[0]);
2367],
2368		pset_functionality=yes,
2369		pset_functionality=no)
2370AC_MSG_RESULT([$pset_functionality])
2371if test $pset_functionality = yes; then
2372	AC_DEFINE(HAVE_PSET, 1, [Define if you have pset functionality])
2373fi
2374
2375AC_MSG_CHECKING([for processor_bind functionality])
2376AC_TRY_LINK([
2377#include <sys/types.h>
2378#include <sys/processor.h>
2379#include <sys/procset.h>
2380],
2381[
2382	int res = processor_bind(P_LWPID, P_MYID, PBIND_NONE, NULL);
2383],
2384		processor_bind_functionality=yes,
2385		processor_bind_functionality=no)
2386AC_MSG_RESULT([$processor_bind_functionality])
2387if test $processor_bind_functionality = yes; then
2388	AC_DEFINE(HAVE_PROCESSOR_BIND, 1, [Define if you have processor_bind functionality])
2389fi
2390
2391AC_MSG_CHECKING([for cpuset_getaffinity/cpuset_setaffinity])
2392AC_TRY_LINK([
2393#include <sys/param.h>
2394#include <sys/cpuset.h>
2395],
2396[
2397	int res;
2398	cpuset_t cpuset;
2399	CPU_ZERO(&cpuset);
2400	CPU_SET(1, &cpuset);
2401	res = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof(cpuset_t), &cpuset);
2402	res = cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof(cpuset_t), &cpuset);
2403	res = CPU_ISSET(1, &cpuset);
2404	CPU_CLR(1, &cpuset);
2405],
2406		cpuset_xetaffinity=yes,
2407		cpuset_xetaffinity=no)
2408AC_MSG_RESULT([$cpuset_xetaffinity])
2409if test $cpuset_xetaffinity = yes; then
2410	AC_DEFINE(HAVE_CPUSET_xETAFFINITY, 1, [Define if you have cpuset_getaffinity/cpuset_setaffinity])
2411fi
2412
2413AC_CACHE_CHECK([for 'end' symbol],
2414		erts_cv_have_end_symbol,
2415		[AC_TRY_LINK([],
2416			[extern char end; {char *x = &end; *x= 0;}],
2417			erts_cv_have_end_symbol=yes,
2418			erts_cv_have_end_symbol=no)])
2419if test $erts_cv_have_end_symbol = yes; then
2420	AC_DEFINE(HAVE_END_SYMBOL, 1, [Define if you have the 'end' symbol])
2421fi
2422
2423AC_CACHE_CHECK([for '_end' symbol],
2424		erts_cv_have__end_symbol,
2425		[AC_TRY_LINK([],
2426			[extern char _end; {char *x = &_end; *x= 0;}],
2427			erts_cv_have__end_symbol=yes,
2428			erts_cv_have__end_symbol=no)])
2429if test $erts_cv_have__end_symbol = yes; then
2430	AC_DEFINE(HAVE__END_SYMBOL, 1, [Define if you have the '_end' symbol])
2431fi
2432
2433AC_CACHE_CHECK([if __after_morecore_hook can track malloc()s core memory use],
2434		erts_cv___after_morecore_hook_can_track_malloc,
2435		[AC_TRY_RUN([
2436#include <stdlib.h>
2437#ifdef HAVE_MALLOC_H
2438#  include <malloc.h>
2439#endif
2440#if defined(HAVE_END_SYMBOL)
2441extern char end;
2442#elif defined(HAVE__END_SYMBOL)
2443extern char _end;
2444#endif
2445
2446#ifdef ETHR_PTHREADS
2447#  ifdef ETHR_HAVE_PTHREAD_H
2448#    include <pthread.h>
2449#  else
2450#    ifdef ETHR_HAVE_MIT_PTHREAD_H
2451#      include <pthread/mit/pthread.h>
2452#    endif
2453#  endif
2454#  define N_THR 5
2455#else
2456#  define N_THR 1
2457#endif
2458
2459static char *heap_start = NULL;
2460static char *heap_end = NULL;
2461
2462void update_heap_size(void)
2463{
2464    heap_end = (char *) sbrk(0);
2465}
2466
2467void init_hook(void)
2468{
2469#if defined(HAVE_END_SYMBOL)
2470    heap_start = &end;
2471#elif defined(HAVE__END_SYMBOL)
2472    heap_start = &_end;
2473#else
2474    heap_start = sbrk(0);
2475#endif
2476    __after_morecore_hook = update_heap_size;
2477}
2478
2479void (*__malloc_initialize_hook) (void) = init_hook;
2480
2481static int
2482check_malloc(int size)
2483{
2484    char *p = (char *) malloc(size);
2485    if (!heap_start || !heap_end) return 0;
2486    if (!p) return 0;
2487    if (p < heap_start || heap_end <= p) return 0;
2488    if (p + size < heap_start || heap_end < p + size) return 0;
2489    return 1;
2490}
2491
2492#ifdef ETHR_PTHREADS
2493pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
2494#endif
2495
2496static void *
2497do_tests(void *vresp)
2498{
2499    int i, ok = 0;
2500#ifdef ETHR_PTHREADS
2501    if (pthread_mutex_lock(&mutex) != 0)
2502	return NULL;
2503#endif
2504
2505    for (i = 0; i < 10; i++)
2506	if (!check_malloc(1000))
2507	    goto failed;
2508    for (i = 0; i < 100; i++)
2509	if (!check_malloc(1))
2510	    goto failed;
2511    if (!check_malloc(1024*1024+1))
2512	goto failed;
2513    if (!check_malloc(10*1024*1024+1))
2514	goto failed;
2515    ok = 1;
2516
2517 failed:
2518#ifdef ETHR_PTHREADS
2519    if (pthread_mutex_unlock(&mutex) != 0)
2520	return NULL;
2521#endif
2522    if (ok)
2523	*((int *) vresp) = 0;
2524    return NULL;
2525}
2526
2527
2528int main(void)
2529{
2530    int res[N_THR], i;
2531#ifdef ETHR_PTHREADS
2532    pthread_t tid[N_THR];
2533#endif
2534
2535#if defined(HAVE_MALLOPT) && defined(M_MMAP_MAX)
2536    (void) mallopt(M_MMAP_MAX, 0);
2537#endif
2538
2539    for (i = 0; i < N_THR; i++)
2540	res[i] = 1;
2541#ifdef ETHR_PTHREADS
2542    for (i = 1; i < N_THR; i++)
2543	if (pthread_create(&tid[i], NULL, do_tests, &res[i]) != 0)
2544	    return 1;
2545#endif
2546    (void) do_tests(&res[0]);
2547#ifdef ETHR_PTHREADS
2548    for (i = 1; i < N_THR; i++)
2549	if (pthread_join(tid[i], NULL) != 0)
2550	    return 1;
2551#endif
2552    for (i = 0; i < N_THR; i++)
2553	if (res[i])
2554	    return 1;
2555    return 0;
2556}
2557	],
2558	erts_cv___after_morecore_hook_can_track_malloc=yes,
2559	erts_cv___after_morecore_hook_can_track_malloc=no,
2560	[
2561	case X$erl_xcomp_after_morecore_hook in
2562	    X) erts_cv___after_morecore_hook_can_track_malloc=cross;;
2563	    Xyes|Xno) erts_cv___after_morecore_hook_can_track_malloc=$erl_xcomp_after_morecore_hook;;
2564	    *) AC_MSG_ERROR([Bad erl_xcomp_after_morecore_hook value: $erl_xcomp_after_morecore_hook]);;
2565	esac
2566	]
2567	)])
2568
2569case $erts_cv___after_morecore_hook_can_track_malloc in
2570	yes) AC_DEFINE(ERTS___AFTER_MORECORE_HOOK_CAN_TRACK_MALLOC, 1, \
2571[Define if __after_morecore_hook can track malloc()s core memory use.]);;
2572	cross) AC_MSG_WARN([result no guessed because of cross compilation]);;
2573	*) ;;
2574esac
2575
2576if test "x$ac_cv_func_sbrk" = "xyes"; then
2577    AC_CACHE_CHECK([types of sbrk()s return value and argument],
2578		    erts_cv_sbrk_ret_arg_types,
2579		    [
2580
2581	erts_cv_sbrk_ret_arg_types=unknown
2582	ret_types="void *,char *"
2583	arg_types="intptr_t,ptrdiff_t,int,long"
2584	save_ifs="$IFS"; IFS=","
2585	for rtype in $ret_types; do
2586	    for atype in $arg_types; do
2587		IFS=$save_ifs
2588		AC_TRY_LINK([#include <sys/types.h>
2589				#include <unistd.h>],
2590				[$rtype sbrk($atype incr);],
2591				[erts_cv_sbrk_ret_arg_types="$rtype,$atype"])
2592		IFS=","
2593		if test "$erts_cv_sbrk_ret_arg_types" != "unknown"; then
2594		    break 2
2595		fi
2596	    done
2597	done
2598	IFS=$save_ifs])
2599
2600    if test "$erts_cv_sbrk_ret_arg_types" != "unknown"; then
2601	save_ifs="$IFS"; IFS=","
2602	read ret_type arg_type <<EOF
2603$erts_cv_sbrk_ret_arg_types
2604EOF
2605	IFS=$save_ifs
2606	AC_DEFINE_UNQUOTED(SBRK_RET_TYPE, $ret_type, \
2607[Define the sbrk() return type.])
2608	AC_DEFINE_UNQUOTED(SBRK_ARG_TYPE, $arg_type, \
2609[Define the sbrk() argument type.])
2610    fi
2611fi
2612
2613if test $ac_cv_func_brk = yes; then
2614    AC_CACHE_CHECK([types of brk()s return value and argument],
2615		    erts_cv_brk_ret_arg_types,
2616		    [
2617
2618	erts_cv_brk_ret_arg_types=unknown
2619	ret_types="int,long,char *,void *"
2620	arg_types="void *,const void *,char *,const char *"
2621	save_ifs="$IFS"; IFS=","
2622	for rtype in $ret_types; do
2623	    for atype in $arg_types; do
2624		IFS=$save_ifs
2625		AC_TRY_LINK([#include <sys/types.h>
2626				#include <unistd.h>],
2627				[$rtype brk($atype endds);],
2628				[erts_cv_brk_ret_arg_types="$rtype,$atype"])
2629		IFS=","
2630		if test "$erts_cv_brk_ret_arg_types" != "unknown"; then
2631		    break 2
2632		fi
2633	    done
2634	done
2635	IFS=$save_ifs])
2636
2637    if test "$erts_cv_brk_ret_arg_types" != "unknown"; then
2638	save_ifs="$IFS"; IFS=","
2639	read ret_type arg_type <<EOF
2640$erts_cv_brk_ret_arg_types
2641EOF
2642	IFS=$save_ifs
2643	AC_DEFINE_UNQUOTED(BRK_RET_TYPE, $ret_type, \
2644[Define the brk() return type.])
2645	AC_DEFINE_UNQUOTED(BRK_ARG_TYPE, $arg_type, \
2646[Define the brk() argument type.])
2647    fi
2648
2649fi
2650
2651if test $ac_cv_func_sbrk = yes; then
2652
2653    AC_CACHE_CHECK([if sbrk()/brk() wrappers can track malloc()s core memory use],
2654		    erts_cv_brk_wrappers_can_track_malloc,
2655		    [AC_TRY_RUN([
2656#include <stdlib.h>
2657#include <sys/types.h>
2658#include <unistd.h>
2659#ifdef HAVE_DLFCN_H
2660#  include <dlfcn.h>
2661#endif
2662
2663/*
2664 * Our implementation requires that we have sbrk(), and 'end' or '_end'.
2665 */
2666
2667#if !defined(HAVE_SBRK)
2668#  error no sbrk()
2669#endif
2670#if defined(HAVE_END_SYMBOL)
2671extern char end;
2672#elif defined(HAVE__END_SYMBOL)
2673extern char _end;
2674#else
2675#  error no 'end' nor '_end'
2676#endif
2677
2678#ifdef ETHR_PTHREADS
2679#  ifdef ETHR_HAVE_PTHREAD_H
2680#    include <pthread.h>
2681#  else
2682#    ifdef ETHR_HAVE_MIT_PTHREAD_H
2683#      include <pthread/mit/pthread.h>
2684#    endif
2685#  endif
2686#  define N_THR 5
2687#else
2688#  define N_THR 1
2689#endif
2690
2691#define SBRK_IMPL(RET_TYPE, SBRK, ARG_TYPE)				\
2692RET_TYPE SBRK (ARG_TYPE);						\
2693static RET_TYPE (*real_ ## SBRK)(ARG_TYPE) = NULL;			\
2694RET_TYPE								\
2695SBRK (ARG_TYPE arg)							\
2696{									\
2697    RET_TYPE res;							\
2698    if (!real_ ## SBRK) real_ ## SBRK = dlsym(RTLD_NEXT, #SBRK);	\
2699    res = (*real_ ## SBRK)(arg);					\
2700    if (res != (RET_TYPE) -1) heap_end = (char *) (*real_ ## SBRK)(0);	\
2701    return res;								\
2702}
2703
2704#define BRK_IMPL(RET_TYPE, BRK, ARG_TYPE)				\
2705RET_TYPE BRK (ARG_TYPE);						\
2706static RET_TYPE (*real_ ## BRK)(ARG_TYPE) = NULL;			\
2707RET_TYPE								\
2708BRK (ARG_TYPE arg)							\
2709{									\
2710    RET_TYPE res;							\
2711    if (!real_ ## BRK) real_ ## BRK = dlsym(RTLD_NEXT, #BRK);		\
2712    res = (*real_ ## BRK)(arg);						\
2713    if (res != (RET_TYPE) -1) heap_end = (char *) arg;			\
2714    return res;								\
2715}
2716
2717static char *heap_start = NULL;
2718static char *heap_end = NULL;
2719
2720SBRK_IMPL(SBRK_RET_TYPE, sbrk, SBRK_ARG_TYPE)
2721#ifdef HAVE_BRK
2722   BRK_IMPL(BRK_RET_TYPE, brk, BRK_ARG_TYPE)
2723#endif
2724
2725#ifdef HAVE__SBRK
2726   SBRK_IMPL(SBRK_RET_TYPE, _sbrk, SBRK_ARG_TYPE)
2727#endif
2728#ifdef HAVE__BRK
2729   BRK_IMPL(BRK_RET_TYPE, _brk, BRK_ARG_TYPE)
2730#endif
2731
2732#ifdef HAVE___SBRK
2733   SBRK_IMPL(SBRK_RET_TYPE, __sbrk, SBRK_ARG_TYPE)
2734#endif
2735#ifdef HAVE___BRK
2736   BRK_IMPL(BRK_RET_TYPE, __brk, BRK_ARG_TYPE)
2737#endif
2738
2739static int
2740check_malloc(int size)
2741{
2742    char *p = (char *) malloc(size);
2743    if (!heap_start || !heap_end) return 0;
2744    if (!p) return 0;
2745    if (p < heap_start || heap_end <= p) return 0;
2746    if (p + size < heap_start || heap_end < p + size) return 0;
2747    return 1;
2748}
2749
2750#ifdef ETHR_PTHREADS
2751pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
2752#endif
2753
2754static void *
2755do_tests(void *vresp)
2756{
2757    int i, ok = 0;
2758#ifdef ETHR_PTHREADS
2759    if (pthread_mutex_lock(&mutex) != 0)
2760	return NULL;
2761#endif
2762
2763    for (i = 0; i < 10; i++)
2764	if (!check_malloc(1000))
2765	    goto failed;
2766    for (i = 0; i < 100; i++)
2767	if (!check_malloc(1))
2768	    goto failed;
2769    if (!check_malloc(1024*1024+1))
2770	goto failed;
2771    if (!check_malloc(10*1024*1024+1))
2772	goto failed;
2773    ok = 1;
2774
2775 failed:
2776#ifdef ETHR_PTHREADS
2777    if (pthread_mutex_unlock(&mutex) != 0)
2778	return NULL;
2779#endif
2780    if (ok)
2781	*((int *) vresp) = 0;
2782    return NULL;
2783}
2784
2785
2786int main(void)
2787{
2788    int res[N_THR], i;
2789#ifdef ETHR_PTHREADS
2790    pthread_t tid[N_THR];
2791#endif
2792#if defined(HAVE_END_SYMBOL)
2793    heap_start = &end;
2794#elif defined(HAVE__END_SYMBOL)
2795    heap_start = &_end;
2796#endif
2797
2798#if defined(HAVE_MALLOPT) && defined(M_MMAP_MAX)
2799    (void) mallopt(M_MMAP_MAX, 0);
2800#endif
2801
2802    for (i = 0; i < N_THR; i++)
2803	res[i] = 1;
2804#ifdef ETHR_PTHREADS
2805    for (i = 1; i < N_THR; i++)
2806	if (pthread_create(&tid[i], NULL, do_tests, &res[i]) != 0)
2807	    return 1;
2808#endif
2809    (void) do_tests(&res[0]);
2810#ifdef ETHR_PTHREADS
2811    for (i = 1; i < N_THR; i++)
2812	if (pthread_join(tid[i], NULL) != 0)
2813	    return 1;
2814#endif
2815    for (i = 0; i < N_THR; i++)
2816	if (res[i])
2817	    return 1;
2818    return 0;
2819}
2820	],
2821	    erts_cv_brk_wrappers_can_track_malloc=yes,
2822	    erts_cv_brk_wrappers_can_track_malloc=no,
2823	    [
2824	    case X$erl_xcomp_dlsym_brk_wrappers in
2825		X) erts_cv_brk_wrappers_can_track_malloc=cross;;
2826		Xyes|Xno) erts_cv_brk_wrappers_can_track_malloc=$erl_xcomp_dlsym_brk_wrappers;;
2827		*) AC_MSG_ERROR([Bad erl_xcomp_dlsym_brk_wrappers value: $erl_xcomp_dlsym_brk_wrappers]);;
2828	    esac
2829	    ])])
2830	case $erts_cv_brk_wrappers_can_track_malloc in
2831	    yes)
2832		AC_DEFINE(ERTS_BRK_WRAPPERS_CAN_TRACK_MALLOC, 1, \
2833[Define if sbrk()/brk() wrappers can track malloc()s core memory use]);;
2834	    cross)
2835		AC_MSG_WARN([result no guessed because of cross compilation]);;
2836	    *) ;;
2837	esac
2838fi
2839
2840dnl Restore LIBS
2841LIBS=$saved_libs
2842dnl restore CPPFLAGS
2843CPPFLAGS=$saved_cppflags
2844
2845case $ARCH in
2846     x86|amd64)
2847	AC_DEFINE(ERTS_STRUCTURE_ALIGNED_ALLOC, 1, [Define if structure alignment is enough for allocators. If not defined, 64-bit alignment will be forced.]);;
2848     *)
2849	;;
2850esac
2851
2852LM_SYS_IPV6
2853LM_SYS_MULTICAST
2854ERL_TIME_CORRECTION
2855AC_CHECK_PROG(M4, m4, m4)
2856
2857
2858if test X${enable_hipe} != Xno; then
2859        dnl HiPE cannot run without mprotect()
2860        if test X$ac_cv_func_mprotect != Xyes; then
2861            if test X${enable_hipe} = Xyes; then
2862	        AC_MSG_ERROR([HiPE needs mprotect() on $ARCH])
2863            else
2864	        enable_hipe=no
2865	        AC_MSG_WARN([HiPE disabled due to lack of mprotect()])
2866            fi
2867        fi
2868        AC_MSG_CHECKING([for safe signal delivery])
2869        AC_TRY_COMPILE([#include <signal.h>],
2870          [#if defined(__APPLE__) && defined(__MACH__) && !defined(__DARWIN__)
2871           #define __DARWIN__ 1
2872           #endif
2873
2874           #if !(defined(__GLIBC__) || defined(__DARWIN__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__sun__))
2875          /*
2876           * Unknown libc -- assume musl, which does not allow safe signals
2877           */
2878           #error "HiPE does not work without a libc that can guarantee that sigaltstack works"
2879           #endif	/* !(__GLIBC__ || __DARWIN__ || __NetBSD__ || __FreeBSD__ || __sun__) */],
2880        [AC_MSG_RESULT([yes])],
2881        [enable_hipe=no
2882         AC_MSG_RESULT([no, musl probably used. Need glibc to work properly])
2883         AC_MSG_WARN([HiPE disabled due to lack of safe signal delivery])])
2884fi
2885
2886dnl check to auto-enable hipe here...
2887if test "$cross_compiling" != "yes" && test X${enable_hipe} != Xno; then
2888  if test -z "$M4"; then
2889	enable_hipe=no
2890   	AC_MSG_NOTICE([HiPE disabled as no valid m4 is found in PATH])
2891  else
2892  	case "$ARCH-$OPSYS" in
2893	    x86-linux|amd64-linux|x86-darwin*|amd64-darwin*|ppc-linux|ppc64-linux|ppc-darwin|arm-linux|amd64-freebsd|x86-freebsd|x86-sol2|amd64-sol2|ultrasparc-linux)
2894      		enable_hipe=yes
2895      		;;
2896  	esac
2897  fi
2898fi
2899
2900if test X${enable_hipe} = Xyes; then
2901   case $OPSYS in
2902	linux)
2903		ppcBEAMLDFLAGS="-Wl,-m,elf32ppc"
2904		ppc64BEAMLDFLAGS="-Wl,-m,elf64ppc,-T,hipe/elf64ppc.x"
2905		;;
2906	darwin)
2907		amd64BEAMLDFLAGS="-pagezero_size 0x10000000"
2908		;;
2909   esac
2910   archVarName="${ARCH}BEAMLDFLAGS"
2911   eval HIPEBEAMLDFLAGS=\$$archVarName
2912fi
2913AC_SUBST(HIPEBEAMLDFLAGS)
2914
2915dnl Permanently disable floating point exceptions.
2916dnl On x86/amd64, floating points exceptions have
2917dnl unresolved stability issues.
2918AC_MSG_CHECKING([for unreliable floating point exceptions])
2919FPE=unreliable
2920AC_SUBST(FPE)
2921AC_MSG_RESULT([unreliable])
2922AC_DEFINE(NO_FPE_SIGNALS,[],[Define if floating points exceptions are non-existing/not reliable])
2923
2924dnl
2925dnl Some operating systems allow you to redefine FD_SETSIZE to be able
2926dnl to select on more than the default number of file descriptors.
2927dnl We first discovered this in BSD/OS where the default is ridiculously
2928dnl low (256). But since we use a lot of file descriptors we found the
2929dnl need to go over the limit in other os's as well. Since FD_SETSIZE
2930dnl must be defined before pulling in sys/types.h the actual number
2931dnl of file descriptors is set in acconfig.h and will thus be in config.h
2932dnl which *always* should be included first.
2933dnl
2934
2935AC_MSG_CHECKING([whether to redefine FD_SETSIZE])
2936case $host_os in
2937  bsdi*)
2938	AC_DEFINE(REDEFINE_FD_SETSIZE,[],[Define if you wish to redefine FD_SETSIZE to be able to select on more fd])
2939	AC_MSG_RESULT(yes)
2940	;;
2941  *)
2942	AC_MSG_RESULT(no)
2943	;;
2944esac
2945
2946
2947
2948dnl ----------------------------------------------------------------------
2949dnl Tests related to configurable options given on command line
2950dnl (using the --disable, --enable and --with switches).
2951dnl ----------------------------------------------------------------------
2952
2953#
2954# Check if we should enable HiPE.
2955#
2956
2957HIPE_ENABLED=
2958HIPE_HELPERS=
2959
2960dnl if not disabled, autoenable HiPE on known supported platforms
2961dnl done up where floating point is checked, need to descide there already...
2962
2963if test X${enable_hipe} = Xyes; then
2964  if test X$ac_cv_sizeof_void_p != X4 -a X$ARCH != Xamd64 -a X$ARCH != Xppc64; then
2965	AC_MSG_WARN([HiPE is not supported in 64-bit builds])
2966  else
2967     HIPE_ENABLED=yes
2968     AC_DEFINE(HIPE,[1],[Define to enable HiPE])
2969     HIPE_HELPERS="xmerl syntax_tools edoc"
2970     ENABLE_ALLOC_TYPE_VARS="$ENABLE_ALLOC_TYPE_VARS hipe"
2971     AC_MSG_NOTICE([Enable exec_alloc for hipe code allocation])
2972     ENABLE_ALLOC_TYPE_VARS="$ENABLE_ALLOC_TYPE_VARS exec_alloc"
2973  fi
2974fi
2975AC_SUBST(HIPE_HELPERS)
2976AC_SUBST(HIPE_ENABLED)
2977
2978#
2979# Check if Erlang libraries should be compiled to native code.
2980#
2981NATIVE_LIBS_ENABLED=
2982if test X${enable_native_libs} = Xyes -a X${HIPE_ENABLED} = Xyes; then
2983  NATIVE_LIBS_ENABLED=yes
2984  cat >> $ERL_TOP/erts/CONF_INFO <<EOF
2985
2986                 WARNING: In OTP 22, HiPE (the native code compiler) is
2987		 not fully functional. The reasons for this are:
2988
2989		 1. There are new BEAM instructions for binary
2990		 matching that the HiPE native code compiler does not
2991		 support.
2992
2993		 2. The new optimizations in the Erlang compiler create
2994		 new combination of instructions that HiPE currently
2995		 does not handle correctly.
2996
2997		 If erlc is invoked like so:
2998
2999		     erlc +native some_file.erl
3000
3001                 or like so:
3002
3003                     erlc +native some_file.beam
3004
3005		 and if any of the new binary matching instructions
3006		 are used, the compiler will issue a warning and
3007		 produce a BEAM file without native code.
3008
3009EOF
3010fi
3011AC_SUBST(NATIVE_LIBS_ENABLED)
3012
3013#
3014# Check for working poll().
3015#
3016AC_MSG_CHECKING([for working poll()])
3017if test "x$ac_cv_header_poll_h" != "xyes" -o "x$ac_cv_func_poll" != "xyes"; then
3018
3019poll_works=no
3020
3021else
3022
3023AC_TRY_RUN([
3024#include <poll.h>
3025main()
3026{
3027#ifdef _POLL_EMUL_H_
3028  exit(1); /* Implemented using select() -- fail */
3029#else
3030  struct pollfd fds[1];
3031  int fd;
3032  fd = open("/dev/null", 1);
3033  fds[0].fd = fd;
3034  fds[0].events = POLLIN;
3035  fds[0].revents = 0;
3036  if (poll(fds, 1, 0) < 0 || (fds[0].revents & POLLNVAL) != 0) {
3037    exit(1);  /* Does not work for devices -- fail */
3038  }
3039  exit(0);
3040#endif
3041}
3042],
3043poll_works=yes,
3044poll_works=no,
3045[
3046case X$erl_xcomp_poll in
3047    X) poll_works=cross;;
3048    Xyes|Xno) poll_works=$erl_xcomp_poll;;
3049    *) AC_MSG_ERROR([Bad erl_xcomp_poll value: $erl_xcomp_poll]);;
3050esac
3051])
3052
3053fi
3054
3055case $poll_works-$host_os in
3056    no-*|cross-darwin*)
3057	#
3058	# The USE_SELECT define is used by the ssl application (should not
3059	# be used by erts).
3060	#
3061	AC_DEFINE(USE_SELECT, 1, [Define if select() should be used instead of poll()])
3062	if test $poll_works = cross; then
3063	    AC_MSG_RESULT(cross)
3064	    AC_MSG_WARN([result no guessed based on OS ($host_os) because of cross compilation])
3065	else
3066	    AC_MSG_RESULT([no; non-existing, broken, or based on select()])
3067        fi
3068	poll_works=no;;
3069    yes-*|cross-*)
3070	AC_DEFINE(ERTS_USE_POLL, 1, [Define if poll() should be used instead of select()])
3071	if test $poll_works = cross; then
3072	    AC_MSG_RESULT(cross)
3073	    AC_MSG_WARN([result yes guessed based on OS ($host_os) because of cross compilation])
3074	else
3075	    AC_MSG_RESULT(yes)
3076        fi
3077	poll_works=yes;;
3078esac
3079
3080#
3081# If kqueue() found
3082#
3083if test $have_kernel_poll = kqueue; then
3084## Some OS X kernel version seems to have bugs in them with regards to kqueue
3085## Disable kernel poll on those versions
3086   AC_MSG_CHECKING([whether host os has known kqueue bugs])
3087   case $host_os in
3088     # Any OS X version < 16 has known problems with using kqueue
3089     # so we don't use it there. See erl_poll.c for details.
3090     darwin[[0-9]].*|darwin1[[0-5]].*)
3091        AC_MSG_RESULT([yes, disabling kernel poll])
3092        have_kernel_poll=no
3093        ;;
3094     *)
3095        AC_MSG_RESULT([no])
3096        ;;
3097   esac
3098fi
3099#
3100# If epoll() found, check that it is level triggered.
3101#
3102if test $have_kernel_poll = epoll; then
3103	AC_MSG_CHECKING([whether epoll is level triggered])
3104	AC_TRY_LINK([#include <sys/epoll.h>],[
3105			#ifdef EPOLLET
3106			/* Edge triggered option exist, assume level triggered
3107			   is default */
3108			;
3109			#else
3110			/* No edge triggered option exist; assume edge
3111			   triggered only */
3112			#error No EPOLLET
3113			#endif
3114			],
3115			level_triggered_epoll=yes,
3116			[level_triggered_epoll=no
3117			 have_kernel_poll=no])
3118	AC_MSG_RESULT([$level_triggered_epoll])
3119fi
3120#
3121# Check if we should enable kernel poll support
3122#
3123AC_MSG_CHECKING(whether kernel poll support should be enabled)
3124ERTS_ENABLE_KERNEL_POLL=no
3125ERTS_BUILD_FALLBACK_POLL=no
3126case $enable_kernel_poll-$have_kernel_poll in
3127    no-*)
3128	AC_MSG_RESULT(no; disabled by user);;
3129    yes-no)
3130	AC_MSG_ERROR(no; kernel poll support requested but not found);;
3131    *-no)
3132	AC_MSG_RESULT(no);;
3133    *)
3134	case $have_kernel_poll in
3135	    epoll)
3136		AC_DEFINE(HAVE_SYS_EPOLL_H, 1, [Define if you have the <sys/epoll.h> header file.])
3137                ERTS_BUILD_FALLBACK_POLL=yes
3138                ;;
3139	    /dev/poll)
3140		AC_DEFINE(HAVE_SYS_DEVPOLL_H, 1, [Define if you have <sys/devpoll.h> header file.])
3141                ;;
3142	    kqueue)
3143		AC_DEFINE(HAVE_SYS_EVENT_H, 1, [Define if you have <sys/event.h> header file.])
3144                ERTS_BUILD_FALLBACK_POLL=yes
3145                ;;
3146	    *)
3147		AC_MSG_ERROR(configure.in need to be updated);;
3148	esac
3149	ERTS_ENABLE_KERNEL_POLL=yes
3150	AC_DEFINE(ERTS_ENABLE_KERNEL_POLL, 1, [Define if you have kernel poll and want to use it])
3151	AC_MSG_RESULT([yes; $have_kernel_poll]);;
3152esac
3153AC_SUBST(ERTS_BUILD_FALLBACK_POLL)
3154
3155AC_MSG_CHECKING([whether putenv() stores a copy of the key-value pair])
3156AC_TRY_RUN([
3157#include <stdlib.h>
3158int main(void) {
3159    int i;
3160    char *env;
3161    char buf[10];
3162    for (i = 0; i < 7; i++)
3163	buf[i] = 'X';
3164    buf[i] = '\0';
3165    buf[3] = '=';
3166    if (putenv(buf) != 0)
3167	return 1;
3168    for (i = 4; i < 7; i++)
3169	buf[i] = 'Y';
3170    env = getenv("XXX");
3171    if (!env)
3172	return 2;
3173    for (i = 0; i < 3; i++)
3174	if (env[i] != 'X')
3175	    return 3;
3176    for (i = 0; i < 3; i++)
3177	buf[i] = 'Y';
3178    env = getenv("XXX");
3179    if (!env)
3180	return 4;
3181    for (i = 0; i < 3; i++)
3182	if (env[i] != 'X')
3183	    return 5;
3184    return 0;
3185}
3186],
3187copying_putenv=yes,
3188copying_putenv=no,
3189[
3190case X$erl_xcomp_putenv_copy in
3191    X) copying_putenv=cross;;
3192    Xyes|Xno) copying_putenv=$erl_xcomp_putenv_copy;;
3193    *) AC_MSG_ERROR([Bad erl_xcomp_putenv_copy value: $erl_xcomp_putenv_copy]);;
3194esac
3195])
3196
3197AC_MSG_RESULT($copying_putenv)
3198case $copying_putenv in
3199    yes)
3200	AC_DEFINE(HAVE_COPYING_PUTENV,[1],\
3201[Define if you have a putenv() that stores a copy of the key-value pair]);;
3202    cross)
3203	AC_MSG_WARN([result no guessed because of cross compilation]);;
3204    *) ;;
3205esac
3206
3207dnl ----------------------------------------------------------------------
3208dnl Stuff that should be moved into their respective application
3209dnl ----------------------------------------------------------------------
3210
3211dnl
3212dnl We should look for a compiler that handles jump tables, for beam_emu
3213dnl to be optimized
3214dnl
3215
3216LM_FIND_EMU_CC
3217
3218dnl
3219dnl Test whether code pointers are always short (32 bits).
3220dnl
3221
3222AC_MSG_CHECKING([whether the code model is small])
3223saved_LDFLAGS="$LDFLAGS"
3224LDFLAGS="$LDFLAGS $HIPEBEAMLDFLAGS"
3225AC_TRY_RUN([
3226   #include <stdlib.h>
3227   int main() {
3228    if ((unsigned long long)&main < (1ull << 32)) {
3229       exit(0);
3230    }
3231    exit(1);
3232   }
3233],
3234erl_code_model_small=yes,
3235erl_code_model_small=no,
3236[case X$erl_xcomp_code_model_small in
3237      X) erl_code_model_small=no;;
3238      Xyes|Xno) erl_code_model_small=$erl_xcomp_code_model_small;;
3239      *) AC_MSG_ERROR([Bad erl_xcomp_code_model_small value: $erl_xcomp_code_model_small]);;
3240 esac])
3241AC_MSG_RESULT([$erl_code_model_small])
3242LDFLAGS="$saved_LDFLAGS"
3243case $erl_code_model_small in
3244     yes)
3245        AC_DEFINE(CODE_MODEL_SMALL,[1],
3246	[Define if the code model is small (code fits below 2Gb)])
3247	CODE_MODEL=small
3248	;;
3249     no)
3250	CODE_MODEL=unknown
3251        ;;
3252esac
3253AC_SUBST(CODE_MODEL)
3254
3255dnl
3256dnl DTrace & LTTNG
3257dnl
3258case $DYNAMIC_TRACE_FRAMEWORK in
3259     dtrace|systemtap)
3260        AC_CHECK_TOOL(DTRACE, dtrace, none)
3261        test "$DTRACE" = "none" && AC_MSG_ERROR([No dtrace utility found.]);
3262        enable_lttng_test=no
3263	enable_dtrace_test=yes;;
3264     lttng)
3265        enable_lttng_test=yes
3266        enable_dtrace_test=no;;
3267     *)
3268        enable_lttng_test=no
3269        enable_dtrace_test=no;;
3270esac
3271
3272AC_SUBST(DTRACE)
3273
3274AC_SUBST(DTRACE_CPP)
3275AC_SUBST(DTRACE_ENABLED)
3276AC_SUBST(DTRACE_ENABLED_2STEP)
3277DTRACE_CPP=-C
3278DTRACE_ENABLED=
3279DTRACE_ENABLED_2STEP=
3280DTRACE_2STEP_TEST=./dtrace-test.o
3281DTRACE_BITS_FLAG=
3282case $OPSYS in
3283    freebsd)
3284	if test "$BITS64" = "yes" ; then
3285		DTRACE_BITS_FLAG=-64
3286	else
3287		DTRACE_BITS_FLAG=-32
3288	fi
3289    ;;
3290    *)
3291	: # Nothing to do
3292    ;;
3293esac
3294if test "$enable_dtrace_test" = "yes" ; then
3295        if test "$DTRACE" = "dtrace" ; then
3296                AC_CHECK_HEADERS(sys/sdt.h)
3297		AC_MSG_CHECKING([for 1-stage DTrace precompilation])
3298                # The OS X version of dtrace prints a spurious line here.
3299                if ! dtrace -h $DTRACE_CPP -Iemulator/beam -o ./foo-dtrace.h -s emulator/beam/erlang_dtrace.d; then
3300                        AC_MSG_ERROR([Could not precompile erlang_dtrace.d: dtrace -h failed])
3301                fi
3302		AC_MSG_RESULT([yes])
3303
3304		AC_MSG_CHECKING([for 2-stage DTrace precompilation])
3305                AC_TRY_COMPILE([ #include "foo-dtrace.h" ],
3306                    [ERLANG_DIST_PORT_BUSY_ENABLED();],
3307		    [rm -f $DTRACE_2STEP_TEST
3308		     dtrace -G $DTRACE_CPP $DTRACE_BITS_FLAG -Iemulator/beam -o $DTRACE_2STEP_TEST -s emulator/beam/erlang_dtrace.d conftest.$OBJEXT 2>&AS_MESSAGE_LOG_FD
3309                     if test -f $DTRACE_2STEP_TEST; then
3310			rm -f $DTRACE_2STEP_TEST
3311                        DTRACE_ENABLED_2STEP=yes
3312		     fi],
3313                    [])
3314		rm -f foo-dtrace.h
3315		AS_IF([test "x$DTRACE_ENABLED_2STEP" = "xyes"],
3316		      [AC_MSG_RESULT([yes])],
3317                      [AC_MSG_RESULT([no])])
3318
3319                DTRACE_ENABLED=yes
3320                case $OPSYS in
3321                    linux)
3322                        : # No extra libs to add to LIBS
3323                    ;;
3324                    freebsd)
3325                        LIBS="$LIBS -lelf"
3326                    ;;
3327                    *)
3328                        LIBS="$LIBS -ldtrace"
3329                    ;;
3330                esac
3331        else
3332                AC_MSG_ERROR([Dtrace preprocessing test failed.])
3333        fi
3334fi
3335
3336if test "$enable_lttng_test" = "yes" ; then
3337    AC_CHECK_HEADERS(lttng/tracepoint.h)
3338    AC_CHECK_HEADERS(lttng/tracepoint-event.h)
3339    dnl The macro tracepoint_enabled is not present in older lttng versions
3340    dnl checking for tracepoint_enabled
3341    AC_MSG_CHECKING([for tracepoint_enabled in lttng/tracepoint.h])
3342    AC_COMPILE_IFELSE(
3343        [AC_LANG_PROGRAM(
3344            [#include <lttng/tracepoint.h>
3345             #define TRACEPOINT_PROVIDER org_erlang_otp
3346             TRACEPOINT_EVENT(
3347                 org_erlang_otp,
3348                 dummy,
3349                 TP_ARGS(int, my_int),
3350                 TP_FIELDS(ctf_integer(int, my_int, my_int)))
3351             #define TRACEPOINT_CREATE_PROBES
3352             #define TRACEPOINT_DEFINE],
3353            [if(tracepoint_enabled(org_erlang_otp,dummy)) do {} while(0)])],
3354        [AC_MSG_RESULT([yes])],
3355        [AC_MSG_ERROR([no (available in lttng-ust v2.7)])])
3356    if test "x$ac_cv_header_lttng_tracepoint_h" = "xyes" \
3357        -a "x$ac_cv_header_lttng_tracepoint_event_h" = "xyes"; then
3358        # No straight forward way to test for liblttng-ust when no public symbol exists,
3359        # just add the lib.
3360        LIBS="$LIBS -llttng-ust -ldl"
3361    else
3362        AC_MSG_ERROR([No LTTng support found.])
3363    fi
3364fi
3365
3366
3367#--------------------------------------------------------------------
3368# Os mon stuff.
3369#--------------------------------------------------------------------
3370AC_SUBST(os_mon_programs)
3371AC_SUBST(CPU_SUP_LIBS)
3372
3373AC_CHECK_LIB(kstat, kstat_open, [
3374	use_cpu_sup=yes
3375	CPU_SUP_LIBS="$CPU_SUP_LIBS -lkstat"
3376	])
3377
3378AC_CHECK_LIB(kvm, kvm_open, [
3379	use_cpu_sup=yes
3380	CPU_SUP_LIBS="$CPU_SUP_LIBS -lkvm"
3381	])
3382
3383case $host_os in
3384	solaris2*)
3385		os_mon_programs="$os_mon_programs ferrule mod_syslog" ;;
3386	darwin*)
3387		use_cpu_sup=yes ;;
3388	openbsd*)
3389		use_cpu_sup=yes ;;
3390	linux*)
3391		use_cpu_sup=yes ;;
3392	freebsd*)
3393		use_cpu_sup=yes ;;
3394esac
3395
3396if test "$use_cpu_sup" = "yes"; then
3397    os_mon_programs="$os_mon_programs cpu_sup"
3398fi
3399
3400AC_ARG_WITH(javac,
3401AS_HELP_STRING([--with-javac=JAVAC], [specify Java compiler to use])
3402AS_HELP_STRING([--with-javac], [use a Java compiler if found (default)])
3403AS_HELP_STRING([--without-javac], [don't use any Java compiler]))
3404
3405dnl
3406dnl Then there are a number of apps which needs a java compiler...
3407dnl
3408need_java="jinterface"
3409
3410if test -d $ERL_TOP/lib/ic; then
3411   need_java="$need_java ic/java_src"
3412fi
3413
3414# Remove all SKIP files from previous runs
3415for a in $need_java ; do
3416  rm -f $ERL_TOP/lib/$a/SKIP
3417done
3418
3419if test "X$with_javac" = "Xno"; then
3420  for a in $need_java ; do
3421	echo "Java compiler disabled by user" > $ERL_TOP/lib/$a/SKIP
3422  done
3423
3424else # begin - try to find javac
3425
3426if test "X$with_javac" != "Xyes" -a "X$with_javac" != "X"; then
3427    check_javac=$with_javac
3428else
3429  check_javac="javac.sh javac guavac gcj jikes bock"
3430fi
3431
3432AC_CHECK_PROGS(JAVAC, $check_javac)
3433if test -n "$JAVAC"; then
3434  dnl Make sure it's at least JDK 1.6
3435  AC_CACHE_CHECK(for JDK version 1.6,
3436     ac_cv_prog_javac_ver_1_6,
3437     [ERL_TRY_LINK_JAVA([], [for (String i : args);],
3438        ac_cv_prog_javac_ver_1_6=yes, ac_cv_prog_javac_ver_1_6=no)])
3439  if test $ac_cv_prog_javac_ver_1_6 = no; then
3440    unset -v JAVAC
3441  fi
3442fi
3443if test -z "$JAVAC"; then
3444
3445  if test "X$with_javac" != "X"; then
3446  	AC_MSG_ERROR([No java compiler found in PATH (checked for $check_javac)])
3447  fi
3448
3449  AC_MSG_WARN([Could not find any usable java compiler, will skip: jinterface])
3450
3451  for a in $need_java ; do
3452	echo "No Java compiler found" > $ERL_TOP/lib/$a/SKIP
3453  done
3454fi
3455
3456fi # end - try to find javac
3457
3458dnl
3459dnl Orber has a c++ example, this isn't the right way to check for
3460dnl it, but....
3461dnl
3462AC_SUBST(CXXFLAGS)
3463dnl this deliberately does not believe that 'gcc' is a C++ compiler
3464AC_CHECK_TOOLS(CXX, [$CCC c++ g++ CC cxx cc++ cl], false)
3465
3466# Remove SKIP file from previous run
3467rm -f $ERL_TOP/lib/orber/SKIP
3468
3469if test "$CXX" = false; then
3470  echo "No C++ compiler found" > $ERL_TOP/lib/orber/SKIP
3471fi
3472
3473dnl ----------------------------------------------------------------------
3474dnl Include CPPFLAGS in CFLAGS
3475dnl ----------------------------------------------------------------------
3476CFLAGS="$CFLAGS $CPPFLAGS"
3477
3478#
3479# Currently if we compile for 64 bits we want to compile
3480# some external port programs using 32 bits
3481#
3482
3483# If not defined we trust the C compiler in $CC to do 32 bits
3484if test -z "$CC32"; then
3485  CC32="$CC"
3486fi
3487
3488if test -z "$CFLAGS32"; then
3489  if test $ac_cv_sizeof_void_p != 4; then
3490    # We are compiling default 64 bits and use -m32 for 32 bit compilations
3491    CFLAGS32="$CFLAGS -m32"
3492  else
3493    CFLAGS32="$CFLAGS"
3494  fi
3495fi
3496
3497AC_SUBST(CC32)
3498AC_SUBST(CFLAGS32)
3499
3500dnl
3501dnl ERTS_EMU_CMDLINE_FLAGS will force modification of config.h when
3502dnl the emulator command line flags are modified by configure, which
3503dnl in turn will make 'make' detect that files depending on config.h
3504dnl needs to be rebuilt.
3505dnl
3506
3507AC_DEFINE_UNQUOTED(ERTS_EMU_CMDLINE_FLAGS,
3508"$STATIC_CFLAGS $CFLAGS $DEBUG_CFLAGS $EMU_THR_DEFS $DEFS $WERRORFLAGS $WFLAGS",
3509[The only reason ERTS_EMU_CMDLINE_FLAGS exists is to force modification of config.h when the emulator command line flags are modified by configure])
3510
3511AC_SUBST(STATIC_CFLAGS)
3512
3513dnl ----------------------------------------------------------------------
3514dnl Directories needed for the build
3515dnl ----------------------------------------------------------------------
3516
3517erts=${erl_top}/erts
3518
3519erts_dirs="
3520  $erts/obj $erts/obj.debug
3521
3522  $erts/obj/$host
3523  $erts/obj.debug/$host
3524
3525"
3526for d in ${erl_top}/bin ${erl_top}/bin/$host $erts_dirs ;
3527do
3528  if test ! -d $d; then
3529    mkdir -p 1>/dev/null 2>&1 $d
3530  fi
3531done
3532
3533dnl ---------------------------------------------------------------------
3534dnl Autoheader macro for adding code at top and bottom of config.h.in
3535dnl ---------------------------------------------------------------------
3536AH_TOP([
3537#define GHBN_R_SOLARIS  2
3538#define GHBN_R_AIX      3
3539#define GHBN_R_GLIBC    4
3540])
3541
3542AH_BOTTOM([
3543/* Redefine in6_addr. XXX this should be moved to the files where it's used? */
3544#ifdef HAVE_IN_ADDR6_STRUCT
3545#define in6_addr in_addr6
3546#endif
3547
3548/* Define a reasonable default for INADDR_LOOPBACK */
3549/* XXX this should be moved to the files where it's used? */
3550#ifdef HAVE_NO_INADDR_LOOPBACK
3551#define INADDR_LOOPBACK (u_long)0x7F000001
3552#endif
3553
3554#ifdef REDEFINE_FD_SETSIZE
3555#define FD_SETSIZE 1024
3556#endif
3557
3558#ifdef HAVE_GETHRVTIME_PROCFS_IOCTL
3559#define HAVE_GETHRVTIME
3560#endif
3561
3562#if !defined(HAVE_ISFINITE) && !defined(HAVE_FINITE)
3563# if defined(HAVE_ISINF) && defined(HAVE_ISNAN)
3564#  define USE_ISINF_ISNAN
3565# endif
3566#endif
3567
3568#if defined(DEBUG) && !defined(ERTS_ENABLE_LOCK_CHECK)
3569#define ERTS_ENABLE_LOCK_CHECK 1
3570#endif
3571])
3572
3573
3574dnl ----------------------------------------------------------------------
3575dnl Check for GCC diagnostic ignored "-Waddress-of-packed-member"
3576dnl ----------------------------------------------------------------------
3577saved_CFLAGS="$CFLAGS"
3578CFLAGS="-Werror $CFLAGS"
3579AC_TRY_COMPILE([],
3580        [_Pragma("GCC diagnostic push")
3581         _Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\"")
3582         _Pragma("GCC diagnostic pop")
3583         ],
3584         AC_DEFINE(HAVE_GCC_DIAG_IGNORE_WADDRESS_OF_PACKED_MEMBER,[1],
3585           [define if compiler support _Pragma('GCC diagnostic ignored '-Waddress-of-packed-member'')]))
3586CFLAGS="$saved_CFLAGS"
3587
3588
3589dnl ----------------------------------------------------------------------
3590dnl Enable any -Werror flags
3591dnl ----------------------------------------------------------------------
3592
3593if test "x$GCC" = xyes; then
3594  CFLAGS="$WERRORFLAGS $CFLAGS"
3595fi
3596
3597dnl ----------------------------------------------------------------------
3598dnl Enable -fsanitize= flags.
3599dnl ----------------------------------------------------------------------
3600
3601m4_define(DEFAULT_SANITIZERS, [address,undefined])
3602AC_ARG_ENABLE(
3603    sanitizers,
3604    AS_HELP_STRING(
3605        [--enable-sanitizers@<:@=comma-separated list of sanitizers@:>@],
3606	    [Default=DEFAULT_SANITIZERS]),
3607[
3608case "$enableval" in
3609    no) sanitizers= ;;
3610    yes) sanitizers="-fsanitize=DEFAULT_SANITIZERS" ;;
3611    *) sanitizers="-fsanitize=$enableval" ;;
3612esac
3613CFLAGS="$CFLAGS $sanitizers"
3614LDFLAGS="$LDFLAGS $sanitizers"
3615])
3616
3617dnl ----------------------------------------------------------------------
3618dnl Check for log2
3619dnl ----------------------------------------------------------------------
3620AC_CHECK_FUNCS([log2])
3621
3622dnl ----------------------------------------------------------------------
3623dnl Output the result.
3624dnl ----------------------------------------------------------------------
3625
3626dnl  Note that the output files are relative to $srcdir
3627AC_CONFIG_FILES([
3628  emulator/$host/Makefile:emulator/Makefile.in
3629  epmd/src/$host/Makefile:epmd/src/Makefile.in
3630  etc/common/$host/Makefile:etc/common/Makefile.in
3631  include/internal/$host/ethread.mk:include/internal/ethread.mk.in
3632  include/internal/$host/erts_internal.mk:include/internal/erts_internal.mk.in
3633  lib_src/$host/Makefile:lib_src/Makefile.in
3634  ../make/$host/otp.mk:../make/otp.mk.in
3635])
3636
3637AC_CONFIG_FILES([../make/make_emakefile:../make/make_emakefile.in],
3638                [chmod +x ../make/make_emakefile])
3639
3640dnl
3641dnl The ones below should be moved to their respective lib
3642dnl
3643AC_CONFIG_FILES([
3644  ../lib/os_mon/c_src/$host/Makefile:../lib/os_mon/c_src/Makefile.in
3645  ../lib/runtime_tools/c_src/$host/Makefile:../lib/runtime_tools/c_src/Makefile.in
3646  ../lib/tools/c_src/$host/Makefile:../lib/tools/c_src/Makefile.in
3647  ])
3648
3649AC_CONFIG_FILES([../make/install_dir_data.sh:../make/install_dir_data.sh.in], [chmod +x ../make/install_dir_data.sh])
3650
3651AC_OUTPUT
3652