* 2022-01-18 [ci skip]
[ruby-80x24.org.git] / configure.ac
blobb870896b5d367ab0cf3e3d3093c757cfb5042155
1 dnl Process this file with autoconf to produce a configure script.
2 AC_INIT
4 AC_CONFIG_AUX_DIR(tool)
6 AC_PREREQ(2.67)
8 tooldir="$srcdir/tool"
10 AC_DISABLE_OPTION_CHECKING
12 m4_include([tool/m4/_colorize_result_prepare.m4])dnl
13 m4_include([tool/m4/ac_msg_result.m4])dnl
14 m4_include([tool/m4/colorize_result.m4])dnl
15 m4_include([tool/m4/ruby_append_option.m4])dnl
16 m4_include([tool/m4/ruby_append_options.m4])dnl
17 m4_include([tool/m4/ruby_check_builtin_func.m4])dnl
18 m4_include([tool/m4/ruby_check_builtin_setjmp.m4])dnl
19 m4_include([tool/m4/ruby_check_printf_prefix.m4])dnl
20 m4_include([tool/m4/ruby_check_setjmp.m4])dnl
21 m4_include([tool/m4/ruby_check_signedness.m4])dnl
22 m4_include([tool/m4/ruby_check_sizeof.m4])dnl
23 m4_include([tool/m4/ruby_check_sysconf.m4])dnl
24 m4_include([tool/m4/ruby_cppoutfile.m4])dnl
25 m4_include([tool/m4/ruby_decl_attribute.m4])dnl
26 m4_include([tool/m4/ruby_default_arch.m4])dnl
27 m4_include([tool/m4/ruby_define_if.m4])dnl
28 m4_include([tool/m4/ruby_defint.m4])dnl
29 m4_include([tool/m4/ruby_dtrace_available.m4])dnl
30 m4_include([tool/m4/ruby_dtrace_postprocess.m4])dnl
31 m4_include([tool/m4/ruby_func_attribute.m4])dnl
32 m4_include([tool/m4/ruby_mingw32.m4])dnl
33 m4_include([tool/m4/ruby_prepend_option.m4])dnl
34 m4_include([tool/m4/ruby_prog_gnu_ld.m4])dnl
35 m4_include([tool/m4/ruby_replace_funcs.m4])dnl
36 m4_include([tool/m4/ruby_replace_type.m4])dnl
37 m4_include([tool/m4/ruby_rm_recursive.m4])dnl
38 m4_include([tool/m4/ruby_setjmp_type.m4])dnl
39 m4_include([tool/m4/ruby_stack_grow_direction.m4])dnl
40 m4_include([tool/m4/ruby_thread.m4])dnl
41 m4_include([tool/m4/ruby_try_cflags.m4])dnl
42 m4_include([tool/m4/ruby_try_cxxflags.m4])dnl
43 m4_include([tool/m4/ruby_try_ldflags.m4])dnl
44 m4_include([tool/m4/ruby_universal_arch.m4])dnl
45 m4_include([tool/m4/ruby_werror_flag.m4])dnl
47 AC_ARG_VAR([cflags], [additional CFLAGS (ignored when CFLAGS is given)])dnl
48 AC_ARG_VAR([cppflags], [additional CPPFLAGS (ignored when CPPFLAGS is given)])dnl
49 AC_ARG_VAR([cxxflags], [additional CXXFLAGS (ignored when CXXFLAGS is given)])dnl
51 : "environment section" && {
52 HAVE_BASERUBY=yes
53 BASERUBY_VERSION=
54 AC_ARG_WITH(baseruby,
55         AS_HELP_STRING([--with-baseruby=RUBY], [use RUBY as baseruby; RUBY is the pathname of ruby]),
56         [AS_CASE(["$withval"],
57             [*ruby*],[BASERUBY=$withval],
58             [no],[HAVE_BASERUBY=no],
59             [AC_MSG_ERROR(need ruby)])
60         ],
61         [
62                 AC_PATH_PROG([BASERUBY], [ruby], [false])
63         ])
64 AS_IF([test "$HAVE_BASERUBY" != no -a "`RUBYOPT=- $BASERUBY --disable=gems -e 'print 42 if RUBY_VERSION > "2.2"' 2>/dev/null`" = 42], [
65     BASERUBY="$BASERUBY --disable=gems"
66     BASERUBY_VERSION=`$BASERUBY -v`
67     $BASERUBY -C "$srcdir" tool/downloader.rb -d tool -e gnu config.guess config.sub >&AS_MESSAGE_FD
68 ], [
69     BASERUBY="echo executable host ruby is required.  use --with-baseruby option.; false"
70     HAVE_BASERUBY=no
72 AC_SUBST(BASERUBY)
73 AC_SUBST(HAVE_BASERUBY)
75 : ${GIT=git}
76 HAVE_GIT=yes
77 AC_ARG_WITH(git,
78         AS_HELP_STRING([--without-git], [never use git]),
79         [AS_CASE([$withval],
80             [no],  [GIT=never-use HAVE_GIT=no],
81             [yes], [],
82             [GIT=$withval])])
83 AS_IF([test x"$HAVE_GIT" = xyes], [command -v "$GIT" > /dev/null || HAVE_GIT=no])
84 AC_SUBST(GIT)
85 AC_SUBST(HAVE_GIT)
87 eval `sed -n -e ['s/^@%:@define RUBY_[A-Z_]*VERSION_\([A-Z][A-Z][A-Z_0-9]*\) \([0-9][0-9]*\)$/\1=\2/p'] \
88       -e ['s/^@%:@define \(RUBY_PATCHLEVEL\) \(.*\)/\1=\2/p'] \
89      $srcdir/include/ruby/version.h $srcdir/version.h`
90 for v in MAJOR MINOR TEENY; do
91     AS_IF([eval "test \"\$$v\" = ''"], [
92         AC_MSG_ERROR(could not determine $v number from version.h)
93     ])
94 done
95 AC_SUBST(MAJOR)
96 AC_SUBST(MINOR)
97 AC_SUBST(TEENY)
98 AC_SUBST(RUBY_API_VERSION, '$(MAJOR).$(MINOR)')
99 AC_SUBST(RUBY_PROGRAM_VERSION, '$(MAJOR).$(MINOR).$(TEENY)')
101 AS_IF([test "$program_prefix" = NONE], [
102   program_prefix=
104 AS_IF([test "$prefix" -ef .], [
105   AC_MSG_ERROR(--prefix cannot be the current working directory.)
107 RUBY_BASE_NAME=`echo ruby | sed "$program_transform_name"`
108 RUBYW_BASE_NAME=`echo rubyw | sed "$program_transform_name"`
109 AC_SUBST(RUBY_BASE_NAME)
110 AC_SUBST(RUBYW_BASE_NAME)
111 AC_SUBST(RUBY_VERSION_NAME, '${RUBY_BASE_NAME}-${ruby_version}')
113 dnl checks for alternative programs
114 AC_CANONICAL_BUILD
115 AC_CANONICAL_HOST
116 AC_CANONICAL_TARGET
117 AS_CASE(["$target_cpu-$target_os"],
118     [aarch64-darwin*], [
119         target_cpu=arm64
120         AS_CASE(["$target_vendor"], [unknown], [target_vendor=apple target=${target/-unknown-/-apple-}])
121         target="${target/aarch64/arm64}"
122         target_alias="${target_alias/aarch64/arm64}"
123     ])
125 AC_ARG_PROGRAM
126 RUBY_RM_RECURSIVE
127 AC_ARG_WITH(gcc,
128         AS_HELP_STRING([--without-gcc], [never use gcc]),
129         [
130         AS_CASE([$withval],
131             [no],  [: ${CC=cc}],
132             [yes], [: ${CC=gcc}],
133                    [CC=$withval])])
134 dnl If the user switches compilers, we can't believe the cache
135 AS_IF([test ! -z "$ac_cv_prog_CC" -a ! -z "$CC" -a "$CC" != "$ac_cv_prog_CC"], [
136   AC_MSG_ERROR(cached CC is different -- throw away $cache_file
137 (it is also a good idea to do 'make clean' before compiling))
139 AS_CASE(["${build_os}"],
140 [linux*|cygwin*|msys*], [
141     # Naruse prefers GCC on Linux
142     AC_CHECK_TOOLS([CC], [gcc clang cc])
144 [solaris*], [
145     # Clang on Solaris is largely untested.
146     # https://bugs.ruby-lang.org/issues/17949
147     AC_CHECK_TOOLS([CC], [cc gcc])
148 ], [
149     # OpenBSD wants to prefer cc over gcc.
150     # See https://github.com/ruby/ruby/pull/2443
151     AC_CHECK_TOOLS([CC], [cl.exe clang cc gcc c99 /usr/ucb/cc])
154 AC_ARG_VAR([AR],       [Archiver command])
155 AC_ARG_VAR([AS],       [Assembler command])
156 AC_ARG_VAR([CC],       [C compiler command])
157 AC_ARG_VAR([CXX],      [C++ compiler command])
158 AC_ARG_VAR([LD],       [Linker command])
159 AC_ARG_VAR([NM],       [Symbol list command])
160 AC_ARG_VAR([OBJCOPY],  [Objcopy command])
161 AC_ARG_VAR([OBJDUMP],  [Objdump command])
162 AC_ARG_VAR([RANLIB],   [Ranlib command])
163 AC_ARG_VAR([STRIP],    [Strip command])
165 # We don't want to bother things like `ccache gcc`, `clang -shared-libgcc`, ...
166 set rb_dummy ${CC}
167 rb_CC=$2
168 AS_CASE(["/${rb_CC} "],
169 [*@<:@\ /@:>@"cc "*], [
170     # Don't try g++/clang++ when CC=cc
171     AC_CHECK_TOOLS([CXX],    [cl.exe CC c++])
173 [*icc*],              [
174     # Intel C++ has interprocedural optimizations.  It tends to come with its
175     # own linker etc.
176     AC_CHECK_TOOL([AR],      [`echo "${rb_CC}" | sed s/icc/xiar/`])
177     AC_CHECK_TOOL([CXX],     [`echo "${rb_CC}" | sed s/icc/icpc/`])
178     AC_CHECK_TOOL([LD],      [`echo "${rb_CC}" | sed s/icc/xild/`])
180 [*gcc*],              [
181     # Dito for GCC.
182     AC_CHECK_TOOL([LD],      [`echo "${rb_CC}" | sed s/gcc/ld/`])
183     AC_CHECK_TOOL([AR],      [`echo "${rb_CC}" | sed s/gcc/gcc-ar/`])
184     AC_CHECK_TOOL([CXX],     [`echo "${rb_CC}" | sed s/gcc/g++/`])
185     AC_CHECK_TOOL([NM],      [`echo "${rb_CC}" | sed s/gcc/gcc-nm/`])
186     AC_CHECK_TOOL([RANLIB],  [`echo "${rb_CC}" | sed s/gcc/gcc-ranlib/`])
188 [*clang*],            [
189     # Dito for LLVM.  Note however that llvm-as is a LLVM-IR to LLVM bitcode
190     # assembler that does not target your machine native binary.
191     : ${LD:="${CC}"}         # ... try -fuse-ld=lld ?
192     AC_CHECK_TOOL([AR],      [`echo "${rb_CC}" | sed s/clang/llvm-ar/`])
193 #   AC_CHECK_TOOL([AS],      [`echo "${rb_CC}" | sed s/clang/llvm-as/`])
194     AC_CHECK_TOOL([CXX],     [`echo "${rb_CC}" | sed s/clang/clang++/`])
195     AC_CHECK_TOOL([NM],      [`echo "${rb_CC}" | sed s/clang/llvm-nm/`])
196     AC_CHECK_TOOL([OBJCOPY], [`echo "${rb_CC}" | sed s/clang/llvm-objcopy/`])
197     AC_CHECK_TOOL([OBJDUMP], [`echo "${rb_CC}" | sed s/clang/llvm-objdump/`])
198     AC_CHECK_TOOL([RANLIB],  [`echo "${rb_CC}" | sed s/clang/llvm-ranlib/`])
199     AC_CHECK_TOOL([STRIP],   [`echo "${rb_CC}" | sed s/clang/llvm-strip/`])
201 AS_UNSET(rb_CC)
202 AS_UNSET(rb_dummy)
204 AS_CASE(["${build_os}"],
205 [solaris*], [
206     AC_PATH_TOOL([LD], [ld], [/usr/ccs/bin/ld], [/usr/ccs/bin:$PATH])
208 [aix*], [
209     AC_PATH_TOOL([NM], [nm], [/usr/ccs/bin/nm], [/usr/ccs/bin:$PATH])
211 AS_CASE(["${target_os}"],
212 [cygwin*|msys*|mingw*], [
213     ac_cv_prog_ac_ct_OBJCOPY=":"
216 rb_test_CFLAGS=${CFLAGS+yes}
217 rb_test_CXXFLAGS=${CXXFLAGS+yes}
219 # BSD's ports and MacPorts prefix GNU binutils with 'g'
221 dnl Seems necessarily in order to add -std=gnu99 option for gcc 4.9.
222 m4_version_prereq([2.70], [AC_PROG_CC], [AC_PROG_CC_C99])
224 AC_PROG_CXX
225 AC_PROG_CPP
226 AC_PROG_RANLIB
227 AC_CHECK_TOOLS([AR],      [gar ar])
228 AC_CHECK_TOOLS([AS],      [gas as])
229 AC_CHECK_TOOLS([LD],      [gld ld]) # ... try gold ?
230 AC_CHECK_TOOLS([NM],      [gnm nm])
231 AC_CHECK_TOOLS([OBJCOPY], [gobjcopy objcopy])
232 AC_CHECK_TOOLS([OBJDUMP], [gobjdump objdump])
233 AC_CHECK_TOOLS([STRIP],   [gstrip strip], [:])
235 AS_IF([test ! $rb_test_CFLAGS], [AS_UNSET(CFLAGS)]); AS_UNSET(rb_test_CFLAGS)
236 AS_IF([test ! $rb_test_CXXFLAGS], [AS_UNSET(CXXFLAGS)]); AS_UNSET(rb_save_CXXFLAGS)
238 AS_IF([test "${CXX}" = "g++" -a -z "${GXX}"], [
239     # AC_PROG_CXX sets $CXX to "g++" when it purposefully finds that there is
240     # _no_ g++.  This brain-damaged design must be worked around.  Thankfully,
241     # similar thing doesn't happen for AC_PROG_CC.
242     rb_there_is_in_fact_no_gplusplus_but_autoconf_is_cheating_us=true
245 test x"$target_alias" = x &&
246 target_os=`echo $target_os | sed 's/linux-gnu$/linux/;s/linux-gnu/linux-/'`
247 ac_install_sh='' # unusable for extension libraries.
249 AC_ARG_WITH(os-version-style,
250         AS_HELP_STRING([--with-os-version-style=TYPE],
251                        [OS version number for target and target_os [[full]]]
252                        [(full|teeny|minor+0|minor|major+0|major|none)]),
253         [os_version_style=$withval],
254         [os_version_style=full
255             AS_CASE($target_os, [[*[0-9].*]],
256                 [AS_CASE([`/usr/bin/ruby -e 'puts RUBY_PLATFORM' 2>/dev/null`],
257                     [[*-*[0-9].*.0]], [os_version_style=minor+0],
258                     [[*-*[0-9].*.*]], [os_version_style=full],
259                     [[*-*[0-9].0]  ], [os_version_style=major+0],
260                     [[*-*[0-9].*]  ], [os_version_style=minor],
261                     [[*-*[0-9]]    ], [os_version_style=major],
262                 )])
263         ])
264 os_version_style_transform=
265 AS_CASE("${os_version_style}",
266         [full|teeny], [],
267         [minor+0], [os_version_style_transform=['s/\([0-9]\.[0-9][0-9]*\)\.[0-9][.0-9]*$/\1.0/']],
268         [minor],   [os_version_style_transform=['s/\([0-9]\.[0-9][0-9]*\)\.[0-9][.0-9]*$/\1/']],
269         [major+0], [os_version_style_transform=['s/\([0-9]\)\.[0-9][.0-9]*$/\1.0/']],
270         [major],   [os_version_style_transform=['s/\([0-9]\)\.[0-9][.0-9]*$/\1/']],
271         [none],    [os_version_style_transform=['s/[0-9]*\.[0-9][.0-9]*$//']],
272         [AC_MSG_ERROR(unknown --with-os-version-style: $withval)])
273 AS_IF([test -z "$target_alias" -a -n "$os_version_style_transform"],
274         [
275         target=`echo ${target} | sed "$os_version_style_transform"`
276         target_os=`echo ${target_os} | sed "$os_version_style_transform"`
277         ])
279 AC_ARG_WITH(arch,
280         AS_HELP_STRING([--with-arch=ARCHS],
281                        [build an Apple/NeXT Multi Architecture Binary (MAB);
282                           ARCHS is a comma-delimited list of architectures for
283                           which to build; if this option is disabled or omitted
284                           entirely, then the package will be built only for the
285                           target platform]),
286        [target_archs="$withval"], [unset target_archs])
288 AC_ARG_ENABLE(load-relative,
289        AS_HELP_STRING([--enable-load-relative], [resolve load paths at run time]),
290        [load_relative=$enableval])
292 # checks for UNIX variants that set C preprocessor variables
293 AC_USE_SYSTEM_EXTENSIONS
295 dnl Checks for programs.
297 cflagspat=
298 test -z "$optflags" ||
299     cflagspat="$cflagspat;s|"`eval echo '"'"${optflags}"'"' | sed 's/[[][|.*]]/\\&/g;s/^ */ /;s/ *$/ /'`'| |g'
300 test -z "$debugflags" ||
301     cflagspat="$cflagspat;s|"`eval echo '"'"${debugflags}"'"' | sed 's/[[][|.*]]/\\&/g;s/^ */ /;s/ *$/ /'`'| |g'
302 test -z "$warnflags" ||
303     cflagspat="$cflagspat;s|"`eval echo '"'"${warnflags}"'"' | sed 's/[[][|.*]]/\\&/g;s/^ */ /;s/ *$/ /'`'| |g'
304 AS_IF([test -z "${CFLAGS+set}"], [
305     cflags=`echo " $cflags " | sed "$cflagspat;s/^ *//;s/ *$//"`
306     orig_cflags="$cflags"
307     cflags="$cflags "'${optflags} ${debugflags} ${warnflags}'
309 dnl AS_IF([test -z "${CXXFLAGS+set}"], [
310 dnl     cxxflags=`echo " $cxxflags " | sed "$cflagspat;s/^ *//;s/ *$//"`
311 dnl     orig_cxxflags="$cxxflags"
312 dnl     cxxflags="$cxxflags "'${optflags} ${debugflags} ${warnflags}'
313 dnl ])
315 AS_CASE(["$host_os:$build_os"],
316 [darwin*:darwin*], [
317     # Following Apple deployed clang are broken
318     # clang version 1.0 (http://llvm.org/svn/llvm-project/cfe/tags/Apple/clang-23 exported)
319     # Apple clang version 2.0 (tags/Apple/clang-137) (based on LLVM 2.9svn)
320     # Apple clang version 2.1 (tags/Apple/clang-163.7.1) (based on LLVM 3.0svn)
321     AC_PREPROC_IFELSE(
322         [AC_LANG_PROGRAM([
323             @%:@if defined __APPLE_CC__ && defined __clang_major__ && __clang_major__ < 3
324             @%:@error premature clang
325             @%:@endif
326         ])],
327         [],
328         [AC_MSG_ERROR([clang version 3.0 or later is required])])
331 AS_CASE(["$target_os"],
332 [darwin*], [
333     AC_MSG_CHECKING(if minimum required OS X version is supported)
334     AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@include <AvailabilityMacros.h>
335         @%:@if MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_5
336         @%:@error pre OS X 10.5
337         [!<===== pre OS X 10.5 =====>]
338         @%:@endif
339         ]])],
340         [macosx_min_required=yes],
341         [AC_MSG_RESULT(no)
342         AC_MSG_ERROR([Unsupported OS X version is required])])
343     AC_MSG_RESULT(${macosx_min_required})
346 RUBY_MINGW32
347 AC_SUBST(GCC)
348 AC_SUBST(LD)
349 AS_IF([test "$GCC" = yes], [
350     linker_flag=-Wl,
351     : ${optflags=-O3}
352     gcc_major=`echo =__GNUC__ | $CC -E -xc - | sed '/^=/!d;s///'`
353     gcc_minor=`echo =__GNUC_MINOR__ | $CC -E -xc - | sed '/^=/!d;s///'`
354     test -n "$gcc_major" || gcc_major=0
355     test -n "$gcc_minor" || gcc_minor=0
356     icc_version=`echo =__ICC | $CC -E -xc - | sed '/^=/!d;s///;/^__ICC/d'`
357     test -n "$icc_version" || icc_version=0
358     # RUBY_APPEND_OPTIONS(XCFLAGS, ["-include ruby/config.h" "-include ruby/missing.h"])
359 ], [
360     linker_flag=
363 AS_IF([test "$GCC" = yes -a "$gcc_major" -lt 3 ], [
364     AC_MSG_ERROR([too old GCC])
367 RUBY_PROG_GNU_LD
368 RUBY_CPPOUTFILE
370 : ${OUTFLAG='-o '}
371 : ${COUTFLAG=${OUTFLAG}}
372 : ${CSRCFLAG=''}
373 AC_SUBST(OUTFLAG)
374 AC_SUBST(COUTFLAG)
375 AC_SUBST(CSRCFLAG)
377 : ${MJIT_CC=$CC}
378 AS_IF([test "x$cross_compiling" = xno], [
379     AC_PATH_PROG([MJIT_CC], ${MJIT_CC})
381     # if $CC is in /usr/lib/ccache/$CC, search original $CC (disable ccache)
382     AS_IF([echo $RUBY_DEBUG | grep ci > /dev/null &&
383            echo $MJIT_CC | grep ^/usr/lib/ccache > /dev/null], [
384            PATH=`echo $PATH | sed "s/\/usr\/lib\/ccache://"` MJIT_CC=`which $CC`])
386     AS_CASE([$target_os],
387         [*mingw*], [command -v cygpath > /dev/null && MJIT_CC=`cygpath -ma $MJIT_CC`])
388     shift 2
389     MJIT_CC="$MJIT_CC${1+ }$*"
392 AS_CASE(["$build_os"],
393   [darwin1*.*], [
394     # Xcode linker warns for deprecated architecture and wrongly
395     # installed TBD files.
396     CC_WRAPPER=""
397     echo 'int main(void) {return 0;}' > conftest.c
398     AS_IF([$CC -framework Foundation -o conftest conftest.c 2>&1 |
399            grep '^ld: warning: text-based stub file' >/dev/null], [
400         CC_WRAPPER=`cd -P "${tooldir}" && pwd`/darwin-cc
401         CC="$CC_WRAPPER $CC"
402     ])
403     rm -fr conftest*
404   ])
406 cc_version=
407 for option in --version -v -V -qversion; do
408     cc_version_message=`$CC $option 2>&1`
409     cc_version_status=$?
410     AS_CASE($cc_version_status, [0], [:], [continue])
411     AS_CASE($cc_version_message, [*Warning*], [continue])
412     cc_version='$(CC) '$option
413     break
414 done
415 AC_SUBST(CC_VERSION, $cc_version)
416 AC_SUBST(CC_VERSION_MESSAGE, $cc_version_message)
418 : ${DLDFLAGS="$LDFLAGS"}
420 RUBY_UNIVERSAL_ARCH
421 AS_IF([test "$target_cpu" != "$host_cpu" -a "$GCC" = yes -a "$cross_compiling" = no -a "${universal_binary:-no}" = no], [
422     RUBY_DEFAULT_ARCH("$target_cpu")
424 host_os=$target_os
425 host_vendor=$target_vendor
426 host_cpu=$target_cpu
427 host=$target
428 host_alias=$target_alias
430 AC_CACHE_CHECK([for $AR flags], [rb_cv_arflags], [
431     AS_IF([$AR rcD conftest.a > /dev/null 2>&1 && rm conftest.a],
432         [rb_cv_arflags=rcD], [rb_cv_arflags=rcu])
434 AC_SUBST(ARFLAGS, ["$rb_cv_arflags "])
435 AC_SUBST(ASFLAGS)
437 AS_CASE(["$target_os"],
438 [cygwin*|msys*|mingw*], [
439     AC_CHECK_TOOL(WINDRES, windres)
440     AC_CHECK_TOOL(DLLWRAP, dllwrap)
441     target=`echo $target | sed "s/^$target_cpu-/-/"`
442     target_alias=`echo $target_alias | sed "s/^$target_cpu-/-/"`
443     target_cpu=`echo $target_cpu | sed s/i.86/i386/`
444     AS_CASE(["$target"], [-*], [ target="$target_cpu${target}"])
445     AS_CASE(["$target_alias"], [-*], [ target_alias="$target_cpu${target_alias}"])
446     AS_CASE(["$target_os"],
447     [mingw*], [
448         test "$rb_cv_msvcrt" = "" && unset rb_cv_msvcrt
449         AC_CACHE_CHECK(for mingw32 runtime DLL, rb_cv_msvcrt, [
450         AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <stdio.h>]],
451                     [[FILE* volatile f = stdin; return 0;]])],
452                     [rb_cv_msvcrt=`$OBJDUMP -p conftest$ac_exeext |
453                                    tr A-Z a-z |
454                                    sed -n '/^[[         ]]*dll name: \(msvc.*\)\.dll$/{s//\1/p;q;};
455                                         /^[[    ]]*dll name: \(ucrtbase\|api-ms-win-crt-.*\)\.dll$/{s//ucrt/p;q;}'`],
456                     [rb_cv_msvcrt=msvcrt])
457         test "$rb_cv_msvcrt" = "" && rb_cv_msvcrt=msvcrt])
458         RT_VER=`echo "$rb_cv_msvcrt" | tr -cd [0-9]`
459         test "$RT_VER" = "" && RT_VER=60
460         test "$rb_cv_msvcrt" = "ucrt" && RT_VER=140
461         AC_DEFINE_UNQUOTED(RUBY_MSVCRT_VERSION, $RT_VER)
462         sysconfdir=
463     ])
464     : ${enable_shared=yes}
465     ],
466 [hiuxmpp*], [AC_DEFINE(__HIUX_MPP__)])    # by TOYODA Eizi <toyoda@npd.kishou.go.jp>
468 AC_PROG_LN_S
469 AC_PROG_MAKE_SET
470 AC_PROG_INSTALL
471 AC_PROG_MKDIR_P
472 AS_IF([test "x$MKDIR_P" = "x -d"], [
473   AS_IF([test x"$as_mkdir_p" != xfalse], [
474     MKDIR_P='mkdir -p'
475     echo "use 'mkdir -p' as MKDIR_P"
476   ], [
477     AC_MSG_ERROR([mkdir -p is required])
478   ])
480 MAKEDIRS="$MKDIR_P"
481 AC_SUBST(MAKEDIRS)
483 AC_CHECK_PROG([DTRACE], [${ac_tool_prefix}dtrace], [${ac_tool_prefix}dtrace])
484 AS_IF([test "$cross_compiling:$ac_cv_prog_DTRACE" = no: -a -n "$ac_tool_prefix"], [
485     AC_CHECK_PROG([DTRACE], [dtrace], [dtrace])
488 AC_CHECK_PROGS(DOT, dot)
489 AC_CHECK_PROGS(DOXYGEN, doxygen)
491 for prog in ${ac_tool_prefix:+${ac_tool_prefix}pkg-config} pkg-config; do
492     AC_CHECK_PROG(PKG_CONFIG, $prog, [$prog], [], [],
493         [`"$as_dir/$ac_word$ac_exec_ext" --print-errors --version > /dev/null 2>&1 || echo "$as_dir/$ac_word$ac_exec_ext"`])
494     test -z "${PKG_CONFIG}" || break
495 done
497 AC_MSG_CHECKING([whether it is Android])
498 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
499         @%:@ifndef __ANDROID__
500         @%:@error Not android
501         @%:@endif
502 ]], [[]])],
504         AC_MSG_RESULT(yes)
505         target_os=${target_os}-android
506         AS_IF([test "x$cross_compiling" = xno], [
507                 AC_MSG_CHECKING([for Android API version])
508                 # hacky workaround: https://github.com/termux/termux-packages/issues/6176
509                 rb_android_api=`getprop ro.build.version.sdk`
510                 AC_MSG_RESULT($rb_android_api)
511                 RUBY_APPEND_OPTIONS(CPPFLAGS, -D__ANDROID_API__=$rb_android_api -Wno-macro-redefined)
512         ])
514 [AC_MSG_RESULT(no)])
516 AC_SUBST(RM, ['rm -f'])
517 AC_SUBST(CP, ['cp'])
518 RMDIRS='$(top_srcdir)/tool/rmdirs'
519 RMDIR=rmdir
520 mkdir "rmdirs_$$_test" "rmdirs_$$_test/a"
521 rmdir --ignore-fail-on-non-empty "rmdirs_$$_test" 2>/dev/null &&
522 RMDIR='rmdir --ignore-fail-on-non-empty'
523 $RMDIR -p "rmdirs_$$_test/a" 2>/dev/null &&
524 { test -d "rmdirs_$$_test" || RMDIRS="$RMDIR -p"; }
525 rmdir "rmdirs_$$_test/a" "rmdirs_$$_test" 2>/dev/null
526 AC_SUBST(RMDIR)
527 AC_SUBST(RMDIRS)
528 AC_SUBST(RMALL, ['rm -fr'])
530 AC_MSG_CHECKING([for cd using physical directory])
531 rm -fr conf$$.dir
532 mkdir conf$$.dir &&
533 (cd conf$$.dir && mkdir src build && cd src &&
534 $as_ln_s ../build . > /dev/null 2>&1 && cd build &&
535 for chdir in 'cd -P' 'PWD= cd'; do
536     /bin/sh -c "$chdir ../src && echo '$chdir' > cdcmd" 2> /dev/null && break
537 done)
538 AS_IF([test -f conf$$.dir/src/cdcmd], [
539     read CHDIR < conf$$.dir/src/cdcmd 2> /dev/null
540 ], [
541     CHDIR=cd
543 rm -fr conf$$.dir
544 AC_MSG_RESULT([$CHDIR])
545 AC_SUBST(CHDIR)
548 : "compiler section" && {
549 RUBY_WERROR_FLAG([
550     AC_MSG_CHECKING([whether CFLAGS is valid])
551     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
552         [AC_MSG_RESULT(yes)],
553         [
554         AC_MSG_RESULT(no)
555         AC_MSG_ERROR([something wrong with CFLAGS="$CFLAGS"])
556         ]
557     )
559     AC_MSG_CHECKING([whether LDFLAGS is valid])
560     {
561         mkdir tmp.$$.try_link &&
562         cd tmp.$$.try_link &&
563         cp ../confdefs.h . &&
564         echo '<?xml?><plist><dict><key>CFBundleIdentifier</key><string></string></dict></plist>' > Info.plist &&
565         :
566     } || AC_MSG_ERROR([failed to make temporary directory])
567     AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
568         [AC_MSG_RESULT(yes)],
569         [
570         cd .. && rm -fr tmp.$$.try_link
571         AC_MSG_RESULT(no)
572         AC_MSG_ERROR([something wrong with LDFLAGS="$LDFLAGS"])
573         ]
574     )
575     cd .. && rm -fr tmp.$$.try_link
578 : ${RPATHFLAG=''}
579 rpathflag=''
580 AS_IF([test x"${RPATHFLAG}" = x], [
581     AS_CASE(["$target_os"],
582         [hpux*], [AS_IF([test "$rb_cv_prog_gnu_ld" = no], [rpathflag='+b '])],
583         [aix*], [rpathflag='-blibpath:'],
584         [for rpathflag in -R "-rpath "; do
585             AS_CASE("$rpathflag",
586                     [*" "], [AS_CASE(["${linker_flag}"],
587                                      [*,], [rpathflag=`echo "$rpathflag" | tr ' ' ,`])])
588             rpathflag="${linker_flag}${rpathflag}"
589             RUBY_TRY_LDFLAGS([${rpathflag}.], [], [rpathflag=])
590             AS_IF([test "x${rpathflag}" != x], [])
591         done])
592 ], [
593     rpathflag=`echo "$RPATHFLAG" | sed 's/%.*//'`
596 RUBY_TRY_LDFLAGS(-fdeclspec, [fdeclspec=yes], [fdeclspec=no])
597 AS_IF([test "$fdeclspec" = yes], [
598     RUBY_APPEND_OPTIONS(CFLAGS, -fdeclspec)
599     RUBY_APPEND_OPTIONS(cflags, -fdeclspec)
600     RUBY_APPEND_OPTIONS(orig_cflags, -fdeclspec)
602 RUBY_TRY_CXXFLAGS(-fdeclspec, [fdeclspec=yes], [fdeclspec=no])
603 AS_IF([test "$fdeclspec" = yes], [
604     RUBY_APPEND_OPTIONS(CXXFLAGS, -fdeclspec)
607 AS_CASE([$RUBY_PATCHLEVEL], [-*],
608         [RUBY_DEVEL=yes], [RUBY_DEVEL=no])
609 particular_werror_flags=$RUBY_DEVEL
610 AC_ARG_ENABLE(werror,
611         AS_HELP_STRING([--disable-werror],
612                        [don't make warnings into errors
613                        even if a compiler support -Werror feature
614                        [[disabled by default unless development version]]]),
615         [particular_werror_flags=$enableval])
617 rb_cv_warnflags="$warnflags"
618 AS_CASE(["$GCC:${warnflags+set}:${extra_warnflags:+set}:"],
619 [yes::*|yes:*:set:], [# GCC && (!warnflags || extra_warnflags)
620     AS_IF([test $gcc_major -ge 4], [
621         extra_warnflags="$extra_warnflags -Werror=extra-tokens"
622     ])
623     AS_IF([test $gcc_major -ge 5 -a $gcc_major -le 6], [
624         extra_warnflags="$extra_warnflags -Wno-maybe-uninitialized"
625     ])
626     # ICC doesn't support -Werror=
627     AS_IF([test $icc_version -gt 0], [
628         particular_werror_flags=no
629     ])
630     for wflag in \
631                  -Werror=deprecated-declarations \
632                  -Werror=division-by-zero \
633                  -Werror=duplicated-cond \
634                  -Werror=implicit-function-declaration \
635                  -Werror=implicit-int \
636                  -Werror=misleading-indentation \
637                  -Werror=pointer-arith \
638                  -Werror=shorten-64-to-32 \
639                  -Werror=write-strings \
640                  -Werror=old-style-definition \
641                  -Wimplicit-fallthrough=0 \
642                  -Wmissing-noreturn \
643                  -Wno-cast-function-type \
644                  -Wno-constant-logical-operand \
645                  -Wno-long-long \
646                  -Wno-missing-field-initializers \
647                  -Wno-overlength-strings \
648                  -Wno-packed-bitfield-compat \
649                  -Wno-parentheses-equality \
650                  -Wno-self-assign \
651                  -Wno-tautological-compare \
652                  -Wno-unused-parameter \
653                  -Wno-unused-value \
654                  -Wsuggest-attribute=format \
655                  -Wsuggest-attribute=noreturn \
656                  -Wunused-variable \
657                  -diag-disable=175,188,1684,2259,2312 \
658                  $extra_warnflags \
659                  ; do
660         AS_IF([test "$particular_werror_flags" != yes], [
661             wflag=`echo x$wflag | sed 's/^x-Werror=/-W/;s/^x//'`
662         ])
663         ok=no
664         RUBY_TRY_CFLAGS($wflag, [
665             RUBY_APPEND_OPTIONS(warnflags, $wflag)
666             ok=yes
667         ])
668         AS_CASE([$ok:$wflag], [no:-Werror=*], [
669             wflag=`echo x$wflag | sed 's/^x-Werror=/-W/'`
670             RUBY_TRY_CFLAGS($wflag, [
671                 RUBY_APPEND_OPTIONS(warnflags, $wflag)
672                 particular_werror_flags=no
673             ])
674         ])
675     done
676     AS_IF([test "$particular_werror_flags" = "yes"], [
677         wflag=-Werror=undef
678     ], [
679         wflag=-Wundef
680     ])
681     RUBY_TRY_CFLAGS($wflag, [
682         RUBY_APPEND_OPTIONS(warnflags, $wflag)
683     ], [], [
684         @%:@if !defined(RUBY_CONFIG_TEST_NEVER_DEFINED_SYMBOL)
685         @%:@elif RUBY_CONFIG_TEST_NEVER_DEFINED_SYMBOL
686         @%:@endif
687     ])
688     AS_CASE([" $warnflags "],[*" -Wno-missing-field-initializers "*], [wflag="-Wall -Wextra"],
689                              [wflag=-Wall])
690     RUBY_TRY_CFLAGS($wflag, [warnflags="$wflag${warnflags+ $warnflags}"])
691     # Disable warnflags while conftest. -Werror=* flags might make bad OS capability guess.
692     rb_cv_warnflags="$warnflags"
693     warnflags=
695 RUBY_TRY_CFLAGS(-Qunused-arguments, [RUBY_APPEND_OPTIONS(rb_cv_wsuppress_flags, -Qunused-arguments)])
696 AC_COMPILE_IFELSE([
697     AC_LANG_PROGRAM([
698 @%:@if !(defined(__SUNPRO_C)||defined(__SUNPRO_CC))
699 @%:@error not sunpro
700 @%:@endif],[])], [
701     for e in \
702         E_STATEMENT_NOT_REACHED \
703         E_INIT_SIGN_EXTEND \
704         E_INIT_DOES_NOT_FIT \
705         E_INITIALIZATION_TYPE_MISMATCH
706     do
707         RUBY_TRY_CFLAGS([-erroff=${e}], [
708             RUBY_APPEND_OPTIONS(rb_cv_warnflags, [-erroff=${e}])
709         ])
710     done
713 AC_ARG_WITH(compress-debug-sections,
714         AS_HELP_STRING([--with-compress-debug-sections=type],
715             [enable debug section compression]),
716         [compress_debug_sections=$withval], [compress_debug_sections=])
718 AS_IF([test "$GCC" = yes], [
719     # -D_FORTIFY_SOURCE
720     # When defined _FORTIFY_SOURCE, glibc enables some additional sanity
721     # argument check. The performance drop is very little and Ubuntu enables
722     # _FORTIFY_SOURCE=2 by default. So, let's support it for protecting us from
723     # a mistake of silly C extensions.
725     # TODO: check if link succeeds with _FORTIFY_SOURCE=2.
726     AS_CASE(["$target_os"],
727     [mingw*], [
728         fortify_source=no
729     ])
730     AC_ARG_ENABLE(fortify_source,
731                   AS_HELP_STRING([--disable-fortify-source],
732                                  [disable -D_FORTIFY_SOURCE=2 option, which causes link error on mingw]),
733                   [fortify_source=$enableval])
734     AS_IF([test "x$fortify_source" != xno], [
735         RUBY_TRY_CFLAGS([$optflags -D_FORTIFY_SOURCE=2], [RUBY_APPEND_OPTION(XCFLAGS, -D_FORTIFY_SOURCE=2)], [],
736                         [@%:@include <stdio.h>])
737     ])
739     : ${MJIT_HEADER_FLAGS='-P -dD'}
741     # -fstack-protector
742     AS_CASE(["$target_os"],
743     [mingw*|emscripten*], [
744         stack_protector=no
745     ])
746     AS_IF([test -z "${stack_protector+set}"], [
747         AS_FOR(option, opt, [-fstack-protector-strong -fstack-protector], [
748             RUBY_TRY_CFLAGS(option, [stack_protector=yes])
749             AS_IF([test "x$stack_protector" = xyes], [
750                 RUBY_TRY_LDFLAGS(option, [], [stack_protector=])
751             ])
752             AS_IF([test "x$stack_protector" = xyes], [stack_protector=option; break])
753         ])
754     ])
755     AS_CASE(["$stack_protector"], [-*], [
756         RUBY_APPEND_OPTION(XCFLAGS, $stack_protector)
757         RUBY_APPEND_OPTION(XLDFLAGS, $stack_protector)
758         RUBY_APPEND_OPTION(LDFLAGS, $stack_protector)
759     ])
761     AS_CASE("${compress_debug_sections:-zlib}",
762     [none|no], [], [
763     RUBY_TRY_LDFLAGS(${linker_flag}--compress-debug-sections=${compress_debug_sections:-zlib},
764                      [compress_debug_sections=${compress_debug_sections:-zlib}],
765                      [compress_debug_sections=no])
766     ])
767     AS_IF([test "x$compress_debug_sections" != xno], [
768         RUBY_APPEND_OPTION(DLDFLAGS, ${linker_flag}--compress-debug-sections=$compress_debug_sections)
769     ])
771     AS_CASE(["$target_os"],[mingw*], [
772       # On  Windows  platforms,   system  provided  headers  are  VC++
773       # optimized.  That  is, C++  habits are often  contaminated into
774       # various  headers.  Most frequent  situation is  the use  of //
775       # comments.   We  bypass  ANSI   C  mode  for  them.   Otherwise
776       # extension libs cannot include those headers.
778       # Since math.h in some mingw64 wrongly declares frexp and modf
779       # to be pure, the variables pointed by the second arguments are
780       # considered uninitialized unexpectedly.
781       AC_CACHE_CHECK([whether frexp and modf are broken],
782         rb_cv_mingw64_broken_frexp_modf,
783         [
784           save_CFLAGS="$CFLAGS"
785           AS_IF([test "$particular_werror_flags" = "yes"], [
786             CFLAGS="$CFLAGS -Werror=uninitialized"
787           ], [
788             CFLAGS="$CFLAGS -Werror -Wuninitialized"
789           ])
790           AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <math.h>
791             int foo(double x)
792             {
793               int exp;
794               frexp(x, &exp);
795               return exp;
796             }]], [[if (foo(0.0)) return 1;]])],
797             [rb_cv_mingw64_broken_frexp_modf=no],
798             [rb_cv_mingw64_broken_frexp_modf=yes])
799           CFLAGS="$save_CFLAGS"
800         ])
801       AS_IF([test "$rb_cv_mingw64_broken_frexp_modf" = yes], [
802         AC_DEFINE(RUBY_MINGW64_BROKEN_FREXP_MODF)
803       ])
804     ],
805     [cygwin*|msys*|darwin*|netbsd*], [
806       # need lgamma_r()
807     ])
809     # ANSI (no XCFLAGS because this is C only)
810     AS_CASE(["$target_os"],
811     [solaris*], [
812       # Because "-std=gnu99" affects existence of functions on Solaris,
813       # "-std=gnu99" will be appended to CPPFLAGS.
814         for ansi_options in -std=gnu99; do
815             RUBY_TRY_CFLAGS(${ansi_options}, [
816                 RUBY_APPEND_OPTIONS(CPPFLAGS, ${ansi_options})
817             ], [ansi_options=])
818             test "x${ansi_options}" = x || break
819         done
820     ],
821     [
822       # ANSI (no XCFLAGS because this is C only)
823       rb_tmp_std_check=`echo $CC $CFLAGS $optflags $warnflags $debugflags | fgrep std= | tr -d  '\015'`
824       AS_IF([test "x$rb_tmp_std_check" = "x"],
825       [
826         for ansi_options in -std=gnu99; do
827             RUBY_TRY_CFLAGS(${ansi_options}, [
828                 RUBY_APPEND_OPTIONS(warnflags, ${ansi_options})
829                 RUBY_APPEND_OPTIONS(strict_warnflags, ${ansi_options})
830             ], [ansi_options=])
831             test "x${ansi_options}" = x || break
832         done
833       ])
834     ])
836     # suppress annoying -Wstrict-overflow warnings
837     RUBY_TRY_CFLAGS(-fno-strict-overflow, [RUBY_APPEND_OPTION(XCFLAGS, -fno-strict-overflow)])
839     test "${debugflags+set}" || {RUBY_TRY_CFLAGS(-ggdb3, [debugflags=-ggdb3])}
840     test "${debugflags+set}" || {RUBY_TRY_CFLAGS(-ggdb, [debugflags=-ggdb])}
841     test "${debugflags+set}" || {RUBY_TRY_CFLAGS(-g3, [debugflags=-g3])}
843 test $ac_cv_prog_cc_g = yes && : ${debugflags=-g}
844 AS_IF([test "x$RUBY_DEVEL" = xyes], [RUBY_APPEND_OPTION(XCFLAGS, -DRUBY_DEVEL=1)])
846 AS_IF([test "$GCC" = ""], [
847     AS_CASE(["$target_os"],[aix*],[warnflags="$warnflags -qinfo=por" rb_cv_warnflags="$rb_cv_warnflags -qinfo=por"])
849 AS_IF([test "$GCC" = yes], [
850     AS_IF([test "$gcc_major" -ge 4], [
851         RUBY_TRY_CFLAGS(-fvisibility=hidden, [visibility_option=yes], [visibility_option=no])
852     ])
853     AC_SUBST(WERRORFLAG, "-Werror")
854     AS_IF([test "$visibility_option" = yes], [
855         RUBY_APPEND_OPTION(XCFLAGS, -fvisibility=hidden)
856         AC_DEFINE(RUBY_SYMBOL_EXPORT_BEGIN, [_Pragma("GCC visibility push(default)")])
857         AC_DEFINE(RUBY_SYMBOL_EXPORT_END,   [_Pragma("GCC visibility pop")])
858     ], [
859         RUBY_TRY_LDFLAGS([-Wl,-unexported_symbol,_Init_*], [visibility_option=ld], [visibility_option=no])
860     ])
861     test "$visibility_option" = no || OBJCOPY=:
864 AS_IF([test "$GCC" = yes], [
865     # optflags
867     AS_CASE(["$target_os"], [mingw*], [
868         RUBY_TRY_CFLAGS(-fno-omit-frame-pointer, [optflags="${optflags+$optflags }-fno-omit-frame-pointer"])
869         RUBY_TRY_CFLAGS(-static-libgcc, [static_libgcc=yes], [static_libgcc=no])
870         AS_IF([test "$static_libgcc" = yes], [
871             RUBY_APPEND_OPTION(EXTLDFLAGS, -static-libgcc)
872         ])
873     ])
875     # disable fast-math
876     for oflag in -fno-fast-math; do
877         RUBY_TRY_CFLAGS($oflag, [RUBY_APPEND_OPTION(optflags, $oflag)])
878     done
879     for oflag in -fexcess-precision=standard -fp-model\ precise; do
880         RUBY_TRY_CFLAGS($oflag, [RUBY_APPEND_OPTION(XCFLAGS, $oflag)])
881     done
884 AS_CASE(["$target_cpu"], [[i[3-6]86*]], [
885     AC_CACHE_CHECK([for __sync_val_compare_and_swap], [rb_cv_gcc_compiler_cas], [
886         AC_LINK_IFELSE([AC_LANG_PROGRAM([[unsigned long atomic_var;]],
887             [[__sync_val_compare_and_swap(&atomic_var, 0, 1);]])],
888             [rb_cv_gcc_compiler_cas=yes],
889             [
890             save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -march=i486"
891             AC_LINK_IFELSE([AC_LANG_PROGRAM([[unsigned long atomic_var;]],
892                 [[__sync_val_compare_and_swap(&atomic_var, 0, 1);]])],
893                 [rb_cv_gcc_compiler_cas=i486],
894                 [rb_cv_gcc_compiler_cas=no])
895             CFLAGS="$save_CFLAGS"
896             ])
897     ])
898     AS_IF([test "$rb_cv_gcc_compiler_cas" = i486], [ARCH_FLAG="-march=i486"])
901 AC_ARG_WITH(opt-dir,
902         AS_HELP_STRING([--with-opt-dir=DIR-LIST],
903                        [add optional headers and libraries directories separated by $PATH_SEPARATOR]),
904         [
905                 val=`echo "$PATH_SEPARATOR$withval" | sed "s|$PATH_SEPARATOR\([[^$PATH_SEPARATOR]*]\)| -I\1/include|g;s/^ //"`
906                 CPPFLAGS="$CPPFLAGS $val"
907                 val=`echo "$PATH_SEPARATOR$withval" | sed "s|$PATH_SEPARATOR\([[^$PATH_SEPARATOR]*]\)| -L\1/lib${rpathflag:+ $rpathflag\\\\1/lib}|g;s/^ //"`
908                 LDFLAGS="$LDFLAGS $val"
909                 LDFLAGS_OPTDIR="$val"
910                 OPT_DIR="$withval"
911         ], [OPT_DIR=])
913 test -z "${ac_env_CFLAGS_set}" -a -n "${cflags+set}" && eval CFLAGS="\"$cflags $ARCH_FLAG\""
914 test -z "${ac_env_CXXFLAGS_set}" -a -n "${cxxflags+set}" && eval CXXFLAGS="\"$cxxflags $ARCH_FLAG\""
917 AC_CACHE_CHECK([whether compiler has statement and declarations in expressions],
918   rb_cv_have_stmt_and_decl_in_expr,
919   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],[[ __extension__ ({ int a = 0; a; }); ]])],
920   [rb_cv_have_stmt_and_decl_in_expr=yes],
921   [rb_cv_have_stmt_and_decl_in_expr=no])])
922 AS_IF([test "$rb_cv_have_stmt_and_decl_in_expr" = yes], [
923   AC_DEFINE(HAVE_STMT_AND_DECL_IN_EXPR)
926 : "header and library section" && {
927 AC_ARG_WITH(winnt-ver,
928   AS_HELP_STRING([--with-winnt-ver=0xXXXX], [target Windows NT version (default to 0x0600)]),
929   [with_winnt_ver="$withval"], [with_winnt_ver="0x0600"])
930 AS_CASE(["$target_os"],
931 [mingw*], [
932   RUBY_APPEND_OPTION(CPPFLAGS, -D_WIN32_WINNT=$with_winnt_ver)
933   RUBY_APPEND_OPTION(CPPFLAGS, -D__MINGW_USE_VC2005_COMPAT)
936 AS_CASE(["$target_os"],
937 [freebsd*], [
938   AC_CACHE_CHECK([whether pthread should be enabled by default],
939     rb_cv_enable_pthread_default,
940     [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
941 #include <osreldate.h>
942 #if __FreeBSD_version < 502102
943 #error pthread should be disabled on this platform
944 #endif
945       ]])],
946       rb_cv_enable_pthread_default=yes,
947       rb_cv_enable_pthread_default=no)])
948   enable_pthread=$rb_cv_enable_pthread_default
949   ],
950 [mingw*], [
951   enable_pthread=no
952   ],
954   enable_pthread=yes
955   ])
957 dnl Checks for libraries.
958 AS_CASE(["$target_os"],[*bsd*|dragonfly*],[],[ac_cv_func_daemon=no])
960 AS_CASE(["$target_os"], [*android*], [
961         AS_CASE(["$target_cpu"], [arm*], [
962                 ac_cv_func___builtin_setjmp=no
963         ])
966 AS_UNSET(ORIG_LIBS)
967 POSTLINK=:
968 AC_SUBST(POSTLINK)
969 cleanlibs=
970 AC_SUBST(cleanlibs)
971 AS_CASE(["$target_os"],
972 [nextstep*], [  ],
973 [openstep*], [  ],
974 [rhapsody*], [  ],
975 [darwin*], [
976                 ORIG_LIBS="$LIBS"
977                 RUBY_PREPEND_OPTION(LIBS, -lobjc)
978                 RUBY_APPEND_OPTIONS(CPPFLAGS, -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT)
979                 AC_CACHE_CHECK([whether syscall(2) is deprecated], rb_cv_syscall_deprecated,
980                     [RUBY_WERROR_FLAG([
981                         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <unistd.h>]],
982                                                            [[if (syscall(0)) return 1;]])],
983                             [rb_cv_syscall_deprecated=no],
984                             [rb_cv_syscall_deprecated=yes])])])
985                 AS_IF([test $rb_cv_syscall_deprecated = yes], [
986                     ac_cv_func___syscall=no
987                     ac_cv_func_syscall=no
988                     ac_cv_header_sys_syscall_h=no
989                     ac_cv_header_syscall_h=no
990                 ])
991                 ac_cv_func_getcontext=no
992                 ac_cv_func_setcontext=no
993                 incs=`$CC -v -E -xc - < /dev/null 2>&1 | sed ['1,/^@%:@include </d;s/^ *//;s|[^./][^/]*/\.\./||g;/\/include$/!d;s||/lib|;/\/usr\/lib/d']`
994                 for d in `$CC -print-search-dirs | sed -e '/^libraries: */!d;s///' | tr : '\012' | fgrep -v /../ | sed -n 's|^\(/.*/lib\)/$|\1|p'`; do
995                     incs=`echo "$incs" | fgrep -v "$d"`
996                 done
997                 for d in $incs; do
998                     test -d "$d" && RUBY_APPEND_OPTIONS(LDFLAGS, "-L$d")
999                 done
1000                 ac_cv_type_getgroups=gid_t # getgroups() on Rosetta fills garbage
1001                 ac_cv_lib_crypt_crypt=no
1002                 ac_cv_func_fdatasync=no # Mac OS X wrongly reports it has fdatasync()
1003                 ac_cv_func_vfork=no
1004                 AS_IF([test $gcc_major -lt 4 -o \( $gcc_major -eq 4 -a $gcc_minor -lt 3 \)], [
1005                     ac_cv_func___builtin_setjmp=no
1006                 ])
1007                 with_setjmp_type=sigsetjmp # to hijack SIGCHLD handler
1008                 AC_CACHE_CHECK(for broken crypt with 8bit chars, rb_cv_broken_crypt,
1009                     [AC_RUN_IFELSE([AC_LANG_SOURCE([[
1010 #include <stdio.h>
1011 #include <unistd.h>
1012 #include <string.h>
1014 void
1015 broken_crypt(const char *salt, const char *buf1, const char *buf2)
1017 #if 0
1018     printf("%.2x%.2x: %s -> %s\n", (unsigned char)salt[0], (unsigned char)salt[1],
1019            buf1+2, buf2+2);
1020 #endif
1024 main()
1026     int i;
1027     char salt[2], buf[256], *s;
1028     for (i = 0; i < 128*128; i++) {
1029         salt[0] = 0x80 | (i & 0x7f);
1030         salt[1] = 0x80 | (i >> 7);
1031         strcpy(buf, crypt("", salt));
1032         if (strcmp(buf, s = crypt("", salt))) {
1033             broken_crypt(salt, buf, s);
1034             return 1;
1035         }
1036     }
1037     salt[0] = salt[1] = ' ';
1038     strcpy(buf, crypt("", salt));
1039     salt[0] = salt[1] = 0x80 | ' ';
1040     if (strcmp(buf, s = crypt("", salt))) {
1041         broken_crypt(salt, buf, s);
1042         return 1;
1043     }
1044     return 0;
1046 ]])],
1047                     rb_cv_broken_crypt=no,
1048                     rb_cv_broken_crypt=yes,
1049                     rb_cv_broken_crypt=yes)])
1050                 AS_IF([test "$rb_cv_broken_crypt" = yes], [
1051                    AC_DEFINE(BROKEN_CRYPT, 1)
1052                 ])
1053                 POSTLINK=""
1054                 AC_CHECK_PROGS(codesign, codesign)
1055                 AC_CHECK_PROGS(dsymutil, dsymutil)
1056                 AS_IF([test -n "$codesign"], [
1057                     POSTLINK="{ test -z '\$(RUBY_CODESIGN)' || $codesign -s '\$(RUBY_CODESIGN)' -f \$@; }${POSTLINK:+; $POSTLINK}"
1058                 ])
1059                 AS_IF([test -n "$dsymutil"], [
1060                     POSTLINK="$dsymutil \$@${POSTLINK:+; $POSTLINK}"
1061                 ])
1062                 AS_IF([test -n "${POSTLINK}"], [
1063                     LINK_SO="$LINK_SO
1064 \$(POSTLINK)"
1065                 ])
1066                 AC_CHECK_HEADERS(crt_externs.h, [], [], [
1067                     #include <crt_externs.h>
1068                 ])
1069                 cleanlibs='$(TARGET_SO).dSYM'
1070                 ],
1071 [hpux*], [      LIBS="-lm $LIBS"
1072                 ac_cv_c_inline=no],
1073 [solaris*], [   LIBS="-lm $LIBS"
1074                 ac_cv_func_vfork=no
1075                 AC_MSG_CHECKING(whether _XOPEN_SOURCE is already given)
1076                 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>
1077                         #ifndef _XOPEN_SOURCE
1078                         #error _XOPEN_SOURCE is not defined
1079                         #endif
1080                         ]], [[]])],
1081                         [given_xopen_source=yes], [given_xopen_source=no])
1082                 AC_MSG_RESULT($given_xopen_source)
1083                 AS_IF([test $given_xopen_source = no], [
1084                   AC_MSG_CHECKING(appropriate _XOPEN_SOURCE value to define)
1085                   define_xopen_source=""
1086                   for tmp_xpg in 7 6 5; do
1087                     AS_IF([test x"$define_xopen_source" != x], [
1088                       break
1089                     ])
1090                     RUBY_WERROR_FLAG([AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1091                         #define _XOPEN_SOURCE ${tmp_xpg}00
1092                         #include <unistd.h>
1093                         #ifndef _XPG${tmp_xpg}
1094                         #error _XPG${tmp_xpg} should be defined by _XOPEN_SOURCE=${tmp_xpg}00
1095                         #endif
1096                         ]], [[]])],
1097                         [define_xopen_source=${tmp_xpg}00], [])
1098                         ])
1099                   done
1100                   AS_IF([test x"$define_xopen_source" = x], [
1101                     define_xopen_source=no
1102                   ])
1103                   AC_MSG_RESULT($define_xopen_source)
1104                   AS_IF([test x"$define_xopen_source" != xno], [
1105                     RUBY_APPEND_OPTIONS(CPPFLAGS, -D_XOPEN_SOURCE=$define_xopen_source)
1106                     # _XOPEN_SOURCE should not be defined for C++ on Solaris.
1107                     RUBY_APPEND_OPTIONS(CXXFLAGS, -U_XOPEN_SOURCE)
1108                   ])
1109                 ])
1110                 AC_CHECK_TYPES([caddr_t],[],[],[@%:@include <sys/types.h>])
1111                 AC_CACHE_CHECK([whether madvise declaration is needed], rb_cv_madvice_prototype_using_caddr_t,
1112                   [RUBY_WERROR_FLAG([AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1113                     @%:@include <sys/unistd.h>
1114                     @%:@include <sys/mman.h>
1115                     @%:@include <sys/types.h>
1116                     extern int madvise(caddr_t, size_t, int);
1117                     ]], [[]])],
1118                     [rb_cv_madvice_prototype_using_caddr_t=yes], [rb_cv_madvice_prototype_using_caddr_t=no])
1119                   ])
1120                 ])
1121                 AS_IF([test $rb_cv_madvice_prototype_using_caddr_t = yes], [AC_DEFINE(NEED_MADVICE_PROTOTYPE_USING_CADDR_T, 1)])
1122                 ],
1123 [haiku*], [
1124                 LIBS="$LIBS" # m lib is include in root
1125                 ],
1126 [cygwin*|msys*], [
1127                 ac_cv_header_langinfo_h=yes
1128                 RUBY_APPEND_OPTIONS(CPPFLAGS, -D_XOPEN_SOURCE -D_GNU_SOURCE)
1129                 AC_CHECK_FUNCS(cygwin_conv_path)
1130                 AC_LIBOBJ([langinfo])
1131                 ],
1132 [mingw*], [     LIBS="-lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi -lbcrypt $LIBS"
1133                 ac_cv_header_pwd_h=no
1134                 ac_cv_header_utime_h=no
1135                 ac_cv_header_sys_ioctl_h=no
1136                 ac_cv_header_sys_param_h=no
1137                 ac_cv_header_sys_resource_h=no
1138                 ac_cv_header_sys_select_h=no
1139                 ac_cv_header_sys_time_h=no
1140                 ac_cv_header_sys_times_h=no
1141                 ac_cv_header_sys_socket_h=no
1142                 ac_cv_func_lstat=yes
1143                 ac_cv_func_times=yes
1144                 ac_cv_func_waitpid=yes
1145                 ac_cv_func_fsync=yes
1146                 ac_cv_func_seekdir=yes
1147                 ac_cv_func_telldir=yes
1148                 ac_cv_func_lchown=yes
1149                 ac_cv_func_link=yes
1150                 ac_cv_func_readlink=yes
1151                 ac_cv_func_symlink=yes
1152                 ac_cv_lib_crypt_crypt=no
1153                 ac_cv_func_getpgrp_void=no
1154                 ac_cv_func_memcmp_working=yes
1155                 ac_cv_lib_dl_dlopen=no
1156                 rb_cv_binary_elf=no
1157                 rb_cv_negative_time_t=yes
1158                 ac_cv_func_fcntl=yes
1159                 ac_cv_func_flock=yes
1160                 ac_cv_func_gmtime_r=yes
1161                 rb_cv_large_fd_select=yes
1162                 ac_cv_type_struct_timeval=yes
1163                 ac_cv_func_clock_gettime=yes
1164                 ac_cv_func_clock_getres=yes
1165                 ac_cv_func_malloc_usable_size=no
1166                 ac_cv_type_off_t=yes
1167                 ac_cv_sizeof_off_t=8
1168                 AS_IF([test "$target_cpu" = x64], [
1169                     ac_cv_func___builtin_setjmp=yes
1170                     ac_cv_func_round=no
1171                     coroutine_type=yes
1172                 ])
1173                 ac_cv_func_tgamma=no
1174                 AC_CHECK_TYPE([NET_LUID], [], [],
1175                               [@%:@include <winsock2.h>
1176                               @%:@include <iphlpapi.h>])
1177                 AS_IF([test x"$ac_cv_type_NET_LUID" = xyes], [
1178                     AC_DEFINE(HAVE_TYPE_NET_LUID, 1)
1179                 ])
1180                 AC_CHECK_FUNCS(_gmtime64_s)
1181                 AC_CHECK_FUNCS(_wfreopen_s)
1182                 AC_LIBOBJ([langinfo])
1183                 ],
1184 [bsdi*], [      LIBS="-lm $LIBS"
1185                 AC_DEFINE(BROKEN_SETREUID, 1)
1186                 AC_DEFINE(BROKEN_SETREGID, 1)
1187                 ac_cv_sizeof_rlim_t=8],
1188 [freebsd*], [   LIBS="-lm $LIBS"
1189                 ac_cv_func_getpeername=no
1190                 ac_cv_func_getsockname=no
1191                 ac_cv_func_shutdown=no
1192                 ac_cv_func_close=no
1193                 ],
1194 [netbsd*], [    LIBS="-lm $LIBS"
1195                 ],
1196 [dragonfly*], [ LIBS="-lm $LIBS"
1197                 ],
1198 [aix*],[        LIBS="-lm $LIBS"
1199                 ac_cv_func_round=no
1200                 ac_cv_func___builtin_setjmp=no
1201                 ],
1202 [linux*],[      LIBS="-lm $LIBS"
1203                 # __builtin_longjmp in ppc64* Linux does not restore
1204                 # the TOC register (r2), which is problematic
1205                 # when a global exit happens from JITted .so code.
1206                 AS_CASE(["$target_cpu"], [powerpc64*], [
1207                         ac_cv_func___builtin_setjmp=no
1208                 ])
1209                 # With gcc-8's -fcf-protection, MJIT's __builtin_longjmp fails.
1210                 AS_CASE(["$CC $CFLAGS "], [*" -fcf-protection "*], [cf_protection=yes], [cf_protection=no])
1211                 AS_IF([test "$cf_protection" = yes], [
1212                         ac_cv_func___builtin_setjmp=no
1213                 ])
1214                 ],
1215 [emscripten*], [LIBS="-lm -lc $LIBS"
1216                 RUBY_APPEND_OPTIONS(LDFLAGS, "-sALLOW_MEMORY_GROWTH=1")
1217                 RUBY_APPEND_OPTIONS(LDFLAGS, "-sASYNCIFY")
1218                 RUBY_APPEND_OPTIONS(LDFLAGS, "-sFORCE_FILESYSTEM=1")
1219                 ac_cv_func_shutdown=no
1220                 ],
1221 [       LIBS="-lm $LIBS"])
1222 : ${ORIG_LIBS=$LIBS}
1224 AS_IF([test -n "${rb_there_is_in_fact_no_gplusplus_but_autoconf_is_cheating_us}"], [
1225     AC_MSG_NOTICE([Test skipped due to lack of a C++ compiler.])
1227 [test -n "${CXX}"], [
1228     RUBY_WERROR_FLAG([
1229         AC_MSG_CHECKING([whether CXXFLAGS is valid])
1230         AC_LANG_PUSH(C++)
1231         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <cstdio>]], [[]])],
1232             [AC_MSG_RESULT(yes)],[
1233             AC_MSG_RESULT(no)
1234             # The message mentions CXXFLAGS, but CPPFLAGS might also affects.
1235             AC_MSG_WARN([something wrong with CXXFLAGS="$CXXFLAGS"])
1236             CXX=false
1237         ])
1238         AC_LANG_POP(C++)
1239     ])
1242 AC_CHECK_LIB(crypt, crypt)      # glibc (GNU/Linux, GNU/Hurd, GNU/kFreeBSD)
1243 AC_CHECK_LIB(dl, dlopen)        # Dynamic linking for SunOS/Solaris and SYSV
1244 AC_CHECK_LIB(dld, shl_load)     # Dynamic linking for HP-UX
1245 AC_CHECK_LIB(socket, shutdown)  # SunOS/Solaris
1247 if pkg-config --exists capstone; then
1248    CAPSTONE_CFLAGS=`pkg-config --cflags capstone`
1249    CAPSTONE_LIB_L=`pkg-config --libs-only-L capstone`
1250    LDFLAGS="$LDFLAGS $CAPSTONE_LIB_L"
1251    CFLAGS="$CFLAGS $CAPSTONE_CFLAGS"
1254 AC_CHECK_LIB(capstone, cs_open) # Capstone disassembler for debugging YJIT
1256 dnl Checks for header files.
1257 AC_HEADER_DIRENT
1258 dnl AC_HEADER_STDC has been checked in AC_USE_SYSTEM_EXTENSIONS
1259 AC_HEADER_STDBOOL
1260 AC_HEADER_SYS_WAIT
1262 AC_CHECK_HEADERS(atomic.h)
1263 AC_CHECK_HEADERS(copyfile.h)
1264 AC_CHECK_HEADERS(direct.h)
1265 AC_CHECK_HEADERS(grp.h)
1266 AC_CHECK_HEADERS(fcntl.h)
1267 AC_CHECK_HEADERS(float.h)
1268 AC_CHECK_HEADERS(ieeefp.h)
1269 AC_CHECK_HEADERS(intrinsics.h)
1270 AC_CHECK_HEADERS(langinfo.h)
1271 AC_CHECK_HEADERS(limits.h)
1272 AC_CHECK_HEADERS(locale.h)
1273 AC_CHECK_HEADERS(malloc.h)
1274 AC_CHECK_HEADERS(malloc/malloc.h)
1275 AC_CHECK_HEADERS(malloc_np.h)
1276 AC_CHECK_HEADERS(net/socket.h)
1277 AC_CHECK_HEADERS(process.h)
1278 AC_CHECK_HEADERS(pwd.h)
1279 AC_CHECK_HEADERS(sanitizer/asan_interface.h)
1280 AC_CHECK_HEADERS(sanitizer/msan_interface.h)
1281 AC_CHECK_HEADERS(setjmpex.h)
1282 AC_CHECK_HEADERS(stdalign.h)
1283 AC_CHECK_HEADERS(sys/attr.h)
1284 AC_CHECK_HEADERS(sys/eventfd.h)
1285 AC_CHECK_HEADERS(sys/fcntl.h)
1286 AC_CHECK_HEADERS(sys/file.h)
1287 AC_CHECK_HEADERS(sys/id.h)
1288 AC_CHECK_HEADERS(sys/ioctl.h)
1289 AC_CHECK_HEADERS(sys/mkdev.h)
1290 AC_CHECK_HEADERS(sys/param.h)
1291 AC_CHECK_HEADERS(sys/prctl.h)
1292 AC_CHECK_HEADERS(sys/random.h)
1293 AC_CHECK_HEADERS(sys/resource.h)
1294 AC_CHECK_HEADERS(sys/select.h)
1295 AC_CHECK_HEADERS(sys/sendfile.h)
1296 AC_CHECK_HEADERS(sys/socket.h)
1297 AC_CHECK_HEADERS(sys/syscall.h)
1298 AC_CHECK_HEADERS(sys/sysmacros.h)
1299 AC_CHECK_HEADERS(sys/time.h)
1300 AC_CHECK_HEADERS(sys/times.h)
1301 AC_CHECK_HEADERS(sys/uio.h)
1302 AC_CHECK_HEADERS(sys/utime.h)
1303 AC_CHECK_HEADERS(syscall.h)
1304 AC_CHECK_HEADERS(time.h)
1305 AC_CHECK_HEADERS(ucontext.h)
1306 AC_CHECK_HEADERS(utime.h)
1307 AS_CASE("$target_cpu", [x64|x86_64|i[3-6]86*], [
1308   AC_CHECK_HEADERS(x86intrin.h)
1310 RUBY_UNIVERSAL_CHECK_HEADER([x86_64, i386], x86intrin.h)
1312 AC_ARG_WITH([gmp],
1313   [AS_HELP_STRING([--without-gmp],
1314     [disable GNU GMP to accelerate Bignum operations])],
1315   [],
1316   [with_gmp=yes])
1317 AS_IF([test "x$with_gmp" != xno],
1318   [AC_CHECK_HEADERS(gmp.h)
1319    AS_IF([test "x$ac_cv_header_gmp_h" != xno],
1320      AC_SEARCH_LIBS([__gmpz_init], [gmp],
1321        [AC_DEFINE(HAVE_LIBGMP, 1)]))])
1323 AC_ARG_WITH([jemalloc],
1324   [AS_HELP_STRING([--with-jemalloc],[use jemalloc allocator])],
1325   [with_jemalloc=$withval], [with_jemalloc=no])
1326 AS_IF([test "x$with_jemalloc" != xno],[
1327   # find jemalloc header first
1328   malloc_header=
1329   AC_CHECK_HEADER(jemalloc/jemalloc.h, [malloc_header=jemalloc/jemalloc.h], [
1330     AC_CHECK_HEADER(jemalloc.h, [malloc_header=jemalloc.h])
1331   ])
1332   AS_IF([test "$malloc_header" != ""], [
1333     AC_DEFINE_UNQUOTED(RUBY_ALTERNATIVE_MALLOC_HEADER, [<$malloc_header>])
1334   ])
1335   save_LIBS="$LIBS"
1336   AC_CACHE_CHECK([for jemalloc library], rb_cv_jemalloc_library, [
1337     rb_cv_jemalloc_library=no
1338     # try [with mangle, without mangle] x [no more additional
1339     # libraries, adding jemalloc] combination, using the jemalloc
1340     # header found above.
1341     for mangle in '' mangle; do
1342       for lib in '' -ljemalloc; do
1343         LIBS="${lib:+$lib }$LIBS"
1344         AC_LINK_IFELSE([AC_LANG_PROGRAM([${mangle:+@%:@define JEMALLOC_MANGLE 1}
1345           @%:@include <stdio.h>
1346           @%:@ifdef RUBY_ALTERNATIVE_MALLOC_HEADER
1347           @%:@include RUBY_ALTERNATIVE_MALLOC_HEADER
1348           @%:@else
1349           extern const char *malloc_conf;
1350           @%:@endif],
1351           [/* access at runtime not to be optimized away */
1352           if (malloc_conf) printf("malloc_conf=%s\n", malloc_conf);])],
1353           [rb_cv_jemalloc_library="${lib:-none required}${mangle:+ with mangle}"])
1354         LIBS="$save_LIBS"
1355         test "${rb_cv_jemalloc_library}" = no || break 2
1356       done
1357     done
1358   ])
1359   with_jemalloc=${rb_cv_jemalloc_library}
1360   AS_CASE(["$with_jemalloc"],
1361   [no],
1362     [AC_MSG_ERROR([jemalloc requested but not found])],
1363   [-l*], [
1364     set dummy $with_jemalloc
1365     LIBS="$2 $LIBS"
1366     DLDLIBS="$2${DLDLIBS:+ $DLDLIBS}" # probably needed also in extension libraries
1367   ])
1368   AS_CASE(["$with_jemalloc"],
1369   [*" with mangle"], [
1370     AC_DEFINE(JEMALLOC_MANGLE)
1371   ])
1372   AC_DEFINE(HAVE_MALLOC_CONF)
1373   ac_cv_func_malloc_usable_size=yes
1374 ]) # with_jemalloc
1376 dnl check for large file stuff
1377 mv confdefs.h confdefs1.h
1378 : > confdefs.h
1379 AC_SYS_LARGEFILE
1380 # On 32-bit Solaris, it is safe to define _LARGEFILE_SOURCE
1381 # which is not added by AC_SYS_LARGEFILE.
1382 AS_IF([test x"$enable_largefile" != xno], [
1383   AS_CASE(["$target_os"], [solaris*], [
1384     AC_MSG_CHECKING([wheather _LARGEFILE_SOURCE should be defined])
1385     AS_CASE(["${ac_cv_sys_file_offset_bits}:${ac_cv_sys_large_files}"],
1386       ["64:"|"64:no"|"64:unknown"], [
1387         # insert _LARGEFILE_SOURCE before _FILE_OFFSET_BITS line
1388         # that is the same order as "getconf LFS_CFLAGS" output
1389         mv confdefs.h largefile0.h
1390         : > confdefs.h
1391         AC_DEFINE(_LARGEFILE_SOURCE)
1392         cat largefile0.h >> confdefs.h
1393         rm largefile0.h
1394         AC_MSG_RESULT([yes])
1395       ], [AC_MSG_RESULT([no])])
1396   ])
1398 mv confdefs.h largefile.h
1399 mv confdefs1.h confdefs.h
1400 cat largefile.h >> confdefs.h
1402 AS_CASE(["$target_os"],
1403     [aix*], [
1404     AS_CASE(["$target_cpu:$ac_cv_sys_large_files"],
1405         [ppc64:*|powerpc64:*], [],
1406         [*:no|*:unknown], [],
1407         [
1408             # AIX currently does not support a 32-bit call to posix_fadvise()
1409             # if _LARGE_FILES is defined.
1410             ac_cv_func_posix_fadvise=no
1411         ])
1412     ])
1414 AC_C_BIGENDIAN([], [], [], [AC_DEFINE(AC_APPLE_UNIVERSAL_BUILD, 1)])
1415 AC_C_CONST
1416 AC_C_CHAR_UNSIGNED
1417 AC_C_INLINE
1418 AC_C_VOLATILE
1419 AC_C_TYPEOF
1420 AC_C_RESTRICT
1422 AS_CASE(":$ac_cv_c_const:$ac_cv_c_volatile:",
1423     [*:no:*], [AC_MSG_ERROR(ANSI C-conforming const and volatile are mandatory)])
1425 AC_CHECK_TYPES([long long, off_t])
1427 AC_CACHE_CHECK([char bit], [rb_cv_char_bit],
1428     [test "$universal_binary" = yes && cross_compiling=yes
1429     AC_COMPUTE_INT([rb_cv_char_bit], [CHAR_BIT],
1430         [AC_INCLUDES_DEFAULT([@%:@include <limits.h>])], [rb_cv_char_bit=8])
1431     test "$universal_binary" = yes && cross_compiling=$real_cross_compiling])
1433 RUBY_CHECK_SIZEOF(int, [], [ILP])
1434 RUBY_CHECK_SIZEOF(short)
1435 RUBY_CHECK_SIZEOF(long, [int], [ILP LP])
1436 RUBY_CHECK_SIZEOF(long long)
1437 RUBY_CHECK_SIZEOF(__int64, [8], [ILP LP])
1438 RUBY_CHECK_SIZEOF(__int128, [16], [ILP LP])
1439 RUBY_CHECK_SIZEOF(off_t)
1440 RUBY_CHECK_SIZEOF(void*, [int long "long long"], [ILP LP LLP])
1441 RUBY_CHECK_SIZEOF(float)
1442 RUBY_CHECK_SIZEOF(double)
1443 RUBY_CHECK_SIZEOF(time_t, [long "long long"], [], [@%:@include <time.h>])
1444 RUBY_CHECK_SIZEOF(clock_t, [], [], [@%:@include <time.h>])
1446 AC_CACHE_CHECK(packed struct attribute, rb_cv_packed_struct,
1447     [rb_cv_packed_struct=no
1448     for mac in \
1449         "__pragma(pack(push, 1)) x __pragma(pack(pop))" \
1450         "x __attribute__((packed))" \
1451         ; do
1452         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@define PACKED_STRUCT(x) $mac
1453                         PACKED_STRUCT(struct { int a; });]], [[]])],
1454                 [rb_cv_packed_struct=$mac; break])
1455     done])
1456 AS_IF([test "$rb_cv_packed_struct" != no], [
1457     AC_DEFINE_UNQUOTED([PACKED_STRUCT(x)], [$rb_cv_packed_struct])
1458     RUBY_TRY_CFLAGS(-Wno-address-of-packed-member, [AC_DEFINE(USE_UNALIGNED_MEMBER_ACCESS)])
1459 ], [
1460     AC_DEFINE_UNQUOTED([PACKED_STRUCT(x)], x)
1463 AS_IF([test "x$ac_cv_type_long_long" = xyes], [
1464     RUBY_CHECK_PRINTF_PREFIX(long long, ll I64, LL)
1465 ], [test "x$ac_cv_type___int64" = xyes], [
1466     RUBY_CHECK_PRINTF_PREFIX(__int64, ll I64, LL)
1469 RUBY_REPLACE_TYPE(pid_t, int, PIDT)
1470 RUBY_REPLACE_TYPE(uid_t, int, UIDT)
1471 RUBY_REPLACE_TYPE(gid_t, int, GIDT)
1472 RUBY_REPLACE_TYPE(time_t, [], TIMET, [@%:@include <time.h>])
1473 RUBY_REPLACE_TYPE(dev_t, [int long "long long"], DEVT)
1474 RUBY_REPLACE_TYPE(mode_t, ["unsigned short" "unsigned int" long], MODET, [@%:@include <sys/stat.h>])
1475 RUBY_REPLACE_TYPE(rlim_t, [int long "long long"], RLIM, [
1476 @%:@ifdef HAVE_SYS_TYPES_H
1477 @%:@include <sys/types.h>
1478 @%:@endif
1479 @%:@ifdef HAVE_SYS_TYPES_H
1480 @%:@include <sys/time.h>
1481 @%:@endif
1482 @%:@include <sys/resource.h>
1484 RUBY_REPLACE_TYPE(off_t, [], OFFT)
1485 RUBY_REPLACE_TYPE(clockid_t, [], CLOCKID, [@%:@ifdef HAVE_TIME_H
1486 @%:@ include <time.h>
1487 @%:@endif
1488 @%:@ifdef HAVE_SYS_TIME_H
1489 @%:@ include <sys/time.h>
1490 @%:@endif])
1492 # __VA_ARGS__ is also tested in AC_PROG_CC_C99 since autoconf 2.60a (around
1493 # 2006). The check below is redundant and should always success.  Remain not
1494 # deleted for backward compat.
1495 AC_CACHE_CHECK(for variable length macro, rb_cv_va_args_macro,
1496   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1497 int foo(const char*);
1498 @%:@define FOO(...) foo(@%:@__VA_ARGS__)
1499 ]], [[FOO(1);FOO(1,2);FOO(1,2,3);]])],
1500   rb_cv_va_args_macro=yes,
1501   rb_cv_va_args_macro=no)])
1502 AS_IF([test "$rb_cv_va_args_macro" = yes], [
1503   AC_DEFINE(HAVE_VA_ARGS_MACRO)
1506 # We want C11's  `_Alignof`.  GCC (and alike) have  `__alignof__`, which behave
1507 # slightly differently  than the  C11's.  We cannot  use `__alignof__`  for our
1508 # purpose.   The problem  is, however,  that  old gcc  and old  clang had  both
1509 # implemented `_Alignof` as  a synonym of `__alignof__`.  They are  not what we
1510 # want.  We have to check sanity.
1512 # See also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023
1513 # See also: https://bugs.llvm.org/show_bug.cgi?id=26547
1514 AC_CACHE_CHECK([if _Alignof() works], rb_cv_have__alignof,[
1515     rb_cv_have__alignof=no
1516     RUBY_WERROR_FLAG([
1517         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1518             @%:@ifdef HAVE_STDALIGN_H
1519             @%:@include <stdalign.h>
1520             @%:@endif
1521             @%:@ifdef STDC_HEADERS
1522             @%:@include <stddef.h>
1523             @%:@endif
1524             @%:@ifndef __GNUC__
1525             @%:@define __extension__
1526             @%:@endif
1527         ]], [[
1528             typedef struct conftest_tag {
1529                 char _;
1530                 double d;
1531             } T;
1532             static int conftest_ary@<:@
1533                 offsetof(T, d) == __extension__ _Alignof(double)
1534                 ? 1 : -1
1535             @:>@;
1536             return conftest_ary@<:@0@:>@;
1537         ]])],[
1538             rb_cv_have__alignof=yes
1539         ],[])
1540     ])
1542 AS_IF([test "$rb_cv_have__alignof" != no], [
1543     AC_DEFINE(HAVE__ALIGNOF)
1546 RUBY_FUNC_ATTRIBUTE(__const__, CONSTFUNC)
1547 RUBY_FUNC_ATTRIBUTE(__pure__, PUREFUNC)
1548 RUBY_FUNC_ATTRIBUTE(__noreturn__, NORETURN)
1549 RUBY_FUNC_ATTRIBUTE(__deprecated__, DEPRECATED)
1550 RUBY_FUNC_ATTRIBUTE(__deprecated__("by "@%:@n), DEPRECATED_BY(n,x), rb_cv_func_deprecated_by)
1551 RUBY_FUNC_ATTRIBUTE(__noinline__, NOINLINE)
1552 RUBY_FUNC_ATTRIBUTE(__always_inline__, ALWAYS_INLINE)
1553 RUBY_FUNC_ATTRIBUTE(__no_sanitize__(san), NO_SANITIZE(san, x), rb_cv_func_no_sanitize)
1554 RUBY_FUNC_ATTRIBUTE(__no_sanitize_address__, NO_SANITIZE_ADDRESS)
1555 RUBY_FUNC_ATTRIBUTE(__no_address_safety_analysis__, NO_ADDRESS_SAFETY_ANALYSIS)
1556 RUBY_FUNC_ATTRIBUTE(__warn_unused_result__, WARN_UNUSED_RESULT)
1557 RUBY_FUNC_ATTRIBUTE(__unused__, MAYBE_UNUSED)
1558 RUBY_FUNC_ATTRIBUTE(__error__ mesg, ERRORFUNC(mesg,x), rb_cv_func___error__)
1559 RUBY_FUNC_ATTRIBUTE(__warning__ mesg, WARNINGFUNC(mesg,x), rb_cv_func___warning__)
1560 RUBY_FUNC_ATTRIBUTE(__weak__, WEAK, rb_cv_func_weak)
1561 AS_IF([test "$rb_cv_func_weak" != x], [
1562    AC_DEFINE(HAVE_FUNC_WEAK)
1565 AC_CACHE_CHECK([for __attribute__((__depreacted__(msg))) in C++],
1566   rb_cv_CentOS6_CXX_workaround,
1567   RUBY_WERROR_FLAG([
1568     AC_LANG_PUSH([C++])
1569     AC_COMPILE_IFELSE(
1570       [AC_LANG_PROGRAM(
1571         [],
1572         [__attribute__((__deprecated__("message"))) int conftest(...);])],
1573       [rb_cv_CentOS6_CXX_workaround=yes],
1574       [rb_cv_CentOS6_CXX_workaround=no])
1575     AC_LANG_POP()]))
1576 AS_IF([test "$rb_cv_CentOS6_CXX_workaround" != no],[
1577   AC_DEFINE([RUBY_CXX_DEPRECATED(msg)],
1578     [__attribute__((__deprecated__(msg)))])])
1580 AC_CACHE_CHECK([for std::nullptr_t], rb_cv_CXX_nullptr, [
1581   AC_LANG_PUSH([C++])
1582   AC_COMPILE_IFELSE(
1583     [AC_LANG_PROGRAM(
1584       [@%:@include <cstddef>],
1585       [static std::nullptr_t const *const conftest = nullptr;])],
1586     [rb_cv_CXX_nullptr=yes],
1587     [rb_cv_CXX_nullptr=no])
1588   AC_LANG_POP()])
1589 AS_IF([test "$rb_cv_CXX_nullptr" != no],[AC_DEFINE(HAVE_NULLPTR)])
1591 if_i386=${universal_binary+[defined __i386__]}
1592 RUBY_FUNC_ATTRIBUTE(__stdcall__,  FUNC_STDCALL,  rb_cv_func_stdcall,  ${if_i386})
1593 RUBY_FUNC_ATTRIBUTE(__cdecl__,    FUNC_CDECL,    rb_cv_func_cdecl,    ${if_i386})
1594 RUBY_FUNC_ATTRIBUTE(__fastcall__, FUNC_FASTCALL, rb_cv_func_fastcall, ${if_i386})
1595 RUBY_FUNC_ATTRIBUTE(__optimize__("O0"), FUNC_UNOPTIMIZED, rb_cv_func_unoptimized)
1596 RUBY_FUNC_ATTRIBUTE(__optimize__("-Os","-fomit-frame-pointer"), FUNC_MINIMIZED, rb_cv_func_minimized)
1598 AS_IF([test "$GCC" = yes], [
1599     AC_CACHE_CHECK([for function alias], [rb_cv_gcc_function_alias],
1600         [rb_cv_gcc_function_alias=no
1601         for a in alias weak,alias; do
1602             AC_LINK_IFELSE([AC_LANG_PROGRAM([[void foo(void) {}
1603                 void bar(void) __attribute__(($a("foo")));]], [[bar()]])],
1604                 [rb_cv_gcc_function_alias=$a; break])
1605         done])
1606     AS_IF([test "$rb_cv_gcc_function_alias" != no], [
1607         AC_DEFINE(HAVE_ATTRIBUTE_FUNCTION_ALIAS)
1608         AC_DEFINE_UNQUOTED([RUBY_ALIAS_FUNCTION_TYPE(type, prot, name, args)],
1609                            [type prot __attribute__(($rb_cv_gcc_function_alias(@%:@name)));])
1610         AC_DEFINE_UNQUOTED([RUBY_ALIAS_FUNCTION_VOID(prot, name, args)],
1611                            [RUBY_ALIAS_FUNCTION_TYPE(void, prot, name, args)])
1612     ])
1616     AC_CACHE_CHECK([for __atomic builtins], [rb_cv_gcc_atomic_builtins], [
1617         AC_LINK_IFELSE([AC_LANG_PROGRAM([[unsigned int atomic_var;]],
1618                     [[
1619                         __atomic_exchange_n(&atomic_var, 0, __ATOMIC_SEQ_CST);
1620                         __atomic_exchange_n(&atomic_var, 1, __ATOMIC_SEQ_CST);
1621                         __atomic_fetch_add(&atomic_var, 1, __ATOMIC_SEQ_CST);
1622                         __atomic_fetch_sub(&atomic_var, 1, __ATOMIC_SEQ_CST);
1623                         __atomic_or_fetch(&atomic_var, 1, __ATOMIC_SEQ_CST);
1624                     ]])],
1625                     [rb_cv_gcc_atomic_builtins=yes],
1626                     [rb_cv_gcc_atomic_builtins=no])])
1627     AS_IF([test "$rb_cv_gcc_atomic_builtins" = yes], [
1628         AC_DEFINE(HAVE_GCC_ATOMIC_BUILTINS)
1629     ])
1631     AC_CACHE_CHECK([for __sync builtins], [rb_cv_gcc_sync_builtins], [
1632         AC_LINK_IFELSE([AC_LANG_PROGRAM([[unsigned int atomic_var;]],
1633                     [[
1634                         __sync_lock_test_and_set(&atomic_var, 0);
1635                         __sync_lock_test_and_set(&atomic_var, 1);
1636                         __sync_fetch_and_add(&atomic_var, 1);
1637                         __sync_fetch_and_sub(&atomic_var, 1);
1638                         __sync_or_and_fetch(&atomic_var, 1);
1639                         __sync_val_compare_and_swap(&atomic_var, 0, 1);
1640                     ]])],
1641                     [rb_cv_gcc_sync_builtins=yes],
1642                     [rb_cv_gcc_sync_builtins=no])])
1643     AS_IF([test "$rb_cv_gcc_sync_builtins" = yes], [
1644         AC_DEFINE(HAVE_GCC_SYNC_BUILTINS)
1645     ])
1647     AC_CACHE_CHECK(for __builtin_unreachable, rb_cv_func___builtin_unreachable,
1648     [RUBY_WERROR_FLAG(
1649     [AC_LINK_IFELSE([AC_LANG_PROGRAM([[volatile int zero;]],
1650         [[if (zero) __builtin_unreachable();]])],
1651         [rb_cv_func___builtin_unreachable=yes],
1652         [rb_cv_func___builtin_unreachable=no])
1653     ])
1654     ])
1655     AS_IF([test "$rb_cv_func___builtin_unreachable" = yes], [
1656         AC_DEFINE_UNQUOTED(UNREACHABLE, [__builtin_unreachable()])
1657     ])
1660 AC_CACHE_CHECK(for exported function attribute, rb_cv_func_exported, [
1661 rb_cv_func_exported=no
1662 RUBY_WERROR_FLAG([
1663 for mac in '__attribute__ ((__visibility__("default")))' '__declspec(dllexport)'; do
1664   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@define RUBY_FUNC_EXPORTED $mac extern
1665     RUBY_FUNC_EXPORTED void conftest_attribute_check(void);]], [[]])],
1666     [rb_cv_func_exported="$mac"; break])
1667 done
1668 ])])
1669 AS_IF([test "$rb_cv_func_exported" != no], [
1670     AC_DEFINE_UNQUOTED(RUBY_FUNC_EXPORTED, [$rb_cv_func_exported extern])
1672 RUBY_DECL_ATTRIBUTE([__nonnull__(n)], [RUBY_FUNC_NONNULL(n,x)], [rb_cv_func_nonnull],
1673                     [], [function], [
1674 @%:@define x int conftest_attribute_check(void *p)
1675 @%:@define n 1
1678 RUBY_APPEND_OPTION(XCFLAGS, -DRUBY_EXPORT)
1680 AC_ARG_ENABLE(mathn,
1681     AS_HELP_STRING([--enable-mathn], [enable canonicalization for mathn]),
1682     [AC_MSG_ERROR([mathn support has been dropped])])
1684 AC_CACHE_CHECK(for function name string predefined identifier,
1685     rb_cv_function_name_string,
1686     [AS_CASE(["$target_os"],[openbsd*],[
1687       rb_cv_function_name_string=__func__
1688      ],[
1689      rb_cv_function_name_string=no
1690       RUBY_WERROR_FLAG([
1691         for func in __func__ __FUNCTION__; do
1692             AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <stdio.h>]],
1693                                             [[puts($func);]])],
1694             [rb_cv_function_name_string=$func
1695             break])
1696         done
1697       ])])]
1699 AS_IF([test "$rb_cv_function_name_string" != no], [
1700     AC_DEFINE_UNQUOTED(RUBY_FUNCTION_NAME_STRING, [$rb_cv_function_name_string])
1703 AC_CACHE_CHECK(if enum over int is allowed, rb_cv_enum_over_int, [
1704     rb_cv_enum_over_int=no
1705     AS_IF([test "x$ac_cv_type_long_long" = xyes], [
1706         type="unsigned long long" max="ULLONG_MAX"
1707     ], [
1708         type="unsigned long" max="ULONG_MAX"
1709     ])
1710     RUBY_WERROR_FLAG([
1711         AC_COMPILE_IFELSE([
1712             AC_LANG_BOOL_COMPILE_TRY([
1713                     @%:@include <limits.h>
1714                     enum {conftest_max = $max};
1715                 ], [
1716                     (conftest_max == $max) &&
1717                     (sizeof(conftest_max) == sizeof($type))
1718                 ]
1719             )],
1720             [rb_cv_enum_over_int=yes],
1721             [rb_cv_enum_over_int=no]
1722         )
1723     ])
1725 AS_IF([test $rb_cv_enum_over_int = yes], [
1726     AC_DEFINE(ENUM_OVER_INT, 1)
1729 dnl Check whether we need to define sys_nerr locally
1730 AC_CHECK_DECLS([sys_nerr], [], [], [$ac_includes_default
1731 @%:@include <errno.h>])
1733 AC_CHECK_DECLS([getenv])
1735 AS_CASE(["$target_cpu"],
1736 [alpha*|sh4|sh4el|sh4eb], [AS_CASE(["$target_os"::"$GCC"],
1737                 [*::yes],  # gcc
1738                         [CFLAGS="-mieee $CFLAGS"],
1739                 [osf*],    # ccc
1740                         [CFLAGS="-ieee $CFLAGS"],
1741                 )],
1742 [sparc*], [AC_LIBOBJ([sparc])])
1744 ac_cv_header_net_socket_h=${ac_cv_header_net_socket_h=no}
1745 AS_IF([test "$ac_cv_header_net_socket_h" = yes], [
1746     ac_cv_header_sys_socket_h=${ac_cv_header_sys_socket_h=no}
1747 ], [
1748     ac_cv_header_sys_socket_h=${ac_cv_header_sys_socket_h=yes}
1752 AC_TYPE_SIZE_T
1753 RUBY_CHECK_SIGNEDNESS(size_t, [AC_MSG_ERROR(size_t is signed)], [],
1754                       [@%:@include <sys/types.h>])
1755 RUBY_CHECK_SIZEOF(size_t, [int long void*], [], [@%:@include <sys/types.h>])
1756 RUBY_CHECK_SIZEOF(ptrdiff_t, size_t, [], [@%:@include <stddef.h>])
1757 RUBY_CHECK_SIZEOF(dev_t)
1758 RUBY_CHECK_PRINTF_PREFIX(size_t, z)
1759 RUBY_CHECK_PRINTF_PREFIX(ptrdiff_t, t)
1760 AC_CHECK_MEMBERS([struct stat.st_blksize])
1761 AC_CHECK_MEMBERS([struct stat.st_blocks])
1762 AC_CHECK_MEMBERS([struct stat.st_rdev])
1763 RUBY_CHECK_SIZEOF([struct stat.st_size], [off_t int long "long long"], [], [@%:@include <sys/stat.h>])
1764 AS_IF([test "$ac_cv_member_struct_stat_st_blocks" = yes], [
1765     RUBY_CHECK_SIZEOF([struct stat.st_blocks], [off_t int long "long long"], [], [@%:@include <sys/stat.h>])
1767 RUBY_CHECK_SIZEOF([struct stat.st_ino], [long "long long"], [], [@%:@include <sys/stat.h>])
1768 RUBY_CHECK_SIZEOF([struct stat.st_dev], [dev_t int long "long long"], [], [@%:@include <sys/stat.h>])
1769 AS_IF([test "$ac_cv_member_struct_stat_st_rdev" = yes], [
1770     RUBY_CHECK_SIZEOF([struct stat.st_rdev], [dev_t int long "long long"], [], [@%:@include <sys/stat.h>])
1772 AC_CHECK_MEMBERS([struct stat.st_atim])
1773 AC_CHECK_MEMBERS([struct stat.st_atimespec])
1774 AC_CHECK_MEMBERS([struct stat.st_atimensec])
1775 AC_CHECK_MEMBERS([struct stat.st_mtim])
1776 AC_CHECK_MEMBERS([struct stat.st_mtimespec])
1777 AC_CHECK_MEMBERS([struct stat.st_mtimensec])
1778 AC_CHECK_MEMBERS([struct stat.st_ctim])
1779 AC_CHECK_MEMBERS([struct stat.st_ctimespec])
1780 AC_CHECK_MEMBERS([struct stat.st_ctimensec])
1781 AC_CHECK_MEMBERS([struct stat.st_birthtimespec])
1782 AS_IF([test "x$ac_cv_member_struct_stat_st_birthtimespec" != xyes],
1783     [AC_CHECK_MEMBERS([struct statx.stx_btime])])
1785 AC_CHECK_TYPES([struct timeval], [], [], [@%:@ifdef HAVE_TIME_H
1786 @%:@include <time.h>
1787 @%:@endif
1788 @%:@ifdef HAVE_SYS_TIME_H
1789 @%:@include <sys/time.h>
1790 @%:@endif])
1792 AS_IF([test "${ac_cv_type_struct_timeval}" = yes], [
1793     RUBY_CHECK_SIZEOF([struct timeval.tv_sec], [time_t long "long long"], [],
1794                       [@%:@ifdef HAVE_TIME_H
1795 @%:@include <time.h>
1796 @%:@endif
1797 @%:@ifdef HAVE_SYS_TIME_H
1798 @%:@include <sys/time.h>
1799 @%:@endif])
1800     AS_CASE(${ac_cv_sizeof_struct_timeval_tv_sec},
1801             [SIZEOF_INT], [t=int],
1802             [SIZEOF_LONG], [t=long],
1803             [SIZEOF_LONG_LONG], [t=LONG_LONG],
1804             [t=])
1805     AS_IF([test "${t}" != ""], [
1806         AC_DEFINE_UNQUOTED(TYPEOF_TIMEVAL_TV_SEC, [$t])
1807     ])
1810 AC_CHECK_TYPES([struct timespec], [], [], [@%:@ifdef HAVE_TIME_H
1811 @%:@include <time.h>
1812 @%:@endif
1813 @%:@ifdef HAVE_SYS_TIME_H
1814 @%:@include <sys/time.h>
1815 @%:@endif])
1817 AC_CHECK_TYPES([struct timezone], [], [], [@%:@ifdef HAVE_TIME_H
1818 @%:@ include <time.h>
1819 @%:@endif
1820 @%:@ifdef HAVE_SYS_TIME_H
1821 @%:@ include <sys/time.h>
1822 @%:@endif])
1824 AC_CACHE_VAL([rb_cv_large_fd_select],
1825     [AC_CHECK_TYPE(fd_mask, [rb_cv_large_fd_select=yes], [rb_cv_large_fd_select=no], [AC_INCLUDES_DEFAULT([])
1826 @%:@ifdef HAVE_SYS_SELECT_H
1827 @%:@ include <sys/select.h>
1828 @%:@endif])])
1829 AS_IF([test "$rb_cv_large_fd_select" = yes], [
1830     AC_DEFINE(HAVE_RB_FD_INIT, 1)
1833 RUBY_DEFINT(int8_t, 1)
1834 RUBY_DEFINT(uint8_t, 1, unsigned)
1835 RUBY_DEFINT(int16_t, 2)
1836 RUBY_DEFINT(uint16_t, 2, unsigned)
1837 RUBY_DEFINT(int32_t, 4)
1838 RUBY_DEFINT(uint32_t, 4, unsigned)
1839 RUBY_DEFINT(int64_t, 8)
1840 RUBY_DEFINT(uint64_t, 8, unsigned)
1841 RUBY_DEFINT(int128_t, 16)
1842 RUBY_DEFINT(uint128_t, 16, unsigned)
1843 RUBY_DEFINT(intptr_t, void*)
1844 RUBY_DEFINT(uintptr_t, void*, unsigned)
1845 AS_IF([test "x$rb_cv_type_intptr_t" != xno], [
1846     RUBY_CHECK_PRINTF_PREFIX(intptr_t, '' ll I64 l, PTR)
1848 RUBY_DEFINT(ssize_t, size_t, [], [@%:@include <sys/types.h>])   dnl may differ from int, so not use AC_TYPE_SSIZE_T.
1849 AS_IF([test "x$rb_cv_type_int64_t" != xno], [
1850     RUBY_CHECK_PRINTF_PREFIX(int64_t, ll I64 l, 64)
1853 AC_CACHE_CHECK(for stack end address, rb_cv_stack_end_address,
1854 [rb_cv_stack_end_address=no
1855   AC_LINK_IFELSE([AC_LANG_PROGRAM(
1856       [[extern void *__libc_stack_end;]],
1857       [[if (!__libc_stack_end) return 1;]])],
1858     [rb_cv_stack_end_address="__libc_stack_end"])
1860 AS_IF([test $rb_cv_stack_end_address != no], [
1861   AC_DEFINE_UNQUOTED(STACK_END_ADDRESS, $rb_cv_stack_end_address)
1864 dnl Checks for library functions.
1865 AC_TYPE_GETGROUPS
1866 AS_CASE(["${target_cpu}-${target_os}:${target_archs}"],
1867 [powerpc-darwin*], [
1868   AC_LIBSOURCES(alloca.c)
1869   AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.${ac_objext}])
1870   AC_DEFINE(C_ALLOCA)
1871   AC_DEFINE_UNQUOTED(alloca, alloca)
1872   ],
1873 [universal-darwin*:*ppc*], [
1874   AC_LIBSOURCES(alloca.c)
1875   AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.${ac_objext}])
1876   RUBY_DEFINE_IF([defined __powerpc__], C_ALLOCA, 1)
1877   RUBY_DEFINE_IF([defined __powerpc__], alloca, alloca)
1878   ],
1880   AC_FUNC_ALLOCA
1881   ])
1882 AS_IF([test "x$ALLOCA" = "x"], [
1883     AC_CACHE_CHECK([for dynamic size alloca], rb_cv_dynamic_alloca, [
1884     for chk in ok __chkstk; do
1885         AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1886             @%:@ifdef HAVE_ALLOCA_H
1887             @%:@include <alloca.h>
1888             @%:@endif
1889             void $chk() {}
1890             int dynamic_alloca_test;
1891             int dynamic_alloca_result;]],
1892             [[dynamic_alloca_result = alloca(dynamic_alloca_test) != 0;]])],
1893             [rb_cv_dynamic_alloca=$chk; break])
1894     done])
1895     AS_IF([test "x$rb_cv_dynamic_alloca" = "x__chkstk"], [
1896         AC_DEFINE_UNQUOTED(RUBY_ALLOCA_CHKSTK, _$rb_cv_dynamic_alloca)
1897         AS_CASE("$target_cpu",
1898         [x64|x86_64], [
1899             AC_SUBST([ALLOCA], [\${LIBOBJDIR}x86_64-chkstk.${ac_objext}])
1900         ],)
1901     ])
1903 AC_FUNC_MEMCMP
1905 AS_CASE(["$target_os"],[freebsd*],[
1906          AC_DEFINE(BROKEN_CLOSE)
1907          AC_REPLACE_FUNCS(close)
1908          ])
1910 AC_DEFUN([RUBY_REQUIRE_FUNC], [
1911     AC_CHECK_FUNCS([$1])
1912     AS_IF([test "$ac_cv_func_[]AS_TR_SH($1)" = yes], [],
1913           [AC_MSG_ERROR($1[() must be supported])])
1915 m4_map_args_w([dup dup2], [RUBY_REQUIRE_FUNC(], [)])
1917 AC_REPLACE_FUNCS(acosh)
1918 AC_REPLACE_FUNCS(cbrt)
1919 AC_REPLACE_FUNCS(crypt)
1920 AC_REPLACE_FUNCS(erf)
1921 AC_REPLACE_FUNCS(explicit_bzero)
1922 AC_REPLACE_FUNCS(ffs)
1923 AC_REPLACE_FUNCS(flock)
1924 AC_REPLACE_FUNCS(hypot)
1925 AC_REPLACE_FUNCS(lgamma_r)
1926 AC_REPLACE_FUNCS(memmove)
1927 AC_REPLACE_FUNCS(nan)
1928 AC_REPLACE_FUNCS(nextafter)
1929 AC_REPLACE_FUNCS(setproctitle)
1930 AC_REPLACE_FUNCS(strchr)
1931 AC_REPLACE_FUNCS(strerror)
1932 AC_REPLACE_FUNCS(strlcat)
1933 AC_REPLACE_FUNCS(strlcpy)
1934 AC_REPLACE_FUNCS(strstr)
1935 AC_REPLACE_FUNCS(tgamma)
1937 AC_DEFINE(HAVE_ISFINITE)        # C99; backward compatibility
1939 # for missing/setproctitle.c
1940 AS_CASE(["$target_os"],
1941 [aix* | k*bsd*-gnu | kopensolaris*-gnu | linux* | darwin*], [AC_DEFINE(SPT_TYPE,SPT_REUSEARGV)],
1942 [hpux*], [AC_DEFINE(SPT_TYPE,SPT_PSTAT) ],
1944 AC_CHECK_HEADERS(sys/pstat.h)
1947 AC_DEFINE(HAVE_SIGNBIT)         # C99; backward compatibility
1949 AC_FUNC_FORK
1951 AC_CHECK_FUNCS(__syscall)
1952 AC_CHECK_FUNCS(_longjmp)                # used for AC_ARG_WITH(setjmp-type)
1953 # we don't use _setjmp if _longjmp doesn't exist.
1954 test x$ac_cv_func__longjmp = xno && ac_cv_func__setjmp=no
1955 AC_CHECK_FUNCS(arc4random_buf)
1956 AC_CHECK_FUNCS(atan2l atan2f)
1957 AC_CHECK_FUNCS(chroot)
1958 AC_CHECK_FUNCS(chsize)
1959 AC_CHECK_FUNCS(clock_gettime)
1960 AC_CHECK_FUNCS(copy_file_range)
1961 AC_CHECK_FUNCS(cosh)
1962 AC_CHECK_FUNCS(crypt_r)
1963 AC_CHECK_FUNCS(daemon)
1964 AC_CHECK_FUNCS(dirfd)
1965 AC_CHECK_FUNCS(dl_iterate_phdr)
1966 AC_CHECK_FUNCS(dlopen)
1967 AC_CHECK_FUNCS(dladdr)
1968 AC_CHECK_FUNCS(dup3)
1969 AC_CHECK_FUNCS(eaccess)
1970 AC_CHECK_FUNCS(endgrent)
1971 AC_CHECK_FUNCS(eventfd)
1972 AC_CHECK_FUNCS(explicit_memset)
1973 AC_CHECK_FUNCS(fcopyfile)
1974 AC_CHECK_FUNCS(fchmod)
1975 AC_CHECK_FUNCS(fchown)
1976 AC_CHECK_FUNCS(fcntl)
1977 AC_CHECK_FUNCS(fdatasync)
1978 AC_CHECK_FUNCS(fdopendir)
1979 AC_CHECK_FUNCS(fgetattrlist)
1980 AC_CHECK_FUNCS(fmod)
1981 AC_CHECK_FUNCS(fstatat)
1982 AC_CHECK_FUNCS(fsync)
1983 AC_CHECK_FUNCS(ftruncate)
1984 AC_CHECK_FUNCS(ftruncate64)             # used for Win32 platform
1985 AC_CHECK_FUNCS(getattrlist)
1986 AC_CHECK_FUNCS(getcwd)
1987 AC_CHECK_FUNCS(getentropy)
1988 AC_CHECK_FUNCS(getgidx)
1989 AC_CHECK_FUNCS(getgrnam)
1990 AC_CHECK_FUNCS(getgrnam_r)
1991 AC_CHECK_FUNCS(getgroups)
1992 AC_CHECK_FUNCS(getlogin)
1993 AC_CHECK_FUNCS(getlogin_r)
1994 AC_CHECK_FUNCS(getpgid)
1995 AC_CHECK_FUNCS(getpgrp)
1996 AC_CHECK_FUNCS(getpriority)
1997 AC_CHECK_FUNCS(getpwnam)
1998 AC_CHECK_FUNCS(getpwnam_r)
1999 AC_CHECK_FUNCS(getpwuid)
2000 AC_CHECK_FUNCS(getpwuid_r)
2001 AC_CHECK_FUNCS(getrandom)
2002 AC_CHECK_FUNCS(getresgid)
2003 AC_CHECK_FUNCS(getresuid)
2004 AC_CHECK_FUNCS(getrlimit)
2005 AC_CHECK_FUNCS(getsid)
2006 AC_CHECK_FUNCS(gettimeofday)            # for making ac_cv_func_gettimeofday
2007 AC_CHECK_FUNCS(getuidx)
2008 AC_CHECK_FUNCS(gmtime_r)
2009 AC_CHECK_FUNCS(grantpt)
2010 AC_CHECK_FUNCS(initgroups)
2011 AC_CHECK_FUNCS(ioctl)
2012 AC_CHECK_FUNCS(isfinite)
2013 AC_CHECK_FUNCS(issetugid)
2014 AC_CHECK_FUNCS(killpg)
2015 AC_CHECK_FUNCS(lchmod)
2016 AC_CHECK_FUNCS(lchown)
2017 AC_CHECK_FUNCS(link)
2018 AC_CHECK_FUNCS(llabs)
2019 AC_CHECK_FUNCS(lockf)
2020 AC_CHECK_FUNCS(log2)
2021 AC_CHECK_FUNCS(lstat)
2022 AC_CHECK_FUNCS(lutimes)
2023 AC_CHECK_FUNCS(malloc_usable_size)
2024 AC_CHECK_FUNCS(malloc_size)
2025 AC_CHECK_FUNCS(mblen)
2026 AC_CHECK_FUNCS(memalign)
2027 AC_CHECK_FUNCS(memset_s)
2028 AC_CHECK_FUNCS(writev)
2029 AC_CHECK_FUNCS(memrchr)
2030 AC_CHECK_FUNCS(memmem)
2031 AC_CHECK_FUNCS(mkfifo)
2032 AC_CHECK_FUNCS(mknod)
2033 AC_CHECK_FUNCS(mktime)
2034 AC_CHECK_FUNCS(mmap)
2035 AC_CHECK_FUNCS(mremap)
2036 AC_CHECK_FUNCS(openat)
2037 AC_CHECK_FUNCS(pipe2)
2038 AC_CHECK_FUNCS(poll)
2039 AC_CHECK_FUNCS(posix_fadvise)
2040 AC_CHECK_FUNCS(posix_memalign)
2041 AC_CHECK_FUNCS(ppoll)
2042 AC_CHECK_FUNCS(pread)
2043 AC_CHECK_FUNCS(pwrite)
2044 AC_CHECK_FUNCS(qsort_r)
2045 AC_CHECK_FUNCS(qsort_s)
2046 AC_CHECK_FUNCS(readlink)
2047 AC_CHECK_FUNCS(realpath)
2048 AC_CHECK_FUNCS(round)
2049 AC_CHECK_FUNCS(sched_getaffinity)
2050 AC_CHECK_FUNCS(seekdir)
2051 AC_CHECK_FUNCS(select_large_fdset)
2052 AC_CHECK_FUNCS(sendfile)
2053 AC_CHECK_FUNCS(setegid)
2054 AC_CHECK_FUNCS(setenv)
2055 AC_CHECK_FUNCS(seteuid)
2056 AC_CHECK_FUNCS(setgid)
2057 AC_CHECK_FUNCS(setgroups)
2058 AC_CHECK_FUNCS(setpgid)
2059 AC_CHECK_FUNCS(setpgrp)
2060 AC_CHECK_FUNCS(setregid)
2061 AC_CHECK_FUNCS(setresgid)
2062 AC_CHECK_FUNCS(setresuid)
2063 AC_CHECK_FUNCS(setreuid)
2064 AC_CHECK_FUNCS(setrgid)
2065 AC_CHECK_FUNCS(setrlimit)
2066 AC_CHECK_FUNCS(setruid)
2067 AC_CHECK_FUNCS(setsid)
2068 AC_CHECK_FUNCS(setuid)
2069 AC_CHECK_FUNCS(shutdown)
2070 AC_CHECK_FUNCS(sigaction)
2071 AC_CHECK_FUNCS(sigaltstack)
2072 AC_CHECK_FUNCS(sigprocmask)
2073 AC_CHECK_FUNCS(sinh)
2074 AC_CHECK_FUNCS(spawnv)
2075 AC_CHECK_FUNCS(symlink)
2076 AC_CHECK_FUNCS(syscall)
2077 AC_CHECK_FUNCS(sysconf)
2078 AC_CHECK_FUNCS(tanh)
2079 AC_CHECK_FUNCS(telldir)
2080 AC_CHECK_FUNCS(timegm)
2081 AC_CHECK_FUNCS(times)
2082 AC_CHECK_FUNCS(truncate)
2083 AC_CHECK_FUNCS(truncate64)              # used for Win32
2084 AC_CHECK_FUNCS(unsetenv)
2085 AC_CHECK_FUNCS(utimensat)
2086 AC_CHECK_FUNCS(utimes)
2087 AC_CHECK_FUNCS(wait4)
2088 AC_CHECK_FUNCS(waitpid)
2089 AC_CHECK_FUNCS(__cospi)
2090 AC_CHECK_FUNCS(__sinpi)
2092 AS_IF([test "x$ac_cv_member_struct_statx_stx_btime" = xyes],
2093     [AC_CHECK_FUNCS(statx)])
2095 AS_CASE(["$ac_cv_func_memset_s:$ac_cv_func_qsort_s"], [*yes*],
2096     [RUBY_DEFINE_IF([!defined __STDC_WANT_LIB_EXT1__], [__STDC_WANT_LIB_EXT1__], 1)])
2098 AS_IF([test "$ac_cv_func_getcwd" = yes], [
2099     AC_CACHE_CHECK(if getcwd allocates buffer if NULL is given, [rb_cv_getcwd_malloc],
2100         [AC_RUN_IFELSE([AC_LANG_SOURCE([[
2101 @%:@include <stddef.h>
2102 @%:@include <stdio.h>
2103 @%:@ifdef HAVE_UNISTD_H
2104 @%:@include <unistd.h>
2105 @%:@endif
2106 @%:@ifndef EXIT_SUCCESS
2107 @%:@define EXIT_SUCCESS 0
2108 @%:@endif
2109 @%:@ifndef EXIT_FAILURE
2110 @%:@define EXIT_FAILURE 1
2111 @%:@endif
2114 main(int argc, char **argv)
2116     if (!getcwd(NULL, 0)) return EXIT_FAILURE;
2117     return EXIT_SUCCESS;
2119 ]])],
2120             rb_cv_getcwd_malloc=yes,
2121             rb_cv_getcwd_malloc=no,
2122             AS_CASE($target_os,
2123                 [linux*|darwin*|*bsd|cygwin*|msys*|mingw*|mswin*],
2124                 [rb_cv_getcwd_malloc=yes],
2125                 [rb_cv_getcwd_malloc=no]))])
2126     AS_IF([test "$rb_cv_getcwd_malloc" = no], [AC_DEFINE(NO_GETCWD_MALLOC, 1)])
2129 AS_IF([test "$ac_cv_func_crypt_r" = yes],
2130     [AC_CHECK_HEADERS(crypt.h)])
2131 AS_IF([test "$ac_cv_func_crypt_r:$ac_cv_header_crypt_h" = yes:yes],
2132     [AC_CHECK_MEMBERS([struct crypt_data.initialized], [], [],
2133                       [AC_INCLUDES_DEFAULT([@%:@include <crypt.h>])])])
2135 RUBY_CHECK_BUILTIN_FUNC(__builtin_alloca_with_align, [__builtin_alloca_with_align(1, 4096)])
2136 RUBY_CHECK_BUILTIN_FUNC(__builtin_assume_aligned, [__builtin_assume_aligned((void*)32, 32)])
2137 RUBY_CHECK_BUILTIN_FUNC(__builtin_bswap16, [__builtin_bswap16(0)])
2138 RUBY_CHECK_BUILTIN_FUNC(__builtin_bswap32, [__builtin_bswap32(0)])
2139 RUBY_CHECK_BUILTIN_FUNC(__builtin_bswap64, [__builtin_bswap64(0)])
2140 RUBY_CHECK_BUILTIN_FUNC(__builtin_popcount, [__builtin_popcount(0)])
2141 RUBY_CHECK_BUILTIN_FUNC(__builtin_popcountll, [__builtin_popcountll(0)])
2142 RUBY_CHECK_BUILTIN_FUNC(__builtin_clz, [__builtin_clz(0)])
2143 RUBY_CHECK_BUILTIN_FUNC(__builtin_clzl, [__builtin_clzl(0)])
2144 RUBY_CHECK_BUILTIN_FUNC(__builtin_clzll, [__builtin_clzll(0)])
2145 RUBY_CHECK_BUILTIN_FUNC(__builtin_ctz, [__builtin_ctz(0)])
2146 RUBY_CHECK_BUILTIN_FUNC(__builtin_ctzll, [__builtin_ctzll(0)])
2147 RUBY_CHECK_BUILTIN_FUNC(__builtin_add_overflow, [int x;__builtin_add_overflow(0,0,&x)])
2148 RUBY_CHECK_BUILTIN_FUNC(__builtin_sub_overflow, [int x;__builtin_sub_overflow(0,0,&x)])
2149 RUBY_CHECK_BUILTIN_FUNC(__builtin_mul_overflow, [int x;__builtin_mul_overflow(0,0,&x)])
2150 RUBY_CHECK_BUILTIN_FUNC(__builtin_mul_overflow_p, [__builtin_mul_overflow_p(0,0,(int)0)])
2151 RUBY_CHECK_BUILTIN_FUNC(__builtin_constant_p, [__builtin_constant_p(0)])
2152 RUBY_CHECK_BUILTIN_FUNC(__builtin_choose_expr, [
2153     [int x[__extension__(__builtin_choose_expr(1, 1, -1))]];
2154     [int y[__extension__(__builtin_choose_expr(0, -1, 1))]];
2155     ])
2156 AS_IF([test x$rb_cv_builtin___builtin_choose_expr = xyes], [
2157     RUBY_CHECK_BUILTIN_FUNC(__builtin_choose_expr_constant_p, [
2158     [int x[__extension__(__builtin_choose_expr(__builtin_constant_p(1), 1, -1))]];
2159     [int y[__extension__(__builtin_choose_expr(__builtin_constant_p(foo), -1, 1))]];
2160     ])
2162 RUBY_CHECK_BUILTIN_FUNC(__builtin_types_compatible_p, [__builtin_types_compatible_p(int, int)])
2163 RUBY_CHECK_BUILTIN_FUNC(__builtin_trap, [__builtin_trap()])
2164 RUBY_CHECK_BUILTIN_FUNC(__builtin_expect, [__builtin_expect(0, 0)])
2166 AS_IF([test "$ac_cv_func_qsort_r" != no], [
2167   AC_CACHE_CHECK(whether qsort_r is GNU version, rb_cv_gnu_qsort_r,
2168     [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2169 @%:@include <stdlib.h>
2170 void (qsort_r)(void *base, size_t nmemb, size_t size,
2171             int (*compar)(const void *, const void *, void *),
2172             void *arg);
2173 ]], [[ ]])],
2174       [rb_cv_gnu_qsort_r=yes],
2175       [rb_cv_gnu_qsort_r=no])
2176   ])
2177   AC_CACHE_CHECK(whether qsort_r is BSD version, rb_cv_bsd_qsort_r,
2178     [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2179 @%:@include <stdlib.h>
2180 void (qsort_r)(void *base, size_t nmemb, size_t size,
2181              void *arg, int (*compar)(void *, const void *, const void *));
2182 ]], [[ ]])],
2183       [rb_cv_bsd_qsort_r=yes],
2184       [rb_cv_bsd_qsort_r=no])
2185   ])
2186   AS_CASE("$rb_cv_gnu_qsort_r:$rb_cv_bsd_qsort_r",
2187   [yes:no], [
2188     AC_DEFINE(HAVE_GNU_QSORT_R, 1)
2189   ],
2190   [no:yes], [
2191     AC_DEFINE(HAVE_BSD_QSORT_R, 1)
2192   ])
2195 AC_CACHE_CHECK(whether atan2 handles Inf as C99, rb_cv_atan2_inf_c99, [
2196     AS_IF([test $ac_cv_func_atan2f:$ac_cv_func_atan2l = yes:yes], [
2197         AC_RUN_IFELSE([AC_LANG_SOURCE([[
2198 @%:@include <math.h>
2199 @%:@ifdef HAVE_UNISTD_H
2200 @%:@include <unistd.h>
2201 @%:@endif
2202 @%:@ifndef EXIT_SUCCESS
2203 @%:@define EXIT_SUCCESS 0
2204 @%:@endif
2205 @%:@ifndef EXIT_FAILURE
2206 @%:@define EXIT_FAILURE 1
2207 @%:@endif
2210 main(int argc, char **argv)
2212     if (fabs(atan2(INFINITY, INFINITY) - M_PI_4) <= 0.01) return EXIT_SUCCESS;
2213     return EXIT_FAILURE;
2215 ]])],
2216         [rb_cv_atan2_inf_c99=yes],
2217         [rb_cv_atan2_inf_c99=no],
2218         [AS_CASE($target_os, [mingw*|mswin*], [rb_cv_atan2_inf_c99=no], [rb_cv_atan2_inf_c99=yes])]
2219         )
2220     ], [rb_cv_atan2_inf_c99=no])
2222 AS_IF([test "x$rb_cv_atan2_inf_c99" = xyes], [AC_DEFINE(ATAN2_INF_C99)])
2224 # Some platform need -lrt for clock_gettime, but the other don't.
2225 AS_IF([test x"$ac_cv_func_clock_gettime" != xyes], [
2226     # glibc 2.17 moves clock_* functions from librt to the main C library.
2227     # http://sourceware.org/ml/libc-announce/2012/msg00001.html
2228     AC_CHECK_LIB(rt, clock_gettime)
2229     AS_IF([test x"$ac_cv_lib_rt_clock_gettime" = xyes], [
2230         AC_DEFINE(HAVE_CLOCK_GETTIME, 1)
2231     ])
2233 AC_CHECK_FUNCS(clock_getres) # clock_getres should be tested after clock_gettime test including librt test.
2234 AC_CHECK_LIB([rt], [timer_create])
2235 AC_CHECK_LIB([rt], [timer_settime])
2236 AS_IF([test x"$ac_cv_lib_rt_timer_create" = xyes], [
2237     AC_DEFINE(HAVE_TIMER_CREATE, 1)
2239 AS_IF([test x"$ac_cv_lib_rt_timer_settime" = xyes], [
2240     AC_DEFINE(HAVE_TIMER_SETTIME, 1)
2243 AC_CACHE_CHECK(for unsetenv returns a value, rb_cv_unsetenv_return_value,
2244   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2245 #include <stdlib.h>
2246 ]], [[int v = unsetenv("foo");]])],
2247         rb_cv_unsetenv_return_value=yes,
2248         rb_cv_unsetenv_return_value=no)])
2249 AS_IF([test "$rb_cv_unsetenv_return_value" = no], [
2250   AC_DEFINE(VOID_UNSETENV)
2253 # End of setjmp check.
2255 AC_ARG_ENABLE(setreuid,
2256        AS_HELP_STRING([--enable-setreuid], [use setreuid()/setregid() according to need even if obsolete]),
2257        [use_setreuid=$enableval])
2258 AS_IF([test "$use_setreuid" = yes], [
2259     AC_DEFINE(USE_SETREUID)
2260     AC_DEFINE(USE_SETREGID)
2262 AC_STRUCT_TIMEZONE
2263 AC_CACHE_CHECK(for struct tm.tm_gmtoff, rb_cv_member_struct_tm_tm_gmtoff,
2264   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2265 @%:@define _BSD_SOURCE
2266 @%:@define _DEFAULT_SOURCE
2267 @%:@include <time.h>
2268     ]],
2269     [[struct tm t; t.tm_gmtoff = 3600;]])],
2270   [rb_cv_member_struct_tm_tm_gmtoff=yes],
2271   [rb_cv_member_struct_tm_tm_gmtoff=no])])
2272 AS_IF([test "$rb_cv_member_struct_tm_tm_gmtoff" = yes], [
2273   AC_DEFINE(HAVE_STRUCT_TM_TM_GMTOFF)
2275 AC_CACHE_CHECK(for external int daylight, rb_cv_have_daylight,
2276   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <time.h>
2277   int i;]],
2278         [[i = daylight;]])],
2279         rb_cv_have_daylight=yes,
2280         rb_cv_have_daylight=no)])
2281 AS_IF([test "$rb_cv_have_daylight" = yes], [
2282   AC_DEFINE(HAVE_DAYLIGHT)
2285 AC_CACHE_CHECK(for negative time_t for gmtime(3), rb_cv_negative_time_t,
2286   [AC_RUN_IFELSE([AC_LANG_SOURCE([[
2287 #include <stdlib.h>
2288 #include <time.h>
2290 void
2291 check(tm, y, m, d, h, s)
2292     struct tm *tm;
2293     int y, m, d, h, s;
2295     if (!tm ||
2296         tm->tm_year != y ||
2297         tm->tm_mon  != m-1 ||
2298         tm->tm_mday != d ||
2299         tm->tm_hour != h ||
2300         tm->tm_sec  != s) {
2301         exit(1);
2302     }
2306 main()
2308    time_t t = -1;
2309    struct tm *tm;
2311    check(gmtime(&t), 69, 12, 31, 23, 59);
2312    t = ~(time_t)0 << 31;
2313    check(gmtime(&t), 1, 12, 13, 20, 52);
2314    return 0;
2316 ]])],
2317         rb_cv_negative_time_t=yes,
2318         rb_cv_negative_time_t=no,
2319         rb_cv_negative_time_t=yes)])
2320 AS_IF([test "$rb_cv_negative_time_t" = yes], [
2321   AC_DEFINE(NEGATIVE_TIME_T)
2324 # [ruby-dev:40910] overflow of time on FreeBSD
2325 # http://www.freebsd.org/cgi/query-pr.cgi?pr=145341
2326 AC_CACHE_CHECK(for localtime(3) overflow correctly, rb_cv_localtime_overflow,
2327   [AC_RUN_IFELSE([AC_LANG_SOURCE([[
2328 #include <stdlib.h>
2329 #include <time.h>
2331 void
2332 check(time_t t1)
2334     struct tm *tm;
2335     time_t t2;
2336     tm = localtime(&t1);
2337     if (!tm)
2338         return; /* overflow detected.  ok. */
2339     t2 = mktime(tm);
2340     if (t1 == t2)
2341         return; /* round-trip.  ok. */
2342     exit(1);
2346 main()
2348     time_t t;
2349     if (~(time_t)0 <= 0) {
2350         t = (((time_t)1) << (sizeof(time_t) * 8 - 2));
2351         t |= t - 1;
2352     }
2353     else {
2354         t = ~(time_t)0;
2355     }
2356     check(t);
2357     return 0;
2359 ]])],
2360         rb_cv_localtime_overflow=yes,
2361         rb_cv_localtime_overflow=no,
2362         rb_cv_localtime_overflow=no)])
2363 AS_IF([test "$rb_cv_localtime_overflow" = no], [
2364   AC_DEFINE(LOCALTIME_OVERFLOW_PROBLEM)
2367 AS_IF([test "$ac_cv_func_sigprocmask" = yes && test "$ac_cv_func_sigaction" = yes], [
2368    AC_DEFINE(POSIX_SIGNAL)
2369 ], [
2370   AC_CHECK_FUNCS(sigsetmask)
2371   AC_CACHE_CHECK(for BSD signal semantics, rb_cv_bsd_signal,
2372     [AC_RUN_IFELSE([AC_LANG_SOURCE([[
2373 #include <stdio.h>
2374 #include <signal.h>
2376 void
2377 sig_handler(dummy)
2378      int dummy;
2383 main()
2385   signal(SIGINT, sig_handler);
2386   kill(getpid(), SIGINT);
2387   kill(getpid(), SIGINT);
2388   return 0;
2390 ]])],
2391         rb_cv_bsd_signal=yes,
2392         rb_cv_bsd_signal=no,
2393         rb_cv_bsd_signal=$ac_cv_func_sigsetmask)])
2394   AS_IF([test "$rb_cv_bsd_signal" = yes], [
2395     AC_DEFINE(BSD_SIGNAL)
2396   ])
2399 AC_CHECK_TYPES([sig_t],[],[],[@%:@include <signal.h>])
2401 AS_IF([test "$ac_cv_func_getpgid" = no], [
2402   # AC_FUNC_GETPGRP fails when cross-compiling with old autoconf.
2403   # autoconf is changed between 2.52d and 2.52f?
2404   # http://lists.gnu.org/archive/html/bug-gnu-utils/2001-09/msg00181.html
2405   # "autoconf cleanup for AC_FUNC_GETPGRP and GETPGRP_VOID"
2406 AC_FUNC_GETPGRP
2408 AS_IF([test "$ac_cv_func_setpgid:$ac_cv_func_setpgrp" = no:yes], [
2409   # AC_FUNC_SETPGRP fails when cross-compiling.  (until autoconf 2.69?)
2410   # https://lists.gnu.org/archive/html/bug-autoconf/2013-02/msg00002.html
2411   # "AC_FUNC_SETPGRP fails to work properly when cross-compiling"
2412 AC_FUNC_SETPGRP
2415 AS_IF([test x"$ac_cv_func_dirfd" = xno], [
2416   AS_CASE(["$target_os"],[solaris*],
2417           [AC_CHECK_MEMBERS([DIR.d_fd, DIR.dd_fd],,,[
2418 #include <sys/types.h>
2419 #include <dirent.h>
2420 ])])
2423 AC_CACHE_CHECK(whether right shift preserve sign bit, rb_cv_rshift_sign,
2424     [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([], [(-1==(-1>>1))])],
2425         rb_cv_rshift_sign=yes,
2426         rb_cv_rshift_sign=no)])
2427 AS_IF([test "$rb_cv_rshift_sign" = yes], [
2428   AC_DEFINE(RSHIFT(x,y), ((x)>>(int)(y)))
2429 ], [
2430   AC_DEFINE(RSHIFT(x,y), (((x)<0) ? ~((~(x))>>(int)(y)) : (x)>>(int)(y)))
2433 AS_IF([test "$ac_cv_func_copy_file_range" = no], [
2434   AC_CACHE_CHECK([for copy_file_range],
2435     rb_cv_use_copy_file_range,
2436     [AC_RUN_IFELSE([AC_LANG_SOURCE([[
2437 #include <sys/types.h>
2438 #include <sys/stat.h>
2439 #include <sys/syscall.h>
2440 #include <fcntl.h>
2441 #include <unistd.h>
2443 #ifndef O_TMPFILE
2444   #define O_TMPFILE __O_TMPFILE
2445 #endif
2448 main()
2450 #ifdef __NR_copy_file_range
2451    int ret, fd_in, fd_out;
2452    fd_in = open("/tmp", O_TMPFILE|O_RDWR, S_IRUSR);
2453    fd_out = open("/tmp", O_TMPFILE|O_WRONLY, S_IWUSR);
2454    ret = syscall(__NR_copy_file_range, fd_in, NULL, fd_out, NULL, 0, 0);
2455    close(fd_in);
2456    close(fd_out);
2457    if (ret == -1) { return 1; }
2458    return 0;
2459 #else
2460    return 1;
2461 #endif
2463   ]])],
2464     [rb_cv_use_copy_file_range=yes],
2465     [rb_cv_use_copy_file_range=no],
2466     [rb_cv_use_copy_file_range=no])])
2468 AS_CASE(["$ac_cv_func_copy_file_range:$rb_cv_use_copy_file_range"], [*yes*], [
2469   AC_DEFINE(USE_COPY_FILE_RANGE)
2472 AS_CASE(["$ac_cv_func_gettimeofday:$ac_cv_func_clock_gettime"],
2473 [*yes*], [],
2475     AC_MSG_ERROR(clock_gettime() or gettimeofday() must exist)
2478 AS_IF([test "$ac_cv_func_sysconf" = yes], [
2479   RUBY_CHECK_SYSCONF(CLK_TCK)
2482 AS_IF([test "${universal_binary-no}" = yes ], [
2483     archflagpat=`eval echo '"'"${ARCH_FLAG}"'"' | sed 's/[[][|.*]]/\\&/g'`
2484     save_CFLAGS="$CFLAGS" new_cflags=`echo "$CFLAGS" | sed "s|$archflagpat"'||'`
2485     save_LDFLAGS="$LDFLAGS" new_ldflags=`echo "$LDFLAGS" | sed "s|$archflagpat"'||'`
2486     stack_dir=
2487     for archs in ${universal_archnames}; do
2488         archs=`echo $archs | sed 's/=.*//'`
2489         CFLAGS="$new_cflags -arch $archs"
2490         LDFLAGS="$new_ldflags -arch $archs"
2491         RUBY_STACK_GROW_DIRECTION($archs, dir)
2492         AS_IF([test x$stack_dir = x], [
2493             stack_dir=$dir
2494         ], [test x$stack_dir != x$dir], [
2495             stack_dir=no
2496         ])
2497     done
2498     CFLAGS="$save_CFLAGS" LDFLAGS="$save_LDFLAGS"
2499     AS_IF([test x$stack_dir = xno], [
2500         for archs in ${universal_archnames}; do
2501             archs=`echo $archs | sed 's/=.*//'`
2502             eval dir=\$[rb_cv_stack_grow_dir_]AS_TR_SH([$archs])
2503             RUBY_DEFINE_IF([defined __${archs}__], STACK_GROW_DIRECTION, $dir)
2504         done
2505     ], [
2506         AC_DEFINE_UNQUOTED(STACK_GROW_DIRECTION, $stack_dir)
2507     ])
2508 ], [
2509     RUBY_STACK_GROW_DIRECTION($target_cpu, dir)
2510     AC_DEFINE_UNQUOTED(STACK_GROW_DIRECTION, $dir)
2513 AC_ARG_WITH(coroutine,
2514     AS_HELP_STRING([--with-coroutine=IMPLEMENTATION], [specify the coroutine implementation to use]),
2515     [coroutine_type=$withval], [coroutine_type=])
2516 AS_CASE([$coroutine_type], [yes|''], [
2517     coroutine_type=
2518     AS_CASE(["$target_cpu-$target_os"],
2519         [universal-darwin*], [
2520             coroutine_type=universal
2521         ],
2522         [x*64-darwin*], [
2523             coroutine_type=amd64
2524         ],
2525         [arm64-darwin*], [
2526             coroutine_type=arm64
2527         ],
2528         [x*64-linux*], [
2529             AS_CASE(["$ac_cv_sizeof_voidp"],
2530                 [8], [ coroutine_type=amd64 ],
2531                 [4], [ coroutine_type=x86 ],
2532                 dnl unknown pointer size, bail out as no Context.h soon.
2533             )
2534         ],
2535         [*86-linux*], [
2536             coroutine_type=x86
2537         ],
2538         [x64-mingw*], [
2539             coroutine_type=win64
2540         ],
2541         [*86-mingw*], [
2542             coroutine_type=win32
2543         ],
2544         [arm*-linux*], [
2545             coroutine_type=arm32
2546         ],
2547         [aarch64-linux*], [
2548             coroutine_type=arm64
2549         ],
2550         [powerpc64le-linux*], [
2551             coroutine_type=ppc64le
2552         ],
2553         [riscv64-linux*], [
2554             coroutine_type=riscv64
2555         ],
2556         [x86_64-freebsd*], [
2557             coroutine_type=amd64
2558         ],
2559         [i386-freebsd*], [
2560             coroutine_type=x86
2561         ],
2562         [aarch64-freebsd*], [
2563             coroutine_type=arm64
2564         ],
2565         [x86_64-netbsd*], [
2566             coroutine_type=amd64
2567         ],
2568         [i386-netbsd*], [
2569             coroutine_type=x86
2570         ],
2571         [aarch64-netbsd*], [
2572             coroutine_type=arm64
2573         ],
2574         [x86_64-openbsd*], [
2575             coroutine_type=amd64
2576         ],
2577         [i386-openbsd*], [
2578             coroutine_type=x86
2579         ],
2580         [*-openbsd*], [
2581             coroutine_type=pthread
2582         ],
2583         [x86_64-dragonfly*], [
2584             coroutine_type=amd64
2585         ],
2586         [*-haiku*], [
2587             coroutine_type=pthread
2588         ],
2589         [*-emscripten*], [
2590             coroutine_type=emscripten
2591         ],
2592         [
2593             AC_CHECK_FUNCS([getcontext swapcontext makecontext],
2594                 [coroutine_type=ucontext],
2595                 [coroutine_type=pthread; break]
2596             )
2597         ]
2598     )
2599     AC_MSG_CHECKING(native coroutine implementation for ${target_cpu}-${target_os})
2600     AC_MSG_RESULT(${coroutine_type})
2602 COROUTINE_H=coroutine/$coroutine_type/Context.h
2603 AS_IF([test ! -f "$srcdir/$COROUTINE_H"],
2604       [AC_MSG_ERROR('$coroutine_type' is not supported as coroutine)])
2605 COROUTINE_SRC=coroutine/$coroutine_type/Context.c
2606 AS_IF([test ! -f "$srcdir/$COROUTINE_SRC"],
2607       [COROUTINE_SRC=coroutine/$coroutine_type/Context.'$(ASMEXT)'])
2608 AC_DEFINE_UNQUOTED(COROUTINE_H, ["$COROUTINE_H"])
2609 AC_SUBST(X_COROUTINE_H, [$COROUTINE_H])
2610 AC_SUBST(X_COROUTINE_SRC, [$COROUTINE_SRC])
2612 AS_IF([test x"$enable_pthread" = xyes], [
2613     for pthread_lib in thr pthread pthreads c c_r root; do
2614         AC_CHECK_LIB($pthread_lib, pthread_create,
2615                      rb_with_pthread=yes, rb_with_pthread=no)
2616         AS_IF([test "$rb_with_pthread" = "yes"], [break])
2617     done
2618     AS_IF([test x"$rb_with_pthread" = xyes], [
2619         AC_DEFINE(_REENTRANT)
2620         AC_DEFINE(_THREAD_SAFE)
2621         AC_DEFINE(HAVE_LIBPTHREAD)
2622         AC_CHECK_HEADERS(pthread_np.h, [], [], [@%:@include <pthread.h>])
2623         AS_CASE(["$pthread_lib:$target_os"],
2624                 [c:*], [],
2625                 [root:*], [],
2626                 [c_r:*|*:openbsd*|*:mirbsd*],  [LIBS="-pthread $LIBS"],
2627                 [LIBS="-l$pthread_lib $LIBS"])
2628     ], [
2629         AC_MSG_WARN("Don't know how to find pthread library on your system -- thread support disabled")
2630     ])
2631     AC_CACHE_CHECK([whether pthread_t is scalar type], [rb_cv_scalar_pthread_t], [
2632         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2633             @%:@include <pthread.h>
2634             ]], [[
2635             pthread_t thread_id;
2636             thread_id = 0;
2637             if (!thread_id) return 0;
2638             ]])],[rb_cv_scalar_pthread_t=yes],[rb_cv_scalar_pthread_t=no])
2639     ])
2640     AS_IF([test x"$rb_cv_scalar_pthread_t" = xyes], [
2641         : # RUBY_CHECK_SIZEOF(pthread_t, [void* int long], [], [@%:@include <pthread.h>])
2642     ], [
2643         AC_DEFINE(NON_SCALAR_THREAD_ID)
2644     ])
2645     AC_CHECK_FUNCS(sched_yield pthread_attr_setinheritsched \
2646         pthread_attr_get_np pthread_attr_getstack pthread_attr_getguardsize \
2647         pthread_get_stackaddr_np pthread_get_stacksize_np \
2648         thr_stksegment pthread_stackseg_np pthread_getthrds_np \
2649         pthread_condattr_setclock \
2650         pthread_setname_np pthread_set_name_np)
2651     AS_CASE(["$target_os"],[emscripten*],[ac_cv_func_pthread_sigmask=no],[AC_CHECK_FUNCS(pthread_sigmask)])
2652     AS_CASE(["$target_os"],[aix*],[ac_cv_func_pthread_getattr_np=no],[AC_CHECK_FUNCS(pthread_getattr_np)])
2653     set_current_thread_name=
2654     AS_IF([test "$ac_cv_func_pthread_setname_np" = yes], [
2655         AC_CACHE_CHECK([arguments of pthread_setname_np], [rb_cv_func_pthread_setname_np_arguments],
2656             [rb_cv_func_pthread_setname_np_arguments=
2657             # Linux,AIX,  (pthread_self(), name)
2658             # NetBSD (pthread_self(), \"%s\", name)
2659             # Darwin (name)
2660             for mac in \
2661                 "(pthread_self(), name)" \
2662                 "(pthread_self(), \"%s\", name)" \
2663                 "(name)" \
2664                 ; do
2665                 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2666                     @%:@include <pthread.h>
2667                     @%:@ifdef HAVE_PTHREAD_NP_H
2668                     @%:@include <pthread_np.h>
2669                     @%:@endif
2670                     @%:@define SET_THREAD_NAME(name) pthread_setname_np${mac}
2671                     ]],
2672                     [[if (SET_THREAD_NAME("conftest")) return 1;]])],
2673                     [rb_cv_func_pthread_setname_np_arguments="${mac}"
2674                     break])
2675             done
2676             ]
2677         )
2678         AS_IF([test -n "${rb_cv_func_pthread_setname_np_arguments}"], [
2679             set_current_thread_name="pthread_setname_np${rb_cv_func_pthread_setname_np_arguments}"
2680         ])
2681     ], [test "$ac_cv_func_pthread_set_name_np" = yes], [
2682         set_current_thread_name="pthread_set_name_np(pthread_self(), name)"
2683     ])
2684     AS_IF([test -n "$set_current_thread_name"], [
2685         AC_DEFINE_UNQUOTED(SET_CURRENT_THREAD_NAME(name), $set_current_thread_name)
2686         AS_CASE([$set_current_thread_name],
2687             [*'pthread_self()'*], [
2688                 set_another_thread_name=`echo "$set_current_thread_name" | sed 's/pthread_self()/thid/'`
2689                 AC_DEFINE_UNQUOTED(SET_ANOTHER_THREAD_NAME(thid,name), $set_another_thread_name)
2690             ])
2691     ])
2694 AS_IF([test x"$ac_cv_header_ucontext_h" = xno], [
2695     AC_CACHE_CHECK([if signal.h defines ucontext_t], [rb_cv_ucontext_in_signal_h],
2696         [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <signal.h>]],
2697                                             [[size_t size = sizeof(ucontext_t);]])],
2698         [rb_cv_ucontext_in_signal_h=yes], [rb_cv_ucontext_in_signal_h=no])])
2699     AS_IF([test x"$rb_cv_ucontext_in_signal_h" = xyes], [
2700             AC_DEFINE_UNQUOTED(UCONTEXT_IN_SIGNAL_H, 1)
2701     ])
2703 AS_IF([test x"$ac_cv_header_ucontext_h" = xyes -o x"$rb_cv_ucontext_in_signal_h" = xyes], [
2704     AC_CACHE_CHECK([if mcontext_t is a pointer], [rb_cv_mcontext_t_ptr],
2705         [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2706             @%:@include <signal.h>
2707             @%:@ifdef HAVE_UCONTEXT_H
2708             @%:@include <ucontext.h>
2709             @%:@endif
2710         mcontext_t test(mcontext_t mc) {return mc+1;}
2711           ]],
2712           [[test(0);]])],
2713         [rb_cv_mcontext_t_ptr=yes], [rb_cv_mcontext_t_ptr=no])])
2714     AS_IF([test x"$rb_cv_mcontext_t_ptr" = xyes], [
2715         AC_DEFINE_UNQUOTED(DEFINE_MCONTEXT_PTR(mc, uc), mcontext_t mc = (uc)->uc_mcontext)
2716     ], [
2717         AC_DEFINE_UNQUOTED(DEFINE_MCONTEXT_PTR(mc, uc), mcontext_t *mc = &(uc)->uc_mcontext)
2718     ])
2719     AS_IF([test x"$rb_with_pthread" = xyes], [
2720         AC_CHECK_FUNCS(getcontext setcontext)
2721     ])
2724 AS_IF([test "$ac_cv_func_fork_works" = "yes" -a "$rb_with_pthread" = "yes"], [
2725     AC_CACHE_CHECK([if fork works with pthread], rb_cv_fork_with_pthread,
2726         [AC_RUN_IFELSE([AC_LANG_SOURCE([[
2727 #include <stdlib.h>
2728 #include <unistd.h>
2729 #include <pthread.h>
2730 #include <stdio.h>
2731 #include <sys/types.h>
2732 #include <sys/wait.h>
2733 #include <signal.h>
2734 #ifndef EXIT_SUCCESS
2735 #define EXIT_SUCCESS 0
2736 #endif
2737 #ifndef EXIT_FAILURE
2738 #define EXIT_FAILURE 1
2739 #endif
2741 void *
2742 thread_func(void *dmy)
2744     return dmy;
2748 use_threads(void)
2750     pthread_t tid;
2751     if (pthread_create(&tid, 0, thread_func, 0) != 0) {
2752         return -1;
2753     }
2754     if (pthread_join(tid, 0) != 0) {
2755         return -1;
2756     }
2757     return 0;
2761 main(int argc, char *argv[])
2763     pid_t pid;
2764     if (use_threads()) return EXIT_FAILURE;
2765     pid = fork();
2767     if (pid) {
2768         int loc;
2769         sleep(1);
2770         if (waitpid(pid, &loc, WNOHANG) == 0) {
2771             kill(pid, SIGKILL);
2772             return EXIT_FAILURE;
2773         }
2774         if (!WIFEXITED(loc) || WEXITSTATUS(loc) != EXIT_SUCCESS)
2775            return EXIT_FAILURE;
2776     }
2777     else {
2778         if (use_threads()) return EXIT_FAILURE;
2779     }
2781     return EXIT_SUCCESS;
2782 }]])],
2783         rb_cv_fork_with_pthread=yes,
2784         rb_cv_fork_with_pthread=no,
2785         rb_cv_fork_with_pthread=yes)])
2786     test x$rb_cv_fork_with_pthread = xyes || AC_DEFINE(CANNOT_FORK_WITH_PTHREAD)
2789 AC_CHECK_HEADERS([sys/user.h])
2790 AS_IF([test "x$ac_cv_func_mmap" = xyes], [
2791     AC_CACHE_CHECK([whether PAGE_SIZE is compile-time const], rb_cv_const_page_size,
2792         [malloc_headers=`sed -n '/MALLOC_HEADERS_BEGIN/,/MALLOC_HEADERS_END/p' ${srcdir}/gc.c`
2793         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[$malloc_headers
2794             typedef char conftest_page[PAGE_SIZE];
2795         ]], [[]])],
2796         [rb_cv_const_page_size=yes],
2797         [rb_cv_const_page_size=no])])
2799 AS_IF([test "x$rb_cv_const_page_size" = xyes],
2800     [AC_DEFINE(HAVE_CONST_PAGE_SIZE, 1)],
2801     [AC_DEFINE(HAVE_CONST_PAGE_SIZE, 0)]
2804 AS_IF([test "x$ac_cv_func_ioctl" = xyes], [
2805     AC_CACHE_CHECK([ioctl request type], rb_cv_ioctl_request_type,
2806         [rb_cv_ioctl_request_type=no
2807         dnl corresponding NUM2IOCTLREQ needs to be defined
2808         for type in "unsigned long:ULONG_MAX" int:INT_MAX; do
2809             max=`echo $type | sed 's/.*://'`
2810             type=`echo $type | sed 's/:.*//'`
2811             RUBY_WERROR_FLAG([
2812                 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2813                     @%:@include <limits.h>
2814                     @%:@include <sys/types.h>
2815                     @%:@if defined(HAVE_SYS_IOCTL_H) && !defined(_WIN32)
2816                     @%:@include <sys/ioctl.h>
2817                     @%:@endif
2818                 ]], [[
2819                     $type req = $max;
2820                     if (ioctl(0, req)) {/* do nothing*/};
2821                 ]])],
2822                 [rb_cv_ioctl_request_type="$type"])
2823             ])
2824             test "x$rb_cv_ioctl_request_type" = xno || break
2825         done])
2826     AS_CASE(["$rb_cv_ioctl_request_type"], [no|int], [],
2827     ["unsigned long"], [
2828         AC_DEFINE_UNQUOTED(IOCTL_REQ_TYPE, [$rb_cv_ioctl_request_type])
2829         AC_DEFINE_UNQUOTED(NUM2IOCTLREQ(num), [NUM2ULONG(num)])
2830     ])
2835 : "runtime section" && {
2836 dnl wheather use dln_a_out or not
2837 AC_ARG_WITH(dln-a-out,
2838         AS_HELP_STRING([--with-dln-a-out], [dln_a_out is deprecated]),
2839         [
2840         AS_CASE([$withval],
2841         [yes], [
2842             AC_MSG_ERROR(dln_a_out no longer supported)
2843         ])
2846 AC_CACHE_CHECK(whether ELF binaries are produced, rb_cv_binary_elf,
2847 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[
2848 AS_CASE(["`head -1 conftest$EXEEXT | tr -dc '\177ELF' | tr '\177' .`"],
2849 [.ELF*], [rb_cv_binary_elf=yes], [rb_cv_binary_elf=no])],
2850 rb_cv_binary_elf=no)])
2852 AS_IF([test "$rb_cv_binary_elf" = yes], [
2853   AC_DEFINE(USE_ELF)
2854   AC_CHECK_HEADERS([elf.h elf_abi.h])
2855   AS_IF([test $ac_cv_header_elf_h = yes -o $ac_cv_header_elf_abi_h = yes], [
2856     AC_LIBOBJ([addr2line])
2857     AC_CHECK_LIB([z], [uncompress])
2858   ])
2861 AC_CHECK_HEADERS([mach-o/loader.h])
2862 AS_IF([test "$ac_cv_header_mach_o_loader_h" = yes], [
2863   AC_LIBOBJ([addr2line])
2866 AS_CASE(["$target_os"],
2867 [linux* | gnu* | k*bsd*-gnu | bsdi* | kopensolaris*-gnu], [
2868     AS_IF([test "$rb_cv_binary_elf" = no], [
2869         AC_MSG_ERROR(Not ELF)
2870     ], [
2871         LDFLAGS="$LDFLAGS -rdynamic"
2872     ])])
2873 LIBEXT=a
2875 AC_ARG_WITH(mjit-tabs,
2876     AS_HELP_STRING([--without-mjit-tabs], [expand tabs in mjit header]),
2877     [AS_IF([test $withval = no], [MJIT_TABS=false])])
2878 AC_SUBST(MJIT_TABS)dnl
2879 AC_SUBST(DLDFLAGS)dnl
2880 AC_SUBST(ARCH_FLAG)dnl
2881 AC_SUBST(MJIT_HEADER_FLAGS)dnl
2882 AC_SUBST(MJIT_HEADER_INSTALL_DIR)dnl
2883 AC_SUBST(MJIT_CC)dnl
2884 AS_CASE(["$GCC:$target_os"],
2885     [yes:aix*], [mjit_std_cflag="-std=gnu99"],
2886     [mjit_std_cflag=])
2887 AC_SUBST(MJIT_CFLAGS, [${MJIT_CFLAGS-"-w ${mjit_std_cflag} ${orig_cflags}"}])dnl
2888 AC_SUBST(MJIT_OPTFLAGS, [${MJIT_OPTFLAGS-'$(optflags)'}])dnl
2889 AC_SUBST(MJIT_DEBUGFLAGS, [${MJIT_DEBUGFLAGS-'$(debugflags)'}])dnl
2890 AC_SUBST(MJIT_LDSHARED)dnl
2892 AC_SUBST(STATIC)dnl
2893 AC_SUBST(CCDLFLAGS)dnl
2894 AC_SUBST(LDSHARED)dnl
2895 AC_SUBST(LDSHAREDXX)dnl
2896 AC_SUBST(DLEXT)dnl
2897 AC_SUBST(LIBEXT)dnl
2898 AC_SUBST(ASMEXT, S)dnl
2900 STATIC=
2902 : "dlopen" && {
2903   rb_cv_dlopen=unknown
2904   AC_MSG_CHECKING(whether OS depend dynamic link works)
2905   AS_IF([test "$GCC" = yes], [
2906     AS_CASE(["$target_os"],
2907     [darwin*], [
2908       # The -fno-common is needed if we wish to embed the Ruby interpreter
2909       # into a plugin module of some project (as opposed to embedding it
2910       # within the project's application).  The -I/usr/local/include is
2911       # needed because CPP as discovered by configure (cc -E -traditional)
2912       # fails to consult /usr/local/include by default.  This causes
2913       # mkmf.rb's have_header() to fail if the desired resource happens to be
2914       # installed in the /usr/local tree.
2915       RUBY_APPEND_OPTION(CCDLFLAGS, -fno-common)],
2916     [bsdi*|cygwin*|msys*|mingw*|aix*|interix*], [ ],
2917     [
2918       RUBY_APPEND_OPTION(CCDLFLAGS, -fPIC)])
2919   ], [
2920     AS_CASE(["$target_os"],
2921         [hpux*],          [CCDLFLAGS="$CCDLFLAGS +Z"],
2922         [solaris*|irix*], [CCDLFLAGS="$CCDLFLAGS -KPIC"],
2923         [sunos*],         [CCDLFLAGS="$CCDLFLAGS -PIC"],
2924         [esix*|uxpds*],   [CCDLFLAGS="$CCDLFLAGS -KPIC"],
2925                           [: ${CCDLFLAGS=""}])
2926   ])
2929 : "rpath" && {
2930   AC_ARG_ENABLE(rpath,
2931        AS_HELP_STRING([--enable-rpath], [embed run path into extension libraries.
2932        enabled by default on ELF platforms]),
2933        [enable_rpath=$enableval], [enable_rpath="$rb_cv_binary_elf"])
2935   AS_CASE(["$target_os"],
2936         [hpux*], [      DLDFLAGS="$DLDFLAGS -E"
2937                         : ${LDSHARED='$(LD) -b'}
2938                         XLDFLAGS="$XLDFLAGS -Wl,-E"
2939                         : ${LIBPATHENV=SHLIB_PATH}
2940                         rb_cv_dlopen=yes],
2941         [solaris*], [   AS_IF([test "$GCC" = yes], [
2942                             : ${LDSHARED='$(CC) -shared'}
2943                             AS_IF([test "$rb_cv_prog_gnu_ld" = yes], [
2944                                 LDFLAGS="$LDFLAGS -Wl,-E"
2945                             ])
2946                         ], [
2947                             : ${LDSHARED='$(CC) -G'}
2948                         ])
2949                         AS_IF([test "$ac_cv_sizeof_voidp" = 8], [
2950                             : ${LIBPATHENV=LD_LIBRARY_PATH_64}
2951                             : ${PRELOADENV=LD_PRELOAD_64}
2952                         ], [
2953                             : ${LIBPATHENV=LD_LIBRARY_PATH_32}
2954                             : ${PRELOADENV=LD_PRELOAD_32}
2955                         ])
2956                         rb_cv_dlopen=yes],
2957         [sunos*], [     : ${LDSHARED='$(LD) -assert nodefinitions'}
2958                         rb_cv_dlopen=yes],
2959         [irix*], [      : ${LDSHARED='$(LD) -shared'}
2960                         rb_cv_dlopen=yes],
2961         [sysv4*], [     : ${LDSHARED='$(LD) -G'}
2962                         rb_cv_dlopen=yes],
2963         [nto-qnx*], [   : ${LDSHARED='$(CC) -shared'}
2964                         rb_cv_dlopen=yes],
2965         [esix*|uxpds*], [ : ${LDSHARED='$(LD) -G'}
2966                         rb_cv_dlopen=yes],
2967         [osf*], [       : ${LDSHARED='$(LD) -shared -expect_unresolved "*"'}
2968                         rb_cv_dlopen=yes],
2969         [bsdi3*], [     AS_CASE(["$CC"],
2970                         [*shlicc*], [   : ${LDSHARED='$(CC) -r'}
2971                                         rb_cv_dlopen=yes])],
2972         [linux* | gnu* | k*bsd*-gnu | netbsd* | bsdi* | kopensolaris*-gnu | haiku*], [
2973                         : ${LDSHARED='$(CC) -shared'}
2974                         AS_IF([test "$rb_cv_binary_elf" = yes], [
2975                             LDFLAGS="$LDFLAGS -Wl,-export-dynamic"
2976                         ])
2977                         rb_cv_dlopen=yes],
2978         [interix*], [   : ${LDSHARED='$(CC) -shared'}
2979                         XLDFLAGS="$XLDFLAGS -Wl,-E"
2980                         LIBPATHFLAG=" -L%1\$-s"
2981                         rb_cv_dlopen=yes],
2982         [freebsd*|dragonfly*], [
2983                         : ${LDSHARED='$(CC) -shared'}
2984                         AS_IF([test "$rb_cv_binary_elf" = yes], [
2985                             LDFLAGS="$LDFLAGS -rdynamic"
2986                             DLDFLAGS="$DLDFLAGS "'-Wl,-soname,$@'
2987                         ], [
2988                           test "$GCC" = yes && test "$rb_cv_prog_gnu_ld" = yes || LDSHARED='$(LD) -Bshareable'
2989                         ])
2990                         rb_cv_dlopen=yes],
2991         [openbsd*|mirbsd*], [   : ${LDSHARED='$(CC) -shared ${CCDLFLAGS}'}
2992                         AS_IF([test "$rb_cv_binary_elf" = yes], [
2993                             LDFLAGS="$LDFLAGS -Wl,-E"
2994                         ])
2995                         rb_cv_dlopen=yes],
2996         [darwin*], [    : ${LDSHARED='$(CC) -dynamic -bundle'}
2997                         : ${DLDSHARED='$(CC) -dynamiclib'}
2998                         : ${LDFLAGS=""}
2999                         : ${LIBPATHENV=DYLD_FALLBACK_LIBRARY_PATH}
3000                         : ${PRELOADENV=DYLD_INSERT_LIBRARIES}
3001                         rb_cv_dlopen=yes],
3002         [aix*], [       : ${LDSHARED='$(CC)'}
3003                         AS_IF([test "$GCC" = yes], [
3004                             LDSHARED="$LDSHARED ${linker_flag}-G -shared"
3005                         ], [
3006                             LDSHARED="$LDSHARED ${linker_flag}-G"
3007                         ])
3008                         EXTDLDFLAGS='-e$(TARGET_ENTRY)'
3009                         XLDFLAGS="${linker_flag}"'-bE:$(ARCHFILE)'" ${linker_flag}-brtl"
3010                         XLDFLAGS="$XLDFLAGS ${linker_flag}-blibpath:${prefix}/lib:${LIBPATH:-/usr/lib:/lib}"
3011                         : ${ARCHFILE="ruby.imp"}
3012                         TRY_LINK='$(CC) -oconftest $(INCFLAGS) -I$(hdrdir) $(CPPFLAGS)'
3013                         TRY_LINK="$TRY_LINK"' $(CFLAGS) $(src) $(LIBPATH) $(LDFLAGS) $(LOCAL_LIBS) $(LIBS)'
3014                         : ${LIBPATHENV=LIBPATH}
3015                         : ${PRELOADENV=LDR_PRELOAD}
3016                         rb_cv_dlopen=yes],
3017         [nto-qnx*], [   DLDFLAGS="$DLDFLAGS -L/lib -L/usr/lib -L/usr/local/lib"
3018                         : ${LDSHARED='$(LD) -Bshareable -x'}
3019                         LDFLAGS="$LDFLAGS -L/lib -L/usr/lib -L/usr/local/lib"
3020                         rb_cv_dlopen=yes],
3021         [cygwin*|msys*|mingw*], [
3022                         : ${LDSHARED='$(CC) -shared'}
3023                         XLDFLAGS="$XLDFLAGS -Wl,--stack,0x00200000,--enable-auto-import"
3024                         DLDFLAGS="${DLDFLAGS} -Wl,--enable-auto-image-base,--enable-auto-import"
3025                         : ${LIBPATHENV=PATH}
3026                         : ${PRELOADENV=""}
3027                         rb_cv_dlopen=yes],
3028         [hiuxmpp], [    : ${LDSHARED='$(LD) -r'}],
3029         [atheos*], [    : ${LDSHARED='$(CC) -shared'}
3030                         rb_cv_dlopen=yes],
3031         [       : ${LDSHARED='$(LD)'}])
3032   AC_MSG_RESULT($rb_cv_dlopen)
3034   AS_IF([test "$rb_cv_dlopen" = yes], [
3035     AS_CASE(["$target_os"],
3036       [darwin*], [
3037         for flag in \
3038           "-undefined dynamic_lookup" \
3039           "-multiply_defined suppress" \
3040           ; do
3041           test "x${linker_flag}" = x || flag="${linker_flag}`echo ${flag} | tr ' ' ,`"
3042           RUBY_TRY_LDFLAGS([$flag], [], [flag=])
3043           AS_IF([test "x$flag" != x], [
3044             RUBY_APPEND_OPTIONS(DLDFLAGS, [$flag])
3045           ])
3046         done
3047       ])
3048   ])
3050   AS_IF([test "$enable_rpath:${RPATHFLAG}" = yes:], [
3051       AS_IF([test "x$rpathflag" != x], [
3052           RPATHFLAG=" ${rpathflag}%1\$-s"
3053       ])
3054   ])
3057 AS_IF([test "${LDSHAREDXX}" = ""], [
3058     AS_CASE(["${LDSHARED}"],
3059         [*'$(CC)'*], [
3060             LDSHAREDXX=`echo "${LDSHARED}" | sed 's/\$(CC)/$(CXX)/'`
3061             ],
3062         [*'${CC}'*], [
3063             LDSHAREDXX=`echo "${LDSHARED}" | sed 's/\${CC}/${CXX}/'`
3064             ],
3065         [*$CC*], [
3066             LDSHAREDXX=`echo "${LDSHARED}" | sed "s|$CC|$CXX|"`
3067             ],
3068         [ld" "*], [
3069             ])
3071 AS_CASE([${RPATHFLAG}],[*'%1$'*],[: ${LIBPATHFLAG=' -L%1$-s'}],[: ${LIBPATHFLAG=' -L%s'}])
3073 AC_SUBST(LINK_SO)
3074 AC_SUBST(LIBPATHFLAG)
3075 AC_SUBST(RPATHFLAG)
3076 AC_SUBST(LIBPATHENV, "${LIBPATHENV-LD_LIBRARY_PATH}")
3077 AC_SUBST(PRELOADENV, "${PRELOADENV-LD_PRELOAD}")
3078 AC_SUBST(TRY_LINK)
3080 AS_IF([test "x$OPT_DIR" != x], [
3081     pat=`echo "${LDFLAGS_OPTDIR}" | sed ['s/[][\\.*|]/\\\\&/']`
3082     LDFLAGS=`echo "${LDFLAGS}" | sed "s| ${pat}||"`
3083     val=`IFS="$PATH_SEPARATOR"
3084         for dir in $OPT_DIR; do
3085             echo x ${LIBPATHFLAG} ${RPATHFLAG} |
3086             sed "s/^x *//;s${IFS}"'%1\\$-s'"${IFS}${dir}/lib${IFS}g;s${IFS}%s${IFS}${dir}/lib${IFS}g"
3087         done | tr '\012' ' ' | sed 's/ *$//'`
3088     AS_IF([test x"$val" != x], [
3089         test x"${LDFLAGS}" = x || LDFLAGS="$LDFLAGS "
3090         LDFLAGS="$LDFLAGS$val"
3091         test x"${DLDFLAGS}" = x || DLDFLAGS="$DLDFLAGS "
3092         DLDFLAGS="$DLDFLAGS$val"
3093     ])
3094     LDFLAGS_OPTDIR="$val"
3097 AS_CASE(["$target_os"],
3098 [freebsd*], [
3099     AC_CHECK_LIB([procstat], [procstat_open_sysctl])
3100     AS_IF([test "x$ac_cv_lib_procstat_procstat_open_sysctl" = xyes], [
3101         AC_CHECK_FUNCS(procstat_getvmmap)
3102     ])
3103     ])
3104 AS_CASE(["$target_cpu-$target_os"],
3105 [*-darwin*], [
3106     AC_CHECK_HEADERS([libproc.h])
3107     AC_CHECK_HEADERS([execinfo.h])
3108     AS_IF([test "x$ac_cv_header_execinfo_h" = xyes], [
3109         AC_CHECK_LIB([execinfo], [backtrace])
3110         AC_CHECK_HEADERS([libunwind.h])
3111     ])],
3112 [*-freebsd*|x86_64-netbsd*], [
3113     AC_CHECK_HEADERS([execinfo.h])
3114     AS_IF([test "x$ac_cv_header_execinfo_h" = xyes], [
3115         AC_CHECK_LIB([execinfo], [backtrace])
3116         AC_CHECK_LIB([unwind], [unw_backtrace])
3117     ])])
3118 AC_CHECK_FUNCS(backtrace)
3120 AS_IF([test "x$ac_cv_func_backtrace" = xyes], [
3121   AC_CACHE_CHECK(for broken backtrace, rb_cv_broken_backtrace,
3122     [AC_RUN_IFELSE([AC_LANG_SOURCE([[
3123 #include <unistd.h>
3124 #include <stdio.h>
3125 #include <stdlib.h>
3126 #include <stdint.h>
3127 #include <string.h>
3128 #include <signal.h>
3129 #include <execinfo.h>
3131 ]`grep '^@%:@ *define  *RUBY_SIGALTSTACK_SIZE' ${srcdir}/signal.c`[
3132 #define TRACE_SIZE 256
3134 void sigsegv(int signum, siginfo_t *info, void *ctx){
3135     void *trace[TRACE_SIZE];
3136     int n = backtrace(trace, TRACE_SIZE);
3137     if (n > 0) {
3138         /*fprintf(stdout, "backtrace:%d\n",n);*/
3139     } else {
3140         _exit(EXIT_FAILURE);
3141     }
3142     _exit(EXIT_SUCCESS);
3145 main(void)
3147     volatile int *a = NULL;
3148     stack_t ss;
3149     struct sigaction sa;
3151     ss.ss_sp = malloc(RUBY_SIGALTSTACK_SIZE);
3152     if (ss.ss_sp == NULL) {
3153         fprintf(stderr, "cannot allocate memory for sigaltstack\n");
3154         return EXIT_FAILURE;
3155     }
3156     ss.ss_size = RUBY_SIGALTSTACK_SIZE;
3157     ss.ss_flags = 0;
3158     if (sigaltstack(&ss, NULL) == -1) {
3159         fprintf(stderr, "sigaltstack failed\n");
3160         return EXIT_FAILURE;
3161     }
3162     memset(&sa, 0, sizeof(struct sigaction));
3163     sigemptyset(&sa.sa_mask);
3164     sa.sa_sigaction = sigsegv;
3165     sa.sa_flags |= SA_SIGINFO;
3166     sa.sa_flags |= SA_ONSTACK;
3167     sigaction(SIGSEGV, &sa, NULL);
3168     a[0] = 1;
3169     return EXIT_SUCCESS;
3171 ]])],
3172         rb_cv_broken_backtrace=no,
3173         rb_cv_broken_backtrace=yes,
3174         rb_cv_broken_backtrace=no)])
3175   AS_IF([test "$rb_cv_broken_backtrace" = yes], [
3176     AC_DEFINE(BROKEN_BACKTRACE, 1)
3177   ])
3180 AC_ARG_WITH(valgrind,
3181         AS_HELP_STRING([--without-valgrind],[disable valgrind memcheck support]),
3182         [], with_valgrind=yes)
3183 AS_IF([test x$with_valgrind != xno],
3184         [AC_CHECK_HEADERS(valgrind/memcheck.h)])
3186 : "dlext & soext" && {
3187   AS_CASE(["$target_os"],
3188     [hpux*], [
3189         DLEXT=sl],
3190     [darwin*], [
3191         SOEXT=dylib
3192         DLEXT=bundle],
3193     [cygwin*|msys*|mingw*|*djgpp*], [
3194         LOAD_RELATIVE=1
3195         SOEXT=dll
3196         DLEXT=so],
3197     [
3198         DLEXT=so])
3199 : ${SOEXT="${DLEXT}"}
3200 AC_SUBST(SOEXT)
3203 AS_IF([test "$rb_cv_dlopen:$load_relative" = yes:yes], [
3204     AS_IF([test "$ac_cv_func_dladdr" = yes], [
3205         LOAD_RELATIVE=1
3206     ])
3208 AS_IF([test x"$LOAD_RELATIVE" = x1], [
3209     load_relative=yes
3210 ], [
3211     unset load_relative
3214 len=2 # .rb
3215 n=`expr "$DLEXT"  : '.*'`; test "$n" -gt "$len" && len=$n
3216 AC_DEFINE_UNQUOTED(DLEXT_MAXLEN, `expr $len + 1`)
3217 test ".$DLEXT"  = "." || AC_DEFINE_UNQUOTED(DLEXT,  ".$DLEXT")
3218 AC_SUBST(DLEXT)
3220 : "strip" && {
3221     AC_MSG_CHECKING([for $STRIP flags])
3222     AC_LINK_IFELSE([AC_LANG_PROGRAM], [AS_IF(
3223         ["${STRIP}" -A -n conftest$ac_exeext 2>/dev/null], [
3224             AC_MSG_RESULT([-A -n])
3225             STRIP="${STRIP} -A -n"
3226         ],
3227         ["${STRIP}" -S -x conftest$ac_exeext 2>/dev/null], [
3228             AC_MSG_RESULT([-S -x])
3229             STRIP="${STRIP} -S -x"
3230         ], [
3231             AC_MSG_RESULT([none needed])
3232         ])
3233     ])
3236 AC_ARG_WITH(ext,
3237             AS_HELP_STRING([--with-ext=EXTS],
3238                            [pass to --with-ext option of extmk.rb]))
3239 AC_ARG_WITH(out-ext,
3240             AS_HELP_STRING([--with-out-ext=EXTS],
3241                            [pass to --without-ext option of extmk.rb]))
3242 EXTSTATIC=
3243 AC_SUBST(EXTSTATIC)dnl
3244 AC_ARG_WITH(static-linked-ext,
3245             AS_HELP_STRING([--with-static-linked-ext], [link external modules statically]),
3246             [AS_CASE([$withval],[yes],[STATIC=;EXTSTATIC=static],[no],[],[EXTSTATIC="$withval"])])
3247 AS_CASE([",$EXTSTATIC,"], [,static,|*,enc,*], [
3248   ENCOBJS='enc/encinit.$(OBJEXT) enc/libenc.$(LIBEXT) enc/libtrans.$(LIBEXT)'
3249   EXTOBJS='ext/extinit.$(OBJEXT)'
3250   AC_DEFINE_UNQUOTED(EXTSTATIC, 1)
3251   AC_SUBST(ENCSTATIC, static)
3252 ], [
3253   ENCOBJS='dmyenc.$(OBJEXT)'
3254   EXTOBJS='dmyext.$(OBJEXT)'
3256 AC_SUBST(ENCOBJS)
3257 AC_SUBST(EXTOBJS)
3259 AC_ARG_WITH(setup,
3260             AS_HELP_STRING([--with-setup=SETUP], [use extension libraries setup]),
3261             [setup=$withval])
3262 AS_IF([test -n "$setup"], [
3263     AS_IF([! test -f "ext/$setup" -o -f "$srcdir/ext/$setup"], [
3264         AC_MSG_ERROR(Setup file $setup not found under ext or $srcdir/ext)
3265     ])
3266 ], [test -f "$srcdir/ext/Setup.$target_os"], [
3267     setup="Setup.$target_os"
3268 ], [
3269     setup=
3270     for file in "$srcdir"/ext/Setup.*; do
3271         AS_CASE(["$file"], [*~|*.bak|*.orig|*.rej|*.tmp], [continue])
3272         setup=`basename "$file"`
3273         AS_CASE(["$target_os"], [`expr "$setup" : 'Setup.\(.*\)'`*], [break])
3274         platform=`sed '/^option  *platform  */!d;s///;s/|/*|/g;q' "$file"`
3275         AS_IF([test "x$platform" != x], [
3276             eval "AS_CASE([\"\$target_os\"], [$platform*], [break])"
3277         ])
3278         setup=
3279     done
3280     : ${setup:=Setup}
3282 AC_SUBST(setup)
3284 rubylibprefix='${libdir}/${RUBY_BASE_NAME}'
3285 AC_ARG_WITH(rubylibprefix,
3286             AS_HELP_STRING([--with-rubylibprefix=DIR], [prefix for ruby libraries [[LIBDIR/RUBY_BASE_NAME]]]),
3287             [AS_IF([test "x$withval" = xno], [
3288                 AC_MSG_ERROR([No ruby, No libprefix])
3289             ])
3290             rubylibprefix="$withval"])
3291 AC_SUBST(rubylibprefix)
3293 AS_IF([test x"${exec_prefix}" != xNONE], [
3294     RUBY_EXEC_PREFIX="$exec_prefix"
3295 ], [test x"$prefix" != xNONE], [
3296     RUBY_EXEC_PREFIX="$prefix"
3297 ], [
3298     RUBY_EXEC_PREFIX=$ac_default_prefix
3300 pat=`echo "${RUBY_EXEC_PREFIX}" | tr -c '\012' .`'\(.*\)'
3301 for var in bindir includedir libdir rubylibprefix; do
3302     eval val='"$'$var'"'
3303     AS_CASE(["$val"], ["${RUBY_EXEC_PREFIX}"*], [val='${exec_prefix}'"`expr \"$val\" : \"$pat\"`"])
3304     eval $var='"$val"'
3305 done
3307 BTESTRUBY='$(MINIRUBY)'
3308 BOOTSTRAPRUBY='$(BASERUBY)'
3309 AS_IF([test x"$cross_compiling" = xyes], [
3310   test x"$MINIRUBY" = x && MINIRUBY="${RUBY-$BASERUBY} -I`$CHDIR .; pwd` "-r'$(arch)-fake'
3311   XRUBY_LIBDIR=`${RUBY-$BASERUBY} -rrbconfig -e ['puts RbConfig::CONFIG["libdir"]']`
3312   XRUBY_RUBYLIBDIR=`${RUBY-$BASERUBY} -rrbconfig -e ['puts RbConfig::CONFIG["rubylibdir"]']`
3313   XRUBY_RUBYHDRDIR=`${RUBY-$BASERUBY} -rrbconfig -e ['puts RbConfig::CONFIG["rubyhdrdir"]']`
3314   AC_SUBST(XRUBY_LIBDIR)
3315   AC_SUBST(XRUBY_RUBYLIBDIR)
3316   AC_SUBST(XRUBY_RUBYHDRDIR)
3317   PREP='$(arch)-fake.rb'
3318   RUNRUBY_COMMAND='$(MINIRUBY) -I`cd $(srcdir)/lib; pwd`'
3319   RUNRUBY='$(RUNRUBY_COMMAND)'
3320   XRUBY='$(MINIRUBY)'
3321   TEST_RUNNABLE=no
3322   CROSS_COMPILING=yes
3323   AC_DEFINE(CROSS_COMPILING, 1)
3324 ], [
3325   MINIRUBY='./miniruby$(EXEEXT) -I$(srcdir)/lib -I.'
3326   MINIRUBY="$MINIRUBY"' -I$(EXTOUT)/common'
3327   PREP='miniruby$(EXEEXT)'
3328   RUNRUBY_COMMAND='$(MINIRUBY) $(tooldir)/runruby.rb --extout=$(EXTOUT) $(RUNRUBYOPT)'
3329   RUNRUBY='$(RUNRUBY_COMMAND) --'
3330   XRUBY='$(RUNRUBY)'
3331   AS_CASE(["$HAVE_BASERUBY:$build_os"], [no:*|*:mingw*], [BOOTSTRAPRUBY='$(MINIRUBY)'])
3332   TEST_RUNNABLE=yes
3333   CROSS_COMPILING=no
3335 AC_SUBST(TEST_RUNNABLE)
3336 AC_SUBST(CROSS_COMPILING)
3337 AC_SUBST(MINIRUBY)
3338 AC_SUBST(BTESTRUBY)
3339 AC_SUBST(PREP)
3340 AC_SUBST(RUNRUBY_COMMAND)
3341 AC_SUBST(RUNRUBY)
3342 AC_SUBST(XRUBY)
3343 AC_SUBST(BOOTSTRAPRUBY)
3344 AC_SUBST(EXTOUT, [${EXTOUT=.ext}])
3346 FIRSTMAKEFILE=""
3347 LIBRUBY_A='lib$(RUBY_SO_NAME)-static.a'
3348 LIBRUBY='$(LIBRUBY_A)'
3349 LIBRUBYARG_STATIC='-l$(RUBY_SO_NAME)-static'
3350 LIBRUBYARG='$(LIBRUBYARG_STATIC)'
3351 SOLIBS='$(MAINLIBS)'
3353 AS_CASE(["$target_os"],
3354   [cygwin*|msys*|mingw*|haiku*|darwin*], [
3355     : ${DLDLIBS=""}
3356     ],
3357   [
3358     DLDLIBS="${DLDLIBS:+$DLDLIBS }-lc"
3359     ])
3361 AC_ARG_ENABLE(multiarch,
3362               AS_HELP_STRING([--enable-multiarch], [enable multiarch compatible directories]),
3363               [multiarch=], [unset multiarch])
3364 AS_IF([test ${multiarch+set}], [
3365    AC_DEFINE(ENABLE_MULTIARCH)
3366    MJIT_HEADER_INSTALL_DIR=include/'${arch}/${RUBY_VERSION_NAME}'
3367 ], [
3368    MJIT_HEADER_INSTALL_DIR=include/'${RUBY_VERSION_NAME}/${arch}'
3371 archlibdir='${libdir}/${arch}'
3372 sitearchlibdir='${libdir}/${sitearch}'
3373 archincludedir='${includedir}/${arch}'
3374 sitearchincludedir='${includedir}/${sitearch}'
3376 AC_ARG_WITH(soname,
3377         AS_HELP_STRING([--with-soname=SONAME], [base name of shared library]),
3378         [RUBY_SO_NAME=$withval],
3379         [
3380             AS_CASE(["$target_os"],
3381             [darwin*], [
3382                 RUBY_SO_NAME='$(RUBY_BASE_NAME).$(RUBY_API_VERSION)'
3383             ],
3384             [cygwin*], [
3385                 RUBY_SO_NAME='$(RUBY_BASE_NAME)$(MAJOR)$(MINOR)0'
3386             ],
3387             [mingw*], [
3388                 RUBY_SO_NAME="${rb_cv_msvcrt}"'-$(RUBY_BASE_NAME)$(MAJOR)$(MINOR)0'
3389                 AS_IF([test x"${target_cpu}" != xi386], [
3390                     RUBY_SO_NAME="${target_cpu}-${RUBY_SO_NAME}"
3391                 ])
3392             ],
3393             [RUBY_SO_NAME='$(RUBY_BASE_NAME)'])
3394         ])
3396 LIBRUBY_LDSHARED=${DLDSHARED=${LDSHARED}}
3397 LIBRUBY_DLDFLAGS=$DLDFLAGS
3398 LIBRUBY_SO='lib$(RUBY_SO_NAME).$(SOEXT).$(RUBY_PROGRAM_VERSION)'
3399 LIBRUBY_SONAME='lib$(RUBY_SO_NAME).$(SOEXT).$(RUBY_API_VERSION)'
3400 LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).$(SOEXT)'
3401 ENABLE_SHARED=no
3403 AC_ARG_ENABLE(shared,
3404        AS_HELP_STRING([--enable-shared], [build a shared library for Ruby]),
3405        [enable_shared=$enableval])
3406 libprefix=${multiarch+'$(archlibdir)'}${multiarch-'$(libdir)'}
3407 LIBRUBY_RELATIVE=${load_relative-no}
3408 AS_CASE("$enable_shared", [yes], [
3409   LIBRUBY='$(LIBRUBY_SO)'
3410   LIBRUBYARG_SHARED='-l$(RUBY_SO_NAME)'
3411   LIBRUBYARG='$(LIBRUBYARG_SHARED)'
3412   LIBRUBY_RELATIVE=no
3413   test -z "$CCDLFLAGS" || CFLAGS="$CFLAGS $CCDLFLAGS"
3414   ENABLE_SHARED=yes
3416   # libdir can be overridden in config.site file (on OpenSUSE at least).
3417   libdir_basename=lib
3418   AS_IF([test "$bindir" = '${exec_prefix}/bin'], [
3419     AS_CASE(["$libdir"], ['${exec_prefix}/'*], [libdir_basename=`basename "$libdir"`])
3420   ])
3421   AC_DEFINE_UNQUOTED(LIBDIR_BASENAME, ["${libdir_basename}"])
3422   libdir_basename="${libdir_basename}"${multiarch+'/${arch}'}
3424   # Debian bullseye reportedly has its ld(1) patched, which breaks
3425   # --enable-shared --with-jemalloc combination.  We might have to deal with
3426   # the ld(1) change sooner or later, but in the meantime let us force it
3427   # the old way.
3428   #
3429   # See https://github.com/ruby/ruby/pull/4627
3430   RUBY_TRY_LDFLAGS([${linker_flag}--no-as-needed], [no_as_needed=yes], [no_as_needed=no])
3431   AS_IF([test "$no_as_needed" = yes], [
3432       RUBY_APPEND_OPTIONS(LDFLAGS, [${linker_flag}--no-as-needed])
3433   ])
3435   AS_CASE(["$target_os"],
3436     [freebsd*|dragonfly*], [],
3437     [
3438      AS_IF([test "$GCC" = yes], [
3439        RUBY_TRY_LDFLAGS([${linker_flag}--no-undefined], [no_undefined=yes], [no_undefined=no])
3440        AS_IF([test "no_undefined" = yes], [
3441           RUBY_APPEND_OPTION(EXTLDFLAGS, [${linker_flag}--no-undefined])
3442        ])
3443      ])
3444     ])
3446   AS_CASE(["$target_os"],
3447     [sunos4*], [
3448         LIBRUBY_ALIASES='$(LIBRUBY_SONAME) lib$(RUBY_SO_NAME).$(SOEXT)'
3449         ],
3450     [linux* | gnu* | k*bsd*-gnu | atheos* | kopensolaris*-gnu | haiku*], [
3451         RUBY_APPEND_OPTIONS(LIBRUBY_DLDFLAGS, ['-Wl,-soname,$(LIBRUBY_SONAME)' "$LDFLAGS_OPTDIR"])
3452         LIBRUBY_ALIASES='$(LIBRUBY_SONAME) lib$(RUBY_SO_NAME).$(SOEXT)'
3453         AS_IF([test "$load_relative" = yes], [
3454             libprefix="'\$\${ORIGIN}/../${libdir_basename}'"
3455             LIBRUBY_RPATHFLAGS="-Wl,-rpath,${libprefix}"
3456             LIBRUBY_RELATIVE=yes
3457         ])
3458         ],
3459     [freebsd*|dragonfly*], [
3460         LIBRUBY_SO='lib$(RUBY_SO_NAME).$(SOEXT).$(MAJOR)$(MINOR)'
3461         LIBRUBY_SONAME='$(LIBRUBY_SO)'
3462         AS_IF([test "$rb_cv_binary_elf" != "yes" ], [
3463             LIBRUBY_SO="$LIBRUBY_SO.\$(TEENY)"
3464             LIBRUBY_ALIASES=''
3465         ], [test "$load_relative" = yes], [
3466             libprefix="'\$\$ORIGIN/../${libdir_basename}'"
3467             LIBRUBY_RPATHFLAGS="-Wl,-rpath,${libprefix}"
3468             LIBRUBY_RELATIVE=yes
3469         ])
3470         ],
3471     [netbsd*], [
3472         LIBRUBY_SONAME='lib$(RUBY_SO_NAME).$(SOEXT).$(MAJOR)$(MINOR)'
3473         LIBRUBY_SO="${LIBRUBY_SONAME}"'.$(TEENY)'
3474         RUBY_APPEND_OPTIONS(LIBRUBY_DLDFLAGS, ['-Wl,-soname,$(LIBRUBY_SONAME)' "$LDFLAGS_OPTDIR"])
3475         AS_IF([test "$rb_cv_binary_elf" = yes], [ # ELF platforms
3476            LIBRUBY_ALIASES='$(LIBRUBY_SONAME) lib$(RUBY_SO_NAME).$(SOEXT)'
3477         ], [    # a.out platforms
3478            LIBRUBY_ALIASES=""
3479         ])
3480         ],
3481     [openbsd*|mirbsd*], [
3482         LIBRUBY_SO='lib$(RUBY_SO_NAME).$(SOEXT).$(MAJOR).'`expr ${MINOR} \* 10 + ${TEENY}`
3483         ],
3484     [solaris*], [
3485         LIBRUBY_SO='lib$(RUBY_SO_NAME).$(SOEXT).$(MAJOR)'
3486         LIBRUBY_SONAME='lib$(RUBY_SO_NAME).$(SOEXT).$(RUBY_PROGRAM_VERSION)'
3487         LIBRUBY_ALIASES='$(LIBRUBY_SONAME) lib$(RUBY_SO_NAME).$(SOEXT)'
3488         RUBY_APPEND_OPTIONS(LIBRUBY_DLDFLAGS, ["${linker_flag}-h${linker_flag:+,}"'$(@F)'])
3489         AS_IF([test "$load_relative" = yes], [
3490             libprefix="'\$\$ORIGIN/../${libdir_basename}'"
3491             LIBRUBY_RPATHFLAGS="-R${libprefix}"
3492             LIBRUBY_RELATIVE=yes
3493         ], [
3494             LIBRUBY_RPATHFLAGS='-R${libdir}'
3495         ])
3496         ],
3497     [hpux*], [
3498         XLDFLAGS="$XLDFLAGS "'-Wl,+s,+b,$(libdir)'
3499         LIBRUBY_ALIASES='$(LIBRUBY_SONAME) lib$(RUBY_SO_NAME).$(SOEXT)'
3500         ],
3501     [aix*], [
3502         RUBY_APPEND_OPTIONS(LIBRUBY_DLDFLAGS, ["${linker_flag}-bnoentry" "$XLDFLAGS" "$LDFLAGS_OPTDIR"])
3503         LIBRUBYARG_SHARED='-L${libdir} -l${RUBY_SO_NAME}'
3504         LIBS="$LIBS -lm -lc"
3505         ],
3506     [darwin*], [
3507         LIBRUBY_SO='lib$(RUBY_SO_NAME).$(SOEXT)'
3508         LIBRUBY_SONAME='$(LIBRUBY_SO)'
3509         LIBRUBY_ALIASES='lib$(RUBY_INSTALL_NAME).$(SOEXT)'
3510         AS_IF([test "$load_relative" = yes], [
3511             libprefix="@executable_path/../${libdir_basename}"
3512             LIBRUBY_RELATIVE=yes
3513         ])
3514         LIBRUBY_DLDFLAGS="$LIBRUBY_DLDFLAGS -install_name ${libprefix}"'/$(LIBRUBY_SONAME)'
3515         LIBRUBY_DLDFLAGS="$LIBRUBY_DLDFLAGS "'-compatibility_version $(RUBY_API_VERSION)'
3516         LIBRUBY_DLDFLAGS="$LIBRUBY_DLDFLAGS "'-current_version $(RUBY_PROGRAM_VERSION)'
3517         AS_IF([test "$visibility_option" = ld], [
3518             LIBRUBY_DLDFLAGS="$LIBRUBY_DLDFLAGS "'-Wl,-unexported_symbol,_Init_*'
3519             LIBRUBY_DLDFLAGS="$LIBRUBY_DLDFLAGS "'-Wl,-unexported_symbol,_ruby_static_id_*'
3520             LIBRUBY_DLDFLAGS="$LIBRUBY_DLDFLAGS "'-Wl,-unexported_symbol,*_threadptr_*'
3521         ])
3522         LIBRUBY_DLDFLAGS="$LIBRUBY_DLDFLAGS "' $(XLDFLAGS)'
3523         ],
3524     [interix*], [
3525         LIBRUBYARG_SHARED='-L. -L${libdir} -l$(RUBY_SO_NAME)'
3526         ],
3527     [cygwin*|msys*|mingw*|mswin*], [
3528         LIBRUBY_RELATIVE=yes
3529         ])
3530 ], [
3531   LIBRUBYARG_SHARED=
3533   # enable PIE if possible
3534   AC_ARG_ENABLE(pie,
3535           AS_HELP_STRING([--disable-pie], [disable PIE feature]),
3536           [pie=$enableval], [pie=])
3537   AS_IF([test "$GCC" = yes -a -z "$EXTSTATIC" -a "x$pie" != xno], [
3538     RUBY_TRY_CFLAGS(-fPIE, [pie=yes], [pie=no])
3539     AS_IF([test "$pie" = yes], [
3540       # Use -fPIE when testing -pie.  RUBY_TRY_LDFLAGS sets
3541       # $save_CFLAGS internally, so set other name here.
3542       save_CFLAGS_before_pie="$CFLAGS"
3543       CFLAGS="$CFLAGS -fPIE"
3545       # gcc need -pie but clang need -Wl,-pie.
3546       for pie in -pie -Wl,-pie; do
3547         RUBY_TRY_LDFLAGS([$pie], [], [pie=])
3548         AS_IF([test "x$pie" != x], [
3549           RUBY_APPEND_OPTION(XCFLAGS, -fPIE)
3550           RUBY_APPEND_OPTION(XLDFLAGS, $pie)
3551           break
3552         ])
3553       done
3554       CFLAGS="$save_CFLAGS_before_pie"
3555     ])
3556   ])
3558 AS_IF([test "$enable_rpath" = yes], [
3559     test -z "$LIBRUBY_RPATHFLAGS" || LIBRUBY_RPATHFLAGS="$LIBRUBY_RPATHFLAGS "
3560     rpathflag="${RPATHFLAG}"
3561     AS_CASE(["${cross_compiling}${load_relative}"], [*yes*], [], [rpathflag="$RPATHFLAG$LIBPATHFLAG"])
3562     rpathflag=`IFS="$PATH_SEPARATOR"
3563         echo x "$rpathflag" |
3564         sed "s/^x *//;s${IFS}"'%1\\$-s'"${IFS}${libprefix}${IFS}g;s${IFS}%s${IFS}${libprefix}${IFS}g"
3565     `
3566     LIBRUBY_RPATHFLAGS="$LIBRUBY_RPATHFLAGS${rpathflag}"
3567     LIBRUBYARG_SHARED="$LIBRUBY_RPATHFLAGS $LIBRUBYARG_SHARED"
3568     LIBRUBYARG_STATIC="$LIBRUBY_RPATHFLAGS $LIBRUBYARG_STATIC"
3570 AC_SUBST(LIBRUBY_RELATIVE)
3572 LDFLAGS="-L. $LDFLAGS"
3573 AC_SUBST(ARCHFILE)
3575 AS_IF([test "$EXEEXT" = .exe], [
3576     EXECUTABLE_EXTS='".exe",".com",".cmd",".bat"'
3577     AC_DEFINE_UNQUOTED(EXECUTABLE_EXTS, $EXECUTABLE_EXTS)
3578     EXECUTABLE_EXTS=`echo $EXECUTABLE_EXTS | tr -d '"' | tr , ' '`
3579     AC_SUBST(EXECUTABLE_EXTS)
3582 AS_CASE("$cross_compiling:${LIBPATHENV}", [yes:* | no:], [], [
3583     AC_MSG_CHECKING(whether wrapper for $LIBPATHENV is needed)
3584     AS_IF([env ${LIBPATHENV}=/lib /bin/sh -c ': ${'${LIBPATHENV}'?}' 2>/dev/null],
3585         [AC_MSG_RESULT(no)],
3586         [PREP="$PREP"' exe/$(PROGRAM)'
3587         AC_MSG_RESULT(yes)]
3588     )
3591 AC_ARG_ENABLE(dtrace,
3592         AS_HELP_STRING([--enable-dtrace],
3593         [enable DTrace for tracing inside ruby. enabled by default on systems having dtrace]),
3594         [enable_dtrace=$enableval], [enable_dtrace=auto])
3596 LIBRUBY_A_OBJS='$(OBJS)'
3597 DTRACE_REBUILD=
3598 AS_CASE(["${enable_dtrace}"],
3599 [yes|auto], [
3600     RUBY_DTRACE_AVAILABLE()
3601 ], [
3602     rb_cv_dtrace_available=no
3604 AS_CASE(["$target_os"],[freebsd*],[
3605          rb_cv_dtrace_available=no
3606          ])
3607 AS_IF([test "${enable_dtrace}" = yes], [dnl
3608     AS_IF([test -z "$DTRACE"], [dnl
3609         AC_MSG_ERROR([dtrace(1) is missing])
3610     ], [test "$cross_compiling" = yes], [dnl
3611         AC_MSG_ERROR([--enable-dtrace, however, cross compiling])
3612     ], [test "${rb_cv_dtrace_available}" = "no"], [dnl
3613        AC_MSG_ERROR([--enable-dtrace, however, USDT is not available])
3614     ])
3616 AS_CASE([$rb_cv_dtrace_available],
3617 [yes*], [dnl
3618     RUBY_DTRACE_POSTPROCESS()
3619     AS_IF([test "$rb_cv_prog_dtrace_g" != no], [dnl
3620         DTRACE_OBJ='probes.$(OBJEXT)'
3621     ])
3622     AS_IF([test "$rb_cv_prog_dtrace_g" = rebuild], [dnl
3623         DTRACE_REBUILD=yes
3624         LIBRUBY_A_OBJS='$(DTRACE_GLOMMED_OBJ)'
3625     ])
3626     AS_CASE("${target_os}", [freebsd*], [dnl
3627         # FreeBSD's dtrace requires libelf
3628         LIBS="-lelf $LIBS"
3629     ])
3630     DTRACE_EXT=d
3631 ], [dnl
3632     enable_dtrace=no
3633     DTRACE_EXT=dmyh
3635 AC_SUBST(DTRACE_EXT)
3636 AC_SUBST(DTRACE_OBJ)
3637 AC_SUBST(DTRACE_REBUILD)
3638 AC_SUBST(DTRACE_OPT)
3639 AC_SUBST(LIBRUBY_A_OBJS)
3641 AC_ARG_ENABLE(gcov,
3642        AS_HELP_STRING([--enable-gcov], [enable coverage measurement by gcov]),
3643        [gcov=yes])
3644 AS_IF([test x"$gcov" = xyes], [
3645     CFLAGS="$CFLAGS -coverage"
3646     LDFLAGS="$LDFLAGS -coverage"
3649 RUBY_SETJMP_TYPE
3652 : "build section" && {
3653 dnl build rdoc index if requested
3654 RDOCTARGET=""
3655 CAPITARGET=""
3656 AC_ARG_ENABLE(install-doc,
3657        AS_HELP_STRING([--disable-install-doc], [do not install either rdoc indexes or C API documents during install]),
3658        [install_doc=$enableval], [install_doc=yes])
3659 AC_ARG_WITH(rdoc,
3660       AS_HELP_STRING([--with-rdoc=ri,html], [comma/space separated list of RDoc formats to install]),
3661       [install_rdoc=`echo ,$withval, | sed 'y/,/ /;s/ ri / rdoc /;s/^ *//;s/ *$//'`], [
3662 AC_ARG_ENABLE(install-rdoc,
3663       AS_HELP_STRING([--disable-install-rdoc], [do not install rdoc indexes during install]),
3664       [install_rdoc=$enableval], [install_rdoc=yes])
3666 AC_ARG_ENABLE(install-capi,
3667       AS_HELP_STRING([--disable-install-capi], [do not install C API documents during install]),
3668       [install_capi=$enableval], [install_capi=no])
3670 AS_IF([test "$install_doc" != no], [
3671     AS_CASE(["$install_rdoc"],
3672     [yes], [
3673         RDOCTARGET="rdoc"
3674     ],
3675     [all], [
3676         RDOCTARGET="rdoc html"
3677     ],
3678     [no|''], [
3679         RDOCTARGET="nodoc"
3680     ],
3681     [
3682         RDOCTARGET="$install_rdoc"
3683     ])
3684     AS_IF([test "$install_capi" != no -a -n "$DOXYGEN"], [
3685         CAPITARGET="capi"
3686     ], [
3687         CAPITARGET="nodoc"
3688     ])
3689 ], [
3690     RDOCTARGET="nodoc"
3691     CAPITARGET="nodoc"
3694 AC_SUBST(RDOCTARGET)
3695 AC_SUBST(CAPITARGET)
3697 AS_CASE(["$RDOCTARGET:$CAPITARGET"],[nodoc:nodoc],[INSTALLDOC=nodoc],[INSTALLDOC=all])
3698 AC_SUBST(INSTALLDOC)
3700 AC_ARG_ENABLE(jit-support,
3701         AS_HELP_STRING([--disable-jit-support], [disable JIT features]),
3702         [MJIT_SUPPORT=$enableval
3703          AS_IF([test x"$enable_jit_support" = "xyes"],
3704                  [AC_DEFINE(USE_MJIT, 1)],
3705                  [AC_DEFINE(USE_MJIT, 0)])],
3706         [MJIT_SUPPORT=yes
3707          AC_DEFINE(USE_MJIT, 1)])
3709 AC_SUBST(MJIT_SUPPORT)
3711 AC_ARG_ENABLE(install-static-library,
3712         AS_HELP_STRING([--disable-install-static-library], [do not install static ruby library]),
3713         [INSTALL_STATIC_LIBRARY=$enableval
3714          AS_IF([test x"$enable_shared" = xno -a x"$INSTALL_STATIC_LIBRARY" = xno],
3715                  [AC_MSG_ERROR([must install either static or shared library])],
3716                  [])],
3717         AS_IF([test x"$enable_shared" = xyes],
3718             [INSTALL_STATIC_LIBRARY=no],
3719             [INSTALL_STATIC_LIBRARY=yes]))
3720 AC_SUBST(INSTALL_STATIC_LIBRARY)
3722 AC_CACHE_CHECK([for prefix of external symbols], rb_cv_symbol_prefix, [
3723     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[extern void conftest_external(void) {}]], [[]])],[
3724         rb_cv_symbol_prefix=`$NM conftest.$ac_objext |
3725                              sed -n ['/.*T[     ]\([^   ]*\)conftest_external.*/!d;s//\1/p;q']`
3726         ],
3727         [rb_cv_symbol_prefix=''])
3728     test -n "$rb_cv_symbol_prefix" || rb_cv_symbol_prefix=NONE
3730 SYMBOL_PREFIX="$rb_cv_symbol_prefix"
3731 test "x$SYMBOL_PREFIX" = xNONE && SYMBOL_PREFIX=''
3732 DLNOBJ=dln.o
3733 AC_ARG_ENABLE(dln,
3734               AS_HELP_STRING([--disable-dln], [disable dynamic link feature]),
3735               [test "$enableval" = yes || DLNOBJ=dmydln.o])
3736 AC_SUBST(DLNOBJ)
3737 MINIDLNOBJ=dmydln.o
3739 AS_CASE(["$target_os"],
3740     [linux*], [
3741         ],
3742     [netbsd*], [
3743         RUBY_APPEND_OPTION(CFLAGS, -pipe)
3744         ],
3745     [darwin*], [
3746         RUBY_APPEND_OPTION(CFLAGS, -pipe)
3747         AC_COMPILE_IFELSE([
3748             AC_LANG_BOOL_COMPILE_TRY([@%:@include <AvailabilityMacros.h>],
3749                 [MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7 &&
3750                  MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10])],
3751             [dnl
3752                 RUBY_APPEND_OPTION(XLDFLAGS, [-framework Security])
3753                 RUBY_APPEND_OPTION(LIBRUBYARG_STATIC, [-framework Security])
3754             ]dnl
3755         )
3756         RUBY_APPEND_OPTION(XLDFLAGS, [-framework CoreFoundation])
3757         RUBY_APPEND_OPTION(LIBRUBYARG_STATIC, [-framework CoreFoundation])
3758         ],
3759     [osf*], [
3760         AS_IF([test "$GCC" != "yes" ], [
3761           # compile something small: taint.c is fine for this.
3762           # the main point is the '-v' flag of 'cc'.
3763           AS_CASE(["`cc -v -I. -c main.c -o /tmp/main.o 2>&1`"],
3764           [*/gemc_cc*], [   # we have the new DEC GEM CC
3765                         CFLAGS="$CFLAGS -oldc"
3766                         ],
3767           [            # we have the old MIPS CC
3768                         ])
3769           # cleanup
3770           rm -f /tmp/main.o
3771           CFLAGS="$CFLAGS -std"
3772         ])
3773         ],
3774     [cygwin*|msys*|mingw*], [
3775         LIBRUBY_DLDFLAGS="${LIBRUBY_DLDFLAGS}"' -Wl,--out-implib=$(LIBRUBY)'
3776         AS_CASE(["$target_os"],
3777         [cygwin*], [
3778             AS_IF([test x"$enable_shared" = xyes], [
3779                 LIBRUBY_SO='cyg$(RUBY_SO_NAME)'.dll
3780                 LIBRUBY_DLDFLAGS="${LIBRUBY_DLDFLAGS}"' $(RUBYDEF)'
3781             ])
3782             ],
3783         [mingw*], [
3784             AS_IF([test x"$enable_shared" = xyes], [
3785                 LIBRUBY_SO='$(RUBY_SO_NAME)'.dll
3786                 LIBRUBY_DLDFLAGS="${LIBRUBY_DLDFLAGS}"' $(RUBYDEF)'
3787             ])
3788             EXPORT_PREFIX=' '
3789             EXTDLDFLAGS='$(DEFFILE)'
3790             AC_LIBOBJ([win32/win32])
3791             AC_LIBOBJ([win32/file])
3792             COMMON_LIBS=m
3793 #           COMMON_MACROS="WIN32_LEAN_AND_MEAN="
3794             COMMON_HEADERS="winsock2.h windows.h"
3795             PLATFORM_DIR=win32
3796             ])
3797         LIBRUBY_ALIASES=''
3798         FIRSTMAKEFILE=GNUmakefile:cygwin/GNUmakefile.in
3799         AS_IF([test x"$enable_shared" = xyes], [
3800             LIBRUBY='lib$(RUBY_SO_NAME).dll.a'
3801         ], [
3802             LIBRUBY_SO=dummy
3803             LIBRUBY='lib$(RUBY_SO_NAME).a'
3804             LIBRUBYARG='-l$(RUBY_SO_NAME)'
3805         ])
3806         ],
3807     [hpux*], [
3808         AS_CASE(["$YACC"],[*yacc*], [
3809             XCFLAGS="$XCFLAGS -DYYMAXDEPTH=300"
3810             YACC="$YACC -Nl40000 -Nm40000"
3811         ])
3814 MINIOBJS="$MINIDLNOBJ"
3816 RUBY_THREAD
3818 AC_ARG_ENABLE(debug-env,
3819        AS_HELP_STRING([--enable-debug-env], [enable RUBY_DEBUG environment variable]),
3820        [AC_SUBST(ENABLE_DEBUG_ENV, yes)])
3822 AS_CASE(["$FIRSTMAKEFILE"], [*GNUmakefile:*], [gnumake=yes], [
3823     AC_MSG_CHECKING([if ${MAKE-make} is GNU make])
3824     mkdir conftest.dir
3825     echo "all:; @echo yes" > conftest.dir/GNUmakefile
3826     echo "all:; @echo no" > conftest.dir/Makefile
3827     gnumake=`(cd conftest.dir; ${MAKE-make})`
3828     rm -fr conftest.dir
3829     AS_CASE(["$gnumake"],
3830     [*yes*], [
3831         FIRSTMAKEFILE=GNUmakefile:template/GNUmakefile.in
3832         gnumake=yes],
3833     [
3834         gnumake=no])
3835     AC_MSG_RESULT($gnumake)
3837 AS_IF([test "$gnumake" = yes], [ NULLCMD=: ], [
3838     AC_MSG_CHECKING([for safe null command for ${MAKE-make}])
3839     mkdir conftest.dir
3840     NULLCMD=
3841     for cmd in : true; do
3842         echo 'A=1' > conftest.dir/Makefile
3843         echo 'B=$(A:1=@'$cmd')' >> conftest.dir/Makefile
3844         echo 'all:; $B 1 2 3 4 5 6 7 8 9' >> conftest.dir/Makefile
3845         AS_IF([(cd conftest.dir; ${MAKE-make} >/dev/null 2>/dev/null)], [
3846             NULLCMD=$cmd
3847             break
3848         ])
3849     done
3850     rm -fr conftest.dir
3851     AS_IF([test -z "$NULLCMD"], [
3852         AC_MSG_ERROR(no candidate for safe null command)
3853     ])
3854     AC_MSG_RESULT($NULLCMD)
3856 AC_SUBST(NULLCMD)
3858 AS_IF([test "${universal_binary-no}" = yes ], [
3859     AC_CACHE_CHECK([for architecture macros], rb_cv_architecture_macros, [
3860     mv confdefs.h confdefs1.h
3861     : > confdefs.h
3862     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@if defined __`echo ${universal_archnames} |
3863     sed 's/=[^ ]*//g;s/ /__ || defined __/g'`__
3864 @%:@else
3865 @%:@error
3866 >>>>>><<<<<<
3867 @%:@endif]], [[]])],[
3868     rb_cv_architecture_macros=yes
3869     mv -f confdefs1.h confdefs.h
3870 ], [
3871     rb_cv_architecture_macros=no
3872     archflagpat=`eval echo '"'"${ARCH_FLAG}"'"' | sed 's/[[][|.*]]/\\&/g'`
3873     new_cflags=`echo "$CFLAGS" | sed "s|$archflagpat"'||'`
3874     for archs in ${universal_archnames}; do
3875         cpu=${archs@%:@*=}
3876         archs=${archs%=*}
3877         CFLAGS="$new_cflags -arch $archs"
3878         archs="__${archs}__"
3879         AC_MSG_CHECKING([for macro ${archs} on ${cpu}])
3880         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@ifndef ${archs}
3881 @%:@error
3882 @%:@endif]], [[]])],
3883         [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
3884     done
3885     mv -f confdefs1.h confdefs.h
3886     AC_MSG_ERROR([failed])
3887     ])])
3888     AC_CACHE_CHECK(whether __ARCHITECTURE__ is available, rb_cv_architecture_available,
3889         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <stdio.h>
3890                 const char arch[[]] = __ARCHITECTURE__;]], [[puts(arch);]])],
3891                 [rb_cv_architecture_available=yes], [rb_cv_architecture_available=no]))
3894 : ${MJIT_LDSHARED=`echo "$LDSHARED" | sed ['s|\$(LD)|'"${LD}"'|g;s|\$(CC)|$(MJIT_CC)|g']`}
3896 MAINLIBS="$LIBS"
3897 LIBS=$ORIG_LIBS
3898 AS_IF([test -n "${LIBS}"], [
3899     libspat=`echo "${LIBS}" | sed 's/[[][|.*$^]]/\\&/g;s/^  */ /;s/^  *$/ /'`
3900     MAINFLAGS=`echo " $MAINLIBS " | sed "s|$libspat"'||;s/^ *//;s/ *$//'`
3902 LIBRUBYARG_STATIC="${LIBRUBYARG_STATIC} \$(MAINLIBS)"
3903 CPPFLAGS="$CPPFLAGS "'$(DEFS)'
3904 test -z "$CPPFLAGS" || CPPFLAGS="$CPPFLAGS "; CPPFLAGS="$CPPFLAGS"'${cppflags}'
3905 AS_IF([test -n "${cflags+set}"], [
3906     cflagspat=`eval echo '"'"${cflags}"'"' | sed 's/[[][|.*]]/\\&/g;s/^  */ /;s/^  *$/ /'`
3907     CFLAGS=`echo " $CFLAGS " | sed "s|$cflagspat"'|${cflags}|;s/^ *//;s/ *$//'`
3909 AS_IF([test -n "${cxxflags+set}"], [
3910     cxxflagspat=`eval echo '"'"${cxxflags}"'"' | sed 's/[[][|.*]]/\\&/g;s/^  */ /;s/^  *$/ /'`
3911     CXXFLAGS=`echo " $CXXFLAGS " | sed "s|$cxxflagspat"'|${cxxflags}|;s/^ *//;s/ *$//'`
3913 AS_IF([test "${ARCH_FLAG}"], [
3914     archflagpat=`eval echo '"'"${ARCH_FLAG}"'"' | sed 's/[[][|.*]]/\\&/g'`
3915     CFLAGS=`echo "$CFLAGS" | sed "s| *$archflagpat"'||'`
3916     CXXFLAGS=`echo "$CXXFLAGS" | sed "s| *$archflagpat"'||'`
3917     LDFLAGS=`echo "$LDFLAGS" | sed "s| *$archflagpat"'||'`
3919 rb_cv_warnflags=`echo "$rb_cv_warnflags" | sed 's/^ *//;s/ *$//'`
3920 warnflags="$rb_cv_warnflags"
3921 AC_SUBST(cppflags)dnl
3922 AC_SUBST(cflags, ["${orig_cflags:+$orig_cflags }"'${optflags} ${debugflags} ${warnflags}'])dnl
3923 AC_SUBST(cxxflags)dnl
3924 AC_SUBST(optflags)dnl
3925 AC_SUBST(debugflags)dnl
3926 AC_SUBST(warnflags)dnl
3927 AC_SUBST(strict_warnflags)dnl
3928 AC_SUBST(XCFLAGS)dnl
3929 AC_SUBST(XLDFLAGS)dnl
3930 AC_SUBST(EXTLDFLAGS)dnl
3931 AC_SUBST(EXTDLDFLAGS)dnl
3932 AC_SUBST(LIBRUBY_LDSHARED)
3933 AC_SUBST(LIBRUBY_DLDFLAGS)
3934 AC_SUBST(RUBY_INSTALL_NAME)
3935 AC_SUBST(rubyw_install_name)
3936 AC_SUBST(RUBYW_INSTALL_NAME)
3937 AC_SUBST(RUBY_SO_NAME)
3938 AC_SUBST(LIBRUBY_A)
3939 AC_SUBST(LIBRUBY_SO)
3940 AC_SUBST(LIBRUBY_SONAME)
3941 AC_SUBST(LIBRUBY_ALIASES)
3942 AC_SUBST(LIBRUBY)
3943 AC_SUBST(LIBRUBYARG)
3944 AC_SUBST(LIBRUBYARG_STATIC)
3945 AC_SUBST(LIBRUBYARG_SHARED)
3946 AC_SUBST(SOLIBS)
3947 AC_SUBST(DLDLIBS)
3948 AC_SUBST(DLDSHARED)
3949 AC_SUBST(ENABLE_SHARED)
3950 AC_SUBST(MAINLIBS)
3951 AC_SUBST(COMMON_LIBS)
3952 AC_SUBST(COMMON_MACROS)
3953 AC_SUBST(COMMON_HEADERS)
3954 AC_SUBST(EXPORT_PREFIX)
3955 AC_SUBST(SYMBOL_PREFIX)
3956 AC_SUBST(MINIOBJS)
3957 AC_SUBST(THREAD_MODEL)
3958 AC_SUBST(PLATFORM_DIR)
3960 firstmf=`echo $FIRSTMAKEFILE | sed 's/:.*//'`
3961 firsttmpl=`echo $FIRSTMAKEFILE | sed 's/.*://'`
3962 MAKEFILES="Makefile $firstmf"
3963 MAKEFILES="`echo $MAKEFILES`"
3964 AC_SUBST(MAKEFILES)
3966 ri_prefix=
3967 test "$program_prefix" != NONE &&
3968   ri_prefix=$program_prefix
3970 ri_suffix=
3971 test "$program_suffix" != NONE &&
3972   ri_suffix=$program_suffix
3974 RUBY_INSTALL_NAME="${ri_prefix}"'$(RUBY_BASE_NAME)'"${ri_suffix}"
3975 AS_CASE(["$target_os"],
3976   [cygwin*|msys*|mingw*], [
3977     RUBYW_INSTALL_NAME="${ri_prefix}"'$(RUBYW_BASE_NAME)'"${ri_suffix}"
3978     rubyw_install_name='$(RUBYW_INSTALL_NAME)'
3979     ])
3981 rubylibdir='${rubylibprefix}/${ruby_version}'
3982 rubyarchdir=${multiarch+'${rubyarchprefix}/${ruby_version}'}${multiarch-'${rubylibdir}/${arch}'}
3984 rubyarchprefix=${multiarch+'${archlibdir}/${RUBY_BASE_NAME}'}${multiarch-'${rubylibprefix}/${arch}'}
3985 AC_ARG_WITH(rubyarchprefix,
3986             AS_HELP_STRING([--with-rubyarchprefix=DIR],
3987                            [prefix for architecture dependent ruby libraries [[RUBYLIBPREFIX/ARCH]]]),
3988             [rubyarchprefix="$withval"])
3989 AC_SUBST(rubyarchprefix)
3991 rubysitearchprefix=${multiarch+'${sitearchlibdir}/${RUBY_BASE_NAME}'}${multiarch-'${rubylibprefix}/${sitearch}'}
3992 AC_ARG_WITH(rubysitearchprefix,
3993             AS_HELP_STRING([--with-rubysitearchprefix=DIR],
3994                            [prefix for architecture dependent site libraries [[RUBYLIBPREFIX/SITEARCH]]]),
3995             [rubysitearchprefix="$withval"])
3996 AC_SUBST(rubysitearchprefix)
3998 RI_BASE_NAME=`echo ${RUBY_BASE_NAME} | sed 's/ruby/ri/'`
3999 ridir='${datarootdir}/${RI_BASE_NAME}'
4000 AC_ARG_WITH(ridir,
4001             AS_HELP_STRING([--with-ridir=DIR], [ri documentation [[DATAROOTDIR/ri]]]),
4002             [ridir=$withval])
4003 AC_SUBST(ridir)
4004 AC_SUBST(RI_BASE_NAME)
4006 AC_ARG_WITH(ruby-version,
4007             AS_HELP_STRING([--with-ruby-version=STR], [ruby version string for version specific directories [[full]] (full|minor|STR)]),
4008             [ruby_version=$withval],
4009             [ruby_version=full])
4010 unset RUBY_LIB_VERSION
4011 unset RUBY_LIB_VERSION_STYLE
4012 AS_CASE(["$ruby_version"],
4013   [full],  [RUBY_LIB_VERSION_STYLE='3   /* full */'],
4014   [minor], [RUBY_LIB_VERSION_STYLE='2   /* minor */'])
4015 AS_IF([test ${RUBY_LIB_VERSION_STYLE+set}], [
4016     {
4017     echo "#define RUBY_LIB_VERSION_STYLE $RUBY_LIB_VERSION_STYLE"
4018     echo '#define STRINGIZE(x) x'
4019     test -f revision.h -o -f "${srcdir}/revision.h" || echo '#define RUBY_REVISION 0'
4020     echo '#include "version.h"'
4021     echo 'ruby_version=RUBY_LIB_VERSION'
4022     } > conftest.c
4023     ruby_version="`$CPP -I. -I"${srcdir}" -I"${srcdir}/include" conftest.c | sed '/^ruby_version=/!d;s/ //g'`"
4024     eval $ruby_version
4025 ], [test -z "${ruby_version}"], [
4026     AC_MSG_ERROR([No ruby version, No place for bundled libraries])
4027 ], [
4028     RUBY_LIB_VERSION="${ruby_version}"
4030 AC_SUBST(RUBY_LIB_VERSION_STYLE)
4031 AC_SUBST(RUBY_LIB_VERSION)
4033 AC_ARG_WITH(sitedir,
4034             AS_HELP_STRING([--with-sitedir=DIR], [site libraries in DIR [[RUBY_LIB_PREFIX/site_ruby]], "no" to disable site directory]),
4035             [sitedir=$withval],
4036             [sitedir='${rubylibprefix}/site_ruby'])
4037 sitelibdir='${sitedir}/${ruby_version}'
4039 AC_ARG_WITH(sitearchdir,
4040             AS_HELP_STRING([--with-sitearchdir=DIR],
4041                            [architecture dependent site libraries in DIR [[SITEDIR/SITEARCH]], "no" to disable site directory]),
4042             [sitearchdir=$withval],
4043             [sitearchdir=${multiarch+'${rubysitearchprefix}/site_ruby/${ruby_version}'}${multiarch-'${sitelibdir}/${sitearch}'}])
4045 AC_ARG_WITH(vendordir,
4046             AS_HELP_STRING([--with-vendordir=DIR], [vendor libraries in DIR [[RUBY_LIB_PREFIX/vendor_ruby]], "no" to disable vendor directory]),
4047             [vendordir=$withval],
4048             [vendordir='${rubylibprefix}/vendor_ruby'])
4049 vendorlibdir='${vendordir}/${ruby_version}'
4051 AC_ARG_WITH(vendorarchdir,
4052             AS_HELP_STRING([--with-vendorarchdir=DIR],
4053                            [architecture dependent vendor libraries in DIR [[VENDORDIR/SITEARCH]], "no" to disable vendor directory]),
4054             [vendorarchdir=$withval],
4055             [vendorarchdir=${multiarch+'${rubysitearchprefix}/vendor_ruby/${ruby_version}'}${multiarch-'${vendorlibdir}/${sitearch}'}])
4057 AS_IF([test "${LOAD_RELATIVE+set}"], [
4058     AC_DEFINE_UNQUOTED(LOAD_RELATIVE, $LOAD_RELATIVE)
4059     RUBY_EXEC_PREFIX=''
4062 AC_SUBST(RUBY_EXEC_PREFIX)
4064 AC_SUBST(libdirname, ${multiarch+arch}libdir)
4065 AC_SUBST(archlibdir)dnl
4066 AC_SUBST(sitearchlibdir)dnl
4067 AC_SUBST(archincludedir)dnl
4068 AC_SUBST(sitearchincludedir)dnl
4069 AC_SUBST(arch)dnl
4070 AC_SUBST(sitearch)dnl
4071 AC_SUBST(ruby_version)dnl
4072 AC_SUBST(rubylibdir)dnl
4073 AC_SUBST(rubyarchdir)dnl
4074 AC_SUBST(sitedir)dnl
4075 AC_SUBST(sitelibdir)dnl
4076 AC_SUBST(sitearchdir)dnl
4077 AC_SUBST(vendordir)dnl
4078 AC_SUBST(vendorlibdir)dnl
4079 AC_SUBST(vendorarchdir)dnl
4081 AC_SUBST(CONFIGURE, "`echo $0 | sed 's|.*/||'`")dnl
4082 AC_SUBST(configure_args, "`echo "${ac_configure_args}" | sed 's/\\$/$$/g'`")dnl
4084 AS_IF([test "${universal_binary-no}" = yes ], [
4085     arch="universal-${target_os}"
4086     AS_IF([test "${rb_cv_architecture_available}" = yes], [
4087         AC_DEFINE_UNQUOTED(RUBY_PLATFORM_CPU, __ARCHITECTURE__)
4088     ], [
4089         for archs in ${universal_archnames}; do
4090             cpu=`echo $archs | sed 's/.*=//'`
4091             archs=`echo $archs | sed 's/=.*//'`
4092             RUBY_DEFINE_IF([defined __${archs}__ &&! defined RUBY_PLATFORM_CPU], RUBY_PLATFORM_CPU, ["${cpu}"])
4093         done
4094     ])
4095     ints='long int short'
4096     test "$ac_cv_type_long_long" = yes && ints="'long long' $ints"
4097     AC_SUBST(UNIVERSAL_ARCHNAMES, "${universal_archnames}")
4098     AC_SUBST(UNIVERSAL_INTS, "${ints}")
4099     AC_DEFINE_UNQUOTED(RUBY_PLATFORM_OS, "${target_os}")
4100     AC_DEFINE_UNQUOTED(RUBY_ARCH, "universal-" RUBY_PLATFORM_OS)
4101     AC_DEFINE_UNQUOTED(RUBY_PLATFORM, "universal." RUBY_PLATFORM_CPU "-" RUBY_PLATFORM_OS)
4102 ], [
4103     AS_IF([test "${target_os}-${rb_cv_msvcrt}" = "mingw32-ucrt" ], [
4104         arch="${target_cpu}-mingw-ucrt"
4105     ], [
4106         arch="${target_cpu}-${target_os}"
4107     ])
4108     AC_DEFINE_UNQUOTED(RUBY_PLATFORM, "$arch")
4111 unset sitearch
4112 AS_CASE(["$target_os"],[mingw*],[sitearch="$target_cpu-$rb_cv_msvcrt"])
4113 : ${sitearch='${arch}'}
4115 AC_ARG_WITH(search-path,
4116                 AS_HELP_STRING([--with-search-path=DIR], [specify the additional search path]),
4117                 [search_path=$withval])
4118 AS_IF([test "$search_path" != ""], [
4119     AC_SUBST(RUBY_SEARCH_PATH, $search_path)
4122 AC_ARG_WITH(rubyhdrdir,
4123             AS_HELP_STRING([--with-rubyhdrdir=DIR], [core headers in DIR [[INCLUDEDIR/RUBY_BASE_NAME-RUBY_VERSION]]]),
4124             [rubyhdrdir=$withval],
4125             [rubyhdrdir='${includedir}/${RUBY_VERSION_NAME}'])
4127 AC_ARG_WITH(rubyarchhdrdir,
4128             AS_HELP_STRING([--with-rubyarchhdrdir=DIR],
4129                            [architecture dependent core headers in DIR [[$(rubyhdrdir)/$(arch)]]]),
4130             [rubyarchhdrdir=$withval],
4131             [rubyarchhdrdir=${multiarch+'${archincludedir}/${RUBY_VERSION_NAME}'}${multiarch-'${rubyhdrdir}/${arch}'}])
4133 AC_ARG_WITH(sitehdrdir,
4134             AS_HELP_STRING([--with-sitehdrdir=DIR], [core site headers in DIR [[RUBYHDRDIR/site_ruby]]]),
4135             [sitehdrdir=$withval],
4136             [sitehdrdir='${rubyhdrdir}/site_ruby'])
4138 AC_ARG_WITH(sitearchhdrdir,
4139             AS_HELP_STRING([--with-sitearchhdrdir=DIR],
4140                            [architecture dependent core site headers in DIR [[RUBYHDRDIR/site_ruby]]]),
4141             [sitearchhdrdir=$withval],
4142             [sitearchhdrdir=${multiarch+'${sitearchincludedir}/${RUBY_VERSION_NAME}/site_ruby'}${multiarch-'${sitehdrdir}/${sitearch}'}])
4144 AC_ARG_WITH(vendorhdrdir,
4145             AS_HELP_STRING([--with-vendorhdrdir=DIR], [core vendor headers in DIR [[RUBYHDRDIR/vendor_ruby]]]),
4146             [vendorhdrdir=$withval],
4147             [vendorhdrdir='${rubyhdrdir}/vendor_ruby'])
4149 AC_ARG_WITH(vendorarchhdrdir,
4150             AS_HELP_STRING([--with-vendorarchhdrdir=DIR],
4151                            [architecture dependent core vendor headers in DIR [[RUBYHDRDIR/vendor_ruby]]]),
4152             [vendorarchhdrdir=$withval],
4153             [vendorarchhdrdir=${multiarch+'${sitearchincludedir}/${RUBY_VERSION_NAME}/vendor_ruby'}${multiarch-'${vendorhdrdir}/${sitearch}'}])
4155 AC_SUBST(rubyhdrdir)dnl
4156 AC_SUBST(sitehdrdir)dnl
4157 AC_SUBST(vendorhdrdir)dnl
4158 AC_SUBST(rubyarchhdrdir)dnl
4159 AC_SUBST(sitearchhdrdir)dnl
4160 AC_SUBST(vendorarchhdrdir)dnl
4162 AC_ARG_WITH(mantype,
4163         AS_HELP_STRING([--with-mantype=TYPE], [specify man page type; TYPE is one of man and doc]),
4164                 [
4165                         AS_CASE(["$withval"],
4166                         [man|man.gz|man.bz2|doc|doc.gz|doc.bz2], [MANTYPE=$withval],
4167                         [AC_MSG_ERROR(invalid man type: $withval)])
4168                 ])
4169 AS_IF([test -z "$MANTYPE"], [
4170         dnl Looks for nroff with -mdoc support.
4171         AC_CACHE_VAL([ac_cv_path_NROFF], [
4172                 AC_PATH_PROGS_FEATURE_CHECK([NROFF],
4173                         [nroff awf mandoc],
4174                         [$ac_path_NROFF -mdoc ${srcdir}/man/ruby.1 \
4175                                 >/dev/null 2>&1 &&
4176                                 ac_cv_path_NROFF=$ac_path_NROFF \
4177                                 ac_path_NROFF_found=:],
4178                         [], ["/usr/bin:/usr/ucb"]
4179                 )
4180         ])
4181         AS_IF([test -n "$ac_cv_path_NROFF"], [
4182                 MANTYPE=doc
4183         ], [
4184                 MANTYPE=man
4185         ])
4187 AC_SUBST(MANTYPE)
4189 AC_ARG_ENABLE(rubygems,
4190         AS_HELP_STRING([--disable-rubygems], [disable rubygems by default]),
4191         [enable_rubygems="$enableval"], [enable_rubygems=yes])
4192 AS_IF([test x"$enable_rubygems" = xno], [
4193     USE_RUBYGEMS=no
4194 ], [
4195     USE_RUBYGEMS=yes
4197 AC_SUBST(USE_RUBYGEMS)
4199 arch_hdrdir="${EXTOUT}/include/${arch}/ruby"
4200 AS_MKDIR_P("${arch_hdrdir}")
4201 config_h="${arch_hdrdir}/config.h"
4202 guard=INCLUDE_RUBY_CONFIG_H
4204   echo "#ifndef $guard"
4205   echo "#define $guard 1"
4206   grep -v "^#define PACKAGE_" confdefs.h
4207   echo "#endif /* $guard */"
4208 } | tr -d '\015' |
4210   AS_IF([test "x$CONFIGURE_TTY" = xyes], [color=--color], [color=])
4211   exec ${SHELL} ${tooldir}/ifchange $color "${config_h}" -
4212 ) >&AS_MESSAGE_FD || AC_MSG_ERROR([failed to create ${config_h}])
4213 tr -d '\015' < largefile.h > confdefs.h
4214 rm largefile.h
4216 BUILTIN_ENCS=["`sed -n -e '/^BUILTIN_ENCS[      ]*=/{' \
4217         -e s/// -e :l -e '/\\\\$/N' -e 's/\\\\\\n/ /' -e 't l' -e p \
4218         -e '}' "${srcdir}/enc/Makefile.in"`"]
4219 BUILTIN_ENCOBJS=
4220 for e in $BUILTIN_ENCS; do BUILTIN_ENCOBJS="$BUILTIN_ENCOBJS "`echo $e | sed 's/\.c$/.$(OBJEXT)/'`; done
4221 AC_SUBST(BUILTIN_ENCOBJS)
4223 BUILTIN_TRANSES=["`sed -n -e '/^BUILTIN_TRANSES[        ]*=/{' \
4224         -e s/// -e :l -e '/\\\\$/N' -e 's/\\\\\\n/ /' -e 't l' -e p \
4225         -e '}' "${srcdir}/enc/Makefile.in"`"]
4226 BUILTIN_TRANSSRCS=
4227 BUILTIN_TRANSOBJS=
4228 for e in $BUILTIN_TRANSES; do
4229   BUILTIN_TRANSSRCS="$BUILTIN_TRANSSRCS "`echo $e | sed 's/\.trans$/.c/'`
4230   BUILTIN_TRANSOBJS="$BUILTIN_TRANSOBJS "`echo $e | sed 's/\.trans$/.$(OBJEXT)/'`
4231 done
4232 AC_SUBST(BUILTIN_TRANSSRCS)
4233 AC_SUBST(BUILTIN_TRANSOBJS)
4235 PACKAGE=$RUBY_BASE_NAME
4236 AC_SUBST(PACKAGE)
4237 AS_MESSAGE([$PACKAGE library version = $ruby_version])
4239 AS_IF([test x"$CC_WRAPPER" != x], [
4240     CC='$(CC_WRAPPER) '"${CC@%:@$CC_WRAPPER }"
4241     CPP='$(CC_WRAPPER) '"${CPP@%:@$CC_WRAPPER }"
4242     CC_WRAPPER='$(rubyarchdir)/darwin-cc'
4243     XCC_WRAPPER='$(top_srcdir)/tool/darwin-cc'
4245 AC_SUBST(CC_WRAPPER, '')
4246 AC_SUBST(XCC_WRAPPER)
4248 AS_CASE([" $CPP "], [*" $CC "*], [CPP=`echo " $CPP " | sed "s| $CC |"' $(CC) |;s/^ *//;s/  *$//'`])
4250 AS_IF([test x"$firstmf" != x], [
4251     AC_CONFIG_FILES($firstmf:$firsttmpl, [], [firstmf="$firstmf" firsttmpl="$firsttmpl"])
4253 AC_CONFIG_FILES(Makefile:template/Makefile.in, [
4254     tmpmk=confmk$$.tmp
4255     {
4256         AS_IF([test ${VCS+set}], [
4257             :
4258         ], [git_dir=`$GIT --work-tree="$srcdir" --git-dir="$srcdir/.git" rev-parse --git-dir 2>/dev/null`], [
4259             VCS='$(GIT)'
4260         ], [
4261             VCS='echo cannot'
4262         ])
4263         AS_CASE("$VCS",
4264                 ['$(GIT)'|git], [VCSUP='$(VCS) pull --rebase $(GITPULLOPTIONS)'],
4265                 [VCSUP='$(VCS)'])
4266         sed -n \
4267             -e '[/^@%:@define \(RUBY_RELEASE_[A-Z]*\) \([0-9][0-9]*\)/]{' \
4268             -e   's//\1 = \2/' \
4269             -e   '[s/ \([0-9]\)$/ 0\1/]' \
4270             -e   p \
4271             -e '}' "$srcdir/version.h"
4272         sed '/^MISSING/s/\$U\././g;/^VCS *=/s#@VCS@#'"$VCS"'#;/^VCSUP *=/s#@VCSUP@#'"$VCSUP"'#' Makefile
4273         echo; test x"$EXEEXT" = x || echo 'miniruby: miniruby$(EXEEXT)'
4274         AS_IF([test "$gnumake" != yes], [
4275             echo ['$(MKFILES): $(srcdir)/common.mk']
4276             sed ['s/{\$([^(){}]*)[^{}]*}//g'] ${srcdir}/common.mk
4277         ], [
4278             echo 'distclean-local::; @$(RM) GNUmakefile uncommon.mk'
4279         ])
4280     } > $tmpmk && AS_IF([! grep '^ruby:' $tmpmk > /dev/null], [
4281         AS_IF([test "${gnumake}" = yes], [
4282             tmpgmk=confgmk$$.tmp
4283             {
4284                 echo "include $tmpmk"
4285                 echo "-include uncommon.mk"
4286             } > $tmpgmk
4287         ], [
4288             tmpgmk=$tmpmk
4289         ]) &&
4290         test -z "`${MAKE-make} -f $tmpgmk info-program | grep '^PROGRAM=ruby$'`" &&
4291         echo 'ruby: $(PROGRAM);' >> $tmpmk
4292         test "$tmpmk" = "$tmpgmk" || rm -f "$tmpgmk"
4293     ]) && mv -f $tmpmk Makefile],
4294 [EXEEXT='$EXEEXT' MAKE='${MAKE-make}' gnumake='$gnumake' GIT='$GIT'])
4296 AC_ARG_WITH([ruby-pc],
4297             AS_HELP_STRING([--with-ruby-pc=FILENAME], [pc file basename]),
4298             [ruby_pc="$withval"],
4299             [ruby_pc="${RUBY_BASE_NAME}-${MAJOR}.${MINOR}.pc"])
4300 AC_SUBST(ruby_pc)
4301 AC_SUBST(exec, [exec])
4303 AC_ARG_WITH(destdir,
4304             AS_HELP_STRING([--with-destdir=DESTDIR], [specify default directory to install]),
4305             [DESTDIR="$withval"])
4306 AC_SUBST(DESTDIR)
4308 AC_OUTPUT
4312 AS_IF([test "$silent" = yes], [], [
4313 AS_IF([${FOLD+:} false], [], [
4314 AS_IF([test "`echo abcdefg hijklmno | fold -s -w10 | sed 1d`" = hijklmno], [FOLD="fold"], [FOLD=])
4316 fold_width=`expr $COLUMNS - 30 2>/dev/null` || fold_width=50
4317 AS_REQUIRE_SHELL_FN([config_summary],
4318     [AS_FUNCTION_DESCRIBE([config_summary], [NAME, VAL], [configuration summary])],
4319     [AS_IF([test -z "$2"], [], [
4320         AS_ECHO_N(["   * $1:                     "]) | dd bs=1 count=26 2>/dev/null
4321         AS_IF([test "$FOLD"], [
4322             echo "$2" | fold -s -w$fold_width |
4323             sed '1!s/^/                          /;$!s/$/\\/'
4324         ], [echo "$2"])
4325     ])]
4328 AS_IF([test $install_doc = yes],
4329     [DOCTARGETS=`echo " $RDOCTARGET $CAPITARGET " | sed 's/ nodoc //g;s/^ *//;s/ *$//'`],
4330     [DOCTARGETS=no])
4331 echo "---"
4332 echo "Configuration summary for $RUBY_BASE_NAME version $MAJOR.$MINOR.$TEENY"
4333 echo ""
4334 config_summary "Installation prefix" "$prefix"
4335 config_summary "exec prefix"         "$exec_prefix"
4336 config_summary "arch"                "$arch"
4337 config_summary "site arch"           "$sitearch"
4338 config_summary "RUBY_BASE_NAME"      "$RUBY_BASE_NAME"
4339 config_summary "enable shared"       "$enable_shared"
4340 config_summary "ruby lib prefix"     "$rubylibprefix"
4341 config_summary "site libraries path" "$rubysitearchprefix"
4342 config_summary "vendor path"         "$vendordir"
4343 config_summary "target OS"           "$target_os"
4344 config_summary "compiler"            "$CC"
4345 config_summary "with pthread"        "$enable_pthread"
4346 config_summary "with coroutine"      "$coroutine_type"
4347 config_summary "enable shared libs"  "$ENABLE_SHARED"
4348 config_summary "dynamic library ext" "$DLEXT"
4349 config_summary "CFLAGS"              "$cflags"
4350 config_summary "CPPFLAGS"            "$cppflags"
4351 config_summary "LDFLAGS"             "$LDFLAGS"
4352 config_summary "DLDFLAGS"            "$DLDFLAGS"
4353 config_summary "optflags"            "$optflags"
4354 config_summary "debugflags"          "$debugflags"
4355 config_summary "warnflags"           "$warnflags"
4356 config_summary "strip command"       "$STRIP"
4357 config_summary "install doc"         "$DOCTARGETS"
4358 config_summary "JIT support"         "$MJIT_SUPPORT"
4359 config_summary "man page type"       "$MANTYPE"
4360 config_summary "search path"         "$search_path"
4361 config_summary "static-linked-ext"   ${EXTSTATIC:+"yes"}
4362 config_summary "BASERUBY -v"         "$BASERUBY_VERSION"
4363 echo ""
4364 echo "---"