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