Improve static checking when using upcoming GCC 13.3
[emacs.git] / configure.ac
blob69a8ba0a9f8f758de2c5bc30193f654c85ced22f
1 dnl  Autoconf script for GNU Emacs
2 dnl To rebuild the 'configure' script from this, execute the command
3 dnl     autoconf
4 dnl in the directory containing this script.
5 dnl If you changed any AC_DEFINES, also run autoheader.
6 dnl
7 dnl Copyright (C) 1994-1996, 1999-2024 Free Software Foundation, Inc.
8 dnl
9 dnl  This file is part of GNU Emacs.
10 dnl
11 dnl  GNU Emacs is free software: you can redistribute it and/or modify
12 dnl  it under the terms of the GNU General Public License as published by
13 dnl  the Free Software Foundation, either version 3 of the License, or
14 dnl  (at your option) any later version.
15 dnl
16 dnl  GNU Emacs is distributed in the hope that it will be useful,
17 dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
18 dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 dnl  GNU General Public License for more details.
20 dnl
21 dnl  You should have received a copy of the GNU General Public License
22 dnl  along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
24 AC_PREREQ([2.65])
25 dnl Note this is parsed by (at least) make-dist and lisp/cedet/ede/emacs.el.
26 AC_INIT([GNU Emacs], [30.0.50], [bug-gnu-emacs@gnu.org], [],
27   [https://www.gnu.org/software/emacs/])
29 if test "$XCONFIGURE" = "android"; then
30   # configure is being called recursively to configure Emacs for
31   # Android!
32   AC_MSG_NOTICE([called to recursively configure Emacs for Android.])
33   # Set CC to ANDROID_CC and CFLAGS to ANDROID_CFLAGS.
34   CC=$ANDROID_CC
35   # Set -Wno-implicit-function-declaration.  Building Emacs for older
36   # versions of Android requires configure tests to fail if the
37   # functions are not defined, as the Android library in the NDK
38   # defines subroutines that are not available in the headers being
39   # used.
40   CFLAGS="$ANDROID_CFLAGS -Werror=implicit-function-declaration"
41   # Don't explicitly enable support for large files unless Emacs is
42   # being built for API 21 or later.  Otherwise, mmap does not work.
43   #
44   # Moreover, 64-bit variants of file IO functions in the C library are
45   # liable to fail with ENOSYS or EINVAL on earlier API versions, and as
46   # such their definitions must be explicitly disabled on NDK releases
47   # that enable them by default.
48   AS_IF([test "$ANDROID_SDK" -lt "21"], [
49     CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=32"
50     enable_largefile=no
51     enable_year2038=no])
54 dnl Set emacs_config_options to the options of 'configure', quoted for the shell,
55 dnl and then quoted again for a C string.  Separate options with spaces.
56 dnl Add some environment variables, if they were passed via the environment
57 dnl rather than on the command-line.
58 emacs_config_options=
59 optsep=
60 dnl This is the documented way to record the args passed to configure,
61 dnl rather than $ac_configure_args.
62 for opt in "$@" CFLAGS CPPFLAGS LDFLAGS; do
63   case $opt in
64     -n | --no-create | --no-recursion)
65       continue ;;
66     CFLAGS | CPPFLAGS | LDFLAGS)
67       eval 'test "${'$opt'+set}" = set' || continue
68       case " $*" in
69         *" $opt="*) continue ;;
70       esac
71       eval opt=$opt=\$$opt ;;
72   esac
74   emacs_shell_specials=$IFS\''"#$&()*;<>?@<:@\\`{|~'
75   case $opt in
76     *[["$emacs_shell_specials"]]*)
77       case $opt in
78         *\'*)
79           emacs_quote_apostrophes="s/'/'\\\\''/g"
80           opt=`AS_ECHO(["$opt"]) | sed "$emacs_quote_apostrophes"` ;;
81       esac
82       opt="'$opt'"
83       case $opt in
84         *[['"\\']]*)
85           emacs_quote_for_c='s/[["\\]]/\\&/g; $!s/$/\\n\\/'
86           opt=`AS_ECHO(["$opt"]) | sed "$emacs_quote_for_c"` ;;
87       esac ;;
88   esac
89   AS_VAR_APPEND([emacs_config_options], ["$optsep$opt"])
90   optsep=' '
91 done
93 AC_CONFIG_HEADERS([src/config.h:src/config.in])
94 AC_CONFIG_SRCDIR([src/lisp.h])
95 AC_CONFIG_AUX_DIR([build-aux])
96 AC_CONFIG_MACRO_DIR([m4])
98 xcsdkdir=
99 AC_CHECK_PROGS([XCRUN], [xcrun])
100 if test -n "$XCRUN"; then
101   if test -z "$MAKE"; then
102     dnl Call the variable MAKE_PROG, not MAKE, to avoid confusion with
103     dnl the usual MAKE variable that 'make' itself uses.
104     AC_CHECK_PROG([MAKE_PROG], [make], [yes])
105     if test -z "$MAKE_PROG"; then
106       MAKE="$XCRUN MAKE"
107       export MAKE
108       xcsdkdir=`$XCRUN --show-sdk-path 2>/dev/null`
109     fi
110   fi
113 dnl Check for GNU Make and possibly set MAKE.
114 [emacs_check_gnu_make ()
116   emacs_makeout=`($1 --version) 2>/dev/null` &&
117   case $emacs_makeout in
118     'GNU Make '3.8[1-9]* | 'GNU Make '3.9[0-9]* | \
119     'GNU Make '3.[1-9][0-9][0-9]* | 'GNU Make '[4-9]* | 'GNU Make '[1-9][0-9]* )
120        ac_path_MAKE_found=:;;
121   esac
123 AC_CACHE_CHECK([for GNU Make], [ac_cv_path_MAKE],
124   [ac_path_MAKE_found=false
125    if test -n "$MAKE"; then
126      emacs_check_gnu_make "$MAKE"
127      ac_cv_path_MAKE=$MAKE
128    else
129      emacs_tried_make=false
130      emacs_tried_gmake=false
131      emacs_tried_gnumake=false
132      AC_PATH_PROGS_FEATURE_CHECK([MAKE], [make gmake gnumake],
133        [[emacs_check_gnu_make "$ac_path_MAKE"
134          if $ac_path_MAKE_found; then
135            # Use the fully-qualified program name only if the basename
136            # would not resolve to it.
137            if eval \$emacs_tried_$ac_prog; then
138              ac_cv_path_MAKE=$ac_path_MAKE
139            else
140              ac_cv_path_MAKE=$ac_prog
141            fi
142          fi
143          eval emacs_tried_$ac_prog=:]])
144    fi])
145 $ac_path_MAKE_found || {
146 AC_MSG_ERROR([[Building Emacs requires GNU Make, at least version 3.81.
147 If you have it installed under another name, configure with 'MAKE=...'.
148 For example, run '$0 MAKE=gnu-make'.]])
150 MAKE=$ac_cv_path_MAKE
151 export MAKE
153 dnl Canonicalize the configuration name.
154 if test "$XCONFIGURE" = "android"; then
155   dnl Set host to whatever Android system Emacs is being configured
156   dnl for.  Determine this by looking at the output of ANDROID_CC.
158   AC_MSG_CHECKING([the cross-compiler's target])
159   cc_target=`${CC} -v 2>&1 | sed -n 's/Target: //p'`
160   case "$cc_target" in
161     *android*) host_alias=$cc_target
162     ;;
163     *) AC_MSG_ERROR([The cross compiler does not compile for Android.
164 Please verify that you specified the correct compiler in the ANDROID_CC
165 variable when you ran configure.])
166     ;;
167   esac
168   AC_MSG_RESULT([$host_alias])
171 AC_CANONICAL_HOST
172 AC_CANONICAL_BUILD
174 AS_IF([test "$XCONFIGURE" = "android"],[
175   # Initialize the Android NDK build system.  Make sure to use the
176   # passed through NDK path.
177   # Make sure to pass through the CFLAGS, as older versions of the
178   # NDK require them to be able to find system includes.
179   with_ndk_path="$android_ndk_path"
180   with_ndk_cxx="$android_ndk_cxx"
181   ndk_INIT([$android_abi], [$ANDROID_SDK], [cross/ndk-build],
182            [$ANDROID_CFLAGS])
184   # At the same time, configure libexec with the build directory
185   # set to `exec'.
186   AS_MKDIR_P([exec])
188   # Enter exec and configure it, using the C compiler as both the
189   # assembler and the linker.  Determine the absolute name of the
190   # source directory.
191   # N.B. that the linker is actually cc, so pass -nostdlib, lest
192   # the crt be linked in.  Likewise for as.
194   AS_CASE([$srcdir], [.], [emacs_srcdir=`pwd`],
195     [[[\\/]* | ?:[\\/]*]], [emacs_srcdir=$srcdir],
196     [*], [emacs_srcdir=`pwd`/$srcdir])
198   AC_MSG_NOTICE([configuring in `exec'])
200   OLDCWD=`pwd`
201   cd exec
202   $CONFIG_SHELL $emacs_srcdir/exec/configure            \
203                 --host=$host "CC=$CC" "LD=$CC" "AS=$CC" \
204                 "AR=$AR" "CFLAGS=$CFLAGS"
205   emacs_val=$?
206   cd $OLDCWD
208   AS_IF([test "$emacs_val" != "0"],
209     [AC_MSG_ERROR([failed to configure in `exec'])])
212 case $host in
213  *-mingw*)
215   if test -z "$host_alias"; then
217       # No --host argument was given to 'configure'; therefore $host
218       # was set to a default value based on the build platform.  But
219       # this default value may be wrong if we are building from a
220       # 64-bit MSYS[2] pre-configured to build 32-bit MinGW programs.
221       # Therefore, we'll try to get the right host platform from the
222       # compiler's target.
224       AC_MSG_CHECKING([the compiler's target])
225       if test -z "$CC"; then
226           cc=gcc
227       else
228           cc=$CC
229       fi
230       cc_target=`$cc -v 2>&1 | sed -n 's/Target: //p'`
231       case "$cc_target" in
232           *-*) host=$cc_target
233               ;;
234           "") AC_MSG_ERROR([Impossible to obtain $cc compiler target.
235 Please explicitly provide --host.])
236               ;;
237           *) AC_MSG_WARN([Compiler reported non-standard target.
238 Defaulting to $host.])
239               ;;
240       esac
241       AC_MSG_RESULT([$host])
242   fi
244   . $srcdir/nt/mingw-cfg.site
246   case $srcdir in
247     /* | ?:*)
248       # srcdir is an absolute path.  In this case, force the format
249       # "/c/foo/bar", to simplify later conversions to native Windows
250       # format ("c:/foo/bar").
251       srcdir=`cd "${srcdir}" && pwd -W`
252       # 'eval' pacifies strict POSIX non-MinGW shells (Bug#18612).
253       # We downcase the drive letter to avoid warnings when
254       # generating autoloads.
255       eval 'srcdir=/`echo ${srcdir:0:1} | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"`"${srcdir:2}"'
256       ;;
257   esac;;
258 esac
260 canonical=$host
261 configuration=${host_alias-${build_alias-$host}}
262 emacs_uname_r=`uname -r`
264 dnl Support for --program-prefix, --program-suffix and
265 dnl --program-transform-name options
266 AC_ARG_PROGRAM
268 dnl It is important that variables on the RHS not be expanded here,
269 dnl hence the single quotes.  This is per the GNU coding standards, see
270 dnl (autoconf) Installation Directory Variables
271 dnl See also epaths.h below.
272 lispdirrel='${version}/lisp'
273 lispdir='${datadir}/emacs/'${lispdirrel}
274 standardlisppath='${lispdir}'
275 locallisppath='${datadir}/emacs/${version}/site-lisp:'\
276 '${datadir}/emacs/site-lisp'
277 lisppath='${locallisppath}:${standardlisppath}'
278 etcdir='${datadir}/emacs/${version}/etc'
279 archlibdir='${libexecdir}/emacs/${version}/${configuration}'
280 etcdocdir='${datadir}/emacs/${version}/etc'
281 gamedir='${localstatedir}/games/emacs'
283 dnl Special option to disable the most of other options.
284 AC_ARG_WITH([all],
285 [AS_HELP_STRING([--without-all],
286                 [omit almost all features and build
287                 small executable with minimal dependencies])],
288   [with_features=$withval],
289   [with_features=yes])
291 dnl ARCH_INDEPENDENT_CONFIG_FILES(FILE...)
292 dnl Like AC_CONFIG_FILES(FILE).  However, do not generate this
293 dnl   if configure is being called recursively in preparation
294 dnl   for cross-compilation.
295 AC_DEFUN([ARCH_INDEPENDENT_CONFIG_FILES], [
296   AS_IF([test "$XCONFIGURE" != "android"], [AC_CONFIG_FILES([$1])])])
298 dnl OPTION_DEFAULT_OFF(NAME, HELP-STRING)
299 dnl Create a new --with option that defaults to being disabled.
300 dnl NAME is the base name of the option.  The shell variable with_NAME
301 dnl   will be set to either the user's value (if the option is
302 dnl   specified; 'yes' for a plain --with-NAME) or to 'no' (if the
303 dnl   option is not specified).  Note that the shell variable name is
304 dnl   constructed as autoconf does, by replacing non-alphanumeric
305 dnl   characters with "_".
306 dnl HELP-STRING is the help text for the option.
307 AC_DEFUN([OPTION_DEFAULT_OFF], [dnl
308   AC_ARG_WITH([$1],[AS_HELP_STRING([--with-$1],[$2])],[],[dnl
309     m4_bpatsubst([with_$1], [[^0-9a-z]], [_])=no])dnl
310 ])dnl
312 dnl OPTION_DEFAULT_IFAVAILABLE(NAME, HELP-STRING)
313 dnl Create a new --with option that defaults to 'ifavailable',
314 dnl unless it is overridden by $with_features being equal to 'no'.
315 dnl NAME is the base name of the option.  The shell variable with_NAME
316 dnl   will be set to either the user's value (if the option is
317 dnl   specified; 'yes' for a plain --with-NAME) or to 'ifavailable' (if the
318 dnl   option is not specified).  Note that the shell variable name is
319 dnl   constructed as autoconf does, by replacing non-alphanumeric
320 dnl   characters with "_".
321 dnl HELP-STRING is the help text for the option.
322 AC_DEFUN([OPTION_DEFAULT_IFAVAILABLE], [dnl
323   AC_ARG_WITH([$1],[AS_HELP_STRING([--with-$1],[$2])],[],[dnl
324     AS_IF([test "$with_features" != no],
325       [m4_bpatsubst([with_$1], [[^0-9a-z]], [_])=ifavailable],
326       [m4_bpatsubst([with_$1], [[^0-9a-z]], [_])=no])dnl
327   ])dnl
328 ])dnl
330 dnl OPTION_DEFAULT_ON(NAME, HELP-STRING)
331 dnl Create a new --with option that defaults to $with_features.
332 dnl NAME is the base name of the option.  The shell variable with_NAME
333 dnl   will be set either to 'no' (for a plain --without-NAME) or to
334 dnl   'yes' (if the option is not specified).  Note that the shell
335 dnl   variable name is constructed as autoconf does, by replacing
336 dnl   non-alphanumeric characters with "_".
337 dnl HELP-STRING is the help text for the option.
338 AC_DEFUN([OPTION_DEFAULT_ON], [dnl
339   AC_ARG_WITH([$1],[AS_HELP_STRING([--without-$1],[$2])],[],[dnl
340    m4_bpatsubst([with_$1], [[^0-9a-z]], [_])=$with_features])dnl
341 ])dnl
343 # For retrieving mail, unencrypted network connections are the default
344 # only on native MS-Windows platforms.  (FIXME: These platforms should
345 # also be secure by default.)
347 AC_ARG_WITH([mailutils],
348   [AS_HELP_STRING([--with-mailutils],
349      [rely on GNU Mailutils, so that the --without-pop through --with-mailhost
350       options are irrelevant; this is the default if GNU Mailutils is
351       installed])],
352   [],
353   [AS_IF([test "$with_features" != "no"],
354    [with_mailutils=yes-unless-android
355     AS_IF([test "x$XCONFIGURE" != "xandroid"],
356      [(movemail --version) >/dev/null 2>&1 || with_mailutils=no],
357      [dnl Don't check for movemail if cross-compiling.
358       dnl instead, default to false.
359       with_mailutils=no])])])
361 AC_ARG_WITH([pop],
362   [AS_HELP_STRING([--with-pop],
363      [Support POP mail retrieval if Emacs movemail is used (not recommended,
364       as Emacs movemail POP is insecure).  This is the default only on
365       native MS-Windows and Android.])],
366   [],
367   dnl Enable movemail POP support on Android as GNU Mailutils is
368   dnl normally unavailable on that platform.
369   [AS_CASE([$host],
370      [*-mingw*|*android*], [with_pop=yes],
371      [with_pop=no-by-default])])
372 if test "$with_pop" = yes; then
373    AC_DEFINE([MAIL_USE_POP])
375 AH_TEMPLATE([MAIL_USE_POP], [Define to support POP mail retrieval.])dnl
377 OPTION_DEFAULT_OFF([kerberos],[support Kerberos-authenticated POP])
378 if test "$with_kerberos" != no; then
379    AC_DEFINE([KERBEROS])
381 AH_TEMPLATE([KERBEROS],
382             [Define to support Kerberos-authenticated POP mail retrieval.])dnl
384 OPTION_DEFAULT_OFF([kerberos5],[support Kerberos version 5 authenticated POP])
385 if test "${with_kerberos5}" != no; then
386   if test "${with_kerberos}" = no; then
387     with_kerberos=yes
388     AC_DEFINE([KERBEROS])
389   fi
390   AC_DEFINE([KERBEROS5], [1],
391     [Define to use Kerberos 5 instead of Kerberos 4.])
394 OPTION_DEFAULT_OFF([hesiod],[support Hesiod to get the POP server host])
395 dnl FIXME hesiod support may not be present, so it seems like an error
396 dnl to define, or at least use, this unconditionally.
397 if test "$with_hesiod" != no; then
398   AC_DEFINE([HESIOD], [1],
399     [Define to support using a Hesiod database to find the POP server.])
402 OPTION_DEFAULT_OFF([mail-unlink],[unlink, rather than empty, mail spool after reading])
403 if test "$with_mail_unlink" != no; then
404    AC_DEFINE([MAIL_UNLINK_SPOOL], [1],
405      [Define to unlink, rather than empty, mail spool after reading.])
408 AC_ARG_WITH([mailhost],[AS_HELP_STRING([--with-mailhost=HOSTNAME],
409     [string giving default POP mail host])],
410     AC_DEFINE_UNQUOTED([MAILHOST], ["$withval"],
411       [String giving fallback POP mail host.]))
413 AC_ARG_WITH([sound],[AS_HELP_STRING([--with-sound=VALUE],
414   [compile with sound support (VALUE one of: yes, alsa, oss, bsd-ossaudio, no;
415 default yes).  Only for GNU/Linux, FreeBSD, NetBSD, MinGW, Cygwin.])],
416   [ case "${withval}" in
417       yes|no|alsa|oss|bsd-ossaudio) val=$withval ;;
418       *) AC_MSG_ERROR(['--with-sound=$withval' is invalid;
419 this option's value should be 'yes', 'no', 'alsa', 'oss', or 'bsd-ossaudio'.])
420       ;;
421     esac
422     with_sound=$val
423   ],
424   [with_sound=$with_features])
426 AC_ARG_WITH([pdumper],
427   AS_HELP_STRING(
428     [--with-pdumper=VALUE],
429     [enable pdumper support unconditionally
430       ('yes', 'no', or 'auto': default 'auto')]),
431     [ case "${withval}" in
432         yes|no|auto) val=$withval ;;
433         *) AC_MSG_ERROR(
434            ['--with-pdumper=$withval' is invalid;
435 this option's value should be 'yes' or 'no'.]) ;;
436       esac
437       with_pdumper=$val
438     ],
439     [with_pdumper=auto])
441 AC_ARG_WITH([unexec],
442   AS_HELP_STRING(
443     [--with-unexec=VALUE],
444     [enable unexec support unconditionally
445       ('yes', 'no', or 'auto': default 'auto')]),
446     [ case "${withval}" in
447         yes|no|auto) val=$withval ;;
448         *) AC_MSG_ERROR(
449            ['--with-unexec=$withval' is invalid;
450 this option's value should be 'yes' or 'no'.]) ;;
451       esac
452       with_unexec=$val
453     ],
454     [with_unexec=auto])
456 AC_ARG_WITH([dumping],[AS_HELP_STRING([--with-dumping=VALUE],
457     [kind of dumping to use for initial Emacs build
458 (VALUE one of: pdumper, unexec, none; default pdumper)])],
459     [ case "${withval}" in
460         pdumper|unexec|none) val=$withval ;;
461         *) AC_MSG_ERROR(['--with-dumping=$withval is invalid;
462 this option's value should be 'pdumper', 'unexec', or 'none'.])
463         ;;
464       esac
465       with_dumping=$val
466     ],
467     [with_dumping=pdumper])
469 if test "$with_pdumper" = "auto"; then
470   if test "$with_dumping" = "pdumper"; then
471     with_pdumper=yes
472   else
473     with_pdumper=no
474   fi
477 if test "$with_unexec" = "auto"; then
478   if test "$with_dumping" = "unexec"; then
479     with_unexec=yes
480   else
481     with_unexec=no
482   fi
485 if test "$with_dumping" = "pdumper" && test "$with_pdumper" = "no"; then
486   AC_MSG_ERROR(['--with-dumping=pdumper' requires pdumper support])
489 if test "$with_dumping" = "unexec" && test "$with_unexec" = "no"; then
490   AC_MSG_ERROR(['--with-dumping=unexec' requires unexec support])
493 if test "$with_pdumper" = "yes"; then
494   AC_DEFINE([HAVE_PDUMPER], [1],
495     [Define to build with portable dumper support])
496   HAVE_PDUMPER=yes
497 else
498   HAVE_PDUMPER=no
500 AC_SUBST([HAVE_PDUMPER])
502 DUMPING=$with_dumping
503 AC_SUBST([DUMPING])
505 dnl FIXME currently it is not the last.
506 dnl This should be the last --with option, because --with-x is
507 dnl added later on when we find the file name of X, and it's best to
508 dnl keep them together visually.
509 AC_ARG_WITH([x-toolkit],[AS_HELP_STRING([--with-x-toolkit=KIT],
510  [use an X toolkit (KIT one of: yes or gtk, gtk2, gtk3, lucid or athena, motif, no)])],
511 [         case "${withval}" in
512             y | ye | yes )      val=gtk ;;
513             n | no )            val=no  ;;
514             l | lu | luc | luci | lucid )       val=lucid ;;
515             a | at | ath | athe | athen | athena )      val=athena ;;
516             m | mo | mot | moti | motif )       val=motif ;;
517             g | gt | gtk  )     val=gtk ;;
518             gtk2  )     val=gtk2 ;;
519             gtk3  )     val=gtk3 ;;
520             * )
521 AC_MSG_ERROR(['--with-x-toolkit=$withval' is invalid;
522 this option's value should be 'yes', 'no', 'lucid', 'athena', 'motif', 'gtk',
523 'gtk2' or 'gtk3'.  'yes' and 'gtk' are synonyms.
524 'athena' and 'lucid' are synonyms.])
525             ;;
526           esac
527           with_x_toolkit=$val
530 OPTION_DEFAULT_OFF([wide-int],
531   [prefer wide Emacs integers (typically 62-bit);
532    on 32-bit hosts, this allows buffer and string size up to 2GB,
533    at the cost of 10% to 30% slowdown of Lisp interpreter
534    and larger memory footprint])
535 if test "$with_wide_int" = yes; then
536   AC_DEFINE([WIDE_EMACS_INT], [1], [Use long long for EMACS_INT if available.])
539 dnl _ON results in a '--without' option in the --help output, so
540 dnl the help text should refer to "don't compile", etc.
541 with_xpm_set=${with_xpm+set}
542 OPTION_DEFAULT_ON([xpm],[don't compile with XPM image support])
543 OPTION_DEFAULT_ON([jpeg],[don't compile with JPEG image support])
544 OPTION_DEFAULT_ON([tiff],[don't compile with TIFF image support])
545 OPTION_DEFAULT_ON([gif],[don't compile with GIF image support])
546 OPTION_DEFAULT_ON([png],[don't compile with PNG image support])
547 OPTION_DEFAULT_ON([rsvg],[don't compile with SVG image support])
548 OPTION_DEFAULT_ON([webp],[don't compile with WebP image support])
549 OPTION_DEFAULT_ON([sqlite3],[don't compile with sqlite3 support])
550 OPTION_DEFAULT_ON([lcms2],[don't compile with Little CMS support])
551 OPTION_DEFAULT_ON([libsystemd],[don't compile with libsystemd support])
552 OPTION_DEFAULT_ON([cairo],[don't compile with Cairo drawing])
553 OPTION_DEFAULT_OFF([cairo-xcb], [use XCB surfaces for Cairo support])
554 OPTION_DEFAULT_ON([xml2],[don't compile with XML parsing support])
555 OPTION_DEFAULT_OFF([imagemagick],[compile with ImageMagick image support])
556 OPTION_DEFAULT_ON([native-image-api], [don't use native image APIs (GDI+ on Windows)])
557 OPTION_DEFAULT_IFAVAILABLE([tree-sitter], [compile with tree-sitter])
559 OPTION_DEFAULT_ON([xft],[don't use XFT for anti aliased fonts])
560 OPTION_DEFAULT_ON([harfbuzz],[don't use HarfBuzz for text shaping])
561 OPTION_DEFAULT_ON([libotf],[don't use libotf for OpenType font support])
562 OPTION_DEFAULT_ON([m17n-flt],[don't use m17n-flt for text shaping])
564 OPTION_DEFAULT_ON([toolkit-scroll-bars],[don't use Motif/Xaw3d/GTK toolkit scroll bars])
565 OPTION_DEFAULT_ON([xaw3d],[don't use Xaw3d])
566 OPTION_DEFAULT_ON([xim],[at runtime, default X11 XIM to off])
567 OPTION_DEFAULT_ON([xdbe],[don't use X11 double buffering support])
568 AC_ARG_WITH([ns],[AS_HELP_STRING([--with-ns],
569 [use Nextstep (macOS Cocoa or GNUstep) windowing system.
570 On by default on macOS.])],[],[with_ns=maybe])
571 OPTION_DEFAULT_OFF([w32], [use native MS Windows GUI in a Cygwin build])
572 OPTION_DEFAULT_OFF([pgtk], [use GTK to support window systems other than X])
574 OPTION_DEFAULT_ON([gpm],[don't use -lgpm for mouse support on a GNU/Linux console])
575 OPTION_DEFAULT_ON([dbus],[don't compile with D-Bus support])
576 AC_ARG_WITH([gconf],[AS_HELP_STRING([--with-gconf],
577 [compile with Gconf support (Gsettings replaces this)])],[],
578 [if test $with_features = yes; then
579 with_gconf=maybe
580 else
581 with_gconf=no
582 fi])
583 OPTION_DEFAULT_ON([gsettings],[don't compile with GSettings support])
584 OPTION_DEFAULT_ON([selinux],[don't compile with SELinux support])
585 OPTION_DEFAULT_ON([gnutls],[don't use -lgnutls for SSL/TLS support])
586 OPTION_DEFAULT_ON([zlib],[don't compile with zlib decompression support])
587 OPTION_DEFAULT_ON([modules],[don't compile with dynamic modules support])
588 OPTION_DEFAULT_ON([threads],[don't compile with elisp threading support])
589 OPTION_DEFAULT_OFF([cygwin32-native-compilation],[use native compilation on 32-bit Cygwin])
590 OPTION_DEFAULT_ON([xinput2],[don't use version 2 of the X Input Extension for input])
591 OPTION_DEFAULT_OFF([small-ja-dic],[generate a smaller-size Japanese dictionary])
592 OPTION_DEFAULT_OFF([android],[cross-compile Android application package])
593 OPTION_DEFAULT_ON([android-debug],[don't build Emacs as a debug package on Android])
595 # Find out of Android support is enabled and mailutils has defaulted
596 # to `yes-unless-android'.  Disable it if so.
598 AS_IF([test "x$with_mailutils" = "xyes-unless-android"],
599   [AS_IF([test "x$with_android" != "xno"],
600      [with_mailutils=no],
601      [with_mailutils=yes])])
603 # Clear with_mailutils if it's set to no.
605 AS_IF([test "$with_mailutils" = no],
606   [with_mailutils=])
608 AS_IF([test x"$with_mailutils" = xyes],
609   [AC_DEFINE([HAVE_MAILUTILS], [1],
610      [Define to 1 if Emacs was configured with mailutils])])
612 AC_SUBST([with_mailutils])
614 AC_ARG_WITH([shared-user-id],
615   [AS_HELP_STRING([--with-shared-user-id=ID],
616     [use the given shared user ID in Android builds])])
618 AC_ARG_WITH([file-notification],[AS_HELP_STRING([--with-file-notification=LIB],
619  [use a file notification library (LIB one of: yes, inotify, kqueue, gfile, w32, no)])],
620  [ case "${withval}" in
621     y | ye | yes )      val=yes ;;
622     n | no )            val=no  ;;
623     i | in | ino | inot | inoti | inotif | inotify )    val=inotify ;;
624     k | kq | kqu | kque | kqueu | kqueue )      val=kqueue ;;
625     g | gf | gfi | gfil | gfile )       val=gfile ;;
626     w | w3 | w32 )      val=w32 ;;
627     * ) AC_MSG_ERROR(['--with-file-notification=$withval' is invalid;
628 this option's value should be 'yes', 'no', 'inotify', 'kqueue', 'gfile' or 'w32'.
629 'yes' is a synonym for 'w32' on MS-Windows, for 'no' on Nextstep,
630 otherwise for the first of 'inotify', 'kqueue' or 'gfile' that is usable.])
631     ;;
632    esac
633    with_file_notification=$val
634  ],
635  [with_file_notification=$with_features])
637 OPTION_DEFAULT_OFF([xwidgets],
638   [enable use of xwidgets in Emacs buffers (requires gtk3 or macOS Cocoa)])
640 OPTION_DEFAULT_OFF([be-app],
641   [enable use of Haiku's Application Kit as a window system])
643 OPTION_DEFAULT_OFF([be-cairo],
644   [enable use of cairo under Haiku's Application Kit])
646 ## Makefile.in needs the cache file name.
647 AC_SUBST([cache_file])
649 ## This is an option because I do not know if all info/man support
650 ## compressed files, nor how to test if they do so.
651 OPTION_DEFAULT_ON([compress-install],
652   [don't compress some files (.el, .info, etc.) when installing.  Equivalent to:
653 make GZIP_PROG= install])
655 AC_ARG_WITH([gameuser],
656 [AS_HELP_STRING([--with-gameuser=USER_OR_GROUP],
657                 [user for shared game score files.
658                 An argument prefixed by ':' specifies a group instead.])])
659 gameuser=
660 gamegroup=
661 case ${with_gameuser} in
662   '' | no) ;;
663   yes) gamegroup=games ;;
664   :*) gamegroup=${with_gameuser#:} ;;
665   *) gameuser=${with_gameuser} ;;
666 esac
668 AC_ARG_WITH([gnustep-conf],
669 [AS_HELP_STRING([--with-gnustep-conf=FILENAME],
670    [name of GNUstep configuration file to use on systems where the command
671     'gnustep-config' does not work; default $GNUSTEP_CONFIG_FILE, or
672     /etc/GNUstep/GNUstep.conf])])
673 test "X${with_gnustep_conf}" != X && test "${with_gnustep_conf}" != yes && \
674   GNUSTEP_CONFIG_FILE="${with_gnustep_conf}"
675 test "X$GNUSTEP_CONFIG_FILE" = "X" && \
676      GNUSTEP_CONFIG_FILE=/etc/GNUstep/GNUstep.conf
678 AC_ARG_ENABLE([ns-self-contained],
679 [AS_HELP_STRING([--disable-ns-self-contained],
680                 [disable self contained build under NeXTstep])],
681    [EN_NS_SELF_CONTAINED=$enableval],
682    [EN_NS_SELF_CONTAINED=yes])
684 locallisppathset=no
685 AC_ARG_ENABLE([locallisppath],
686 [AS_HELP_STRING([--enable-locallisppath=PATH],
687                 [directories Emacs should search for lisp files specific
688                  to this site])],
689 [if test "${enableval}" = "no"; then
690   locallisppath=
691 elif test "${enableval}" != "yes"; then
692   locallisppath=${enableval} locallisppathset=yes
693 fi])
695 AC_ARG_ENABLE([checking],
696 [AS_HELP_STRING([--enable-checking@<:@=LIST@:>@],
697                 [enable expensive checks.  With LIST,
698                  enable only specific categories of checks.
699                  Categories are: all,yes,no.
700                  Flags are: stringbytes, stringoverrun, stringfreelist,
701                  structs, glyphs])],
702 [ac_checking_flags="${enableval}"],[])
703 IFS="${IFS=     }"; ac_save_IFS="$IFS"; IFS="$IFS,"
704 CHECK_STRUCTS=false
705 for check in $ac_checking_flags
707         case $check in
708         # these set all the flags to specific states
709         yes)            ac_enable_checking=1 ;;
710         no)             ac_enable_checking= ;
711                         CHECK_STRUCTS=false
712                         ac_gc_check_stringbytes= ;
713                         ac_gc_check_string_overrun= ;
714                         ac_gc_check_string_free_list= ;
715                         ac_glyphs_debug= ;;
716         all)            ac_enable_checking=1 ;
717                         CHECK_STRUCTS=true
718                         ac_gc_check_stringbytes=1 ;
719                         ac_gc_check_string_overrun=1 ;
720                         ac_gc_check_string_free_list=1 ;
721                         ac_glyphs_debug=1 ;;
722         # these enable particular checks
723         stringbytes)    ac_gc_check_stringbytes=1 ;;
724         stringoverrun)  ac_gc_check_string_overrun=1 ;;
725         stringfreelist) ac_gc_check_string_free_list=1 ;;
726         structs)        CHECK_STRUCTS=true ;;
727         glyphs)         ac_glyphs_debug=1 ;;
728         *)      AC_MSG_ERROR([unknown check category $check]) ;;
729         esac
730 done
731 IFS="$ac_save_IFS"
733 # This environment variable is used to signal that checking should be
734 # enabled on Android.  When that happens, simply enable checking for
735 # the cross-compiled Android binary.
737 AS_IF([test "x$XCONFIGURE" = "xandroid" \
738        && test "x$android_enable_checking" = "xyes"],
739   [ac_enable_checking=yes])
741 # There is little point in enabling checking in the build machine if
742 # cross-compiling for Android.
743 AS_IF([test "$with_android" = no || test -n "$XCONFIGURE"],[
744   if test x$ac_enable_checking != x ; then
745     AC_DEFINE([ENABLE_CHECKING], [1],
746   [Define to 1 if expensive run-time data type and consistency checks are enabled.])
747   fi
748   if $CHECK_STRUCTS; then
749     AC_DEFINE([CHECK_STRUCTS], [1],
750       [Define this to check whether someone updated the portable dumper
751        code after changing the layout of a structure that it uses.
752        If you change one of these structures, check that the pdumper.c
753        code is still valid, and update the pertinent hash in pdumper.c
754        by manually copying the hash from the newly-generated dmpstruct.h.])
755   fi
756   AC_SUBST([CHECK_STRUCTS])
757   if test x$ac_gc_check_stringbytes != x ; then
758     AC_DEFINE([GC_CHECK_STRING_BYTES], [1],
759   [Define this temporarily to hunt a bug.  If defined, the size of
760      strings is redundantly recorded in sdata structures so that it can
761      be compared to the sizes recorded in Lisp strings.])
762   fi
763   if test x$ac_gc_check_string_overrun != x ; then
764     AC_DEFINE([GC_CHECK_STRING_OVERRUN], [1],
765   [Define this to check for short string overrun.])
766   fi
767   if test x$ac_gc_check_string_free_list != x ; then
768     AC_DEFINE([GC_CHECK_STRING_FREE_LIST], [1],
769   [Define this to check the string free list.])
770   fi
771   if test x$ac_glyphs_debug != x ; then
772     AC_DEFINE([GLYPH_DEBUG], [1],
773   [Define this to enable glyphs debugging code.])
774   fi
775 ],[AS_IF([test "x$ac_enable_checking" != x],
776     [android_enable_checking=yes
777      export android_enable_checking])])
779 dnl The name of this option is unfortunate.  It predates, and has no
780 dnl relation to, the "sampling-based elisp profiler" added in 24.3.
781 dnl Actually, it stops it working.
782 dnl https://lists.gnu.org/r/emacs-devel/2012-11/msg00393.html
783 AC_ARG_ENABLE([profiling],
784 [AS_HELP_STRING([--enable-profiling],
785                 [build emacs with low-level, gprof profiling support.
786                 Mainly useful for debugging Emacs itself.  May not work on
787                 all platforms.  Stops profiler.el working.])],
788 [ac_enable_profiling="${enableval}"],[])
789 if test x$ac_enable_profiling != x ; then
790    PROFILING_CFLAGS="-DPROFILING=1 -pg"
791 else
792    PROFILING_CFLAGS=
794 AC_SUBST([PROFILING_CFLAGS])
796 AC_ARG_ENABLE([autodepend],
797 [AS_HELP_STRING([--enable-autodepend],
798                 [automatically generate dependencies to .h-files.
799                  Requires gcc, enabled if found.])],
800 [ac_enable_autodepend="${enableval}"],[ac_enable_autodepend=yes])
802 AC_ARG_ENABLE([gtk-deprecation-warnings],
803 [AS_HELP_STRING([--enable-gtk-deprecation-warnings],
804                 [Show Gtk+/Gdk deprecation warnings for Gtk+ >= 3.0])],
805 [ac_enable_gtk_deprecation_warnings="${enableval}"],[])
807 BUILD_DETAILS=
808 AC_ARG_ENABLE([build-details],
809   [AS_HELP_STRING([--disable-build-details],
810                   [Make the build more deterministic by omitting host
811                    names, time stamps, etc. from the output.])],
812   [test "$enableval" = no && BUILD_DETAILS=--no-build-details])
813 AC_SUBST([BUILD_DETAILS])
815 # JAVA_PUSH_LINT(OPT)
816 # -------------------
817 # Check if javac supports the diagnostic flag -Xlint:OPT.
818 # If it does, add it to WARN_JAVAFLAGS.
820 AC_DEFUN([JAVA_PUSH_LINT],
822   AC_CACHE_CHECK([whether Java compiler accepts -Xlint:$1],
823     [emacs_cv_javac_knows_lint_$1],
824     AS_IF([rm -f conftest.class
825 cat << EOF > conftest.java
827 class conftest
833 ("$JAVAC" -Xlint:$1 conftest.java 2>&AS_MESSAGE_LOG_FD) \
834   && rm -f conftest.class], [emacs_cv_javac_knows_lint_$1=yes],
835      [emacs_cv_javac_knows_lint_$1=no]))
837   AS_IF([test "$emacs_cv_javac_knows_lint_$1" = "yes"],
838     [WARN_JAVAFLAGS="$WARN_JAVAFLAGS -Xlint:$1"])
841 # Start Android configuration.  This is done in three steps:
843 # First, the SDK tools needed to build the Android package on the host
844 # are found.
846 # Then, configure is called inside itself with the NDK C and C++
847 # compilers, and the Makefiles generated, along with config.h, are
848 # renamed to end with .android.
850 # Finally, configure continues to configure the Emacs binary that will
851 # run on the host.
853 ANDROID=
854 JAVAC=
855 AAPT=
856 JARSIGNER=
857 APKSIGNER=
858 ZIPALIGN=
860 ANDROID_JAR=
861 ANDROID_ABI=
862 WARN_JAVAFLAGS=
863 ANDROID_SHARED_USER_ID=
864 ANDROID_SHARED_USER_NAME=
865 IS_D8_R8=
867 # This is a list of Makefiles that have alternative versions for
868 # Android.
869 android_makefiles="lib/Makefile lib/gnulib.mk lib-src/Makefile src/Makefile"
871 # This is whether or not to package mailutils into the executable.
872 emacs_use_mailutils=
874 AC_ARG_VAR([ANDROID_CC], [The Android C cross-compiler.])
875 AC_ARG_VAR([SDK_BUILD_TOOLS], [Name of directory holding Android SDK build-tools.])
876 AC_ARG_VAR([ANDROID_CFLAGS], [Flags given to the Android C cross-compiler.])
877 AC_ARG_VAR([JAVAC], [Java compiler path.  Used for Android.])
878 AC_ARG_VAR([JARSIGNER], [Java package signer path.  Used for Android.])
879 AC_ARG_VAR([APKSIGNER], [Android package signer path.  Used for Android.])
880 AC_ARG_VAR([SDK_BUILD_TOOLS], [Path to the Android SDK build tools.])
882 if test "$with_android" = "yes"; then
883    AC_MSG_ERROR([Please specify the path to the Android.jar file, like so:
885   ./configure --with-android=/path/to/android.jar
887 along with the path to the SDK build-tools (this is the directory with
888 tools such as aapt, dx, and aidl):
890               SDK_BUILD_TOOLS=/path/to/sdk-build-tools
892 The cross-compiler should then be specified:
894               ANDROID_CC=/path/to/armv7a-linux-androideabi19-clang
896 In addition, you may pass any special arguments to the cross-compiler
897 via the ANDROID_CFLAGS environment variable.])
898 elif test "$with_android" = "no" || test "$with_android" = ""; then
899   ANDROID=no
900 else
901   AC_CHECK_PROGS([JAVAC], [javac])
902   if test "$JAVAC" = ""; then
903     AC_MSG_ERROR([The Java compiler required to build Emacs was not found.
904 Please make sure `javac' can be found on your path, or alternatively specify
905 the path to your Java compiler before configuring Emacs, like so:
907   JAVAC=/opt/jdk/bin/javac ./configure --with-android])
908   fi
910   AC_CHECK_PROGS([JARSIGNER], [jarsigner])
911   if test "$JARSIGNER" = ""; then
912     AC_MSG_ERROR([The Java package signing utility was not found.
913 Please make sure `jarsigner' can be found on your path, or alternatively
914 specify its location before configuring Emacs, like so:
916   JARSIGNER=/opt/jdk/bin/jarsigner ./configure --with-android])
917   fi
919   AC_CACHE_CHECK([whether the Java compiler works],
920     [emacs_cv_working_javac],
921     AS_IF([rm -f conftest.class
922 cat << EOF > conftest.java
924 import android.app.Activity;
925 import android.os.Bundle;
927 class conftest extends Activity
929   @Override
930   public void
931   onCreate (Bundle savedInstanceState)
932   {
933     super.onCreate (savedInstanceState);
934   }
938 ("$JAVAC" -classpath "$with_android" -target 1.7 -source 1.7 conftest.java \
939   -d . >&AS_MESSAGE_LOG_FD 2>&1) && test -s conftest.class && rm -f conftest.class],
940           [emacs_cv_working_javac=yes],
941           [emacs_cv_working_javac=no]))
943   if test "$emacs_cv_working_javac" = "no"; then
944     AC_MSG_ERROR([The Java compiler does not work, or you did not specify
945 a valid path to android.jar.  See config.log for more details.])
946   fi
948   AC_CACHE_CHECK([whether android.jar is new enough],
949     [emacs_cv_android_u_or_later],
950     AS_IF([rm -f conftest.class
951 cat << EOF > conftest.java
953 import android.os.Build;
955 class conftest
957   private static int test = Build.VERSION_CODES.UPSIDE_DOWN_CAKE;
961 ("$JAVAC" -classpath "$with_android" -target 1.7 -source 1.7 conftest.java \
962   -d . >&AS_MESSAGE_LOG_FD 2>&1) && test -s conftest.class && rm -f conftest.class],
963           [emacs_cv_android_u_or_later=yes],
964           [emacs_cv_android_u_or_later=no]))
966   if test "$emacs_cv_android_u_or_later" = "no"; then
967     AC_MSG_ERROR([Emacs must be built with an android.jar file produced for \
968 Android 14 (Upside Down Cake) or later.])
969   fi
971   dnl See if the Java compiler supports the `--release' option which
972   dnl makes it check for and prevent using features introduced after
973   dnl Java 1.7.
975   AC_CACHE_CHECK([whether javac accepts --release 7],
976     [emacs_cv_javac_release_7], AS_IF([rm -f conftest.class
977 cat << EOF > conftest.java
979 class conftest
985 ("$JAVAC" --release 7 conftest.java 2>&AS_MESSAGE_LOG_FD) \
986   && rm -f conftest.class],
987       [emacs_cv_javac_release_7=yes],
988       [emacs_cv_javac_release_7=no]))
990   if test "$emacs_cv_javac_release_7" = "yes"; then
991     WARN_JAVAFLAGS="$WARN_JAVAFLAGS --release 7"
992   else
993     dnl If not, just make sure the generated bytecode is correct.
994     WARN_JAVAFLAGS="$WARN_JAVAFLAGS -target 1.7 -source 1.7"
995   fi
997   dnl Enable some useful Java linting options.
998   JAVA_PUSH_LINT([deprecation])
999   JAVA_PUSH_LINT([cast])
1000   JAVA_PUSH_LINT([divzero])
1001   JAVA_PUSH_LINT([nonempty])
1002   JAVA_PUSH_LINT([empty])
1003   JAVA_PUSH_LINT([finally])
1004   JAVA_PUSH_LINT([overrides])
1005   JAVA_PUSH_LINT([path])
1006   JAVA_PUSH_LINT([serial])
1007   JAVA_PUSH_LINT([unchecked])
1009   # Get the name of the android.jar file.
1010   ANDROID_JAR="$with_android"
1012   # Substitute this into java/Makefile.
1013   AC_SUBST([WARN_JAVAFLAGS])
1015   AC_PATH_PROGS([AAPT], [aapt], [], "${SDK_BUILD_TOOLS}:$PATH")
1016   if test "$AAPT" = ""; then
1017     AC_MSG_ERROR([The Android asset packaging tool was not found.
1018 Please verify that the path to the SDK build tools you specified is correct])
1019   fi
1021   AC_PATH_PROGS([APKSIGNER], [apksigner], [], "${SDK_BUILD_TOOLS}:$PATH")
1022   if test "$APKSIGNER" = ""; then
1023     AC_MSG_ERROR([The Android package signing tool was not found.
1024 Please verify that the path to the SDK build tools you specified is correct])
1025   fi
1027   AC_PATH_PROGS([D8], [d8], [], "${SDK_BUILD_TOOLS}:$PATH")
1028   if test "D8" = ""; then
1029     AC_MSG_ERROR([The Android dexer was not found.
1030 Please verify that the path to the SDK build tools you specified is correct])
1031   fi
1033   # Locate any d8.jar within the SDK build tools directory.  The R8
1034   # optimizing compiler is also present in this bundle, and it generates
1035   # far superior code.
1036   emacs_val=`which $D8`
1037   emacs_val=`AS_DIRNAME([$emacs_val])`/lib/d8.jar
1038   AS_IF([test -f "$emacs_val"],
1039     [AC_CACHE_CHECK([whether d8.jar coresident with d8 binary provides r8],
1040        [emacs_cv_d8_provides_r8],
1041        [AS_IF([java -cp "$emacs_val" com.android.tools.r8.R8 --help &>/dev/null],
1042          [emacs_cv_d8_provides_r8=yes], [emacs_cv_d8_provides_r8=no])])])
1043   AS_IF([test "$emacs_cv_d8_provides_r8" = "yes"],
1044     # And substitute it for D8 if present.
1045     [D8="java -cp $emacs_val com.android.tools.r8.R8"
1046      IS_D8_R8=yes])
1048   AC_PATH_PROGS([ZIPALIGN], [zipalign], [], "${SDK_BUILD_TOOLS}:$PATH")
1049   if test "ZIPALIGN" = ""; then
1050     AC_MSG_ERROR([The Android ZIP archive alignment utility was not found.
1051 Please verify that the path to the SDK build tools you specified is correct]);
1052   fi
1054   dnl Now configure Emacs to generate binaries for Android.  After the
1055   dnl configuration completes, move the generated Makefiles.
1057   if test "$ANDROID_CC" = ""; then
1058     AC_MSG_ERROR([Please specify the path to the Android cross-compiler
1059 for your machine.  For example:
1061   ANDROID_CC=/path/to/armv7a-linux-androideabi19-clang    \\
1062     ./configure --with-android])
1063   fi
1065   dnl Obtain the cross compiler's target to find out where binaries go
1066   dnl in the resulting package.
1068   AC_MSG_CHECKING([for the kind of Android system Emacs is being built for])
1069   cc_target=`${ANDROID_CC} -v 2>&1 | sed -n 's/Target: //p'`
1070   case "$cc_target" in
1072     *i[3-6]86*) android_abi=x86
1073       ;;
1074     *x86_64*) android_abi=x86_64
1075       ;;
1076     *aarch64*) android_abi=arm64-v8a
1077       ;;
1078     *arm*v7a*) android_abi=armeabi-v7a
1079       ;;
1080     *mips64*) android_abi=mips64
1081       ;;
1082     *mips*) android_abi=mips
1083       ;;
1084     *arm*) android_abi=armeabi
1085       ;;
1087     *) AC_MSG_ERROR([configure could not determine the type of Android \
1088 binary Emacs is being configured for.  Please port this configure script \
1089 to your Android system, or verify that you specified the correct compiler \
1090 in the ANDROID_CC variable when you ran configure.
1092 The compiler target is: $cc_target])
1093       ;;
1094   esac
1095   AC_MSG_RESULT([$android_abi])
1097   ANDROID_ABI=$android_abi
1099   dnl Obtain the minimum SDK version of the resulting Emacs binary
1100   dnl built with this NDK.
1102   ANDROID_MIN_SDK=8
1103   AC_MSG_CHECKING([for the lowest Android version Emacs can run on])
1104   [android_sdk=`echo "$cc_target" | grep -oE 'android([0-9][0-9]?)'`]
1106   if test -n "$android_sdk"; then
1107     android_sdk=`echo "$android_sdk" | sed -n 's/android//p'`
1108     AC_MSG_RESULT([$android_sdk])
1109     ANDROID_MIN_SDK=$android_sdk
1110   else
1111     # This is probably GCC.
1112     [ cat << EOF > conftest.c
1113 #include <android/api-level.h>
1114 extern const char *foo;
1117 main (void)
1119 #if __ANDROID_API__ < 7
1120    foo = "emacs_api_6";
1121 #elif __ANDROID_API__ < 8
1122    foo = "emacs_api_7";
1123 #elif __ANDROID_API__ < 9
1124    foo = "emacs_api_8";
1125 #elif __ANDROID_API__ < 10
1126   foo = "emacs_api_9";
1127 #elif __ANDROID_API__ < 11
1128   foo = "emacs_api_10";
1129 #elif __ANDROID_API__ < 12
1130   foo = "emacs_api_11";
1131 #elif __ANDROID_API__ < 13
1132   foo = "emacs_api_12";
1133 #elif __ANDROID_API__ < 14
1134    foo = "emacs_api_13";
1135 #elif __ANDROID_API__ < 15
1136    foo = "emacs_api_14";
1137 #elif __ANDROID_API__ < 16
1138    foo = "emacs_api_15";
1139 #elif __ANDROID_API__ < 17
1140    foo = "emacs_api_16";
1141 #elif __ANDROID_API__ < 18
1142    foo = "emacs_api_17";
1143 #elif __ANDROID_API__ < 19
1144    foo = "emacs_api_18";
1145 #elif __ANDROID_API__ < 20
1146    foo = "emacs_api_19";
1147 #elif __ANDROID_API__ < 21
1148    foo = "emacs_api_20";
1149 #elif __ANDROID_API__ < 22
1150    foo = "emacs_api_21";
1151 #elif __ANDROID_API__ < 23
1152    foo = "emacs_api_22";
1153 #elif __ANDROID_API__ < 24
1154    foo = "emacs_api_23";
1155 #elif __ANDROID_API__ < 25
1156    foo = "emacs_api_24";
1157 #elif __ANDROID_API__ < 26
1158    foo = "emacs_api_25";
1159 #elif __ANDROID_API__ < 27
1160    foo = "emacs_api_26";
1161 #elif __ANDROID_API__ < 28
1162    foo = "emacs_api_27";
1163 #elif __ANDROID_API__ < 29
1164    foo = "emacs_api_28";
1165 #elif __ANDROID_API__ < 30
1166    foo = "emacs_api_29";
1167 #elif __ANDROID_API__ < 31
1168    foo = "emacs_api_30";
1169 #elif __ANDROID_API__ < 32
1170    foo = "emacs_api_31";
1171 #elif __ANDROID_API__ < 33
1172    foo = "emacs_api_32";
1173 #elif __ANDROID_API__ < 34
1174    foo = "emacs_api_33";
1175 #elif __ANDROID_API__ < 35
1176    foo = "emacs_api_34";
1177 #else
1178    foo = "emacs_api_future";
1179 #endif
1181 EOF]
1183     AC_CACHE_VAL([emacs_cv_android_api],
1184                  [$ANDROID_CC $ANDROID_CFLAGS -c conftest.c -o conftest.o \
1185                   && emacs_cv_android_api=`grep -ao -E                    \
1186                      "emacs_api_([[0-9][0-9]]?|future)" conftest.o`])
1187     android_sdk="$emacs_cv_android_api"
1188     rm -rf conftest.c conftest.o
1190     # If this version of the NDK requires __ANDROID_API__ to be
1191     # specified, then complain to the user.
1192     if test "$android_sdk" = "emacs_api_future"; then
1193        AC_MSG_ERROR([The version of Android to build for was not specified.
1194 You must tell the Android compiler what version of Android to build for,
1195 by defining the __ANDROID_API__ preprocessor macro in ANDROID_CC, like so:
1197     ANDROID_CC="/path/to/ndk/arm-linux-android-gcc -D__ANDROID_API__=8"])
1198     fi
1200     if test -n "$android_sdk"; then
1201        android_sdk=`echo $android_sdk | sed -n 's/emacs_api_//p'`
1202        AC_MSG_RESULT([$android_sdk])
1203        ANDROID_MIN_SDK=$android_sdk
1204     else
1205       AC_MSG_RESULT([unknown ($cc_target); assuming 8])
1206       AC_MSG_ERROR([configure could not determine the versions of Android \
1207 a binary built with this compiler will run on.  The generated application \
1208 package will likely install on older systems but crash on startup.])
1209       android_sdk=8
1210     fi
1211   fi
1212   AC_SUBST([ANDROID_MIN_SDK])
1214   # Now tell java/Makefile if Emacs is being built for Android 4.3 or
1215   # earlier.
1216   ANDROID_SDK_18_OR_EARLIER=
1217   if test "$android_sdk" -le "18"; then
1218      ANDROID_SDK_18_OR_EARLIER=yes
1219   fi
1220   AC_SUBST([ANDROID_SDK_18_OR_EARLIER])
1222   # Likewise for Android 2.2.
1223   ANDROID_SDK_8_OR_EARLIER=
1224   if test "$android_sdk" -le "8"; then
1225      ANDROID_SDK_8_OR_EARLIER=yes
1226   fi
1227   AC_SUBST([ANDROID_SDK_8_OR_EARLIER])
1229   # Save confdefs.h and config.log for now.
1230   mv -f confdefs.h _confdefs.h
1231   mv -f config.log _config.log
1233   # Make sure these files are removed upon exit.
1234   trap "rm -rf _confdefs.h _config.log" 0
1236   # Figure out what --with-FOO options to pass through.
1237   passthrough="$passthrough --with-png=$with_png"
1238   passthrough="$passthrough --with-webp=$with_webp"
1239   passthrough="$passthrough --with-gif=$with_gif"
1240   passthrough="$passthrough --with-jpeg=$with_jpeg"
1241   passthrough="$passthrough --with-xml2=$with_xml2"
1242   passthrough="$passthrough --with-sqlite3=$with_sqlite3"
1243   passthrough="$passthrough --with-gnutls=$with_gnutls"
1244   passthrough="$passthrough --with-tiff=$with_tiff"
1245   passthrough="$passthrough --with-selinux=$with_selinux"
1246   passthrough="$passthrough --with-modules=$with_modules"
1247   passthrough="$passthrough --with-tree-sitter=$with_tree_sitter"
1248   passthrough="$passthrough --with-imagemagick=$with_imagemagick"
1249   passthrough="$passthrough --with-lcms2=$with_lcms2"
1250   passthrough="$passthrough --with-mailutils=$with_mailutils"
1251   passthrough="$passthrough --with-pop=$with_pop"
1252   passthrough="$passthrough --with-harfbuzz=$with_harfbuzz"
1253   passthrough="$passthrough --with-threads=$with_threads"
1255   # Now pass through some checking-related options.
1256   emacs_val="--enable-check-lisp-object-type=$enable_check_lisp_object_type"
1257   passthrough="$passthrough $emacs_val"
1259   AS_IF([test "x$with_mailutils" = "xyes"], [emacs_use_mailutils=yes])
1260   AC_SUBST([emacs_use_mailutils])
1262   AS_IF([XCONFIGURE=android ANDROID_CC="$ANDROID_CC"            \
1263          ANDROID_SDK="$android_sdk" android_abi=$android_abi    \
1264          android_ndk_path="$with_ndk_path"                      \
1265          android_ndk_cxx="$android_ndk_cxx"                     \
1266          $CONFIG_SHELL $0 $passthrough], [],
1267     [AC_MSG_ERROR([Failed to cross-configure Emacs for android.])])
1269   # Now set ANDROID to yes.
1270   ANDROID=yes
1272   for makefile in $android_makefiles; do
1273     AC_MSG_NOTICE([Generating $makefile.android])
1274     mv -f "$makefile" "$makefile.android"
1275   done
1277   AC_MSG_NOTICE([Generating src/config.h.android])
1278   mv -f src/config.h src/config.h.android
1280   # Tell AndroidManifest.xml whether or not Emacs should be built
1281   # debug.
1282   ANDROID_DEBUGGABLE=false
1283   if test "$with_android_debug" = "yes"; then
1284     ANDROID_DEBUGGABLE=true
1285   fi
1286   AC_SUBST([ANDROID_DEBUGGABLE])
1288   # Move confdefs.h back now that the recursive call to configure is
1289   # complete.
1290   mv -f _confdefs.h confdefs.h
1292   # Move the Android config.log to config.log.android.  */
1293   mv -f config.log config.log.android
1295   # And _config.log back.
1296   mv -f _config.log config.log
1299 AC_SUBST([ANDROID])
1300 AC_SUBST([JAVAC])
1301 AC_SUBST([AAPT])
1302 AC_SUBST([D8])
1303 AC_SUBST([ZIPALIGN])
1304 AC_SUBST([ANDROID_JAR])
1305 AC_SUBST([ANDROID_ABI])
1306 AC_SUBST([IS_D8_R8])
1308 if test "$XCONFIGURE" = "android"; then
1309   ANDROID=yes
1311   # Enable cross compiling.
1312   cross_compiling=yes
1315 AC_SUBST([XCONFIGURE])
1317 if test "$ANDROID" = "yes"; then
1318   # When --with-android is specified, almost all build options must be
1319   # disabled, both within the recursive invocation of configure and
1320   # outside.
1321   with_xpm=no
1323   # Some of these dependencies are now supported within Android, so
1324   # they can be enabled.
1325   if test "$XCONFIGURE" != "android"; then
1326     with_png=no
1327     with_webp=no
1328     with_gif=no
1329     with_jpeg=no
1330     with_xml2=no
1331     with_sqlite3=no
1332     with_gnutls=no
1333     with_tiff=no
1334     with_selinux=no
1335     with_modules=no
1336     with_tree_sitter=no
1337     with_imagemagick=no
1338     with_lcms2=no
1339     with_mailutils=no
1340     with_pop=no
1341     with_harfbuzz=no
1342     with_native_compilation=no
1343     with_threads=no
1344   fi
1346   with_rsvg=no
1347   with_libsystemd=no
1348   with_cairo=no
1349   with_xft=no
1350   with_libotf=no
1351   with_gpm=no
1352   with_dbus=no
1353   with_gsettings=no
1354   with_ns=no
1356   # zlib is available in android.
1359 dnl This used to use changequote, but, apart from 'changequote is evil'
1360 dnl per the autoconf manual, we can speed up autoconf somewhat by quoting
1361 dnl the great gob of text.  Thus it's not processed for possible expansion.
1362 dnl Just make sure the brackets remain balanced.
1364 dnl Since Emacs can't find matching pairs of quotes, boundaries are
1365 dnl indicated by comments.
1366 dnl quotation begins
1369 ### If you add support for a new configuration, add code to this
1370 ### switch statement to recognize your configuration name and select
1371 ### the appropriate opsys.
1373 ### As far as handling version numbers on operating systems is
1374 ### concerned, make sure things will fail in a fixable way.  If
1375 ### /etc/MACHINES doesn't say anything about version numbers, be
1376 ### prepared to handle anything reasonably.  If version numbers
1377 ### matter, be sure /etc/MACHINES says something about it.
1379 opsys='' unported=no
1380 case "${canonical}" in
1382   ## Android
1383   *linux-android* )
1384     opsys=android
1385   ;;
1387   ## GNU/Linux and similar ports
1388   *-*-linux* )
1389     opsys=gnu-linux
1390   ;;
1392   ## FreeBSD ports
1393   *-*-freebsd* )
1394     opsys=freebsd
1395   ;;
1397   ## DragonFly ports
1398   *-*-dragonfly* )
1399     opsys=dragonfly
1400   ;;
1402   ## FreeBSD kernel + glibc based userland
1403   *-*-kfreebsd*gnu* )
1404     opsys=gnu-kfreebsd
1405   ;;
1407   ## NetBSD ports
1408   *-*-netbsd* )
1409     opsys=netbsd
1410   ;;
1412   ## OpenBSD ports
1413   *-*-openbsd* | *-*-mirbsd* )
1414     opsys=openbsd
1415   ;;
1417   ## Apple Darwin / macOS
1418   *-apple-darwin* )
1419     case "${canonical}" in
1420       *-apple-darwin[0-9].*) unported=yes ;;
1421       i[3456]86-* | x86_64-* | arm-* | aarch64-* )  ;;
1422       * )            unported=yes ;;
1423     esac
1424     opsys=darwin
1425     ## FIXME: Find a way to use Fink if available (Bug#11507).
1426   ;;
1428   ## Chromium Native Client
1429   *-nacl )
1430     opsys=nacl
1431   ;;
1433   ## Cygwin ports
1434   *-*-cygwin )
1435     opsys=cygwin
1436   ;;
1438   ## HP 9000 series 700 and 800, running HP/UX
1439   hppa*-hp-hpux10.2* )
1440     opsys=hpux10-20
1441   ;;
1442   hppa*-hp-hpux1[1-9]* )
1443     opsys=hpux11
1444     CFLAGS="-D_INCLUDE__STDC_A1_SOURCE $CFLAGS"
1445   ;;
1447   ## IBM machines
1448   rs6000-ibm-aix4.[23]* )
1449     opsys=aix4-2
1450   ;;
1451   powerpc-ibm-aix4.[23]*  )
1452     opsys=aix4-2
1453   ;;
1454   rs6000-ibm-aix[56]* )
1455     opsys=aix4-2
1456   ;;
1457   powerpc-ibm-aix[5-9]* | powerpc-ibm-aix[1-9][0-9]* )
1458     opsys=aix4-2
1459   ;;
1461   ## Solaris
1462   *-*-solaris* | *-*-sunos*)
1463     case "${canonical}" in
1464       i[3456]86-*-* )   ;;
1465       amd64-*-*|x86_64-*-*) ;;
1466       sparc* )          ;;
1467       * )               unported=yes ;;
1468     esac
1469     opsys=solaris
1470     ## Watch out for a compiler that we know will not work.
1471     if [ "$CC" = /usr/ucb/cc ]; then
1472       ## /usr/ucb/cc doesn't work;
1473       ## we should find some other compiler that does work.
1474       unset CC
1475     fi
1476   ;;
1478   ## QNX Neutrino
1479   *-nto-qnx* )
1480     opsys=qnxnto
1481     test -z "$CC" && CC=qcc
1482     LDFLAGS="-N2M $LDFLAGS"
1483   ;;
1485   *-haiku )
1486     opsys=haiku
1487   ;;
1489   ## Intel 386 machines where we don't care about the manufacturer.
1490   i[3456]86-*-* )
1491     case "${canonical}" in
1492       *-darwin* )               opsys=darwin ;;
1493       *-mingw* )
1494                 opsys=mingw32
1495                 # MinGW overrides and adds some system headers in nt/inc.
1496                 GCC_TEST_OPTIONS="-I $srcdir/nt/inc"
1497                 ;;
1498       *-sysv4.2uw* )            opsys=unixware ;;
1499       *-sysv5uw* )              opsys=unixware ;;
1500       *-sysv5OpenUNIX* )        opsys=unixware ;;
1501       ## Otherwise, we'll fall through to the generic opsys code at the bottom.
1502     esac
1503   ;;
1505   # MinGW64
1506   x86_64-*-* )
1507     case "${canonical}" in
1508       *-mingw* )
1509                 opsys=mingw32
1510                 # MinGW overrides and adds some system headers in nt/inc.
1511                 GCC_TEST_OPTIONS="-I $srcdir/nt/inc"
1512                 ;;
1513       ## Otherwise, we'll fall through to the generic opsys code at the bottom.
1514     esac
1515   ;;
1517   * )
1518     unported=yes
1519   ;;
1520 esac
1522 ### If the code above didn't choose an operating system, just choose
1523 ### an operating system based on the configuration name.  You really
1524 ### only want to use this when you have no idea what the right
1525 ### operating system is; if you know what operating systems a machine
1526 ### runs, it's cleaner to make it explicit in the case statement
1527 ### above.
1528 if test x"${opsys}" = x; then
1529   case "${canonical}" in
1530     *-gnu* )                            opsys=gnu ;;
1531     * )
1532       unported=yes
1533     ;;
1534   esac
1538 dnl quotation ends
1540 if test $unported = yes; then
1541   AC_MSG_ERROR([Emacs does not support '${canonical}' systems.
1542 If you think it should, please send a report to ${PACKAGE_BUGREPORT}.
1543 Check 'etc/MACHINES' for recognized configuration names.])
1546 #### Choose a compiler.
1548 dnl Don't bother to test for C89.
1549 AC_DEFUN([_AC_PROG_CC_C89], [$2])
1551 dnl Sets GCC=yes if using gcc.
1552 AC_PROG_CC([gcc cc cl clang "$XCRUN gcc" "$XCRUN clang"])
1554 if test -n "$XCRUN"; then
1555   AC_CHECK_PROGS([AR], [ar "$XCRUN ar"])
1556   test -n "$AR" && export AR
1559 dnl Emacs needs C99 or later.
1560 gl_PROG_CC_C99
1562 AC_PROG_CC_C_O
1564 if test x$GCC = xyes; then
1565   test "x$GCC_TEST_OPTIONS" != x && CC="$CC $GCC_TEST_OPTIONS"
1568 # Avoid gnulib's tests for -lcrypto, so that there's no static dependency on it.
1569 AC_DEFUN([gl_CRYPTO_CHECK])
1570 # Avoid gnulib's tests for HAVE_WORKING_O_NOATIME and HAVE_WORKING_O_NOFOLLOW,
1571 # as we don't use them.
1572 AC_DEFUN([gl_FCNTL_O_FLAGS])
1573 # Avoid gnulib's test for pthread_sigmask.
1574 funcs=
1575 for func in $ac_func_list; do
1576   test $func = pthread_sigmask || AS_VAR_APPEND([funcs], [" $func"])
1577 done
1578 ac_func_list=$funcs
1579 # Emacs does not use the wchar or wctype-h modules.
1580 AC_DEFUN([gt_TYPE_WINT_T],
1581   [GNULIBHEADERS_OVERRIDE_WINT_T=0
1582    AC_SUBST([GNULIBHEADERS_OVERRIDE_WINT_T])])
1583 # Emacs does not need precise checks for the Solaris 10 MB_CUR_MAX bug.
1584 AC_DEFUN_ONCE([gl_STDLIB_H],
1585   [AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
1586    gl_NEXT_HEADERS([stdlib.h])])
1588 # Initialize gnulib right after choosing the compiler.
1589 dnl Amongst other things, this sets AR and ARFLAGS.
1590 gl_EARLY
1592 # ndk_LATE must be enclosed in this conditional to prevent the
1593 # AC_PROG_CXX it indirectly requires from being expanded at top level.
1594 if test "$ndk_INITIALIZED" = "yes"; then
1595   ndk_LATE_EARLY
1596   ndk_LATE
1599 if test "$ac_test_CFLAGS" != set; then
1600   # It's helpful to have C macros available to GDB, so prefer -g3 to -g
1601   # if -g3 works and the user does not specify CFLAGS.
1602   # This test must follow gl_EARLY; otherwise AC_LINK_IFELSE complains.
1603   case $CFLAGS in
1604     '-g')
1605       emacs_g3_CFLAGS='-g3';;
1606     '-g -O2')
1607       emacs_g3_CFLAGS='-g3 -O2';;
1608     *)
1609       emacs_g3_CFLAGS='';;
1610   esac
1611   if test -n "$emacs_g3_CFLAGS"; then
1612     emacs_save_CFLAGS=$CFLAGS
1613     CFLAGS=$emacs_g3_CFLAGS
1614     AC_CACHE_CHECK([whether $CC accepts $emacs_g3_CFLAGS],
1615       [emacs_cv_prog_cc_g3],
1616       [AC_LINK_IFELSE([AC_LANG_PROGRAM()],
1617          [emacs_cv_prog_cc_g3=yes],
1618          [emacs_cv_prog_cc_g3=no])])
1619     if test $emacs_cv_prog_cc_g3 != yes; then
1620       CFLAGS=$emacs_save_CFLAGS
1621     fi
1622     # Haiku also needs -gdwarf-2 because its GDB is too old
1623     # to understand newer formats.
1624     if test $opsys = mingw32 || test $opsys = haiku; then
1625       CFLAGS="$CFLAGS -gdwarf-2"
1626     fi
1627   fi
1629   case $CFLAGS in
1630     *-O*) ;;
1631     *)
1632       # No optimization flag was inferred for this non-GCC compiler.
1633       # Try -O.  This is needed for xlc on AIX; see Bug#14258.
1634       emacs_save_CFLAGS=$CFLAGS
1635       test -z "$CFLAGS" || CFLAGS="$CFLAGS "
1636       CFLAGS=${CFLAGS}-O
1637       AC_CACHE_CHECK([whether $CC accepts -O],
1638         [emacs_cv_prog_cc_o],
1639         [AC_LINK_IFELSE([AC_LANG_PROGRAM()],
1640            [emacs_cv_prog_cc_o=yes],
1641            [emacs_cv_prog_cc_o=no])])
1642       if test $emacs_cv_prog_cc_o != yes; then
1643         CFLAGS=$emacs_save_CFLAGS
1644       fi ;;
1645   esac
1648 # gl_GCC_VERSION_IFELSE([major], [minor], [run-if-found], [run-if-not-found])
1649 # ---------------------------------------------------------------------------
1650 # If $CPP is gcc-MAJOR.MINOR or newer, then run RUN-IF-FOUND.
1651 # Otherwise, run RUN-IF-NOT-FOUND.
1652 AC_DEFUN([gl_GCC_VERSION_IFELSE],
1653   [AC_PREPROC_IFELSE(
1654     [AC_LANG_PROGRAM(
1655       [[
1656 #if ($1) < __GNUC__ || (($1) == __GNUC__ && ($2) <= __GNUC_MINOR__)
1657 /* ok */
1658 #else
1659 # error "your version of gcc is older than $1.$2"
1660 #endif
1661       ]]),
1662     ], [$3], [$4])
1663   ]
1666 # clang is unduly picky about some things.
1667 AC_CACHE_CHECK([whether the compiler is clang], [emacs_cv_clang],
1668   [AC_COMPILE_IFELSE(
1669      [AC_LANG_PROGRAM([[
1670           #ifndef __clang__
1671             error "not clang";
1672           #endif
1673         ]])],
1674      [emacs_cv_clang=yes],
1675      [emacs_cv_clang=no])])
1677 AC_ARG_ENABLE([gcc-warnings],
1678   [AS_HELP_STRING([--enable-gcc-warnings@<:@=TYPE@:>@],
1679                   [control generation of GCC warnings.  The TYPE 'yes'
1680                    means to fail if any warnings are issued; 'warn-only'
1681                    means issue warnings without failing (default for
1682                    developer builds); 'no' means disable warnings
1683                    (default for non-developer builds).])],
1684   [case $enableval in
1685      yes|no|warn-only) ;;
1686      *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
1687    esac
1688    gl_gcc_warnings=$enableval],
1689   [# By default, use 'warn-only' if it looks like the invoker of 'configure'
1690    # is a developer as opposed to a builder.  This is most likely true
1691    # if GCC is recent enough and there is a .git directory or file;
1692    # however, if there is also a .tarball-version file it is probably
1693    # just a release imported into Git for patch management.
1694    gl_gcc_warnings=no
1695    AS_IF([test -d "$srcdir"/.git || test -f "$srcdir"/.git],
1696      [AS_IF([test -f "$srcdir"/.tarball-version], [],
1697         # Clang typically identifies itself as GCC 4.2 or something similar
1698         # even if it is recent enough to accept the warnings we enable.
1699         [AS_IF([test "$emacs_cv_clang" = yes],
1700            [gl_gcc_warnings=warn-only],
1701            [gl_GCC_VERSION_IFELSE([5], [3], [gl_gcc_warnings=warn-only])])])])])
1703 NATIVE_COMPILATION_AOT=no
1704 AC_ARG_WITH([native-compilation],
1705   [AS_HELP_STRING([--with-native-compilation@<:@=TYPE@:>@],
1706                   [compile with Emacs Lisp native compiler support.  The TYPE
1707                    'yes' (or empty) means to enable it and compile natively
1708                    preloaded Lisp files; 'no' means to disable it;
1709                    'aot' will make the build process compile all the Lisp
1710                    files in the tree natively ahead of time.  (This will
1711                    usually be quite slow.)])],
1712   [
1713   case $withval in
1714      aot)
1715        withval=yes
1716        NATIVE_COMPILATION_AOT=yes
1717        ;;
1718      yes|no) ;;
1719      *)      AC_MSG_ERROR([bad value $withval for native-compilation option]) ;;
1720    esac
1721    with_native_compilation=$withval],
1722   [with_native_compilation=default]
1724 AC_SUBST([NATIVE_COMPILATION_AOT])
1726 AC_ARG_ENABLE([check-lisp-object-type],
1727   [AS_HELP_STRING([--enable-check-lisp-object-type],
1728      [Enable compile time checks for the Lisp_Object data type,
1729       which can catch some bugs during development.])])
1730 if test "$enable_check_lisp_object_type" = yes; then
1731   AC_DEFINE([CHECK_LISP_OBJECT_TYPE], [1],
1732     [Define to enable compile-time checks for the Lisp_Object data type.])
1735 WERROR_CFLAGS=
1736 # When compiling with GCC, prefer -isystem to -I when including system
1737 # include files, to avoid generating useless diagnostics for the files.
1738 AS_IF([test $gl_gcc_warnings = no],
1740   isystem='-I'
1741   AS_IF([test "$emacs_cv_clang" = yes],
1742    [
1743      # Turn off some warnings if supported.
1744      gl_WARN_ADD([-Wno-pointer-sign])
1745      gl_WARN_ADD([-Wno-string-plus-int])
1746      gl_WARN_ADD([-Wno-unknown-attributes])
1747      gl_WARN_ADD([-Wno-unknown-pragmas])
1748    ])
1749  ],[
1750   isystem='-isystem '
1752   # This, $nw, is the list of warnings we disable.
1753   nw=
1755   case $with_x_toolkit in
1756     lucid | athena | motif)
1757        # Old toolkits mishandle 'const'.
1758        nw="$nw -Wwrite-strings"
1759        ;;
1760   esac
1761   AS_IF([test $gl_gcc_warnings = yes],
1762     [WERROR_CFLAGS=-Werror],
1763     [# Use -fanalyzer and related options only if --enable-gcc-warnings,
1764      # as they slow GCC considerably.
1765      nw="$nw -fanalyzer -Wno-analyzer-double-free -Wno-analyzer-malloc-leak"
1766      nw="$nw -Wno-analyzer-null-dereference -Wno-analyzer-use-after-free"
1767      # Use -Wsuggest-attribute=malloc only if --enable-gcc-warnings,
1768      # as it doesn't flag code that is wrong in any way.
1769      nw="$nw -Wsuggest-attribute=malloc"])
1771   nw="$nw -Wcast-align=strict"      # Emacs is tricky with pointers.
1772   nw="$nw -Wduplicated-branches"    # Too many false alarms
1773   nw="$nw -Wformat-overflow=2"      # False alarms due to GCC bug 110333
1774   nw="$nw -Wsystem-headers"         # Don't let system headers trigger warnings
1775   nw="$nw -Woverlength-strings"     # Not a problem these days
1776   nw="$nw -Wvla"                    # Emacs uses <vla.h>.
1777   nw="$nw -Wunused-const-variable=2" # lisp.h declares const objects.
1778   nw="$nw -Winline"                 # OK to ignore 'inline'
1779   nw="$nw -Wstrict-overflow"        # OK to optimize assuming that
1780                                     # signed overflow has undefined behavior
1781   nw="$nw -Wsync-nand"              # irrelevant here, and provokes ObjC warning
1782   nw="$nw -Wunsafe-loop-optimizations" # OK to suppress unsafe optimizations
1783   nw="$nw -Wbad-function-cast"      # These casts are no worse than others.
1785   # Emacs doesn't care about shadowing; see
1786   # <https://lists.gnu.org/r/emacs-diffs/2011-11/msg00265.html>.
1787   nw="$nw -Wshadow"
1789   # Emacs's use of alloca inhibits protecting the stack.
1790   nw="$nw -Wstack-protector"
1792   # Emacs's use of __attribute__ ((cold)) causes false alarms with this option.
1793   nw="$nw -Wsuggest-attribute=cold"
1795   # Emacs's use of partly-const functions such as Fgnutls_available_p
1796   # make this option problematic.
1797   nw="$nw -Wsuggest-attribute=const"
1799   # Emacs's use of partly-pure functions such as CHECK_TYPE make this
1800   # option problematic.
1801   nw="$nw -Wsuggest-attribute=pure"
1803   # Emacs doesn't need this paranoia.
1804   nw="$nw -Wbidi-chars=any,ucn"
1806   if test "$emacs_cv_clang" = yes; then
1807     nw="$nw -Wdouble-promotion"
1808     nm="$nm -Wunknown-pragmas"
1809   fi
1811   # This causes too much noise in the MinGW build.
1812   if test $opsys = mingw32; then
1813     nw="$nw -Wsuggest-attribute=format"
1814   fi
1816   # If Emacs is being built for Android and many functions are
1817   # currently stubbed out for operation on the build machine, disable
1818   # -Wsuggest-attribute=noreturn.
1820   AS_IF([test "$ANDROID" = "yes"],
1821     [nw="$nw -Wsuggest-attribute=noreturn"])
1823   gl_MANYWARN_ALL_GCC([ws])
1824   gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
1825   for w in $ws; do
1826     gl_WARN_ADD([$w])
1827   done
1828   gl_WARN_ADD([-Wredundant-decls])     # Prefer this, as we don't use Bison.
1829   gl_WARN_ADD([-Wno-missing-field-initializers]) # We need this one
1830   gl_WARN_ADD([-Wno-override-init])    # More trouble than it is worth
1831   gl_WARN_ADD([-Wno-sign-compare])     # Too many warnings for now
1832   gl_WARN_ADD([-Wno-type-limits])      # Too many warnings for now
1833   gl_WARN_ADD([-Wno-unused-parameter]) # Too many warnings for now
1834   gl_WARN_ADD([-Wno-format-nonliteral])
1835   gl_WARN_ADD([-Wno-bidi-chars])
1836   AS_IF([test $gl_gcc_warnings = yes],
1837     [gl_WARN_ADD([-Wno-analyzer-fd-leak])]) # GCC bug 109839
1839   # clang is unduly picky about some things.
1840   if test "$emacs_cv_clang" = yes; then
1841     gl_WARN_ADD([-Wno-bitwise-instead-of-logical])
1842     gl_WARN_ADD([-Wno-missing-braces])
1843     gl_WARN_ADD([-Wno-null-pointer-arithmetic])
1844     gl_WARN_ADD([-Wno-implicit-const-int-float-conversion])
1845     gl_WARN_ADD([-Wno-int-in-bool-context])
1846     gl_WARN_ADD([-Wno-shift-overflow])
1847   fi
1849   # This causes too much noise in the MinGW build
1850   if test $opsys = mingw32; then
1851     gl_WARN_ADD([-Wno-pointer-sign])
1852   fi
1854   AC_DEFINE([GCC_LINT], [1], [Define to 1 if --enable-gcc-warnings.])
1855   AS_IF([test $gl_gcc_warnings = yes],
1856     [AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks])
1857      AH_VERBATIM([GNULIB_PORTCHECK_FORTIFY_SOURCE],
1858      [/* Enable compile-time and run-time bounds-checking, and some warnings,
1859          without upsetting glibc 2.15+. */
1860       #if (defined GNULIB_PORTCHECK && !defined _FORTIFY_SOURCE \
1861            && defined __OPTIMIZE__ && __OPTIMIZE__)
1862       # define _FORTIFY_SOURCE 2
1863       #endif
1864      ])])
1865  ])
1867 # clang is picky about these regardless of whether
1868 # --enable-gcc-warnings is specified.
1869 if test "$emacs_cv_clang" = yes; then
1870   gl_WARN_ADD([-Wno-initializer-overrides])
1871   gl_WARN_ADD([-Wno-tautological-compare])
1872   gl_WARN_ADD([-Wno-tautological-constant-out-of-range-compare])
1875 # Suppress deprecation warnings from using sprintf variants,
1876 # starting with Xcode 14.1 on macOS 13.
1877 # These warnings are false alarms, as Emacs usage of sprintf is safe.
1878 if test $opsys = darwin; then
1879   gl_WARN_ADD([-Wno-deprecated-declarations])
1882 # Use a slightly smaller set of warning options for lib/.
1884 nw="$nw -Wunused-macros"
1885 gl_MANYWARN_COMPLEMENT([GNULIB_WARN_CFLAGS], [$WARN_CFLAGS], [$nw])
1887 AC_SUBST([WERROR_CFLAGS])
1888 AC_SUBST([GNULIB_WARN_CFLAGS])
1890 edit_cflags="
1891   s,///*,/,g
1892   s/^/ /
1893   s/ -I/ $isystem/g
1894   s/^ //
1897 AC_ARG_ENABLE([link-time-optimization],
1898 [AS_HELP_STRING([--enable-link-time-optimization],
1899                 [build with link-time optimization
1900                  (experimental; see INSTALL)])],
1901 if test "${enableval}" != "no"; then
1902    ac_lto_supported=no
1903    if test "$emacs_cv_clang" = yes; then
1904       AC_MSG_CHECKING([whether link-time optimization is supported by clang])
1905       GOLD_PLUGIN=`$CC -print-file-name=LLVMgold.so 2>/dev/null`
1906       if test -x "$GOLD_PLUGIN"; then
1907          LTO="-flto"
1908       fi
1909    elif test x$GCC = xyes; then
1910       AC_MSG_CHECKING([whether link-time optimization is supported by gcc])
1911       CPUS=`getconf _NPROCESSORS_ONLN 2>/dev/null`
1912       if test x$CPUS != x; then
1913          LTO="-flto=$CPUS"
1914       else
1915          LTO="-flto"
1916       fi
1917    else
1918       AC_MSG_ERROR([Link-time optimization is not supported with your compiler.])
1919    fi
1920    if test -z "$LTO"; then
1921       ac_lto_supported=no
1922    else
1923       old_CFLAGS=$CFLAGS
1924       CFLAGS="$CFLAGS $LTO"
1925       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1926          [ac_lto_supported=yes], [ac_lto_supported=no])
1927          CFLAGS="$old_CFLAGS"
1928    fi
1929    AC_MSG_RESULT([$ac_lto_supported])
1930    if test "$ac_lto_supported" = "yes"; then
1931       CFLAGS="$CFLAGS $LTO"
1932       if test "$emacs_cv_clang" = yes; then
1933          AC_MSG_WARN([Please read INSTALL before using link-time optimization with clang])
1934          # WARNING: 'ar --plugin ...' doesn't work without
1935          # command, so plugin name is appended to ARFLAGS.
1936          ARFLAGS="cru --plugin $GOLD_PLUGIN"
1937          RANLIB="$RANLIB --plugin $GOLD_PLUGIN"
1938       else
1939         dnl The following is needed for GCC 4.9.0.  The GCC 4.9.0 release notes
1940         dnl suggest that instead of -ffat-lto-objects we should use gcc-ar and
1941         dnl gcc-ranlib in place of ar and ranlib, but gcc-ar makes /usr/bin/ar
1942         dnl dump core on Fedora 20, so play it safe for now.
1943         gl_COMPILER_OPTION_IF([-ffat-lto-objects],
1944           [CFLAGS="$CFLAGS -ffat-lto-objects"])
1945       fi
1946    fi
1950 dnl Automake replacements.
1951 AC_DEFUN([AM_CONDITIONAL],
1952   [$2 && $1_CONDITION=1 || $1_CONDITION=
1953    AC_SUBST([$1_CONDITION])])
1954 AC_DEFUN([AM_COND_IF],
1955   [AS_IF([test "$$1_CONDITION"], [$2], [$3])])
1957 dnl Prefer silent make output.  For verbose output, use
1958 dnl 'configure --disable-silent-rules' or 'make V=1' .
1959 AC_ARG_ENABLE([silent-rules],
1960   [AS_HELP_STRING(
1961      [--disable-silent-rules],
1962      [verbose build output (undo: "make V=0")])])
1963 if test "$enable_silent_rules" = no; then
1964   AM_DEFAULT_VERBOSITY=1
1965 else
1966   AM_DEFAULT_VERBOSITY=0
1968 AC_SUBST([AM_DEFAULT_VERBOSITY])
1969 ARCH_INDEPENDENT_CONFIG_FILES([src/verbose.mk])
1971 dnl Some other nice autoconf tests.
1972 AC_PROG_INSTALL
1973 dnl These are commented out, since gl_EARLY and/or Autoconf already does them.
1974 dnl AC_PROG_MKDIR_P
1975 dnl if test "x$RANLIB" = x; then
1976 dnl   AC_PROG_RANLIB
1977 dnl fi
1980 dnl Sadly, AC_PROG_LN_S is too restrictive.  It also tests whether links
1981 dnl can be made to directories.  This is not relevant for our usage, and
1982 dnl excludes some cases that work fine for us.  Eg MS Windows or files
1983 dnl hosted on AFS, both examples where simple links work, but links to
1984 dnl directories fail.  We use a cut-down version instead.
1985 dnl AC_PROG_LN_S
1987 AC_CACHE_CHECK([command to symlink files in the same directory], [emacs_cv_ln_s_fileonly],
1988 [rm -f conf$$ conf$$.file
1990 emacs_cv_ln_s_fileonly='cp -p'
1992 dnl On MinGW, ensure we will call the MSYS /bin/ln.exe, not some
1993 dnl random program in the current directory.
1994 if (echo >conf$$.file) 2>/dev/null; then
1995   if test "$opsys" = "mingw32"; then
1996     emacs_cv_ln_s_fileonly=/bin/ln
1997   elif ln -s conf$$.file conf$$ 2>/dev/null; then
1998     emacs_cv_ln_s_fileonly='ln -s'
1999   elif ln conf$$.file conf$$ 2>/dev/null; then
2000     emacs_cv_ln_s_fileonly=ln
2001   fi
2004 rm -f conf$$ conf$$.file])
2005 LN_S_FILEONLY=$emacs_cv_ln_s_fileonly
2007 AC_SUBST([LN_S_FILEONLY])
2010 dnl AC_PROG_LN_S sets LN_S to 'cp -pR' for MinGW, on the premise that 'ln'
2011 dnl doesn't support links to directories, as in "ln file dir".  But that
2012 dnl use is non-portable, and OTOH MinGW wants to use hard links for Emacs
2013 dnl executables at "make install" time.
2014 dnl See https://lists.gnu.org/r/emacs-devel/2013-04/msg00475.html
2015 dnl for more details.
2016 if test "$opsys" = "mingw32"; then
2017   LN_S="/bin/ln"
2020 dnl On some Debian versions, "install-info" prints irritating messages
2021 dnl "This is not dpkg install-info anymore, but GNU install-info"
2022 dnl if called via an absolute file name.
2023 dnl Use the entirely-identical-but-quieter ginstall-info instead if present.
2024 dnl Sadly some people may have an old ginstall-info installed on
2025 dnl non-Debian systems, so we can't use this.
2026 dnl AC_PATH_PROGS([INSTALL_INFO], [ginstall-info install-info], [:],
2027 dnl   [$PATH$PATH_SEPARATOR/usr/sbin$PATH_SEPARATOR/sbin])
2029 AC_PATH_PROG([INSTALL_INFO], [install-info], [:],
2030   [$PATH$PATH_SEPARATOR/usr/sbin$PATH_SEPARATOR/sbin])
2031 dnl Don't use GZIP, which is used by gzip for additional parameters.
2032 AC_PATH_PROG([GZIP_PROG], [gzip])
2034 test $with_compress_install != yes && test -n "$GZIP_PROG" && \
2035    GZIP_PROG=" # $GZIP_PROG # (disabled by configure --without-compress-install)"
2037 if test "$with_dumping" = "unexec" && test "$opsys" = "nacl"; then
2038   AC_MSG_ERROR([nacl is not compatible with --with-dumping=unexec])
2041 AC_CACHE_CHECK([for 'find' args to delete a file],
2042   [emacs_cv_find_delete],
2043   [if touch conftest.tmp && find conftest.tmp -delete 2>/dev/null &&
2044       test ! -f conftest.tmp
2045    then emacs_cv_find_delete="-delete"
2046    else emacs_cv_find_delete="-exec rm -f {} ';'"
2047    fi])
2048 FIND_DELETE=$emacs_cv_find_delete
2049 AC_SUBST([FIND_DELETE])
2051 PAXCTL_dumped=
2052 PAXCTL_notdumped=
2053 if test $with_unexec = yes && test $opsys = gnu-linux; then
2054   if test "${SETFATTR+set}" != set; then
2055     AC_CACHE_CHECK([for setfattr],
2056       [emacs_cv_prog_setfattr],
2057       [touch conftest.tmp
2058        if (setfattr -n user.pax.flags conftest.tmp) >/dev/null 2>&1; then
2059          emacs_cv_prog_setfattr=yes
2060        else
2061          emacs_cv_prog_setfattr=no
2062        fi])
2063     if test "$emacs_cv_prog_setfattr" = yes; then
2064       PAXCTL_notdumped='$(SETFATTR) -n user.pax.flags -v er'
2065       SETFATTR=setfattr
2066     else
2067       SETFATTR=
2068     fi
2069   fi
2070   case $opsys,$PAXCTL_notdumped,$emacs_uname_r in
2071     gnu-linux,,* | netbsd,,[0-7].*)
2072       AC_PATH_PROG([PAXCTL], [paxctl], [],
2073         [$PATH$PATH_SEPARATOR/sbin$PATH_SEPARATOR/usr/sbin])
2074       if test -n "$PAXCTL"; then
2075         if test "$opsys" = netbsd; then
2076           PAXCTL_dumped='$(PAXCTL) +a'
2077           PAXCTL_notdumped=$PAXCTL_dumped
2078         else
2079           AC_MSG_CHECKING([whether binaries have a PT_PAX_FLAGS header])
2080           AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
2081             [if $PAXCTL -v conftest$EXEEXT >/dev/null 2>&1; then
2082                AC_MSG_RESULT([yes])
2083              else
2084                AC_MSG_RESULT([no])
2085                PAXCTL=
2086              fi])
2087           if test -n "$PAXCTL"; then
2088             PAXCTL_dumped='$(PAXCTL) -zex'
2089             PAXCTL_notdumped='$(PAXCTL) -r'
2090           fi
2091         fi
2092       fi;;
2093   esac
2095 AC_SUBST([PAXCTL_dumped])
2096 AC_SUBST([PAXCTL_notdumped])
2097 AC_SUBST([SETFATTR])
2099 # Makeinfo on macOS is ancient, check whether there is a more recent
2100 # version installed by Homebrew.
2101 AC_CHECK_PROGS([BREW], [brew])
2102 if test -n "$BREW"; then
2103   AC_PATH_PROG([MAKEINFO], [makeinfo], [],
2104     [`$BREW --prefix texinfo 2>/dev/null`/bin$PATH_SEPARATOR$PATH])
2107 # Check MacPorts on macOS.
2108 if test $opsys = darwin; then
2109   AC_PATH_PROG([HAVE_MACPORTS], [port])
2112 ## Require makeinfo >= 4.13 (last of the 4.x series) to build the manuals.
2113 : ${MAKEINFO:=makeinfo}
2114 case `($MAKEINFO --version) 2>/dev/null` in
2115   *' (GNU texinfo) '4.1[[3-9]]* | \
2116   *' (GNU texinfo) '[[5-9]]* | \
2117   *' (GNU texinfo) '[[1-9][0-9]]* ) ;;
2118   *) MAKEINFO=no;;
2119 esac
2121 ## Makeinfo is unusual.  For a released Emacs, the manuals are
2122 ## pre-built, and not deleted by the normal clean rules.  makeinfo is
2123 ## therefore in the category of "special tools" not normally required, which
2124 ## configure does not have to check for (eg autoconf itself).
2125 ## In a repository checkout on the other hand, the manuals are not included.
2126 ## So makeinfo is a requirement to build from the repository, and configure
2127 ## should test for it as it does for any other build requirement.
2128 ## We use the presence of $srcdir/info/emacs to distinguish a release,
2129 ## with pre-built manuals, from a repository checkout.
2130 if test "$MAKEINFO" = "no"; then
2131   MAKEINFO=makeinfo
2132   if test ! -e "$srcdir/info/emacs" && test ! -e "$srcdir/info/emacs.info"; then
2133     AC_MSG_ERROR( [You do not seem to have makeinfo >= 4.13, and your
2134 source tree does not seem to have pre-built manuals in the 'info' directory.
2135 Please install a suitable version of makeinfo.] )
2136   else
2137     AC_MSG_WARN( [You do not seem to have makeinfo >= 4.13.
2138 You will not be able to rebuild the manuals if you delete them or change
2139 their sources.] )
2140   fi
2142 AC_SUBST([MAKEINFO])
2144 if test $opsys = mingw32; then
2145    DOCMISC_W32=efaq-w32
2146 else
2147    DOCMISC_W32=
2149 AC_SUBST([DOCMISC_W32])
2151 dnl Add our options to ac_link now, after it is set up.
2153 if test x$GCC = xyes; then
2154   test "x$GCC_LINK_TEST_OPTIONS" != x && \
2155     ac_link="$ac_link $GCC_LINK_TEST_OPTIONS"
2156 else
2157   test "x$NON_GCC_LINK_TEST_OPTIONS" != x && \
2158     ac_link="$ac_link $NON_GCC_LINK_TEST_OPTIONS"
2161 dnl On some platforms using GNU ld, linking temacs needs -znocombreloc.
2162 dnl Although this has something to do with dumping, the details are unknown.
2163 dnl If the flag is used but not needed,
2164 dnl Emacs should still work (albeit a bit more slowly),
2165 dnl so use the flag everywhere that it is supported.
2166 dnl When testing whether the flag works, treat GCC specially
2167 dnl since it just gives a non-fatal 'unrecognized option'
2168 dnl if not built to support GNU ld.
2169 if test "$GCC" = yes; then
2170   LDFLAGS_NOCOMBRELOC="-Wl,-znocombreloc"
2171 else
2172   LDFLAGS_NOCOMBRELOC="-znocombreloc"
2175 AC_CACHE_CHECK([for -znocombreloc], [emacs_cv_znocombreloc],
2176   [if test $with_unexec = no; then
2177      emacs_cv_znocombreloc='not needed'
2178    else
2179      save_LDFLAGS=$LDFLAGS
2180      LDFLAGS="$LDFLAGS $LDFLAGS_NOCOMBRELOC"
2181      AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
2182        [emacs_cv_znocombreloc=yes], [emacs_cv_znocombreloc=no])
2183      LDFLAGS=$save_LDFLAGS
2184    fi])
2186 case $emacs_cv_znocombreloc in
2187   no*)
2188     LDFLAGS_NOCOMBRELOC= ;;
2189 esac
2192 AC_CACHE_CHECK([whether addresses are sanitized],
2193   [emacs_cv_sanitize_address],
2194   [AC_COMPILE_IFELSE(
2195      [AC_LANG_PROGRAM(
2196         [[#ifndef __has_feature
2197           #define __has_feature(f) 0
2198           #endif
2199           #if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer)
2200           #else
2201            error "Addresses are not sanitized.";
2202           #endif
2203         ]])],
2204      [emacs_cv_sanitize_address=yes],
2205      [emacs_cv_sanitize_address=no])])
2207 if test $with_unexec = yes; then
2208   AC_DEFINE([HAVE_UNEXEC], [1], [Define if Emacs supports unexec.])
2209   if test "$emacs_cv_sanitize_address" = yes; then
2210     AC_MSG_WARN([[Addresses are sanitized; suggest --without-unexec]])
2211   fi
2215 UNEXEC_OBJ=
2216 test $with_unexec = yes &&
2217 case "$opsys" in
2218   # MSDOS uses unexcoff.o
2219   aix4-2)
2220    UNEXEC_OBJ=unexaix.o
2221    ;;
2222   cygwin)
2223    UNEXEC_OBJ=unexcw.o
2224    ;;
2225   darwin)
2226    UNEXEC_OBJ=unexmacosx.o
2227    ;;
2228   hpux10-20 | hpux11)
2229    UNEXEC_OBJ=unexhp9k800.o
2230    ;;
2231   mingw32)
2232    UNEXEC_OBJ=unexw32.o
2233    ;;
2234   solaris)
2235    # Use the Solaris dldump() function, called from unexsol.c, to dump
2236    # emacs, instead of the generic ELF dump code found in unexelf.c.
2237    # The resulting binary has a complete symbol table, and is better
2238    # for debugging and other observability tools (debuggers, pstack, etc).
2239    UNEXEC_OBJ=unexsol.o
2240    ;;
2241   *)
2242    UNEXEC_OBJ=unexelf.o
2243    ;;
2244 esac
2245 AC_SUBST([UNEXEC_OBJ])
2247 LD_SWITCH_SYSTEM=
2248 test "$with_unexec" = no || case "$opsys" in
2249   freebsd|dragonfly)
2250    ## Let 'ld' find image libs and similar things in /usr/local/lib.
2251    ## The system compiler, GCC, has apparently been modified to not
2252    ## look there, contrary to what a stock GCC would do.
2253 ### It's not our place to do this.  See bug#10313#17.
2254 ###   LD_SWITCH_SYSTEM=-L/usr/local/lib
2255       :
2256    ;;
2258   gnu-linux)
2259    ## cpp test was "ifdef __mips__", but presumably this is equivalent...
2260    case $host_cpu in mips*) LD_SWITCH_SYSTEM="-G 0";; esac
2261    ;;
2263   netbsd)
2264 ### It's not our place to do this.  See bug#10313#17.
2265 ###   LD_SWITCH_SYSTEM="-Wl,-rpath,/usr/pkg/lib -L/usr/pkg/lib -Wl,-rpath,/usr/local/lib -L/usr/local/lib"
2266       :
2267    ;;
2269   openbsd)
2270    ## Han Boetes <han@boetes.org> says this is necessary,
2271    ## otherwise Emacs dumps core on elf systems.
2272    LD_SWITCH_SYSTEM="-Z"
2273    ;;
2274 esac
2275 AC_SUBST([LD_SWITCH_SYSTEM])
2277 ac_link="$ac_link $LD_SWITCH_SYSTEM"
2279 ## This setting of LD_SWITCH_SYSTEM references LD_SWITCH_X_SITE_RPATH,
2280 ## which has not been defined yet.  When this was handled with cpp,
2281 ## it was expanded to null when configure sourced the s/*.h file.
2282 ## Thus LD_SWITCH_SYSTEM had different values in configure and the Makefiles.
2283 ## FIXME it would be cleaner to put this in LD_SWITCH_SYSTEM_TEMACS
2284 ## (or somesuch), but because it is supposed to go at the _front_
2285 ## of LD_SWITCH_SYSTEM, we cannot do that in exactly the same way.
2286 ## Compare with the gnu-linux case below, which added to the end
2287 ## of LD_SWITCH_SYSTEM, and so can instead go at the front of
2288 ## LD_SWITCH_SYSTEM_TEMACS.
2289 case "$opsys" in
2290   netbsd|openbsd)
2291    LD_SWITCH_SYSTEM="\$(LD_SWITCH_X_SITE_RPATH) $LD_SWITCH_SYSTEM" ;;
2292 esac
2294 C_SWITCH_MACHINE=
2296 test $with_unexec = yes &&
2297 case $canonical in
2298  alpha*)
2299     ## With ELF, make sure that all common symbols get allocated to in the
2300     ## data section.  Otherwise, the dump of temacs may miss variables in
2301     ## the shared library that have been initialized.  For example, with
2302     ## GNU libc, __malloc_initialized would normally be resolved to the
2303     ## shared library's .bss section, which is fatal.
2304     if test "x$GCC" = "xyes"; then
2305       C_SWITCH_MACHINE="-fno-common"
2306     else
2307       AC_MSG_ERROR([Non-GCC compilers are not supported.])
2308     fi
2309   ;;
2310 esac
2311 AC_SUBST([C_SWITCH_MACHINE])
2313 C_SWITCH_SYSTEM=
2314 ## Some programs in src produce warnings saying certain subprograms
2315 ## are too complex and need a MAXMEM value greater than 2000 for
2316 ## additional optimization.  --nils@exp-math.uni-essen.de
2317 test "$opsys" = "aix4.2" && test "x$GCC" != "xyes" && \
2318   C_SWITCH_SYSTEM="-ma -qmaxmem=4000"
2319 if test "$opsys" = "mingw32"; then
2320   case "$canonical" in
2321     x86_64-*-mingw*) C_SWITCH_SYSTEM="-mtune=generic" ;;
2322     *) C_SWITCH_SYSTEM="-mtune=pentium4" ;;
2323   esac
2325 ## gnu-linux might need -D_BSD_SOURCE on old libc5 systems.
2326 ## It is redundant in glibc2, since we define _GNU_SOURCE.
2327 AC_SUBST([C_SWITCH_SYSTEM])
2330 LIBS_SYSTEM=
2331 case "$opsys" in
2332   ## IBM's X11R5 uses -lIM and -liconv in AIX 3.2.2.
2333   aix4-2) LIBS_SYSTEM="-lrts -lIM -liconv" ;;
2335   freebsd|dragonfly) LIBS_SYSTEM="-lutil" ;;
2337   hpux*) LIBS_SYSTEM="-l:libdld.sl" ;;
2339   qnxnto) LIBS_SYSTEM="-lsocket" ;;
2341   solaris) LIBS_SYSTEM="-lsocket -lnsl" ;;
2343   ## Motif needs -lgen.
2344   unixware) LIBS_SYSTEM="-lsocket -lnsl -lelf -lgen" ;;
2346   # Haiku needs -lbsd for cfsetspeed.
2347   haiku) LIBS_SYSTEM="-lnetwork -lbsd" ;;
2348 esac
2350 AC_SUBST([LIBS_SYSTEM])
2352 ### Make sure subsequent tests use flags consistent with the build flags.
2354 if test x"${OVERRIDE_CPPFLAGS}" != x; then
2355   CPPFLAGS="${OVERRIDE_CPPFLAGS}"
2356 else
2357   CPPFLAGS="$C_SWITCH_SYSTEM $C_SWITCH_MACHINE $CPPFLAGS"
2360 # Suppress obsolescent Autoconf test for size_t; Emacs assumes C99 or better.
2361 AC_DEFUN([AC_TYPE_SIZE_T])
2362 # Likewise for obsolescent test for uid_t, gid_t; Emacs assumes them.
2363 AC_DEFUN([AC_TYPE_UID_T])
2364 ac_cv_type_gid_t=yes # AC_TYPE_GETGROUPS needs this in Autoconf 2.72.
2366 # Check for all math.h functions that Emacs uses; on some platforms,
2367 # -lm is needed for some of these functions.
2368 AC_CACHE_CHECK([for math library],
2369   [emacs_cv_lib_math],
2370   [OLD_LIBS=$LIBS
2371    AC_LINK_IFELSE(
2372      [AC_LANG_SOURCE([[
2373         #include <math.h>
2374         int
2375         main (int argc, char **argv)
2376         {
2377           double d = argc;
2378           float f = argc;
2379           int i = argc;
2380           long l = argc;
2381           d = acos (d);
2382           d = asin (d);
2383           d = atan (d);
2384           d = atan2 (d, d);
2385           d = ceil (d);
2386           d = copysign (d, d);
2387           d = cos (d);
2388           d = exp (d);
2389           d = fabs (d);
2390           d = floor (d);
2391           d = fmod (d, d);
2392           d = frexp (d, &i);
2393           d = ldexp (d, i);
2394           d = log (d);
2395           d = log10 (d);
2396           d = pow (d, d);
2397           d = rint (d);
2398           d = scalbn (d, l);
2399           d = sin (d);
2400           d = sqrt (d);
2401           d = tan (d);
2402           d = trunc (d);
2403           f = fabsf (f);
2404           f = powf (f, f);
2405           i = ilogb (d);
2406           i = signbit (d);
2407           l = lrint (d);
2408           l = lround (d);
2409           return d == f && i == l;
2410         }
2411      ]])],
2412      [emacs_cv_lib_math='none required'],
2413      [LIBS="-lm $LIBS"
2414       AC_LINK_IFELSE([],
2415         [emacs_cv_lib_math=-lm],
2416         [AC_MSG_ERROR([Math library (-lm) not found])])])
2417    LIBS=$OLD_LIBS])
2418 case $emacs_cv_lib_math in
2419   -*) LIB_MATH=$emacs_cv_lib_math;;
2420   *)  LIB_MATH=;;
2421 esac
2423 dnl Current possibilities handled by sed (aix4-2 -> aix,
2424 dnl gnu-linux -> gnu/linux, etc.):
2425 dnl gnu, gnu/linux, gnu/kfreebsd, aix, cygwin, darwin, hpux.
2426 dnl And special cases: berkeley-unix, usg-unix-v, ms-dos, windows-nt.
2427 SYSTEM_TYPE=`echo $opsys | sed -e 's/[[0-9]].*//' -e 's|-|/|'`
2429 case $opsys in
2430   cygwin )
2431     LIB_MATH=
2432     ;;
2433   darwin )
2434     ## Adding -lm confuses the dynamic linker, so omit it.
2435     LIB_MATH=
2436     ;;
2437   freebsd | dragonfly )
2438     SYSTEM_TYPE=berkeley-unix
2439     ;;
2440   gnu-linux | gnu-kfreebsd )
2441     ;;
2442   hpux10-20 | hpux11 )
2443     ;;
2444   mingw32 )
2445     LIB_MATH=
2446     SYSTEM_TYPE=windows-nt
2447     ;;
2448   netbsd | openbsd )
2449     SYSTEM_TYPE=berkeley-unix
2450     ;;
2452   solaris | unixware )
2453     SYSTEM_TYPE=usg-unix-v
2454     ;;
2456 esac
2458 AC_SUBST([LIB_MATH])
2459 AC_DEFINE_UNQUOTED([SYSTEM_TYPE], ["$SYSTEM_TYPE"],
2460   [The type of system you are compiling for; sets 'system-type'.])
2461 AC_SUBST([SYSTEM_TYPE])
2463 # Check for pw_gecos in struct passwd; this is known to be missing on
2464 # Android.
2466 AC_CHECK_MEMBERS([struct passwd.pw_gecos], [], [], [#include <pwd.h>])
2468 pre_PKG_CONFIG_CFLAGS=$CFLAGS
2469 pre_PKG_CONFIG_LIBS=$LIBS
2471 dnl pkg-config does not work when cross-compiling for Android.
2472 if test "${ANDROID}" != "yes"; then
2473   PKG_PROG_PKG_CONFIG([0.9.0])
2476 dnl EMACS_CHECK_MODULES([GSTUFF], [gtk+-2.0 >= 1.3 glib = 1.3.4])
2477 dnl acts like PKG_CHECK_MODULES([GSTUFF], [gtk+-2.0 >= 1.3 glib = 1.3.4],
2478 dnl [HAVE_GSTUFF=yes], [HAVE_GSTUFF=no]) -- see pkg-config man page --
2479 dnl except that it postprocesses CFLAGS as needed for --enable-gcc-warnings.
2480 dnl EMACS_CHECK_MODULES accepts optional 3rd and 4th arguments that
2481 dnl can take the place of the default HAVE_GSTUFF=yes and HAVE_GSTUFF=no
2482 dnl actions.
2483 AC_DEFUN([EMACS_CHECK_MODULES],
2484   [AS_IF([test -n "$ndk_INITIALIZED"],
2485     [ndk_CHECK_MODULES([$1], [$2], m4_default([$3], [HAVE_$1=yes]),
2486       m4_default([$4],[HAVE_$1=no]))],
2487     [PKG_CHECK_MODULES([$1], [$2],
2488        [$1_CFLAGS=`AS_ECHO(["$$1_CFLAGS"]) | sed -e "$edit_cflags"`
2489         m4_default([$3], [HAVE_$1=yes])],
2490        [m4_default([$4], [HAVE_$1=no])])])])
2492 dnl EMACS_CHECK_LIB(NAME, FUNCTION, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND,
2493 dnl OTHER-LIBRARIES, INCLUDES)
2494 dnl ---------------------------------------------------------------------
2495 dnl This is like AC_CHECK_LIB; however, there is no default action, and
2496 dnl when cross-configuring for Android, AC_CHECK_DECLS is called with NAME
2497 dnl and INCLUDES instead, as the library being checked against will likely
2498 dnl be built together with Emacs.
2499 AC_DEFUN([EMACS_CHECK_LIB],
2500   [AS_IF([test -n "$ndk_INITIALIZED"],
2501     [AC_CHECK_DECL([$2], [$3], [$4], [$6])],
2502     [AC_CHECK_LIB([$1], [$2], [$3], [$4], [$5])])])
2504 HAVE_SOUND=no
2505 if test "${with_sound}" != "no"; then
2506   # Sound support for GNU/Linux, the free BSDs, MinGW, and Cygwin.
2507   AC_CHECK_HEADERS([machine/soundcard.h sys/soundcard.h soundcard.h mmsystem.h],
2508     [have_sound_header=yes], [], [
2509     #ifdef __MINGW32__
2510     #define WIN32_LEAN_AND_MEAN
2511     #include <windows.h>
2512     #endif
2513     ])
2514   test "${with_sound}" = "oss" && test "${have_sound_header}" != "yes" && \
2515     AC_MSG_ERROR([OSS sound support requested but not found.])
2517   if test "${with_sound}" = "bsd-ossaudio" || test "${with_sound}" = "yes"; then
2518     # OSS emulation library used on NetBSD and OpenBSD.
2519     AC_CHECK_LIB([ossaudio], [_oss_ioctl], [LIBSOUND=-lossaudio], [LIBSOUND=])
2520     test "${with_sound}" = "bsd-ossaudio" && test -z "$LIBSOUND" && \
2521       AC_MSG_ERROR([bsd-ossaudio sound support requested but not found.])
2522     # On {Net,Open}BSD use the system audio library instead of
2523     # potentially switching to ALSA below, as ALSA on these appears to
2524     # just wrap system libraries.
2525     test "${with_sound}" = "yes" && test "$LIBSOUND" = "-lossaudio" && \
2526       with_sound="bsd-ossaudio"
2527   fi
2528   AC_SUBST([LIBSOUND])
2530   if test "${with_sound}" = "alsa" || test "${with_sound}" = "yes"; then
2531     ALSA_REQUIRED=1.0.0
2532     ALSA_MODULES="alsa >= $ALSA_REQUIRED"
2533     EMACS_CHECK_MODULES([ALSA], [$ALSA_MODULES])
2534     if test $HAVE_ALSA = yes; then
2535       LIBSOUND="$LIBSOUND $ALSA_LIBS"
2536       CFLAGS_SOUND="$CFLAGS_SOUND $ALSA_CFLAGS"
2537       AC_DEFINE([HAVE_ALSA], [1], [Define to 1 if ALSA is available.])
2538     elif test "${with_sound}" = "alsa"; then
2539       AC_MSG_ERROR([ALSA sound support requested but not found.])
2540     fi
2541   fi                            dnl with_sound = alsa|yes
2543   dnl Define HAVE_SOUND if we have sound support.  We know it works and
2544   dnl compiles only on the specified platforms.  For others, it
2545   dnl probably doesn't make sense to try.
2546   dnl FIXME So surely we should bypass this whole section if not using
2547   dnl one of these platforms?
2548   if test x$have_sound_header = xyes || test $HAVE_ALSA = yes; then
2549      case "$opsys" in
2550        dnl defined __FreeBSD__ || defined __NetBSD__ || defined __linux__
2551        dnl Adjust the --with-sound help text if you change this.
2552        gnu-linux|freebsd|netbsd|mingw32|cygwin)
2553          AC_DEFINE([HAVE_SOUND], [1], [Define to 1 if you have sound support.])
2554          HAVE_SOUND=yes
2555          ;;
2556      esac
2557   fi
2559   AC_SUBST([CFLAGS_SOUND])
2562 dnl checks for header files
2563 AC_CHECK_HEADERS_ONCE(
2564  [linux/fs.h
2565   malloc.h
2566   sys/systeminfo.h
2567   sys/sysinfo.h
2568   coff.h pty.h
2569   sys/resource.h
2570   sys/utsname.h pwd.h util.h
2571   sanitizer/lsan_interface.h
2572   sanitizer/asan_interface.h
2573   sanitizer/common_interface_defs.h])
2575 AC_CACHE_CHECK([for ADDR_NO_RANDOMIZE],
2576   [emacs_cv_personality_addr_no_randomize],
2577   [AC_COMPILE_IFELSE(
2578      [AC_LANG_PROGRAM([[#include <sys/personality.h>]],
2579                       [[personality (personality (0xffffffff)
2580                                      | ADDR_NO_RANDOMIZE)]])],
2581      [emacs_cv_personality_addr_no_randomize=yes],
2582      [emacs_cv_personality_addr_no_randomize=no])])
2583 if test $emacs_cv_personality_addr_no_randomize = yes; then
2584   AC_DEFINE([HAVE_PERSONALITY_ADDR_NO_RANDOMIZE], [1],
2585             [Define to 1 if personality flag ADDR_NO_RANDOMIZE exists.])
2588 # Note that Solaris has sys/sysinfo.h which defines struct
2589 # sysinfo as well.  To make sure that we're using GNU/Linux
2590 # sysinfo, we explicitly set one of its fields.
2591 if test "$ac_cv_header_sys_sysinfo_h" = yes; then
2592   AC_CACHE_CHECK([if Linux sysinfo may be used], [emacs_cv_linux_sysinfo],
2593   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/sysinfo.h>]],
2594                                      [[struct sysinfo si;
2595                                        si.totalram = 0;
2596                                        sysinfo (&si)]])],
2597     emacs_cv_linux_sysinfo=yes, emacs_cv_linux_sysinfo=no)])
2599   if test $emacs_cv_linux_sysinfo = yes; then
2600     AC_DEFINE([HAVE_LINUX_SYSINFO], [1],
2601       [Define to 1 if you have Linux sysinfo function.])
2602     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/sysinfo.h>]],
2603                                        [[struct sysinfo si; return si.mem_unit]])],
2604       AC_DEFINE([LINUX_SYSINFO_UNIT], [1],
2605                 [Define to 1 if Linux sysinfo sizes are in multiples of mem_unit bytes.]))
2606   fi
2609 dnl On Solaris 8 there's a compilation warning for term.h because
2610 dnl it doesn't define 'bool'.
2611 AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[#include <term.h>]],[[]])],
2612   [AC_DEFINE([HAVE_TERM_H], [1],
2613      [Define to 1 if you have the <term.h> header file.])])
2614 AC_HEADER_SYS_WAIT
2616 AC_CHECK_HEADERS_ONCE([sys/socket.h])
2617 AC_CHECK_HEADERS([net/if.h], [], [], [AC_INCLUDES_DEFAULT
2618 #if HAVE_SYS_SOCKET_H
2619 #include <sys/socket.h>
2620 #endif])
2621 AC_CHECK_HEADERS([ifaddrs.h], [], [], [AC_INCLUDES_DEFAULT
2622 #if HAVE_SYS_SOCKET_H
2623 #include <sys/socket.h>
2624 #endif])
2625 AC_CHECK_HEADERS([net/if_dl.h], [], [], [AC_INCLUDES_DEFAULT
2626 #if HAVE_SYS_SOCKET_H
2627 #include <sys/socket.h>
2628 #endif])
2630 dnl checks for structure members
2631 AC_CHECK_MEMBERS([struct ifreq.ifr_flags, struct ifreq.ifr_hwaddr,
2632                   struct ifreq.ifr_netmask, struct ifreq.ifr_broadaddr,
2633                   struct ifreq.ifr_addr,
2634                   struct ifreq.ifr_addr.sa_len], [], [],
2635                  [AC_INCLUDES_DEFAULT
2636 #if HAVE_SYS_SOCKET_H
2637 #include <sys/socket.h>
2638 #endif
2639 #if HAVE_NET_IF_H
2640 #include <net/if.h>
2641 #endif])
2643 dnl Check for endianness.
2644 dnl AC_C_BIGENDIAN is done by gnulib.
2646 dnl check for Make feature
2648 AUTO_DEPEND=no
2649 AUTODEPEND_PARENTS='lib src'
2650 dnl check if we have GCC and autodepend is on.
2651 if test "$GCC" = yes && test "$ac_enable_autodepend" = yes; then
2652    AC_CACHE_CHECK([whether gcc understands -MMD -MF], [emacs_cv_autodepend],
2653    [SAVE_CFLAGS="$CFLAGS"
2654    CFLAGS="$CFLAGS -MMD -MF deps.d -MP"
2655    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
2656      [emacs_cv_autodepend=yes], [emacs_cv_autodepend=no])
2657    CFLAGS="$SAVE_CFLAGS"
2658    test -f deps.d || emacs_cv_autodepend=no
2659    rm -rf deps.d])
2660    if test $emacs_cv_autodepend = yes; then
2661       AUTO_DEPEND=yes
2662    fi
2664 AC_SUBST([AUTO_DEPEND])
2666 #### Choose a window system.
2668 ## We leave window_system equal to none if
2669 ## we end up building without one.  Any new window system should
2670 ## set window_system to an appropriate value and add objects to
2671 ## window-system-specific substs.
2673 window_system=none
2675 ANDROID_OBJ=
2676 ANDROID_LIBS=
2677 # ANDROID_CFLAGS is a precious variable used to pass information to
2678 # the cross-compiler.
2679 ANDROID_BUILD_CFLAGS=
2680 REALLY_ANDROID=
2681 CM_OBJ="cm.o"
2683 AS_IF([test "$ANDROID" = "yes"],[
2684   window_system=android
2685   no_x=yes
2686   ANDROID_OBJ="androidterm.o androidfns.o androidfont.o androidmenu.o"
2687   ANDROID_OBJ="$ANDROID_OBJ android.o"
2688   ANDROID_LIBS=
2689   CM_OBJ=
2691   AC_DEFINE([HAVE_ANDROID], [1], [Define to 1 if Emacs is being built
2692 with Android support])
2694   AS_IF([test "$XCONFIGURE" != "android"], [
2695     AC_DEFINE([ANDROID_STUBIFY], [1], [Define to 1 if Emacs is being built
2696 for Android, but all API calls need to be stubbed out])
2698     # Now set any shared user ID that was specified.
2699     AS_IF([test -n "$with_shared_user_id"],
2700       [emacs_val=$with_shared_user_id
2701        emacs_val=`AS_ECHO(["$with_shared_user_id"]) \
2702                   | sed -e 's/"/\\"/'`
2703        emacs_val="\"$emacs_val\""
2704        ANDROID_SHARED_USER_ID="android:sharedUserId=$emacs_val"
2705        # `android:sharedUserName' is required for sharedUserID to work
2706        # on recent Android releases.  It does not otherwise affect the
2707        # behavior of any code.
2708        emacs_val="\"@string/shared_user_name\""
2709        ANDROID_SHARED_USER_NAME="android:sharedUserLabel=$emacs_val"])],[
2710     # Emacs will be built as a shared library, and a wrapper around it
2711     # will also be built for the benefit of applications.  This
2712     # requires Emacs be built as a position independent executable.
2713     ANDROID_BUILD_CFLAGS="-fPIC -fvisibility=hidden"
2715     # Graphics code in sfntfont-android.c benefits heavily from
2716     # vectorization.
2717     ANDROID_BUILD_CFLAGS="$ANDROID_BUILD_CFLAGS -ftree-vectorize"
2719     # Link with libraries required for Android support.
2720     # API 9 and later require `-landroid' for the asset manager.
2721     # API 8 uses an emulation via the JNI.
2722     AS_IF([test "$ANDROID_SDK" -lt "9"],
2723       [ANDROID_LIBS="-llog -ljnigraphics"],
2724       [ANDROID_LIBS="-landroid -llog -ljnigraphics"])
2726     # This is required to make the system load emacs.apk's libpng
2727     # (among others) instead of the system's own.  But it doesn't work
2728     # on all Android versions yet, so for now just suffix shared
2729     # libraries with _emacs.
2730     # ANDROID_LDFLAGS="-Wl,-rpath,'\$\$ORIGIN'"
2732     # Link with the sfnt font library and sfntfont.o, along with
2733     # sfntfont-android.o.
2734     ANDROID_OBJ="$ANDROID_OBJ sfnt.o sfntfont.o sfntfont-android.o"
2736     # Build androidselect.o and androidvfs.o.
2737     ANDROID_OBJ="$ANDROID_OBJ androidselect.o androidvfs.o"
2739     # Check for some functions not always present in the NDK.
2740     AC_CHECK_DECLS([android_get_device_api_level])
2742     # Mention this build is really for Android.
2743     REALLY_ANDROID=yes])])
2745 AC_SUBST([ANDROID])
2746 AC_SUBST([ANDROID_OBJ])
2747 AC_SUBST([ANDROID_LIBS])
2748 AC_SUBST([ANDROID_LDFLAGS])
2749 AC_SUBST([ANDROID_BUILD_CFLAGS])
2750 AC_SUBST([ANDROID_SHARED_USER_ID])
2751 AC_SUBST([ANDROID_SHARED_USER_NAME])
2753 if test "${with_pgtk}" = "yes"; then
2754   window_system=pgtk
2757 if test "${ANDROID}" != "yes"; then
2758   AC_PATH_X
2759   if test "$no_x" != yes && test "${with_pgtk}" != "yes"; then
2760     window_system=x11
2761   fi
2764 LD_SWITCH_X_SITE_RPATH=
2765 if test "${x_libraries}" != NONE; then
2766   if test -n "${x_libraries}"; then
2767     LD_SWITCH_X_SITE=-L`AS_ECHO(["$x_libraries"]) | sed -e 's/:/ -L/g'`
2768     LD_SWITCH_X_SITE_RPATH=-Wl,-rpath,`
2769       AS_ECHO(["$x_libraries"]) | sed -e 's/:/ -Wl,-rpath,/g'
2770     `
2771   fi
2772   x_default_search_path=""
2773   x_search_path=${x_libraries}
2774   if test -z "${x_search_path}"; then
2775     x_search_path=/usr/lib
2776   fi
2777   for x_library in `AS_ECHO(["$x_search_path:"]) | \
2778                     sed -e "s/:/ /g" -e p -e "s:/lib[[^ /]]* :/share :g"`; do
2779     x_search_path="\
2780 ${x_library}/X11/%L/%T/%N%C%S:\
2781 ${x_library}/X11/%l/%T/%N%C%S:\
2782 ${x_library}/X11/%T/%N%C%S:\
2783 ${x_library}/X11/%L/%T/%N%S:\
2784 ${x_library}/X11/%l/%T/%N%S:\
2785 ${x_library}/X11/%T/%N%S"
2786     if test x"${x_default_search_path}" = x; then
2787       x_default_search_path=${x_search_path}
2788     else
2789       x_default_search_path="${x_search_path}:${x_default_search_path}"
2790     fi
2791   done
2793 AC_SUBST([LD_SWITCH_X_SITE_RPATH])
2795 if test "${x_includes}" != NONE && test -n "${x_includes}"; then
2796   C_SWITCH_X_SITE=$isystem`AS_ECHO(["$x_includes"]) | sed -e "s/:/ $isystem/g"`
2799 if test x"${x_includes}" = x; then
2800   bitmapdir=/usr/include/X11/bitmaps
2801 else
2802   # accumulate include directories that have X11 bitmap subdirectories
2803   AS_UNSET([bmd_acc])
2804   for bmd in `AS_ECHO(["$x_includes"]) | sed -e 's/:/ /g'`; do
2805     if test -d "${bmd}/X11/bitmaps"; then
2806       bmd_acc="${bmd_acc+$bmd_acc:}${bmd}/X11/bitmaps"
2807     fi
2808     if test -d "${bmd}/bitmaps"; then
2809       bmd_acc="${bmd_acc+$bmd_acc:}${bmd}/bitmaps"
2810     fi
2811   done
2812   bitmapdir=$bmd_acc
2815 NATIVE_IMAGE_API=no
2817 test "${with_ns}" = maybe && test "${opsys}" != darwin && with_ns=no
2818 HAVE_NS=no
2819 NS_GNUSTEP_CONFIG=no
2820 NS_IMPL_COCOA=no
2821 NS_IMPL_GNUSTEP=no
2822 tmp_CPPFLAGS="$CPPFLAGS"
2823 tmp_CFLAGS="$CFLAGS"
2824 CPPFLAGS="$CPPFLAGS -x objective-c"
2825 CFLAGS="$CFLAGS -x objective-c"
2826 GNU_OBJC_CFLAGS=""
2827 LIBS_GNUSTEP=
2828 if test "${with_ns}" != no; then
2829   # macfont.o requires macuvs.h which is absent after 'make extraclean',
2830   # so avoid NS_IMPL_COCOA if macuvs.h is absent.
2831   # Even a headless Emacs can build macuvs.h, so this should let you bootstrap.
2832   if test "${opsys}" = darwin && test -f "$srcdir/src/macuvs.h"; then
2833      NS_IMPL_COCOA=yes
2834      ns_appdir=`pwd`/nextstep/Emacs.app
2835      ns_appbindir=${ns_appdir}/Contents/MacOS
2836      ns_applibexecdir=${ns_appdir}/Contents/MacOS/libexec
2837      ns_applibdir=${ns_appdir}/Contents/Frameworks
2838      ns_appresdir=${ns_appdir}/Contents/Resources
2839      ns_appsrc=Cocoa/Emacs.base
2840      ns_fontfile=macfont.o
2841   elif flags=`(gnustep-config --objc-flags) 2>/dev/null`; then
2842      NS_IMPL_GNUSTEP=yes
2843      NS_GNUSTEP_CONFIG=yes
2844      GNU_OBJC_CFLAGS="$flags"
2845      LIBS_GNUSTEP=`gnustep-config --gui-libs || exit`
2846   elif test -f $GNUSTEP_CONFIG_FILE; then
2847      NS_IMPL_GNUSTEP=yes
2848      dnl FIXME sourcing this several times in subshells seems inefficient.
2849      GNUSTEP_SYSTEM_HEADERS=`. $GNUSTEP_CONFIG_FILE \
2850        && AS_ECHO(["$GNUSTEP_SYSTEM_HEADERS"])`
2851      GNUSTEP_SYSTEM_LIBRARIES=` . $GNUSTEP_CONFIG_FILE \
2852        && AS_ECHO(["$GNUSTEP_SYSTEM_LIBRARIES"])`
2853      dnl I seemed to need these as well with GNUstep-startup 0.25.
2854      GNUSTEP_LOCAL_HEADERS=`. $GNUSTEP_CONFIG_FILE \
2855        && AS_ECHO(["$GNUSTEP_LOCAL_HEADERS"])`
2856      GNUSTEP_LOCAL_LIBRARIES=`. $GNUSTEP_CONFIG_FILE \
2857        && AS_ECHO(["$GNUSTEP_LOCAL_LIBRARIES"])`
2858      test "x${GNUSTEP_LOCAL_HEADERS}" != "x" && \
2859        GNUSTEP_LOCAL_HEADERS="-I${GNUSTEP_LOCAL_HEADERS}"
2860      test "x${GNUSTEP_LOCAL_LIBRARIES}" != "x" && \
2861        GNUSTEP_LOCAL_LIBRARIES="-L${GNUSTEP_LOCAL_LIBRARIES}"
2862      CPPFLAGS="$CPPFLAGS -isystem ${GNUSTEP_SYSTEM_HEADERS} ${GNUSTEP_LOCAL_HEADERS}"
2863      CFLAGS="$CFLAGS -isystem ${GNUSTEP_SYSTEM_HEADERS} ${GNUSTEP_LOCAL_HEADERS}"
2864      LDFLAGS="$LDFLAGS -L${GNUSTEP_SYSTEM_LIBRARIES} ${GNUSTEP_LOCAL_LIBRARIES}"
2865      LIBS_GNUSTEP="-lgnustep-gui -lgnustep-base -lobjc -lpthread"
2866      dnl GNUstep defines BASE_NATIVE_OBJC_EXCEPTIONS to 0 or 1.
2867      dnl If they had chosen to either define it or not, we could have
2868      dnl just used AC_CHECK_DECL here.
2869      AC_CACHE_CHECK([if GNUstep defines BASE_NATIVE_OBJC_EXCEPTIONS],
2870        [emacs_cv_objc_exceptions],
2871        [AC_COMPILE_IFELSE(
2872           [AC_LANG_PROGRAM([[#include <GNUstepBase/GSConfig.h>]],
2873 [[#if defined BASE_NATIVE_OBJC_EXCEPTIONS && BASE_NATIVE_OBJC_EXCEPTIONS > 0
2875 #else
2876 fail;
2877 #endif]])],
2878        [emacs_cv_objc_exceptions=yes],
2879        [emacs_cv_objc_exceptions=no])])
2880      if test $emacs_cv_objc_exceptions = yes; then
2881        dnl _NATIVE_OBJC_EXCEPTIONS is used by the GNUstep headers.
2882        AC_DEFINE([_NATIVE_OBJC_EXCEPTIONS], [1],
2883          [Define if GNUstep uses ObjC exceptions.])
2884        GNU_OBJC_CFLAGS="$GNU_OBJC_CFLAGS -fobjc-exceptions"
2885      fi
2886   fi
2887   if test $NS_IMPL_GNUSTEP = yes; then
2888      ns_appdir=`pwd`/nextstep/Emacs.app
2889      ns_appbindir=${ns_appdir}
2890      ns_applibexecdir=${ns_appdir}/libexec
2891      ns_applibdir=${ns_appdir}/Frameworks
2892      ns_appresdir=${ns_appdir}/Resources
2893      ns_appsrc=GNUstep/Emacs.base
2894      ns_fontfile=nsfont.o
2895   fi
2897   dnl This is only used while we test the NS headers, it gets reset below.
2898   CPPFLAGS="$CPPFLAGS $GNU_OBJC_CFLAGS"
2899   CFLAGS="$CFLAGS $GNU_OBJC_CFLAGS"
2901   AC_CHECK_HEADER([AppKit/AppKit.h], [HAVE_NS=yes],
2902                   [AC_MSG_ERROR([The include files (AppKit/AppKit.h etc) that
2903 are required for a Nextstep build are missing or cannot be compiled.
2904 Either fix this, or re-configure with the option '--without-ns'.])])
2906   macfont_file=""
2907   if test "${NS_IMPL_COCOA}" = "yes"; then
2908     AC_MSG_CHECKING([for Mac OS X 10.6 or newer])
2909     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <AppKit/AppKit.h>],
2910                                      [
2911 #ifdef MAC_OS_X_VERSION_MAX_ALLOWED
2912 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
2913  ; /* OK */
2914 #else
2915  error "Mac OS X 10.6 or newer required";
2916 #endif
2917 #endif
2918                     ])],
2919                     [ns_osx_have_106=yes],
2920                     [ns_osx_have_106=no])
2921     AC_MSG_RESULT([$ns_osx_have_106])
2923     if test $ns_osx_have_106 = no; then
2924        AC_MSG_ERROR([Mac OS X 10.6 or newer is required]);
2925     fi
2926   fi
2928   AC_CACHE_CHECK([for Mac OS X 12.0 or later],
2929                  [emacs_cv_macosx_12_0],
2930                  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2931 #include <AvailabilityMacros.h>
2932 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 120000
2933 Mac OS X 12.x or later.
2934 #endif
2935                  ]])], [emacs_cv_macosx_12_0=no],
2936                  [emacs_cv_macosx_12_0=yes]))
2938   if test "${with_native_image_api}" = yes; then
2939      AC_DEFINE([HAVE_NATIVE_IMAGE_API], [1],
2940        [Define to use native OS APIs for images.])
2941      NATIVE_IMAGE_API="yes (ns)"
2942   fi
2945 AC_SUBST([LIBS_GNUSTEP])
2947 INSTALL_ARCH_INDEP_EXTRA=install-etc
2948 ns_self_contained=no
2949 NS_OBJ=
2950 NS_OBJC_OBJ=
2951 if test "${HAVE_NS}" = yes; then
2952   if test "$with_toolkit_scroll_bars" = "no"; then
2953     AC_MSG_WARN([Non-toolkit scroll bars are not implemented for Nextstep.])
2954   fi
2956   window_system=nextstep
2957   # set up packaging dirs
2958   if test "${EN_NS_SELF_CONTAINED}" = yes; then
2959      AC_DEFINE([NS_SELF_CONTAINED], [1], [Build an NS bundled app])
2960      ns_self_contained=yes
2961      prefix=${ns_appresdir}
2962      exec_prefix=${ns_appbindir}
2963      dnl This one isn't really used, only archlibdir is.
2964      libexecdir="\${ns_applibexecdir}"
2965      archlibdir="\${ns_applibexecdir}"
2966      etcdocdir="\${ns_appresdir}/etc"
2967      etcdir="\${ns_appresdir}/etc"
2968      dnl FIXME maybe set datarootdir instead.
2969      dnl That would also get applications, icons, man.
2970      infodir="\${ns_appresdir}/info"
2971      mandir="\${ns_appresdir}/man"
2972      lispdir="\${ns_appresdir}/lisp"
2973      lispdirrel="\${ns_appresdir}/lisp"
2974      test "$locallisppathset" = no && locallisppath="\${ns_appresdir}/site-lisp"
2975      INSTALL_ARCH_INDEP_EXTRA=
2976   fi
2978   NS_OBJC_OBJ="nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o $ns_fontfile"
2980 CFLAGS="$tmp_CFLAGS"
2981 CPPFLAGS="$tmp_CPPFLAGS"
2982 AC_SUBST([INSTALL_ARCH_INDEP_EXTRA])
2983 AC_SUBST([ns_self_contained])
2984 AC_SUBST([NS_OBJ])
2985 AC_SUBST([NS_OBJC_OBJ])
2987 if test "${HAVE_NS}" = yes; then
2988   AC_LANG_PUSH([Objective C])
2989   AC_CACHE_CHECK(
2990     [if the Objective C compiler supports instancetype],
2991     [emacs_cv_objc_instancetype],
2992     [AC_COMPILE_IFELSE(
2993        [AC_LANG_SOURCE([[@interface Test
2994                           + (instancetype)test;
2995                           @end]])],
2996        [emacs_cv_objc_instancetype=yes],
2997        [emacs_cv_objc_instancetype=no])])
2999   if test x$emacs_cv_objc_instancetype = xyes ; then
3000     AC_DEFINE([NATIVE_OBJC_INSTANCETYPE], [1],
3001               [Define if ObjC compiler supports instancetype natively.])
3002   fi
3004   AC_CACHE_CHECK(
3005     [if the Objective C compiler defaults to C99],
3006     [emacs_cv_objc_c99],
3007     [AC_COMPILE_IFELSE(
3008        [AC_LANG_PROGRAM([], [[for (int i = 0;;);]])],
3009        [emacs_cv_objc_c99=yes],
3010        [emacs_cv_objc_c99=no])])
3012   if test x$emacs_cv_objc_c99 = xno ; then
3013     GNU_OBJC_CFLAGS="$GNU_OBJC_CFLAGS -std=c99"
3014   fi
3015   AC_LANG_POP([Objective C])
3018 HAVE_BE_APP=no
3019 if test "${opsys}" = "haiku" && test "${with_be_app}" = "yes"; then
3020    dnl Only GCC is supported.  Clang might work, but it's
3021    dnl not reliable, so don't check for it here.
3022    AC_PROG_CXX([gcc g++])
3023    CXXFLAGS="$CXXFLAGS $emacs_g3_CFLAGS"
3024    AC_LANG_PUSH([C++])
3025    AC_CHECK_HEADER([app/Application.h], [HAVE_BE_APP=yes],
3026                    [AC_MSG_ERROR([The Application Kit headers required for building
3027 with the Application Kit were not found or cannot be compiled. Either fix this, or
3028 re-configure with the option '--without-be-app'.])])
3029    AC_LANG_POP([C++])
3032 AC_SUBST([HAVE_BE_APP])
3034 HAVE_W32=no
3035 W32_OBJ=
3036 W32_LIBS=
3037 EMACSRES=
3038 CLIENTRES=
3039 CLIENTW=
3040 W32_RES_LINK=
3041 EMACS_MANIFEST=
3042 if test "${with_w32}" != no; then
3043   case "${opsys}" in
3044     cygwin)
3045       AC_CHECK_HEADER([windows.h], [HAVE_W32=yes],
3046              [AC_MSG_ERROR(['--with-w32' was specified, but windows.h
3047                    cannot be found.])])
3048     ;;
3049     mingw32)
3050     ## Using --with-w32 with MinGW is a no-op, but we allow it.
3051     ;;
3052     *)
3053       AC_MSG_ERROR([Using w32 with an autotools build is only supported for Cygwin and MinGW32.])
3054     ;;
3055   esac
3058 if test "${opsys}" = "mingw32"; then
3059   AC_CACHE_CHECK([whether Windows API headers are recent enough], [emacs_cv_w32api],
3060   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3061      #include <windows.h>
3062      #include <usp10.h>]],
3063    [[PIMAGE_NT_HEADERS pHeader;
3064      PIMAGE_SECTION_HEADER pSection = IMAGE_FIRST_SECTION(pHeader)]])],
3065    [emacs_cv_w32api=yes], [emacs_cv_w32api=no])])
3066   if test "${emacs_cv_w32api}" = "no"; then
3067     AC_MSG_ERROR([the Windows API headers are too old to support this build.])
3068   fi
3069   HAVE_W32=${emacs_cv_w32api}
3072 FIRSTFILE_OBJ=
3073 NTDIR=
3074 LIBS_ECLIENT=
3075 LIB_WSOCK32=
3076 NTLIB=
3077 XARGS_LIMIT=
3078 if test "${HAVE_W32}" = "yes"; then
3079   AC_DEFINE([HAVE_NTGUI], [1], [Define to use native MS Windows GUI.])
3080   if test "$with_toolkit_scroll_bars" = "no"; then
3081     AC_MSG_ERROR([Non-toolkit scroll bars are not implemented for w32 build.])
3082   fi
3083   AC_CHECK_TOOL([WINDRES], [windres],
3084                 [AC_MSG_ERROR([No resource compiler found.])])
3085   W32_OBJ="w32fns.o w32menu.o w32reg.o w32font.o w32term.o"
3086   W32_OBJ="$W32_OBJ w32xfns.o w32select.o w32uniscribe.o w32cygwinx.o"
3087   EMACSRES="emacs.res"
3088   case "$canonical" in
3089     x86_64-*-*) EMACS_MANIFEST="emacs-x64.manifest" ;;
3090     *) EMACS_MANIFEST="emacs-x86.manifest" ;;
3091   esac
3092   dnl Construct something of the form "24,4,0,0" with 4 components.
3093   comma_version=`echo "${PACKAGE_VERSION}.0.0" | sed -e 's/\./,/g' -e 's/^\([[^,]]*,[[^,]]*,[[^,]]*,[[^,]]*\).*/\1/'`
3095   comma_space_version=`echo "$comma_version" | sed 's/,/, /g'`
3096   AC_SUBST([comma_version])
3097   AC_SUBST([comma_space_version])
3098   AC_CONFIG_FILES([nt/emacs.rc nt/emacsclient.rc])
3099   if test "${opsys}" = "cygwin"; then
3100     W32_LIBS="$W32_LIBS -lkernel32 -luser32 -lusp10 -lgdi32"
3101     W32_LIBS="$W32_LIBS -lole32 -lcomdlg32 -lcomctl32 -lwinspool"
3102     # Tell the linker that emacs.res is an object (which we compile from
3103     # the rc file), not a linker script.
3104     W32_RES_LINK="-Wl,emacs.res"
3105   else
3106     W32_OBJ="$W32_OBJ w32.o w32console.o w32heap.o w32inevt.o w32proc.o"
3107     dnl FIXME: This should probably be supported for Cygwin/w32 as
3108     dnl well, but the Cygwin build needs to link against -lgdiplus
3109     if test "${with_native_image_api}" = yes; then
3110       AC_DEFINE([HAVE_NATIVE_IMAGE_API], [1],
3111         [Define to use native OS APIs for images.])
3112       NATIVE_IMAGE_API="yes (w32)"
3113       W32_OBJ="$W32_OBJ w32image.o"
3114     fi
3115     W32_LIBS="$W32_LIBS -lwinmm -lusp10 -lgdi32 -lcomdlg32"
3116     W32_LIBS="$W32_LIBS -lmpr -lwinspool -lole32 -lcomctl32"
3117     W32_RES_LINK="\$(EMACSRES)"
3118     CLIENTRES="emacsclient.res"
3119     CLIENTW="emacsclientw\$(EXEEXT)"
3120     FIRSTFILE_OBJ=firstfile.o
3121     NTDIR=nt
3122     CM_OBJ=
3123     LIBS_ECLIENT="-lcomctl32"
3124     LIB_WSOCK32="-lwsock32"
3125     NTLIB="ntlib.$ac_objext"
3126     XARGS_LIMIT="-s 10000"
3127   fi
3130 if test "${HAVE_W32}" = "no" && test "${opsys}" = "cygwin"; then
3131   W32_LIBS="-lkernel32"
3132   W32_OBJ="w32cygwinx.o"
3135 AC_SUBST([W32_OBJ])
3136 AC_SUBST([W32_LIBS])
3137 AC_SUBST([EMACSRES])
3138 AC_SUBST([EMACS_MANIFEST])
3139 AC_SUBST([CLIENTRES])
3140 AC_SUBST([CLIENTW])
3141 AC_SUBST([W32_RES_LINK])
3142 AC_SUBST([FIRSTFILE_OBJ])
3143 AC_SUBST([NTDIR])
3144 AC_SUBST([CM_OBJ])
3145 AC_SUBST([LIBS_ECLIENT])
3146 AC_SUBST([LIB_WSOCK32])
3147 AC_SUBST([NTLIB])
3148 AC_SUBST([XARGS_LIMIT])
3150 if test "${HAVE_W32}" = "yes"; then
3151   window_system=w32
3152   with_xft=no
3155 HAIKU_OBJ=
3156 HAIKU_CXX_OBJ=
3157 HAIKU_LIBS=
3158 HAIKU_CFLAGS=
3160 if test "$opsys" = "haiku"; then
3161   HAIKU_OBJ="$HAIKU_OBJ haiku.o"
3164 if test "${HAVE_BE_APP}" = "yes"; then
3165   AC_DEFINE([HAVE_HAIKU], [1],
3166       [Define if Emacs will be built with Haiku windowing support])
3169 if test "${HAVE_BE_APP}" = "yes"; then
3170   window_system=haiku
3171   with_xft=no
3172   HAIKU_OBJ="$HAIKU_OBJ haikufns.o haikuterm.o haikumenu.o haikufont.o haikuselect.o haiku_io.o"
3173   HAIKU_CXX_OBJ="haiku_support.o haiku_font_support.o haiku_draw_support.o haiku_select.o"
3174   HAIKU_LIBS="-lbe -lgame -ltranslation -ltracker" # -lgame is needed for set_mouse_position.
3176   if test "${with_native_image_api}" = yes; then
3177      AC_DEFINE([HAVE_NATIVE_IMAGE_API], [1],
3178        [Define to use native OS APIs for images.])
3179      NATIVE_IMAGE_API="yes (haiku)"
3180      HAIKU_OBJ="$HAIKU_OBJ haikuimage.o"
3181   fi
3184 AC_SUBST([HAIKU_LIBS])
3185 AC_SUBST([HAIKU_OBJ])
3186 AC_SUBST([HAIKU_CXX_OBJ])
3187 AC_SUBST([HAIKU_CFLAGS])
3189 ## $window_system is now set to the window system we will
3190 ## ultimately use.
3192 term_header=
3193 HAVE_X_WINDOWS=no
3194 HAVE_X11=no
3195 USE_X_TOOLKIT=none
3196 HAVE_PGTK=no
3198 case "${window_system}" in
3199   x11 )
3200     HAVE_X_WINDOWS=yes
3201     HAVE_X11=yes
3202     term_header=xterm.h
3203     case "${with_x_toolkit}" in
3204       athena | lucid ) USE_X_TOOLKIT=LUCID ;;
3205       motif ) USE_X_TOOLKIT=MOTIF ;;
3206       gtk ) with_gtk=yes
3207             term_header=gtkutil.h
3208 dnl Don't set this for GTK.  A lot of tests below assumes Xt when
3209 dnl USE_X_TOOLKIT is set.
3210             USE_X_TOOLKIT=none ;;
3211       gtk2 ) with_gtk2=yes
3212              term_header=gtkutil.h
3213              USE_X_TOOLKIT=none ;;
3214       gtk3 ) with_gtk3=yes
3215              term_header=gtkutil.h
3216              USE_X_TOOLKIT=none ;;
3217       no ) USE_X_TOOLKIT=none ;;
3218 dnl If user did not say whether to use a toolkit, make this decision later:
3219 dnl use the toolkit if we have gtk, or X11R5 or newer.
3220       * ) USE_X_TOOLKIT=maybe ;;
3221     esac
3222   ;;
3223   nextstep )
3224     term_header=nsterm.h
3225   ;;
3226   w32 )
3227     term_header=w32term.h
3228   ;;
3229   pgtk )
3230     term_header=pgtkterm.h
3231     with_gtk3=yes
3232     USE_X_TOOLKIT=none
3233     HAVE_PGTK=yes
3234     AC_DEFINE([HAVE_PGTK], [1], [Define to 1 if you have pure Gtk+-3.])
3235   ;;
3236   haiku )
3237     term_header=haikuterm.h
3238   ;;
3239   android )
3240     term_header=androidterm.h
3241   ;;
3242 esac
3244 AC_SUBST([HAVE_PGTK])
3246 if test "$window_system" = none && test "X$with_x" != "Xno"; then
3247    AC_CHECK_PROG([HAVE_XSERVER], [X], [true], [false])
3248    if test "$HAVE_XSERVER" = true ||
3249       test -n "$DISPLAY" ||
3250       {
3251         for emacs_libX11 in /usr/lib/libX11.*; do break; done
3252         test "$emacs_libX11" != '/usr/lib/libX11.*'
3253       }
3254    then
3255         AC_MSG_ERROR([You seem to be running X, but no X development libraries
3256 were found.  You should install the relevant development files for X
3257 and for the toolkit you want, such as Gtk+ or Motif.  Also make
3258 sure you have development files for image handling, i.e.
3259 tiff, gif, jpeg, png and xpm.
3260 If you are sure you want Emacs compiled without X window support, pass
3261   --without-x
3262 to configure.])
3263    fi
3266 # Does the opsystem file prohibit the use of the GNU malloc?
3267 # Assume not, until told otherwise.
3268 GNU_MALLOC=yes
3270 AC_CACHE_CHECK(
3271   [whether malloc is Doug Lea style],
3272   [emacs_cv_var_doug_lea_malloc],
3273   [emacs_cv_var_doug_lea_malloc=no
3274    dnl Hooks do not work with address sanitization.
3275    if test "$emacs_cv_sanitize_address" != yes; then
3276      AC_LINK_IFELSE(
3277        [AC_LANG_PROGRAM(
3278           [[#include <malloc.h>
3279             static void hook (void) {}]],
3280           [[malloc_set_state (malloc_get_state ());
3281             __after_morecore_hook = hook;
3282             __malloc_initialize_hook = hook;]])],
3283        [emacs_cv_var_doug_lea_malloc=yes])
3284    fi])
3285 doug_lea_malloc=$emacs_cv_var_doug_lea_malloc
3287 hybrid_malloc=
3288 system_malloc=yes
3290 dnl This must be before the test of $ac_cv_func_sbrk below.
3291 AC_CHECK_FUNCS_ONCE([sbrk])
3293 test $with_unexec = yes &&
3294 case "$opsys" in
3295   ## darwin ld insists on the use of malloc routines in the System framework.
3296   darwin | mingw32 | nacl | solaris) ;;
3297   cygwin | qnxnto | freebsd)
3298           hybrid_malloc=yes
3299           system_malloc= ;;
3300   *) test "$ac_cv_func_sbrk" = yes && system_malloc=$emacs_cv_sanitize_address;;
3301 esac
3303 if test "${system_malloc}" != yes && test "${doug_lea_malloc}" != yes \
3304    && test "${UNEXEC_OBJ}" = unexelf.o; then
3305   hybrid_malloc=yes
3308 GMALLOC_OBJ=
3309 HYBRID_MALLOC=
3310 if test "${system_malloc}" = "yes"; then
3311   AC_DEFINE([SYSTEM_MALLOC], [1],
3312     [Define to 1 to use the system memory allocator, even if it is not
3313      Doug Lea style.])
3314   GNU_MALLOC=no
3315   GNU_MALLOC_reason="
3316     (The GNU allocators don't work with this system configuration.)"
3317   VMLIMIT_OBJ=
3318 elif test "$hybrid_malloc" = yes; then
3319   AC_DEFINE([HYBRID_MALLOC], [1],
3320     [Define to use gmalloc before dumping and the system malloc after.])
3321   HYBRID_MALLOC=1
3322   GNU_MALLOC=no
3323   GNU_MALLOC_reason=" (only before dumping)"
3324   GMALLOC_OBJ=gmalloc.o
3325   VMLIMIT_OBJ=
3326 else
3327   test "$doug_lea_malloc" != "yes" && GMALLOC_OBJ=gmalloc.o
3328   VMLIMIT_OBJ=vm-limit.o
3330   AC_CHECK_HEADERS([sys/vlimit.h])
3331   AC_CACHE_CHECK([for data_start], [emacs_cv_data_start],
3332     [AC_LINK_IFELSE(
3333        [AC_LANG_PROGRAM(
3334          [[extern char data_start[]; char ch;]],
3335          [[return data_start < &ch;]])],
3336        [emacs_cv_data_start=yes],
3337        [emacs_cv_data_start=no])])
3338   if test $emacs_cv_data_start = yes; then
3339     AC_DEFINE([HAVE_DATA_START], [1],
3340       [Define to 1 if data_start is the address of the start
3341        of the main data segment.])
3342   fi
3344 AC_SUBST([HYBRID_MALLOC])
3345 AC_SUBST([GMALLOC_OBJ])
3346 AC_SUBST([VMLIMIT_OBJ])
3348 if test "$doug_lea_malloc" = "yes" && test "$hybrid_malloc" != yes; then
3349   if test "$GNU_MALLOC" = yes ; then
3350     GNU_MALLOC_reason="
3351       (Using Doug Lea's new malloc from the GNU C Library.)"
3352   fi
3353   AC_DEFINE([DOUG_LEA_MALLOC], [1],
3354     [Define to 1 if the system memory allocator is Doug Lea style,
3355      with malloc hooks and malloc_set_state.])
3357   ## Use mmap directly for allocating larger buffers.
3358   ## FIXME this comes from src/s/{gnu,gnu-linux}.h:
3359   ## #ifdef DOUG_LEA_MALLOC; #undef REL_ALLOC; #endif
3360   ## Does the AC_FUNC_MMAP test below make this check unnecessary?
3361   case "$opsys" in
3362     mingw32|gnu*) REL_ALLOC=no ;;
3363   esac
3366 if test x"${REL_ALLOC}" = x; then
3367   REL_ALLOC=${GNU_MALLOC}
3370 use_mmap_for_buffers=no
3371 case "$opsys" in
3372   mingw32) use_mmap_for_buffers=yes ;;
3373 esac
3375 AC_FUNC_MMAP
3376 if test $use_mmap_for_buffers = yes; then
3377   AC_DEFINE([USE_MMAP_FOR_BUFFERS], [1],
3378     [Define to use mmap to allocate buffer text.])
3379   REL_ALLOC=no
3382 LIBS="$LIBS_SYSTEM $LIBS"
3384 dnl FIXME replace main with a function we actually want from this library.
3385 AC_CHECK_LIB([Xbsd], [main], [LD_SWITCH_X_SITE="$LD_SWITCH_X_SITE -lXbsd"])
3387 dnl Check for the POSIX thread library.
3388 LIB_PTHREAD=
3389 AC_CHECK_HEADERS_ONCE([pthread.h])
3390 if test "$ac_cv_header_pthread_h" && test "$opsys" != "mingw32"; then
3391   AC_CACHE_CHECK([for pthread library],
3392     [emacs_cv_pthread_lib],
3393     [emacs_cv_pthread_lib=no
3394      OLD_LIBS=$LIBS
3395      for emacs_pthread_lib in 'none needed' -lpthread; do
3396        case $emacs_pthread_lib in
3397          -*) LIBS="$OLD_LIBS $emacs_pthread_lib";;
3398        esac
3399        AC_LINK_IFELSE(
3400          [AC_LANG_PROGRAM(
3401             [[#include <pthread.h>
3402               #include <signal.h>
3403               sigset_t old_mask, new_mask;
3404               void noop (void) {}]],
3405             [[pthread_t th = pthread_self ();
3406               int status = 0;
3407               status += pthread_create (&th, 0, 0, 0);
3408               status += pthread_sigmask (SIG_BLOCK, &new_mask, &old_mask);
3409               status += pthread_kill (th, 0);
3410               #if ! (defined SYSTEM_MALLOC || defined HYBRID_MALLOC \
3411                      || defined DOUG_LEA_MALLOC)
3412               /* Test for pthread_atfork only if gmalloc uses it,
3413                  as older-style hosts like MirBSD 10 lack it.  */
3414               status += pthread_atfork (noop, noop, noop);
3415               #endif
3416               return status;]])],
3417          [emacs_cv_pthread_lib=$emacs_pthread_lib])
3418        LIBS=$OLD_LIBS
3419        if test "$emacs_cv_pthread_lib" != no; then
3420          break
3421        fi
3422      done])
3423   if test "$emacs_cv_pthread_lib" != no; then
3424     AC_DEFINE([HAVE_PTHREAD], [1], [Define to 1 if you have POSIX threads.])
3425     case $emacs_cv_pthread_lib in
3426       -*) LIB_PTHREAD=$emacs_cv_pthread_lib;;
3427     esac
3428     ac_cv_func_pthread_sigmask=yes
3429     # Some systems optimize for single-threaded programs by default, and
3430     # need special flags to disable these optimizations. For example, the
3431     # definition of 'errno' in <errno.h>.
3432     case $opsys in
3433       hpux* | solaris)
3434         AC_DEFINE([_REENTRANT], [1],
3435           [Define to 1 if your system requires this in multithreaded code.]);;
3436       aix4-2)
3437         AC_DEFINE([_THREAD_SAFE], [1],
3438           [Define to 1 if your system requires this in multithreaded code.]);;
3439     esac
3440   fi
3442 AC_SUBST([LIB_PTHREAD])
3444 AC_MSG_CHECKING([for thread support])
3445 threads_enabled=no
3446 if test "$with_threads" = yes; then
3447    if test "$emacs_cv_pthread_lib" != no; then
3448       AC_DEFINE([THREADS_ENABLED], [1],
3449                 [Define to 1 if you want elisp thread support.])
3450       threads_enabled=yes
3451    elif test "${opsys}" = "mingw32"; then
3452       dnl MinGW can do native Windows threads even without pthreads
3453       AC_DEFINE([THREADS_ENABLED], [1],
3454                 [Define to 1 if you want elisp thread support.])
3455       threads_enabled=yes
3456    fi
3458 AC_MSG_RESULT([$threads_enabled])
3460 dnl Check for need for bigtoc support on IBM AIX
3462 case ${host_os} in
3463 aix*)
3464   AC_CACHE_CHECK([for -bbigtoc option], [gdb_cv_bigtoc], [
3465     case $GCC in
3466     yes) gdb_cv_bigtoc=-Wl,-bbigtoc ;;
3467     *) gdb_cv_bigtoc=-bbigtoc ;;
3468     esac
3470     LDFLAGS=$LDFLAGS\ $gdb_cv_bigtoc
3471     AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[int i;]])], [], [gdb_cv_bigtoc=])
3472   ])
3473   ;;
3474 esac
3476 # Change CFLAGS, CPPFLAGS, and LIBS temporarily so that C_SWITCH_X_SITE
3477 # is for the tests that follow.  We set them back later on.
3479 REAL_CFLAGS="$CFLAGS"
3480 REAL_CPPFLAGS="$CPPFLAGS"
3481 REAL_LIBS="$LIBS"
3483 if test "${HAVE_X11}" = "yes"; then
3484   DEFS="$C_SWITCH_X_SITE $DEFS"
3485   LDFLAGS="$LDFLAGS $LD_SWITCH_X_SITE"
3486   LIBS="-lX11 $LIBS"
3487   CFLAGS="$C_SWITCH_X_SITE $CFLAGS"
3488   CPPFLAGS="$C_SWITCH_X_SITE $CPPFLAGS"
3490   # On Solaris, arrange for LD_RUN_PATH to point to the X libraries for tests.
3491   # This is handled by LD_SWITCH_X_SITE_RPATH during the real build,
3492   # but it's more convenient here to set LD_RUN_PATH since this
3493   # also works on hosts that don't understand LD_SWITCH_X_SITE_RPATH.
3494   if test "${x_libraries}" != NONE && test -n "${x_libraries}"; then
3495     LD_RUN_PATH=$x_libraries${LD_RUN_PATH+:}$LD_RUN_PATH
3496     export LD_RUN_PATH
3497   fi
3499   # Reportedly, some broken Solaris systems have XKBlib.h but are missing
3500   # header files included from there.
3501   AC_CACHE_CHECK([for Xkb], [emacs_cv_xkb],
3502   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <X11/Xlib.h>
3503 #include <X11/XKBlib.h>]],
3504         [[XkbDescPtr kb = XkbGetKeyboard (0, XkbAllComponentsMask, XkbUseCoreKbd);]])],
3505         [emacs_cv_xkb=yes],
3506         [emacs_cv_xkb=no])])
3507   if test $emacs_cv_xkb = yes; then
3508     AC_DEFINE([HAVE_XKB], [1], [Define to 1 if you have the Xkb extension.])
3509     AC_CHECK_FUNCS([XkbRefreshKeyboardMapping XkbFreeNames])
3510   fi
3512   AC_CHECK_FUNCS([XrmSetDatabase XScreenResourceString XScreenNumberOfScreen])
3513   AC_CHECK_FUNCS([XDisplayCells XDestroySubwindows])
3516 if test "${window_system}" = "x11"; then
3517   AC_MSG_CHECKING([X11 version 6])
3518   AC_CACHE_VAL([emacs_cv_x11_version_6],
3519   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <X11/Xlib.h>]],
3520 [[#if XlibSpecificationRelease < 6
3521 fail;
3522 #endif
3523 ]])], [emacs_cv_x11_version_6=yes],
3524       [emacs_cv_x11_version_6=no])])
3525   if test $emacs_cv_x11_version_6 = yes; then
3526     AC_MSG_RESULT([6 or newer])
3527     AC_DEFINE([HAVE_X11R6], [1],
3528               [Define to 1 if you have the X11R6 or newer version of Xlib.])
3529     AC_DEFINE([HAVE_X_I18N], [1], [Define if you have usable i18n support.])
3530     AC_CHECK_MEMBERS([XICCallback.callback], [], [], [#include <X11/Xlib.h>])
3531     ## inoue@ainet.or.jp says Solaris has a bug related to X11R6-style
3532     ## XIM support.
3533     case "$opsys" in
3534       solaris) : ;;
3535       *) AC_DEFINE([HAVE_X11R6_XIM], [1],
3536            [Define if you have usable X11R6-style XIM support.])
3537          ;;
3538     esac
3539   else
3540     AC_MSG_RESULT([before 6])
3541   fi
3544 ### Use -lrsvg-2 if available, unless '--with-rsvg=no' is specified.
3545 HAVE_RSVG=no
3546 if test "${HAVE_X11}" = "yes" || test "${HAVE_NS}" = "yes" \
3547    || test "${opsys}" = "mingw32" || test "${HAVE_BE_APP}" = "yes" \
3548    || test "${window_system}" = "pgtk"; then
3549   if test "${with_rsvg}" != "no"; then
3550     RSVG_REQUIRED=2.14.0
3551     RSVG_MODULE="librsvg-2.0 >= $RSVG_REQUIRED"
3553     EMACS_CHECK_MODULES([RSVG], [$RSVG_MODULE])
3554     AC_SUBST([RSVG_CFLAGS])
3555     AC_SUBST([RSVG_LIBS])
3557     if test $HAVE_RSVG = yes; then
3558       AC_DEFINE([HAVE_RSVG], [1], [Define to 1 if using librsvg.])
3559       CFLAGS="$CFLAGS $RSVG_CFLAGS"
3560       # Windows loads librsvg dynamically
3561       if test "${opsys}" = "mingw32"; then
3562         RSVG_LIBS=
3563       fi
3564     fi
3565   fi
3568 ### Use -lwebp if available, unless '--with-webp=no'
3569 HAVE_WEBP=no
3570 if test "${with_webp}" != "no"; then
3571    if test "${HAVE_X11}" = "yes" || test "${opsys}" = "mingw32" \
3572    || test "${HAVE_W32}" = "yes" || test "${HAVE_NS}" = "yes" \
3573    || test "${HAVE_BE_APP}" = "yes" || test "${HAVE_PGTK}" = "yes" \
3574    || test "${REALLY_ANDROID}" = "yes"; then
3575       WEBP_REQUIRED=0.6.0
3576       WEBP_MODULE="libwebpdemux >= $WEBP_REQUIRED"
3578       EMACS_CHECK_MODULES([WEBP], [$WEBP_MODULE])
3580       # WebPGetInfo is sometimes not present inside libwebpdemux, so
3581       # if it does not link, also check for libwebpdecoder.
3583       OLD_CFLAGS=$CFLAGS
3584       OLD_LIBS=$LIBS
3585       CFLAGS="$CFLAGS $WEBP_CFLAGS"
3586       LIBS="$LIBS $WEBP_LIBS"
3588       AS_IF([test "$REALLY_ANDROID" != "yes"], [
3589         AC_CHECK_FUNC([WebPGetInfo], [],
3590           [WEBP_MODULE="$WEBP_MODULE libwebpdecoder >= $WEBP_REQUIRED"
3591            HAVE_WEBP=no
3592            AS_UNSET([WEBP_LIBS])
3593            AS_UNSET([WEBP_CFLAGS])
3594            EMACS_CHECK_MODULES([WEBP], [$WEBP_MODULE])])])
3596       CFLAGS=$OLD_CFLAGS
3597       LIBS=$OLD_LIBS
3599       AC_SUBST([WEBP_CFLAGS])
3600       AC_SUBST([WEBP_LIBS])
3601    fi
3602    if test $HAVE_WEBP = yes; then
3603       AC_DEFINE([HAVE_WEBP], [1], [Define to 1 if using libwebp.])
3604       # Windows loads libwebp dynamically
3605       if test "${opsys}" = "mingw32"; then
3606         WEBP_LIBS=
3607       fi
3608    fi
3611 ### Use -lsqlite3 if available, unless '--with-sqlite3=no'
3612 HAVE_SQLITE3=no
3613 SQLITE3_LIBS=
3614 SQLITE3_CFLAGS=
3615 if test "${with_sqlite3}" != "no"; then
3616    if test "${REALLY_ANDROID}" = "yes"; then
3617      ndk_SEARCH_MODULE([sqlite3], [SQLITE3], [HAVE_SQLITE3=yes])
3619      if test "$HAVE_SQLITE3" = "yes"; then
3620        SAVE_CFLAGS="$CFLAGS"
3621        CFLAGS="$CFLAGS $SQLITE3_CFLAGS"
3622        AC_CHECK_DECL([sqlite3_open_v2], [HAVE_SQLITE=yes],
3623          [HAVE_SQLITE3=no], [#include <sqlite3.h>])
3624        CFLAGS="$SAVE_CFLAGS"
3625      fi
3626    else
3627      AC_CHECK_LIB([sqlite3], [sqlite3_open_v2],
3628        [HAVE_SQLITE3=yes],
3629        [HAVE_SQLITE3=no])
3630      if test "$HAVE_SQLITE3" = "yes"; then
3631        SQLITE3_LIBS=-lsqlite3
3632        LIBS="$SQLITE3_LIBS $LIBS"
3633        # Windows loads libsqlite dynamically
3634        if test "${opsys}" = "mingw32"; then
3635           SQLITE3_LIBS=
3636        fi
3637        AC_CHECK_LIB([sqlite3], [sqlite3_load_extension],
3638          [HAVE_SQLITE3_LOAD_EXTENSION=yes],
3639          [HAVE_SQLITE3_LOAD_EXTENSION=no])
3640        if test "$HAVE_SQLITE3_LOAD_EXTENSION" = "yes"; then
3641          AC_DEFINE([HAVE_SQLITE3_LOAD_EXTENSION], [1],
3642            [Define to 1 if sqlite3 supports loading extensions.])
3643        fi
3644      fi
3645   fi
3647   if test "$HAVE_SQLITE3" = "yes"; then
3648     AC_DEFINE([HAVE_SQLITE3], [1],
3649       [Define to 1 if you have the libsqlite3 library (-lsqlite).])
3650   fi
3653 AC_SUBST([SQLITE3_LIBS])
3654 AC_SUBST([SQLITE3_CFLAGS])
3656 HAVE_IMAGEMAGICK=no
3657 if test "${HAVE_X11}" = "yes" || test "${HAVE_NS}" = "yes" || test "${HAVE_W32}" = "yes" || \
3658    test "${HAVE_BE_APP}" = "yes" || test "${window_system}" = "pgtk" || \
3659    test "${REALLY_ANDROID}" = "yes"; then
3660   if test "${with_imagemagick}" != "no"; then
3661     if test -n "$BREW"; then
3662       # Homebrew doesn't link ImageMagick 6 by default, so make sure
3663       # pkgconfig can find it.
3664       export PKG_CONFIG_PATH="$PKG_CONFIG_PATH$PATH_SEPARATOR`$BREW --prefix imagemagick@6 2>/dev/null`/lib/pkgconfig"
3665     fi
3667     EMACS_CHECK_MODULES([IMAGEMAGICK], [MagickWand >= 7])
3668     if test $HAVE_IMAGEMAGICK = yes; then
3669        AC_DEFINE([HAVE_IMAGEMAGICK7], [1],
3670          [Define to 1 if using ImageMagick7.])
3671     else
3672        ## 6.3.5 is the earliest version known to work; see Bug#17339.
3673        ## 6.8.2 makes Emacs crash; see Bug#13867.
3674        EMACS_CHECK_MODULES([IMAGEMAGICK], [Wand >= 6.3.5 Wand != 6.8.2])
3675     fi
3677     if test $HAVE_IMAGEMAGICK = yes; then
3678       OLD_CFLAGS=$CFLAGS
3679       OLD_LIBS=$LIBS
3680       CFLAGS="$CFLAGS $IMAGEMAGICK_CFLAGS"
3681       LIBS="$IMAGEMAGICK_LIBS $LIBS"
3682       if test "$REALLY_ANDROID" != "yes"; then
3683         AC_CHECK_FUNCS([MagickRelinquishMemory MagickExportImagePixels \
3684                         MagickMergeImageLayers MagickAutoOrientImage])
3685       else
3686         # AC_CHECK_FUNCS doesn't work for Android dependencies because
3687         # they are built alongside Emacs.
3688         AC_CHECK_DECLS([MagickRelinquishMemory,MagickExportImagePixels,
3689 MagickMergeImageLayers,MagickAutoOrientImage],
3690                        [], [], [#include <MagickWand/MagickWand.h>])
3691       fi
3692       CFLAGS=$OLD_CFLAGS
3693       LIBS=$OLD_LIBS
3694       # Check that ImageMagick links.  It does not link on Fedora 25
3695       # with './configure CC=clang', as pkg-config outputs flags like
3696       # -lomp that work for GCC but not Clang.
3697       if test "$ac_cv_func_MagickRelinquishMemory" != yes \
3698          && test "$REALLY_ANDROID" != "yes"; then
3699         HAVE_IMAGEMAGICK=no
3700       fi
3701     fi
3702     if test $HAVE_IMAGEMAGICK = yes; then
3703       AC_DEFINE([HAVE_IMAGEMAGICK], [1], [Define to 1 if using ImageMagick.])
3704     else
3705       if test "${with_imagemagick}" != "no"; then
3706         AC_MSG_ERROR([ImageMagick wanted, but it does not compile.  Maybe some library files are missing?]);
3707       fi
3708       IMAGEMAGICK_CFLAGS=
3709       IMAGEMAGICK_LIBS=
3710     fi
3711     AC_SUBST([IMAGEMAGICK_CFLAGS])
3712     AC_SUBST([IMAGEMAGICK_LIBS])
3713   fi
3716 AC_CHECK_LIB([anl], [getaddrinfo_a], [HAVE_GETADDRINFO_A=yes])
3717 if test "${HAVE_GETADDRINFO_A}" = "yes"; then
3718   AC_DEFINE([HAVE_GETADDRINFO_A], [1],
3719 [Define to 1 if you have getaddrinfo_a for asynchronous DNS resolution.])
3720   GETADDRINFO_A_LIBS="-lanl"
3721   AC_SUBST([GETADDRINFO_A_LIBS])
3724 HAVE_GTK=no
3725 GTK_OBJ=
3726 gtk_term_header=$term_header
3727 check_gtk2=no
3728 gtk3_pkg_errors=
3729 if test "${opsys}" != "mingw32"; then
3730   if test "${with_gtk3}" = "yes" || test "${with_gtk}" = "yes" || test "$USE_X_TOOLKIT" = "maybe"; then
3731     GLIB_REQUIRED=2.37.5
3732     if test "${window_system}" = "x11"; then
3733       GTK_REQUIRED=3.10
3734     else
3735       GTK_REQUIRED=3.22.23
3736     fi
3737     GTK_MODULES="gtk+-3.0 >= $GTK_REQUIRED glib-2.0 >= $GLIB_REQUIRED"
3739     dnl Checks for libraries.
3740     EMACS_CHECK_MODULES([GTK], [$GTK_MODULES],
3741       [pkg_check_gtk=yes], [pkg_check_gtk=no])
3742     if test "$pkg_check_gtk" = "no" && test "$with_gtk3" = "yes"; then
3743        AC_MSG_ERROR([$GTK_PKG_ERRORS])
3744     fi
3745     if test "$pkg_check_gtk" = "yes"; then
3746        AC_DEFINE([HAVE_GTK3], [1], [Define to 1 if using GTK 3 or later.])
3747        GTK_OBJ=emacsgtkfixed.o
3748        gtk_term_header=gtkutil.h
3749        USE_GTK_TOOLKIT="GTK3"
3750        if test "x$ac_enable_gtk_deprecation_warnings" = x; then
3751          AC_DEFINE([GDK_DISABLE_DEPRECATION_WARNINGS], [1],
3752            [Define to 1 to disable GTK+/GDK deprecation warnings.])
3753          AC_DEFINE([GLIB_DISABLE_DEPRECATION_WARNINGS], [1],
3754            [Define to 1 to disable Glib deprecation warnings.])
3755        fi
3756     else
3757        check_gtk2=yes
3758        gtk3_pkg_errors="$GTK_PKG_ERRORS "
3759     fi
3760   fi
3762   if test "${with_gtk2}" = "yes" || test "$check_gtk2" = "yes"; then
3763     GLIB_REQUIRED=2.28
3764     GTK_REQUIRED=2.24
3765     GTK_MODULES="gtk+-2.0 >= $GTK_REQUIRED glib-2.0 >= $GLIB_REQUIRED"
3767     dnl Checks for libraries.
3768     EMACS_CHECK_MODULES([GTK], [$GTK_MODULES],
3769       [pkg_check_gtk=yes], [pkg_check_gtk=no])
3770     if test "$pkg_check_gtk" = "no" &&
3771        { test "$with_gtk" = yes || test "$with_gtk2" = "yes"; }
3772     then
3773       AC_MSG_ERROR([$gtk3_pkg_errors$GTK_PKG_ERRORS])
3774     fi
3775     test "$pkg_check_gtk" = "yes" && USE_GTK_TOOLKIT="GTK2"
3776   fi
3779 OLD_CFLAGS=$CFLAGS
3780 OLD_LIBS=$LIBS
3782 if test x"$pkg_check_gtk" = xyes; then
3784   AC_SUBST([GTK_LIBS])
3785   CFLAGS="$CFLAGS $GTK_CFLAGS"
3786   LIBS="$GTK_LIBS $LIBS"
3787   dnl Try to compile a simple GTK program.
3788   AC_CACHE_CHECK([whether GTK compiles], [emacs_cv_gtk_compiles],
3789   [AC_LINK_IFELSE(
3790     [AC_LANG_PROGRAM(
3791        [[/* Check the Gtk and Glib APIs.  */
3792          #include <gtk/gtk.h>
3793          #include <glib-object.h>
3794          static void
3795          callback (GObject *go, GParamSpec *spec, gpointer user_data)
3796          {}
3797        ]],
3798        [[
3799          GtkSettings *gs = 0;
3800          /* Use G_CALLBACK to make sure function pointers can be cast to void *;
3801             strict C prohibits this.  Use gtk_main_iteration to test that the
3802             libraries are there.  */
3803          if (g_signal_handler_find (G_OBJECT (gs), G_SIGNAL_MATCH_FUNC,
3804                                     0, 0, 0, G_CALLBACK (callback), 0))
3805            gtk_main_iteration ();
3806        ]])],
3807     [emacs_cv_gtk_compiles=yes], [emacs_cv_gtk_compiles=no])])
3808   if test "${emacs_cv_gtk_compiles}" != "yes"; then
3809     GTK_OBJ=
3810     if test "$USE_X_TOOLKIT" != "maybe"; then
3811       AC_MSG_ERROR([Gtk+ wanted, but it does not compile, see config.log.  Maybe some x11-devel files missing?]);
3812     fi
3813   else
3814     C_SWITCH_X_SITE="$C_SWITCH_X_SITE $GTK_CFLAGS"
3815     HAVE_GTK=yes
3816     AC_DEFINE([USE_GTK], [1], [Define to 1 if using GTK.])
3817     GTK_OBJ="gtkutil.o $GTK_OBJ"
3818     term_header=$gtk_term_header
3819     USE_X_TOOLKIT=none
3820     AC_MSG_WARN([[Your version of Gtk+ will have problems with
3821        closing open displays.  This is no problem if you just use
3822        one display, but if you use more than one and close one of them
3823        Emacs may crash.
3824        See https://gitlab.gnome.org/GNOME/gtk/issues/221]])
3825   fi
3828 AC_SUBST([GTK_OBJ])
3831 if test "${HAVE_GTK}" = "yes"; then
3833   dnl  GTK scrollbars resemble toolkit scrollbars a lot, so to avoid
3834   dnl  a lot if #ifdef:s, say we have toolkit scrollbars.
3835   if test "$with_toolkit_scroll_bars" != no; then
3836     with_toolkit_scroll_bars=yes
3837   fi
3839   term_header=gtkutil.h
3841   if test "${USE_GTK_TOOLKIT}" = GTK2; then
3843     dnl  Check if we have the old file selection dialog declared and
3844     dnl  in the link library.  In 2.x it may be in the library,
3845     dnl  but not declared if deprecated featured has been selected out.
3846     dnl  AC_CHECK_DECL checks for a macro, so check for GTK_TYPE_FILE_SELECTION.
3847     HAVE_GTK_FILE_SELECTION=no
3848     AC_CHECK_DECL([GTK_TYPE_FILE_SELECTION],
3849                   [HAVE_GTK_FILE_SELECTION=yes],
3850                   [HAVE_GTK_FILE_SELECTION=no],
3851                   [AC_INCLUDES_DEFAULT
3852 #include <gtk/gtk.h>])
3853     if test "$HAVE_GTK_FILE_SELECTION" = yes; then
3854       AC_CHECK_FUNCS([gtk_file_selection_new])
3855     fi
3857     dnl This procedure causes a bug on certain Ubuntu GTK+2 builds
3858     AC_CHECK_FUNCS([gtk_window_set_has_resize_grip])
3859   fi
3862 CFLAGS=$OLD_CFLAGS
3863 LIBS=$OLD_LIBS
3865 PGTK_OBJ=
3866 PGTK_LIBS=
3867 if test "$window_system" = "pgtk"; then
3868   PGTK_OBJ="pgtkfns.o pgtkterm.o pgtkselect.o pgtkmenu.o pgtkim.o xsettings.o"
3869   PGTK_LIBS="$GTK_LIBS"
3871 AC_SUBST([PGTK_OBJ])
3872 AC_SUBST([PGTK_LIBS])
3874 AC_CHECK_FUNCS([malloc_trim])
3876 dnl D-Bus has been tested under GNU/Linux only.  Must be adapted for
3877 dnl other platforms.
3878 HAVE_DBUS=no
3879 DBUS_OBJ=
3880 if test "${with_dbus}" = "yes"; then
3881    EMACS_CHECK_MODULES([DBUS], [dbus-1 >= 1.0])
3882    if test "$HAVE_DBUS" = yes; then
3883      AC_DEFINE([HAVE_DBUS], [1], [Define to 1 if using D-Bus.])
3884      dnl dbus_watch_get_unix_fd has been introduced in D-Bus 1.1.1.
3885      dnl dbus_type_is_valid and dbus_validate_* have been introduced in
3886      dnl D-Bus 1.5.12.
3887      OLD_LIBS=$LIBS
3888      LIBS="$LIBS $DBUS_LIBS"
3889      AC_CHECK_FUNCS([dbus_watch_get_unix_fd \
3890                     dbus_type_is_valid \
3891                     dbus_validate_bus_name \
3892                     dbus_validate_path \
3893                     dbus_validate_interface \
3894                     dbus_validate_member])
3895      LIBS=$OLD_LIBS
3896      DBUS_OBJ=dbusbind.o
3897    fi
3899 AC_SUBST([DBUS_CFLAGS])
3900 AC_SUBST([DBUS_LIBS])
3901 AC_SUBST([DBUS_OBJ])
3903 dnl GSettings has been tested under GNU/Linux only.
3904 HAVE_GSETTINGS=no
3905 if test "${HAVE_X11}" = "yes" -o "${window_system}" = "pgtk" && test "${with_gsettings}" = "yes"; then
3906    EMACS_CHECK_MODULES([GSETTINGS], [gio-2.0 >= 2.26])
3907    if test "$HAVE_GSETTINGS" = "yes"; then
3908       old_CFLAGS=$CFLAGS
3909       CFLAGS="$CFLAGS $GSETTINGS_CFLAGS"
3910       old_LIBS=$LIBS
3911       LIBS="$LIBS $GSETTINGS_LIBS"
3912       AC_CACHE_CHECK([whether GSettings is in gio], [emacs_cv_gsettings_in_gio],
3913       [AC_LINK_IFELSE(
3914          [AC_LANG_PROGRAM(
3915              [[/* Check that gsettings really is present.  */
3916              #include <glib-object.h>
3917              #include <gio/gio.h>
3918              ]],
3919              [[
3920                GSettings *settings;
3921                GVariant *val = g_settings_get_value (settings, "");
3922              ]])],
3923        [emacs_cv_gsettings_in_gio=yes], [emacs_cv_gsettings_in_gio=no])])
3925       if test "$emacs_cv_gsettings_in_gio" = "yes"; then
3926         AC_DEFINE([HAVE_GSETTINGS], [1], [Define to 1 if using GSettings.])
3927         SETTINGS_CFLAGS="$GSETTINGS_CFLAGS"
3928         SETTINGS_LIBS="$GSETTINGS_LIBS"
3929         test "$with_gconf" = "yes" || with_gconf=no
3930       fi
3931       CFLAGS=$old_CFLAGS
3932       LIBS=$old_LIBS
3933    fi
3935 AC_SUBST([HAVE_GSETTINGS])
3937 dnl GConf has been tested under GNU/Linux only.
3938 dnl The version is really arbitrary, it is about the same age as Gtk+ 2.6.
3939 HAVE_GCONF=no
3940 if test "${HAVE_X11}" = "yes" -o "${window_system}" = "pgtk" && test "${with_gconf}" != "no"; then
3941    EMACS_CHECK_MODULES([GCONF], [gconf-2.0 >= 2.13])
3942    if test "$HAVE_GCONF" = yes; then
3943       AC_DEFINE([HAVE_GCONF], [1], [Define to 1 if using GConf.])
3944       dnl Newer GConf doesn't link with g_objects, so this is not defined.
3945       SETTINGS_CFLAGS="$SETTINGS_CFLAGS $GCONF_CFLAGS"
3946       SETTINGS_LIBS="$SETTINGS_LIBS $GCONF_LIBS"
3947    fi
3950 if test "$HAVE_GSETTINGS" = "yes" || test "$HAVE_GCONF" = "yes"; then
3951     EMACS_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.0])
3952     if test "$HAVE_GOBJECT" = "yes"; then
3953        SETTINGS_CFLAGS="$SETTINGS_CFLAGS $GOBJECT_CFLAGS"
3954        SETTINGS_LIBS="$SETTINGS_LIBS $GOBJECT_LIBS"
3955     fi
3956     SAVE_CFLAGS="$CFLAGS"
3957     SAVE_LIBS="$LIBS"
3958     CFLAGS="$SETTINGS_CFLAGS $CFLAGS"
3959     LIBS="$SETTINGS_LIBS $LIBS"
3960     CFLAGS="$SAVE_CFLAGS"
3961     LIBS="$SAVE_LIBS"
3963 AC_SUBST([SETTINGS_CFLAGS])
3964 AC_SUBST([SETTINGS_LIBS])
3966 USE_STARTUP_NOTIFICATION=no
3967 if test "${HAVE_GTK}" = "yes"; then
3968     USE_STARTUP_NOTIFICATION=yes
3970 AC_SUBST([USE_STARTUP_NOTIFICATION])
3972 dnl SELinux is available for Linux kernel based systems only.
3973 dnl These include GNU/Linux and Android.
3974 HAVE_LIBSELINUX=no
3975 LIBSELINUX_LIBS=
3976 LIBSELINUX_CFLAGS=
3977 if test "${with_selinux}" = "yes"; then
3978    if test "$REALLY_ANDROID" = "yes"; then
3979      ndk_SEARCH_MODULE([libselinux], [LIBSELINUX],
3980        [HAVE_LIBSELINUX=yes])
3981    else
3982      AC_CHECK_LIB([selinux], [lgetfilecon],
3983        [HAVE_LIBSELINUX=yes],
3984        [HAVE_LIBSELINUX=no])
3985    fi
3986    if test "$HAVE_LIBSELINUX" = yes; then
3987       AC_DEFINE([HAVE_LIBSELINUX], [1], [Define to 1 if using SELinux.])
3988       if test "$REALLY_ANDROID" != "yes"; then
3989         LIBSELINUX_LIBS=-lselinux
3990       fi
3991    fi
3993 AC_SUBST([LIBSELINUX_LIBS])
3994 AC_SUBST([LIBSELINUX_CFLAGS])
3996 HAVE_GNUTLS=no
3997 if test "${with_gnutls}" != "no" ; then
3998   EMACS_CHECK_MODULES([LIBGNUTLS], [gnutls >= 2.12.2],
3999     [HAVE_GNUTLS=yes], [HAVE_GNUTLS=no])
4000   if test "${HAVE_GNUTLS}" = "yes"; then
4001     AC_DEFINE([HAVE_GNUTLS], [1], [Define if using GnuTLS.])
4002   fi
4004   # Windows loads GnuTLS dynamically
4005   if test "${opsys}" = "mingw32"; then
4006     LIBGNUTLS_LIBS=
4007   fi
4010 AC_SUBST([LIBGNUTLS_LIBS])
4011 AC_SUBST([LIBGNUTLS_CFLAGS])
4013 HAVE_LIBSYSTEMD=no
4014 if test "${with_libsystemd}" = "yes" ; then
4015   dnl This code has been tested with libsystemd 222 and later.
4016   dnl FIXME: Find the earliest version number for which Emacs should work,
4017   dnl and change '222' to that number.
4018   EMACS_CHECK_MODULES([LIBSYSTEMD], [libsystemd >= 222],
4019     [HAVE_LIBSYSTEMD=yes], [HAVE_LIBSYSTEMD=no])
4020   if test "${HAVE_LIBSYSTEMD}" = "yes"; then
4021     AC_DEFINE([HAVE_LIBSYSTEMD], [1], [Define if using libsystemd.])
4022   fi
4025 AC_SUBST([LIBSYSTEMD_LIBS])
4026 AC_SUBST([LIBSYSTEMD_CFLAGS])
4028 HAVE_TREE_SITTER=no
4029 TREE_SITTER_OBJ=
4030 NEED_DYNLIB=no
4032 if test "${with_tree_sitter}" != "no"; then
4033    dnl Tree-sitter 0.20.2 added support to change the malloc it uses
4034    dnl at runtime, we need that feature.  However, tree-sitter's
4035    dnl Makefile has problems, until that's fixed, all tree-sitter
4036    dnl libraries distributed are versioned 0.6.3.  We try to
4037    dnl accept a tree-sitter library that has incorrect version as long
4038    dnl as it supports changing malloc.
4039   EMACS_CHECK_MODULES([TREE_SITTER], [tree-sitter >= 0.20.2],
4040     [HAVE_TREE_SITTER=yes], [HAVE_TREE_SITTER=no])
4041   if test "${HAVE_TREE_SITTER}" = yes; then
4042     AC_DEFINE(HAVE_TREE_SITTER, 1, [Define if using tree-sitter.])
4043     NEED_DYNLIB=yes
4044   else
4045     EMACS_CHECK_MODULES([TREE_SITTER], [tree-sitter >= 0.6.3],
4046       [HAVE_TREE_SITTER=yes], [HAVE_TREE_SITTER=no])
4047     if test "${HAVE_TREE_SITTER}" = yes; then
4048       OLD_CFLAGS=$CFLAGS
4049       OLD_LIBS=$LIBS
4050       CFLAGS="$CFLAGS $TREE_SITTER_CFLAGS"
4051       LIBS="$TREE_SITTER_LIBS $LIBS"
4052       AC_CHECK_FUNCS([ts_set_allocator])
4053       CFLAGS=$OLD_CFLAGS
4054       LIBS=$OLD_LIBS
4055       if test "$ac_cv_func_ts_set_allocator" = yes; then
4056         AC_DEFINE(HAVE_TREE_SITTER, 1, [Define if using tree-sitter.])
4057         NEED_DYNLIB=yes
4058       else
4059         AC_MSG_ERROR([Tree-sitter library exists but its version is too old]);
4060         TREE_SITTER_CFLAGS=
4061         TREE_SITTER_LIBS=
4062       fi
4063     fi
4064   fi
4066   # Windows loads tree-sitter dynamically
4067   if test "${opsys}" = "mingw32"; then
4068     TREE_SITTER_LIBS=
4069   fi
4072 AC_SUBST(TREE_SITTER_LIBS)
4073 AC_SUBST(TREE_SITTER_CFLAGS)
4075 NOTIFY_OBJ=
4076 NOTIFY_SUMMARY=no
4078 dnl MS Windows native file monitor is available for mingw32 only.
4079 case $with_file_notification,$opsys in
4080   w32,cygwin)
4081     AC_MSG_ERROR(['--with-file-notification=w32' was specified, but
4082     this is only supported on MS-Windows native and MinGW32 builds.
4083     Consider using gfile instead.])
4084     ;;
4085   w32,* | yes,mingw32)
4086     AC_CHECK_HEADER([windows.h])
4087     if test "$ac_cv_header_windows_h" = yes ; then
4088        AC_DEFINE([HAVE_W32NOTIFY], [1], [Define to 1 to use w32notify.])
4089        NOTIFY_OBJ=w32notify.o
4090        NOTIFY_SUMMARY="yes (w32)"
4091     fi ;;
4092 esac
4094 dnl inotify is available only on Linux-kernel based systems.
4095 case $with_file_notification,$NOTIFY_OBJ in
4096   inotify, | yes,)
4097     AC_CHECK_HEADER([sys/inotify.h])
4098     if test "$ac_cv_header_sys_inotify_h" = yes ; then
4099         AC_CHECK_FUNCS([inotify_init inotify_init1])
4100         if test "$ac_cv_func_inotify_init" = yes; then
4101           AC_DEFINE([HAVE_INOTIFY], [1], [Define to 1 to use inotify.])
4102           NOTIFY_OBJ=inotify.o
4103           NOTIFY_SUMMARY="yes (inotify)"
4104        fi
4105     fi ;;
4106 esac
4108 dnl kqueue is available on BSD-like systems.
4109 case $with_file_notification,$NOTIFY_OBJ in
4110   kqueue,* | yes,)
4111     EMACS_CHECK_MODULES([KQUEUE], [libkqueue])
4112     if test "$HAVE_KQUEUE" = "yes"; then
4113        AC_DEFINE([HAVE_KQUEUE], [1], [Define to 1 to use kqueue.])
4114        CPPFLAGS="$CPPFLAGS -I/usr/include/kqueue"
4115        NOTIFY_CFLAGS=$KQUEUE_CFLAGS
4116        NOTIFY_LIBS=$KQUEUE_LIBS
4117        NOTIFY_OBJ=kqueue.o
4118        NOTIFY_SUMMARY="yes -lkqueue"
4119     else
4120        AC_SEARCH_LIBS([kqueue], [])
4121        if test "$ac_cv_search_kqueue" != no; then
4122          AC_DEFINE([HAVE_KQUEUE], [1], [Define to 1 to use kqueue.])
4123          NOTIFY_OBJ=kqueue.o
4124          NOTIFY_SUMMARY="yes (kqueue)"
4125        fi
4126     fi ;;
4127 esac
4129 dnl g_file_monitor exists since glib 2.18.  G_FILE_MONITOR_EVENT_MOVED
4130 dnl has been added in glib 2.24.  It has been tested under
4131 dnl GNU/Linux only.
4132 case $with_file_notification,$NOTIFY_OBJ in
4133   gfile,* | yes,)
4134     if test "${HAVE_NS}" = yes; then
4135        AC_MSG_ERROR(['--with-file-notification=gfile' is not supported in NextStep builds.
4136 Consider kqueue instead.])
4137     else
4138        EMACS_CHECK_MODULES([GFILENOTIFY], [gio-2.0 >= 2.24])
4139        if test "$HAVE_GFILENOTIFY" = "yes"; then
4140           AC_DEFINE([HAVE_GFILENOTIFY], [1], [Define to 1 if using GFile.])
4141           NOTIFY_CFLAGS=$GFILENOTIFY_CFLAGS
4142           NOTIFY_LIBS=$GFILENOTIFY_LIBS
4143           NOTIFY_OBJ=gfilenotify.o
4144           NOTIFY_SUMMARY="yes -lgio (gfile)"
4145        fi
4146     fi ;;
4147 esac
4149 case $with_file_notification,$NOTIFY_OBJ in
4150   yes,* | no,* | *,?*) ;;
4151   *) AC_MSG_ERROR([File notification '$with_file_notification' requested but requirements not found.]) ;;
4152 esac
4154 if test -n "$NOTIFY_OBJ"; then
4155    AC_DEFINE([USE_FILE_NOTIFY], [1],
4156      [Define to 1 if using file notifications.])
4158 AC_SUBST([NOTIFY_CFLAGS])
4159 AC_SUBST([NOTIFY_LIBS])
4160 AC_SUBST([NOTIFY_OBJ])
4162 dnl Do not put whitespace before the #include statements below.
4163 dnl Older compilers (eg sunos4 cc) choke on it.
4164 HAVE_XAW3D=no
4165 LUCID_LIBW=
4166 if test x"${USE_X_TOOLKIT}" = xmaybe || test x"${USE_X_TOOLKIT}" = xLUCID; then
4167   if test "$with_xaw3d" != no; then
4168     AC_CACHE_VAL([emacs_cv_xaw3d],
4169     [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
4170 #include <X11/Intrinsic.h>
4171 #include <X11/Xaw3d/Simple.h>]],
4172       [[]])],
4173       [AC_CHECK_LIB([Xaw3d], [XawScrollbarSetThumb],
4174                     [emacs_cv_xaw3d=yes],
4175                     [emacs_cv_xaw3d=no])],
4176       [emacs_cv_xaw3d=no])])
4177   else
4178     emacs_cv_xaw3d=no
4179   fi
4180   if test $emacs_cv_xaw3d = yes; then
4181     AC_MSG_CHECKING([for xaw3d])
4182     AC_MSG_RESULT([yes; using Lucid toolkit])
4183     USE_X_TOOLKIT=LUCID
4184     HAVE_XAW3D=yes
4185     LUCID_LIBW=-lXaw3d
4186     AC_DEFINE([HAVE_XAW3D], [1],
4187               [Define to 1 if you have the Xaw3d library (-lXaw3d).])
4188   else
4189     AC_MSG_CHECKING([for xaw3d])
4190     AC_MSG_RESULT([no])
4191     AC_MSG_CHECKING([for libXaw])
4192     AC_CACHE_VAL([emacs_cv_xaw],
4193     [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
4194 #include <X11/Intrinsic.h>
4195 #include <X11/Xaw/Simple.h>]],
4196       [[]])],
4197       [emacs_cv_xaw=yes],
4198       [emacs_cv_xaw=no])])
4199     if test $emacs_cv_xaw = yes; then
4200       AC_MSG_RESULT([yes; using Lucid toolkit])
4201       USE_X_TOOLKIT=LUCID
4202       LUCID_LIBW=-lXaw
4203     elif test x"${USE_X_TOOLKIT}" = xLUCID; then
4204       AC_MSG_ERROR([Lucid toolkit requires X11/Xaw include files])
4205     else
4206       AC_MSG_ERROR([No X toolkit could be found.
4207 If you are sure you want Emacs compiled without an X toolkit, pass
4208   --with-x-toolkit=no
4209 to configure.  Otherwise, install the development libraries for the toolkit
4210 that you want to use (e.g. Gtk+) and re-run configure.])
4211     fi
4212   fi
4215 X_TOOLKIT_TYPE=$USE_X_TOOLKIT
4217 LIBXTR6=
4218 LIBXMU=
4219 if test "${USE_X_TOOLKIT}" != "none"; then
4220   AC_MSG_CHECKING([X11 toolkit version])
4221   AC_CACHE_VAL([emacs_cv_x11_toolkit_version_6],
4222   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <X11/Intrinsic.h>]],
4223 [[#if XtSpecificationRelease < 6
4224 fail;
4225 #endif
4226 ]])], [emacs_cv_x11_toolkit_version_6=yes],
4227       [emacs_cv_x11_toolkit_version_6=no])])
4228   HAVE_X11XTR6=$emacs_cv_x11_toolkit_version_6
4229   if test $emacs_cv_x11_toolkit_version_6 = yes; then
4230     AC_MSG_RESULT([6 or newer])
4231     AC_DEFINE([HAVE_X11XTR6], [1],
4232               [Define to 1 if you have the X11R6 or newer version of Xt.])
4233     LIBXTR6="-lSM -lICE"
4234     case "$opsys" in
4235       ## Use libw.a along with X11R6 Xt.
4236       unixware) LIBXTR6="$LIBXTR6 -lw" ;;
4237     esac
4238   else
4239     AC_MSG_RESULT([before 6])
4240   fi
4242 dnl If using toolkit, check whether libXmu.a exists.
4243 dnl tranle@intellicorp.com says libXmu.a can need XtMalloc in libXt.a to link.
4244   OLDLIBS="$LIBS"
4245   if test x$HAVE_X11XTR6 = xyes; then
4246     OTHERLIBS='-lXt -lSM -lICE'
4247   else
4248     OTHERLIBS='-lXt'
4249   fi
4250   AC_SEARCH_LIBS([XmuConvertStandardSelection], [Xmu], [], [], [$OTHERLIBS])
4251   if test "X$LIBS" != "X$OLDLIBS"; then
4252     LIBXMU=$ac_cv_search_XmuConvertStandardSelection
4253   fi
4254   LIBS=$OLDLIBS
4255   dnl ac_cv_search_XmuConvertStandardSelection is also referenced below.
4257 AC_SUBST([LIBXTR6])
4258 AC_SUBST([LIBXMU])
4260 LIBXP=
4261 if test "${USE_X_TOOLKIT}" = "MOTIF"; then
4262   # OpenMotif may be installed in such a way on some GNU/Linux systems.
4263   if test -d /usr/include/openmotif; then
4264     CPPFLAGS="-I/usr/include/openmotif $CPPFLAGS"
4265     emacs_cv_openmotif=yes
4266     case "$canonical" in
4267       x86_64-*-linux-gnu* | powerpc64-*-linux-gnu* | sparc64-*-linux-gnu*)
4268       test -d /usr/lib64/openmotif && LDFLAGS="-L/usr/lib64/openmotif $LDFLAGS"
4269       ;;
4270       *)
4271       test -d /usr/lib/openmotif && LDFLAGS="-L/usr/lib/openmotif $LDFLAGS"
4272     esac
4273   else
4274     emacs_cv_openmotif=no
4275   fi
4276   AC_CACHE_CHECK([for (Open)Motif version 2.1], [emacs_cv_motif_version_2_1],
4277   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <Xm/Xm.h>]],
4278     [[#if XmVERSION > 2 || (XmVERSION == 2 && XmREVISION >= 1)
4279 int x = 5;
4280 #else
4281 Motif version prior to 2.1.
4282 #endif]])],
4283      [emacs_cv_motif_version_2_1=yes],
4284      [emacs_cv_motif_version_2_1=no])])
4285   if test $emacs_cv_motif_version_2_1 = yes; then
4286     AC_CHECK_LIB([Xp], [XpCreateContext], [LIBXP=-lXp])
4287     if test x$emacs_cv_openmotif = xyes; then
4288       REAL_CPPFLAGS="-I/usr/include/openmotif $REAL_CPPFLAGS"
4289     fi
4290   else
4291     # We put this in CFLAGS temporarily to precede other -I options
4292     # that might be in CFLAGS temporarily.
4293     # We put this in CPPFLAGS where it precedes the other -I options.
4294     OLD_CPPFLAGS=$CPPFLAGS
4295     OLD_CFLAGS=$CFLAGS
4296     CPPFLAGS="-I/usr/X11R6/LessTif/Motif1.2/include $CPPFLAGS"
4297     CFLAGS="-I/usr/X11R6/LessTif/Motif1.2/include $CFLAGS"
4298     AC_CACHE_CHECK([for LessTif where some systems put it], [emacs_cv_lesstif],
4299       [AC_COMPILE_IFELSE(
4300          [AC_LANG_PROGRAM(
4301             [[#include </usr/X11R6/LessTif/Motif1.2/include/Xm/Xm.h>
4302             ]],
4303             [[int x = 5;]])],
4304          [emacs_cv_lesstif=yes],
4305          [emacs_cv_lesstif=no])])
4306     if test $emacs_cv_lesstif = yes; then
4307       # Make sure this -I option remains in CPPFLAGS after it is set
4308       # back to REAL_CPPFLAGS.
4309       # There is no need to change REAL_CFLAGS, because REAL_CFLAGS does not
4310       # have those other -I options anyway.  Ultimately, having this
4311       # directory ultimately in CPPFLAGS will be enough.
4312       REAL_CPPFLAGS="-I/usr/X11R6/LessTif/Motif1.2/include $REAL_CPPFLAGS"
4313       LDFLAGS="-L/usr/X11R6/LessTif/Motif1.2/lib $LDFLAGS"
4314     else
4315       CFLAGS=$OLD_CFLAGS
4316       CPPFLAGS=$OLD_CPPFLAGS
4317     fi
4318   fi
4319   AC_CHECK_HEADER([Xm/BulletinB.h], [],
4320     [AC_MSG_ERROR([Motif toolkit requested but requirements not found.])])
4323 dnl Use toolkit scroll bars if configured for GTK or X toolkit and either
4324 dnl using Motif or Xaw3d is available, and unless
4325 dnl --with-toolkit-scroll-bars=no was specified.
4327 AH_TEMPLATE([USE_TOOLKIT_SCROLL_BARS],
4328             [Define to 1 if we should use toolkit scroll bars.])dnl
4329 USE_TOOLKIT_SCROLL_BARS=no
4330 if test "${with_toolkit_scroll_bars}" != "no"; then
4331   if test "${USE_X_TOOLKIT}" != "none"; then
4332     if test "${USE_X_TOOLKIT}" = "MOTIF"; then
4333       AC_DEFINE([USE_TOOLKIT_SCROLL_BARS])
4334       HAVE_XAW3D=no
4335       USE_TOOLKIT_SCROLL_BARS=yes
4336     elif test "${HAVE_XAW3D}" = "yes" || test "${USE_X_TOOLKIT}" = "LUCID"; then
4337       AC_DEFINE([USE_TOOLKIT_SCROLL_BARS])
4338       USE_TOOLKIT_SCROLL_BARS=yes
4339     fi
4340   elif test "${HAVE_GTK}" = "yes"; then
4341     AC_DEFINE([USE_TOOLKIT_SCROLL_BARS])
4342     USE_TOOLKIT_SCROLL_BARS=yes
4343   elif test "${HAVE_NS}" = "yes"; then
4344     AC_DEFINE([USE_TOOLKIT_SCROLL_BARS])
4345     USE_TOOLKIT_SCROLL_BARS=yes
4346   elif test "${HAVE_W32}" = "yes"; then
4347     AC_DEFINE([USE_TOOLKIT_SCROLL_BARS])
4348     USE_TOOLKIT_SCROLL_BARS=yes
4349   elif test "${HAVE_BE_APP}" = "yes"; then
4350     AC_DEFINE([USE_TOOLKIT_SCROLL_BARS])
4351     USE_TOOLKIT_SCROLL_BARS=yes
4352   fi
4353 elif test "${window_system}" != "x11" && test "${window_system}" != "none"; then
4354   AC_MSG_ERROR([Non-toolkit scroll bars are not implemented for your system])
4357 dnl See if XIM is available.
4358 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4359           #include <X11/Xlib.h>
4360           #include <X11/Xresource.h>]],
4361          [[XIMProc  callback;]])],
4362          [HAVE_XIM=yes
4363          AC_DEFINE([HAVE_XIM], [1], [Define to 1 if XIM is available])],
4364          [HAVE_XIM=no])
4366 dnl Note this is non-standard.  --with-xim does not control whether
4367 dnl XIM support is compiled in, it only affects the runtime default of
4368 dnl use_xim in xterm.c.
4369 if test "${with_xim}" != "no"; then
4370   AC_DEFINE([USE_XIM], [1],
4371             [Define to 1 to default runtime use of XIM to on.])
4374 # Check for XRender
4375 HAVE_XRENDER=no
4376 if test "${HAVE_X11}" = "yes"; then
4377   AC_COMPILE_IFELSE(
4378     [AC_LANG_PROGRAM(
4379        [[#include <X11/Intrinsic.h>
4380          #include <X11/extensions/Xrender.h>
4381        ]],
4382        [[return !XRenderQueryExtension;]])],
4383     [AC_CHECK_LIB([Xrender], [XRenderQueryExtension], [HAVE_XRENDER=yes])])
4384   if test $HAVE_XRENDER = yes; then
4385     XRENDER_LIBS="-lXrender"
4386     AC_SUBST([XRENDER_LIBS])
4387     AC_DEFINE([HAVE_XRENDER], [1], [Define to 1 if XRender is available.])
4388   fi
4391 HAVE_CAIRO=no
4392 if test "${HAVE_X11}" = "yes"; then
4393   if test "${with_cairo}" != "no"; then
4394     CAIRO_REQUIRED=1.8.0
4395     CAIRO_MODULE="cairo >= $CAIRO_REQUIRED"
4396     EMACS_CHECK_MODULES([CAIRO], [$CAIRO_MODULE])
4397     if test $HAVE_CAIRO = yes; then
4398       AS_IF([test "x$with_cairo_xcb" = "xyes"], [
4399         CAIRO_XCB_MODULE="cairo-xcb >= $CAIRO_REQUIRED"
4400         EMACS_CHECK_MODULES([CAIRO_XCB], [$CAIRO_XCB_MODULE])
4401         AS_IF([test "x$HAVE_CAIRO_XCB" = "xyes"], [
4402           CAIRO_CFLAGS="$CAIRO_CFLAGS $CAIRO_XCB_CFLAGS"
4403           CAIRO_LIBS="$CAIRO_LIBS $CAIRO_XCB_LIBS"
4404           AC_DEFINE([USE_CAIRO_XCB], [1],
4405             [Define to 1 if cairo XCB surfaces are available.])])])
4406       AC_DEFINE([USE_CAIRO], [1], [Define to 1 if using cairo.])
4407       CFLAGS="$CFLAGS $CAIRO_CFLAGS"
4408       LIBS="$LIBS $CAIRO_LIBS"
4409       AC_SUBST([CAIRO_CFLAGS])
4410       AC_SUBST([CAIRO_LIBS])
4411     else
4412       AC_MSG_WARN([cairo requested but not found.])
4413     fi
4414   fi
4417 dnl Enable xwidgets if GTK3 and WebKitGTK+ are available.
4418 dnl Enable xwidgets if macOS Cocoa and WebKit framework are available.
4419 HAVE_XWIDGETS=no
4420 XWIDGETS_OBJ=
4421 if test "$with_xwidgets" != "no"; then
4422   if test "$USE_GTK_TOOLKIT" = "GTK3" && test "$window_system" != "none"; then
4423     WEBKIT_REQUIRED=2.12
4424     WEBKIT_MODULES="webkit2gtk-4.1 >= $WEBKIT_REQUIRED"
4425     EMACS_CHECK_MODULES([WEBKIT], [$WEBKIT_MODULES])
4426     if test "$HAVE_WEBKIT" = "no"; then
4427       WEBKIT_MODULES="webkit2gtk-4.0 >= $WEBKIT_REQUIRED"
4428       EMACS_CHECK_MODULES([WEBKIT], [$WEBKIT_MODULES])
4429     fi
4430     HAVE_XWIDGETS=$HAVE_WEBKIT
4431     XWIDGETS_OBJ="xwidget.o"
4432     if test "$HAVE_X_WINDOWS" = "yes" && test "${with_cairo}" = "no"; then
4433       CAIRO_XLIB_MODULES="cairo >= 1.8.0 cairo-xlib >= 1.8.0"
4434       EMACS_CHECK_MODULES([CAIRO_XLIB], [$CAIRO_XLIB_MODULES])
4435       if test $HAVE_CAIRO_XLIB = "yes"; then
4436         CAIRO_CFLAGS="$CAIRO_XLIB_CFLAGS"
4437         CAIRO_LIBS="$CAIRO_XLIB_LIBS"
4438         AC_SUBST([CAIRO_CFLAGS])
4439         AC_SUBST([CAIRO_LIBS])
4440       else
4441         AC_MSG_ERROR([xwidgets requested, but a suitable cairo installation wasn't found])
4442       fi
4443     fi
4444   elif test "${NS_IMPL_COCOA}" = "yes"; then
4445     dnl FIXME: Check framework WebKit2
4446     dnl WEBKIT_REQUIRED=M.m.p
4447     WEBKIT_LIBS="-Wl,-framework -Wl,WebKit"
4448     WEBKIT_CFLAGS="-I/System/Library/Frameworks/WebKit.framework/Headers"
4449     HAVE_WEBKIT="yes"
4450     HAVE_XWIDGETS=$HAVE_WEBKIT
4451     XWIDGETS_OBJ="xwidget.o"
4452     NS_OBJC_OBJ="$NS_OBJC_OBJ nsxwidget.o"
4453     dnl Update NS_OBJC_OBJ with added nsxwidget.o
4454     AC_SUBST([NS_OBJC_OBJ])
4455   else
4456     AC_MSG_ERROR([xwidgets requested, it requires GTK3 as X window toolkit or macOS Cocoa as window system.])
4457   fi
4459   test $HAVE_XWIDGETS = yes ||
4460     AC_MSG_ERROR([xwidgets requested but WebKitGTK+ or WebKit framework not found.])
4462   AC_DEFINE([HAVE_XWIDGETS], [1], [Define to 1 if you have xwidgets support.])
4464 AC_SUBST([XWIDGETS_OBJ])
4466 if test "$window_system" = "pgtk"; then
4467   CAIRO_REQUIRED=1.12.0
4468   CAIRO_MODULE="cairo >= $CAIRO_REQUIRED"
4469   EMACS_CHECK_MODULES([CAIRO], [$CAIRO_MODULE])
4470   if test $HAVE_CAIRO = yes; then
4471     AC_DEFINE([USE_CAIRO], [1], [Define to 1 if using cairo.])
4472   else
4473     AC_MSG_ERROR([cairo required but not found.])
4474   fi
4476   CFLAGS="$CFLAGS $CAIRO_CFLAGS"
4477   LIBS="$LIBS $CAIRO_LIBS"
4478   AC_SUBST([CAIRO_CFLAGS])
4479   AC_SUBST([CAIRO_LIBS])
4482 if test "${HAVE_BE_APP}" = "yes"; then
4483   if test "${with_be_cairo}" != "no"; then
4484     CAIRO_REQUIRED=1.8.0
4485     CAIRO_MODULE="cairo >= $CAIRO_REQUIRED"
4486     EMACS_CHECK_MODULES([CAIRO], [$CAIRO_MODULE])
4487     if test $HAVE_CAIRO = yes; then
4488       AC_DEFINE([USE_BE_CAIRO], [1], [Define to 1 if using cairo on Haiku.])
4489       CFLAGS="$CFLAGS $CAIRO_CFLAGS"
4490       LIBS="$LIBS $CAIRO_LIBS"
4491       AC_SUBST([CAIRO_CFLAGS])
4492       AC_SUBST([CAIRO_LIBS])
4493     else
4494       AC_MSG_WARN([cairo requested but not found.])
4495     fi
4496   fi
4499 ### Start of font-backend (under any platform) section.
4500 # (nothing here yet -- this is a placeholder)
4501 ### End of font-backend (under any platform) section.
4503 ### Start of font-backend (under X11) section.
4504 if test "${HAVE_X11}" = "yes"; then
4505   if test $HAVE_CAIRO = yes; then
4506     dnl Strict linkers fail with
4507     dnl ftfont.o: undefined reference to symbol 'FT_New_Face'
4508     dnl if -lfreetype is not specified.
4509     dnl The following is needed to set FREETYPE_LIBS.
4510     EMACS_CHECK_MODULES([FREETYPE], [freetype2])
4512     test "$HAVE_FREETYPE" = "no" && AC_MSG_ERROR([cairo requires libfreetype])
4514     EMACS_CHECK_MODULES([FONTCONFIG], [fontconfig >= 2.2.0])
4516     test "$HAVE_FONTCONFIG" = "no" &&
4517       AC_MSG_ERROR([cairo requires libfontconfig])
4518     dnl For the "Does Emacs use" message at the end.
4519     HAVE_XFT=no
4520   else
4521     ## Use -lXft if available, unless '--with-xft=no'.
4522     HAVE_XFT=maybe
4523     if test "x${with_x}" = "xno"; then
4524       with_xft="no";
4525     fi
4527     if test "$with_xft" != no; then
4528       EMACS_CHECK_MODULES([FONTCONFIG], [fontconfig >= 2.2.0])
4529       with_xft=$HAVE_FONTCONFIG
4530     fi
4532     if test "x${with_xft}" != "xno"; then
4534       EMACS_CHECK_MODULES([XFT], [xft >= 0.13.0], [], [HAVE_XFT=no])
4535       ## Because xterm.c uses XRenderQueryExtension when XFT is
4536       ## enabled, we also need to link to -lXrender.
4537       if test "$HAVE_XFT" != no && test "$HAVE_XRENDER" != no; then
4538         OLD_CPPFLAGS="$CPPFLAGS"
4539         OLD_CFLAGS="$CFLAGS"
4540         OLD_LIBS="$LIBS"
4541         CPPFLAGS="$CPPFLAGS $XFT_CFLAGS"
4542         CFLAGS="$CFLAGS $XFT_CFLAGS"
4543         LIBS="$XFT_LIBS $LIBS"
4544         AC_CHECK_HEADER([X11/Xft/Xft.h],
4545           [AC_CHECK_LIB([Xft], [XftFontOpen], [HAVE_XFT=yes],
4546              [], [$XFT_LIBS])],
4547           [],
4548           [[#include <X11/X.h>]])
4550         if test "${HAVE_XFT}" = "yes"; then
4551           AC_DEFINE([HAVE_XFT], [1], [Define to 1 if you have the Xft library.])
4552             AC_SUBST([XFT_LIBS])
4553           C_SWITCH_X_SITE="$C_SWITCH_X_SITE $XFT_CFLAGS"
4554         fi                        # "${HAVE_XFT}" = "yes"
4555         CPPFLAGS=$OLD_CPPFLAGS
4556         CFLAGS=$OLD_CFLAGS
4557         LIBS=$OLD_LIBS
4558       else
4559       # Make sure XFT is disabled if we found XFT but not XRender
4560         HAVE_XFT=no
4561       fi                          # "$HAVE_XFT" != no
4562     fi                            # "x${with_xft}" != "xno"
4564     if test "$HAVE_XFT" != "yes"; then
4565        dnl For the "Does Emacs use" message at the end.
4566        HAVE_XFT=no
4567        HAVE_FREETYPE=no
4568     else
4569        dnl Strict linkers fail with
4570        dnl ftfont.o: undefined reference to symbol 'FT_New_Face'
4571        dnl if -lfreetype is not specified.
4572        dnl The following is needed to set FREETYPE_LIBS.
4573        EMACS_CHECK_MODULES([FREETYPE], [freetype2])
4575        test "$HAVE_FREETYPE" = "no" &&
4576          AC_MSG_ERROR([libxft requires libfreetype])
4577     fi
4578   fi                              # $HAVE_CAIRO != yes
4580   HAVE_LIBOTF=no
4581   if test "${HAVE_FREETYPE}" = "yes"; then
4582     AC_DEFINE([HAVE_FREETYPE], [1],
4583               [Define to 1 if using the freetype and fontconfig libraries.])
4584     OLD_CFLAGS=$CFLAGS
4585     OLD_LIBS=$LIBS
4586     CFLAGS="$CFLAGS $FREETYPE_CFLAGS"
4587     LIBS="$FREETYPE_LIBS $LIBS"
4588     AC_CHECK_FUNCS([FT_Face_GetCharVariantIndex])
4589     CFLAGS=$OLD_CFLAGS
4590     LIBS=$OLD_LIBS
4591     if test "${with_libotf}" != "no"; then
4592       EMACS_CHECK_MODULES([LIBOTF], [libotf])
4593       if test "$HAVE_LIBOTF" = "yes"; then
4594         AC_DEFINE([HAVE_LIBOTF], [1], [Define to 1 if using libotf.])
4595         AC_CHECK_LIB([otf], [OTF_get_variation_glyphs],
4596                      [HAVE_OTF_GET_VARIATION_GLYPHS=yes],
4597                      [HAVE_OTF_GET_VARIATION_GLYPHS=no])
4598         if test "${HAVE_OTF_GET_VARIATION_GLYPHS}" = "yes"; then
4599           AC_DEFINE([HAVE_OTF_GET_VARIATION_GLYPHS], [1],
4600                     [Define to 1 if libotf has OTF_get_variation_glyphs.])
4601         fi
4602         if $PKG_CONFIG --atleast-version=0.9.16 libotf; then :; else
4603           AC_DEFINE([HAVE_OTF_KANNADA_BUG], [1],
4604 [Define to 1 if libotf is affected by https://debbugs.gnu.org/28110.])
4605         fi
4606       fi
4607     fi
4608   dnl FIXME should there be an error if HAVE_FREETYPE != yes?
4609   dnl Does the new font backend require it, or can it work without it?
4610   fi
4612   HAVE_M17N_FLT=no
4613   if test "${HAVE_LIBOTF}" = yes; then
4614     if test "${with_m17n_flt}" != "no"; then
4615       EMACS_CHECK_MODULES([M17N_FLT], [m17n-flt])
4616       if test "$HAVE_M17N_FLT" = "yes"; then
4617         AC_DEFINE([HAVE_M17N_FLT], [1], [Define to 1 if using libm17n-flt.])
4618       fi
4619     fi
4620   fi
4621 else # "${HAVE_X11}" != "yes"
4622   if test $window_system = pgtk; then
4623     EMACS_CHECK_MODULES([FONTCONFIG], [fontconfig >= 2.2.0])
4624     EMACS_CHECK_MODULES([FREETYPE], [freetype2])
4625     if test "$HAVE_FONTCONFIG" != yes -o "$HAVE_FREETYPE" != yes; then
4626       AC_MSG_ERROR([fontconfig and freetype is required.])
4627     fi
4628     HAVE_LIBOTF=no
4629     AC_DEFINE([HAVE_FREETYPE], [1],
4630               [Define to 1 if using the freetype and fontconfig libraries.])
4631     if test "${with_libotf}" != "no"; then
4632       EMACS_CHECK_MODULES([LIBOTF], [libotf])
4633       if test "$HAVE_LIBOTF" = "yes"; then
4634         AC_DEFINE([HAVE_LIBOTF], [1], [Define to 1 if using libotf.])
4635         AC_CHECK_LIB([otf], [OTF_get_variation_glyphs],
4636                      [HAVE_OTF_GET_VARIATION_GLYPHS=yes],
4637                      [HAVE_OTF_GET_VARIATION_GLYPHS=no])
4638         if test "${HAVE_OTF_GET_VARIATION_GLYPHS}" = "yes"; then
4639           AC_DEFINE([HAVE_OTF_GET_VARIATION_GLYPHS], [1],
4640                     [Define to 1 if libotf has OTF_get_variation_glyphs.])
4641         fi
4642       fi
4643     fi
4644   else
4645     HAVE_XFT=no
4646     HAVE_FREETYPE=no
4647     HAVE_LIBOTF=no
4648     HAVE_M17N_FLT=no
4649   fi
4650 fi   # "${HAVE_X11}" != "yes"
4652 HAVE_HARFBUZZ=no
4653 ### On MS-Windows we use hb_font_get_nominal_glyph, which appeared
4654 ### in HarfBuzz version 1.2.3
4655 if test "${HAVE_W32}" = "yes"; then
4656   harfbuzz_required_ver=1.2.3
4657 else
4658   harfbuzz_required_ver=0.9.42
4660 if test "${HAVE_X11}" = "yes" && test "${HAVE_FREETYPE}" = "yes" \
4661         || test "$window_system" = "pgtk" \
4662         || test "${HAVE_W32}" = "yes" \
4663         || test "$REALLY_ANDROID" = "yes"; then
4664   if test "${with_harfbuzz}" != "no"; then
4665     EMACS_CHECK_MODULES([HARFBUZZ], [harfbuzz >= $harfbuzz_required_ver])
4666     AS_IF([test "$HAVE_HARFBUZZ" = "yes"],[
4667       AC_DEFINE([HAVE_HARFBUZZ], [1], [Define to 1 if using HarfBuzz.])
4668       ### mingw32 and Cygwin-w32 don't use -lharfbuzz, since they load
4669       ### the library dynamically.
4670       AS_IF([test "${HAVE_W32}" = "yes"], [HARFBUZZ_LIBS=])
4671       ## Now check for `hb_font_set_var_named_instance'.
4672       OLD_CFLAGS=$CFLAGS
4673       CFLAGS="$HARFBUZZ_CFLAGS $CFLAGS"
4674       EMACS_CHECK_LIB([harfbuzz], [hb_font_set_var_named_instance],
4675         [AC_DEFINE([HAVE_HB_FONT_SET_VAR_NAMED_INSTANCE], [1],
4676           [Define to 1 if `hb_font_set_var_named_instance' is present.])],
4677         [], [$HARFBUZZ_LIBS], [#include <hb.h>])
4678       CFLAGS=$OLD_CFLAGS])
4679   fi
4682 ### Start of font-backend (under Haiku) selectionn.
4683 if test "${HAVE_BE_APP}" = "yes"; then
4684   if test $HAVE_CAIRO = "yes"; then
4685       EMACS_CHECK_MODULES([FREETYPE], [freetype2 >= 2.5.0])
4686       test "$HAVE_FREETYPE" = "no" &&
4687         AC_MSG_ERROR([cairo on Haiku requires libfreetype])
4688       EMACS_CHECK_MODULES([FONTCONFIG], [fontconfig >= 2.2.0])
4689       test "$HAVE_FONTCONFIG" = "no" &&
4690         AC_MSG_ERROR([cairo on Haiku requires libfontconfig])
4691   fi
4693   HAVE_LIBOTF=no
4695   if test "${HAVE_FREETYPE}" = "yes"; then
4696     AC_DEFINE([HAVE_FREETYPE], [1],
4697               [Define to 1 if using the freetype and fontconfig libraries.])
4698     OLD_CFLAGS=$CFLAGS
4699     OLD_LIBS=$LIBS
4700     CFLAGS="$CFLAGS $FREETYPE_CFLAGS"
4701     LIBS="$FREETYPE_LIBS $LIBS"
4702     AC_CHECK_FUNCS([FT_Face_GetCharVariantIndex])
4703     CFLAGS=$OLD_CFLAGS
4704     LIBS=$OLD_LIBS
4705     if test "${with_libotf}" != "no"; then
4706       EMACS_CHECK_MODULES([LIBOTF], [libotf])
4707       if test "$HAVE_LIBOTF" = "yes"; then
4708         AC_DEFINE([HAVE_LIBOTF], [1], [Define to 1 if using libotf.])
4709         AC_CHECK_LIB([otf], [OTF_get_variation_glyphs],
4710                      [HAVE_OTF_GET_VARIATION_GLYPHS=yes],
4711                      [HAVE_OTF_GET_VARIATION_GLYPHS=no])
4712         if test "${HAVE_OTF_GET_VARIATION_GLYPHS}" = "yes"; then
4713           AC_DEFINE([HAVE_OTF_GET_VARIATION_GLYPHS], [1],
4714                     [Define to 1 if libotf has OTF_get_variation_glyphs.])
4715         fi
4716         if $PKG_CONFIG --atleast-version=0.9.16 libotf; then :; else
4717           AC_DEFINE([HAVE_OTF_KANNADA_BUG], [1],
4718 [Define to 1 if libotf is affected by https://debbugs.gnu.org/28110.])
4719         fi
4720       fi
4721     fi
4722   dnl FIXME should there be an error if HAVE_FREETYPE != yes?
4723   dnl Does the new font backend require it, or can it work without it?
4724   fi
4727 if test "${HAVE_BE_APP}" = "yes" && test "${HAVE_FREETYPE}" = "yes"; then
4728   if test "${with_harfbuzz}" != "no"; then
4729     EMACS_CHECK_MODULES([HARFBUZZ], [harfbuzz >= $harfbuzz_required_ver])
4730     if test "$HAVE_HARFBUZZ" = "yes"; then
4731       AC_DEFINE([HAVE_HARFBUZZ], [1], [Define to 1 if using HarfBuzz.])
4732     fi
4733   fi
4736 ### End of font-backend section.
4738 AC_SUBST([FREETYPE_CFLAGS])
4739 AC_SUBST([FREETYPE_LIBS])
4740 AC_SUBST([FONTCONFIG_CFLAGS])
4741 AC_SUBST([FONTCONFIG_LIBS])
4742 AC_SUBST([HARFBUZZ_CFLAGS])
4743 AC_SUBST([HARFBUZZ_LIBS])
4744 AC_SUBST([LIBOTF_CFLAGS])
4745 AC_SUBST([LIBOTF_LIBS])
4746 AC_SUBST([M17N_FLT_CFLAGS])
4747 AC_SUBST([M17N_FLT_LIBS])
4749 XCB_LIBS=
4750 if test "${HAVE_X11}" = "yes"; then
4751   AC_CHECK_HEADER([X11/Xlib-xcb.h],
4752     [AC_CHECK_LIB([xcb], [xcb_translate_coordinates], [HAVE_XCB=yes])])
4753   if test "${HAVE_XCB}" = "yes"; then
4754     AC_CHECK_LIB([X11-xcb], [XGetXCBConnection], [HAVE_X11_XCB=yes])
4755     if test "${HAVE_X11_XCB}" = "yes"; then
4756       AC_DEFINE([USE_XCB], [1],
4757 [Define to 1 if you have the XCB library and X11-XCB library for mixed
4758 X11/XCB programming.])
4759       XCB_LIBS="-lX11-xcb -lxcb"
4760     fi
4761   fi
4763 AC_SUBST([XCB_LIBS])
4765 ### Use -lXpm if available, unless '--with-xpm=no'.
4766 ### mingw32 doesn't use -lXpm, since it loads the library dynamically.
4767 ### The Cygwin-w32 build uses <noX/xpm.h> instead of <X11/xpm.h>, so
4768 ### we need to set LDFLAGS accordingly.
4769 HAVE_XPM=no
4770 LIBXPM=
4771 if test "${HAVE_W32}" = "yes" && test "${opsys}" = "cygwin"; then
4772   if test "${with_xpm}" != "no"; then
4773     SAVE_LDFLAGS="$LDFLAGS"
4774     LDFLAGS="$LDFLAGS -L/usr/lib/noX"
4775     AC_CHECK_HEADER([noX/xpm.h],
4776       [AC_CHECK_LIB([Xpm], [XpmReadFileToImage], [HAVE_XPM=yes])])
4777     if test "${HAVE_XPM}" = "yes"; then
4778       AC_CACHE_CHECK([for XpmReturnAllocPixels preprocessor define],
4779       [emacs_cv_cpp_xpm_return_alloc_pixels],
4780       [AC_EGREP_CPP([no_return_alloc_pixels],
4781       [#include "noX/xpm.h"
4782 #ifndef XpmReturnAllocPixels
4783 no_return_alloc_pixels
4784 #endif
4785       ], [emacs_cv_cpp_xpm_return_alloc_pixels=no],
4786          [emacs_cv_cpp_xpm_return_alloc_pixels=yes])])
4788       if test "$emacs_cv_cpp_xpm_return_alloc_pixels" = "no"; then
4789         HAVE_XPM=no
4790         LDFLAGS="$SAVE_LDFLAGS"
4791       fi
4792     fi
4793   fi
4795   if test "${HAVE_XPM}" = "yes"; then
4796     AC_DEFINE([HAVE_XPM], [1],
4797       [Define to 1 if you have the Xpm library (-lXpm).])
4798     LIBXPM=-lXpm
4799   fi
4802 if test "${HAVE_X11}" = "yes"; then
4803   dnl Avoid Xpm on AIX unless requested, as it crashes; see Bug#17598.
4804   case $opsys,$with_xpm_set,$with_xpm in
4805     aix4-2,set,yes) ;;
4806     aix4-2,*) with_xpm=no;;
4807   esac
4809   if test "${with_xpm}" != "no"; then
4810     AC_CHECK_HEADER([X11/xpm.h],
4811       [AC_CHECK_LIB([Xpm], [XpmReadFileToPixmap],
4812          [HAVE_XPM=yes], [], [-lX11])])
4813     if test "${HAVE_XPM}" = "yes"; then
4814       AC_CACHE_CHECK([for XpmReturnAllocPixels preprocessor define],
4815       [emacs_cv_cpp_xpm_return_alloc_pixels],
4816       [AC_EGREP_CPP([no_return_alloc_pixels],
4817       [#include "X11/xpm.h"
4818 #ifndef XpmReturnAllocPixels
4819 no_return_alloc_pixels
4820 #endif
4821       ], [emacs_cv_cpp_xpm_return_alloc_pixels=no],
4822          [emacs_cv_cpp_xpm_return_alloc_pixels=yes])])
4824       if test "$emacs_cv_cpp_xpm_return_alloc_pixels" = "no"; then
4825         HAVE_XPM=no
4826       fi
4827     fi
4828   fi
4830   if test "${HAVE_XPM}" = "yes"; then
4831     AC_DEFINE([HAVE_XPM], [1],
4832       [Define to 1 if you have the Xpm library (-lXpm).])
4833     LIBXPM=-lXpm
4834   elif test "$opsys,$LUCID_LIBW" = aix4-2,-lXaw; then
4835     dnl AIX -lXaw needs -lXpm linked too; see Bug#17598 Message#152.
4836     LIBXPM=-lXpm
4837   fi
4840 ### FIXME: Perhaps regroup to minimize code duplication due to MinGW's
4841 ### slightly different requirements wrt image libraries (it doesn't
4842 ### use -lXpm because it loads the xpm shared library dynamically at
4843 ### run time).
4844 if test "${opsys}" = "mingw32"; then
4845   if test "${with_xpm}" != "no"; then
4846     AC_CHECK_HEADER([X11/xpm.h], [HAVE_XPM=yes], [HAVE_XPM=no], [
4847 #define FOR_MSW 1])
4848   fi
4850   if test "${HAVE_XPM}" = "yes"; then
4851     AC_DEFINE([HAVE_XPM], [1],
4852       [Define to 1 if you have the Xpm library (-lXpm).])
4853   fi
4856 AC_SUBST([LIBXPM])
4858 ### Use -ljpeg if available, unless '--with-jpeg=no'.
4859 HAVE_JPEG=no
4860 LIBJPEG=
4861 JPEG_CFLAGS=
4862 if test "${HAVE_X11}" = "yes" || test "${HAVE_W32}" = "yes" \
4863    || test "${HAVE_NS}" = "yes" || test "${HAVE_BE_APP}" = "yes" \
4864    || test "$window_system" = "pgtk" \
4865    || test "${REALLY_ANDROID}" = "yes"; then
4866   if test "${with_jpeg}" != "no"; then
4867     if test "${REALLY_ANDROID}" = "yes"; then
4868       # Look for libjpeg using the NDK.
4869       ndk_SEARCH_MODULE([libjpeg], [JPEG], [HAVE_JPEG=yes])
4871       if test "$HAVE_JPEG" = "yes"; then
4872         LIBJPEG="$JPEG_LIBS"
4874         AC_DEFINE([HAVE_JPEG], [1],
4875           [Define to 1 if you have the jpeg library (typically -ljpeg).])
4876       fi
4877     else
4878       AC_CACHE_CHECK([for jpeglib 6b or later],
4879         [emacs_cv_jpeglib],
4880         [OLD_LIBS=$LIBS
4881          for emacs_cv_jpeglib in yes -ljpeg no; do
4882            case $emacs_cv_jpeglib in
4883              yes) ;;
4884              no) break;;
4885              *) LIBS="$LIBS $emacs_cv_jpeglib";;
4886            esac
4887            AC_LINK_IFELSE(
4888              [AC_LANG_PROGRAM(
4889                 [[#undef HAVE_STDLIB_H /* Avoid config.h/jpeglib.h collision.  */
4890                   #include <stdio.h> /* jpeglib.h needs FILE and size_t.  */
4891                   #include <jpeglib.h>
4892                   #include <jerror.h>
4893                   char verify[JPEG_LIB_VERSION < 62 ? -1 : 1];
4894                   struct jpeg_decompress_struct cinfo;
4895                 ]],
4896                 [[
4897                   jpeg_create_decompress (&cinfo);
4898                   WARNMS (&cinfo, JWRN_JPEG_EOF);
4899                   jpeg_destroy_decompress (&cinfo);
4900                 ]])],
4901              [emacs_link_ok=yes],
4902              [emacs_link_ok=no])
4903            LIBS=$OLD_LIBS
4904            test $emacs_link_ok = yes && break
4905          done])
4906       if test "$emacs_cv_jpeglib" != no; then
4907         HAVE_JPEG=yes
4908         AC_DEFINE([HAVE_JPEG], [1],
4909           [Define to 1 if you have the jpeg library (typically -ljpeg).])
4910         ### mingw32 doesn't use -ljpeg, since it loads the library
4911         ### dynamically when needed, and doesn't want a run-time
4912         ### dependency on the jpeglib DLL.
4913         test "$emacs_cv_jpeglib" != yes && test "${opsys}" != "mingw32" \
4914         && LIBJPEG=$emacs_cv_jpeglib
4915       fi
4916     fi
4917   fi
4919 AC_SUBST([LIBJPEG])
4920 AC_SUBST([JPEG_CFLAGS])
4922 HAVE_LCMS2=no
4923 LCMS2_CFLAGS=
4924 LCMS2_LIBS=
4925 if test "${with_lcms2}" != "no"; then
4926   EMACS_CHECK_MODULES([LCMS2], [lcms2])
4928 if test "${HAVE_LCMS2}" = "yes"; then
4929   AC_DEFINE([HAVE_LCMS2], [1],
4930     [Define to 1 if you have the lcms2 library (-llcms2).])
4931   ### mingw32 doesn't use -llcms2, since it loads the library dynamically.
4932   if test "${opsys}" = "mingw32"; then
4933      LCMS2_LIBS=
4934   fi
4936 AC_SUBST([LCMS2_CFLAGS])
4937 AC_SUBST([LCMS2_LIBS])
4939 HAVE_ZLIB=no
4940 LIBZ=
4941 if test "${with_zlib}" != "no"; then
4942   OLIBS=$LIBS
4943   AC_SEARCH_LIBS([inflateEnd], [z], [HAVE_ZLIB=yes])
4944   LIBS=$OLIBS
4945   case $ac_cv_search_inflateEnd in
4946     -*) LIBZ=$ac_cv_search_inflateEnd ;;
4947   esac
4949 if test "${HAVE_ZLIB}" = "yes"; then
4950   AC_DEFINE([HAVE_ZLIB], [1],
4951     [Define to 1 if you have the zlib library (-lz).])
4952   ### mingw32 doesn't use -lz, since it loads the library dynamically.
4953   if test "${opsys}" = "mingw32"; then
4954      LIBZ=
4955   fi
4957 AC_SUBST([LIBZ])
4959 ### Dynamic library support
4960 case $opsys in
4961   cygwin|mingw32) DYNAMIC_LIB_SUFFIX=".dll" ;;
4962   darwin) DYNAMIC_LIB_SUFFIX=".dylib" ;;
4963   *) DYNAMIC_LIB_SUFFIX=".so" ;;
4964 esac
4965 case "${opsys}" in
4966   darwin) DYNAMIC_LIB_SECONDARY_SUFFIX='.so' ;;
4967   *) DYNAMIC_LIB_SECONDARY_SUFFIX='' ;;
4968 esac
4969 AC_DEFINE_UNQUOTED(DYNAMIC_LIB_SUFFIX, "$DYNAMIC_LIB_SUFFIX",
4970   [System extension for dynamic libraries])
4971 AC_DEFINE_UNQUOTED(DYNAMIC_LIB_SECONDARY_SUFFIX, "$DYNAMIC_LIB_SECONDARY_SUFFIX",
4972   [Alternative system extension for dynamic libraries.])
4974 AC_SUBST(DYNAMIC_LIB_SUFFIX)
4975 AC_SUBST(DYNAMIC_LIB_SECONDARY_SUFFIX)
4977 ### Dynamic modules support
4978 LIBMODULES=
4979 HAVE_MODULES=no
4980 MODULES_OBJ=
4981 MODULES_SUFFIX="${DYNAMIC_LIB_SUFFIX}"
4982 MODULES_SECONDARY_SUFFIX="${DYNAMIC_LIB_SECONDARY_SUFFIX}"
4984 # pgtkterm.c uses dlsym
4985 if test $window_system = pgtk; then
4986   case $opsys in
4987     gnu|gnu-linux)
4988     LIBMODULES="-ldl"
4989     ;;
4990   esac
4993 AS_IF([test "x$with_modules" != "xno"],
4994   [AS_CASE(["$opsys"],
4995     [gnu|gnu-linux],
4996       [LIBMODULES="-ldl"
4997        HAVE_MODULES=yes],
4998     [cygwin|mingw32|darwin],
4999       [HAVE_MODULES=yes],
5000     # BSD systems have dlopen in libc.
5001     [AC_CHECK_FUNC([dlopen], [HAVE_MODULES=yes])])
5003   AS_IF([test "x$HAVE_MODULES" = "xno"],
5004     [AS_IF([test "$with_modules" = "ifavailable"],
5005       [AC_MSG_WARN([Dynamic modules are not supported on your system])],
5006       [AC_MSG_ERROR([Dynamic modules are not supported on your system])])],
5007     [SAVE_LIBS=$LIBS
5008      LIBS="$LIBS $LIBMODULES"
5009      AC_CHECK_FUNCS([dladdr dlfunc])
5010      LIBS=$SAVE_LIBS])])
5012 AS_IF([test "x$HAVE_MODULES" = xyes],
5013    [MODULES_OBJ="emacs-module.o"
5014     NEED_DYNLIB=yes
5015     AC_DEFINE([HAVE_MODULES], [1], [Define to 1 if dynamic modules are enabled])
5016     AC_DEFINE_UNQUOTED([MODULES_SUFFIX], ["$MODULES_SUFFIX"],
5017       [System extension for dynamic libraries])
5018     AS_IF([test -n "$MODULES_SECONDARY_SUFFIX"],
5019       [AC_DEFINE_UNQUOTED([MODULES_SECONDARY_SUFFIX],
5020         ["$MODULES_SECONDARY_SUFFIX"],
5021         [Alternative system extension for dynamic libraries.])])])
5023 AC_SUBST([MODULES_OBJ])
5024 AC_SUBST([LIBMODULES])
5025 AC_SUBST([HAVE_MODULES])
5026 AC_SUBST([MODULES_SUFFIX])
5027 AC_SUBST([MODULES_SECONDARY_SUFFIX])
5029 ARCH_INDEPENDENT_CONFIG_FILES([src/emacs-module.h])
5030 AC_SUBST_FILE([module_env_snippet_25])
5031 AC_SUBST_FILE([module_env_snippet_26])
5032 AC_SUBST_FILE([module_env_snippet_27])
5033 AC_SUBST_FILE([module_env_snippet_28])
5034 AC_SUBST_FILE([module_env_snippet_29])
5035 AC_SUBST_FILE([module_env_snippet_30])
5036 module_env_snippet_25="$srcdir/src/module-env-25.h"
5037 module_env_snippet_26="$srcdir/src/module-env-26.h"
5038 module_env_snippet_27="$srcdir/src/module-env-27.h"
5039 module_env_snippet_28="$srcdir/src/module-env-28.h"
5040 module_env_snippet_29="$srcdir/src/module-env-29.h"
5041 module_env_snippet_30="$srcdir/src/module-env-30.h"
5042 emacs_major_version=`AS_ECHO([$PACKAGE_VERSION]) | sed 's/[[.]].*//'`
5043 AC_SUBST([emacs_major_version])
5045 ### Emacs Lisp native compiler support
5047 AC_DEFUN([libgccjit_smoke_test], [
5048   AC_LANG_SOURCE(
5049     [[#include <libgccjit.h>
5050       #include <stdlib.h>
5051       #include <stdio.h>
5052       int
5053       main (int argc, char **argv)
5054       {
5055         gcc_jit_context *ctxt;
5056         gcc_jit_result *result;
5057         ctxt = gcc_jit_context_acquire ();
5058         if (!ctxt)
5059           exit (1);
5060         gcc_jit_type *int_type =
5061           gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
5062         gcc_jit_function *func =
5063           gcc_jit_context_new_function (ctxt, NULL,
5064                                         GCC_JIT_FUNCTION_EXPORTED,
5065                                         int_type, "foo", 0, NULL, 0);
5066         gcc_jit_block *block = gcc_jit_function_new_block (func, "foo");
5067         gcc_jit_block_end_with_return (
5068           block,
5069           NULL,
5070           gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 1));
5071         result = gcc_jit_context_compile (ctxt);
5072         if (!result)
5073           exit (1);
5074         typedef int (*fn_type) (void);
5075         fn_type foo =
5076           (fn_type)gcc_jit_result_get_code (result, "foo");
5077         if (!foo)
5078           exit (1);
5079         if (foo () != 1)
5080           exit (1);
5081         gcc_jit_context_release (ctxt);
5082         gcc_jit_result_release (result);
5083         return 0;
5084       }]])])
5086 AC_DEFUN([libgccjit_not_found_err], [
5087   AC_MSG_ERROR([ELisp native compiler was requested, but libgccjit was not found.
5088 Please try installing libgccjit or a similar package.
5089 If you are sure you want Emacs be compiled without ELisp native compiler,
5090 pass the --without-native-compilation option to configure.])])
5092 AC_DEFUN([libgccjit_dev_not_found_err], [
5093   AC_MSG_ERROR([ELisp native compiler was requested, but libgccjit header files were
5094 not found.
5095 Please try installing libgccjit-dev or a similar package.
5096 If you are sure you want Emacs be compiled without ELisp native compiler,
5097 pass the --without-native-compilation option to configure.])])
5099 AC_DEFUN([libgccjit_broken_err], [
5100   AC_MSG_ERROR([The installed libgccjit failed to compile and run a test program using
5101 the libgccjit library; see config.log for the details of the failure.
5102 The test program can be found here:
5103 <https://gcc.gnu.org/onlinedocs/jit/intro/tutorial01.html>.
5104 You can try compiling it yourself to investigate the issues.
5105 Please report the issue to your distribution if libgccjit was installed
5106 through that.
5107 You can find the instructions on how to compile and install libgccjit from
5108 source on this site:
5109 <https://gcc.gnu.org/wiki/JIT>.])])
5111 HAVE_NATIVE_COMP=no
5112 LIBGCCJIT_LIBS=
5113 LIBGCCJIT_CFLAGS=
5114 if test "$canonical" = i686-pc-cygwin; then
5115   if test "${with_cygwin32_native_compilation}" = yes; then
5116     with_native_compilation=yes
5117   elif test "${with_native_compilation}" != no; then
5118     AC_MSG_ERROR([Native compilation is not supported on 32-bit Cygwin.
5119 If you really want to try it anyway, use the configure option
5120 '--with-cygwin32-native-compilation'.])
5121   fi
5124 AC_DEFUN([libgccjit_not_found], [
5125   AC_MSG_WARN([Elisp native compiler can't be enabled as libgccjit was not
5126 found.
5127 Please try installing libgccjit or a similar package if you want to have it
5128 enabled.])
5130   with_native_compilation=no
5133 AC_DEFUN([libgccjit_dev_not_found], [
5134   AC_MSG_WARN([Elisp native compiler can't be enabled as libgccjit header files
5135 were not found.
5136 Please try installing libgccjit-dev or a similar package if you want to have it
5137 enabled.])
5139   with_native_compilation=no
5142 AC_DEFUN([libgccjit_broken], [
5143   AC_MSG_WARN([Elisp native compiler can't be enabled as the installed libgccjit
5144 failed to compile and run a test program using the libgccjit library; see
5145 config.log for the details of the failure.
5146 The test program can be found here:
5147 <https://gcc.gnu.org/onlinedocs/jit/intro/tutorial01.html>.
5148 You can try compiling it yourself to investigate the issues.
5149 Please report the issue to your distribution if libgccjit was installed
5150 through that.
5151 You can find the instructions on how to compile and install libgccjit from
5152 source on this site:
5153 <https://gcc.gnu.org/wiki/JIT>.])
5155   with_native_compilation=no])
5157 if test "$with_features" = "no" \
5158    && test "${with_native_compilation}" = "default"; then
5159   with_native_compilation=no
5162 if test "${with_native_compilation}" = "default"; then
5163     # Check if libgccjit is available.
5164     AC_CHECK_LIB([gccjit], [gcc_jit_context_acquire],
5165       [], [libgccjit_not_found])
5166     AC_CHECK_HEADERS([libgccjit.h], [], [libgccjit_dev_not_found])
5167     if test "${with_native_compilation}" != "no"; then
5168       # Check if libgccjit really works.
5169       AC_RUN_IFELSE([libgccjit_smoke_test], [], [libgccjit_broken])
5170     fi
5171     if test "$with_unexec" = yes; then
5172       with_native_compilation=no
5173     fi
5176 if test "${with_native_compilation}" != "no"; then
5177     if test "$with_unexec" = yes; then
5178        AC_MSG_ERROR(['--with-native-compilation' is not compatible with unexec])
5179     fi
5180     if test "${HAVE_ZLIB}" = no; then
5181        AC_MSG_ERROR(['--with-native-compilation' requires zlib])
5182     fi
5184     SAVE_CFLAGS=$CFLAGS
5185     SAVE_LIBS=$LIBS
5187     if test "${opsys}" = "darwin"; then
5188       # Ensure libgccjit installed by Homebrew or macports can be found.
5189       if test -n "$BREW"; then
5190         if test -n "`$BREW --prefix --installed libgccjit 2>/dev/null`"; then
5191           MAC_CFLAGS="-I$(dirname $($BREW ls -v libgccjit | \
5192                                                 grep libgccjit.h))"
5193           MAC_LIBS="-L$(dirname $($BREW ls -v libgccjit \
5194                                   | grep -m1 -E 'libgccjit\.(so|dylib)$'))"
5195         fi
5196       fi
5198       if test -n "$HAVE_MACPORTS"; then
5199         # Determine which gcc version has been installed (gcc11, for
5200         # instance). Use the latest version, if more than one is
5201         # available.  (We filter out the gcc4 packages, because they
5202         # don't support jit, and they have names like "gcc49" that
5203         # sort later than "gcc11".)
5204         PORT_PACKAGE=`port installed active | grep '^ *gcc@<:@0-9@:>@* ' | \
5205                             awk '{ print $1; }' | grep -v 'gcc4@<:@0-9@:>@' | \
5206                             sort -V | tail -n 1`
5207         if test -n "$PORT_PACKAGE"; then
5208           emacs_val=`port contents $PORT_PACKAGE | grep libgccjit.h`
5209           emacs_val=`dirname $emacs_val`
5210           MAC_CFLAGS="-I$emacs_val"
5211           emacs_val=`port contents $PORT_PACKAGE | grep libgccjit.dylib`
5212           emacs_val=`dirname $emacs_val`
5213           MAC_LIBS="-L$emacs_val"
5214         fi
5215       fi
5217       if test -n "$MAC_CFLAGS" && test -n "$MAC_LIBS"; then
5218         CFLAGS="$CFLAGS ${MAC_CFLAGS}"
5219         LIBS="$LIBS ${MAC_LIBS}"
5220       fi
5221     fi
5223     # In the default case we already checked
5224     if test "${with_native_compilation}" != "default"; then
5225       # Check if libgccjit is available.
5226       AC_CHECK_LIB([gccjit], [gcc_jit_context_acquire],
5227         [], [libgccjit_not_found_err])
5228       AC_CHECK_HEADERS([libgccjit.h], [], [libgccjit_dev_not_found_err])
5229       # Check if libgccjit really works.
5230       AC_RUN_IFELSE([libgccjit_smoke_test], [], [libgccjit_broken_err])
5231     fi
5232     HAVE_NATIVE_COMP=yes
5233     case "${opsys}" in
5234       # mingw32 loads the library dynamically.
5235       mingw32) ;;
5236       # Neither NetBSD, OpenBSD nor Haiku have libdl, with all dynamic
5237       # linker functions placed within libc.
5238       netbsd|openbsd|haiku)
5239         LIBGCCJIT_LIBS="-lgccjit" ;;
5240       darwin)
5241         LIBGCCJIT_CFLAGS="${MAC_CFLAGS}"
5242         LIBGCCJIT_LIBS="${MAC_LIBS} -lgccjit -ldl";;
5243       *)
5244         LIBGCCJIT_LIBS="-lgccjit -ldl" ;;
5245     esac
5246     NEED_DYNLIB=yes
5247     AC_DEFINE([HAVE_NATIVE_COMP], [1],
5248       [Define to 1 if native compiler is available.])
5250     CFLAGS=$SAVE_CFLAGS
5251     LIBS=$SAVE_LIBS
5253 AC_DEFINE_UNQUOTED([NATIVE_ELISP_SUFFIX], [".eln"],
5254   [System extension for native compiled elisp])
5255 AC_SUBST([HAVE_NATIVE_COMP])
5256 AC_SUBST([LIBGCCJIT_CFLAGS])
5257 AC_SUBST([LIBGCCJIT_LIBS])
5259 DYNLIB_OBJ=
5260 if test "${NEED_DYNLIB}" = yes; then
5261   DYNLIB_OBJ="dynlib.o"
5263 AC_SUBST([DYNLIB_OBJ])
5265 ### Use -lpng if available, unless '--with-png=no'.
5266 HAVE_PNG=no
5267 LIBPNG=
5268 PNG_CFLAGS=
5269 if test "${with_png}" != no; then
5270   # mingw32 loads the library dynamically.
5271   if test "$opsys" = mingw32; then
5272     AC_CHECK_HEADER([png.h], [HAVE_PNG=yes])
5273   elif test "${HAVE_X11}" = "yes" || test "${HAVE_W32}" = "yes" \
5274        || test "${HAVE_NS}" = "yes" || test "${HAVE_BE_APP}" = "yes" \
5275        || test "$window_system" = "pgtk" \
5276        || test "${REALLY_ANDROID}" = "yes"; then
5277     EMACS_CHECK_MODULES([PNG], [libpng >= 1.0.0])
5278     if test $HAVE_PNG = yes; then
5279       LIBPNG=$PNG_LIBS
5280     else
5281       # Test old way in case pkg-config doesn't have it (older machines).
5282       AC_MSG_CHECKING([for libpng not configured by pkg-config])
5284       png_cflags=`(libpng-config --cflags) 2>&AS_MESSAGE_LOG_FD` &&
5285       png_ldflags=`(libpng-config --ldflags) 2>&AS_MESSAGE_LOG_FD` || {
5286         # libpng-config does not work; configure by hand.
5287         # Debian unstable as of July 2003 has multiple libpngs, and puts png.h
5288         # in /usr/include/libpng.
5289         if test -r /usr/include/libpng/png.h &&
5290            test ! -r /usr/include/png.h; then
5291           png_cflags=-I/usr/include/libpng
5292         else
5293           png_cflags=
5294         fi
5295         png_ldflags='-lpng'
5296       }
5297       SAVE_CFLAGS=$CFLAGS
5298       SAVE_LIBS=$LIBS
5299       CFLAGS="$CFLAGS $png_cflags"
5300       LIBS="$png_ldflags -lz -lm $LIBS"
5301       AC_LINK_IFELSE(
5302         [AC_LANG_PROGRAM([[#include <png.h>]],
5303            [[return !png_get_channels (0, 0);]])],
5304         [HAVE_PNG=yes
5305          PNG_CFLAGS=`AS_ECHO(["$png_cflags"]) | sed -e "$edit_cflags"`
5306          LIBPNG=$png_ldflags])
5307       CFLAGS=$SAVE_CFLAGS
5308       LIBS=$SAVE_LIBS
5309       AC_MSG_RESULT([$HAVE_PNG])
5310     fi
5312     # $LIBPNG requires explicit -lz in some cases.
5313     # We don't know what those cases are, exactly, so play it safe and
5314     # append -lz to any nonempty $LIBPNG, unless we're already using LIBZ.
5315     case " $LIBPNG ",$LIBZ in
5316       *' -lz '*, | *' ',?*) ;;
5317       *) LIBPNG="$LIBPNG -lz" ;;
5318     esac
5319   fi
5321 if test $HAVE_PNG = yes; then
5322   AC_DEFINE([HAVE_PNG], [1], [Define to 1 if you have the png library.])
5324   SAVE_CFLAGS=$CFLAGS
5325   CFLAGS="$CFLAGS $PNG_CFLAGS"
5326   AC_CHECK_DECL([png_longjmp],
5327     [],
5328     [AC_DEFINE([PNG_DEPSTRUCT], [],
5329        [Define to empty to suppress deprecation warnings when building
5330         with --enable-gcc-warnings and with libpng versions before 1.5,
5331         which lack png_longjmp.])],
5332     [[#include <png.h>
5333     ]])
5334   CFLAGS=$SAVE_CFLAGS
5336 AC_SUBST([LIBPNG])
5337 AC_SUBST([PNG_CFLAGS])
5339 ### Use -ltiff if available, unless '--with-tiff=no'.
5340 ### mingw32 doesn't use -ltiff, since it loads the library dynamically.
5341 HAVE_TIFF=no
5342 LIBTIFF=
5343 TIFF_CFLAGS=
5344 if test "${opsys}" = "mingw32"; then
5345   if test "${with_tiff}" != "no"; then
5346     AC_CHECK_HEADER([tiffio.h], [HAVE_TIFF=yes], [HAVE_TIFF=no])
5347   fi
5348   if test "${HAVE_TIFF}" = "yes"; then
5349     AC_DEFINE([HAVE_TIFF], [1],
5350       [Define to 1 if you have the tiff library (-ltiff).])
5351   fi
5352 elif test "${HAVE_X11}" = "yes" || test "${HAVE_W32}" = "yes" \
5353      || test "${HAVE_NS}" = "yes" || test "${HAVE_BE_APP}" = "yes" \
5354      || test "$window_system" = "pgtk" \
5355      || test "${REALLY_ANDROID}" = "yes"; then
5356   if test "${with_tiff}" != "no"; then
5357     if test "${REALLY_ANDROID}" != "yes"; then
5358       AC_CHECK_HEADER([tiffio.h],
5359         [tifflibs="-lz -lm"
5360         # At least one tiff package requires the jpeg library.
5361         if test "${HAVE_JPEG}" = yes; then tifflibs="-ljpeg $tifflibs"; fi
5362         AC_CHECK_LIB([tiff], [TIFFGetVersion], [HAVE_TIFF=yes], [],
5363           [$tifflibs])])
5364     else
5365       ndk_SEARCH_MODULE([libtiff], [TIFF], [HAVE_TIFF=yes])
5367       if test "$HAVE_TIFF" = "yes"; then
5368         LIBTIFF="$TIFF_LIBS"
5369       fi
5370     fi
5371   fi
5373   if test "${HAVE_TIFF}" = "yes"; then
5374     AC_DEFINE([HAVE_TIFF], [1],
5375       [Define to 1 if you have the tiff library (-ltiff).])
5377     if test "$REALLY_ANDROID" != "yes"; then
5378       dnl FIXME -lz -lm, as per libpng?
5379       LIBTIFF=-ltiff
5380     fi
5381   fi
5383 AC_SUBST([LIBTIFF])
5384 AC_SUBST([TIFF_CFLAGS])
5386 ### Use -lgif or -lungif if available, unless '--with-gif=no'.
5387 ### mingw32 doesn't use -lgif/-lungif, since it loads the library dynamically.
5388 HAVE_GIF=no
5389 GIF_CFLAGS=
5390 LIBGIF=
5391 if test "${opsys}" = "mingw32"; then
5392   if test "${with_gif}" != "no"; then
5393     AC_CHECK_HEADER([gif_lib.h], [HAVE_GIF=yes], [HAVE_GIF=no])
5394   fi
5395   if test "${HAVE_GIF}" = "yes"; then
5396     AC_DEFINE([HAVE_GIF], [1],
5397       [Define to 1 if you have a gif (or ungif) library.])
5398   fi
5399 elif test "${HAVE_X11}" = "yes" && test "${with_gif}" != "no" \
5400         || test "${HAVE_W32}" = "yes" || test "${HAVE_NS}" = "yes" \
5401         || test "${HAVE_BE_APP}" = "yes" || test "$window_system" = "pgtk" \
5402         || test "${REALLY_ANDROID}" = "yes" \
5403         && test "${with_gif}" != "no"; then
5404   AC_CHECK_HEADER([gif_lib.h],
5405 # EGifPutExtensionLast only exists from version libungif-4.1.0b1.
5406 # Earlier versions can crash Emacs, but version 5.0 removes EGifPutExtensionLast.
5407     [AC_CHECK_LIB([gif], [GifMakeMapObject], [HAVE_GIF=yes],
5408         [AC_CHECK_LIB([gif], [EGifPutExtensionLast],
5409            [HAVE_GIF=yes],
5410            [HAVE_GIF=maybe])])])
5412   if test "$HAVE_GIF" = yes; then
5413     LIBGIF=-lgif
5414   elif test "$HAVE_GIF" = maybe; then
5415 # If gif_lib.h but no libgif, try libungif.
5416     AC_CHECK_LIB([ungif], [EGifPutExtensionLast],
5417       [HAVE_GIF=yes],
5418       [HAVE_GIF=no])
5419     test "$HAVE_GIF" = yes && LIBGIF=-lungif
5420   fi
5422 # Finally, try ndk-build on Android.
5423   if test "$REALLY_ANDROID" = "yes"; then
5424     ndk_SEARCH_MODULE([libgif], [GIF], [HAVE_GIF=yes],
5425       [HAVE_GIF=no])
5426     test "$HAVE_GIF" = yes && LIBGIF="$GIF_LIBS"
5427   fi
5429   if test "${HAVE_GIF}" = "yes"; then
5430     AC_DEFINE([HAVE_GIF], [1],
5431       [Define to 1 if you have a gif (or ungif) library.])
5432   fi
5434 AC_SUBST([LIBGIF])
5435 AC_SUBST([GIF_CFLAGS])
5437 dnl Check for required libraries.
5438 MISSING=
5439 WITH_IFAVAILABLE=
5440 if test "${HAVE_X11}" = "yes"; then
5441   case $with_xpm,$HAVE_XPM in
5442     no,* | ifavailable,* | *,yes) ;;
5443     *) MISSING="libXpm"
5444        WITH_IFAVAILABLE="--with-xpm=ifavailable";;
5445   esac
5446   case $with_jpeg,$HAVE_JPEG in
5447     no,* | ifavailable,* | *,yes) ;;
5448     *) MISSING="$MISSING libjpeg"
5449        WITH_IFAVAILABLE="$WITH_IFAVAILABLE --with-jpeg=ifavailable";;
5450   esac
5451   case $with_png,$HAVE_PNG in
5452     no,* | ifavailable,* | *,yes) ;;
5453     *) MISSING="$MISSING libpng"
5454        WITH_IFAVAILABLE="$WITH_IFAVAILABLE --with-png=ifavailable";;
5455   esac
5456   case $with_gif,$HAVE_GIF in
5457     no,* | ifavailable,* | *,yes) ;;
5458     *) MISSING="$MISSING libgif/libungif"
5459        WITH_IFAVAILABLE="$WITH_IFAVAILABLE --with-gif=ifavailable";;
5460   esac
5461   case $with_tiff,$HAVE_TIFF in
5462     no,* | ifavailable,* | *,yes) ;;
5463     *) MISSING="$MISSING libtiff"
5464        WITH_IFAVAILABLE="$WITH_IFAVAILABLE --with-tiff=ifavailable";;
5465   esac
5467 case $with_gnutls,$HAVE_GNUTLS in
5468   no,* | ifavailable,* | *,yes) ;;
5469   *) MISSING="$MISSING gnutls"
5470      WITH_IFAVAILABLE="$WITH_IFAVAILABLE --with-gnutls=ifavailable";;
5471 esac
5472 case $with_tree_sitter,$HAVE_TREE_SITTER in
5473   no,* | ifavailable,* | *,yes) ;;
5474   *) MISSING="$MISSING tree-sitter"
5475      WITH_IFAVAILABLE="$WITH_IFAVAILABLE --with-tree-sitter=ifavailable";;
5476 esac
5478 if test "X${MISSING}" != X; then
5479   # If we have a missing library, and we don't have pkg-config installed,
5480   # the missing pkg-config may be the reason.  Give the user a hint.
5481   if test "X${PKG_CONFIG}" = X; then
5482     AC_MSG_WARN([Unable to locate a usable pkg-config])
5483   fi
5484   AC_MSG_ERROR([The following required libraries were not found:
5485     $MISSING
5486 Maybe some development libraries/packages are missing?
5487 To build anyway, give:
5488     $WITH_IFAVAILABLE
5489 as options to configure.])
5492 ### Use -lgpm if available, unless '--with-gpm=no'.
5493 HAVE_GPM=no
5494 LIBGPM=
5495 if test "${with_gpm}" != "no"; then
5496   AC_CHECK_HEADER([gpm.h],
5497     [AC_CHECK_LIB([gpm], [Gpm_Open], [HAVE_GPM=yes])])
5499   if test "${HAVE_GPM}" = "yes"; then
5500     AC_DEFINE([HAVE_GPM], [1],
5501       [Define to 1 if you have the gpm library (-lgpm).])
5502     LIBGPM=-lgpm
5503   fi
5505 AC_SUBST([LIBGPM])
5507 dnl Check for malloc/malloc.h on darwin
5508 AC_CHECK_HEADERS_ONCE([malloc/malloc.h])
5510 GNUSTEP_CFLAGS=
5511 ### Use NeXTstep API to implement GUI.
5512 if test "${HAVE_NS}" = "yes"; then
5513   AC_DEFINE([HAVE_NS], [1],
5514     [Define to 1 if you are using the NeXTstep API,
5515      either GNUstep or Cocoa on macOS.])
5516   if test "${NS_IMPL_COCOA}" = "yes"; then
5517     AC_DEFINE([NS_IMPL_COCOA], [1],
5518       [Define to 1 if you are using NS windowing under macOS.])
5519   fi
5520   if test "${NS_IMPL_GNUSTEP}" = "yes"; then
5521     AC_DEFINE([NS_IMPL_GNUSTEP], [1],
5522       [Define to 1 if you are using NS windowing under GNUstep.])
5523     if test $NS_GNUSTEP_CONFIG != yes; then
5524       # See also .m.o rule in src/Makefile.in.  */
5525       # FIXME: are all these flags really needed?  Document here why.  */
5526       GNUSTEP_CFLAGS="-D_REENTRANT -fPIC -fno-strict-aliasing -I${GNUSTEP_SYSTEM_HEADERS} ${GNUSTEP_LOCAL_HEADERS}"
5527       ## Extra CFLAGS applied to src/*.m files.
5528       GNU_OBJC_CFLAGS="$GNU_OBJC_CFLAGS -fgnu-runtime -Wno-import -fconstant-string-class=NSConstantString -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGSWARN -DGSDIAGNOSE"
5529     fi
5530   fi
5531   OTHER_FILES=ns-app
5534 ### Use session management (-lSM -lICE) if available
5535 HAVE_X_SM=no
5536 LIBXSM=
5537 if test "${HAVE_X11}" = "yes"; then
5538   AC_CHECK_HEADER([X11/SM/SMlib.h],
5539     [AC_CHECK_LIB([SM], [SmcOpenConnection], [HAVE_X_SM=yes], [], [-lICE])])
5541   if test "${HAVE_X_SM}" = "yes"; then
5542     AC_DEFINE([HAVE_X_SM], [1],
5543       [Define to 1 if you have the SM library (-lSM).])
5544     LIBXSM="-lSM -lICE"
5545   fi
5547 AC_SUBST([LIBXSM])
5549 ### Use XRandr (-lXrandr) if available
5550 HAVE_XRANDR=no
5551 if test "${HAVE_X11}" = "yes"; then
5552   XRANDR_REQUIRED=1.2.2
5553   XRANDR_MODULES="xrandr >= $XRANDR_REQUIRED"
5554   EMACS_CHECK_MODULES([XRANDR], [$XRANDR_MODULES])
5555   if test $HAVE_XRANDR = no; then
5556     # Test old way in case pkg-config doesn't have it (older machines).
5557     # Include Xrender.h by hand to work around bug in older Xrandr.h
5558     # (e.g. RHEL5) and silence (harmless) configure warning (bug#18465).
5559     AC_CHECK_HEADER([X11/extensions/Xrandr.h],
5560       [AC_CHECK_LIB([Xrandr], [XRRGetScreenResources], [HAVE_XRANDR=yes])],
5561       [], [AC_INCLUDES_DEFAULT
5562 #include <X11/extensions/Xrender.h>])
5563     if test $HAVE_XRANDR = yes; then
5564       XRANDR_LIBS=-lXrandr
5565     fi
5566   fi
5567   if test $HAVE_XRANDR = yes; then
5568     AC_DEFINE([HAVE_XRANDR], [1],
5569       [Define to 1 if you have the XRandr extension.])
5570   fi
5572 AC_SUBST([XRANDR_CFLAGS])
5573 AC_SUBST([XRANDR_LIBS])
5575 ### Use Xinerama (-lXinerama) if available
5576 HAVE_XINERAMA=no
5577 if test "${HAVE_X11}" = "yes"; then
5578   XINERAMA_REQUIRED=1.0.2
5579   XINERAMA_MODULES="xinerama >= $XINERAMA_REQUIRED"
5580   EMACS_CHECK_MODULES([XINERAMA], [$XINERAMA_MODULES])
5581   if test $HAVE_XINERAMA = no; then
5582     # Test old way in case pkg-config doesn't have it (older machines).
5583     AC_CHECK_HEADER([X11/extensions/Xinerama.h],
5584       [AC_CHECK_LIB([Xinerama], [XineramaQueryExtension],
5585          [HAVE_XINERAMA=yes])])
5586     if test $HAVE_XINERAMA = yes; then
5587       XINERAMA_LIBS=-lXinerama
5588     fi
5589   fi
5590   if test $HAVE_XINERAMA = yes; then
5591     AC_DEFINE([HAVE_XINERAMA], [1],
5592       [Define to 1 if you have the Xinerama extension.])
5593   fi
5595 AC_SUBST([XINERAMA_CFLAGS])
5596 AC_SUBST([XINERAMA_LIBS])
5598 ### Use Xfixes (-lXfixes) if available
5599 HAVE_XFIXES=no
5600 if test "${HAVE_X11}" = "yes"; then
5601   XFIXES_REQUIRED=1.0.0
5602   XFIXES_MODULES="xfixes >= $XFIXES_REQUIRED"
5603   EMACS_CHECK_MODULES([XFIXES], [$XFIXES_MODULES])
5604   if test $HAVE_XFIXES = no; then
5605     # Test old way in case pkg-config doesn't have it (older machines).
5606     AC_CHECK_HEADER([X11/extensions/Xfixes.h],
5607       [AC_CHECK_LIB([Xfixes], [XFixesHideCursor], [HAVE_XFIXES=yes])])
5608     if test $HAVE_XFIXES = yes; then
5609       XFIXES_LIBS=-lXfixes
5610     fi
5611   fi
5612   if test $HAVE_XFIXES = yes; then
5613     AC_DEFINE([HAVE_XFIXES], [1],
5614       [Define to 1 if you have the Xfixes extension.])
5615   fi
5617 AC_SUBST([XFIXES_CFLAGS])
5618 AC_SUBST([XFIXES_LIBS])
5620 ## Use XInput 2.0 if available
5621 HAVE_XINPUT2=no
5622 if test "${HAVE_X11}" = "yes" && test "${with_xinput2}" != "no"; then
5623    EMACS_CHECK_MODULES([XINPUT], [xi])
5624    if test $HAVE_XINPUT = yes; then
5625      # Now check for XInput2.h
5626      AC_CHECK_HEADER([X11/extensions/XInput2.h],
5627        [AC_CHECK_LIB([Xi], [XIGrabButton], [HAVE_XINPUT2=yes])])
5628    fi
5629    if test $HAVE_XINPUT2 = yes; then
5630      AC_DEFINE([HAVE_XINPUT2], [1],
5631        [Define to 1 if the X Input Extension version 2.0 or later is present.])
5632      if test "$USE_GTK_TOOLKIT" = "GTK2"; then
5633        AC_MSG_WARN([You are building Emacs with GTK+ 2 and the X Input Extension version 2.
5634 This might lead to problems if your version of GTK+ is not built with support for XInput 2.])
5635      fi
5637      # Now check for some members (which used in conjunction with
5638      # protocol definitions) can be used to determine the version of
5639      # XInput supported.
5640      AC_CHECK_MEMBERS([XIScrollClassInfo.type, XITouchClassInfo.type,
5641        XIBarrierReleasePointerInfo.deviceid, XIGestureClassInfo.type],
5642        [], [], [#include <X11/extensions/XInput2.h>])
5643    fi
5645 AC_SUBST([XINPUT_CFLAGS])
5646 AC_SUBST([XINPUT_LIBS])
5648 XSYNC_LIBS=
5649 XSYNC_CFLAGS=
5650 HAVE_XSYNC=no
5651 if test "${HAVE_X11}" = "yes"; then
5652    AC_CHECK_HEADER([X11/extensions/sync.h],
5653      [AC_CHECK_LIB([Xext], [XSyncQueryExtension], [HAVE_XSYNC=yes])],
5654      [], [#include <X11/Xlib.h>])
5656   if test "${HAVE_XSYNC}" = "yes"; then
5657     AC_DEFINE([HAVE_XSYNC], [1],
5658       [Define to 1 if the X Synchronization Extension is available.])
5659     XSYNC_LIBS="-lXext"
5660     OLDLIBS="$LIBS"
5661     LIBS="-lXext $LIBS" # Set this temporarily for AC_CHECK_FUNC
5662     AC_CHECK_FUNCS([XSyncTriggerFence]) # Check for version 3.1
5663     LIBS="$OLDLIBS"
5664   fi
5666 AC_SUBST([XSYNC_LIBS])
5667 AC_SUBST([XSYNC_CFLAGS])
5669 ### Use Xdbe (-lXdbe) if available
5670 HAVE_XDBE=no
5671 if test "${HAVE_X11}" = "yes"; then
5672   if test "${with_xdbe}" != "no"; then
5673     AC_CHECK_HEADER([X11/extensions/Xdbe.h],
5674       [AC_CHECK_LIB([Xext], [XdbeAllocateBackBufferName], [HAVE_XDBE=yes])],
5675       [],
5676       [#include <X11/Xlib.h>
5677       ])
5678   fi
5679   if test $HAVE_XDBE = yes; then
5680     XDBE_LIBS=-lXext
5681   fi
5682   if test $HAVE_XDBE = yes; then
5683     AC_DEFINE([HAVE_XDBE], [1], [Define to 1 if you have the Xdbe extension.])
5684   fi
5686 AC_SUBST([XDBE_CFLAGS])
5687 AC_SUBST([XDBE_LIBS])
5689 ### Use the Nonrectangular Window Shape extension if available.
5690 HAVE_XSHAPE=no
5691 HAVE_XCB_SHAPE=no
5692 if test "${HAVE_X11}" = "yes"; then
5693   AC_CHECK_HEADER([X11/extensions/shape.h],
5694     [AC_CHECK_LIB([Xext], [XShapeQueryVersion], [HAVE_XSHAPE=yes])],
5695     [],
5696     [#include <X11/extensions/shape.h>
5697     ])
5698   if test $HAVE_XSHAPE = yes; then
5699     XSHAPE_LIBS=-lXext
5700     AC_CHECK_HEADER([xcb/shape.h],
5701       [AC_CHECK_LIB([xcb-shape], [xcb_shape_combine], [HAVE_XCB_SHAPE=yes])],
5702       [],
5703       [#include <xcb/shape.h>])
5705     if test $HAVE_XCB_SHAPE = yes && test "$XCB_LIBS" != ""; then
5706       XSHAPE_LIBS="$XSHAPE_LIBS -lxcb-shape"
5707       AC_DEFINE([HAVE_XCB_SHAPE], [1],
5708         [Define to 1 if XCB supports the
5709          Nonrectangular Window Shape extension.])
5710     fi
5711   fi
5712   if test $HAVE_XSHAPE = yes; then
5713     AC_DEFINE([HAVE_XSHAPE], [1],
5714       [Define to 1 if you have the Nonrectangular Window Shape extension.])
5715   fi
5717 AC_SUBST([XSHAPE_CFLAGS])
5718 AC_SUBST([XSHAPE_LIBS])
5720 ### Use Xcomposite (-lXcomposite) if available
5721 HAVE_XCOMPOSITE=no
5722 if test "${HAVE_X11}" = "yes"; then
5723   AC_CHECK_HEADER([X11/extensions/Xcomposite.h],
5724     [AC_CHECK_LIB([Xcomposite], [XCompositeRedirectWindow],
5725        [HAVE_XCOMPOSITE=yes])],
5726     [],
5727     [#include <X11/extensions/Xcomposite.h>
5728     ])
5729   if test $HAVE_XCOMPOSITE = yes; then
5730     XCOMPOSITE_LIBS=-lXcomposite
5731   fi
5732   if test $HAVE_XCOMPOSITE = yes; then
5733     AC_DEFINE([HAVE_XCOMPOSITE], [1],
5734       [Define to 1 if you have the XCOMPOSITE extension.])
5735   fi
5737 AC_SUBST([XCOMPOSITE_CFLAGS])
5738 AC_SUBST([XCOMPOSITE_LIBS])
5740 ### Use libxml (-lxml2) if available
5741 ### mingw32 doesn't use -lxml2, since it loads the library dynamically.
5742 HAVE_LIBXML2=no
5743 if test "${with_xml2}" != "no"; then
5744   ### I'm not sure what the version number should be, so I just guessed.
5745   EMACS_CHECK_MODULES([LIBXML2], [libxml-2.0 > 2.6.17])
5746   # Built-in libxml2 on OS X 10.8 lacks libxml-2.0.pc.
5747   if test "${HAVE_LIBXML2}" != "yes" && test "$opsys" = "darwin"; then
5748     SAVE_CPPFLAGS="$CPPFLAGS"
5749     if test -z "$xcsdkdir" -a -n "$XCRUN" -a ! -d /usr/include; then
5750       dnl /usr/include is not found.  Try Xcode SDK dir if it is sane.
5751       xcsdkdir=`$XCRUN --show-sdk-path 2>/dev/null`
5752       case $xcsdkdir in
5753         *[[\\\"\#\$\&\'\`$am_lf\ \      ]]*)
5754         xcsdkdir="" ;;
5755       esac
5756     fi
5757     CPPFLAGS="$CPPFLAGS -isystem${xcsdkdir}/usr/include/libxml2"
5758     AC_CHECK_HEADER([libxml/HTMLparser.h],
5759       [AC_CHECK_DECL([HTML_PARSE_RECOVER], [HAVE_LIBXML2=yes], [],
5760                      [#include <libxml/HTMLparser.h>])])
5761     CPPFLAGS="$SAVE_CPPFLAGS"
5762     if test "${HAVE_LIBXML2}" = "yes"; then
5763       LIBXML2_CFLAGS="-isystem${xcsdkdir}/usr/include/libxml2"
5764       LIBXML2_LIBS="-lxml2"
5765     fi
5766   fi
5767   if test "${HAVE_LIBXML2}" = "yes"; then
5768     if test "${opsys}" != "mingw32"; then
5769       SAVE_CFLAGS=$CFLAGS
5770       CFLAGS="$CFLAGS $LIBXML2_CFLAGS"
5771       EMACS_CHECK_LIB([xml2], [htmlReadMemory],
5772         [HAVE_LIBXML2=yes],
5773         [HAVE_LIBXML2=no],
5774         [$LIBXML2_LIBS], [#include <libxml/HTMLparser.h>])
5775       CFLAGS="$SAVE_CFLAGS"
5776     else
5777       LIBXML2_LIBS=""
5778     fi
5779     if test "${HAVE_LIBXML2}" = "yes"; then
5780       AC_DEFINE([HAVE_LIBXML2], [1],
5781         [Define to 1 if you have the libxml library (-lxml2).])
5782     else
5783       LIBXML2_LIBS=""
5784       LIBXML2_CFLAGS=""
5785     fi
5786   fi
5788 AC_SUBST([LIBXML2_LIBS])
5789 AC_SUBST([LIBXML2_CFLAGS])
5791 BLESSMAIL_TARGET=
5792 LIBS_MAIL=
5793 if test ! "$with_mailutils"; then
5794   # Check for mail-locking functions in a "mail" library.  Probably this should
5795   # have the same check as for liblockfile below.
5796   AC_CHECK_LIB([mail], [maillock], [have_mail=yes], [have_mail=no])
5797   if test $have_mail = yes; then
5798     LIBS_MAIL=-lmail
5799     AC_DEFINE([HAVE_LIBMAIL], [1],
5800       [Define to 1 if you have the 'mail' library (-lmail).])
5802     OLD_LIBS=$LIBS
5803     LIBS="$LIBS_MAIL $LIBS"
5804     AC_CHECK_FUNCS([touchlock])
5805     LIBS=$OLD_LIBS
5806   fi
5807   dnl Debian, at least:
5808   AC_CHECK_LIB([lockfile], [maillock], [have_lockfile=yes], [have_lockfile=no])
5809   if test $have_lockfile = yes; then
5810      LIBS_MAIL=-llockfile
5811      AC_DEFINE([HAVE_LIBLOCKFILE], [1],
5812        [Define to 1 if you have the 'lockfile' library (-llockfile).])
5813   else
5814     # If we have the shared liblockfile, assume we must use it for mail
5815     # locking (e.g. Debian).  If we couldn't link against liblockfile
5816     # (no liblockfile.a installed), ensure that we don't need to.
5817     dnl This works for files generally, not just executables.
5818     dnl Should we look elsewhere for it?  Maybe examine /etc/ld.so.conf?
5819     AC_CHECK_PROG([liblockfile], [liblockfile.so], [yes], [no],
5820                   [/usr/lib:/lib:/usr/local/lib:$LD_LIBRARY_PATH])
5821     if test "$ac_cv_prog_liblockfile" = yes; then
5822       AC_MSG_ERROR([Shared liblockfile found but can't link against it.
5823 This probably means that movemail could lose mail.
5824 There may be a 'development' package to install containing liblockfile.])
5825     fi
5826   fi
5827   AC_CHECK_HEADERS([maillock.h])
5829   ## Define MAIL_USE_FLOCK (or LOCKF) if the mailer uses flock (or lockf) to
5830   ## interlock access to the mail spool.  The alternative is a lock file named
5831   ## /usr/spool/mail/$USER.lock.
5832   mail_lock=no
5833   case $opsys in
5834     aix4-2) mail_lock="lockf" ;;
5836     gnu|freebsd|dragonfly|netbsd|openbsd|darwin) mail_lock="flock" ;;
5838     ## On GNU/Linux systems, both methods are used by various mail programs.
5839     ## I assume most people are using newer mailers that have heard of flock.
5840     ## Change this if you need to.
5841     ## Debian contains a patch which says: "On Debian/GNU/Linux systems,
5842     ## configure gets the right answers, and that means *NOT* using flock.
5843     ## Using flock is guaranteed to be the wrong thing. See Debian Policy
5844     ## for details." and then uses '#ifdef DEBIAN'.  Unfortunately the
5845     ## Debian maintainer hasn't provided a clean fix for Emacs.
5846     ## movemail.c will use 'maillock' when MAILDIR, HAVE_LIBMAIL and
5847     ## HAVE_MAILLOCK_H are defined, so the following appears to be the
5848     ## correct logic.  -- fx
5849     ## We must check for HAVE_LIBLOCKFILE too, as movemail does.
5850     ## liblockfile is a Free Software replacement for libmail, used on
5851     ## Debian systems and elsewhere. -rfr.
5852     gnu-*)
5853       mail_lock="flock"
5854       if test $have_mail = yes || test $have_lockfile = yes; then
5855         test $ac_cv_header_maillock_h = yes && mail_lock=no
5856       fi ;;
5858     mingw32)
5859       mail_lock="none-needed" ;;
5860   esac
5862   case $mail_lock in
5863     flock) AC_DEFINE([MAIL_USE_FLOCK], [1],
5864              [Define if the mailer uses flock to interlock the mail spool.]);;
5866     lockf) AC_DEFINE([MAIL_USE_LOCKF], [1],
5867              [Define if the mailer uses lockf to interlock the mail spool.]);;
5869     none-needed) ;;
5871     *) BLESSMAIL_TARGET="need-blessmail" ;;
5872   esac
5874 AC_SUBST([BLESSMAIL_TARGET])
5875 AC_SUBST([LIBS_MAIL])
5877 HAVE_SECCOMP=no
5878 AC_CHECK_HEADERS(
5879   [linux/seccomp.h linux/filter.h],
5880   [AC_CHECK_DECLS(
5881     [SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_TSYNC],
5882     [HAVE_SECCOMP=yes], [],
5883     [[
5884     #include <linux/seccomp.h>
5885     ]])])
5886 AC_SUBST([HAVE_SECCOMP])
5888 EMACS_CHECK_MODULES([LIBSECCOMP], [libseccomp >= 2.5.2])
5889 AC_SUBST([HAVE_LIBSECCOMP])
5890 AC_SUBST([LIBSECCOMP_LIBS])
5891 AC_SUBST([LIBSECCOMP_CFLAGS])
5893 AC_CHECK_SIZEOF([long])
5894 SIZEOF_LONG="$ac_cv_sizeof_long"
5895 AC_SUBST([SIZEOF_LONG])
5897 OLD_LIBS=$LIBS
5898 LIBS="$LIB_PTHREAD $LIB_MATH $LIBS"
5899 AC_CHECK_FUNCS([accept4 fchdir gethostname \
5900 getrusage get_current_dir_name \
5901 lrand48 random rint tcdrain trunc \
5902 select getpagesize setlocale newlocale \
5903 getrlimit setrlimit shutdown \
5904 pthread_sigmask strsignal setitimer \
5905 sendto recvfrom getsockname getifaddrs freeifaddrs \
5906 gai_strerror sync \
5907 endpwent getgrent endgrent \
5908 cfmakeraw cfsetspeed __executable_start log2 pthread_setname_np \
5909 pthread_set_name_np])
5911 # getpwent is not present in older versions of Android.  (bug#65319)
5912 gl_CHECK_FUNCS_ANDROID([getpwent], [[#include <pwd.h>]])
5914 # renameat2 is not present in older versions of Android.
5915 gl_CHECK_FUNCS_ANDROID([renameat2], [[#include <stdio.h>]])
5917 if test "$ac_cv_func_cfmakeraw" != "yes"; then
5918   # On some systems (Android), cfmakeraw is inline, so AC_CHECK_FUNCS
5919   # cannot find it.  Check if some code including termios.h and using
5920   # cfmakeraw builds.
5921   AC_CACHE_CHECK([whether cfmakeraw is inline],
5922    [emacs_cv_func_cfmakeraw_inline],
5923    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
5924        [[#include <termios.h>]],
5925        [[&cfmakeraw;]])],
5926      [emacs_cv_func_cfmakeraw_inline=yes],
5927      [emacs_cv_func_cfmakeraw_inline=no])])
5929   if test "$emacs_cv_func_cfmakeraw_inline" = "yes"; then
5930      # Define HAVE_CFMAKERAW again.
5931      AC_DEFINE([HAVE_CFMAKERAW], [1])
5932   fi
5935 if test "$ac_cv_func_cfsetspeed" != "yes"; then
5936   AC_CACHE_CHECK([whether cfsetspeed is inline],
5937    [emacs_cv_func_cfsetspeed_inline],
5938    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
5939        [[#include <termios.h>]],
5940        [[&cfsetspeed;]])],
5941      [emacs_cv_func_cfsetspeed_inline=yes],
5942      [emacs_cv_func_cfsetspeed_inline=no])])
5944   if test "$emacs_cv_func_cfsetspeed_inline" = "yes"; then
5945      # Define HAVE_CFSETSPEED again.
5946      AC_DEFINE([HAVE_CFSETSPEED], [1])
5947   fi
5950 LIBS=$OLD_LIBS
5952 if test "$ac_cv_func_pthread_setname_np" = "yes"; then
5953   AC_CACHE_CHECK(
5954    [whether pthread_setname_np takes a single argument],
5955    [emacs_cv_pthread_setname_np_1arg],
5956    [AC_COMPILE_IFELSE(
5957      [AC_LANG_PROGRAM(
5958        [[#include <pthread.h>]],
5959        [[pthread_setname_np ("a");]])],
5960      [emacs_cv_pthread_setname_np_1arg=yes],
5961      [emacs_cv_pthread_setname_np_1arg=no])])
5962   if test "$emacs_cv_pthread_setname_np_1arg" = "yes"; then
5963     AC_DEFINE(
5964       [HAVE_PTHREAD_SETNAME_NP_1ARG], [1],
5965       [Define to 1 if pthread_setname_np takes a single argument.])
5966   else
5967     AC_CACHE_CHECK(
5968      [whether pthread_setname_np takes three arguments],
5969      [emacs_cv_pthread_setname_np_3arg],
5970      [AC_COMPILE_IFELSE(
5971        [AC_LANG_PROGRAM(
5972          [[#include <pthread.h>]],
5973          [[pthread_setname_np (0, "%s", "a");]])],
5974        [emacs_cv_pthread_setname_np_3arg=yes],
5975        [emacs_cv_pthread_setname_np_3arg=no])])
5976      if test "$emacs_cv_pthread_setname_np_3arg" = "yes"; then
5977        AC_DEFINE(
5978          [HAVE_PTHREAD_SETNAME_NP_3ARG], [1],
5979          [Define to 1 if pthread_setname_np takes three arguments.])
5980      fi
5981   fi
5984 dnl No need to check for posix_memalign if aligned_alloc works.
5985 AC_CHECK_FUNCS([aligned_alloc posix_memalign], [break])
5986 AC_CHECK_DECLS([aligned_alloc], [], [], [[#include <stdlib.h>]])
5988 case $with_unexec,$canonical in
5989   yes,alpha*)
5990     AC_CHECK_DECL([__ELF__], [],
5991       [AC_MSG_ERROR([Non-ELF systems are not supported on this platform.])]);;
5992 esac
5994 if test "$with_unexec" = yes && test "$opsys" = "haiku"; then
5995   dnl A serious attempt was actually made to port unexec to Haiku.
5996   dnl Something in libstdc++ seems to prevent it from working.
5997   AC_MSG_ERROR([Haiku is not supported by the legacy unexec dumper.
5998 Please use the portable dumper instead.])
6001 # Dump loading.  Android lacks posix_madvise.
6002 AC_CHECK_FUNCS([posix_madvise madvise])
6004 dnl Cannot use AC_CHECK_FUNCS
6005 AC_CACHE_CHECK([for __builtin_frame_address],
6006   [emacs_cv_func___builtin_frame_address],
6007   [AC_LINK_IFELSE([AC_LANG_PROGRAM([], [__builtin_frame_address (0);])],
6008      [emacs_cv_func___builtin_frame_address=yes],
6009      [emacs_cv_func___builtin_frame_address=no])])
6010 if test $emacs_cv_func___builtin_frame_address = yes; then
6011   AC_DEFINE([HAVE___BUILTIN_FRAME_ADDRESS], [1],
6012             [Define to 1 if you have the '__builtin_frame_address' function.])
6014 AC_CACHE_CHECK([for __builtin_unwind_init],
6015                [emacs_cv_func___builtin_unwind_init],
6016 [AC_LINK_IFELSE([AC_LANG_PROGRAM([], [__builtin_unwind_init ();])],
6017                 [emacs_cv_func___builtin_unwind_init=yes],
6018                 [emacs_cv_func___builtin_unwind_init=no])])
6019 if test $emacs_cv_func___builtin_unwind_init = yes; then
6020   AC_DEFINE([HAVE___BUILTIN_UNWIND_INIT], [1],
6021             [Define to 1 if you have the '__builtin_unwind_init' function.])
6024 AC_CHECK_HEADERS_ONCE([sys/un.h])
6026 AC_FUNC_FSEEKO
6028 # UNIX98 PTYs.
6029 AC_CHECK_FUNCS([grantpt])
6031 # PTY-related GNU extensions.
6032 AC_CHECK_FUNCS([getpt posix_openpt])
6034 dnl Run a test program that contains a call to tputs, a call that is
6035 dnl never executed.  This tests whether a pre-'main' dynamic linker
6036 dnl works with the library.  It's too much trouble to actually call
6037 dnl tputs in the test program, due to portability hassles.  When
6038 dnl cross-compiling, assume the test program will run if it links.
6039 AC_DEFUN([tputs_link_source], [
6040   AC_LANG_SOURCE(
6041      [[extern void tputs (const char *, int, int (*)(int));
6042        int main (int argc, char **argv)
6043        {
6044           if (argc == 10000)
6045             tputs (argv[0], 0, 0);
6046           return 0;
6047        }]])
6049 # Check this now, so that we will NOT find the above functions in ncurses.
6050 # That is because we have not set up to link ncurses in lib-src.
6051 # It's better to believe a function is not available
6052 # than to expect to find it in ncurses.
6053 # Also we need tputs and friends to be able to build at all.
6054 AC_CACHE_CHECK([for library containing tputs], [emacs_cv_tputs_lib],
6055 [if test "${opsys}" = "mingw32" || test x"$REALLY_ANDROID" = "xyes"; then
6056   emacs_cv_tputs_lib='none required'
6057 else
6058   # curses precedes termcap because of AIX (Bug#9736#35) and OpenIndiana.
6059   tputs_libraries='tinfo ncurses terminfo curses termcap tinfow ncursesw'
6060   for tputs_library in '' $tputs_libraries; do
6061     OLIBS=$LIBS
6062     if test -z "$tputs_library"; then
6063       emacs_cv_tputs_lib='none required'
6064     else
6065       emacs_cv_tputs_lib=-l$tputs_library
6066       LIBS="$emacs_cv_tputs_lib $LIBS"
6067     fi
6068     AC_RUN_IFELSE([tputs_link_source], [], [emacs_cv_tputs_lib=no],
6069       [AC_LINK_IFELSE([tputs_link_source], [], [emacs_cv_tputs_lib=no])])
6070     LIBS=$OLIBS
6071     if test "X$emacs_cv_tputs_lib" != Xno; then
6072       break
6073     fi
6074   done
6075 fi])
6076 AS_CASE(["$emacs_cv_tputs_lib"],
6077   [no], [AC_MSG_ERROR([The required function 'tputs' was not found in any library.
6078 The following libraries were tried (in order):
6079   libtinfo, libncurses, libterminfo, libcurses, libtermcap
6080 Please try installing whichever of these libraries is most appropriate
6081 for your system, together with its header files.
6082 For example, a libncurses-dev(el) or similar package.])],
6083   [-l*], [LIBS_TERMCAP=$emacs_cv_tputs_lib],
6084   [*], [LIBS_TERMCAP=])
6086 ## Use termcap instead of terminfo?
6087 ## Only true for: freebsd < 40000, ms-w32, msdos, netbsd < 599002500.
6088 TERMINFO=yes
6089 ## FIXME?  In the cases below where we unconditionally set
6090 ## LIBS_TERMCAP="-lncurses", this overrides LIBS_TERMCAP = -ltinfo,
6091 ## if that was found above to have tputs.
6092 ## Should we use the gnu* logic everywhere?
6093 case "$opsys$REALLY_ANDROID" in
6094   ## darwin: Prevents crashes when running Emacs in Terminal.app under 10.2.
6095   ##  The ncurses library has been moved out of the System framework in
6096   ##  Mac OS X 10.2.  So if configure detects it, set the command-line
6097   ##  option to use it.
6098   darwin) LIBS_TERMCAP="-lncurses" ;;
6100   gnu*) test -z "$LIBS_TERMCAP" && LIBS_TERMCAP="-lncurses" ;;
6102   freebsd)
6103     AC_MSG_CHECKING([whether FreeBSD is new enough to use terminfo])
6104     AC_CACHE_VAL([emacs_cv_freebsd_terminfo],
6105     [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <osreldate.h>]],
6106 [[#if __FreeBSD_version < 400000
6107 fail;
6108 #endif
6109 ]])], [emacs_cv_freebsd_terminfo=yes],
6110       [emacs_cv_freebsd_terminfo=no])])
6112     AC_MSG_RESULT([$emacs_cv_freebsd_terminfo])
6114     if test $emacs_cv_freebsd_terminfo = yes; then
6115       LIBS_TERMCAP="-lncurses"
6116     else
6117       TERMINFO=no
6118       LIBS_TERMCAP="-ltermcap"
6119     fi
6120     ;;
6122   # The case condition is a concatenation of both $opsys and
6123   # $REALLY_ANDROID.  Only disable termcap if building a GUI program.
6124   # (bug#65340)
6125   mingw32 | androidyes)
6126     TERMINFO=no
6127     LIBS_TERMCAP=
6128     ;;
6130   netbsd)
6131     # NetBSD versions prior to 6.0 lack native terminfo, but have a
6132     # tputs() built on top of termcap in these libraries. Use native
6133     # termcap instead in this case. NetBSD >= 6.0 has native terminfo
6134     # implementation in -lterminfo.
6135     if test "x$LIBS_TERMCAP" = "x-ltermcap" -o "x$LIBS_TERMCAP" = "x-lcurses"; then
6136       TERMINFO=no
6137       LIBS_TERMCAP="-ltermcap"
6138     fi
6139     ;;
6141   openbsd | dragonfly) LIBS_TERMCAP="-lncurses" ;;
6143   ## hpux: Make sure we get select from libc rather than from libcurses
6144   ##  because libcurses on HPUX 10.10 has a broken version of select.
6145   ##  We used to use -lc -lcurses, but this may be cleaner.
6146   ## FIXME?  But TERMINFO = yes on hpux (it used to be explicitly
6147   # set that way, now it uses the default).  Isn't this a contradiction?
6148   hpux*) LIBS_TERMCAP="-ltermcap" ;;
6150 esac
6152 TERMCAP_OBJ=tparam.o
6153 if test $TERMINFO = yes; then
6154   AC_DEFINE([TERMINFO], [1],
6155     [Define to 1 if you use terminfo instead of termcap.])
6156   TERMCAP_OBJ=terminfo.o
6157   AC_CACHE_CHECK([whether $LIBS_TERMCAP library defines BC],
6158     [emacs_cv_terminfo_defines_BC],
6159     [OLD_LIBS=$LIBS
6160      LIBS="$LIBS $LIBS_TERMCAP"
6161      AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern char *BC;]], [[return !*BC;]])],
6162        [emacs_cv_terminfo_defines_BC=yes],
6163        [emacs_cv_terminfo_defines_BC=no])
6164      LIBS=$OLD_LIBS])
6165   if test "$emacs_cv_terminfo_defines_BC" = yes; then
6166     AC_DEFINE([TERMINFO_DEFINES_BC], [1], [Define to 1 if the
6167       terminfo library defines the variables BC, PC, and UP.])
6168   fi
6170 if test "X$LIBS_TERMCAP" = "X-lncurses"; then
6171   AC_DEFINE([USE_NCURSES], [1], [Define to 1 if you use ncurses.])
6173 AC_SUBST([LIBS_TERMCAP])
6174 AC_SUBST([TERMCAP_OBJ])
6176 # GNU/Linux-specific timer functions.
6177 AC_CACHE_CHECK([for timerfd interface], [emacs_cv_have_timerfd],
6178   [AC_COMPILE_IFELSE(
6179      [AC_LANG_PROGRAM([[#include <sys/timerfd.h>
6180                       ]],
6181                       [[timerfd_create (CLOCK_REALTIME,
6182                                         TFD_CLOEXEC | TFD_NONBLOCK);
6183                         timerfd_settime (0, TFD_TIMER_ABSTIME, 0, 0);]])],
6184      [emacs_cv_have_timerfd=yes],
6185      [emacs_cv_have_timerfd=no])])
6186 if test "$emacs_cv_have_timerfd" = yes; then
6187   AC_DEFINE([HAVE_TIMERFD], [1],
6188     [Define to 1 if timerfd functions are supported as in GNU/Linux.])
6191 # Alternate stack for signal handlers.
6192 AC_CACHE_CHECK([whether signals can be handled on alternate stack],
6193                [emacs_cv_alternate_stack],
6194   [AC_COMPILE_IFELSE(
6195      [AC_LANG_PROGRAM([[#include <signal.h>
6196                         #include <stdlib.h>
6197                       ]],
6198                       [[stack_t ss;
6199                         struct sigaction sa;
6200                         ss.ss_sp = malloc (SIGSTKSZ);
6201                         ss.ss_size = SIGSTKSZ;
6202                         sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
6203                         sigaltstack (&ss, 0);
6204                         sigaction (SIGSEGV, &sa, 0);]])],
6205      [emacs_cv_alternate_stack=yes],
6206      [emacs_cv_alternate_stack=no])])
6208 # Do we need the Hesiod library to provide the support routines?
6209 dnl FIXME?  Should we be skipping this on Darwin too?
6210 LIBHESIOD=
6211 LIBRESOLV=
6212 if test "$with_hesiod" != no ; then
6213   # Don't set $LIBS here -- see comments above.  FIXME which comments?
6214   resolv=no
6215   AC_CHECK_FUNC([res_send], [], [AC_CHECK_FUNC([__res_send], [],
6216      [AC_CHECK_LIB([resolv], [res_send], [resolv=yes],
6217                   [AC_CHECK_LIB([resolv], [__res_send], [resolv=yes])])])])
6218   if test "$resolv" = yes ; then
6219     RESOLVLIB=-lresolv
6220   else
6221     RESOLVLIB=
6222   fi
6223   hesiod=no
6224   AC_CHECK_FUNC([hes_getmailhost], [],
6225     [AC_CHECK_LIB([hesiod], [hes_getmailhost],
6226        [hesiod=yes], [:], [$RESOLVLIB])])
6228   if test x"$hesiod" = xyes; then
6229     LIBHESIOD=-lhesiod
6230     LIBRESOLV=$RESOLVLIB
6231   fi
6233 AC_SUBST([LIBHESIOD])
6234 AC_SUBST([LIBRESOLV])
6236 # These tell us which Kerberos-related libraries to use.
6237 COM_ERRLIB=
6238 CRYPTOLIB=
6239 KRB5LIB=
6240 DESLIB=
6241 KRB4LIB=
6243 if test "${with_kerberos}" != no; then
6244   OLD_LIBS=$LIBS
6245   AC_CHECK_LIB([com_err], [com_err], [have_com_err=yes], [have_com_err=no])
6246   if test $have_com_err = yes; then
6247     COM_ERRLIB=-lcom_err
6248     LIBS="$COM_ERRLIB $LIBS"
6249   fi
6250   AC_CHECK_LIB([crypto], [mit_des_cbc_encrypt],
6251     [have_crypto=yes],
6252     [have_crypto=no])
6253   if test $have_crypto = yes; then
6254     CRYPTOLIB=-lcrypto
6255     LIBS="$CRYPTOLIB $LIBS"
6256   fi
6257   AC_CHECK_LIB([k5crypto], [mit_des_cbc_encrypt],
6258     [have_k5crypto=yes],
6259     [have_k5crypto=no])
6260   if test $have_k5crypto = yes; then
6261     CRYPTOLIB=-lk5crypto
6262     LIBS="$CRYPTOLIB $LIBS"
6263   fi
6264   AC_CHECK_LIB([krb5], [krb5_init_context], [have_krb5=yes], [have_krb5=no])
6265   if test $have_krb5=yes; then
6266     KRB5LIB=-lkrb5
6267     LIBS="$KRB5LIB $LIBS"
6268   fi
6269   dnl FIXME Simplify.  Does not match 22 logic, thanks to default_off?
6270   if test "${with_kerberos5}" = no; then
6271     AC_CHECK_LIB([des425], [des_cbc_encrypt],
6272       [have_des425=yes],
6273       [have_des425=no])
6274     if test $have_des425 = yes; then
6275       DESLIB=-ldes425
6276       LIBS="$DESLIB $LIBS"
6277     else
6278       AC_CHECK_LIB([des], [des_cbc_encrypt], [have_des=yes], [have_des=no])
6279       if test $have_des = yes; then
6280         DESLIB=-ldes
6281         LIBS="$DESLIB $LIBS"
6282       fi
6283     fi
6284     AC_CHECK_LIB([krb4], [krb_get_cred], [have_krb4=yes], [have_krb4=no])
6285     if test $have_krb4 = yes; then
6286       KRB4LIB=-lkrb4
6287       LIBS="$KRB4LIB $LIBS"
6288     else
6289       AC_CHECK_LIB([krb], [krb_get_cred], [have_krb=yes], [have_krb=no])
6290       if test $have_krb = yes; then
6291         KRB4LIB=-lkrb
6292         LIBS="$KRB4LIB $LIBS"
6293       fi
6294     fi
6295   fi
6297   if test "${with_kerberos5}" != no; then
6298     AC_CHECK_HEADERS([krb5.h],
6299       [AC_CHECK_MEMBERS([krb5_error.text, krb5_error.e_text], [], [],
6300                         [#include <krb5.h>])])
6301   else
6302     AC_CHECK_HEADERS([krb.h], [],
6303                      [AC_CHECK_HEADERS([kerberosIV/krb.h], [],
6304                                        [AC_CHECK_HEADERS([kerberos/krb.h])])])
6305   fi
6306   AC_CHECK_HEADERS([com_err.h])
6307   LIBS=$OLD_LIBS
6310 AC_SUBST([COM_ERRLIB])
6311 AC_SUBST([CRYPTOLIB])
6312 AC_SUBST([KRB5LIB])
6313 AC_SUBST([DESLIB])
6314 AC_SUBST([KRB4LIB])
6316 AC_CHECK_HEADERS([valgrind/valgrind.h])
6318 AC_CHECK_MEMBERS([struct unipair.unicode], [], [], [[#include <linux/kd.h>]])
6320 AC_CHECK_FUNCS_ONCE([__lsan_ignore_object])
6322 AC_FUNC_FORK
6324 dnl AC_CHECK_FUNCS_ONCE wouldn’t be right for snprintf, which needs
6325 dnl the current CFLAGS etc.
6326 AC_CHECK_FUNCS([snprintf open_memstream])
6328 dnl posix_spawn.  The chdir and setsid functionality is relatively
6329 dnl recent, so we check for it specifically.
6330 AC_CHECK_HEADERS([spawn.h])
6331 AC_SUBST([HAVE_SPAWN_H])
6332 AC_CHECK_FUNCS([posix_spawn \
6333                 posix_spawn_file_actions_addchdir \
6334                 posix_spawn_file_actions_addchdir_np \
6335                 posix_spawnattr_setflags])
6336 AC_SUBST([HAVE_POSIX_SPAWN])
6337 AC_SUBST([HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR])
6338 AC_SUBST([HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR_NP])
6339 AC_SUBST([HAVE_POSIX_SPAWNATTR_SETFLAGS])
6340 AC_CHECK_DECLS([POSIX_SPAWN_SETSID], [], [], [[
6341                #include <spawn.h>
6342                ]])
6343 AC_SUBST([HAVE_DECL_POSIX_SPAWN_SETSID])
6345 dnl Check for glib.  This differs from other library checks in that
6346 dnl Emacs need not link to glib unless some other library is already
6347 dnl linking to glib.  Although glib provides no facilities that Emacs
6348 dnl needs for its own purposes, when glib is present Emacs needs to
6349 dnl use primitives like g_main_context_query to avoid clashing with
6350 dnl glib at a low level.
6352 dnl Check this late, since it depends on $GTK_CFLAGS etc.
6353 XGSELOBJ=
6354 AC_CACHE_CHECK([whether GLib is linked in], [emacs_cv_links_glib],
6355 [OLDCFLAGS="$CFLAGS"
6356 OLDLIBS="$LIBS"
6357 CFLAGS="$CFLAGS $GTK_CFLAGS $RSVG_CFLAGS $DBUS_CFLAGS $SETTINGS_CFLAGS"
6358 LIBS="$LIBS $GTK_LIBS $RSVG_LIBS $DBUS_LIBS $SETTINGS_LIBS"
6359 CFLAGS="$CFLAGS $NOTIFY_CFLAGS $CAIRO_CFLAGS"
6360 LIBS="$LIBS $NOTIFY_LIBS $CAIRO_LIBS"
6361 AC_LINK_IFELSE([AC_LANG_PROGRAM(
6362         [[#include <glib.h>
6363         ]],
6364         [[g_print ("Hello world");]])],
6365      [emacs_cv_links_glib=yes],
6366      [emacs_cv_links_glib=no])
6367 CFLAGS="$OLDCFLAGS"
6368 LIBS="$OLDLIBS"])
6369 if test "${emacs_cv_links_glib}" = "yes"; then
6370   AC_DEFINE([HAVE_GLIB], [1], [Define to 1 if GLib is linked in.])
6371   if test "$HAVE_NS" = no ; then
6372     XGSELOBJ=xgselect.o
6373   fi
6375 AC_SUBST([XGSELOBJ])
6377 AC_DEFUN([EMACS_PAPER_WIDTH],
6378   [AC_REQUIRE([AM_LANGINFO_CODESET])
6379    AS_IF([test "$am_cv_langinfo_codeset" = yes],
6380      [AC_CACHE_CHECK([for nl_langinfo and _NL_PAPER_WIDTH],
6381         [emacs_cv_langinfo__nl_paper_width],
6382         [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <langinfo.h>]],
6383           [[char *cs = nl_langinfo (_NL_PAPER_WIDTH);]])],
6384           [emacs_cv_langinfo__nl_paper_width=yes],
6385           [emacs_cv_langinfo__nl_paper_width=no])
6386         ])
6387       AS_IF([test "$emacs_cv_langinfo__nl_paper_width" = yes],
6388         [AC_DEFINE([HAVE_LANGINFO__NL_PAPER_WIDTH], [1],
6389            [Define if you have <langinfo.h>
6390             and nl_langinfo (_NL_PAPER_WIDTH).])])])])
6391 EMACS_PAPER_WIDTH
6393 AC_TYPE_MBSTATE_T
6395 dnl Fixme: AC_SYS_POSIX_TERMIOS should probably be used, but it's not clear
6396 dnl how the tty code is related to POSIX and/or other versions of termios.
6397 dnl The following looks like a useful start.
6399 dnl AC_SYS_POSIX_TERMIOS
6400 dnl if test $ac_cv_sys_posix_termios = yes; then
6401 dnl    AC_DEFINE([HAVE_TERMIOS], [1],
6402 dnl      [Define to 1 if you have POSIX-style
6403 dnl       functions and macros for terminal control.])
6404 dnl    AC_DEFINE([HAVE_TCATTR], [1],
6405 dnl      [Define to 1 if you have tcgetattr and tcsetattr.])
6406 dnl fi
6408 dnl Turned on June 1996 supposing nobody will mind it.
6409 dnl MinGW emulates passwd database, so this feature doesn't make sense there.
6410 if test "${opsys}" != "mingw32"; then
6411    AC_DEFINE([AMPERSAND_FULL_NAME], [1], [Define to use the convention that &
6412      in the full name stands for the login id.])
6415 dnl Everybody supports this, except MS.
6416 dnl Seems like the kind of thing we should be testing for, though.
6417 ## Note: PTYs are broken on darwin <6.  Use at your own risk.
6418 if test "${opsys}" != "mingw32"; then
6419   AC_DEFINE([HAVE_PTYS], [1], [Define if the system supports pty devices.])
6422 dnl Everybody supports this, except MS-DOS.
6423 dnl Seems like the kind of thing we should be testing for, though.
6424 AC_DEFINE([HAVE_SOCKETS], [1], [Define if the system supports
6425   4.2-compatible sockets.])
6427 AH_TEMPLATE([INTERNAL_TERMINAL],
6428   [This is substituted when $TERM is "internal".])
6430 AH_TEMPLATE([NULL_DEVICE], [Name of the file to open to get
6431   a null file, or a data sink.])
6432 if test "${opsys}" = "mingw32"; then
6433   AC_DEFINE([NULL_DEVICE], ["NUL:"])
6434 else
6435   AC_DEFINE([NULL_DEVICE], ["/dev/null"])
6438 if test "${opsys}" = "mingw32"; then
6439   SEPCHAR=';'
6440 else
6441   SEPCHAR=':'
6443 AC_DEFINE_UNQUOTED([SEPCHAR], ['$SEPCHAR'],
6444   [Character that separates PATH elements.])
6445 dnl This is for MinGW, and is used in test/Makefile.in.
6446 dnl The MSYS Bash has heuristics for replacing ':' with ';' when it
6447 dnl decides that a command-line argument to be passed to a MinGW program
6448 dnl is a PATH-style list of directories.  But that heuristics plays it
6449 dnl safe, and only does the replacement when it is _absolutely_ sure it
6450 dnl sees a colon-separated list of file names; e.g. ":." is left alone,
6451 dnl which breaks in-tree builds.  So we do this manually instead.
6452 dnl Note that we cannot rely on PATH_SEPARATOR, as that one will always
6453 dnl be computed as ':' in MSYS Bash.
6454 AC_SUBST([SEPCHAR])
6456 dnl Everybody supports this, except MS-DOS.
6457 AC_DEFINE([subprocesses], [1], [Define to enable asynchronous subprocesses.])
6459 AC_DEFINE([USER_FULL_NAME], [pw->pw_gecos], [How to get a user's full name.])
6462 AC_DEFINE([DIRECTORY_SEP], ['/'],
6463   [Character that separates directories in a file name.])
6465 if test "${opsys}" = "mingw32"; then
6466   AC_DEFINE([IS_DEVICE_SEP(_c_)], [((_c_) == ':')],
6467     [Returns true if character is a device separator.])
6469   AC_DEFINE([IS_DIRECTORY_SEP(_c_)], [((_c_) == '/' || (_c_) == '\\')],
6470     [Returns true if character is a directory separator.])
6472   AC_DEFINE([IS_ANY_SEP(_c_)],
6473     [(IS_DIRECTORY_SEP (_c_) || IS_DEVICE_SEP (_c_))],
6474     [Returns true if character is any form of separator.])
6475 else
6476   AC_DEFINE([IS_DEVICE_SEP(_c_)], 0,
6477     [Returns true if character is a device separator.])
6479   AC_DEFINE([IS_DIRECTORY_SEP(_c_)], [((_c_) == DIRECTORY_SEP)],
6480     [Returns true if character is a directory separator.])
6482   AC_DEFINE([IS_ANY_SEP(_c_)], [(IS_DIRECTORY_SEP (_c_))],
6483     [Returns true if character is any form of separator.])
6486 if test "$USE_X_TOOLKIT" != "none"; then
6487   have_editres=yes
6488   case $opsys in
6489     hpux*)
6490       dnl Assar Westerlund <assar@sics.se> says this is necessary
6491       dnl for HP-UX 10.20, and that it works for HP-UX 0 as well.
6492       have_editres=no
6493     ;;
6494   esac
6495   if test "$have_editres" != no && test ! -z "$LIBXMU"; then
6496     OLDLIBS="$LIBS"
6497     dnl See libXmu.a check above.
6498     if test x$HAVE_X11XTR6 = xyes; then
6499       LIBS="-lXt -lSM -lICE $LIBXMU"
6500     else
6501       OTHERLIBS="-lXt -$LIBXMU"
6502     fi
6503     AC_LINK_IFELSE([AC_LANG_PROGRAM(
6504       [[#include <X11/Intrinsic.h>
6505        #include <X11/Xmu/Editres.h>]],
6506       [[_XEditResCheckMessages (0, 0, 0, 0);]])],
6507       [AC_DEFINE([X_TOOLKIT_EDITRES], [1],
6508         [Define to 1 if we should use XEditRes.])])
6509     LIBS=$OLDLIBS
6510   fi
6513 case $opsys in
6514   solaris | unixware )
6515     dnl Some SVr4s don't define NSIG in sys/signal.h for ANSI environments;
6516     dnl instead, there's a system variable _sys_nsig.  Unfortunately, we
6517     dnl need the constant to dimension an array.  So wire in the appropriate
6518     dnl value here.
6519     AC_DEFINE([NSIG_MINIMUM], [32], [Minimum value of NSIG.])
6520     ;;
6521 esac
6523 emacs_broken_SIGIO=no
6525 case $opsys in
6526   dnl SIGIO exists, but the feature doesn't work in the way Emacs needs.
6527   hpux* | nacl | solaris | unixware )
6528     emacs_broken_SIGIO=yes
6529     ;;
6531   aix4-2)
6532     dnl On AIX Emacs uses the gmalloc.c malloc implementation.  But given
6533     dnl the way this system works, libc functions that return malloced
6534     dnl memory use the libc malloc implementation. Calling xfree or
6535     dnl xrealloc on the results of such functions results in a crash.
6536     dnl
6537     dnl One solution for this could be to define SYSTEM_MALLOC in configure,
6538     dnl but that does not currently work on this system.
6539     dnl
6540     dnl It is possible to completely override the malloc implementation on
6541     dnl AIX, but that involves putting the malloc functions in a shared
6542     dnl library and setting the MALLOCTYPE environment variable to point to
6543     dnl that shared library.
6544     dnl
6545     dnl Emacs currently calls xrealloc on the results of get_current_dir name,
6546     dnl to avoid a crash just use the Emacs implementation for that function.
6547     dnl
6548     dnl FIXME We could change the AC_CHECK_FUNCS call near the start
6549     dnl of this file, so that we do not check for get_current_dir_name
6550     dnl on AIX.  But that might be fragile if something else ends
6551     dnl up testing for get_current_dir_name as a dependency.
6552     AC_DEFINE([BROKEN_GET_CURRENT_DIR_NAME], [1], [Define if
6553       get_current_dir_name should not be used.])
6554     ;;
6556   freebsd)
6557     dnl Circumvent a bug in FreeBSD.  In the following sequence of
6558     dnl writes/reads on a PTY, read(2) returns bogus data:
6559     dnl
6560     dnl write(2)  1022 bytes
6561     dnl write(2)   954 bytes, get EAGAIN
6562     dnl read(2)   1024 bytes in process_read_output
6563     dnl read(2)     11 bytes in process_read_output
6564     dnl
6565     dnl That is, read(2) returns more bytes than have ever been written
6566     dnl successfully.  The 1033 bytes read are the 1022 bytes written
6567     dnl successfully after processing (for example with CRs added if the
6568     dnl terminal is set up that way which it is here).  The same bytes will
6569     dnl be seen again in a later read(2), without the CRs.
6570     AC_DEFINE([BROKEN_PTY_READ_AFTER_EAGAIN], [1], [Define on FreeBSD to
6571       work around an issue when reading from a PTY.])
6572     ;;
6573 esac
6575 case $opsys in
6576   gnu-* | android | solaris | cygwin )
6577     dnl FIXME Can't we test if this exists (eg /proc/$$)?
6578     AC_DEFINE([HAVE_PROCFS], [1], [Define if you have the /proc filesystem.])
6579   ;;
6580 esac
6582 case $opsys in
6583   darwin | dragonfly | freebsd | netbsd | openbsd )
6584     AC_DEFINE([DONT_REOPEN_PTY], [1], [Define if process.c does not need to
6585       close a pty to make it a controlling terminal (it is already a
6586       controlling terminal of the subprocess, because we did ioctl TIOCSCTTY).])
6587   ;;
6588 esac
6590 dnl FIXME Surely we can test for this rather than hard-code it.
6591 case $opsys in
6592   netbsd | openbsd) sound_device="/dev/audio" ;;
6593   *) sound_device="/dev/dsp" ;;
6594 esac
6596 dnl Used in sound.c
6597 AC_DEFINE_UNQUOTED([DEFAULT_SOUND_DEVICE], ["$sound_device"],
6598   [Name of the default sound device.])
6601 dnl Emacs can read input using SIGIO and buffering characters itself,
6602 dnl or using CBREAK mode and making C-g cause SIGINT.
6603 dnl The choice is controlled by the variable interrupt_input.
6605 dnl Define INTERRUPT_INPUT to make interrupt_input = 1 the default (use SIGIO)
6607 dnl Emacs uses the presence of the USABLE_SIGIO macro
6608 dnl to indicate whether or not signal-driven I/O is possible.  It uses
6609 dnl INTERRUPT_INPUT to decide whether to use it by default.
6611 dnl SIGIO can be used only on systems that implement it (4.2 and 4.3).
6612 dnl CBREAK mode has two disadvantages
6613 dnl 1) At least in 4.2, it is impossible to handle the Meta key properly.
6614 dnl I hear that in system V this problem does not exist.
6615 dnl 2) Control-G causes output to be discarded.
6616 dnl I do not know whether this can be fixed in system V.
6618 dnl Another method of doing input is planned but not implemented.
6619 dnl It would have Emacs fork off a separate process
6620 dnl to read the input and send it to the true Emacs process
6621 dnl through a pipe.
6622 case $opsys in
6623   darwin | gnu-linux | gnu-kfreebsd)
6624     AC_DEFINE([INTERRUPT_INPUT], [1], [Define to read input using SIGIO.])
6625   ;;
6626 esac
6629 dnl If the system's imake configuration file defines 'NeedWidePrototypes'
6630 dnl as 'NO', we must define NARROWPROTO manually.  Such a define is
6631 dnl generated in the Makefile generated by 'xmkmf'.  If we don't define
6632 dnl NARROWPROTO, we will see the wrong function prototypes for X functions
6633 dnl taking float or double parameters.
6634 case $opsys in
6635   cygwin|gnu|gnu-linux|gnu-kfreebsd|freebsd|netbsd|openbsd)
6636     AC_DEFINE([NARROWPROTO], [1], [Define if system's imake configuration
6637       file defines 'NeedWidePrototypes' as 'NO'.])
6638   ;;
6639 esac
6642 dnl Used in process.c, this must be a loop, even if it only runs once.
6643 AH_TEMPLATE([PTY_ITERATION], [How to iterate over PTYs.])
6644 dnl Only used if !PTY_ITERATION.  Iterate from FIRST_PTY_LETTER to z,
6645 dnl trying suffixes 0-16.
6646 AH_TEMPLATE([FIRST_PTY_LETTER], [Letter to use in finding device name of
6647   first PTY, if PTYs are supported.])
6648 AH_TEMPLATE([PTY_OPEN], [How to open a PTY, if non-standard.])
6649 AH_TEMPLATE([PTY_NAME_SPRINTF], [How to get the device name of the control
6650   end of a PTY, if non-standard.])
6651 AH_TEMPLATE([PTY_TTY_NAME_SPRINTF], [How to get device name of the tty
6652   end of a PTY, if non-standard.])
6654 case $opsys in
6655   aix4-2 )
6656     AC_DEFINE([PTY_ITERATION], [int c; for (c = 0; !c ; c++)])
6657     dnl You allocate a pty by opening /dev/ptc to get the master side.
6658     dnl To get the name of the slave side, you just ttyname() the master side.
6659     AC_DEFINE([PTY_NAME_SPRINTF], [strcpy (pty_name, "/dev/ptc");])
6660     AC_DEFINE([PTY_TTY_NAME_SPRINTF], [strcpy (pty_name, ttyname (fd));])
6661     ;;
6663   cygwin )
6664     AC_DEFINE([PTY_ITERATION], [int i; for (i = 0; i < 1; i++)])
6665     dnl multi-line AC_DEFINEs are hard. :(
6666     AC_DEFINE([PTY_OPEN],
6667       [ do { int dummy; sigset_t blocked, procmask; sigemptyset (&blocked); sigaddset (&blocked, SIGCHLD); pthread_sigmask (SIG_BLOCK, &blocked, &procmask); if (-1 == openpty (&fd, &dummy, pty_name, 0, 0)) fd = -1; pthread_sigmask (SIG_SETMASK, &procmask, 0); if (fd >= 0) emacs_close (dummy); } while (false)])
6668     AC_DEFINE([PTY_NAME_SPRINTF], [])
6669     AC_DEFINE([PTY_TTY_NAME_SPRINTF], [])
6670     ;;
6672   gnu | qnxnto )
6673     AC_DEFINE([FIRST_PTY_LETTER], ['p'])
6674     ;;
6676   android )
6677     AC_DEFINE([PTY_ITERATION], [int i; for (i = 0; i < 1; ++i)])
6678     dnl grantpt may be defined in libc but not declared.  The same
6679     dnl goes for posix_openpt.  When that is the case, it means that
6680     dnl grantpt or posix_openpt cannot actually be used.
6681     AC_CHECK_DECLS([grantpt, posix_openpt])
6682     AS_IF([test "x$ac_cv_have_decl_grantpt" = xyes],
6683       [AC_DEFINE([PTY_TTY_NAME_SPRINTF],
6684         [{ char *ptyname = 0; sigset_t blocked; sigemptyset (&blocked); sigaddset (&blocked, SIGCHLD); pthread_sigmask (SIG_BLOCK, &blocked, 0); if (grantpt (fd) != -1 && unlockpt (fd) != -1) ptyname = ptsname(fd); pthread_sigmask (SIG_UNBLOCK, &blocked, 0); if (!ptyname) { emacs_close (fd); return -1; } snprintf (pty_name, PTY_NAME_SIZE, "%s", ptyname); }])],
6685       [AC_DEFINE([PTY_TTY_NAME_SPRINTF],
6686         [{ char *ptyname = 0; sigset_t blocked; sigemptyset (&blocked); sigaddset (&blocked, SIGCHLD); pthread_sigmask (SIG_BLOCK, &blocked, 0); if (unlockpt (fd) != -1) ptyname = ptsname(fd); pthread_sigmask (SIG_UNBLOCK, &blocked, 0); if (!ptyname) { emacs_close (fd); return -1; } snprintf (pty_name, PTY_NAME_SIZE, "%s", ptyname); }])])
6687     AS_IF([test "x$ac_cv_have_decl_posix_openpt" = xyes],
6688       [AC_DEFINE([PTY_OPEN],
6689         [do { fd = posix_openpt (O_RDWR | O_CLOEXEC | O_NOCTTY); if (fd < 0 && errno == EINVAL) fd = posix_openpt (O_RDWR | O_NOCTTY); } while (false)])
6690        AC_DEFINE([PTY_NAME_SPRINTF], [])],
6691       [AC_DEFINE([PTY_NAME_SPRINTF], [])
6692        AC_DEFINE([PTY_OPEN], [fd = getpt ()])])
6693     ;;
6695   gnu-linux | gnu-kfreebsd | dragonfly | freebsd | openbsd | netbsd | darwin | nacl )
6696     dnl if HAVE_GRANTPT
6697     if test "x$ac_cv_func_grantpt" = xyes; then
6698       AC_DEFINE([UNIX98_PTYS], [1], [Define if the system has Unix98 PTYs.])
6699       AC_DEFINE([PTY_ITERATION], [int i; for (i = 0; i < 1; i++)])
6700       dnl Note that grantpt and unlockpt may fork.  We must block SIGCHLD
6701       dnl to prevent sigchld_handler from intercepting the child's death.
6702       AC_DEFINE([PTY_TTY_NAME_SPRINTF],
6703         [{ char *ptyname = 0; sigset_t blocked; sigemptyset (&blocked); sigaddset (&blocked, SIGCHLD); pthread_sigmask (SIG_BLOCK, &blocked, 0); if (grantpt (fd) != -1 && unlockpt (fd) != -1) ptyname = ptsname(fd); pthread_sigmask (SIG_UNBLOCK, &blocked, 0); if (!ptyname) { emacs_close (fd); return -1; } snprintf (pty_name, PTY_NAME_SIZE, "%s", ptyname); }])
6704       dnl if HAVE_POSIX_OPENPT
6705       if test "x$ac_cv_func_posix_openpt" = xyes; then
6706         AC_DEFINE([PTY_OPEN],
6707           [do { fd = posix_openpt (O_RDWR | O_CLOEXEC | O_NOCTTY); if (fd < 0 && errno == EINVAL) fd = posix_openpt (O_RDWR | O_NOCTTY); } while (false)])
6708         AC_DEFINE([PTY_NAME_SPRINTF], [])
6709       dnl if HAVE_GETPT
6710       elif test "x$ac_cv_func_getpt" = xyes; then
6711         AC_DEFINE([PTY_OPEN], [fd = getpt ()])
6712         AC_DEFINE([PTY_NAME_SPRINTF], [])
6713       else
6714         AC_DEFINE([PTY_NAME_SPRINTF], [strcpy (pty_name, "/dev/ptmx");])
6715       fi
6716     else
6717       AC_DEFINE([FIRST_PTY_LETTER], ['p'])
6718     fi
6719     ;;
6721   hpux*)
6722     AC_DEFINE([FIRST_PTY_LETTER], ['p'])
6723     AC_DEFINE([PTY_NAME_SPRINTF],
6724       [sprintf (pty_name, "/dev/ptym/pty%c%x", c, i);])
6725     AC_DEFINE([PTY_TTY_NAME_SPRINTF],
6726       [sprintf (pty_name, "/dev/pty/tty%c%x", c, i);])
6727     ;;
6729   solaris )
6730     dnl On SysVr4, grantpt(3) forks a subprocess, so do not use
6731     dnl O_CLOEXEC when opening the pty, and keep the SIGCHLD handler
6732     dnl from intercepting that death.  If any child but grantpt's should die
6733     dnl within, it should be caught after sigrelse(2).
6734     AC_DEFINE([PTY_OPEN], [fd = open (pty_name, O_RDWR | O_NONBLOCK)])
6735     AC_DEFINE([PTY_TTY_NAME_SPRINTF],
6736       [{ char *ptsname (int), *ptyname; int grantpt_result; sigset_t blocked; sigemptyset (&blocked); sigaddset (&blocked, SIGCHLD); pthread_sigmask (SIG_BLOCK, &blocked, 0); grantpt_result = grantpt (fd); pthread_sigmask (SIG_UNBLOCK, &blocked, 0); if (grantpt_result == -1 || unlockpt (fd) == -1 || !(ptyname = ptsname (fd))) { emacs_close (fd); return -1; } snprintf (pty_name, PTY_NAME_SIZE, "%s", ptyname); }])
6737     ;;
6739   unixware )
6740     dnl Comments are as per solaris.
6741     AC_DEFINE([PTY_OPEN], [fd = open (pty_name, O_RDWR | O_NONBLOCK)])
6742     AC_DEFINE([PTY_TTY_NAME_SPRINTF],
6743       [{ char *ptsname (int), *ptyname; int grantpt_result; sigset_t blocked; sigemptyset (&blocked); sigaddset (&blocked, SIGCHLD); pthread_sigmask (SIG_BLOCK, &blocked, 0); grantpt_result = grantpt (fd); pthread_sigmask (SIG_UNBLOCK, &blocked, 0); if (grantpt_result == -1) fatal("could not grant slave pty"); if (unlockpt(fd) == -1) fatal("could not unlock slave pty"); if (!(ptyname = ptsname(fd))) fatal ("could not enable slave pty"); snprintf (pty_name, PTY_NAME_SIZE, "%s", ptyname); }])
6744     ;;
6746   haiku*)
6747     AC_DEFINE([FIRST_PTY_LETTER], ['s'])
6748     AC_DEFINE([PTY_NAME_SPRINTF], [])
6749     dnl on Haiku pty names aren't distinctive, thus the use of posix_openpt
6750     AC_DEFINE([PTY_OPEN], [fd = posix_openpt (O_RDWR | O_NONBLOCK)])
6751     AC_DEFINE([PTY_TTY_NAME_SPRINTF],
6752       [{ char *ptyname; int grantpt_result; sigset_t blocked; sigemptyset (&blocked); sigaddset (&blocked, SIGCHLD); pthread_sigmask (SIG_BLOCK, &blocked, 0); grantpt_result = grantpt (fd); pthread_sigmask (SIG_UNBLOCK, &blocked, 0); if (grantpt_result == -1) fatal("could not grant slave pty"); if (unlockpt(fd) == -1) fatal("could not unlock slave pty"); if (!(ptyname = ptsname(fd))) fatal ("could not enable slave pty"); snprintf (pty_name, PTY_NAME_SIZE, "%s", ptyname); }])
6753     ;;
6754 esac
6757 case $opsys in
6758   solaris | unixware )
6759     dnl This change means that we don't loop through allocate_pty too
6760     dnl many times in the (rare) event of a failure.
6761     AC_DEFINE([FIRST_PTY_LETTER], ['z'])
6762     AC_DEFINE([PTY_NAME_SPRINTF], [strcpy (pty_name, "/dev/ptmx");])
6763     dnl Push various streams modules onto a PTY channel.  Used in process.c.
6764     AC_DEFINE([SETUP_SLAVE_PTY],
6765       [if (ioctl (std_in, I_PUSH, "ptem") == -1) fatal ("ioctl I_PUSH ptem"); if (ioctl (std_in, I_PUSH, "ldterm") == -1) fatal ("ioctl I_PUSH ldterm"); if (ioctl (std_in, I_PUSH, "ttcompat") == -1) fatal ("ioctl I_PUSH ttcompat");], [How to set up a slave PTY, if needed.])
6766     ;;
6767 esac
6770 AH_TEMPLATE([SIGNALS_VIA_CHARACTERS], [Make process_send_signal work by
6771 "typing" a signal character on the pty.])
6773 case $opsys in
6774   dnl Perry Smith <pedz@ddivt1.austin.ibm.com> says this is correct for AIX.
6775   aix4-2 | cygwin | gnu | dragonfly | freebsd | netbsd | openbsd | darwin )
6776     AC_DEFINE([SIGNALS_VIA_CHARACTERS], [1])
6777     ;;
6779   dnl 21 Jun 06: Eric Hanchrow <offby1@blarg.net> says this works.
6780   dnl FIXME Does gnu-kfreebsd have linux/version.h?  It seems unlikely...
6781   gnu-linux | gnu-kfreebsd )
6783     AC_CACHE_CHECK([for signals via characters], [emacs_cv_signals_via_chars],
6784     [AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[
6785 #include <linux/version.h>
6786 #if LINUX_VERSION_CODE < 0x20400
6787 # error "Linux version too old"
6788 #endif
6789       ]], [[]])],
6790         [emacs_cv_signals_via_chars=yes],
6791         [emacs_cv_signals_via_chars=no])])
6793     test "$emacs_cv_signals_via_chars" = yes &&
6794       AC_DEFINE([SIGNALS_VIA_CHARACTERS], [1])
6795     ;;
6796 esac
6799 AH_TEMPLATE([TAB3], [Undocumented.])
6801 case $opsys in
6802   darwin) AC_DEFINE([TAB3], [OXTABS]) ;;
6804   gnu | dragonfly | freebsd | netbsd | openbsd )
6805     AC_DEFINE([TABDLY], [OXTABS], [Undocumented.])
6806     AC_DEFINE([TAB3], [OXTABS])
6807     ;;
6809   gnu-linux | gnu-kfreebsd )
6810     AC_PREPROC_IFELSE(
6811       [AC_LANG_PROGRAM(
6812          [[
6813 #ifndef __ia64__
6814 # error "not ia64"
6815 #endif
6816          ]], [[]])],
6817       [AC_DEFINE([GC_MARK_SECONDARY_STACK()],
6818         [do { extern void *__libc_ia64_register_backing_store_base; __builtin_ia64_flushrs (); mark_memory (__libc_ia64_register_backing_store_base, __builtin_ia64_bsp ());} while (false)],
6819         [Mark a secondary stack, like the register stack on the ia64.])], [])
6820     ;;
6822   hpux*)
6823     AC_DEFINE([RUN_TIME_REMAP], [1], [Define if emacs.c needs to call
6824       run_time_remap; for HPUX.])
6825     ;;
6826 esac
6829 dnl This won't be used automatically yet.  We also need to know, at least,
6830 dnl that the stack is continuous.
6831 AH_TEMPLATE([GC_SETJMP_WORKS], [Define if setjmp is known to save all
6832   registers relevant for conservative garbage collection in the jmp_buf.])
6835 case $opsys in
6836   dnl Not all the architectures are tested, but there are Debian packages
6837   dnl for SCM and/or Guile on them, so the technique must work.  See also
6838   dnl comments in alloc.c concerning setjmp and gcc.
6839   dnl Fixme: it's probably safe to just use the GCC conditional below.
6840   gnu-linux | gnu-kfreebsd )
6841     AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[
6842 #if defined __i386__ || defined __sparc__ || defined __mc68000__ \
6843   || defined __alpha__ || defined __mips__ || defined __s390__ \
6844   || defined __arm__ || defined __powerpc__ || defined __amd64__ \
6845   || defined __x86_64__ \
6846   || defined __ia64__ || defined __sh__
6847 /* ok */
6848 #else
6849 # error "setjmp not known to work on this arch"
6850 #endif
6851     ]], [[]])], [AC_DEFINE([GC_SETJMP_WORKS], [1])])
6852     ;;
6853 esac
6856 if test x$GCC = xyes; then
6857    dnl GC_SETJMP_WORKS is nearly always appropriate for GCC.
6858    AC_DEFINE([GC_SETJMP_WORKS], [1])
6859 else
6860   case $opsys in
6861     aix* | dragonfly | freebsd | netbsd | openbsd | solaris )
6862       AC_DEFINE([GC_SETJMP_WORKS], [1])
6863       ;;
6864   esac
6865 fi                              dnl GCC?
6867 dnl In a weird quirk, MS runtime uses _setjmp and longjmp.
6868 AC_CACHE_CHECK([for _setjmp], [emacs_cv_func__setjmp],
6869   [AC_LINK_IFELSE(
6870      [AC_LANG_PROGRAM(
6871        [[#include <setjmp.h>
6872          #ifdef __MINGW32__
6873          # define _longjmp longjmp
6874          #endif
6875        ]],
6876        [[jmp_buf j;
6877          if (! _setjmp (j))
6878            _longjmp (j, 1);]])],
6879      [emacs_cv_func__setjmp=yes],
6880      [emacs_cv_func__setjmp=no])])
6881 if test $emacs_cv_func__setjmp = yes; then
6882   AC_DEFINE([HAVE__SETJMP], [1], [Define to 1 if _setjmp and _longjmp work.])
6885 # We need to preserve signal mask to handle C stack overflows.
6886 AC_CACHE_CHECK([for sigsetjmp], [emacs_cv_func_sigsetjmp],
6887   [AC_LINK_IFELSE(
6888      [AC_LANG_PROGRAM(
6889        [[#include <setjmp.h>
6890        ]],
6891        [[sigjmp_buf j;
6892          if (! sigsetjmp (j, 1))
6893            siglongjmp (j, 1);]])],
6894      [emacs_cv_func_sigsetjmp=yes],
6895      [emacs_cv_func_sigsetjmp=no])])
6896 if test $emacs_cv_func_sigsetjmp = yes; then
6897   AC_DEFINE([HAVE_SIGSETJMP], [1],
6898     [Define to 1 if sigsetjmp and siglongjmp work.])
6901 case $emacs_cv_func_sigsetjmp,$emacs_cv_alternate_stack,$opsys in
6902   yes,yes,* | *,*,mingw32)
6903     AC_DEFINE([HAVE_STACK_OVERFLOW_HANDLING], [1],
6904       [Define to 1 if C stack overflow can be handled in some cases.]);;
6905 esac
6907 case $opsys in
6908   solaris | unixware )
6909     dnl TIOCGPGRP is broken in SysVr4, so we can't send signals to PTY
6910     dnl subprocesses the usual way.  But TIOCSIGNAL does work for PTYs,
6911     dnl and this is all we need.
6912     AC_DEFINE([TIOCSIGSEND], [TIOCSIGNAL], [Some platforms redefine this.])
6913     ;;
6914 esac
6917 case $opsys in
6918   hpux* | solaris )
6919     dnl Used in xfaces.c.
6920     AC_DEFINE([XOS_NEEDS_TIME_H], [1], [Compensate for a bug in Xos.h on
6921       some systems, where it requires time.h.])
6922     ;;
6923 esac
6926 dnl Define symbols to identify the version of Unix this is.
6927 dnl Define all the symbols that apply correctly.
6928 AH_TEMPLATE([DOS_NT], [Define if the system is MS DOS or MS Windows.])
6929 AH_TEMPLATE([MSDOS], [Define if the system is MS DOS.])
6930 AH_TEMPLATE([USG], [Define if the system is compatible with System III.])
6931 AH_TEMPLATE([USG5_4],
6932   [Define if the system is compatible with System V Release 4.])
6934 case $opsys in
6935   aix4-2)
6936     AC_DEFINE([USG], [])
6937     dnl This symbol should be defined on AIX Version 3  ???????
6938     AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[
6939 #ifndef _AIX
6940 # error "_AIX not defined"
6941 #endif
6942     ]], [[]])], [], [AC_DEFINE([_AIX], [], [Define if the system is AIX.])])
6943     ;;
6945   cygwin)
6946     AC_DEFINE([CYGWIN], [1], [Define if the system is Cygwin.])
6947     ;;
6949   darwin)
6950     dnl Not __APPLE__, as this may not be defined on non-macOS Darwin.
6951     dnl Not DARWIN, because Panther and lower CoreFoundation.h use DARWIN to
6952     dnl distinguish macOS from pure Darwin.
6953     AC_DEFINE([DARWIN_OS], [], [Define if the system is Darwin.])
6954     ;;
6956   gnu-linux | gnu-kfreebsd )
6957     AC_DEFINE([USG], [])
6958     AC_DEFINE([GNU_LINUX], [],
6959       [Define if this system is compatible with GNU/Linux.])
6960     ;;
6962   hpux*)
6963     AC_DEFINE([USG], [])
6964     AC_DEFINE([HPUX], [], [Define if the system is HPUX.])
6965     ;;
6967   mingw32)
6968     AC_DEFINE([DOS_NT], [])
6969     AC_DEFINE([WINDOWSNT], [1], [Define if compiling for native MS Windows.])
6970     if test "x$ac_enable_checking" != "x" ; then
6971       AC_DEFINE([EMACSDEBUG], [1],
6972         [Define to 1 to enable w32 debug facilities.])
6973     fi
6974     ;;
6976   solaris)
6977     AC_DEFINE([USG], [])
6978     AC_DEFINE([USG5_4], [])
6979     AC_DEFINE([SOLARIS2], [], [Define if the system is Solaris.])
6980     ;;
6982   unixware)
6983     AC_DEFINE([USG], [])
6984     AC_DEFINE([USG5_4], [])
6985     ;;
6987   haiku)
6988     AC_DEFINE([HAIKU], [], [Define if the system is Haiku.])
6989     ;;
6990 esac
6992 AC_SYS_POSIX_TERMIOS
6993 if test $ac_cv_sys_posix_termios = yes; then
6994   AC_CHECK_SIZEOF([speed_t], [], [#include <termios.h>])
6995   dnl on Haiku, and possibly other platforms, speed_t is defined to
6996   dnl unsigned char, even when speeds greater than 200 baud are
6997   dnl defined.
6999   if test ${ac_cv_sizeof_speed_t} -lt 2; then
7000     AC_DEFINE([HAVE_TINY_SPEED_T], [1],
7001         [Define to 1 if speed_t has some sort of nonsensically tiny size.])
7002   fi
7005 AC_CACHE_CHECK([for usable FIONREAD], [emacs_cv_usable_FIONREAD],
7006   [case $opsys in
7007      aix4-2 | nacl)
7008        dnl BUILD 9008 - FIONREAD problem still exists in X-Windows.
7009        emacs_cv_usable_FIONREAD=no
7010        ;;
7012      mingw32)
7013        emacs_cv_usable_FIONREAD=yes
7014        ;;
7016      *)
7017        AC_COMPILE_IFELSE(
7018          [AC_LANG_PROGRAM([[#include <sys/types.h>
7019                             #include <sys/ioctl.h>
7020                             #ifdef USG5_4
7021                             # include <sys/filio.h>
7022                             #endif
7023                           ]],
7024                           [[int foo = ioctl (0, FIONREAD, &foo);]])],
7025          [emacs_cv_usable_FIONREAD=yes],
7026          [emacs_cv_usable_FIONREAD=no])
7027        ;;
7028    esac])
7029 if test $emacs_cv_usable_FIONREAD = yes; then
7030   AC_DEFINE([USABLE_FIONREAD], [1], [Define to 1 if FIONREAD is usable.])
7032   if test $emacs_broken_SIGIO = no; then
7033     AC_CACHE_CHECK([for usable SIGIO], [emacs_cv_usable_SIGIO],
7034       [AC_COMPILE_IFELSE(
7035          [AC_LANG_PROGRAM([[#include <fcntl.h>
7036                             #include <signal.h>
7037                           ]],
7038                           [[int foo = SIGIO | F_SETFL | FASYNC;]])],
7039          [emacs_cv_usable_SIGIO=yes],
7040          [emacs_cv_usable_SIGIO=no])],
7041       [emacs_cv_usable_SIGIO=yes],
7042       [emacs_cv_usable_SIGIO=no])
7043     if test $emacs_cv_usable_SIGIO = yes; then
7044       AC_DEFINE([USABLE_SIGIO], [1], [Define to 1 if SIGIO is usable.])
7045     fi
7046   fi
7048   if test $emacs_broken_SIGIO = no && test $emacs_cv_usable_SIGIO = no; then
7049     AC_CACHE_CHECK([for usable SIGPOLL], [emacs_cv_usable_SIGPOLL],
7050       [AC_COMPILE_IFELSE(
7051          [AC_LANG_PROGRAM([[#include <fcntl.h>
7052                             #include <signal.h>
7053                           ]],
7054                           [[int foo = SIGPOLL | F_SETFL;]])],
7055          [emacs_cv_usable_SIGPOLL=yes],
7056          [emacs_cv_usable_SIGPOLL=no])],
7057       [emacs_cv_usable_SIGPOLL=yes],
7058       [emacs_cv_usable_SIGPOLL=no])
7059     if test $emacs_cv_usable_SIGPOLL = yes; then
7060       AC_DEFINE([USABLE_SIGPOLL], [1], [Define to 1 if SIGPOLL is usable but SIGIO is not.])
7061     fi
7062   fi
7065 case $opsys in
7066   hpux11)
7067     dnl It works to open the pty's tty in the parent (Emacs), then
7068     dnl close and reopen it in the child.
7069     AC_DEFINE([USG_SUBTTY_WORKS], [1], [Define for USG systems where it
7070       works to open a pty's tty in the parent process, then close and
7071       reopen it in the child.])
7072     ;;
7074   solaris)
7075     AC_DEFINE([_STRUCTURED_PROC], [1], [Needed for system_process_attributes
7076       on Solaris.])
7077     ;;
7078 esac
7080 # Set up the CFLAGS for real compilation, so we can substitute it.
7081 CFLAGS="$REAL_CFLAGS"
7082 CPPFLAGS="$REAL_CPPFLAGS"
7083 LIBS="$REAL_LIBS"
7085 ## Hack to detect a buggy GCC version.
7086 if test "$GCC" = yes && \
7087    $CC --version 2> /dev/null | grep 'gcc.* 4.5.0' >/dev/null; then
7088   case $CFLAGS in
7089     *-fno-optimize-sibling-calls*) ;;
7090     *-O@<:@23@:>@*)
7091       AC_MSG_ERROR([GCC 4.5.0 has problems compiling Emacs; see etc/PROBLEMS.]);;
7092   esac
7095 version=$PACKAGE_VERSION
7097 copyright="Copyright (C) 2024 Free Software Foundation, Inc."
7098 AC_DEFINE_UNQUOTED([COPYRIGHT], ["$copyright"],
7099   [Short copyright string for this version of Emacs.])
7100 AC_SUBST([copyright])
7102 ### Specify what sort of things we'll be editing into Makefile and config.h.
7103 ### Use configuration here uncanonicalized to avoid exceeding size limits.
7104 AC_SUBST([version])
7105 AC_SUBST([configuration])
7106 ## Unused?
7107 AC_SUBST([canonical])
7108 AC_SUBST([srcdir])
7109 AC_SUBST([prefix])
7110 AC_SUBST([exec_prefix])
7111 AC_SUBST([bindir])
7112 AC_SUBST([datadir])
7113 AC_SUBST([gsettingsschemadir])
7114 AC_SUBST([sharedstatedir])
7115 AC_SUBST([libexecdir])
7116 AC_SUBST([mandir])
7117 AC_SUBST([infodir])
7118 AC_SUBST([lispdirrel])
7119 AC_SUBST([lispdir])
7120 AC_SUBST([standardlisppath])
7121 AC_SUBST([locallisppath])
7122 AC_SUBST([lisppath])
7123 AC_SUBST([x_default_search_path])
7124 AC_SUBST([etcdir])
7125 AC_SUBST([archlibdir])
7126 AC_SUBST([etcdocdir])
7127 AC_SUBST([bitmapdir])
7128 AC_SUBST([gamedir])
7129 AC_SUBST([gameuser])
7130 AC_SUBST([gamegroup])
7131 ## FIXME? Nothing uses @LD_SWITCH_X_SITE@.
7132 ## src/Makefile.in did add LD_SWITCH_X_SITE (as a cpp define) to the
7133 ## end of LIBX_BASE, but nothing ever set it.
7134 AC_SUBST([LD_SWITCH_X_SITE])
7135 AC_SUBST([C_SWITCH_X_SITE])
7136 AC_SUBST([GNUSTEP_CFLAGS])
7137 AC_SUBST([CFLAGS])
7138 ## Used in lwlib/Makefile.in.
7139 AC_SUBST([X_TOOLKIT_TYPE])
7140 AC_SUBST([ns_appdir])
7141 AC_SUBST([ns_appbindir])
7142 AC_SUBST([ns_applibexecdir])
7143 AC_SUBST([ns_applibdir])
7144 AC_SUBST([ns_appresdir])
7145 AC_SUBST([ns_appsrc])
7146 AC_SUBST([GNU_OBJC_CFLAGS])
7147 AC_SUBST([OTHER_FILES])
7149 if test -n "${term_header}"; then
7150     AC_DEFINE_UNQUOTED([TERM_HEADER], ["${term_header}"],
7151         [Define to the header for the built-in window system.])
7154 AC_DEFINE_UNQUOTED([EMACS_CONFIGURATION],  ["${canonical}"],
7155                    [Define to the canonical Emacs configuration name.])
7156 AC_DEFINE_UNQUOTED([EMACS_CONFIG_OPTIONS], "${emacs_config_options}",
7157                    [Define to the options passed to configure.])
7159 XMENU_OBJ=
7160 XOBJ=
7161 FONT_OBJ=
7162 if test "${HAVE_X_WINDOWS}" = "yes" ; then
7163   AC_DEFINE([HAVE_X_WINDOWS], [1],
7164             [Define to 1 if you want to use the X window system.])
7165   XMENU_OBJ=xmenu.o
7166   XOBJ="xterm.o xfns.o xselect.o xrdb.o xsmfns.o xsettings.o"
7167   FONT_OBJ=xfont.o
7168   if test "$HAVE_CAIRO" = "yes"; then
7169     FONT_OBJ="$FONT_OBJ ftfont.o ftcrfont.o"
7170   elif test "$HAVE_XFT" = "yes"; then
7171     FONT_OBJ="$FONT_OBJ ftfont.o xftfont.o"
7172   elif test "$HAVE_FREETYPE" = "yes"; then
7173     FONT_OBJ="$FONT_OBJ ftfont.o"
7174   fi
7177 if test "${window_system}" = "pgtk"; then
7178    FONT_OBJ="ftfont.o ftcrfont.o"
7181 if test "${HAVE_BE_APP}" = "yes" ; then
7182   if test "${HAVE_CAIRO}" = "yes"; then
7183     FONT_OBJ="$FONT_OBJ ftfont.o ftcrfont.o"
7184   fi
7187 if test "${HAVE_HARFBUZZ}" = "yes" ; then
7188   FONT_OBJ="$FONT_OBJ hbfont.o"
7190 AC_SUBST([FONT_OBJ])
7191 AC_SUBST([XMENU_OBJ])
7192 AC_SUBST([XOBJ])
7193 AC_SUBST([FONT_OBJ])
7195 WIDGET_OBJ=
7196 MOTIF_LIBW=
7197 if test "${USE_X_TOOLKIT}" != "none" ; then
7198   WIDGET_OBJ=widget.o
7199   AC_DEFINE([USE_X_TOOLKIT], [1], [Define to 1 if using an X toolkit.])
7200   if test "${USE_X_TOOLKIT}" = "LUCID"; then
7201     AC_DEFINE([USE_LUCID], [1], [Define to 1 if using the Lucid X toolkit.])
7202   elif test "${USE_X_TOOLKIT}" = "MOTIF"; then
7203     AC_DEFINE([USE_MOTIF], [1], [Define to 1 if using the Motif X toolkit.])
7204     MOTIF_LIBW=-lXm
7205     case "$opsys" in
7206       gnu-linux)
7207         ## Paul Abrahams <abrahams at equinox.shaysnet.com> says this is needed.
7208         MOTIF_LIBW="$MOTIF_LIBW -lXpm"
7209         ;;
7211       unixware)
7212         ## Richard Anthony Ryan <ryanr at ellingtn.ftc.nrcs.usda.gov>
7213         ## says -lXimp is needed in UNIX_SV ... 4.2 1.1.2.
7214         MOTIF_LIBW="MOTIF_LIBW -lXimp"
7215         ;;
7217       aix4-2)
7218         ## olson@mcs.anl.gov says -li18n is needed by -lXm.
7219         MOTIF_LIBW="$MOTIF_LIBW -li18n"
7220         ;;
7221     esac
7222     MOTIF_LIBW="$MOTIF_LIBW $LIBXP"
7223   fi
7225 AC_SUBST([WIDGET_OBJ])
7227 TOOLKIT_LIBW=
7228 case "$USE_X_TOOLKIT" in
7229   MOTIF) TOOLKIT_LIBW="$MOTIF_LIBW" ;;
7230   LUCID) TOOLKIT_LIBW="$LUCID_LIBW" ;;
7231   none) test "x$HAVE_GTK" = "xyes" && TOOLKIT_LIBW="$GTK_LIBS" ;;
7232 esac
7233 if test "$HAVE_XWIDGETS" = "yes"; then
7234   TOOLKIT_LIBW="$TOOLKIT_LIBW -lXcomposite"
7236 AC_SUBST([TOOLKIT_LIBW])
7238 if test "${opsys}" != "mingw32"; then
7239   if test "$USE_X_TOOLKIT" = "none"; then
7240     LIBXT_OTHER="\$(LIBXSM)"
7241   else
7242     LIBXT_OTHER="\$(LIBXMU) -lXt \$(LIBXTR6) -lXext"
7243   fi
7245 AC_SUBST([LIBXT_OTHER])
7247 if test "${HAVE_X11}" = "yes" ; then
7248   AC_DEFINE([HAVE_X11], [1],
7249             [Define to 1 if you want to use version 11 of X windows.])
7250   LIBX_OTHER="\$(LIBXT) \$(LIBX_EXTRA)"
7251 else
7252   LIBX_OTHER=
7254 AC_SUBST([LIBX_OTHER])
7256 HAVE_OLDXMENU=no
7257 if test "$HAVE_GTK" = yes || test "$HAVE_X11" != yes; then
7258   LIBXMENU=
7259 elif test "$USE_X_TOOLKIT" = none; then
7260   HAVE_OLDXMENU=yes
7261   LIBXMENU='$(oldXMenudir)/libXMenu11.a'
7262   AUTODEPEND_PARENTS="$AUTODEPEND_PARENTS oldXMenu"
7263 else
7264   LIBXMENU='$(lwlibdir)/liblw.a'
7265   AUTODEPEND_PARENTS="$AUTODEPEND_PARENTS lwlib"
7267 AC_SUBST([LIBXMENU])
7269 AC_CACHE_CHECK([for struct alignment],
7270   [emacs_cv_struct_alignment],
7271   [AC_COMPILE_IFELSE(
7272      [AC_LANG_PROGRAM([[#include <stddef.h>
7273                         struct s { char c; } __attribute__ ((aligned (8)));
7274                         struct t { char c; struct s s; };
7275                         char verify[offsetof (struct t, s) == 8 ? 1 : -1];
7276                       ]])],
7277      [emacs_cv_struct_alignment=yes],
7278      [emacs_cv_struct_alignment=no])])
7279 if test "$emacs_cv_struct_alignment" = yes; then
7280   AC_DEFINE([HAVE_STRUCT_ATTRIBUTE_ALIGNED], [1],
7281     [Define to 1 if 'struct __attribute__ ((aligned (N)))' aligns the
7282      structure to an N-byte boundary.])
7285 AC_C_RESTRICT
7286 AC_C_TYPEOF
7288 AC_CACHE_CHECK([for statement expressions],
7289   [emacs_cv_statement_expressions],
7290   [AC_COMPILE_IFELSE(
7291      [AC_LANG_PROGRAM([], [[return ({ int x = 5; x-x; });]])],
7292      [emacs_cv_statement_expressions=yes],
7293      [emacs_cv_statement_expressions=no])])
7294 if test "$emacs_cv_statement_expressions" = yes; then
7295   AC_DEFINE([HAVE_STATEMENT_EXPRESSIONS], [1],
7296     [Define to 1 if statement expressions work.])
7299 if test "${GNU_MALLOC}" = "yes" ; then
7300   AC_DEFINE([GNU_MALLOC], [1],
7301             [Define to 1 if you want to use the GNU memory allocator.])
7304 RALLOC_OBJ=
7305 if test "${REL_ALLOC}" = "yes" ; then
7306   AC_DEFINE([REL_ALLOC], [1],
7307             [Define REL_ALLOC if you want to use the relocating allocator for
7308              buffer space.])
7310   test "$system_malloc" != "yes" && RALLOC_OBJ=ralloc.o
7312 AC_SUBST([RALLOC_OBJ])
7314 if test "$opsys" = "cygwin"; then
7315   CYGWIN_OBJ="cygw32.o"
7316   ## Cygwin differs because of its unexec().
7317   PRE_ALLOC_OBJ=
7318   POST_ALLOC_OBJ=lastfile.o
7319 elif test "$opsys" = "mingw32"; then
7320   CYGWIN_OBJ=
7321   PRE_ALLOC_OBJ=
7322   POST_ALLOC_OBJ=lastfile.o
7323 else
7324   CYGWIN_OBJ=
7325   PRE_ALLOC_OBJ=lastfile.o
7326   POST_ALLOC_OBJ=
7328 AC_SUBST([CYGWIN_OBJ])
7329 AC_SUBST([PRE_ALLOC_OBJ])
7330 AC_SUBST([POST_ALLOC_OBJ])
7332 dnl Call this 'FORTIFY_SOUR' so that it sorts before the 'FORTIFY_SOURCE'
7333 dnl verbatim defined above.  The tricky name is apropos, as this hack
7334 dnl makes Fortify go sour!
7335 AH_VERBATIM([FORTIFY_SOUR],
7336 [/* Without the following workaround, Emacs runs slowly on OS X 10.8.
7337    The workaround disables some useful run-time checking, so it
7338    should be conditional to the platforms with the performance bug.
7339    Perhaps Apple will fix this some day; also see m4/extern-inline.m4.  */
7340 #if defined __APPLE__ && defined __GNUC__
7341 # ifndef _DONT_USE_CTYPE_INLINE_
7342 #  define _DONT_USE_CTYPE_INLINE_
7343 # endif
7344 # ifndef _FORTIFY_SOURCE
7345 #  define _FORTIFY_SOURCE 0
7346 # endif
7347 #endif
7350 # If user asks to omit features, disable optional features that gnulib
7351 # might otherwise enable.
7352 if test "$with_features" = no && test "$enable_acl" != yes; then
7353   enable_acl=no
7356 # Configure gnulib.  Although this does not affect CFLAGS or LIBS permanently.
7357 # it temporarily reverts them to their pre-pkg-config values,
7358 # because gnulib needs to work with both src (which uses the
7359 # pkg-config stuff) and lib-src (which does not).  For example, gnulib
7360 # may need to determine whether CLOCK_TIME_LIB should contain -lrt,
7361 # and it therefore needs to run in an environment where LIBS does not
7362 # already contain -lrt merely because 'pkg-config --libs' printed '-lrt'
7363 # for some package unrelated to lib-src.
7364 SAVE_CFLAGS=$CFLAGS
7365 SAVE_LIBS=$LIBS
7366 CFLAGS=$pre_PKG_CONFIG_CFLAGS
7367 LIBS="$LIB_PTHREAD $pre_PKG_CONFIG_LIBS"
7368 gl_ASSERT_NO_GNULIB_POSIXCHECK
7369 gl_ASSERT_NO_GNULIB_TESTS
7370 gl_EEMALLOC
7371 gl_INIT
7372 CFLAGS=$SAVE_CFLAGS
7373 LIBS=$SAVE_LIBS
7375 # Set up libgmp on Android.  Make sure to override what gnulib has
7376 # found.
7377 LIBGMP_CFLAGS=
7378 if test "$REALLY_ANDROID" = "yes" && test "$with_libgmp" != "no"; then
7379   HAVE_LIBGMP=no
7380   ndk_SEARCH_MODULE([libgmp], [LIBGMP], [HAVE_LIBGMP=yes])
7382   if test "$HAVE_LIBGMP" = "yes"; then
7383     SAVE_CFLAGS="$CFLAGS"
7384     CFLAGS="$CFLAGS $LIBGMP_CFLAGS"
7385     unset ac_cv_header_gmp_h
7386     unset ac_cv_header_gmp_gmp_h
7387     AC_CHECK_HEADERS([gmp.h gmp/gmp.h], [break])
7388     CFLAGS="$SAVE_CFLAGS"
7389     GL_GENERATE_GMP_H=
7390     GL_GENERATE_GMP_H_CONDITION=
7391     GL_GENERATE_GMP_GMP_H=
7392     GL_GENERATE_GMP_GMP_H_CONDITION=
7393     GL_GENERATE_MINI_GMP_H=
7394     GL_GENERATE_MINI_GMP_H_CONDITION=
7396     if test "$ac_cv_header_gmp_h" != "no" \
7397        || test "$ac_cv_header_gmp_gmp_h" != "no"; then
7398        HAVE_LIBGMP=yes
7399        GL_GENERATE_GMP_H=false
7400        LIBGMP="$LIBGMP_LIBS"
7401        GMP_H=
7402     fi
7403   fi
7405 AC_SUBST([LIBGMP_CFLAGS])
7407 # timer_getoverrun needs the same library as timer_settime
7408 OLD_LIBS=$LIBS
7409 LIBS="$LIB_TIMER_TIME $LIBS"
7410 AC_CHECK_FUNCS([timer_getoverrun])
7411 LIBS=$OLD_LIBS
7413 if test "${opsys}" = "mingw32"; then
7414   CPPFLAGS="$CPPFLAGS -DUSE_CRT_DLL=1 -I \${abs_top_srcdir}/nt/inc"
7415   # Remove unneeded switches from the value of CC that goes to Makefiles
7416   CC=`AS_ECHO(["$CC"]) | sed -e "s,$GCC_TEST_OPTIONS,,"`
7419 case "$opsys" in
7420   aix4-2) LD_SWITCH_SYSTEM_TEMACS="-Wl,-bnodelcsect" ;;
7422   cygwin) LD_SWITCH_SYSTEM_TEMACS="-Wl,-stack,0x00800000" ;;
7424   darwin)
7425    if test "$HAVE_NS" = "yes"; then
7426      libs_nsgui="-framework AppKit"
7427      if test "$NS_IMPL_COCOA" = "yes"; then
7428         libs_nsgui="$libs_nsgui -framework IOKit -framework Carbon \
7429                     -framework IOSurface -framework QuartzCore"
7430         if test "$emacs_cv_macosx_12_0" = "yes"; then
7431           libs_nsgui="$libs_nsgui -framework UniformTypeIdentifiers"
7432         fi
7433      fi
7434    else
7435      libs_nsgui=
7436    fi
7437    LD_SWITCH_SYSTEM_TEMACS=$libs_nsgui
7438    ## The -headerpad option tells ld (see man page) to leave room at the
7439    ## end of the header for adding load commands.  Needed for dumping.
7440    ## 0x1000 is enough for roughly 52 load commands on the x86_64
7441    ## architecture (where they are 78 bytes each). The actual number of
7442    ## load commands added is not consistent but normally ranges from
7443    ## about 14 to about 34. Setting it high gets us plenty of slop and
7444    ## only costs about 1.5K of wasted binary space.
7445    headerpad_extra=1000
7446    if test "$with_unexec" = yes; then
7447      LD_SWITCH_SYSTEM_TEMACS="-fno-pie $LD_SWITCH_SYSTEM_TEMACS -Xlinker -headerpad -Xlinker $headerpad_extra"
7448    fi
7450    ## This is here because src/Makefile.in did some extra fiddling around
7451    ## with LD_SWITCH_SYSTEM.  It seems cleaner to put this in
7452    ## LD_SWITCH_SYSTEM_TEMACS instead,
7453    test "x$LD_SWITCH_SYSTEM" = "x" && test "x$GCC" != "xyes" && \
7454      LD_SWITCH_SYSTEM_TEMACS="-X $LD_SWITCH_SYSTEM_TEMACS"
7455    ;;
7457   ## LD_SWITCH_X_SITE_RPATH is a -rpath option saying where to
7458   ## find X at run-time.
7459   ## When handled by cpp, this was in LD_SWITCH_SYSTEM.  However, at the
7460   ## point where configure sourced the s/*.h file, LD_SWITCH_X_SITE_RPATH
7461   ## had not yet been defined and was expanded to null.  Hence LD_SWITCH_SYSTEM
7462   ## had different values in configure (in ac_link) and src/Makefile.in.
7463   ## It seems clearer therefore to put this piece in LD_SWITCH_SYSTEM_TEMACS.
7464   gnu*) LD_SWITCH_SYSTEM_TEMACS="\$(LD_SWITCH_X_SITE_RPATH)" ;;
7466   mingw32)
7467    ## Is it any better under MinGW64 to relocate emacs into higher addresses?
7468    ## If the values of -image-base are modified, the corresponding
7469    ## values of DEFAULT_IMAGE_BASE in w32fns.c should be kept in sync.
7470    case "$canonical" in
7471      x86_64-*-*) LD_SWITCH_SYSTEM_TEMACS="-Wl,-stack,0x00800000 -Wl,-heap,0x00100000 -Wl,-image-base,0x400000000 -Wl,-entry,__start -Wl,-Map,./temacs.map" ;;
7472      *) LD_SWITCH_SYSTEM_TEMACS="-Wl,-stack,0x00800000 -Wl,-heap,0x00100000 -Wl,-image-base,0x01000000 -Wl,-entry,__start -Wl,-Map,./temacs.map" ;;
7473    esac
7474    ## If they want unexec, disable Windows ASLR for the Emacs binary
7475    if test "$with_dumping" = "unexec"; then
7476       case "$canonical" in
7477         x86_64-*-*) LD_SWITCH_SYSTEM_TEMACS="$LD_SWITCH_SYSTEM_TEMACS -Wl,-disable-dynamicbase -Wl,-disable-high-entropy-va -Wl,-default-image-base-low" ;;
7478         *) LD_SWITCH_SYSTEM_TEMACS="$LD_SWITCH_SYSTEM_TEMACS -Wl,-disable-dynamicbase" ;;
7479       esac
7480    fi
7481    ;;
7483   *) LD_SWITCH_SYSTEM_TEMACS= ;;
7484 esac
7486 # -no-pie or -nopie fixes a temacs segfault on Gentoo, OpenBSD,
7487 # Ubuntu, and other systems with "hardened" GCC configurations for
7488 # some reason (Bug#18784).  We don't know why this works, but not
7489 # segfaulting is better than segfaulting.  Use ac_c_werror_flag=yes
7490 # when trying the option, otherwise clang keeps warning that it does
7491 # not understand it, and pre-4.6 GCC has a similar problem
7492 # (Bug#20338).  Prefer -no-pie to -nopie, as -no-pie is the
7493 # spelling used by GCC 6.1.0 and later (Bug#24682).
7494 AC_CACHE_CHECK(
7495   [for $CC option to disable position independent executables],
7496   [emacs_cv_prog_cc_no_pie],
7497   [if test $with_unexec = no; then
7498      emacs_cv_prog_cc_no_pie='not needed'
7499    else
7500      emacs_save_c_werror_flag=$ac_c_werror_flag
7501      emacs_save_LDFLAGS=$LDFLAGS
7502      ac_c_werror_flag=yes
7503      for emacs_cv_prog_cc_no_pie in -no-pie -nopie no; do
7504        test $emacs_cv_prog_cc_no_pie = no && break
7505        LDFLAGS="$emacs_save_LDFLAGS $emacs_cv_prog_cc_no_pie"
7506        AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [break])
7507      done
7508      ac_c_werror_flag=$emacs_save_c_werror_flag
7509      LDFLAGS=$emacs_save_LDFLAGS
7510    fi])
7511 case $emacs_cv_prog_cc_no_pie in
7512   -*)
7513     LD_SWITCH_SYSTEM_TEMACS="$LD_SWITCH_SYSTEM_TEMACS $emacs_cv_prog_cc_no_pie"
7514     ;;
7515 esac
7517 if test x$ac_enable_profiling != x ; then
7518   case $opsys in
7519     *freebsd | gnu-linux) ;;
7520     *) LD_SWITCH_SYSTEM_TEMACS="$LD_SWITCH_SYSTEM_TEMACS -pg" ;;
7521   esac
7524 LD_SWITCH_SYSTEM_TEMACS="$LDFLAGS_NOCOMBRELOC $LD_SWITCH_SYSTEM_TEMACS"
7526 AC_SUBST([LD_SWITCH_SYSTEM_TEMACS])
7528 ## Common for all window systems
7529 if test "$window_system" != "none"; then
7530   AC_DEFINE([HAVE_WINDOW_SYSTEM], [1], [Define if you have a window system.])
7531   AC_DEFINE([POLL_FOR_INPUT], [1],
7532     [Define if you poll periodically to detect C-g.])
7533   WINDOW_SYSTEM_OBJ="fontset.o fringe.o image.o"
7535   if test "$window_system" = "x11" || test "$REALLY_ANDROID" = "yes"; then
7536     AC_DEFINE([HAVE_TEXT_CONVERSION], [1],
7537       [Define if the window system has text conversion support.])
7538     WINDOW_SYSTEM_OBJ="$WINDOW_SYSTEM_OBJ textconv.o"
7539   fi
7542 AC_SUBST([WINDOW_SYSTEM_OBJ])
7544 # Some systems have MB_CUR_MAX defined to a call to
7545 # __ctype_get_mb_cur_max, but do not have __ctype_get_mb_cur_max in
7546 # libc.  Check for that situation and define MB_CUR_MAX to something
7547 # sane.
7549 AC_CHECK_FUNC([__ctype_get_mb_cur_max])
7551 AC_CACHE_CHECK([whether MB_CUR_MAX is defined to function that won't link],
7552   [emacs_cv_broken_mb_cur_max],
7553   [AC_EGREP_CPP(__ctype_get_mb_cur_max, [
7554 #include <stdlib.h>
7555 #ifndef MB_CUR_MAX
7556 #define MB_CUR_MAX -1
7557 #endif
7558 static int foo = MB_CUR_MAX;
7559 ], [AS_IF([test "$ac_cv_func___ctype_get_mb_cur_max" = "yes"],
7560      [emacs_cv_broken_mb_cur_max=no],
7561      [emacs_cv_broken_mb_cur_max=yes])],
7562   [emacs_cv_broken_mb_cur_max=no])])
7564 AS_IF([test "$emacs_cv_broken_mb_cur_max" = "yes"],
7565  # Define this to 4, which is right for Android.
7566  [AS_CASE([$opsys], [android],
7567    [AC_DEFINE([REPLACEMENT_MB_CUR_MAX], [4],
7568       [Define to MB_CUR_MAX if stdlib.h is broken.])],
7569    [AC_MSG_ERROR([MB_CUR_MAX does not work on your system.
7570 Please modify configure.ac to set an appropriate value, then
7571 send your change to bug-gnu-emacs@gnu.org])])])
7573 AH_TOP([/* GNU Emacs site configuration template file.
7575 Copyright (C) 1988, 1993-1994, 1999-2002, 2004-2021
7576   Free Software Foundation, Inc.
7578 This file is part of GNU Emacs.
7580 GNU Emacs is free software: you can redistribute it and/or modify
7581 it under the terms of the GNU General Public License as published by
7582 the Free Software Foundation, either version 3 of the License, or (at
7583 your option) any later version.
7585 GNU Emacs is distributed in the hope that it will be useful,
7586 but WITHOUT ANY WARRANTY; without even the implied warranty of
7587 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7588 GNU General Public License for more details.
7590 You should have received a copy of the GNU General Public License
7591 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
7594 /* No code in Emacs #includes config.h twice, but some bits of code
7595    intended to work with other packages as well (like gmalloc.c)
7596    think they can include it as many times as they like.  */
7597 #ifndef EMACS_CONFIG_H
7598 #define EMACS_CONFIG_H
7599 ])dnl
7601 AH_BOTTOM([#include <conf_post.h>
7603 #endif /* EMACS_CONFIG_H */
7606 Local Variables:
7607 mode: c
7608 End:
7610 ])dnl
7612 #### Report on what we decided to do.
7613 #### Report GTK as a toolkit, even if it doesn't use Xt.
7614 #### It makes printing result more understandable as using GTK sets
7615 #### toolkit_scroll_bars to yes by default.
7616 if test "${HAVE_GTK}" = "yes"; then
7617   USE_X_TOOLKIT="$USE_GTK_TOOLKIT"
7620 if test $USE_ACL -ne 0; then
7621   ACL_SUMMARY="yes"
7622   test "$LIB_ACL" && ACL_SUMMARY="$ACL_SUMMARY $LIB_ACL"
7623   test "$LIB_XATTR" && ACL_SUMMARY="$ACL_SUMMARY $LIB_XATTR"
7624 else
7625   ACL_SUMMARY=no
7628 if test -z "$GMP_H"; then
7629   HAVE_GMP=yes
7630 else
7631   HAVE_GMP=no
7634 emacs_standard_dirs='Standard dirs'
7635 AS_ECHO(["
7636 Configured for '${canonical}'.
7638   Where should the build process find the source code?    ${srcdir}
7639   What compiler should emacs be built with?               ${CC} ${CFLAGS}
7640   Should Emacs use the GNU version of malloc?             ${GNU_MALLOC}${GNU_MALLOC_reason}
7641   Should Emacs use a relocating allocator for buffers?    ${REL_ALLOC}
7642   Should Emacs use mmap(2) for buffer allocation?         $use_mmap_for_buffers
7643   What window system should Emacs use?                    ${window_system}
7644   What toolkit should Emacs use?                          ${USE_X_TOOLKIT}
7645   Where do we find X Windows header files?                ${x_includes:-$emacs_standard_dirs}
7646   Where do we find X Windows libraries?                   ${x_libraries:-$emacs_standard_dirs}"])
7648 #### Please respect alphabetical ordering when making additions.
7649 optsep=
7650 emacs_config_features=
7651 for opt in ACL BE_APP CAIRO DBUS FREETYPE GCONF GIF GLIB GMP GNUTLS GPM GSETTINGS \
7652  HARFBUZZ IMAGEMAGICK JPEG LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 \
7653  M17N_FLT MODULES NATIVE_COMP NOTIFY NS OLDXMENU PDUMPER PGTK PNG RSVG SECCOMP \
7654  SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER \
7655  UNEXEC WEBP X11 XAW3D XDBE XFT XIM XINPUT2 XPM XWIDGETS X_TOOLKIT \
7656  ZLIB; do
7658     case $opt in
7659       PDUMPER) val=${with_pdumper} ;;
7660       UNEXEC) val=${with_unexec} ;;
7661       GLIB) val=${emacs_cv_links_glib} ;;
7662       NOTIFY|ACL) eval val=\${${opt}_SUMMARY} ;;
7663       TOOLKIT_SCROLL_BARS|X_TOOLKIT) eval val=\${USE_$opt} ;;
7664       THREADS) val=${threads_enabled} ;;
7665       *) eval val=\${HAVE_$opt} ;;
7666     esac
7667     case x$val in
7668       xno|xnone|x) continue ;;
7669     esac
7670     case $opt in
7671       X_TOOLKIT)
7672         case $val in
7673           GTK*|LUCID|MOTIF) opt=$val ;;
7674           *) continue ;;
7675         esac
7676       ;;
7677       NOTIFY)
7678         case $val in
7679           *lkqueue*) opt="$opt LIBKQUEUE" ;;
7680           *kqueue*) opt="$opt KQUEUE" ;;
7681           *inotify*) opt="$opt INOTIFY" ;;
7682           *gfile*) opt="$opt GFILENOTIFY" ;;
7683           *w32*) opt="$opt W32NOTIFY" ;;
7684         esac
7685       ;;
7686     esac
7687     AS_VAR_APPEND([emacs_config_features], ["$optsep$opt"])
7688     optsep=' '
7689 done
7690 AC_DEFINE_UNQUOTED([EMACS_CONFIG_FEATURES], ["${emacs_config_features}"],
7691   [Summary of some of the main features enabled by configure.])
7693 # This is just a printable representation of the shared user ID.
7694 android_shared_user=
7695 AS_IF([test -n "$with_shared_user_id"],[android_shared_user="($with_shared_user_id)"])
7697 AS_ECHO(["  Does Emacs use -lXaw3d?                                 ${HAVE_XAW3D}
7698   Is Emacs being built for Android?                       ${ANDROID} ${android_shared_user}
7699   Does Emacs use the X Double Buffer Extension?           ${HAVE_XDBE}
7700   Does Emacs use -lXpm?                                   ${HAVE_XPM}
7701   Does Emacs use -ljpeg?                                  ${HAVE_JPEG}
7702   Does Emacs use -ltiff?                                  ${HAVE_TIFF}
7703   Does Emacs use a gif library?                           ${HAVE_GIF} $LIBGIF
7704   Does Emacs use a png library?                           ${HAVE_PNG} $LIBPNG
7705   Does Emacs use -lrsvg-2?                                ${HAVE_RSVG}
7706   Does Emacs use -lwebp?                                  ${HAVE_WEBP}
7707   Does Emacs use -lsqlite3?                               ${HAVE_SQLITE3}
7708   Does Emacs use cairo?                                   ${HAVE_CAIRO}
7709   Does Emacs use -llcms2?                                 ${HAVE_LCMS2}
7710   Does Emacs use imagemagick?                             ${HAVE_IMAGEMAGICK}
7711   Does Emacs use native APIs for images?                  ${NATIVE_IMAGE_API}
7712   Does Emacs support sound?                               ${HAVE_SOUND}
7713   Does Emacs use -lgpm?                                   ${HAVE_GPM}
7714   Does Emacs use -ldbus?                                  ${HAVE_DBUS}
7715   Does Emacs use -lgconf?                                 ${HAVE_GCONF}
7716   Does Emacs use GSettings?                               ${HAVE_GSETTINGS}
7717   Does Emacs use a file notification library?             ${NOTIFY_SUMMARY}
7718   Does Emacs use access control lists?                    ${ACL_SUMMARY}
7719   Does Emacs use -lselinux?                               ${HAVE_LIBSELINUX}
7720   Does Emacs use -lgnutls?                                ${HAVE_GNUTLS}
7721   Does Emacs use -lxml2?                                  ${HAVE_LIBXML2}
7722   Does Emacs use -lfreetype?                              ${HAVE_FREETYPE}
7723   Does Emacs use HarfBuzz?                                ${HAVE_HARFBUZZ}
7724   Does Emacs use -lm17n-flt?                              ${HAVE_M17N_FLT}
7725   Does Emacs use -lotf?                                   ${HAVE_LIBOTF}
7726   Does Emacs use -lxft?                                   ${HAVE_XFT}
7727   Does Emacs use -lsystemd?                               ${HAVE_LIBSYSTEMD}
7728   Does Emacs use -ltree-sitter?                           ${HAVE_TREE_SITTER}
7729   Does Emacs use the GMP library?                         ${HAVE_GMP}
7730   Does Emacs directly use zlib?                           ${HAVE_ZLIB}
7731   Does Emacs have dynamic modules support?                ${HAVE_MODULES}
7732   Does Emacs use toolkit scroll bars?                     ${USE_TOOLKIT_SCROLL_BARS}
7733   Does Emacs support Xwidgets?                            ${HAVE_XWIDGETS}
7734   Does Emacs have threading support in lisp?              ${threads_enabled}
7735   Does Emacs support the portable dumper?                 ${with_pdumper}
7736   Does Emacs support legacy unexec dumping?               ${with_unexec}
7737   Which dumping strategy does Emacs use?                  ${with_dumping}
7738   Does Emacs have native lisp compiler?                   ${HAVE_NATIVE_COMP}
7739   Does Emacs use version 2 of the X Input Extension?      ${HAVE_XINPUT2}
7740   Does Emacs generate a smaller-size Japanese dictionary? ${with_small_ja_dic}
7743 if test -n "${EMACSDATA}"; then
7744    AS_ECHO(["  Environment variable EMACSDATA set to:                  $EMACSDATA"])
7746 if test -n "${EMACSDOC}"; then
7747    AS_ECHO(["  Environment variable EMACSDOC set to:                   $EMACSDOC"])
7750 echo
7752 if test "$HAVE_NS" = "yes"; then
7753    echo
7754    AS_ECHO(["Run '${MAKE-make}' to build Emacs, then run 'src/emacs' to test it.
7755 Run '${MAKE-make} install' in order to build an application bundle.
7756 The application will go to nextstep/Emacs.app and can be run or moved
7757 from there."])
7758    if test "$EN_NS_SELF_CONTAINED" = "yes"; then
7759       echo "The application will be fully self-contained."
7760     else
7761       AS_ECHO(["The lisp resources for the application will be installed under ${prefix}.
7762 You may need to run \"${MAKE-make} install\" with sudo.  The application will fail
7763 to run if these resources are not installed."])
7764    fi
7765    echo
7768 case $opsys,$emacs_uname_r in
7769   cygwin,1.5.*)
7770     AC_MSG_WARN([[building Emacs on Cygwin 1.5 is not supported.]])
7771            echo
7772            ;;
7773   cygwin,3.0.[[0-7]]'('* | cygwin,3.1.[[0-2]]'('*)
7774     AC_DEFINE([HAVE_CYGWIN_O_PATH_BUG], [1],
7775       [Define to 1 if opening a FIFO, socket, or symlink with O_PATH is buggy.]);;
7776 esac
7778 # Remove any trailing slashes in these variables.
7779 case $prefix in
7780   */) prefix=`AS_DIRNAME(["$prefix."])`;;
7781 esac
7782 case $exec_prefix in
7783   */) exec_prefix=`AS_DIRNAME(["$exec_prefix."])`;;
7784 esac
7786 if test "$HAVE_NS" = "yes"; then
7787   if test "$NS_IMPL_GNUSTEP" = yes; then
7788     AC_CONFIG_FILES([nextstep/GNUstep/Emacs.base/Resources/Info-gnustep.plist:nextstep/templates/Info-gnustep.plist.in \
7789       nextstep/GNUstep/Emacs.base/Resources/Emacs.desktop:nextstep/templates/Emacs.desktop.in])
7790     ns_check_file=Resources/Info-gnustep.plist
7791   else
7792     AC_CONFIG_FILES([nextstep/Cocoa/Emacs.base/Contents/Info.plist:nextstep/templates/Info.plist.in \
7793       nextstep/Cocoa/Emacs.base/Contents/Resources/English.lproj/InfoPlist.strings:nextstep/templates/InfoPlist.strings.in])
7794     ns_check_file=Contents/Info.plist
7795   fi
7796   AC_SUBST([ns_check_file])
7799 AC_CONFIG_FILES([Makefile lib/gnulib.mk])
7801 dnl config.status treats $srcdir specially, so I think this is ok...
7802 ARCH_INDEPENDENT_CONFIG_FILES([$srcdir/doc/man/emacs.1])
7804 AC_CONFIG_FILES([lib/Makefile lib-src/Makefile oldXMenu/Makefile src/Makefile
7805                  lwlib/Makefile nextstep/Makefile nt/Makefile])
7806 ARCH_INDEPENDENT_CONFIG_FILES([doc/emacs/Makefile doc/misc/Makefile
7807                                doc/lispintro/Makefile doc/lispref/Makefile
7808                                lisp/Makefile leim/Makefile])
7810 SUBDIR_MAKEFILES="lib/Makefile lib-src/Makefile oldXMenu/Makefile src/Makefile lwlib/Makefile nextstep/Makefile nt/Makefile doc/emacs/Makefile doc/misc/Makefile doc/lispintro/Makefile doc/lispref/Makefile lisp/Makefile leim/Makefile"
7812 dnl The test/ directory is missing if './make-dist --no-tests' was used.
7813 opt_makefile=test/Makefile
7814 if test -f "$srcdir/$opt_makefile.in"; then
7815   SUBDIR_MAKEFILES="$SUBDIR_MAKEFILES $opt_makefile"
7816   dnl Again, it's best not to use a variable.  Though you can add
7817   dnl ", [], [opt_makefile='$opt_makefile']" and it should work.
7818   ARCH_INDEPENDENT_CONFIG_FILES([test/Makefile])
7819   ARCH_INDEPENDENT_CONFIG_FILES([test/manual/noverlay/Makefile])
7821 opt_makefile=test/infra/Makefile
7822 if test -f "$srcdir/$opt_makefile.in"; then
7823   SUBDIR_MAKEFILES="$SUBDIR_MAKEFILES $opt_makefile"
7824   dnl Again, it's best not to use a variable.  Though you can add
7825   dnl ", [], [opt_makefile='$opt_makefile']" and it should work.
7826   ARCH_INDEPENDENT_CONFIG_FILES([test/infra/Makefile])
7829 if test "$ANDROID" = "yes"; then
7830   SUBDIR_MAKEFILES="$SUBDIR_MAKEFILES java/Makefile cross/Makefile"
7833 dnl The admin/ directory used to be excluded from tarfiles.
7834 if test -d $srcdir/admin; then
7835   SUBDIR_MAKEFILES="$SUBDIR_MAKEFILES admin/charsets/Makefile admin/unidata/Makefile admin/grammars/Makefile"
7836   ARCH_INDEPENDENT_CONFIG_FILES([admin/charsets/Makefile])
7837   ARCH_INDEPENDENT_CONFIG_FILES([admin/unidata/Makefile])
7838   ARCH_INDEPENDENT_CONFIG_FILES([admin/grammars/Makefile])
7839 fi                              dnl -d admin
7842 SUBDIR_MAKEFILES_IN=`echo " ${SUBDIR_MAKEFILES}" | sed -e 's| | $(srcdir)/|g' -e 's|Makefile|Makefile.in|g'`
7844 AC_SUBST([SUBDIR_MAKEFILES_IN])
7846 SMALL_JA_DIC=$with_small_ja_dic
7847 AC_SUBST([SMALL_JA_DIC])
7849 dnl The following commands are run on the build system when building
7850 dnl Emacs.
7852 if test "$XCONFIGURE" != "android"; then
7853   dnl You might wonder (I did) why epaths.h is generated by running
7854   dnl make, rather than just letting configure generate it from
7855   dnl epaths.in.  One reason is that the various paths are not fully
7856   dnl expanded (see above); e.g.,
7857   dnl gamedir='${localstatedir}/games/emacs'.  Secondly, the GNU
7858   dnl Coding standards require that one should be able to run 'make
7859   dnl prefix=/some/where/else' and override the values set by
7860   dnl configure.  This also explains the 'move-if-change' test and the
7861   dnl use of force in the 'epaths-force' rule in Makefile.in.
7862   AC_CONFIG_COMMANDS([src/epaths.h], [
7863   if test "${opsys}" = "mingw32"; then
7864     ${MAKE-make} MAKEFILE_NAME=do-not-make-Makefile epaths-force-w32
7865   elif test "$HAVE_NS" = "yes" && test "$EN_NS_SELF_CONTAINED" = "yes"; then
7866     ${MAKE-make} MAKEFILE_NAME=do-not-make-Makefile epaths-force-ns-self-contained
7867   else
7868     ${MAKE-make} MAKEFILE_NAME=do-not-make-Makefile epaths-force
7869   fi || AC_MSG_ERROR(['src/epaths.h' could not be made.])
7870   ], [GCC="$GCC" CPPFLAGS="$CPPFLAGS" opsys="$opsys" HAVE_NS="$HAVE_NS"
7871       EN_NS_SELF_CONTAINED="$EN_NS_SELF_CONTAINED"])
7873   dnl NB we have to cheat and use the ac_... version because abs_top_srcdir
7874   dnl is not yet set, sigh.  Or we could use ../$srcdir/src/.gdbinit,
7875   dnl or a symlink?
7876   AC_CONFIG_COMMANDS([src/.gdbinit], [
7877   if test ! -f src/.gdbinit && test -f "$srcdir/src/.gdbinit"; then
7878     AS_ECHO(["source $ac_abs_top_srcdir/src/.gdbinit"]) > src/.gdbinit
7879   fi
7880   ])
7882   dnl Perhaps this would be better named doc-emacs-emacsver.texi?
7883   dnl See comments for etc-refcards-emacsver.tex.
7884   dnl Since we get a doc/emacs directory generated anyway, for the Makefile,
7885   dnl it is not quite the same.  But we are generating in $srcdir.
7886   AC_CONFIG_COMMANDS([doc/emacs/emacsver.texi], [
7887   ${MAKE-make} -s --no-print-directory -C doc/emacs doc-emacsver || \
7888   AC_MSG_ERROR(['doc/emacs/emacsver.texi' could not be made.])
7889   ])
7891   dnl If we give this the more natural name, etc/refcards/emacsver.texi,
7892   dnl then a directory etc/refcards is created in the build directory,
7893   dnl which is probably harmless, but confusing (in out-of-tree builds).
7894   dnl (If we were to generate etc/refcards/Makefile, this might change.)
7895   dnl It is really $srcdir/etc/refcards/emacsver.tex that we generate.
7896   AC_CONFIG_COMMANDS([etc-refcards-emacsver.tex], [
7897   ${MAKE-make} -s MAKEFILE_NAME=do-not-make-Makefile etc-emacsver || \
7898   AC_MSG_ERROR(['etc/refcards/emacsver.tex' could not be made.])
7899   ])
7901   if test $AUTO_DEPEND = yes; then
7902      for dir in $AUTODEPEND_PARENTS; do
7903        AS_MKDIR_P([$dir/deps])
7904        AS_MKDIR_P([cross/$dir/deps])
7905      done
7906   fi
7907   if $gl_gnulib_enabled_dynarray || $gl_gnulib_enabled_scratch_buffer; then
7908     AS_MKDIR_P([lib/malloc])
7909     AS_MKDIR_P([cross/lib/malloc])
7910     if test $AUTO_DEPEND = yes; then
7911       AS_MKDIR_P([lib/deps/malloc])
7912       AS_MKDIR_P([cross/lib/deps/malloc])
7913     fi
7914   fi
7916   dnl Make cross/lib, which various Makefiles in cross expect to
7917   dnl always exist.
7918   AS_MKDIR_P([cross/lib])
7919   AS_MKDIR_P([cross/lib/malloc])
7920   AS_MKDIR_P([cross/lib/sys])
7921   AS_MKDIR_P([cross/lib-src])
7923   dnl Make cross/etc; this directory will hold the documentation file
7924   dnl holding doc strings for Android specific C files that aren't
7925   dnl built during the initial compilation of Emacs for the build
7926   dnl machine.
7927   AS_MKDIR_P([cross/etc])
7929   AS_IF([test "x$with_android" != "xno"], [
7930     dnl Link gnulib files to cross/lib as well.  af_alg.h and
7931     dnl lib/save-cwd.h are copied manually from gnulib, and as such
7932     dnl aren't specified in gl_FILE_LIST.
7933     emacs_files='gl_FILE_LIST lib/af_alg.h lib/save-cwd.h'
7934     dnl These files are specific to Emacs.
7935     emacs_files="$emacs_files lib/fingerprint.c lib/fingerprint.h \
7936                    lib/save-cwd.c lib/openat-die.c lib/save-cwd.c \
7937                    lib/min-max.h"
7938     for file in $emacs_files; do
7939       AS_IF([expr "X${file}J" : "Xlib/.*[[ch]]J" >/dev/null],
7940         [AS_IF([test -f "$srcdir/$file"],
7941           [AC_CONFIG_LINKS([cross/$file:$file])])])
7942     done])
7945 # Make java/Makefile
7946 ARCH_INDEPENDENT_CONFIG_FILES([java/Makefile])
7947 ARCH_INDEPENDENT_CONFIG_FILES([cross/Makefile])
7949 # Make java/AndroidManifest.xml
7950 ARCH_INDEPENDENT_CONFIG_FILES([java/AndroidManifest.xml])
7952 # Make ndk-build Makefiles.  This is only done inside the recursive
7953 # configure.
7954 ndk_CONFIG_FILES
7956 AC_OUTPUT
7958 if test ! "$with_mailutils"; then
7959   if test "$with_pop" = yes; then
7960     AC_MSG_WARN([This configuration installs a 'movemail' program
7961 that retrieves POP3 email via only insecure channels.
7962 To omit insecure POP3, you can use '$0 --without-pop'.])
7963   elif test "$with_pop" = no-by-default; then
7964     AC_MSG_WARN([This configuration installs a 'movemail' program
7965 that does not retrieve POP3 email.  By default, Emacs 25 and earlier
7966 installed a 'movemail' program that retrieved POP3 email via only
7967 insecure channels, a practice that is no longer recommended but that
7968 you can continue to support by using '$0 --with-pop'.])
7969   fi
7971   case $opsys in
7972     mingw32)
7973       # Don't suggest GNU Mailutils, as it hasn't been ported.
7974       ;;
7975     *)
7976       emacs_fix_movemail="use '$0 --with-mailutils'"
7977       case `(movemail --version) 2>/dev/null` in
7978         *Mailutils*) ;;
7979         *) emacs_fix_movemail="install GNU Mailutils
7980 <https://mailutils.org> and $emacs_fix_movemail";;
7981       esac
7982       AC_MSG_NOTICE([You might want to $emacs_fix_movemail.]);;
7983   esac
7986 if test "${HAVE_XFT}" = yes; then
7987   AC_MSG_WARN([This configuration uses libXft, which has a number of
7988     font rendering issues, and is being considered for removal in the
7989     next release of Emacs.  Please consider using Cairo graphics +
7990     HarfBuzz text shaping instead (they are auto-detected if the
7991     relevant development headers are installed).])
7994 if test "${HAVE_CAIRO}" = "yes" && test "${HAVE_HARFBUZZ}" = no; then
7995   AC_MSG_WARN([This configuration uses the Cairo graphics library,
7996     but not the HarfBuzz font shaping library (minimum version $harfbuzz_required_ver).
7997     We recommend the use of HarfBuzz when using Cairo, please install
7998     appropriate HarfBuzz development packages.])
8001 # Let plain 'make' work.
8002 test "$MAKE" = make || test -f makefile || cat >makefile <<EOF
8003 .POSIX:
8004 MAKE = $MAKE
8005 all:
8006         \$(MAKE) -f Makefile \$?
8007 .DEFAULT:
8008         \$(MAKE) -f Makefile \$<