1dnl  Autoconf script for GNU Emacs
2dnl To rebuild the 'configure' script from this, execute the command
3dnl	autoconf
4dnl in the directory containing this script.
5dnl If you changed any AC_DEFINES, also run autoheader.
6dnl
7dnl Copyright (C) 1994-1996, 1999-2021 Free Software Foundation, Inc.
8dnl
9dnl  This file is part of GNU Emacs.
10dnl
11dnl  GNU Emacs is free software: you can redistribute it and/or modify
12dnl  it under the terms of the GNU General Public License as published by
13dnl  the Free Software Foundation, either version 3 of the License, or
14dnl  (at your option) any later version.
15dnl
16dnl  GNU Emacs is distributed in the hope that it will be useful,
17dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
18dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19dnl  GNU General Public License for more details.
20dnl
21dnl  You should have received a copy of the GNU General Public License
22dnl  along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
23
24AC_PREREQ(2.65)
25dnl Note this is parsed by (at least) make-dist and lisp/cedet/ede/emacs.el.
26AC_INIT(GNU Emacs, 29.0.50, bug-gnu-emacs@gnu.org, , https://www.gnu.org/software/emacs/)
27
28dnl Set emacs_config_options to the options of 'configure', quoted for the shell,
29dnl and then quoted again for a C string.  Separate options with spaces.
30dnl Add some environment variables, if they were passed via the environment
31dnl rather than on the command-line.
32emacs_config_options=
33optsep=
34dnl This is the documented way to record the args passed to configure,
35dnl rather than $ac_configure_args.
36for opt in "$@" CFLAGS CPPFLAGS LDFLAGS; do
37  case $opt in
38    -n | --no-create | --no-recursion)
39      continue ;;
40    CFLAGS | CPPFLAGS | LDFLAGS)
41      eval 'test "${'$opt'+set}" = set' || continue
42      case " $*" in
43	*" $opt="*) continue ;;
44      esac
45      eval opt=$opt=\$$opt ;;
46  esac
47
48  emacs_shell_specials=$IFS\''"#$&()*;<>?@<:@\\`{|~'
49  case $opt in
50    *[["$emacs_shell_specials"]]*)
51      case $opt in
52	*\'*)
53	  emacs_quote_apostrophes="s/'/'\\\\''/g"
54	  opt=`AS_ECHO(["$opt"]) | sed "$emacs_quote_apostrophes"` ;;
55      esac
56      opt="'$opt'"
57      case $opt in
58	*[['"\\']]*)
59	  emacs_quote_for_c='s/[["\\]]/\\&/g; $!s/$/\\n\\/'
60	  opt=`AS_ECHO(["$opt"]) | sed "$emacs_quote_for_c"` ;;
61      esac ;;
62  esac
63  AS_VAR_APPEND([emacs_config_options], ["$optsep$opt"])
64  optsep=' '
65done
66
67AC_CONFIG_HEADERS(src/config.h:src/config.in)
68AC_CONFIG_SRCDIR(src/lisp.h)
69AC_CONFIG_AUX_DIR(build-aux)
70AC_CONFIG_MACRO_DIR(m4)
71
72xcsdkdir=
73AC_CHECK_PROGS(XCRUN, [xcrun])
74if test -n "$XCRUN"; then
75  if test -z "$MAKE"; then
76    dnl Call the variable MAKE_PROG, not MAKE, to avoid confusion with
77    dnl the usual MAKE variable that 'make' itself uses.
78    AC_CHECK_PROG([MAKE_PROG], [make], [yes])
79    if test -z "$MAKE_PROG"; then
80      MAKE="$XCRUN MAKE"
81      export MAKE
82      xcsdkdir=`$XCRUN --show-sdk-path 2>/dev/null`
83    fi
84  fi
85fi
86
87dnl Check for GNU Make and possibly set MAKE.
88[emacs_check_gnu_make ()
89{
90  emacs_makeout=`($1 --version) 2>/dev/null` &&
91  case $emacs_makeout in
92    'GNU Make '3.8[1-9]* | 'GNU Make '3.9[0-9]* | \
93    'GNU Make '3.[1-9][0-9][0-9]* | 'GNU Make '[4-9]* | 'GNU Make '[1-9][0-9]* )
94       ac_path_MAKE_found=:;;
95  esac
96}]
97AC_CACHE_CHECK([for GNU Make], [ac_cv_path_MAKE],
98  [ac_path_MAKE_found=false
99   if test -n "$MAKE"; then
100     emacs_check_gnu_make "$MAKE"
101     ac_cv_path_MAKE=$MAKE
102   else
103     emacs_tried_make=false
104     emacs_tried_gmake=false
105     emacs_tried_gnumake=false
106     AC_PATH_PROGS_FEATURE_CHECK([MAKE], [make gmake gnumake],
107       [[emacs_check_gnu_make "$ac_path_MAKE"
108	 if $ac_path_MAKE_found; then
109	   # Use the fully-qualified program name only if the basename
110	   # would not resolve to it.
111	   if eval \$emacs_tried_$ac_prog; then
112	     ac_cv_path_MAKE=$ac_path_MAKE
113	   else
114	     ac_cv_path_MAKE=$ac_prog
115	   fi
116	 fi
117	 eval emacs_tried_$ac_prog=:]])
118   fi])
119$ac_path_MAKE_found || {
120AC_MSG_ERROR([[Building Emacs requires GNU Make, at least version 3.81.
121If you have it installed under another name, configure with 'MAKE=...'.
122For example, run '$0 MAKE=gnu-make'.]])
123}
124MAKE=$ac_cv_path_MAKE
125export MAKE
126
127dnl Canonicalize the configuration name.
128AC_CANONICAL_HOST
129
130case $host in
131 *-mingw*)
132
133  if test -z "$host_alias"; then
134
135      # No --host argument was given to 'configure'; therefore $host
136      # was set to a default value based on the build platform.  But
137      # this default value may be wrong if we are building from a
138      # 64-bit MSYS[2] pre-configured to build 32-bit MinGW programs.
139      # Therefore, we'll try to get the right host platform from the
140      # compiler's target.
141
142      AC_MSG_CHECKING([the compiler's target])
143      if test -z "$CC"; then
144	  cc=gcc
145      else
146	  cc=$CC
147      fi
148      cc_target=`$cc -v 2>&1 | sed -n 's/Target: //p'`
149      case "$cc_target" in
150          *-*) host=$cc_target
151	      ;;
152          "") AC_MSG_ERROR([Impossible to obtain $cc compiler target.
153Please explicitly provide --host.])
154              ;;
155	  *) AC_MSG_WARN([Compiler reported non-standard target.
156Defaulting to $host.])
157              ;;
158      esac
159      AC_MSG_RESULT([$host])
160  fi
161
162  . $srcdir/nt/mingw-cfg.site
163
164  case $srcdir in
165    /* | ?:*)
166      # srcdir is an absolute path.  In this case, force the format
167      # "/c/foo/bar", to simplify later conversions to native Windows
168      # format ("c:/foo/bar").
169      srcdir=`cd "${srcdir}" && pwd -W`
170      # 'eval' pacifies strict POSIX non-MinGW shells (Bug#18612).
171      # We downcase the drive letter to avoid warnings when
172      # generating autoloads.
173      eval 'srcdir=/`echo ${srcdir:0:1} | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"`"${srcdir:2}"'
174      ;;
175  esac;;
176esac
177
178canonical=$host
179configuration=${host_alias-${build_alias-$host}}
180emacs_uname_r=`uname -r`
181
182dnl Support for --program-prefix, --program-suffix and
183dnl --program-transform-name options
184AC_ARG_PROGRAM
185
186dnl It is important that variables on the RHS not be expanded here,
187dnl hence the single quotes.  This is per the GNU coding standards, see
188dnl (autoconf) Installation Directory Variables
189dnl See also epaths.h below.
190lispdirrel='${version}/lisp'
191lispdir='${datadir}/emacs/'${lispdirrel}
192standardlisppath='${lispdir}'
193locallisppath='${datadir}/emacs/${version}/site-lisp:'\
194'${datadir}/emacs/site-lisp'
195lisppath='${locallisppath}:${standardlisppath}'
196etcdir='${datadir}/emacs/${version}/etc'
197archlibdir='${libexecdir}/emacs/${version}/${configuration}'
198etcdocdir='${datadir}/emacs/${version}/etc'
199gamedir='${localstatedir}/games/emacs'
200
201dnl Special option to disable the most of other options.
202AC_ARG_WITH(all,
203[AS_HELP_STRING([--without-all],
204		[omit almost all features and build
205		small executable with minimal dependencies])],
206  [with_features=$withval],
207  [with_features=yes])
208
209dnl OPTION_DEFAULT_OFF(NAME, HELP-STRING)
210dnl Create a new --with option that defaults to being disabled.
211dnl NAME is the base name of the option.  The shell variable with_NAME
212dnl   will be set to either the user's value (if the option is
213dnl   specified; 'yes' for a plain --with-NAME) or to 'no' (if the
214dnl   option is not specified).  Note that the shell variable name is
215dnl   constructed as autoconf does, by replacing non-alphanumeric
216dnl   characters with "_".
217dnl HELP-STRING is the help text for the option.
218AC_DEFUN([OPTION_DEFAULT_OFF], [dnl
219  AC_ARG_WITH([$1],[AS_HELP_STRING([--with-$1],[$2])],[],[dnl
220    m4_bpatsubst([with_$1], [[^0-9a-z]], [_])=no])dnl
221])dnl
222
223dnl OPTION_DEFAULT_IFAVAILABLE(NAME, HELP-STRING)
224dnl Create a new --with option that defaults to 'ifavailable'.
225dnl NAME is the base name of the option.  The shell variable with_NAME
226dnl   will be set to either the user's value (if the option is
227dnl   specified; 'yes' for a plain --with-NAME) or to 'ifavailable' (if the
228dnl   option is not specified).  Note that the shell variable name is
229dnl   constructed as autoconf does, by replacing non-alphanumeric
230dnl   characters with "_".
231dnl HELP-STRING is the help text for the option.
232AC_DEFUN([OPTION_DEFAULT_IFAVAILABLE], [dnl
233  AC_ARG_WITH([$1],[AS_HELP_STRING([--with-$1],[$2])],[],[dnl
234    m4_bpatsubst([with_$1], [[^0-9a-z]], [_])=ifavailable])dnl
235])dnl
236
237
238dnl OPTION_DEFAULT_ON(NAME, HELP-STRING)
239dnl Create a new --with option that defaults to $with_features.
240dnl NAME is the base name of the option.  The shell variable with_NAME
241dnl   will be set either to 'no' (for a plain --without-NAME) or to
242dnl   'yes' (if the option is not specified).  Note that the shell
243dnl   variable name is constructed as autoconf does, by replacing
244dnl   non-alphanumeric characters with "_".
245dnl HELP-STRING is the help text for the option.
246AC_DEFUN([OPTION_DEFAULT_ON], [dnl
247  AC_ARG_WITH([$1],[AS_HELP_STRING([--without-$1],[$2])],[],[dnl
248   m4_bpatsubst([with_$1], [[^0-9a-z]], [_])=$with_features])dnl
249])dnl
250
251# For retrieving mail, unencrypted network connections are the default
252# only on native MS-Windows platforms.  (FIXME: These platforms should
253# also be secure by default.)
254
255AC_ARG_WITH([mailutils],
256  [AS_HELP_STRING([--with-mailutils],
257     [rely on GNU Mailutils, so that the --without-pop through --with-mailhost
258      options are irrelevant; this is the default if GNU Mailutils is
259      installed])],
260  [],
261  [with_mailutils=$with_features
262   if test "$with_mailutils" = yes; then
263     (movemail --version) >/dev/null 2>&1 || with_mailutils=no
264   fi])
265if test "$with_mailutils" = no; then
266  with_mailutils=
267fi
268AC_SUBST([with_mailutils])
269
270AC_ARG_WITH([pop],
271  [AS_HELP_STRING([--with-pop],
272     [Support POP mail retrieval if Emacs movemail is used (not recommended,
273      as Emacs movemail POP is insecure).  This is the default only on
274      native MS-Windows.])],
275  [],
276  [case $host in
277     *-mingw*) with_pop=yes;;
278     *) with_pop=no-by-default;;
279   esac])
280if test "$with_pop" = yes; then
281   AC_DEFINE(MAIL_USE_POP)
282fi
283AH_TEMPLATE(MAIL_USE_POP, [Define to support POP mail retrieval.])dnl
284
285OPTION_DEFAULT_OFF([kerberos],[support Kerberos-authenticated POP])
286if test "$with_kerberos" != no; then
287   AC_DEFINE(KERBEROS)
288fi
289AH_TEMPLATE(KERBEROS,
290	    [Define to support Kerberos-authenticated POP mail retrieval.])dnl
291
292OPTION_DEFAULT_OFF([kerberos5],[support Kerberos version 5 authenticated POP])
293if test "${with_kerberos5}" != no; then
294  if test "${with_kerberos}" = no; then
295    with_kerberos=yes
296    AC_DEFINE(KERBEROS)
297  fi
298  AC_DEFINE(KERBEROS5, 1, [Define to use Kerberos 5 instead of Kerberos 4.])
299fi
300
301OPTION_DEFAULT_OFF([hesiod],[support Hesiod to get the POP server host])
302dnl FIXME hesiod support may not be present, so it seems like an error
303dnl to define, or at least use, this unconditionally.
304if test "$with_hesiod" != no; then
305  AC_DEFINE(HESIOD, 1, [Define to support using a Hesiod database to find the POP server.])
306fi
307
308OPTION_DEFAULT_OFF([mail-unlink],[unlink, rather than empty, mail spool after reading])
309if test "$with_mail_unlink" != no; then
310   AC_DEFINE(MAIL_UNLINK_SPOOL, 1, [Define to unlink, rather than empty, mail spool after reading.])
311fi
312
313AC_ARG_WITH([mailhost],[AS_HELP_STRING([--with-mailhost=HOSTNAME],
314    [string giving default POP mail host])],
315    AC_DEFINE_UNQUOTED(MAILHOST, ["$withval"], [String giving fallback POP mail host.]))
316
317AC_ARG_WITH([sound],[AS_HELP_STRING([--with-sound=VALUE],
318  [compile with sound support (VALUE one of: yes, alsa, oss, bsd-ossaudio, no;
319default yes).  Only for GNU/Linux, FreeBSD, NetBSD, MinGW, Cygwin.])],
320  [ case "${withval}" in
321      yes|no|alsa|oss|bsd-ossaudio) val=$withval ;;
322      *) AC_MSG_ERROR(['--with-sound=$withval' is invalid;
323this option's value should be 'yes', 'no', 'alsa', 'oss', or 'bsd-ossaudio'.])
324      ;;
325    esac
326    with_sound=$val
327  ],
328  [with_sound=$with_features])
329
330AC_ARG_WITH([pdumper],
331  AS_HELP_STRING(
332    [--with-pdumper=VALUE],
333    [enable pdumper support unconditionally
334      ('yes', 'no', or 'auto': default 'auto')]),
335    [ case "${withval}" in
336        yes|no|auto) val=$withval ;;
337        *) AC_MSG_ERROR(
338           ['--with-pdumper=$withval' is invalid;
339this option's value should be 'yes' or 'no'.]) ;;
340      esac
341      with_pdumper=$val
342    ],
343    [with_pdumper=auto])
344
345AC_ARG_WITH([unexec],
346  AS_HELP_STRING(
347    [--with-unexec=VALUE],
348    [enable unexec support unconditionally
349      ('yes', 'no', or 'auto': default 'auto')]),
350    [ case "${withval}" in
351        yes|no|auto) val=$withval ;;
352        *) AC_MSG_ERROR(
353           ['--with-unexec=$withval' is invalid;
354this option's value should be 'yes' or 'no'.]) ;;
355      esac
356      with_unexec=$val
357    ],
358    [with_unexec=auto])
359
360AC_ARG_WITH([dumping],[AS_HELP_STRING([--with-dumping=VALUE],
361    [kind of dumping to use for initial Emacs build
362(VALUE one of: pdumper, unexec, none; default pdumper)])],
363    [ case "${withval}" in
364        pdumper|unexec|none) val=$withval ;;
365        *) AC_MSG_ERROR(['--with-dumping=$withval is invalid;
366this option's value should be 'pdumper', 'unexec', or 'none'.])
367        ;;
368      esac
369      with_dumping=$val
370    ],
371    [with_dumping=pdumper])
372
373if test "$with_pdumper" = "auto"; then
374  if test "$with_dumping" = "pdumper"; then
375    with_pdumper=yes
376  else
377    with_pdumper=no
378  fi
379fi
380
381if test "$with_unexec" = "auto"; then
382  if test "$with_dumping" = "unexec"; then
383    with_unexec=yes
384  else
385    with_unexec=no
386  fi
387fi
388
389if test "$with_dumping" = "pdumper" && test "$with_pdumper" = "no"; then
390  AC_MSG_ERROR(['--with-dumping=pdumper' requires pdumper support])
391fi
392
393if test "$with_dumping" = "unexec" && test "$with_unexec" = "no"; then
394  AC_MSG_ERROR(['--with-dumping=unexec' requires unexec support])
395fi
396
397if test "$with_pdumper" = "yes"; then
398  AC_DEFINE([HAVE_PDUMPER], 1, [Define to build with portable dumper support])
399  HAVE_PDUMPER=yes
400else
401  HAVE_PDUMPER=no
402fi
403AC_SUBST([HAVE_PDUMPER])
404
405DUMPING=$with_dumping
406AC_SUBST(DUMPING)
407
408dnl FIXME currently it is not the last.
409dnl This should be the last --with option, because --with-x is
410dnl added later on when we find the file name of X, and it's best to
411dnl keep them together visually.
412AC_ARG_WITH([x-toolkit],[AS_HELP_STRING([--with-x-toolkit=KIT],
413 [use an X toolkit (KIT one of: yes or gtk, gtk2, gtk3, lucid or athena, motif, no)])],
414[	  case "${withval}" in
415	    y | ye | yes )	val=gtk ;;
416	    n | no )		val=no  ;;
417	    l | lu | luc | luci | lucid )	val=lucid ;;
418	    a | at | ath | athe | athen | athena )	val=athena ;;
419	    m | mo | mot | moti | motif )	val=motif ;;
420	    g | gt | gtk  )	val=gtk ;;
421	    gtk2  )	val=gtk2 ;;
422	    gtk3  )	val=gtk3 ;;
423	    * )
424AC_MSG_ERROR(['--with-x-toolkit=$withval' is invalid;
425this option's value should be 'yes', 'no', 'lucid', 'athena', 'motif', 'gtk',
426'gtk2' or 'gtk3'.  'yes' and 'gtk' are synonyms.
427'athena' and 'lucid' are synonyms.])
428	    ;;
429	  esac
430	  with_x_toolkit=$val
431])
432
433OPTION_DEFAULT_OFF([wide-int],
434  [prefer wide Emacs integers (typically 62-bit);
435   on 32-bit hosts, this allows buffer and string size up to 2GB,
436   at the cost of 10% to 30% slowdown of Lisp interpreter
437   and larger memory footprint])
438if test "$with_wide_int" = yes; then
439  AC_DEFINE([WIDE_EMACS_INT], 1, [Use long long for EMACS_INT if available.])
440fi
441
442dnl _ON results in a '--without' option in the --help output, so
443dnl the help text should refer to "don't compile", etc.
444with_xpm_set=${with_xpm+set}
445OPTION_DEFAULT_ON([xpm],[don't compile with XPM image support])
446OPTION_DEFAULT_ON([jpeg],[don't compile with JPEG image support])
447OPTION_DEFAULT_ON([tiff],[don't compile with TIFF image support])
448OPTION_DEFAULT_ON([gif],[don't compile with GIF image support])
449OPTION_DEFAULT_ON([png],[don't compile with PNG image support])
450OPTION_DEFAULT_ON([rsvg],[don't compile with SVG image support])
451OPTION_DEFAULT_ON([webp],[don't compile with WebP image support])
452OPTION_DEFAULT_ON([sqlite3],[don't compile with sqlite3 support])
453OPTION_DEFAULT_ON([lcms2],[don't compile with Little CMS support])
454OPTION_DEFAULT_ON([libsystemd],[don't compile with libsystemd support])
455OPTION_DEFAULT_ON([cairo],[don't compile with Cairo drawing])
456OPTION_DEFAULT_ON([xml2],[don't compile with XML parsing support])
457OPTION_DEFAULT_OFF([imagemagick],[compile with ImageMagick image support])
458OPTION_DEFAULT_ON([native-image-api], [don't use native image APIs (GDI+ on Windows)])
459OPTION_DEFAULT_IFAVAILABLE([json], [compile with native JSON support])
460
461OPTION_DEFAULT_ON([xft],[don't use XFT for anti aliased fonts])
462OPTION_DEFAULT_ON([harfbuzz],[don't use HarfBuzz for text shaping])
463OPTION_DEFAULT_ON([libotf],[don't use libotf for OpenType font support])
464OPTION_DEFAULT_ON([m17n-flt],[don't use m17n-flt for text shaping])
465
466OPTION_DEFAULT_ON([toolkit-scroll-bars],[don't use Motif/Xaw3d/GTK toolkit scroll bars])
467OPTION_DEFAULT_ON([xaw3d],[don't use Xaw3d])
468OPTION_DEFAULT_ON([xim],[at runtime, default X11 XIM to off])
469OPTION_DEFAULT_ON([xdbe],[don't use X11 double buffering support])
470AC_ARG_WITH([ns],[AS_HELP_STRING([--with-ns],
471[use Nextstep (macOS Cocoa or GNUstep) windowing system.
472On by default on macOS.])],[],[with_ns=maybe])
473OPTION_DEFAULT_OFF([w32], [use native MS Windows GUI in a Cygwin build])
474OPTION_DEFAULT_OFF([pgtk], [use pure GTK build without reliance on X libs (Wayland support) (requires cairo) - Experimental])
475
476OPTION_DEFAULT_ON([gpm],[don't use -lgpm for mouse support on a GNU/Linux console])
477OPTION_DEFAULT_ON([dbus],[don't compile with D-Bus support])
478AC_ARG_WITH([gconf],[AS_HELP_STRING([--with-gconf],
479[compile with Gconf support (Gsettings replaces this)])],[],
480[if test $with_features = yes; then
481with_gconf=maybe
482else
483with_gconf=no
484fi])
485OPTION_DEFAULT_ON([gsettings],[don't compile with GSettings support])
486OPTION_DEFAULT_ON([selinux],[don't compile with SELinux support])
487OPTION_DEFAULT_ON([gnutls],[don't use -lgnutls for SSL/TLS support])
488OPTION_DEFAULT_ON([zlib],[don't compile with zlib decompression support])
489OPTION_DEFAULT_ON([modules],[don't compile with dynamic modules support])
490OPTION_DEFAULT_ON([threads],[don't compile with elisp threading support])
491OPTION_DEFAULT_OFF([native-compilation],[compile with Emacs Lisp native compiler support])
492OPTION_DEFAULT_OFF([cygwin32-native-compilation],[use native compilation on 32-bit Cygwin])
493OPTION_DEFAULT_OFF([xinput2],[use version 2 of the X Input Extension for input])
494
495AC_ARG_WITH([file-notification],[AS_HELP_STRING([--with-file-notification=LIB],
496 [use a file notification library (LIB one of: yes, inotify, kqueue, gfile, w32, no)])],
497 [ case "${withval}" in
498    y | ye | yes )	val=yes ;;
499    n | no )		val=no  ;;
500    i | in | ino | inot | inoti | inotif | inotify )	val=inotify ;;
501    k | kq | kqu | kque | kqueu | kqueue )	val=kqueue ;;
502    g | gf | gfi | gfil | gfile )	val=gfile ;;
503    w | w3 | w32 )	val=w32 ;;
504    * ) AC_MSG_ERROR(['--with-file-notification=$withval' is invalid;
505this option's value should be 'yes', 'no', 'inotify', 'kqueue', 'gfile' or 'w32'.
506'yes' is a synonym for 'w32' on MS-Windows, for 'no' on Nextstep,
507otherwise for the first of 'inotify', 'kqueue' or 'gfile' that is usable.])
508    ;;
509   esac
510   with_file_notification=$val
511 ],
512 [with_file_notification=$with_features])
513
514OPTION_DEFAULT_OFF([xwidgets],
515  [enable use of xwidgets in Emacs buffers (requires gtk3 or macOS Cocoa)])
516
517OPTION_DEFAULT_OFF([be-app],
518  [enable use of Haiku's Application Kit as a window system])
519
520OPTION_DEFAULT_OFF([be-cairo],
521  [enable use of cairo under Haiku's Application Kit])
522
523## Makefile.in needs the cache file name.
524AC_SUBST(cache_file)
525
526## This is an option because I do not know if all info/man support
527## compressed files, nor how to test if they do so.
528OPTION_DEFAULT_ON([compress-install],
529  [don't compress some files (.el, .info, etc.) when installing.  Equivalent to:
530make GZIP_PROG= install])
531
532AC_ARG_WITH(gameuser,dnl
533[AS_HELP_STRING([--with-gameuser=USER_OR_GROUP],
534		[user for shared game score files.
535		An argument prefixed by ':' specifies a group instead.])])
536gameuser=
537gamegroup=
538case ${with_gameuser} in
539  '' | no) ;;
540  yes) gamegroup=games ;;
541  :*) gamegroup=${with_gameuser#:} ;;
542  *) gameuser=${with_gameuser} ;;
543esac
544
545AC_ARG_WITH([gnustep-conf],dnl
546[AS_HELP_STRING([--with-gnustep-conf=FILENAME],
547   [name of GNUstep configuration file to use on systems where the command
548    'gnustep-config' does not work; default $GNUSTEP_CONFIG_FILE, or
549    /etc/GNUstep/GNUstep.conf])])
550test "X${with_gnustep_conf}" != X && test "${with_gnustep_conf}" != yes && \
551  GNUSTEP_CONFIG_FILE="${with_gnustep_conf}"
552test "X$GNUSTEP_CONFIG_FILE" = "X" && \
553     GNUSTEP_CONFIG_FILE=/etc/GNUstep/GNUstep.conf
554
555AC_ARG_ENABLE(ns-self-contained,
556[AS_HELP_STRING([--disable-ns-self-contained],
557                [disable self contained build under NeXTstep])],
558   EN_NS_SELF_CONTAINED=$enableval,
559   EN_NS_SELF_CONTAINED=yes)
560
561locallisppathset=no
562AC_ARG_ENABLE(locallisppath,
563[AS_HELP_STRING([--enable-locallisppath=PATH],
564                [directories Emacs should search for lisp files specific
565		 to this site])],
566if test "${enableval}" = "no"; then
567  locallisppath=
568elif test "${enableval}" != "yes"; then
569  locallisppath=${enableval} locallisppathset=yes
570fi)
571
572AC_ARG_ENABLE(checking,
573[AS_HELP_STRING([--enable-checking@<:@=LIST@:>@],
574		[enable expensive checks.  With LIST,
575		 enable only specific categories of checks.
576		 Categories are: all,yes,no.
577		 Flags are: stringbytes, stringoverrun, stringfreelist,
578		 structs, glyphs])],
579[ac_checking_flags="${enableval}"],[])
580IFS="${IFS= 	}"; ac_save_IFS="$IFS"; IFS="$IFS,"
581CHECK_STRUCTS=false
582for check in $ac_checking_flags
583do
584	case $check in
585	# these set all the flags to specific states
586	yes)		ac_enable_checking=1 ;;
587	no)		ac_enable_checking= ;
588			CHECK_STRUCTS=false
589			ac_gc_check_stringbytes= ;
590	                ac_gc_check_string_overrun= ;
591	                ac_gc_check_string_free_list= ;
592			ac_glyphs_debug= ;;
593	all)		ac_enable_checking=1 ;
594			CHECK_STRUCTS=true
595			ac_gc_check_stringbytes=1 ;
596	                ac_gc_check_string_overrun=1 ;
597	                ac_gc_check_string_free_list=1 ;
598			ac_glyphs_debug=1 ;;
599	# these enable particular checks
600	stringbytes)	ac_gc_check_stringbytes=1 ;;
601	stringoverrun)	ac_gc_check_string_overrun=1 ;;
602	stringfreelist) ac_gc_check_string_free_list=1 ;;
603	structs)	CHECK_STRUCTS=true ;;
604	glyphs)		ac_glyphs_debug=1 ;;
605	*)	AC_MSG_ERROR(unknown check category $check) ;;
606	esac
607done
608IFS="$ac_save_IFS"
609
610if test x$ac_enable_checking != x ; then
611  AC_DEFINE(ENABLE_CHECKING, 1,
612[Define to 1 if expensive run-time data type and consistency checks are enabled.])
613fi
614if $CHECK_STRUCTS; then
615  AC_DEFINE([CHECK_STRUCTS], 1,
616    [Define this to check whether someone updated the portable dumper
617     code after changing the layout of a structure that it uses.
618     If you change one of these structures, check that the pdumper.c
619     code is still valid, and update the pertinent hash in pdumper.c
620     by manually copying the hash from the newly-generated dmpstruct.h.])
621fi
622AC_SUBST([CHECK_STRUCTS])
623if test x$ac_gc_check_stringbytes != x ; then
624  AC_DEFINE(GC_CHECK_STRING_BYTES, 1,
625[Define this temporarily to hunt a bug.  If defined, the size of
626   strings is redundantly recorded in sdata structures so that it can
627   be compared to the sizes recorded in Lisp strings.])
628fi
629if test x$ac_gc_check_string_overrun != x ; then
630  AC_DEFINE(GC_CHECK_STRING_OVERRUN, 1,
631[Define this to check for short string overrun.])
632fi
633if test x$ac_gc_check_string_free_list != x ; then
634  AC_DEFINE(GC_CHECK_STRING_FREE_LIST, 1,
635[Define this to check the string free list.])
636fi
637if test x$ac_glyphs_debug != x ; then
638  AC_DEFINE(GLYPH_DEBUG, 1,
639[Define this to enable glyphs debugging code.])
640fi
641
642dnl The name of this option is unfortunate.  It predates, and has no
643dnl relation to, the "sampling-based elisp profiler" added in 24.3.
644dnl Actually, it stops it working.
645dnl https://lists.gnu.org/r/emacs-devel/2012-11/msg00393.html
646AC_ARG_ENABLE(profiling,
647[AS_HELP_STRING([--enable-profiling],
648		[build emacs with low-level, gprof profiling support.
649                Mainly useful for debugging Emacs itself.  May not work on
650                all platforms.  Stops profiler.el working.])],
651[ac_enable_profiling="${enableval}"],[])
652if test x$ac_enable_profiling != x ; then
653   PROFILING_CFLAGS="-DPROFILING=1 -pg"
654else
655   PROFILING_CFLAGS=
656fi
657AC_SUBST(PROFILING_CFLAGS)
658
659AC_ARG_ENABLE(autodepend,
660[AS_HELP_STRING([--enable-autodepend],
661		[automatically generate dependencies to .h-files.
662		 Requires gcc, enabled if found.])],
663[ac_enable_autodepend="${enableval}"],[ac_enable_autodepend=yes])
664
665AC_ARG_ENABLE(gtk-deprecation-warnings,
666[AS_HELP_STRING([--enable-gtk-deprecation-warnings],
667		[Show Gtk+/Gdk deprecation warnings for Gtk+ >= 3.0])],
668[ac_enable_gtk_deprecation_warnings="${enableval}"],[])
669
670BUILD_DETAILS=
671AC_ARG_ENABLE([build-details],
672  [AS_HELP_STRING([--disable-build-details],
673		  [Make the build more deterministic by omitting host
674		   names, time stamps, etc. from the output.])],
675  [test "$enableval" = no && BUILD_DETAILS=--no-build-details])
676AC_SUBST([BUILD_DETAILS])
677
678dnl This used to use changequote, but, apart from 'changequote is evil'
679dnl per the autoconf manual, we can speed up autoconf somewhat by quoting
680dnl the great gob of text.  Thus it's not processed for possible expansion.
681dnl Just make sure the brackets remain balanced.
682dnl
683dnl Since Emacs can't find matching pairs of quotes, boundaries are
684dnl indicated by comments.
685dnl quotation begins
686[
687
688### If you add support for a new configuration, add code to this
689### switch statement to recognize your configuration name and select
690### the appropriate opsys.
691
692### As far as handling version numbers on operating systems is
693### concerned, make sure things will fail in a fixable way.  If
694### /etc/MACHINES doesn't say anything about version numbers, be
695### prepared to handle anything reasonably.  If version numbers
696### matter, be sure /etc/MACHINES says something about it.
697
698opsys='' unported=no
699case "${canonical}" in
700
701  ## GNU/Linux and similar ports
702  *-*-linux* )
703    opsys=gnu-linux
704  ;;
705
706  ## FreeBSD ports
707  *-*-freebsd* )
708    opsys=freebsd
709  ;;
710
711  ## DragonFly ports
712  *-*-dragonfly* )
713    opsys=dragonfly
714  ;;
715
716  ## FreeBSD kernel + glibc based userland
717  *-*-kfreebsd*gnu* )
718    opsys=gnu-kfreebsd
719  ;;
720
721  ## NetBSD ports
722  *-*-netbsd* )
723    opsys=netbsd
724  ;;
725
726  ## OpenBSD ports
727  *-*-openbsd* | *-*-mirbsd* )
728    opsys=openbsd
729  ;;
730
731  ## Apple Darwin / macOS
732  *-apple-darwin* )
733    case "${canonical}" in
734      *-apple-darwin[0-9].*) unported=yes ;;
735      i[3456]86-* | x86_64-* | arm-* | aarch64-* )  ;;
736      * )            unported=yes ;;
737    esac
738    opsys=darwin
739    ## FIXME: Find a way to use Fink if available (Bug#11507).
740  ;;
741
742  ## Chromium Native Client
743  *-nacl )
744    opsys=nacl
745  ;;
746
747  ## Cygwin ports
748  *-*-cygwin )
749    opsys=cygwin
750  ;;
751
752  ## HP 9000 series 700 and 800, running HP/UX
753  hppa*-hp-hpux10.2* )
754    opsys=hpux10-20
755  ;;
756  hppa*-hp-hpux1[1-9]* )
757    opsys=hpux11
758    CFLAGS="-D_INCLUDE__STDC_A1_SOURCE $CFLAGS"
759  ;;
760
761  ## IBM machines
762  rs6000-ibm-aix4.[23]* )
763    opsys=aix4-2
764  ;;
765  powerpc-ibm-aix4.[23]*  )
766    opsys=aix4-2
767  ;;
768  rs6000-ibm-aix[56]* )
769    opsys=aix4-2
770  ;;
771  powerpc-ibm-aix[5-9]* | powerpc-ibm-aix[1-9][0-9]* )
772    opsys=aix4-2
773  ;;
774
775  ## Solaris
776  *-*-solaris* | *-*-sunos*)
777    case "${canonical}" in
778      i[3456]86-*-* )   ;;
779      amd64-*-*|x86_64-*-*) ;;
780      sparc* )		;;
781      * )		unported=yes ;;
782    esac
783    opsys=solaris
784    ## Watch out for a compiler that we know will not work.
785    if [ "$CC" = /usr/ucb/cc ]; then
786      ## /usr/ucb/cc doesn't work;
787      ## we should find some other compiler that does work.
788      unset CC
789    fi
790  ;;
791
792  ## QNX Neutrino
793  *-nto-qnx* )
794    opsys=qnxnto
795    test -z "$CC" && CC=qcc
796    LDFLAGS="-N2M $LDFLAGS"
797  ;;
798
799  *-haiku )
800    opsys=haiku
801  ;;
802
803  ## Intel 386 machines where we don't care about the manufacturer.
804  i[3456]86-*-* )
805    case "${canonical}" in
806      *-darwin* )               opsys=darwin ;;
807      *-mingw* )
808		opsys=mingw32
809		# MinGW overrides and adds some system headers in nt/inc.
810		GCC_TEST_OPTIONS="-I $srcdir/nt/inc"
811		;;
812      *-sysv4.2uw* )		opsys=unixware ;;
813      *-sysv5uw* )		opsys=unixware ;;
814      *-sysv5OpenUNIX* )	opsys=unixware ;;
815      ## Otherwise, we'll fall through to the generic opsys code at the bottom.
816    esac
817  ;;
818
819  # MinGW64
820  x86_64-*-* )
821    case "${canonical}" in
822      *-mingw* )
823		opsys=mingw32
824		# MinGW overrides and adds some system headers in nt/inc.
825		GCC_TEST_OPTIONS="-I $srcdir/nt/inc"
826		;;
827      ## Otherwise, we'll fall through to the generic opsys code at the bottom.
828    esac
829  ;;
830
831  * )
832    unported=yes
833  ;;
834esac
835
836### If the code above didn't choose an operating system, just choose
837### an operating system based on the configuration name.  You really
838### only want to use this when you have no idea what the right
839### operating system is; if you know what operating systems a machine
840### runs, it's cleaner to make it explicit in the case statement
841### above.
842if test x"${opsys}" = x; then
843  case "${canonical}" in
844    *-gnu* )				opsys=gnu ;;
845    * )
846      unported=yes
847    ;;
848  esac
849fi
850
851]
852dnl quotation ends
853
854if test $unported = yes; then
855  AC_MSG_ERROR([Emacs does not support '${canonical}' systems.
856If you think it should, please send a report to ${PACKAGE_BUGREPORT}.
857Check 'etc/MACHINES' for recognized configuration names.])
858fi
859
860#### Choose a compiler.
861
862dnl Don't bother to test for C89.
863AC_DEFUN([_AC_PROG_CC_C89], [$2])
864
865dnl Sets GCC=yes if using gcc.
866AC_PROG_CC([gcc cc cl clang "$XCRUN gcc" "$XCRUN clang"])
867if test -n "$XCRUN"; then
868  AC_CHECK_PROGS(AR, [ar "$XCRUN ar"])
869  test -n "$AR" && export AR
870fi
871
872dnl Emacs needs C99 or later.
873gl_PROG_CC_C99
874
875AC_PROG_CC_C_O
876
877if test x$GCC = xyes; then
878  test "x$GCC_TEST_OPTIONS" != x && CC="$CC $GCC_TEST_OPTIONS"
879fi
880
881# Avoid gnulib's tests for -lcrypto, so that there's no static dependency on it.
882AC_DEFUN([gl_CRYPTO_CHECK])
883# Avoid gnulib's tests for HAVE_WORKING_O_NOATIME and HAVE_WORKING_O_NOFOLLOW,
884# as we don't use them.
885AC_DEFUN([gl_FCNTL_O_FLAGS])
886# Avoid gnulib's test for pthread_sigmask.
887funcs=
888for func in $ac_func_list; do
889  test $func = pthread_sigmask || AS_VAR_APPEND([funcs], [" $func"])
890done
891ac_func_list=$funcs
892# Emacs does not use the wchar or wctype-h modules.
893AC_DEFUN([gt_TYPE_WINT_T],
894  [GNULIBHEADERS_OVERRIDE_WINT_T=0
895   AC_SUBST([GNULIBHEADERS_OVERRIDE_WINT_T])])
896
897# Initialize gnulib right after choosing the compiler.
898dnl Amongst other things, this sets AR and ARFLAGS.
899gl_EARLY
900
901if test "$ac_test_CFLAGS" != set; then
902  # It's helpful to have C macros available to GDB, so prefer -g3 to -g
903  # if -g3 works and the user does not specify CFLAGS.
904  # This test must follow gl_EARLY; otherwise AC_LINK_IFELSE complains.
905  case $CFLAGS in
906    '-g')
907      emacs_g3_CFLAGS='-g3';;
908    '-g -O2')
909      emacs_g3_CFLAGS='-g3 -O2';;
910    *)
911      emacs_g3_CFLAGS='';;
912  esac
913  if test -n "$emacs_g3_CFLAGS"; then
914    emacs_save_CFLAGS=$CFLAGS
915    CFLAGS=$emacs_g3_CFLAGS
916    AC_CACHE_CHECK([whether $CC accepts $emacs_g3_CFLAGS],
917      [emacs_cv_prog_cc_g3],
918      [AC_LINK_IFELSE([AC_LANG_PROGRAM()],
919	 [emacs_cv_prog_cc_g3=yes],
920	 [emacs_cv_prog_cc_g3=no])])
921    if test $emacs_cv_prog_cc_g3 != yes; then
922      CFLAGS=$emacs_save_CFLAGS
923    fi
924    # Haiku also needs -gdwarf-2 because its GDB is too old
925    # to understand newer formats.
926    if test $opsys = mingw32 || test $opsys = haiku; then
927      CFLAGS="$CFLAGS -gdwarf-2"
928    fi
929  fi
930
931  case $CFLAGS in
932    *-O*) ;;
933    *)
934      # No optimization flag was inferred for this non-GCC compiler.
935      # Try -O.  This is needed for xlc on AIX; see Bug#14258.
936      emacs_save_CFLAGS=$CFLAGS
937      test -z "$CFLAGS" || CFLAGS="$CFLAGS "
938      CFLAGS=${CFLAGS}-O
939      AC_CACHE_CHECK([whether $CC accepts -O],
940        [emacs_cv_prog_cc_o],
941	[AC_LINK_IFELSE([AC_LANG_PROGRAM()],
942	   [emacs_cv_prog_cc_o=yes],
943	   [emacs_cv_prog_cc_o=no])])
944      if test $emacs_cv_prog_cc_o != yes; then
945	CFLAGS=$emacs_save_CFLAGS
946      fi ;;
947  esac
948fi
949
950# gl_GCC_VERSION_IFELSE([major], [minor], [run-if-found], [run-if-not-found])
951# ---------------------------------------------------------------------------
952# If $CPP is gcc-MAJOR.MINOR or newer, then run RUN-IF-FOUND.
953# Otherwise, run RUN-IF-NOT-FOUND.
954AC_DEFUN([gl_GCC_VERSION_IFELSE],
955  [AC_PREPROC_IFELSE(
956    [AC_LANG_PROGRAM(
957      [[
958#if ($1) < __GNUC__ || (($1) == __GNUC__ && ($2) <= __GNUC_MINOR__)
959/* ok */
960#else
961# error "your version of gcc is older than $1.$2"
962#endif
963      ]]),
964    ], [$3], [$4])
965  ]
966)
967
968AC_ARG_ENABLE([gcc-warnings],
969  [AS_HELP_STRING([--enable-gcc-warnings@<:@=TYPE@:>@],
970                  [control generation of GCC warnings.  The TYPE 'yes'
971		   means to fail if any warnings are issued; 'warn-only'
972		   means issue warnings without failing (default for
973		   developer builds); 'no' means disable warnings
974		   (default for non-developer builds).])],
975  [case $enableval in
976     yes|no|warn-only) ;;
977     *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
978   esac
979   gl_gcc_warnings=$enableval],
980  [# By default, use 'warn-only' if it looks like the invoker of 'configure'
981   # is a developer as opposed to a builder.  This is most likely true
982   # if GCC is recent enough and there is a .git directory or file;
983   # however, if there is also a .tarball-version file it is probably
984   # just a release imported into Git for patch management.
985   gl_gcc_warnings=no
986   if test -e "$srcdir"/.git && test ! -f "$srcdir"/.tarball-version; then
987     gl_GCC_VERSION_IFELSE([5], [3], [gl_gcc_warnings=warn-only])
988   fi])
989
990AC_ARG_ENABLE([check-lisp-object-type],
991  [AS_HELP_STRING([--enable-check-lisp-object-type],
992     [Enable compile time checks for the Lisp_Object data type,
993      which can catch some bugs during development.])])
994if test "$enable_check_lisp_object_type" = yes; then
995  AC_DEFINE([CHECK_LISP_OBJECT_TYPE], 1,
996    [Define to enable compile-time checks for the Lisp_Object data type.])
997fi
998
999# clang is unduly picky about some things.
1000AC_CACHE_CHECK([whether the compiler is clang], [emacs_cv_clang],
1001  [AC_COMPILE_IFELSE(
1002     [AC_LANG_PROGRAM([[
1003	  #ifndef __clang__
1004	    error "not clang";
1005	  #endif
1006        ]])],
1007     [emacs_cv_clang=yes],
1008     [emacs_cv_clang=no])])
1009
1010WERROR_CFLAGS=
1011# When compiling with GCC, prefer -isystem to -I when including system
1012# include files, to avoid generating useless diagnostics for the files.
1013AS_IF([test $gl_gcc_warnings = no],
1014 [
1015  isystem='-I'
1016  AS_IF([test "$emacs_cv_clang" = yes],
1017   [
1018     # Turn off some warnings if supported.
1019     gl_WARN_ADD([-Wno-switch])
1020     gl_WARN_ADD([-Wno-pointer-sign])
1021     gl_WARN_ADD([-Wno-string-plus-int])
1022     gl_WARN_ADD([-Wno-unknown-attributes])
1023   ])
1024 ],[
1025  isystem='-isystem '
1026
1027  # This, $nw, is the list of warnings we disable.
1028  nw=
1029
1030  case $with_x_toolkit in
1031    lucid | athena | motif)
1032       # Old toolkits mishandle 'const'.
1033       nw="$nw -Wwrite-strings"
1034       ;;
1035  esac
1036  AS_IF([test $gl_gcc_warnings = yes],
1037    [WERROR_CFLAGS=-Werror],
1038    [# Use -fanalyzer and related options only if --enable-gcc-warnings,
1039     # as they slow GCC considerably.
1040     nw="$nw -fanalyzer -Wno-analyzer-double-free -Wno-analyzer-malloc-leak"
1041     nw="$nw -Wno-analyzer-null-dereference -Wno-analyzer-use-after-free"
1042     # Use -Wsuggest-attribute=malloc only if --enable-gcc-warnings,
1043     # as it doesn't flag code that is wrong in any way.
1044     nw="$nw -Wsuggest-attribute=malloc"])
1045
1046  nw="$nw -Wcast-align=strict"      # Emacs is tricky with pointers.
1047  nw="$nw -Wduplicated-branches"    # Too many false alarms
1048  nw="$nw -Wformat-overflow=2"      # False alarms due to GCC bug 80776
1049  nw="$nw -Wsystem-headers"         # Don't let system headers trigger warnings
1050  nw="$nw -Woverlength-strings"     # Not a problem these days
1051  nw="$nw -Wvla"                    # Emacs uses <vla.h>.
1052  nw="$nw -Wunused-const-variable=2" # lisp.h declares const objects.
1053  nw="$nw -Winline"                 # OK to ignore 'inline'
1054  nw="$nw -Wstrict-overflow"        # OK to optimize assuming that
1055                                    # signed overflow has undefined behavior
1056  nw="$nw -Wsync-nand"              # irrelevant here, and provokes ObjC warning
1057  nw="$nw -Wunsafe-loop-optimizations" # OK to suppress unsafe optimizations
1058  nw="$nw -Wbad-function-cast"      # These casts are no worse than others.
1059
1060  # Emacs doesn't care about shadowing; see
1061  # <https://lists.gnu.org/r/emacs-diffs/2011-11/msg00265.html>.
1062  nw="$nw -Wshadow"
1063
1064  # Emacs's use of alloca inhibits protecting the stack.
1065  nw="$nw -Wstack-protector"
1066
1067  # Emacs's use of __attribute__ ((cold)) causes false alarms with this option.
1068  nw="$nw -Wsuggest-attribute=cold"
1069
1070  # Emacs's use of partly-const functions such as Fgnutls_available_p
1071  # make this option problematic.
1072  nw="$nw -Wsuggest-attribute=const"
1073
1074  # Emacs's use of partly-pure functions such as CHECK_TYPE make this
1075  # option problematic.
1076  nw="$nw -Wsuggest-attribute=pure"
1077
1078  if test "$emacs_cv_clang" = yes; then
1079    nw="$nw -Wdouble-promotion"
1080  fi
1081
1082  # This causes too much noise in the MinGW build.
1083  if test $opsys = mingw32; then
1084    nw="$nw -Wsuggest-attribute=format"
1085  fi
1086
1087  gl_MANYWARN_ALL_GCC([ws])
1088  gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
1089  for w in $ws; do
1090    gl_WARN_ADD([$w])
1091  done
1092  gl_WARN_ADD([-Wredundant-decls])     # Prefer this, as we don't use Bison.
1093  gl_WARN_ADD([-Wno-missing-field-initializers]) # We need this one
1094  gl_WARN_ADD([-Wno-override-init])    # More trouble than it is worth
1095  gl_WARN_ADD([-Wno-sign-compare])     # Too many warnings for now
1096  gl_WARN_ADD([-Wno-type-limits])      # Too many warnings for now
1097  gl_WARN_ADD([-Wno-unused-parameter]) # Too many warnings for now
1098  gl_WARN_ADD([-Wno-format-nonliteral])
1099
1100  # clang is unduly picky about some things.
1101  if test "$emacs_cv_clang" = yes; then
1102    gl_WARN_ADD([-Wno-missing-braces])
1103    gl_WARN_ADD([-Wno-null-pointer-arithmetic])
1104  fi
1105
1106  # This causes too much noise in the MinGW build
1107  if test $opsys = mingw32; then
1108    gl_WARN_ADD([-Wno-pointer-sign])
1109  fi
1110
1111  AC_DEFINE([GCC_LINT], [1], [Define to 1 if --enable-gcc-warnings.])
1112  AS_IF([test $gl_gcc_warnings = yes],
1113    [AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks])
1114     AH_VERBATIM([GNULIB_PORTCHECK_FORTIFY_SOURCE],
1115     [/* Enable compile-time and run-time bounds-checking, and some warnings,
1116	 without upsetting glibc 2.15+. */
1117      #if (defined GNULIB_PORTCHECK && !defined _FORTIFY_SOURCE \
1118	   && defined __OPTIMIZE__ && __OPTIMIZE__)
1119      # define _FORTIFY_SOURCE 2
1120      #endif
1121     ])])
1122 ])
1123
1124# clang is picky about these regardless of whether
1125# --enable-gcc-warnings is specified.
1126if test "$emacs_cv_clang" = yes; then
1127  gl_WARN_ADD([-Wno-initializer-overrides])
1128  gl_WARN_ADD([-Wno-tautological-compare])
1129  gl_WARN_ADD([-Wno-tautological-constant-out-of-range-compare])
1130fi
1131
1132# Use a slightly smaller set of warning options for lib/.
1133nw=
1134nw="$nw -Wunused-macros"
1135gl_MANYWARN_COMPLEMENT([GNULIB_WARN_CFLAGS], [$WARN_CFLAGS], [$nw])
1136
1137AC_SUBST([WERROR_CFLAGS])
1138AC_SUBST([GNULIB_WARN_CFLAGS])
1139
1140edit_cflags="
1141  s,///*,/,g
1142  s/^/ /
1143  s/ -I/ $isystem/g
1144  s/^ //
1145"
1146
1147AC_ARG_ENABLE(link-time-optimization,
1148[AS_HELP_STRING([--enable-link-time-optimization],
1149                [build with link-time optimization
1150		 (experimental; see INSTALL)])],
1151if test "${enableval}" != "no"; then
1152   ac_lto_supported=no
1153   if test "$emacs_cv_clang" = yes; then
1154      AC_MSG_CHECKING([whether link-time optimization is supported by clang])
1155      GOLD_PLUGIN=`$CC -print-file-name=LLVMgold.so 2>/dev/null`
1156      if test -x "$GOLD_PLUGIN"; then
1157	 LTO="-flto"
1158      fi
1159   elif test x$GCC = xyes; then
1160      AC_MSG_CHECKING([whether link-time optimization is supported by gcc])
1161      CPUS=`getconf _NPROCESSORS_ONLN 2>/dev/null`
1162      if test x$CPUS != x; then
1163	 LTO="-flto=$CPUS"
1164      else
1165	 LTO="-flto"
1166      fi
1167   else
1168      AC_MSG_ERROR([Link-time optimization is not supported with your compiler.])
1169   fi
1170   if test -z "$LTO"; then
1171      ac_lto_supported=no
1172   else
1173      old_CFLAGS=$CFLAGS
1174      CFLAGS="$CFLAGS $LTO"
1175      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1176         [ac_lto_supported=yes], [ac_lto_supported=no])
1177         CFLAGS="$old_CFLAGS"
1178   fi
1179   AC_MSG_RESULT([$ac_lto_supported])
1180   if test "$ac_lto_supported" = "yes"; then
1181      CFLAGS="$CFLAGS $LTO"
1182      if test "$emacs_cv_clang" = yes; then
1183	 AC_MSG_WARN([Please read INSTALL before using link-time optimization with clang])
1184	 # WARNING: 'ar --plugin ...' doesn't work without
1185	 # command, so plugin name is appended to ARFLAGS.
1186	 ARFLAGS="cru --plugin $GOLD_PLUGIN"
1187	 RANLIB="$RANLIB --plugin $GOLD_PLUGIN"
1188      else
1189        dnl The following is needed for GCC 4.9.0.  The GCC 4.9.0 release notes
1190        dnl suggest that instead of -ffat-lto-objects we should use gcc-ar and
1191        dnl gcc-ranlib in place of ar and ranlib, but gcc-ar makes /usr/bin/ar
1192        dnl dump core on Fedora 20, so play it safe for now.
1193        gl_COMPILER_OPTION_IF([-ffat-lto-objects],
1194          [CFLAGS="$CFLAGS -ffat-lto-objects"])
1195      fi
1196   fi
1197fi)
1198
1199
1200dnl Automake replacements.
1201AC_DEFUN([AM_CONDITIONAL],
1202  [$2 && $1_CONDITION=1 || $1_CONDITION=
1203   AC_SUBST([$1_CONDITION])])
1204
1205dnl Prefer silent make output.  For verbose output, use
1206dnl 'configure --disable-silent-rules' or 'make V=1' .
1207AC_ARG_ENABLE([silent-rules],
1208  [AS_HELP_STRING(
1209     [--disable-silent-rules],
1210     [verbose build output (undo: "make V=0")])])
1211if test "$enable_silent_rules" = no; then
1212  AM_DEFAULT_VERBOSITY=1
1213else
1214  AM_DEFAULT_VERBOSITY=0
1215fi
1216AC_SUBST([AM_DEFAULT_VERBOSITY])
1217AC_CONFIG_FILES([src/verbose.mk])
1218
1219dnl Some other nice autoconf tests.
1220AC_PROG_INSTALL
1221dnl These are commented out, since gl_EARLY and/or Autoconf already does them.
1222dnl AC_PROG_MKDIR_P
1223dnl if test "x$RANLIB" = x; then
1224dnl   AC_PROG_RANLIB
1225dnl fi
1226
1227
1228dnl Sadly, AC_PROG_LN_S is too restrictive.  It also tests whether links
1229dnl can be made to directories.  This is not relevant for our usage, and
1230dnl excludes some cases that work fine for us.  Eg MS Windows or files
1231dnl hosted on AFS, both examples where simple links work, but links to
1232dnl directories fail.  We use a cut-down version instead.
1233dnl AC_PROG_LN_S
1234
1235AC_CACHE_CHECK([command to symlink files in the same directory], [emacs_cv_ln_s_fileonly],
1236[rm -f conf$$ conf$$.file
1237
1238emacs_cv_ln_s_fileonly='cp -p'
1239
1240dnl On MinGW, ensure we will call the MSYS /bin/ln.exe, not some
1241dnl random program in the current directory.
1242if (echo >conf$$.file) 2>/dev/null; then
1243  if test "$opsys" = "mingw32"; then
1244    emacs_cv_ln_s_fileonly=/bin/ln
1245  elif ln -s conf$$.file conf$$ 2>/dev/null; then
1246    emacs_cv_ln_s_fileonly='ln -s'
1247  elif ln conf$$.file conf$$ 2>/dev/null; then
1248    emacs_cv_ln_s_fileonly=ln
1249  fi
1250fi
1251
1252rm -f conf$$ conf$$.file])
1253LN_S_FILEONLY=$emacs_cv_ln_s_fileonly
1254
1255AC_SUBST(LN_S_FILEONLY)
1256
1257
1258dnl AC_PROG_LN_S sets LN_S to 'cp -pR' for MinGW, on the premise that 'ln'
1259dnl doesn't support links to directories, as in "ln file dir".  But that
1260dnl use is non-portable, and OTOH MinGW wants to use hard links for Emacs
1261dnl executables at "make install" time.
1262dnl See https://lists.gnu.org/r/emacs-devel/2013-04/msg00475.html
1263dnl for more details.
1264if test "$opsys" = "mingw32"; then
1265  LN_S="/bin/ln"
1266fi
1267
1268dnl On some Debian versions, "install-info" prints irritating messages
1269dnl "This is not dpkg install-info anymore, but GNU install-info"
1270dnl if called via an absolute file name.
1271dnl Use the entirely-identical-but-quieter ginstall-info instead if present.
1272dnl Sadly some people may have an old ginstall-info installed on
1273dnl non-Debian systems, so we can't use this.
1274dnl AC_PATH_PROGS(INSTALL_INFO, [ginstall-info install-info], :,
1275dnl   $PATH$PATH_SEPARATOR/usr/sbin$PATH_SEPARATOR/sbin)
1276
1277AC_PATH_PROG(INSTALL_INFO, install-info, :,
1278  $PATH$PATH_SEPARATOR/usr/sbin$PATH_SEPARATOR/sbin)
1279dnl Don't use GZIP, which is used by gzip for additional parameters.
1280AC_PATH_PROG(GZIP_PROG, gzip)
1281
1282test $with_compress_install != yes && test -n "$GZIP_PROG" && \
1283   GZIP_PROG=" # $GZIP_PROG # (disabled by configure --without-compress-install)"
1284
1285if test "$with_dumping" = "unexec" && test "$opsys" = "nacl"; then
1286  AC_MSG_ERROR([nacl is not compatible with --with-dumping=unexec])
1287fi
1288
1289AC_CACHE_CHECK([for 'find' args to delete a file],
1290  [emacs_cv_find_delete],
1291  [if touch conftest.tmp && find conftest.tmp -delete 2>/dev/null &&
1292      test ! -f conftest.tmp
1293   then emacs_cv_find_delete="-delete"
1294   else emacs_cv_find_delete="-exec rm -f {} ';'"
1295   fi])
1296FIND_DELETE=$emacs_cv_find_delete
1297AC_SUBST([FIND_DELETE])
1298
1299PAXCTL_dumped=
1300PAXCTL_notdumped=
1301if test $with_unexec = yes && test $opsys = gnu-linux; then
1302  if test "${SETFATTR+set}" != set; then
1303    AC_CACHE_CHECK([for setfattr],
1304      [emacs_cv_prog_setfattr],
1305      [touch conftest.tmp
1306       if (setfattr -n user.pax.flags conftest.tmp) >/dev/null 2>&1; then
1307	 emacs_cv_prog_setfattr=yes
1308       else
1309	 emacs_cv_prog_setfattr=no
1310       fi])
1311    if test "$emacs_cv_prog_setfattr" = yes; then
1312      PAXCTL_notdumped='$(SETFATTR) -n user.pax.flags -v er'
1313      SETFATTR=setfattr
1314    else
1315      SETFATTR=
1316    fi
1317  fi
1318  case $opsys,$PAXCTL_notdumped,$emacs_uname_r in
1319    gnu-linux,,* | netbsd,,[0-7].*)
1320      AC_PATH_PROG([PAXCTL], [paxctl], [],
1321	[$PATH$PATH_SEPARATOR/sbin$PATH_SEPARATOR/usr/sbin])
1322      if test -n "$PAXCTL"; then
1323	if test "$opsys" = netbsd; then
1324	  PAXCTL_dumped='$(PAXCTL) +a'
1325	  PAXCTL_notdumped=$PAXCTL_dumped
1326	else
1327	  AC_MSG_CHECKING([whether binaries have a PT_PAX_FLAGS header])
1328	  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
1329	    [if $PAXCTL -v conftest$EXEEXT >/dev/null 2>&1; then
1330	       AC_MSG_RESULT([yes])
1331	     else
1332	       AC_MSG_RESULT([no])
1333	       PAXCTL=
1334	     fi])
1335	  if test -n "$PAXCTL"; then
1336	    PAXCTL_dumped='$(PAXCTL) -zex'
1337	    PAXCTL_notdumped='$(PAXCTL) -r'
1338	  fi
1339	fi
1340      fi;;
1341  esac
1342fi
1343AC_SUBST([PAXCTL_dumped])
1344AC_SUBST([PAXCTL_notdumped])
1345AC_SUBST([SETFATTR])
1346
1347# Makeinfo on macOS is ancient, check whether there is a more recent
1348# version installed by Homebrew.
1349AC_CHECK_PROGS(BREW, [brew])
1350if test -n "$BREW"; then
1351  AC_PATH_PROG([MAKEINFO], [makeinfo], [],
1352    [`$BREW --prefix texinfo 2>/dev/null`/bin$PATH_SEPARATOR$PATH])
1353fi
1354
1355# Check MacPorts on macOS.
1356if test $opsys = darwin; then
1357  AC_PATH_PROG(HAVE_MACPORTS, port)
1358fi
1359
1360## Require makeinfo >= 4.13 (last of the 4.x series) to build the manuals.
1361: ${MAKEINFO:=makeinfo}
1362case `($MAKEINFO --version) 2>/dev/null` in
1363  *' (GNU texinfo) '4.1[[3-9]]* | \
1364  *' (GNU texinfo) '[[5-9]]* | \
1365  *' (GNU texinfo) '[[1-9][0-9]]* ) ;;
1366  *) MAKEINFO=no;;
1367esac
1368
1369## Makeinfo is unusual.  For a released Emacs, the manuals are
1370## pre-built, and not deleted by the normal clean rules.  makeinfo is
1371## therefore in the category of "special tools" not normally required, which
1372## configure does not have to check for (eg autoconf itself).
1373## In a repository checkout on the other hand, the manuals are not included.
1374## So makeinfo is a requirement to build from the repository, and configure
1375## should test for it as it does for any other build requirement.
1376## We use the presence of $srcdir/info/emacs to distinguish a release,
1377## with pre-built manuals, from a repository checkout.
1378if test "$MAKEINFO" = "no"; then
1379  MAKEINFO=makeinfo
1380  if test ! -e "$srcdir/info/emacs" && test ! -e "$srcdir/info/emacs.info"; then
1381    AC_MSG_ERROR( [You do not seem to have makeinfo >= 4.13, and your
1382source tree does not seem to have pre-built manuals in the 'info' directory.
1383Please install a suitable version of makeinfo.] )
1384  else
1385    AC_MSG_WARN( [You do not seem to have makeinfo >= 4.13.
1386You will not be able to rebuild the manuals if you delete them or change
1387their sources.] )
1388  fi
1389fi
1390AC_SUBST([MAKEINFO])
1391
1392if test $opsys = mingw32; then
1393   DOCMISC_W32=efaq-w32
1394else
1395   DOCMISC_W32=
1396fi
1397AC_SUBST(DOCMISC_W32)
1398
1399dnl Add our options to ac_link now, after it is set up.
1400
1401if test x$GCC = xyes; then
1402  test "x$GCC_LINK_TEST_OPTIONS" != x && \
1403    ac_link="$ac_link $GCC_LINK_TEST_OPTIONS"
1404else
1405  test "x$NON_GCC_LINK_TEST_OPTIONS" != x && \
1406    ac_link="$ac_link $NON_GCC_LINK_TEST_OPTIONS"
1407fi
1408
1409dnl On some platforms using GNU ld, linking temacs needs -znocombreloc.
1410dnl Although this has something to do with dumping, the details are unknown.
1411dnl If the flag is used but not needed,
1412dnl Emacs should still work (albeit a bit more slowly),
1413dnl so use the flag everywhere that it is supported.
1414dnl When testing whether the flag works, treat GCC specially
1415dnl since it just gives a non-fatal 'unrecognized option'
1416dnl if not built to support GNU ld.
1417if test "$GCC" = yes; then
1418  LDFLAGS_NOCOMBRELOC="-Wl,-znocombreloc"
1419else
1420  LDFLAGS_NOCOMBRELOC="-znocombreloc"
1421fi
1422
1423AC_CACHE_CHECK([for -znocombreloc], [emacs_cv_znocombreloc],
1424  [if test $with_unexec = no; then
1425     emacs_cv_znocombreloc='not needed'
1426   else
1427     save_LDFLAGS=$LDFLAGS
1428     LDFLAGS="$LDFLAGS $LDFLAGS_NOCOMBRELOC"
1429     AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
1430       [emacs_cv_znocombreloc=yes], [emacs_cv_znocombreloc=no])
1431     LDFLAGS=$save_LDFLAGS
1432   fi])
1433
1434case $emacs_cv_znocombreloc in
1435  no*)
1436    LDFLAGS_NOCOMBRELOC= ;;
1437esac
1438
1439
1440AC_CACHE_CHECK([whether addresses are sanitized],
1441  [emacs_cv_sanitize_address],
1442  [AC_COMPILE_IFELSE(
1443     [AC_LANG_PROGRAM(
1444	[[#ifndef __has_feature
1445	  #define __has_feature(f) 0
1446	  #endif
1447	  #if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer)
1448	  #else
1449	   error "Addresses are not sanitized.";
1450	  #endif
1451	]])],
1452     [emacs_cv_sanitize_address=yes],
1453     [emacs_cv_sanitize_address=no])])
1454
1455if test $with_unexec = yes; then
1456  AC_DEFINE([HAVE_UNEXEC], 1, [Define if Emacs supports unexec.])
1457  if test "$emacs_cv_sanitize_address" = yes; then
1458    AC_MSG_WARN([[Addresses are sanitized; suggest --without-unexec]])
1459  fi
1460fi
1461
1462
1463UNEXEC_OBJ=
1464test $with_unexec = yes &&
1465case "$opsys" in
1466  # MSDOS uses unexcoff.o
1467  aix4-2)
1468   UNEXEC_OBJ=unexaix.o
1469   ;;
1470  cygwin)
1471   UNEXEC_OBJ=unexcw.o
1472   ;;
1473  darwin)
1474   UNEXEC_OBJ=unexmacosx.o
1475   ;;
1476  hpux10-20 | hpux11)
1477   UNEXEC_OBJ=unexhp9k800.o
1478   ;;
1479  mingw32)
1480   UNEXEC_OBJ=unexw32.o
1481   ;;
1482  solaris)
1483   # Use the Solaris dldump() function, called from unexsol.c, to dump
1484   # emacs, instead of the generic ELF dump code found in unexelf.c.
1485   # The resulting binary has a complete symbol table, and is better
1486   # for debugging and other observability tools (debuggers, pstack, etc).
1487   UNEXEC_OBJ=unexsol.o
1488   ;;
1489  *)
1490   UNEXEC_OBJ=unexelf.o
1491   ;;
1492esac
1493AC_SUBST(UNEXEC_OBJ)
1494
1495LD_SWITCH_SYSTEM=
1496test "$with_unexec" = no || case "$opsys" in
1497  freebsd|dragonfly)
1498   ## Let 'ld' find image libs and similar things in /usr/local/lib.
1499   ## The system compiler, GCC, has apparently been modified to not
1500   ## look there, contrary to what a stock GCC would do.
1501### It's not our place to do this.  See bug#10313#17.
1502###   LD_SWITCH_SYSTEM=-L/usr/local/lib
1503      :
1504   ;;
1505
1506  gnu-linux)
1507   ## cpp test was "ifdef __mips__", but presumably this is equivalent...
1508   case $host_cpu in mips*) LD_SWITCH_SYSTEM="-G 0";; esac
1509   ;;
1510
1511  netbsd)
1512### It's not our place to do this.  See bug#10313#17.
1513###   LD_SWITCH_SYSTEM="-Wl,-rpath,/usr/pkg/lib -L/usr/pkg/lib -Wl,-rpath,/usr/local/lib -L/usr/local/lib"
1514      :
1515   ;;
1516
1517  openbsd)
1518   ## Han Boetes <han@boetes.org> says this is necessary,
1519   ## otherwise Emacs dumps core on elf systems.
1520   LD_SWITCH_SYSTEM="-Z"
1521   ;;
1522esac
1523AC_SUBST(LD_SWITCH_SYSTEM)
1524
1525ac_link="$ac_link $LD_SWITCH_SYSTEM"
1526
1527## This setting of LD_SWITCH_SYSTEM references LD_SWITCH_X_SITE_RPATH,
1528## which has not been defined yet.  When this was handled with cpp,
1529## it was expanded to null when configure sourced the s/*.h file.
1530## Thus LD_SWITCH_SYSTEM had different values in configure and the Makefiles.
1531## FIXME it would be cleaner to put this in LD_SWITCH_SYSTEM_TEMACS
1532## (or somesuch), but because it is supposed to go at the _front_
1533## of LD_SWITCH_SYSTEM, we cannot do that in exactly the same way.
1534## Compare with the gnu-linux case below, which added to the end
1535## of LD_SWITCH_SYSTEM, and so can instead go at the front of
1536## LD_SWITCH_SYSTEM_TEMACS.
1537case "$opsys" in
1538  netbsd|openbsd)
1539   LD_SWITCH_SYSTEM="\$(LD_SWITCH_X_SITE_RPATH) $LD_SWITCH_SYSTEM" ;;
1540esac
1541
1542C_SWITCH_MACHINE=
1543
1544test $with_unexec = yes &&
1545case $canonical in
1546 alpha*)
1547    ## With ELF, make sure that all common symbols get allocated to in the
1548    ## data section.  Otherwise, the dump of temacs may miss variables in
1549    ## the shared library that have been initialized.  For example, with
1550    ## GNU libc, __malloc_initialized would normally be resolved to the
1551    ## shared library's .bss section, which is fatal.
1552    if test "x$GCC" = "xyes"; then
1553      C_SWITCH_MACHINE="-fno-common"
1554    else
1555      AC_MSG_ERROR([Non-GCC compilers are not supported.])
1556    fi
1557  ;;
1558esac
1559AC_SUBST(C_SWITCH_MACHINE)
1560
1561C_SWITCH_SYSTEM=
1562## Some programs in src produce warnings saying certain subprograms
1563## are too complex and need a MAXMEM value greater than 2000 for
1564## additional optimization.  --nils@exp-math.uni-essen.de
1565test "$opsys" = "aix4.2" && test "x$GCC" != "xyes" && \
1566  C_SWITCH_SYSTEM="-ma -qmaxmem=4000"
1567if test "$opsys" = "mingw32"; then
1568  case "$canonical" in
1569    x86_64-*-mingw*) C_SWITCH_SYSTEM="-mtune=generic" ;;
1570    *) C_SWITCH_SYSTEM="-mtune=pentium4" ;;
1571  esac
1572fi
1573## gnu-linux might need -D_BSD_SOURCE on old libc5 systems.
1574## It is redundant in glibc2, since we define _GNU_SOURCE.
1575AC_SUBST(C_SWITCH_SYSTEM)
1576
1577
1578LIBS_SYSTEM=
1579case "$opsys" in
1580  ## IBM's X11R5 uses -lIM and -liconv in AIX 3.2.2.
1581  aix4-2) LIBS_SYSTEM="-lrts -lIM -liconv" ;;
1582
1583  freebsd|dragonfly) LIBS_SYSTEM="-lutil" ;;
1584
1585  hpux*) LIBS_SYSTEM="-l:libdld.sl" ;;
1586
1587  qnxnto) LIBS_SYSTEM="-lsocket" ;;
1588
1589  solaris) LIBS_SYSTEM="-lsocket -lnsl" ;;
1590
1591  ## Motif needs -lgen.
1592  unixware) LIBS_SYSTEM="-lsocket -lnsl -lelf -lgen" ;;
1593
1594  haiku) LIBS_SYSTEM="-lnetwork" ;;
1595esac
1596
1597AC_SUBST(LIBS_SYSTEM)
1598
1599### Make sure subsequent tests use flags consistent with the build flags.
1600
1601if test x"${OVERRIDE_CPPFLAGS}" != x; then
1602  CPPFLAGS="${OVERRIDE_CPPFLAGS}"
1603else
1604  CPPFLAGS="$C_SWITCH_SYSTEM $C_SWITCH_MACHINE $CPPFLAGS"
1605fi
1606
1607# Suppress obsolescent Autoconf test for size_t; Emacs assumes C99 or better.
1608AC_DEFUN([AC_TYPE_SIZE_T])
1609# Likewise for obsolescent test for uid_t, gid_t; Emacs assumes them.
1610AC_DEFUN([AC_TYPE_UID_T])
1611
1612# sqrt and other floating-point functions such as fmod and frexp
1613# are found in -lm on many systems.
1614OLD_LIBS=$LIBS
1615AC_SEARCH_LIBS([sqrt], [m])
1616if test "X$LIBS" = "X$OLD_LIBS"; then
1617  LIB_MATH=
1618else
1619  LIB_MATH=$ac_cv_search_sqrt
1620fi
1621LIBS=$OLD_LIBS
1622
1623dnl Current possibilities handled by sed (aix4-2 -> aix,
1624dnl gnu-linux -> gnu/linux, etc.):
1625dnl gnu, gnu/linux, gnu/kfreebsd, aix, cygwin, darwin, hpux.
1626dnl And special cases: berkeley-unix, usg-unix-v, ms-dos, windows-nt.
1627SYSTEM_TYPE=`echo $opsys | sed -e 's/[[0-9]].*//' -e 's|-|/|'`
1628
1629case $opsys in
1630  cygwin )
1631    LIB_MATH=
1632    ;;
1633  darwin )
1634    ## Adding -lm confuses the dynamic linker, so omit it.
1635    LIB_MATH=
1636    ;;
1637  freebsd | dragonfly )
1638    SYSTEM_TYPE=berkeley-unix
1639    ;;
1640  gnu-linux | gnu-kfreebsd )
1641    ;;
1642  hpux10-20 | hpux11 )
1643    ;;
1644  mingw32 )
1645    LIB_MATH=
1646    SYSTEM_TYPE=windows-nt
1647    ;;
1648  netbsd | openbsd )
1649    SYSTEM_TYPE=berkeley-unix
1650    ;;
1651
1652  solaris | unixware )
1653    SYSTEM_TYPE=usg-unix-v
1654    ;;
1655
1656esac
1657
1658AC_SUBST(LIB_MATH)
1659AC_DEFINE_UNQUOTED(SYSTEM_TYPE, "$SYSTEM_TYPE",
1660  [The type of system you are compiling for; sets 'system-type'.])
1661AC_SUBST([SYSTEM_TYPE])
1662
1663
1664pre_PKG_CONFIG_CFLAGS=$CFLAGS
1665pre_PKG_CONFIG_LIBS=$LIBS
1666
1667PKG_PROG_PKG_CONFIG(0.9.0)
1668
1669dnl EMACS_CHECK_MODULES(GSTUFF, gtk+-2.0 >= 1.3 glib = 1.3.4)
1670dnl acts like PKG_CHECK_MODULES(GSTUFF, gtk+-2.0 >= 1.3 glib = 1.3.4,
1671dnl HAVE_GSTUFF=yes, HAVE_GSTUFF=no) -- see pkg-config man page --
1672dnl except that it postprocesses CFLAGS as needed for --enable-gcc-warnings.
1673dnl EMACS_CHECK_MODULES accepts optional 3rd and 4th arguments that
1674dnl can take the place of the default HAVE_GSTUFF=yes and HAVE_GSTUFF=no
1675dnl actions.
1676AC_DEFUN([EMACS_CHECK_MODULES],
1677  [PKG_CHECK_MODULES([$1], [$2],
1678     [$1_CFLAGS=`AS_ECHO(["$$1_CFLAGS"]) | sed -e "$edit_cflags"`
1679      m4_default([$3], [HAVE_$1=yes])],
1680     [m4_default([$4], [HAVE_$1=no])])])
1681
1682HAVE_SOUND=no
1683if test "${with_sound}" != "no"; then
1684  # Sound support for GNU/Linux, the free BSDs, MinGW, and Cygwin.
1685  AC_CHECK_HEADERS([machine/soundcard.h sys/soundcard.h soundcard.h mmsystem.h],
1686    have_sound_header=yes, [], [
1687    #ifdef __MINGW32__
1688    #define WIN32_LEAN_AND_MEAN
1689    #include <windows.h>
1690    #endif
1691    ])
1692  test "${with_sound}" = "oss" && test "${have_sound_header}" != "yes" && \
1693    AC_MSG_ERROR([OSS sound support requested but not found.])
1694
1695  if test "${with_sound}" = "bsd-ossaudio" || test "${with_sound}" = "yes"; then
1696    # Emulation library used on NetBSD.
1697    AC_CHECK_LIB(ossaudio, _oss_ioctl, LIBSOUND=-lossaudio, LIBSOUND=)
1698    test "${with_sound}" = "bsd-ossaudio" && test -z "$LIBSOUND" && \
1699      AC_MSG_ERROR([bsd-ossaudio sound support requested but not found.])
1700    dnl FIXME?  If we did find ossaudio, should we set with_sound=bsd-ossaudio?
1701    dnl Traditionally, we go on to check for alsa too.  Does that make sense?
1702  fi
1703  AC_SUBST(LIBSOUND)
1704
1705  if test "${with_sound}" = "alsa" || test "${with_sound}" = "yes"; then
1706    ALSA_REQUIRED=1.0.0
1707    ALSA_MODULES="alsa >= $ALSA_REQUIRED"
1708    EMACS_CHECK_MODULES([ALSA], [$ALSA_MODULES])
1709    if test $HAVE_ALSA = yes; then
1710      LIBSOUND="$LIBSOUND $ALSA_LIBS"
1711      CFLAGS_SOUND="$CFLAGS_SOUND $ALSA_CFLAGS"
1712      AC_DEFINE(HAVE_ALSA, 1, [Define to 1 if ALSA is available.])
1713    elif test "${with_sound}" = "alsa"; then
1714      AC_MSG_ERROR([ALSA sound support requested but not found.])
1715    fi
1716  fi                            dnl with_sound = alsa|yes
1717
1718  dnl Define HAVE_SOUND if we have sound support.  We know it works and
1719  dnl compiles only on the specified platforms.  For others, it
1720  dnl probably doesn't make sense to try.
1721  dnl FIXME So surely we should bypass this whole section if not using
1722  dnl one of these platforms?
1723  if test x$have_sound_header = xyes || test $HAVE_ALSA = yes; then
1724     case "$opsys" in
1725       dnl defined __FreeBSD__ || defined __NetBSD__ || defined __linux__
1726       dnl Adjust the --with-sound help text if you change this.
1727       gnu-linux|freebsd|netbsd|mingw32|cygwin)
1728         AC_DEFINE(HAVE_SOUND, 1, [Define to 1 if you have sound support.])
1729         HAVE_SOUND=yes
1730         ;;
1731     esac
1732  fi
1733
1734  AC_SUBST(CFLAGS_SOUND)
1735fi
1736
1737dnl checks for header files
1738AC_CHECK_HEADERS_ONCE(
1739  linux/fs.h
1740  malloc.h
1741  sys/systeminfo.h
1742  sys/sysinfo.h
1743  coff.h pty.h
1744  sys/resource.h
1745  sys/utsname.h pwd.h utmp.h util.h
1746  sanitizer/lsan_interface.h)
1747
1748AC_CACHE_CHECK([for ADDR_NO_RANDOMIZE],
1749  [emacs_cv_personality_addr_no_randomize],
1750  [AC_COMPILE_IFELSE(
1751     [AC_LANG_PROGRAM([[#include <sys/personality.h>]],
1752		      [[personality (personality (0xffffffff)
1753				     | ADDR_NO_RANDOMIZE)]])],
1754     [emacs_cv_personality_addr_no_randomize=yes],
1755     [emacs_cv_personality_addr_no_randomize=no])])
1756if test $emacs_cv_personality_addr_no_randomize = yes; then
1757  AC_DEFINE([HAVE_PERSONALITY_ADDR_NO_RANDOMIZE], [1],
1758            [Define to 1 if personality flag ADDR_NO_RANDOMIZE exists.])
1759fi
1760
1761# Note that Solaris has sys/sysinfo.h which defines struct
1762# sysinfo as well.  To make sure that we're using GNU/Linux
1763# sysinfo, we explicitly set one of its fields.
1764if test "$ac_cv_header_sys_sysinfo_h" = yes; then
1765  AC_CACHE_CHECK([if Linux sysinfo may be used], [emacs_cv_linux_sysinfo],
1766  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/sysinfo.h>]],
1767                                     [[struct sysinfo si;
1768                                       si.totalram = 0;
1769                                       sysinfo (&si)]])],
1770    emacs_cv_linux_sysinfo=yes, emacs_cv_linux_sysinfo=no)])
1771
1772  if test $emacs_cv_linux_sysinfo = yes; then
1773    AC_DEFINE([HAVE_LINUX_SYSINFO], 1, [Define to 1 if you have Linux sysinfo function.])
1774    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/sysinfo.h>]],
1775                                       [[struct sysinfo si; return si.mem_unit]])],
1776      AC_DEFINE(LINUX_SYSINFO_UNIT, 1,
1777                [Define to 1 if Linux sysinfo sizes are in multiples of mem_unit bytes.]))
1778  fi
1779fi
1780
1781dnl On Solaris 8 there's a compilation warning for term.h because
1782dnl it doesn't define 'bool'.
1783AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[#include <term.h>]],[[]])],
1784  AC_DEFINE(HAVE_TERM_H, 1, [Define to 1 if you have the <term.h> header file.]))
1785AC_HEADER_SYS_WAIT
1786
1787AC_CHECK_HEADERS_ONCE(sys/socket.h)
1788AC_CHECK_HEADERS(net/if.h, , , [AC_INCLUDES_DEFAULT
1789#if HAVE_SYS_SOCKET_H
1790#include <sys/socket.h>
1791#endif])
1792AC_CHECK_HEADERS(ifaddrs.h, , , [AC_INCLUDES_DEFAULT
1793#if HAVE_SYS_SOCKET_H
1794#include <sys/socket.h>
1795#endif])
1796AC_CHECK_HEADERS(net/if_dl.h, , , [AC_INCLUDES_DEFAULT
1797#if HAVE_SYS_SOCKET_H
1798#include <sys/socket.h>
1799#endif])
1800
1801dnl checks for structure members
1802AC_CHECK_MEMBERS([struct ifreq.ifr_flags, struct ifreq.ifr_hwaddr,
1803		  struct ifreq.ifr_netmask, struct ifreq.ifr_broadaddr,
1804		  struct ifreq.ifr_addr,
1805		  struct ifreq.ifr_addr.sa_len], , ,
1806		 [AC_INCLUDES_DEFAULT
1807#if HAVE_SYS_SOCKET_H
1808#include <sys/socket.h>
1809#endif
1810#if HAVE_NET_IF_H
1811#include <net/if.h>
1812#endif])
1813
1814dnl Check for endianness.
1815dnl AC_C_BIGENDIAN is done by gnulib.
1816
1817dnl check for Make feature
1818
1819AUTO_DEPEND=no
1820AUTODEPEND_PARENTS='lib src'
1821dnl check if we have GCC and autodepend is on.
1822if test "$GCC" = yes && test "$ac_enable_autodepend" = yes; then
1823   AC_CACHE_CHECK([whether gcc understands -MMD -MF], [emacs_cv_autodepend],
1824   [SAVE_CFLAGS="$CFLAGS"
1825   CFLAGS="$CFLAGS -MMD -MF deps.d -MP"
1826   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1827     [emacs_cv_autodepend=yes], [emacs_cv_autodepend=no])
1828   CFLAGS="$SAVE_CFLAGS"
1829   test -f deps.d || emacs_cv_autodepend=no
1830   rm -rf deps.d])
1831   if test $emacs_cv_autodepend = yes; then
1832      AUTO_DEPEND=yes
1833   fi
1834fi
1835AC_SUBST(AUTO_DEPEND)
1836
1837#### Choose a window system.
1838
1839## We leave window_system equal to none if
1840## we end up building without one.  Any new window system should
1841## set window_system to an appropriate value and add objects to
1842## window-system-specific substs.
1843
1844window_system=none
1845
1846if test "${with_pgtk}" = "yes"; then
1847  window_system=pgtk
1848fi
1849
1850
1851AC_PATH_X
1852if test "$no_x" != yes && test "${with_pgtk}" != "yes"; then
1853  window_system=x11
1854fi
1855
1856LD_SWITCH_X_SITE_RPATH=
1857if test "${x_libraries}" != NONE; then
1858  if test -n "${x_libraries}"; then
1859    LD_SWITCH_X_SITE=-L`AS_ECHO(["$x_libraries"]) | sed -e 's/:/ -L/g'`
1860    LD_SWITCH_X_SITE_RPATH=-Wl,-rpath,`
1861      AS_ECHO(["$x_libraries"]) | sed -e 's/:/ -Wl,-rpath,/g'
1862    `
1863  fi
1864  x_default_search_path=""
1865  x_search_path=${x_libraries}
1866  if test -z "${x_search_path}"; then
1867    x_search_path=/usr/lib
1868  fi
1869  for x_library in `AS_ECHO(["$x_search_path:"]) | \
1870		    sed -e "s/:/ /g" -e p -e "s:/lib[[^ /]]* :/share :g"`; do
1871    x_search_path="\
1872${x_library}/X11/%L/%T/%N%C%S:\
1873${x_library}/X11/%l/%T/%N%C%S:\
1874${x_library}/X11/%T/%N%C%S:\
1875${x_library}/X11/%L/%T/%N%S:\
1876${x_library}/X11/%l/%T/%N%S:\
1877${x_library}/X11/%T/%N%S"
1878    if test x"${x_default_search_path}" = x; then
1879      x_default_search_path=${x_search_path}
1880    else
1881      x_default_search_path="${x_search_path}:${x_default_search_path}"
1882    fi
1883  done
1884fi
1885AC_SUBST(LD_SWITCH_X_SITE_RPATH)
1886
1887if test "${x_includes}" != NONE && test -n "${x_includes}"; then
1888  C_SWITCH_X_SITE=$isystem`AS_ECHO(["$x_includes"]) | sed -e "s/:/ $isystem/g"`
1889fi
1890
1891if test x"${x_includes}" = x; then
1892  bitmapdir=/usr/include/X11/bitmaps
1893else
1894  # accumulate include directories that have X11 bitmap subdirectories
1895  bmd_acc=
1896  for bmd in `AS_ECHO(["$x_includes"]) | sed -e 's/:/ /g'`; do
1897    if test -d "${bmd}/X11/bitmaps"; then
1898      bmd_acc="${bmd_acc}:${bmd}/X11/bitmaps"
1899    fi
1900    if test -d "${bmd}/bitmaps"; then
1901      bmd_acc="${bmd_acc}:${bmd}/bitmaps"
1902    fi
1903  done
1904  bitmapdir=${bmd_acc#:}
1905fi
1906
1907NATIVE_IMAGE_API=no
1908
1909test "${with_ns}" = maybe && test "${opsys}" != darwin && with_ns=no
1910HAVE_NS=no
1911NS_GNUSTEP_CONFIG=no
1912NS_IMPL_COCOA=no
1913NS_IMPL_GNUSTEP=no
1914tmp_CPPFLAGS="$CPPFLAGS"
1915tmp_CFLAGS="$CFLAGS"
1916CPPFLAGS="$CPPFLAGS -x objective-c"
1917CFLAGS="$CFLAGS -x objective-c"
1918GNU_OBJC_CFLAGS=""
1919LIBS_GNUSTEP=
1920if test "${with_ns}" != no; then
1921  # macfont.o requires macuvs.h which is absent after 'make extraclean',
1922  # so avoid NS_IMPL_COCOA if macuvs.h is absent.
1923  # Even a headless Emacs can build macuvs.h, so this should let you bootstrap.
1924  if test "${opsys}" = darwin && test -f "$srcdir/src/macuvs.h"; then
1925     NS_IMPL_COCOA=yes
1926     ns_appdir=`pwd`/nextstep/Emacs.app
1927     ns_appbindir=${ns_appdir}/Contents/MacOS
1928     ns_applibexecdir=${ns_appdir}/Contents/MacOS/libexec
1929     ns_applibdir=${ns_appdir}/Contents/Frameworks
1930     ns_appresdir=${ns_appdir}/Contents/Resources
1931     ns_appsrc=Cocoa/Emacs.base
1932     ns_fontfile=macfont.o
1933  elif flags=$( (gnustep-config --objc-flags) 2>/dev/null); then
1934     NS_IMPL_GNUSTEP=yes
1935     NS_GNUSTEP_CONFIG=yes
1936     GNU_OBJC_CFLAGS="$flags"
1937     LIBS_GNUSTEP=$(gnustep-config --gui-libs) || exit
1938  elif test -f $GNUSTEP_CONFIG_FILE; then
1939     NS_IMPL_GNUSTEP=yes
1940     dnl FIXME sourcing this several times in subshells seems inefficient.
1941     GNUSTEP_SYSTEM_HEADERS=$(
1942       . $GNUSTEP_CONFIG_FILE
1943       AS_ECHO(["$GNUSTEP_SYSTEM_HEADERS"])
1944     )
1945     GNUSTEP_SYSTEM_LIBRARIES=$(
1946       . $GNUSTEP_CONFIG_FILE
1947       AS_ECHO(["$GNUSTEP_SYSTEM_LIBRARIES"])
1948     )
1949     dnl I seemed to need these as well with GNUstep-startup 0.25.
1950     GNUSTEP_LOCAL_HEADERS=$(
1951       . $GNUSTEP_CONFIG_FILE
1952       AS_ECHO(["$GNUSTEP_LOCAL_HEADERS"])
1953     )
1954     GNUSTEP_LOCAL_LIBRARIES=$(
1955       . $GNUSTEP_CONFIG_FILE
1956       AS_ECHO(["$GNUSTEP_LOCAL_LIBRARIES"])
1957     )
1958     test "x${GNUSTEP_LOCAL_HEADERS}" != "x" && \
1959       GNUSTEP_LOCAL_HEADERS="-I${GNUSTEP_LOCAL_HEADERS}"
1960     test "x${GNUSTEP_LOCAL_LIBRARIES}" != "x" && \
1961       GNUSTEP_LOCAL_LIBRARIES="-L${GNUSTEP_LOCAL_LIBRARIES}"
1962     CPPFLAGS="$CPPFLAGS -I${GNUSTEP_SYSTEM_HEADERS} ${GNUSTEP_LOCAL_HEADERS}"
1963     CFLAGS="$CFLAGS -I${GNUSTEP_SYSTEM_HEADERS} ${GNUSTEP_LOCAL_HEADERS}"
1964     LDFLAGS="$LDFLAGS -L${GNUSTEP_SYSTEM_LIBRARIES} ${GNUSTEP_LOCAL_LIBRARIES}"
1965     LIBS_GNUSTEP="-lgnustep-gui -lgnustep-base -lobjc -lpthread"
1966     dnl GNUstep defines BASE_NATIVE_OBJC_EXCEPTIONS to 0 or 1.
1967     dnl If they had chosen to either define it or not, we could have
1968     dnl just used AC_CHECK_DECL here.
1969     AC_CACHE_CHECK(if GNUstep defines BASE_NATIVE_OBJC_EXCEPTIONS,
1970       emacs_cv_objc_exceptions,
1971AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <GNUstepBase/GSConfig.h>]],
1972[[#if defined BASE_NATIVE_OBJC_EXCEPTIONS && BASE_NATIVE_OBJC_EXCEPTIONS > 0
19731;
1974#else
1975fail;
1976#endif]])], emacs_cv_objc_exceptions=yes, emacs_cv_objc_exceptions=no ) )
1977     if test $emacs_cv_objc_exceptions = yes; then
1978       dnl _NATIVE_OBJC_EXCEPTIONS is used by the GNUstep headers.
1979       AC_DEFINE(_NATIVE_OBJC_EXCEPTIONS, 1,
1980         [Define if GNUstep uses ObjC exceptions.])
1981       GNU_OBJC_CFLAGS="$GNU_OBJC_CFLAGS -fobjc-exceptions"
1982     fi
1983  fi
1984  if test $NS_IMPL_GNUSTEP = yes; then
1985     ns_appdir=`pwd`/nextstep/Emacs.app
1986     ns_appbindir=${ns_appdir}
1987     ns_applibexecdir=${ns_appdir}/libexec
1988     ns_applibdir=${ns_appdir}/Frameworks
1989     ns_appresdir=${ns_appdir}/Resources
1990     ns_appsrc=GNUstep/Emacs.base
1991     ns_fontfile=nsfont.o
1992  fi
1993
1994  dnl This is only used while we test the NS headers, it gets reset below.
1995  CPPFLAGS="$CPPFLAGS $GNU_OBJC_CFLAGS"
1996  CFLAGS="$CFLAGS $GNU_OBJC_CFLAGS"
1997
1998  AC_CHECK_HEADER([AppKit/AppKit.h], [HAVE_NS=yes],
1999		  [AC_MSG_ERROR([The include files (AppKit/AppKit.h etc) that
2000are required for a Nextstep build are missing or cannot be compiled.
2001Either fix this, or re-configure with the option '--without-ns'.])])
2002
2003  macfont_file=""
2004  if test "${NS_IMPL_COCOA}" = "yes"; then
2005    AC_MSG_CHECKING([for Mac OS X 10.6 or newer])
2006    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <AppKit/AppKit.h>],
2007                                     [
2008#ifdef MAC_OS_X_VERSION_MAX_ALLOWED
2009#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
2010 ; /* OK */
2011#else
2012 error "Mac OS X 10.6 or newer required";
2013#endif
2014#endif
2015		    ])],
2016		    ns_osx_have_106=yes,
2017		    ns_osx_have_106=no)
2018    AC_MSG_RESULT([$ns_osx_have_106])
2019
2020    if test $ns_osx_have_106 = no; then
2021       AC_MSG_ERROR([Mac OS X 10.6 or newer is required]);
2022    fi
2023  fi
2024
2025  if test "${with_native_image_api}" = yes; then
2026     AC_DEFINE(HAVE_NATIVE_IMAGE_API, 1, [Define to use native OS APIs for images.])
2027     NATIVE_IMAGE_API="yes (ns)"
2028  fi
2029fi
2030
2031AC_SUBST(LIBS_GNUSTEP)
2032
2033INSTALL_ARCH_INDEP_EXTRA=install-etc
2034ns_self_contained=no
2035NS_OBJ=
2036NS_OBJC_OBJ=
2037if test "${HAVE_NS}" = yes; then
2038  if test "$with_toolkit_scroll_bars" = "no"; then
2039    AC_MSG_WARN([Non-toolkit scroll bars are not implemented for Nextstep.])
2040  fi
2041
2042  window_system=nextstep
2043  # set up packaging dirs
2044  if test "${EN_NS_SELF_CONTAINED}" = yes; then
2045     AC_DEFINE(NS_SELF_CONTAINED, 1, [Build an NS bundled app])
2046     ns_self_contained=yes
2047     prefix=${ns_appresdir}
2048     exec_prefix=${ns_appbindir}
2049     dnl This one isn't really used, only archlibdir is.
2050     libexecdir="\${ns_applibexecdir}"
2051     archlibdir="\${ns_applibexecdir}"
2052     etcdocdir="\${ns_appresdir}/etc"
2053     etcdir="\${ns_appresdir}/etc"
2054     dnl FIXME maybe set datarootdir instead.
2055     dnl That would also get applications, icons, man.
2056     infodir="\${ns_appresdir}/info"
2057     mandir="\${ns_appresdir}/man"
2058     lispdir="\${ns_appresdir}/lisp"
2059     lispdirrel="\${ns_appresdir}/lisp"
2060     test "$locallisppathset" = no && locallisppath="\${ns_appresdir}/site-lisp"
2061     INSTALL_ARCH_INDEP_EXTRA=
2062  fi
2063
2064  NS_OBJC_OBJ="nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o $ns_fontfile"
2065fi
2066CFLAGS="$tmp_CFLAGS"
2067CPPFLAGS="$tmp_CPPFLAGS"
2068AC_SUBST(INSTALL_ARCH_INDEP_EXTRA)
2069AC_SUBST(ns_self_contained)
2070AC_SUBST(NS_OBJ)
2071AC_SUBST(NS_OBJC_OBJ)
2072
2073if test "${HAVE_NS}" = yes; then
2074  AC_CACHE_CHECK(
2075    [if the Objective C compiler supports instancetype],
2076    [emacs_cv_objc_instancetype],
2077    [AC_LANG_PUSH([Objective C])
2078     AC_COMPILE_IFELSE(
2079       [AC_LANG_SOURCE([[@interface Test
2080                          + (instancetype)test;
2081                          @end]])],
2082       emacs_cv_objc_instancetype=yes,
2083       emacs_cv_objc_instancetype=no)
2084     AC_LANG_POP([Objective C])])
2085
2086  if test x$emacs_cv_objc_instancetype = xyes ; then
2087    AC_DEFINE(NATIVE_OBJC_INSTANCETYPE, 1,
2088              [Define if ObjC compiler supports instancetype natively.])
2089  fi
2090
2091  AC_CACHE_CHECK(
2092    [if the Objective C compiler defaults to C99],
2093    [emacs_cv_objc_c99],
2094    [AC_LANG_PUSH([Objective C])
2095     AC_COMPILE_IFELSE(
2096       [AC_LANG_PROGRAM([], [[for (int i = 0;;);]])],
2097       emacs_cv_objc_c99=yes,
2098       emacs_cv_objc_c99=no)
2099     AC_LANG_POP([Objective C])])
2100
2101   if test x$emacs_cv_objc_c99 = xno ; then
2102     GNU_OBJC_CFLAGS="$GNU_OBJC_CFLAGS -std=c99"
2103   fi
2104fi
2105
2106HAVE_BE_APP=no
2107if test "${opsys}" = "haiku" && test "${with_be_app}" = "yes"; then
2108   dnl Only GCC is supported.  Clang might work, but it's
2109   dnl not reliable, so don't check for it here.
2110   AC_PROG_CXX([gcc g++])
2111   CXXFLAGS="$CXXFLAGS $emacs_g3_CFLAGS"
2112   AC_LANG_PUSH([C++])
2113   AC_CHECK_HEADER([app/Application.h], [HAVE_BE_APP=yes],
2114                   [AC_MSG_ERROR([The Application Kit headers required for building
2115with the Application Kit were not found or cannot be compiled. Either fix this, or
2116re-configure with the option '--without-be-app'.])])
2117   AC_LANG_POP([C++])
2118fi
2119
2120AC_SUBST(HAVE_BE_APP)
2121
2122HAVE_W32=no
2123W32_OBJ=
2124W32_LIBS=
2125EMACSRES=
2126CLIENTRES=
2127CLIENTW=
2128W32_RES_LINK=
2129EMACS_MANIFEST=
2130if test "${with_w32}" != no; then
2131  case "${opsys}" in
2132    cygwin)
2133      AC_CHECK_HEADER([windows.h], [HAVE_W32=yes],
2134             [AC_MSG_ERROR(['--with-w32' was specified, but windows.h
2135                   cannot be found.])])
2136    ;;
2137    mingw32)
2138    ## Using --with-w32 with MinGW is a no-op, but we allow it.
2139    ;;
2140    *)
2141      AC_MSG_ERROR([Using w32 with an autotools build is only supported for Cygwin and MinGW32.])
2142    ;;
2143  esac
2144fi
2145
2146if test "${opsys}" = "mingw32"; then
2147  AC_CACHE_CHECK([whether Windows API headers are recent enough], [emacs_cv_w32api],
2148  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2149     #include <windows.h>
2150     #include <usp10.h>]],
2151   [[PIMAGE_NT_HEADERS pHeader;
2152     PIMAGE_SECTION_HEADER pSection = IMAGE_FIRST_SECTION(pHeader)]])],
2153   [emacs_cv_w32api=yes], [emacs_cv_w32api=no])])
2154  if test "${emacs_cv_w32api}" = "no"; then
2155    AC_MSG_ERROR([the Windows API headers are too old to support this build.])
2156  fi
2157  HAVE_W32=${emacs_cv_w32api}
2158fi
2159
2160FIRSTFILE_OBJ=
2161NTDIR=
2162LIBS_ECLIENT=
2163LIB_WSOCK32=
2164NTLIB=
2165CM_OBJ="cm.o"
2166XARGS_LIMIT=
2167if test "${HAVE_W32}" = "yes"; then
2168  AC_DEFINE(HAVE_NTGUI, 1, [Define to use native MS Windows GUI.])
2169  if test "$with_toolkit_scroll_bars" = "no"; then
2170    AC_MSG_ERROR([Non-toolkit scroll bars are not implemented for w32 build.])
2171  fi
2172  AC_CHECK_TOOL(WINDRES, [windres],
2173                [AC_MSG_ERROR([No resource compiler found.])])
2174  W32_OBJ="w32fns.o w32menu.o w32reg.o w32font.o w32term.o"
2175  W32_OBJ="$W32_OBJ w32xfns.o w32select.o w32uniscribe.o w32cygwinx.o"
2176  EMACSRES="emacs.res"
2177  case "$canonical" in
2178    x86_64-*-*) EMACS_MANIFEST="emacs-x64.manifest" ;;
2179    *) EMACS_MANIFEST="emacs-x86.manifest" ;;
2180  esac
2181  dnl Construct something of the form "24,4,0,0" with 4 components.
2182  comma_version=`echo "${PACKAGE_VERSION}.0.0" | sed -e 's/\./,/g' -e 's/^\([[^,]]*,[[^,]]*,[[^,]]*,[[^,]]*\).*/\1/'`
2183
2184  comma_space_version=`echo "$comma_version" | sed 's/,/, /g'`
2185  AC_SUBST(comma_version)
2186  AC_SUBST(comma_space_version)
2187  AC_CONFIG_FILES([nt/emacs.rc nt/emacsclient.rc])
2188  if test "${opsys}" = "cygwin"; then
2189    W32_LIBS="$W32_LIBS -lkernel32 -luser32 -lusp10 -lgdi32"
2190    W32_LIBS="$W32_LIBS -lole32 -lcomdlg32 -lcomctl32 -lwinspool"
2191    # Tell the linker that emacs.res is an object (which we compile from
2192    # the rc file), not a linker script.
2193    W32_RES_LINK="-Wl,emacs.res"
2194  else
2195    W32_OBJ="$W32_OBJ w32.o w32console.o w32heap.o w32inevt.o w32proc.o"
2196    dnl FIXME: This should probably be supported for Cygwin/w32 as
2197    dnl well, but the Cygwin build needs to link against -lgdiplus
2198    if test "${with_native_image_api}" = yes; then
2199      AC_DEFINE(HAVE_NATIVE_IMAGE_API, 1, [Define to use native OS APIs for images.])
2200      NATIVE_IMAGE_API="yes (w32)"
2201      W32_OBJ="$W32_OBJ w32image.o"
2202    fi
2203    W32_LIBS="$W32_LIBS -lwinmm -lusp10 -lgdi32 -lcomdlg32"
2204    W32_LIBS="$W32_LIBS -lmpr -lwinspool -lole32 -lcomctl32"
2205    W32_RES_LINK="\$(EMACSRES)"
2206    CLIENTRES="emacsclient.res"
2207    CLIENTW="emacsclientw\$(EXEEXT)"
2208    FIRSTFILE_OBJ=firstfile.o
2209    NTDIR=nt
2210    CM_OBJ=
2211    LIBS_ECLIENT="-lcomctl32"
2212    LIB_WSOCK32="-lwsock32"
2213    NTLIB="ntlib.$ac_objext"
2214    XARGS_LIMIT="-s 10000"
2215  fi
2216fi
2217
2218if test "${HAVE_W32}" = "no" && test "${opsys}" = "cygwin"; then
2219  W32_LIBS="-lkernel32"
2220  W32_OBJ="w32cygwinx.o"
2221fi
2222
2223AC_SUBST(W32_OBJ)
2224AC_SUBST(W32_LIBS)
2225AC_SUBST(EMACSRES)
2226AC_SUBST(EMACS_MANIFEST)
2227AC_SUBST(CLIENTRES)
2228AC_SUBST(CLIENTW)
2229AC_SUBST(W32_RES_LINK)
2230AC_SUBST(FIRSTFILE_OBJ)
2231AC_SUBST(NTDIR)
2232AC_SUBST(CM_OBJ)
2233AC_SUBST(LIBS_ECLIENT)
2234AC_SUBST(LIB_WSOCK32)
2235AC_SUBST(NTLIB)
2236AC_SUBST(XARGS_LIMIT)
2237
2238if test "${HAVE_W32}" = "yes"; then
2239  window_system=w32
2240  with_xft=no
2241fi
2242
2243HAIKU_OBJ=
2244HAIKU_CXX_OBJ=
2245HAIKU_LIBS=
2246HAIKU_CFLAGS=
2247
2248if test "$opsys" = "haiku"; then
2249  HAIKU_OBJ="$HAIKU_OBJ haiku.o"
2250fi
2251
2252if test "${HAVE_BE_APP}" = "yes"; then
2253  AC_DEFINE([HAVE_HAIKU], 1,
2254      [Define if Emacs will be built with Haiku windowing support])
2255fi
2256
2257if test "${HAVE_BE_APP}" = "yes"; then
2258  window_system=haiku
2259  with_xft=no
2260  HAIKU_OBJ="$HAIKU_OBJ haikufns.o haikuterm.o haikumenu.o haikufont.o haikuselect.o haiku_io.o"
2261  HAIKU_CXX_OBJ="haiku_support.o haiku_font_support.o haiku_draw_support.o haiku_select.o"
2262  HAIKU_LIBS="-lbe -lgame -ltranslation -ltracker" # -lgame is needed for set_mouse_position.
2263
2264  if test "${with_native_image_api}" = yes; then
2265     AC_DEFINE(HAVE_NATIVE_IMAGE_API, 1, [Define to use native OS APIs for images.])
2266     NATIVE_IMAGE_API="yes (haiku)"
2267     HAIKU_OBJ="$HAIKU_OBJ haikuimage.o"
2268  fi
2269fi
2270
2271AC_SUBST(HAIKU_LIBS)
2272AC_SUBST(HAIKU_OBJ)
2273AC_SUBST(HAIKU_CXX_OBJ)
2274AC_SUBST(HAIKU_CFLAGS)
2275
2276## $window_system is now set to the window system we will
2277## ultimately use.
2278
2279term_header=
2280HAVE_X_WINDOWS=no
2281HAVE_X11=no
2282USE_X_TOOLKIT=none
2283
2284case "${window_system}" in
2285  x11 )
2286    HAVE_X_WINDOWS=yes
2287    HAVE_X11=yes
2288    term_header=xterm.h
2289    case "${with_x_toolkit}" in
2290      athena | lucid ) USE_X_TOOLKIT=LUCID ;;
2291      motif ) USE_X_TOOLKIT=MOTIF ;;
2292      gtk ) with_gtk=yes
2293            term_header=gtkutil.h
2294dnl Don't set this for GTK.  A lot of tests below assumes Xt when
2295dnl USE_X_TOOLKIT is set.
2296            USE_X_TOOLKIT=none ;;
2297      gtk2 ) with_gtk2=yes
2298             term_header=gtkutil.h
2299             USE_X_TOOLKIT=none ;;
2300      gtk3 ) with_gtk3=yes
2301             term_header=gtkutil.h
2302             USE_X_TOOLKIT=none ;;
2303      no ) USE_X_TOOLKIT=none ;;
2304dnl If user did not say whether to use a toolkit, make this decision later:
2305dnl use the toolkit if we have gtk, or X11R5 or newer.
2306      * ) USE_X_TOOLKIT=maybe ;;
2307    esac
2308  ;;
2309  nextstep )
2310    term_header=nsterm.h
2311  ;;
2312  w32 )
2313    term_header=w32term.h
2314  ;;
2315  pgtk )
2316    term_header=pgtkterm.h
2317    with_gtk3=yes
2318    USE_X_TOOLKIT=none
2319    HAVE_PGTK=yes
2320    AC_DEFINE([HAVE_PGTK], 1, [Define to 1 if you have pure Gtk+-3.])
2321  ;;
2322  haiku )
2323    term_header=haikuterm.h
2324  ;;
2325esac
2326
2327if test "$window_system" = none && test "X$with_x" != "Xno"; then
2328   AC_CHECK_PROG(HAVE_XSERVER, X, true, false)
2329   if test "$HAVE_XSERVER" = true ||
2330      test -n "$DISPLAY" ||
2331      {
2332        for emacs_libX11 in /usr/lib/libX11.*; do break; done
2333        test "$emacs_libX11" != '/usr/lib/libX11.*'
2334      }
2335   then
2336        AC_MSG_ERROR([You seem to be running X, but no X development libraries
2337were found.  You should install the relevant development files for X
2338and for the toolkit you want, such as Gtk+ or Motif.  Also make
2339sure you have development files for image handling, i.e.
2340tiff, gif, jpeg, png and xpm.
2341If you are sure you want Emacs compiled without X window support, pass
2342  --without-x
2343to configure.])
2344   fi
2345fi
2346
2347# Does the opsystem file prohibit the use of the GNU malloc?
2348# Assume not, until told otherwise.
2349GNU_MALLOC=yes
2350
2351AC_CACHE_CHECK(
2352  [whether malloc is Doug Lea style],
2353  [emacs_cv_var_doug_lea_malloc],
2354  [emacs_cv_var_doug_lea_malloc=no
2355   dnl Hooks do not work with address sanitization.
2356   if test "$emacs_cv_sanitize_address" != yes; then
2357     AC_LINK_IFELSE(
2358       [AC_LANG_PROGRAM(
2359	  [[#include <malloc.h>
2360	    static void hook (void) {}]],
2361	  [[malloc_set_state (malloc_get_state ());
2362	    __after_morecore_hook = hook;
2363	    __malloc_initialize_hook = hook;]])],
2364       [emacs_cv_var_doug_lea_malloc=yes])
2365   fi])
2366doug_lea_malloc=$emacs_cv_var_doug_lea_malloc
2367
2368hybrid_malloc=
2369system_malloc=yes
2370
2371dnl This must be before the test of $ac_cv_func_sbrk below.
2372AC_CHECK_FUNCS_ONCE([sbrk])
2373
2374test $with_unexec = yes &&
2375case "$opsys" in
2376  ## darwin ld insists on the use of malloc routines in the System framework.
2377  darwin | mingw32 | nacl | solaris) ;;
2378  cygwin | qnxnto | freebsd)
2379	  hybrid_malloc=yes
2380          system_malloc= ;;
2381  *) test "$ac_cv_func_sbrk" = yes && system_malloc=$emacs_cv_sanitize_address;;
2382esac
2383
2384if test "${system_malloc}" != yes && test "${doug_lea_malloc}" != yes \
2385   && test "${UNEXEC_OBJ}" = unexelf.o; then
2386  hybrid_malloc=yes
2387fi
2388
2389GMALLOC_OBJ=
2390HYBRID_MALLOC=
2391if test "${system_malloc}" = "yes"; then
2392  AC_DEFINE([SYSTEM_MALLOC], 1,
2393    [Define to 1 to use the system memory allocator, even if it is not
2394     Doug Lea style.])
2395  GNU_MALLOC=no
2396  GNU_MALLOC_reason="
2397    (The GNU allocators don't work with this system configuration.)"
2398  VMLIMIT_OBJ=
2399elif test "$hybrid_malloc" = yes; then
2400  AC_DEFINE(HYBRID_MALLOC, 1,
2401    [Define to use gmalloc before dumping and the system malloc after.])
2402  HYBRID_MALLOC=1
2403  GNU_MALLOC=no
2404  GNU_MALLOC_reason=" (only before dumping)"
2405  GMALLOC_OBJ=gmalloc.o
2406  VMLIMIT_OBJ=
2407else
2408  test "$doug_lea_malloc" != "yes" && GMALLOC_OBJ=gmalloc.o
2409  VMLIMIT_OBJ=vm-limit.o
2410
2411  AC_CHECK_HEADERS([sys/vlimit.h])
2412  AC_CACHE_CHECK([for data_start], [emacs_cv_data_start],
2413    [AC_LINK_IFELSE(
2414       [AC_LANG_PROGRAM(
2415	 [[extern char data_start[]; char ch;]],
2416	 [[return data_start < &ch;]])],
2417       [emacs_cv_data_start=yes],
2418       [emacs_cv_data_start=no])])
2419  if test $emacs_cv_data_start = yes; then
2420    AC_DEFINE([HAVE_DATA_START], 1,
2421      [Define to 1 if data_start is the address of the start
2422       of the main data segment.])
2423  fi
2424fi
2425AC_SUBST([HYBRID_MALLOC])
2426AC_SUBST(GMALLOC_OBJ)
2427AC_SUBST(VMLIMIT_OBJ)
2428
2429if test "$doug_lea_malloc" = "yes" && test "$hybrid_malloc" != yes; then
2430  if test "$GNU_MALLOC" = yes ; then
2431    GNU_MALLOC_reason="
2432      (Using Doug Lea's new malloc from the GNU C Library.)"
2433  fi
2434  AC_DEFINE(DOUG_LEA_MALLOC, 1,
2435    [Define to 1 if the system memory allocator is Doug Lea style,
2436     with malloc hooks and malloc_set_state.])
2437
2438  ## Use mmap directly for allocating larger buffers.
2439  ## FIXME this comes from src/s/{gnu,gnu-linux}.h:
2440  ## #ifdef DOUG_LEA_MALLOC; #undef REL_ALLOC; #endif
2441  ## Does the AC_FUNC_MMAP test below make this check unnecessary?
2442  case "$opsys" in
2443    mingw32|gnu*) REL_ALLOC=no ;;
2444  esac
2445fi
2446
2447if test x"${REL_ALLOC}" = x; then
2448  REL_ALLOC=${GNU_MALLOC}
2449fi
2450
2451use_mmap_for_buffers=no
2452case "$opsys" in
2453  mingw32) use_mmap_for_buffers=yes ;;
2454esac
2455
2456AC_FUNC_MMAP
2457if test $use_mmap_for_buffers = yes; then
2458  AC_DEFINE(USE_MMAP_FOR_BUFFERS, 1, [Define to use mmap to allocate buffer text.])
2459  REL_ALLOC=no
2460fi
2461
2462LIBS="$LIBS_SYSTEM $LIBS"
2463
2464dnl FIXME replace main with a function we actually want from this library.
2465AC_CHECK_LIB(Xbsd, main, LD_SWITCH_X_SITE="$LD_SWITCH_X_SITE -lXbsd")
2466
2467dnl Check for the POSIX thread library.
2468LIB_PTHREAD=
2469AC_CHECK_HEADERS_ONCE(pthread.h)
2470if test "$ac_cv_header_pthread_h" && test "$opsys" != "mingw32"; then
2471  AC_CACHE_CHECK([for pthread library],
2472    [emacs_cv_pthread_lib],
2473    [emacs_cv_pthread_lib=no
2474     OLD_LIBS=$LIBS
2475     for emacs_pthread_lib in 'none needed' -lpthread; do
2476       case $emacs_pthread_lib in
2477	 -*) LIBS="$OLD_LIBS $emacs_pthread_lib";;
2478       esac
2479       AC_LINK_IFELSE(
2480	 [AC_LANG_PROGRAM(
2481	    [[#include <pthread.h>
2482	      #include <signal.h>
2483	      sigset_t old_mask, new_mask;
2484	      void noop (void) {}]],
2485	    [[pthread_t th = pthread_self ();
2486	      int status = 0;
2487	      status += pthread_create (&th, 0, 0, 0);
2488	      status += pthread_sigmask (SIG_BLOCK, &new_mask, &old_mask);
2489	      status += pthread_kill (th, 0);
2490	      #if ! (defined SYSTEM_MALLOC || defined HYBRID_MALLOC \
2491		     || defined DOUG_LEA_MALLOC)
2492	      /* Test for pthread_atfork only if gmalloc uses it,
2493		 as older-style hosts like MirBSD 10 lack it.  */
2494	      status += pthread_atfork (noop, noop, noop);
2495	      #endif
2496	      return status;]])],
2497	 [emacs_cv_pthread_lib=$emacs_pthread_lib])
2498       LIBS=$OLD_LIBS
2499       if test "$emacs_cv_pthread_lib" != no; then
2500	 break
2501       fi
2502     done])
2503  if test "$emacs_cv_pthread_lib" != no; then
2504    AC_DEFINE([HAVE_PTHREAD], 1, [Define to 1 if you have POSIX threads.])
2505    case $emacs_cv_pthread_lib in
2506      -*) LIB_PTHREAD=$emacs_cv_pthread_lib;;
2507    esac
2508    ac_cv_func_pthread_sigmask=yes
2509    # Some systems optimize for single-threaded programs by default, and
2510    # need special flags to disable these optimizations. For example, the
2511    # definition of 'errno' in <errno.h>.
2512    case $opsys in
2513      hpux* | solaris)
2514	AC_DEFINE([_REENTRANT], 1,
2515	  [Define to 1 if your system requires this in multithreaded code.]);;
2516      aix4-2)
2517	AC_DEFINE([_THREAD_SAFE], 1,
2518	  [Define to 1 if your system requires this in multithreaded code.]);;
2519    esac
2520  fi
2521fi
2522AC_SUBST([LIB_PTHREAD])
2523
2524AC_MSG_CHECKING([for thread support])
2525threads_enabled=no
2526if test "$with_threads" = yes; then
2527   if test "$emacs_cv_pthread_lib" != no; then
2528      AC_DEFINE(THREADS_ENABLED, 1,
2529                [Define to 1 if you want elisp thread support.])
2530      threads_enabled=yes
2531   elif test "${opsys}" = "mingw32"; then
2532      dnl MinGW can do native Windows threads even without pthreads
2533      AC_DEFINE(THREADS_ENABLED, 1,
2534                [Define to 1 if you want elisp thread support.])
2535      threads_enabled=yes
2536   fi
2537fi
2538AC_MSG_RESULT([$threads_enabled])
2539
2540dnl Check for need for bigtoc support on IBM AIX
2541
2542case ${host_os} in
2543aix*)
2544  AC_CACHE_CHECK([for -bbigtoc option], [gdb_cv_bigtoc], [
2545    case $GCC in
2546    yes) gdb_cv_bigtoc=-Wl,-bbigtoc ;;
2547    *) gdb_cv_bigtoc=-bbigtoc ;;
2548    esac
2549
2550    LDFLAGS=$LDFLAGS\ $gdb_cv_bigtoc
2551    AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[int i;]])], [], [gdb_cv_bigtoc=])
2552  ])
2553  ;;
2554esac
2555
2556# Change CFLAGS, CPPFLAGS, and LIBS temporarily so that C_SWITCH_X_SITE
2557# is for the tests that follow.  We set them back later on.
2558
2559REAL_CFLAGS="$CFLAGS"
2560REAL_CPPFLAGS="$CPPFLAGS"
2561REAL_LIBS="$LIBS"
2562
2563if test "${HAVE_X11}" = "yes"; then
2564  DEFS="$C_SWITCH_X_SITE $DEFS"
2565  LDFLAGS="$LDFLAGS $LD_SWITCH_X_SITE"
2566  LIBS="-lX11 $LIBS"
2567  CFLAGS="$C_SWITCH_X_SITE $CFLAGS"
2568  CPPFLAGS="$C_SWITCH_X_SITE $CPPFLAGS"
2569
2570  # On Solaris, arrange for LD_RUN_PATH to point to the X libraries for tests.
2571  # This is handled by LD_SWITCH_X_SITE_RPATH during the real build,
2572  # but it's more convenient here to set LD_RUN_PATH since this
2573  # also works on hosts that don't understand LD_SWITCH_X_SITE_RPATH.
2574  if test "${x_libraries}" != NONE && test -n "${x_libraries}"; then
2575    LD_RUN_PATH=$x_libraries${LD_RUN_PATH+:}$LD_RUN_PATH
2576    export LD_RUN_PATH
2577  fi
2578
2579  if test "${opsys}" = "gnu-linux"; then
2580    AC_CACHE_CHECK([whether X on GNU/Linux needs -b to link], [emacs_cv_b_link],
2581    [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
2582     [[XOpenDisplay ("foo");]])],
2583     [xgnu_linux_first_failure=no],
2584     [xgnu_linux_first_failure=yes])
2585    if test "${xgnu_linux_first_failure}" = "yes"; then
2586      OLD_CPPFLAGS="$CPPFLAGS"
2587      OLD_LIBS="$LIBS"
2588      CPPFLAGS="$CPPFLAGS -b i486-linuxaout"
2589      LIBS="$LIBS -b i486-linuxaout"
2590      AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
2591       [[XOpenDisplay ("foo");]])],
2592       [xgnu_linux_second_failure=no],
2593       [xgnu_linux_second_failure=yes])
2594      if test "${xgnu_linux_second_failure}" = "yes"; then
2595	# If we get the same failure with -b, there is no use adding -b.
2596	# So leave it out.  This plays safe.
2597        emacs_cv_b_link=no
2598      else
2599        emacs_cv_b_link=yes
2600      fi
2601      CPPFLAGS=$OLD_CPPFLAGS
2602      LIBS=$OLD_LIBS
2603    else
2604      emacs_cv_b_link=no
2605    fi])
2606    if test "x$emacs_cv_b_link" = xyes ; then
2607      LD_SWITCH_X_SITE="$LD_SWITCH_X_SITE -b i486-linuxaout"
2608      C_SWITCH_X_SITE="$C_SWITCH_X_SITE -b i486-linuxaout"
2609    fi
2610  fi
2611
2612  # Reportedly, some broken Solaris systems have XKBlib.h but are missing
2613  # header files included from there.
2614  AC_CACHE_CHECK([for Xkb], [emacs_cv_xkb],
2615  [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <X11/Xlib.h>
2616#include <X11/XKBlib.h>]],
2617	[[XkbDescPtr kb = XkbGetKeyboard (0, XkbAllComponentsMask, XkbUseCoreKbd);]])],
2618	emacs_cv_xkb=yes, emacs_cv_xkb=no)])
2619  if test $emacs_cv_xkb = yes; then
2620    AC_DEFINE(HAVE_XKB, 1, [Define to 1 if you have the Xkb extension.])
2621  fi
2622
2623  AC_CHECK_FUNCS(XrmSetDatabase XScreenResourceString \
2624XScreenNumberOfScreen)
2625fi
2626
2627if test "${window_system}" = "x11"; then
2628  AC_MSG_CHECKING(X11 version 6)
2629  AC_CACHE_VAL(emacs_cv_x11_version_6,
2630  [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <X11/Xlib.h>]],
2631[[#if XlibSpecificationRelease < 6
2632fail;
2633#endif
2634]])], emacs_cv_x11_version_6=yes, emacs_cv_x11_version_6=no)])
2635  if test $emacs_cv_x11_version_6 = yes; then
2636    AC_MSG_RESULT(6 or newer)
2637    AC_DEFINE(HAVE_X11R6, 1,
2638	      [Define to 1 if you have the X11R6 or newer version of Xlib.])
2639    AC_DEFINE(HAVE_X_I18N, 1, [Define if you have usable i18n support.])
2640    ## inoue@ainet.or.jp says Solaris has a bug related to X11R6-style
2641    ## XIM support.
2642    case "$opsys" in
2643      solaris) : ;;
2644      *) AC_DEFINE(HAVE_X11R6_XIM, 1,
2645           [Define if you have usable X11R6-style XIM support.])
2646         ;;
2647    esac
2648  else
2649    AC_MSG_RESULT(before 6)
2650  fi
2651fi
2652
2653
2654### Use -lrsvg-2 if available, unless '--with-rsvg=no' is specified.
2655HAVE_RSVG=no
2656if test "${HAVE_X11}" = "yes" || test "${HAVE_NS}" = "yes" \
2657   || test "${opsys}" = "mingw32" || test "${HAVE_BE_APP}" = "yes" \
2658   || test "${window_system}" = "pgtk"; then
2659  if test "${with_rsvg}" != "no"; then
2660    RSVG_REQUIRED=2.14.0
2661    RSVG_MODULE="librsvg-2.0 >= $RSVG_REQUIRED"
2662
2663    EMACS_CHECK_MODULES([RSVG], [$RSVG_MODULE])
2664    AC_SUBST(RSVG_CFLAGS)
2665    AC_SUBST(RSVG_LIBS)
2666
2667    if test $HAVE_RSVG = yes; then
2668      AC_DEFINE(HAVE_RSVG, 1, [Define to 1 if using librsvg.])
2669      CFLAGS="$CFLAGS $RSVG_CFLAGS"
2670      # Windows loads librsvg dynamically
2671      if test "${opsys}" = "mingw32"; then
2672	RSVG_LIBS=
2673      fi
2674    fi
2675  fi
2676fi
2677
2678### Use -lwebp if available, unless '--with-webp=no'
2679HAVE_WEBP=no
2680if test "${with_webp}" != "no"; then
2681   if test "${HAVE_X11}" = "yes" || test "${opsys}" = "mingw32" \
2682   || test "${HAVE_W32}" = "yes" || test "${HAVE_NS}" = "yes" \
2683   || test "${HAVE_BE_APP}" = "yes" || test "${HAVE_PGTK}" = "yes"; then
2684      WEBP_REQUIRED=0.6.0
2685      WEBP_MODULE="libwebp >= $WEBP_REQUIRED"
2686
2687      EMACS_CHECK_MODULES([WEBP], [$WEBP_MODULE])
2688      AC_SUBST(WEBP_CFLAGS)
2689      AC_SUBST(WEBP_LIBS)
2690   fi
2691   if test $HAVE_WEBP = yes; then
2692      AC_DEFINE(HAVE_WEBP, 1, [Define to 1 if using libwebp.])
2693      CFLAGS="$CFLAGS $WEBP_CFLAGS"
2694      # Windows loads libwebp dynamically
2695      if test "${opsys}" = "mingw32"; then
2696	WEBP_LIBS=
2697      fi
2698   fi
2699fi
2700
2701### Use -lsqlite3 if available, unless '--with-sqlite3=no'
2702HAVE_SQLITE3=no
2703if test "${with_sqlite3}" != "no"; then
2704   AC_CHECK_LIB(sqlite3, sqlite3_open_v2, HAVE_SQLITE3=yes, HAVE_SQLITE3=no)
2705   if test "$HAVE_SQLITE3" = "yes"; then
2706     SQLITE3_LIBS=-lsqlite3
2707     AC_SUBST(SQLITE3_LIBS)
2708     LIBS="$SQLITE3_LIBS $LIBS"
2709     AC_DEFINE(HAVE_SQLITE3, 1, [Define to 1 if you have the libsqlite3 library (-lsqlite).])
2710     # Windows loads libsqlite dynamically
2711     if test "${opsys}" = "mingw32"; then
2712        SQLITE3_LIBS=
2713     fi
2714     AC_CHECK_LIB(sqlite3, sqlite3_load_extension,
2715         HAVE_SQLITE3_LOAD_EXTENSION=yes, HAVE_SQLITE3_LOAD_EXTENSION=no)
2716     if test "$HAVE_SQLITE3_LOAD_EXTENSION" = "yes"; then
2717       AC_DEFINE(HAVE_SQLITE3_LOAD_EXTENSION, 1, [Define to 1 if sqlite3 supports loading extensions.])
2718     fi
2719   fi
2720fi
2721
2722HAVE_IMAGEMAGICK=no
2723if test "${HAVE_X11}" = "yes" || test "${HAVE_NS}" = "yes" || test "${HAVE_W32}" = "yes" || \
2724   test "${HAVE_BE_APP}" = "yes" || test "${window_system}" = "pgtk"; then
2725  if test "${with_imagemagick}" != "no"; then
2726    if test -n "$BREW"; then
2727      # Homebrew doesn't link ImageMagick 6 by default, so make sure
2728      # pkgconfig can find it.
2729      export PKG_CONFIG_PATH="$PKG_CONFIG_PATH$PATH_SEPARATOR`$BREW --prefix imagemagick@6 2>/dev/null`/lib/pkgconfig"
2730    fi
2731
2732    EMACS_CHECK_MODULES([IMAGEMAGICK], [MagickWand >= 7])
2733    if test $HAVE_IMAGEMAGICK = yes; then
2734       AC_DEFINE([HAVE_IMAGEMAGICK7], 1, [Define to 1 if using ImageMagick7.])
2735    else
2736       ## 6.3.5 is the earliest version known to work; see Bug#17339.
2737       ## 6.8.2 makes Emacs crash; see Bug#13867.
2738       EMACS_CHECK_MODULES([IMAGEMAGICK], [Wand >= 6.3.5 Wand != 6.8.2])
2739    fi
2740
2741    if test $HAVE_IMAGEMAGICK = yes; then
2742      OLD_CFLAGS=$CFLAGS
2743      OLD_LIBS=$LIBS
2744      CFLAGS="$CFLAGS $IMAGEMAGICK_CFLAGS"
2745      LIBS="$IMAGEMAGICK_LIBS $LIBS"
2746      AC_CHECK_FUNCS([MagickRelinquishMemory MagickExportImagePixels \
2747		      MagickMergeImageLayers MagickAutoOrientImage])
2748      CFLAGS=$OLD_CFLAGS
2749      LIBS=$OLD_LIBS
2750      # Check that ImageMagick links.  It does not link on Fedora 25
2751      # with './configure CC=clang', as pkg-config outputs flags like
2752      # -lomp that work for GCC but not Clang.
2753      if test "$ac_cv_func_MagickRelinquishMemory" != yes; then
2754	HAVE_IMAGEMAGICK=no
2755      fi
2756    fi
2757    if test $HAVE_IMAGEMAGICK = yes; then
2758      AC_DEFINE([HAVE_IMAGEMAGICK], 1, [Define to 1 if using ImageMagick.])
2759    else
2760      if test "${with_imagemagick}" != "no"; then
2761        AC_MSG_ERROR([ImageMagick wanted, but it does not compile.  Maybe some library files are missing?]);
2762      fi
2763      IMAGEMAGICK_CFLAGS=
2764      IMAGEMAGICK_LIBS=
2765    fi
2766    AC_SUBST([IMAGEMAGICK_CFLAGS])
2767    AC_SUBST([IMAGEMAGICK_LIBS])
2768  fi
2769fi
2770
2771AC_CHECK_LIB(anl, getaddrinfo_a, HAVE_GETADDRINFO_A=yes)
2772if test "${HAVE_GETADDRINFO_A}" = "yes"; then
2773  AC_DEFINE(HAVE_GETADDRINFO_A, 1,
2774[Define to 1 if you have getaddrinfo_a for asynchronous DNS resolution.])
2775  GETADDRINFO_A_LIBS="-lanl"
2776  AC_SUBST(GETADDRINFO_A_LIBS)
2777fi
2778
2779HAVE_GTK=no
2780GTK_OBJ=
2781gtk_term_header=$term_header
2782check_gtk2=no
2783gtk3_pkg_errors=
2784if test "${opsys}" != "mingw32"; then
2785  if test "${with_gtk3}" = "yes" || test "${with_gtk}" = "yes" || test "$USE_X_TOOLKIT" = "maybe"; then
2786    GLIB_REQUIRED=2.37.5
2787    GTK_REQUIRED=3.10
2788    GTK_MODULES="gtk+-3.0 >= $GTK_REQUIRED glib-2.0 >= $GLIB_REQUIRED"
2789
2790    dnl Checks for libraries.
2791    EMACS_CHECK_MODULES([GTK], [$GTK_MODULES],
2792      [pkg_check_gtk=yes], [pkg_check_gtk=no])
2793    if test "$pkg_check_gtk" = "no" && test "$with_gtk3" = "yes"; then
2794       AC_MSG_ERROR($GTK_PKG_ERRORS)
2795    fi
2796    if test "$pkg_check_gtk" = "yes"; then
2797       AC_DEFINE(HAVE_GTK3, 1, [Define to 1 if using GTK 3 or later.])
2798       GTK_OBJ=emacsgtkfixed.o
2799       gtk_term_header=gtkutil.h
2800       USE_GTK_TOOLKIT="GTK3"
2801       if test "x$ac_enable_gtk_deprecation_warnings" = x; then
2802	 AC_DEFINE([GDK_DISABLE_DEPRECATION_WARNINGS], [1],
2803	   [Define to 1 to disable GTK+/GDK deprecation warnings.])
2804	 AC_DEFINE([GLIB_DISABLE_DEPRECATION_WARNINGS], [1],
2805	   [Define to 1 to disable Glib deprecation warnings.])
2806       fi
2807       if test "$window_system" = pgtk; then
2808	  GLIB_GSETTINGS
2809       fi
2810    else
2811       check_gtk2=yes
2812       gtk3_pkg_errors="$GTK_PKG_ERRORS "
2813    fi
2814  fi
2815
2816  if test "${with_gtk2}" = "yes" || test "$check_gtk2" = "yes"; then
2817    GLIB_REQUIRED=2.28
2818    GTK_REQUIRED=2.24
2819    GTK_MODULES="gtk+-2.0 >= $GTK_REQUIRED glib-2.0 >= $GLIB_REQUIRED"
2820
2821    dnl Checks for libraries.
2822    EMACS_CHECK_MODULES([GTK], [$GTK_MODULES],
2823      [pkg_check_gtk=yes], [pkg_check_gtk=no])
2824    if test "$pkg_check_gtk" = "no" &&
2825       { test "$with_gtk" = yes || test "$with_gtk2" = "yes"; }
2826    then
2827      AC_MSG_ERROR($gtk3_pkg_errors$GTK_PKG_ERRORS)
2828    fi
2829    test "$pkg_check_gtk" = "yes" && USE_GTK_TOOLKIT="GTK2"
2830  fi
2831fi
2832
2833OLD_CFLAGS=$CFLAGS
2834OLD_LIBS=$LIBS
2835
2836if test x"$pkg_check_gtk" = xyes; then
2837
2838  AC_SUBST(GTK_LIBS)
2839  CFLAGS="$CFLAGS $GTK_CFLAGS"
2840  LIBS="$GTK_LIBS $LIBS"
2841  dnl Try to compile a simple GTK program.
2842  AC_CACHE_CHECK([whether GTK compiles], [emacs_cv_gtk_compiles],
2843  [AC_LINK_IFELSE(
2844    [AC_LANG_PROGRAM(
2845       [[/* Check the Gtk and Glib APIs.  */
2846	 #include <gtk/gtk.h>
2847	 #include <glib-object.h>
2848	 static void
2849	 callback (GObject *go, GParamSpec *spec, gpointer user_data)
2850	 {}
2851       ]],
2852       [[
2853	 GtkSettings *gs = 0;
2854	 /* Use G_CALLBACK to make sure function pointers can be cast to void *;
2855	    strict C prohibits this.  Use gtk_main_iteration to test that the
2856	    libraries are there.  */
2857	 if (g_signal_handler_find (G_OBJECT (gs), G_SIGNAL_MATCH_FUNC,
2858				    0, 0, 0, G_CALLBACK (callback), 0))
2859	   gtk_main_iteration ();
2860       ]])],
2861    [emacs_cv_gtk_compiles=yes], [emacs_cv_gtk_compiles=no])])
2862  if test "${emacs_cv_gtk_compiles}" != "yes"; then
2863    GTK_OBJ=
2864    if test "$USE_X_TOOLKIT" != "maybe"; then
2865      AC_MSG_ERROR([Gtk+ wanted, but it does not compile, see config.log.  Maybe some x11-devel files missing?]);
2866    fi
2867  else
2868    C_SWITCH_X_SITE="$C_SWITCH_X_SITE $GTK_CFLAGS"
2869    HAVE_GTK=yes
2870    AC_DEFINE(USE_GTK, 1, [Define to 1 if using GTK.])
2871    GTK_OBJ="gtkutil.o $GTK_OBJ"
2872    term_header=$gtk_term_header
2873    USE_X_TOOLKIT=none
2874    AC_MSG_WARN([[Your version of Gtk+ will have problems with
2875       closing open displays.  This is no problem if you just use
2876       one display, but if you use more than one and close one of them
2877       Emacs may crash.
2878       See https://gitlab.gnome.org/GNOME/gtk/issues/221]])
2879  fi
2880
2881fi
2882AC_SUBST(GTK_OBJ)
2883
2884
2885if test "${HAVE_GTK}" = "yes"; then
2886
2887  dnl  GTK scrollbars resemble toolkit scrollbars a lot, so to avoid
2888  dnl  a lot if #ifdef:s, say we have toolkit scrollbars.
2889  if test "$with_toolkit_scroll_bars" != no; then
2890    with_toolkit_scroll_bars=yes
2891  fi
2892
2893  term_header=gtkutil.h
2894
2895  if test "${USE_GTK_TOOLKIT}" = GTK2; then
2896
2897    dnl  Check if we have the old file selection dialog declared and
2898    dnl  in the link library.  In 2.x it may be in the library,
2899    dnl  but not declared if deprecated featured has been selected out.
2900    dnl  AC_CHECK_DECL checks for a macro, so check for GTK_TYPE_FILE_SELECTION.
2901    HAVE_GTK_FILE_SELECTION=no
2902    AC_CHECK_DECL(GTK_TYPE_FILE_SELECTION, HAVE_GTK_FILE_SELECTION=yes,
2903                     HAVE_GTK_FILE_SELECTION=no, [AC_INCLUDES_DEFAULT
2904#include <gtk/gtk.h>])
2905    if test "$HAVE_GTK_FILE_SELECTION" = yes; then
2906      AC_CHECK_FUNCS(gtk_file_selection_new)
2907    fi
2908
2909    dnl This procedure causes a bug on certain Ubuntu GTK+2 builds
2910    AC_CHECK_FUNCS(gtk_window_set_has_resize_grip)
2911  fi
2912fi
2913
2914
2915dnl Enable xwidgets if GTK3 and WebKitGTK+ are available.
2916dnl Enable xwidgets if macOS Cocoa and WebKit framework are available.
2917HAVE_XWIDGETS=no
2918XWIDGETS_OBJ=
2919if test "$with_xwidgets" != "no"; then
2920  if test "$USE_GTK_TOOLKIT" = "GTK3" && test "$window_system" != "none"; then
2921    WEBKIT_REQUIRED=2.12
2922    WEBKIT_MODULES="webkit2gtk-4.0 >= $WEBKIT_REQUIRED"
2923    EMACS_CHECK_MODULES([WEBKIT], [$WEBKIT_MODULES])
2924    HAVE_XWIDGETS=$HAVE_WEBKIT
2925    XWIDGETS_OBJ="xwidget.o"
2926  elif test "${NS_IMPL_COCOA}" = "yes"; then
2927    dnl FIXME: Check framework WebKit2
2928    dnl WEBKIT_REQUIRED=M.m.p
2929    WEBKIT_LIBS="-Wl,-framework -Wl,WebKit"
2930    WEBKIT_CFLAGS="-I/System/Library/Frameworks/WebKit.framework/Headers"
2931    HAVE_WEBKIT="yes"
2932    HAVE_XWIDGETS=$HAVE_WEBKIT
2933    XWIDGETS_OBJ="xwidget.o"
2934    NS_OBJC_OBJ="$NS_OBJC_OBJ nsxwidget.o"
2935    dnl Update NS_OBJC_OBJ with added nsxwidget.o
2936    AC_SUBST(NS_OBJC_OBJ)
2937  else
2938    AC_MSG_ERROR([xwidgets requested, it requires GTK3 as X window toolkit or macOS Cocoa as window system.])
2939  fi
2940
2941  test $HAVE_XWIDGETS = yes ||
2942    AC_MSG_ERROR([xwidgets requested but WebKitGTK+ or WebKit framework not found.])
2943
2944  AC_DEFINE([HAVE_XWIDGETS], 1, [Define to 1 if you have xwidgets support.])
2945fi
2946AC_SUBST(XWIDGETS_OBJ)
2947
2948CFLAGS=$OLD_CFLAGS
2949LIBS=$OLD_LIBS
2950
2951PGTK_OBJ=
2952PGTK_LIBS=
2953if test "$window_system" = "pgtk"; then
2954  PGTK_OBJ="pgtkfns.o pgtkterm.o pgtkselect.o pgtkmenu.o pgtkim.o xsettings.o"
2955  PGTK_LIBS="$GTK_LIBS"
2956fi
2957AC_SUBST(PGTK_OBJ)
2958AC_SUBST(PGTK_LIBS)
2959
2960dnl D-Bus has been tested under GNU/Linux only.  Must be adapted for
2961dnl other platforms.
2962HAVE_DBUS=no
2963DBUS_OBJ=
2964if test "${with_dbus}" = "yes"; then
2965   EMACS_CHECK_MODULES([DBUS], [dbus-1 >= 1.0])
2966   if test "$HAVE_DBUS" = yes; then
2967     AC_DEFINE(HAVE_DBUS, 1, [Define to 1 if using D-Bus.])
2968     dnl dbus_watch_get_unix_fd has been introduced in D-Bus 1.1.1.
2969     dnl dbus_type_is_valid and dbus_validate_* have been introduced in
2970     dnl D-Bus 1.5.12.
2971     OLD_LIBS=$LIBS
2972     LIBS="$LIBS $DBUS_LIBS"
2973     AC_CHECK_FUNCS(dbus_watch_get_unix_fd \
2974		    dbus_type_is_valid \
2975		    dbus_validate_bus_name \
2976                    dbus_validate_path \
2977		    dbus_validate_interface \
2978		    dbus_validate_member)
2979     LIBS=$OLD_LIBS
2980     DBUS_OBJ=dbusbind.o
2981   fi
2982fi
2983AC_SUBST(DBUS_CFLAGS)
2984AC_SUBST(DBUS_LIBS)
2985AC_SUBST(DBUS_OBJ)
2986
2987dnl GSettings has been tested under GNU/Linux only.
2988HAVE_GSETTINGS=no
2989if test "${HAVE_X11}" = "yes" -o "${window_system}" = "pgtk" && test "${with_gsettings}" = "yes"; then
2990   EMACS_CHECK_MODULES([GSETTINGS], [gio-2.0 >= 2.26])
2991   if test "$HAVE_GSETTINGS" = "yes"; then
2992      old_CFLAGS=$CFLAGS
2993      CFLAGS="$CFLAGS $GSETTINGS_CFLAGS"
2994      old_LIBS=$LIBS
2995      LIBS="$LIBS $GSETTINGS_LIBS"
2996      AC_CACHE_CHECK([whether GSettings is in gio], [emacs_cv_gsettings_in_gio],
2997      [AC_LINK_IFELSE(
2998         [AC_LANG_PROGRAM(
2999	     [[/* Check that gsettings really is present.  */
3000	     #include <glib-object.h>
3001	     #include <gio/gio.h>
3002	     ]],
3003	     [[
3004	       GSettings *settings;
3005	       GVariant *val = g_settings_get_value (settings, "");
3006	     ]])],
3007       [emacs_cv_gsettings_in_gio=yes], [emacs_cv_gsettings_in_gio=no])])
3008
3009      if test "$emacs_cv_gsettings_in_gio" = "yes"; then
3010        AC_DEFINE(HAVE_GSETTINGS, 1, [Define to 1 if using GSettings.])
3011	SETTINGS_CFLAGS="$GSETTINGS_CFLAGS"
3012	SETTINGS_LIBS="$GSETTINGS_LIBS"
3013	test "$with_gconf" = "yes" || with_gconf=no
3014      fi
3015      CFLAGS=$old_CFLAGS
3016      LIBS=$old_LIBS
3017   fi
3018fi
3019
3020dnl GConf has been tested under GNU/Linux only.
3021dnl The version is really arbitrary, it is about the same age as Gtk+ 2.6.
3022HAVE_GCONF=no
3023if test "${HAVE_X11}" = "yes" -o "${window_system}" = "pgtk" && test "${with_gconf}" != "no"; then
3024   EMACS_CHECK_MODULES([GCONF], [gconf-2.0 >= 2.13])
3025   if test "$HAVE_GCONF" = yes; then
3026      AC_DEFINE(HAVE_GCONF, 1, [Define to 1 if using GConf.])
3027      dnl Newer GConf doesn't link with g_objects, so this is not defined.
3028      SETTINGS_CFLAGS="$SETTINGS_CFLAGS $GCONF_CFLAGS"
3029      SETTINGS_LIBS="$SETTINGS_LIBS $GCONF_LIBS"
3030   fi
3031fi
3032
3033if test "$HAVE_GSETTINGS" = "yes" || test "$HAVE_GCONF" = "yes"; then
3034    EMACS_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.0])
3035    if test "$HAVE_GOBJECT" = "yes"; then
3036       SETTINGS_CFLAGS="$SETTINGS_CFLAGS $GOBJECT_CFLAGS"
3037       SETTINGS_LIBS="$SETTINGS_LIBS $GOBJECT_LIBS"
3038    fi
3039    SAVE_CFLAGS="$CFLAGS"
3040    SAVE_LIBS="$LIBS"
3041    CFLAGS="$SETTINGS_CFLAGS $CFLAGS"
3042    LIBS="$SETTINGS_LIBS $LIBS"
3043    CFLAGS="$SAVE_CFLAGS"
3044    LIBS="$SAVE_LIBS"
3045fi
3046AC_SUBST(SETTINGS_CFLAGS)
3047AC_SUBST(SETTINGS_LIBS)
3048
3049USE_STARTUP_NOTIFICATION=no
3050if test "${HAVE_GTK}" = "yes"; then
3051    USE_STARTUP_NOTIFICATION=yes
3052fi
3053AC_SUBST(USE_STARTUP_NOTIFICATION)
3054
3055dnl SELinux is available for GNU/Linux only.
3056HAVE_LIBSELINUX=no
3057LIBSELINUX_LIBS=
3058if test "${with_selinux}" = "yes"; then
3059   AC_CHECK_LIB([selinux], [lgetfilecon], HAVE_LIBSELINUX=yes, HAVE_LIBSELINUX=no)
3060   if test "$HAVE_LIBSELINUX" = yes; then
3061      AC_DEFINE(HAVE_LIBSELINUX, 1, [Define to 1 if using SELinux.])
3062      LIBSELINUX_LIBS=-lselinux
3063   fi
3064fi
3065AC_SUBST(LIBSELINUX_LIBS)
3066
3067HAVE_GNUTLS=no
3068if test "${with_gnutls}" != "no" ; then
3069  EMACS_CHECK_MODULES([LIBGNUTLS], [gnutls >= 2.12.2],
3070    [HAVE_GNUTLS=yes], [HAVE_GNUTLS=no])
3071  if test "${HAVE_GNUTLS}" = "yes"; then
3072    AC_DEFINE(HAVE_GNUTLS, 1, [Define if using GnuTLS.])
3073  fi
3074
3075  # Windows loads GnuTLS dynamically
3076  if test "${opsys}" = "mingw32"; then
3077    LIBGNUTLS_LIBS=
3078  fi
3079fi
3080
3081AC_SUBST(LIBGNUTLS_LIBS)
3082AC_SUBST(LIBGNUTLS_CFLAGS)
3083
3084HAVE_LIBSYSTEMD=no
3085if test "${with_libsystemd}" = "yes" ; then
3086  dnl This code has been tested with libsystemd 222 and later.
3087  dnl FIXME: Find the earliest version number for which Emacs should work,
3088  dnl and change '222' to that number.
3089  EMACS_CHECK_MODULES([LIBSYSTEMD], [libsystemd >= 222],
3090    [HAVE_LIBSYSTEMD=yes], [HAVE_LIBSYSTEMD=no])
3091  if test "${HAVE_LIBSYSTEMD}" = "yes"; then
3092    AC_DEFINE(HAVE_LIBSYSTEMD, 1, [Define if using libsystemd.])
3093  fi
3094fi
3095
3096AC_SUBST(LIBSYSTEMD_LIBS)
3097AC_SUBST(LIBSYSTEMD_CFLAGS)
3098
3099HAVE_JSON=no
3100JSON_OBJ=
3101
3102if test "${with_json}" != no; then
3103  EMACS_CHECK_MODULES([JSON], [jansson >= 2.7],
3104    [HAVE_JSON=yes], [HAVE_JSON=no])
3105  if test "${HAVE_JSON}" = yes; then
3106    AC_DEFINE(HAVE_JSON, 1, [Define if using Jansson.])
3107    JSON_OBJ=json.o
3108  fi
3109
3110  # Windows loads libjansson dynamically
3111  if test "${opsys}" = "mingw32"; then
3112    JSON_LIBS=
3113  fi
3114fi
3115
3116AC_SUBST(JSON_LIBS)
3117AC_SUBST(JSON_CFLAGS)
3118AC_SUBST(JSON_OBJ)
3119
3120NOTIFY_OBJ=
3121NOTIFY_SUMMARY=no
3122
3123dnl MS Windows native file monitor is available for mingw32 only.
3124case $with_file_notification,$opsys in
3125  w32,cygwin)
3126    AC_MSG_ERROR(['--with-file-notification=w32' was specified, but
3127    this is only supported on MS-Windows native and MinGW32 builds.
3128    Consider using gfile instead.])
3129    ;;
3130  w32,* | yes,mingw32)
3131    AC_CHECK_HEADER(windows.h)
3132    if test "$ac_cv_header_windows_h" = yes ; then
3133       AC_DEFINE(HAVE_W32NOTIFY, 1, [Define to 1 to use w32notify.])
3134       NOTIFY_OBJ=w32notify.o
3135       NOTIFY_SUMMARY="yes (w32)"
3136    fi ;;
3137esac
3138
3139dnl inotify is available only on GNU/Linux.
3140case $with_file_notification,$NOTIFY_OBJ in
3141  inotify, | yes,)
3142    AC_CHECK_HEADER(sys/inotify.h)
3143    if test "$ac_cv_header_sys_inotify_h" = yes ; then
3144	AC_CHECK_FUNC(inotify_init1)
3145	if test "$ac_cv_func_inotify_init1" = yes; then
3146	  AC_DEFINE(HAVE_INOTIFY, 1, [Define to 1 to use inotify.])
3147	  NOTIFY_OBJ=inotify.o
3148	  NOTIFY_SUMMARY="yes -lglibc (inotify)"
3149       fi
3150    fi ;;
3151esac
3152
3153dnl kqueue is available on BSD-like systems.
3154case $with_file_notification,$NOTIFY_OBJ in
3155  kqueue,* | yes,)
3156    EMACS_CHECK_MODULES([KQUEUE], [libkqueue])
3157    if test "$HAVE_KQUEUE" = "yes"; then
3158       AC_DEFINE(HAVE_KQUEUE, 1, [Define to 1 to use kqueue.])
3159       CPPFLAGS="$CPPFLAGS -I/usr/include/kqueue"
3160       NOTIFY_CFLAGS=$KQUEUE_CFLAGS
3161       NOTIFY_LIBS=$KQUEUE_LIBS
3162       NOTIFY_OBJ=kqueue.o
3163       NOTIFY_SUMMARY="yes -lkqueue"
3164    else
3165       AC_SEARCH_LIBS(kqueue, [])
3166       if test "$ac_cv_search_kqueue" != no; then
3167         AC_DEFINE(HAVE_KQUEUE, 1, [Define to 1 to use kqueue.])
3168	 NOTIFY_OBJ=kqueue.o
3169	 NOTIFY_SUMMARY="yes (kqueue)"
3170       fi
3171    fi ;;
3172esac
3173
3174dnl g_file_monitor exists since glib 2.18.  G_FILE_MONITOR_EVENT_MOVED
3175dnl has been added in glib 2.24.  It has been tested under
3176dnl GNU/Linux only.
3177case $with_file_notification,$NOTIFY_OBJ in
3178  gfile,* | yes,)
3179    if test "${HAVE_NS}" = yes; then
3180       AC_MSG_ERROR(['--with-file-notification=gfile' is not supported in NextStep builds.
3181Consider kqueue instead.])
3182    else
3183       EMACS_CHECK_MODULES([GFILENOTIFY], [gio-2.0 >= 2.24])
3184       if test "$HAVE_GFILENOTIFY" = "yes"; then
3185	  AC_DEFINE(HAVE_GFILENOTIFY, 1, [Define to 1 if using GFile.])
3186	  NOTIFY_CFLAGS=$GFILENOTIFY_CFLAGS
3187	  NOTIFY_LIBS=$GFILENOTIFY_LIBS
3188	  NOTIFY_OBJ=gfilenotify.o
3189	  NOTIFY_SUMMARY="yes -lgio (gfile)"
3190       fi
3191    fi ;;
3192esac
3193
3194case $with_file_notification,$NOTIFY_OBJ in
3195  yes,* | no,* | *,?*) ;;
3196  *) AC_MSG_ERROR([File notification '$with_file_notification' requested but requirements not found.]) ;;
3197esac
3198
3199if test -n "$NOTIFY_OBJ"; then
3200   AC_DEFINE(USE_FILE_NOTIFY, 1, [Define to 1 if using file notifications.])
3201fi
3202AC_SUBST(NOTIFY_CFLAGS)
3203AC_SUBST(NOTIFY_LIBS)
3204AC_SUBST(NOTIFY_OBJ)
3205
3206dnl Do not put whitespace before the #include statements below.
3207dnl Older compilers (eg sunos4 cc) choke on it.
3208HAVE_XAW3D=no
3209LUCID_LIBW=
3210if test x"${USE_X_TOOLKIT}" = xmaybe || test x"${USE_X_TOOLKIT}" = xLUCID; then
3211  if test "$with_xaw3d" != no; then
3212    AC_CACHE_VAL(emacs_cv_xaw3d,
3213    [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
3214#include <X11/Intrinsic.h>
3215#include <X11/Xaw3d/Simple.h>]],
3216      [[]])],
3217      [AC_CHECK_LIB(Xaw3d, XawScrollbarSetThumb,
3218                    emacs_cv_xaw3d=yes, emacs_cv_xaw3d=no)],
3219      emacs_cv_xaw3d=no)])
3220  else
3221    emacs_cv_xaw3d=no
3222  fi
3223  if test $emacs_cv_xaw3d = yes; then
3224    AC_MSG_CHECKING(for xaw3d)
3225    AC_MSG_RESULT([yes; using Lucid toolkit])
3226    USE_X_TOOLKIT=LUCID
3227    HAVE_XAW3D=yes
3228    LUCID_LIBW=-lXaw3d
3229    AC_DEFINE(HAVE_XAW3D, 1,
3230              [Define to 1 if you have the Xaw3d library (-lXaw3d).])
3231  else
3232    AC_MSG_CHECKING(for xaw3d)
3233    AC_MSG_RESULT(no)
3234    AC_MSG_CHECKING(for libXaw)
3235    AC_CACHE_VAL(emacs_cv_xaw,
3236    [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
3237#include <X11/Intrinsic.h>
3238#include <X11/Xaw/Simple.h>]],
3239      [[]])],
3240      emacs_cv_xaw=yes,
3241      emacs_cv_xaw=no)])
3242    if test $emacs_cv_xaw = yes; then
3243      AC_MSG_RESULT([yes; using Lucid toolkit])
3244      USE_X_TOOLKIT=LUCID
3245      LUCID_LIBW=-lXaw
3246    elif test x"${USE_X_TOOLKIT}" = xLUCID; then
3247      AC_MSG_ERROR([Lucid toolkit requires X11/Xaw include files])
3248    else
3249      AC_MSG_ERROR([No X toolkit could be found.
3250If you are sure you want Emacs compiled without an X toolkit, pass
3251  --with-x-toolkit=no
3252to configure.  Otherwise, install the development libraries for the toolkit
3253that you want to use (e.g. Gtk+) and re-run configure.])
3254    fi
3255  fi
3256fi
3257
3258X_TOOLKIT_TYPE=$USE_X_TOOLKIT
3259
3260LIBXTR6=
3261LIBXMU=
3262if test "${USE_X_TOOLKIT}" != "none"; then
3263  AC_MSG_CHECKING(X11 toolkit version)
3264  AC_CACHE_VAL(emacs_cv_x11_toolkit_version_6,
3265  [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <X11/Intrinsic.h>]],
3266[[#if XtSpecificationRelease < 6
3267fail;
3268#endif
3269]])], emacs_cv_x11_toolkit_version_6=yes, emacs_cv_x11_toolkit_version_6=no)])
3270  HAVE_X11XTR6=$emacs_cv_x11_toolkit_version_6
3271  if test $emacs_cv_x11_toolkit_version_6 = yes; then
3272    AC_MSG_RESULT(6 or newer)
3273    AC_DEFINE(HAVE_X11XTR6, 1,
3274	      [Define to 1 if you have the X11R6 or newer version of Xt.])
3275    LIBXTR6="-lSM -lICE"
3276    case "$opsys" in
3277      ## Use libw.a along with X11R6 Xt.
3278      unixware) LIBXTR6="$LIBXTR6 -lw" ;;
3279    esac
3280  else
3281    AC_MSG_RESULT(before 6)
3282  fi
3283
3284dnl If using toolkit, check whether libXmu.a exists.
3285dnl tranle@intellicorp.com says libXmu.a can need XtMalloc in libXt.a to link.
3286  OLDLIBS="$LIBS"
3287  if test x$HAVE_X11XTR6 = xyes; then
3288    OTHERLIBS='-lXt -lSM -lICE'
3289  else
3290    OTHERLIBS='-lXt'
3291  fi
3292  AC_SEARCH_LIBS([XmuConvertStandardSelection], [Xmu], [], [], [$OTHERLIBS])
3293  if test "X$LIBS" != "X$OLDLIBS"; then
3294    LIBXMU=$ac_cv_search_XmuConvertStandardSelection
3295  fi
3296  LIBS=$OLDLIBS
3297  dnl ac_cv_search_XmuConvertStandardSelection is also referenced below.
3298fi
3299AC_SUBST(LIBXTR6)
3300AC_SUBST(LIBXMU)
3301
3302LIBXP=
3303if test "${USE_X_TOOLKIT}" = "MOTIF"; then
3304  # OpenMotif may be installed in such a way on some GNU/Linux systems.
3305  if test -d /usr/include/openmotif; then
3306    CPPFLAGS="-I/usr/include/openmotif $CPPFLAGS"
3307    emacs_cv_openmotif=yes
3308    case "$canonical" in
3309      x86_64-*-linux-gnu* | powerpc64-*-linux-gnu* | sparc64-*-linux-gnu*)
3310      test -d /usr/lib64/openmotif && LDFLAGS="-L/usr/lib64/openmotif $LDFLAGS"
3311      ;;
3312      *)
3313      test -d /usr/lib/openmotif && LDFLAGS="-L/usr/lib/openmotif $LDFLAGS"
3314    esac
3315  else
3316    emacs_cv_openmotif=no
3317  fi
3318  AC_CACHE_CHECK(for (Open)Motif version 2.1, emacs_cv_motif_version_2_1,
3319  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <Xm/Xm.h>]],
3320    [[#if XmVERSION > 2 || (XmVERSION == 2 && XmREVISION >= 1)
3321int x = 5;
3322#else
3323Motif version prior to 2.1.
3324#endif]])],
3325    emacs_cv_motif_version_2_1=yes, emacs_cv_motif_version_2_1=no)])
3326  if test $emacs_cv_motif_version_2_1 = yes; then
3327    AC_CHECK_LIB(Xp, XpCreateContext, LIBXP=-lXp)
3328    if test x$emacs_cv_openmotif = xyes; then
3329      REAL_CPPFLAGS="-I/usr/include/openmotif $REAL_CPPFLAGS"
3330    fi
3331  else
3332    AC_CACHE_CHECK(for LessTif where some systems put it, emacs_cv_lesstif,
3333    # We put this in CFLAGS temporarily to precede other -I options
3334    # that might be in CFLAGS temporarily.
3335    # We put this in CPPFLAGS where it precedes the other -I options.
3336    OLD_CPPFLAGS=$CPPFLAGS
3337    OLD_CFLAGS=$CFLAGS
3338    CPPFLAGS="-I/usr/X11R6/LessTif/Motif1.2/include $CPPFLAGS"
3339    CFLAGS="-I/usr/X11R6/LessTif/Motif1.2/include $CFLAGS"
3340    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include </usr/X11R6/LessTif/Motif1.2/include/Xm/Xm.h>]],
3341      [[int x = 5;]])],
3342      emacs_cv_lesstif=yes, emacs_cv_lesstif=no)])
3343    if test $emacs_cv_lesstif = yes; then
3344      # Make sure this -I option remains in CPPFLAGS after it is set
3345      # back to REAL_CPPFLAGS.
3346      # There is no need to change REAL_CFLAGS, because REAL_CFLAGS does not
3347      # have those other -I options anyway.  Ultimately, having this
3348      # directory ultimately in CPPFLAGS will be enough.
3349      REAL_CPPFLAGS="-I/usr/X11R6/LessTif/Motif1.2/include $REAL_CPPFLAGS"
3350      LDFLAGS="-L/usr/X11R6/LessTif/Motif1.2/lib $LDFLAGS"
3351    else
3352      CFLAGS=$OLD_CFLAGS
3353      CPPFLAGS=$OLD_CPPFLAGS
3354    fi
3355  fi
3356  AC_CHECK_HEADER([Xm/BulletinB.h], [],
3357    [AC_MSG_ERROR([Motif toolkit requested but requirements not found.])])
3358fi
3359
3360dnl Use toolkit scroll bars if configured for GTK or X toolkit and either
3361dnl using Motif or Xaw3d is available, and unless
3362dnl --with-toolkit-scroll-bars=no was specified.
3363
3364AH_TEMPLATE(USE_TOOLKIT_SCROLL_BARS,
3365	    [Define to 1 if we should use toolkit scroll bars.])dnl
3366USE_TOOLKIT_SCROLL_BARS=no
3367if test "${with_toolkit_scroll_bars}" != "no"; then
3368  if test "${USE_X_TOOLKIT}" != "none"; then
3369    if test "${USE_X_TOOLKIT}" = "MOTIF"; then
3370      AC_DEFINE(USE_TOOLKIT_SCROLL_BARS)
3371      HAVE_XAW3D=no
3372      USE_TOOLKIT_SCROLL_BARS=yes
3373    elif test "${HAVE_XAW3D}" = "yes" || test "${USE_X_TOOLKIT}" = "LUCID"; then
3374      AC_DEFINE(USE_TOOLKIT_SCROLL_BARS)
3375      USE_TOOLKIT_SCROLL_BARS=yes
3376    fi
3377  elif test "${HAVE_GTK}" = "yes"; then
3378    AC_DEFINE(USE_TOOLKIT_SCROLL_BARS)
3379    USE_TOOLKIT_SCROLL_BARS=yes
3380  elif test "${HAVE_NS}" = "yes"; then
3381    AC_DEFINE(USE_TOOLKIT_SCROLL_BARS)
3382    USE_TOOLKIT_SCROLL_BARS=yes
3383  elif test "${HAVE_W32}" = "yes"; then
3384    AC_DEFINE(USE_TOOLKIT_SCROLL_BARS)
3385    USE_TOOLKIT_SCROLL_BARS=yes
3386  elif test "${HAVE_BE_APP}" = "yes"; then
3387    AC_DEFINE(USE_TOOLKIT_SCROLL_BARS)
3388    USE_TOOLKIT_SCROLL_BARS=yes
3389  fi
3390fi
3391
3392dnl See if XIM is available.
3393AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3394	  #include <X11/Xlib.h>
3395	  #include <X11/Xresource.h>]],
3396	 [[XIMProc  callback;]])],
3397	 [HAVE_XIM=yes
3398	 AC_DEFINE(HAVE_XIM, 1, [Define to 1 if XIM is available])],
3399	 HAVE_XIM=no)
3400
3401dnl Note this is non-standard.  --with-xim does not control whether
3402dnl XIM support is compiled in, it only affects the runtime default of
3403dnl use_xim in xterm.c.
3404if test "${with_xim}" != "no"; then
3405  AC_DEFINE(USE_XIM, 1,
3406	    [Define to 1 to default runtime use of XIM to on.])
3407fi
3408
3409
3410if test "${HAVE_XIM}" != "no"; then
3411  late_CFLAGS=$CFLAGS
3412  if test "$GCC" = yes; then
3413    CFLAGS="$CFLAGS --pedantic-errors"
3414  fi
3415  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3416#include <X11/Xlib.h>
3417#include <X11/Xresource.h>]],
3418[[Display *display;
3419XrmDatabase db;
3420char *res_name;
3421char *res_class;
3422XIMProc  callback;
3423XPointer *client_data;
3424#ifndef __GNUC__
3425/* If we're not using GCC, it's probably not XFree86, and this is
3426   probably right, but we can't use something like --pedantic-errors.  */
3427extern Bool XRegisterIMInstantiateCallback(Display*, XrmDatabase, char*,
3428                                           char*, XIMProc, XPointer*);
3429#endif
3430(void)XRegisterIMInstantiateCallback(display, db, res_name, res_class, callback,
3431   client_data);]])],
3432    [emacs_cv_arg6_star=yes])
3433  AH_TEMPLATE(XRegisterIMInstantiateCallback_arg6,
3434         [Define to the type of the 6th arg of XRegisterIMInstantiateCallback,
3435either XPointer or XPointer*.])dnl
3436  if test "$emacs_cv_arg6_star" = yes; then
3437    AC_DEFINE(XRegisterIMInstantiateCallback_arg6, [XPointer*])
3438  else
3439    AC_DEFINE(XRegisterIMInstantiateCallback_arg6, [XPointer])
3440  fi
3441  CFLAGS=$late_CFLAGS
3442fi
3443
3444# Check for XRender
3445HAVE_XRENDER=no
3446if test "${HAVE_X11}" = "yes"; then
3447  AC_COMPILE_IFELSE(
3448    [AC_LANG_PROGRAM(
3449       [[#include <X11/Intrinsic.h>
3450	 #include <X11/extensions/Xrender.h>
3451       ]],
3452       [[return !XRenderQueryExtension;]])],
3453    [AC_CHECK_LIB([Xrender], [XRenderQueryExtension], [HAVE_XRENDER=yes])])
3454  if test $HAVE_XRENDER = yes; then
3455    XRENDER_LIBS="-lXrender"
3456    AC_SUBST(XRENDER_LIBS)
3457    AC_DEFINE([HAVE_XRENDER], 1, [Define to 1 if XRender is available.])
3458  fi
3459fi
3460
3461HAVE_CAIRO=no
3462if test "${HAVE_X11}" = "yes"; then
3463  if test "${with_cairo}" != "no"; then
3464    CAIRO_REQUIRED=1.8.0
3465    CAIRO_MODULE="cairo >= $CAIRO_REQUIRED"
3466    EMACS_CHECK_MODULES(CAIRO, $CAIRO_MODULE)
3467    if test $HAVE_CAIRO = yes; then
3468      AC_DEFINE(USE_CAIRO, 1, [Define to 1 if using cairo.])
3469      CFLAGS="$CFLAGS $CAIRO_CFLAGS"
3470      LIBS="$LIBS $CAIRO_LIBS"
3471      AC_SUBST(CAIRO_CFLAGS)
3472      AC_SUBST(CAIRO_LIBS)
3473    else
3474      AC_MSG_WARN([cairo requested but not found.])
3475    fi
3476  fi
3477fi
3478
3479if test "$window_system" = "pgtk"; then
3480  CAIRO_REQUIRED=1.12.0
3481  CAIRO_MODULE="cairo >= $CAIRO_REQUIRED"
3482  EMACS_CHECK_MODULES(CAIRO, $CAIRO_MODULE)
3483  if test $HAVE_CAIRO = yes; then
3484    AC_DEFINE(USE_CAIRO, 1, [Define to 1 if using cairo.])
3485  else
3486    AC_MSG_ERROR([cairo required but not found.])
3487  fi
3488
3489  CFLAGS="$CFLAGS $CAIRO_CFLAGS"
3490  LIBS="$LIBS $CAIRO_LIBS"
3491  AC_SUBST(CAIRO_CFLAGS)
3492  AC_SUBST(CAIRO_LIBS)
3493fi
3494
3495if test "${HAVE_BE_APP}" = "yes"; then
3496  if test "${with_be_cairo}" != "no"; then
3497    CAIRO_REQUIRED=1.8.0
3498    CAIRO_MODULE="cairo >= $CAIRO_REQUIRED"
3499    EMACS_CHECK_MODULES(CAIRO, $CAIRO_MODULE)
3500    if test $HAVE_CAIRO = yes; then
3501      AC_DEFINE(USE_BE_CAIRO, 1, [Define to 1 if using cairo on Haiku.])
3502      CFLAGS="$CFLAGS $CAIRO_CFLAGS"
3503      LIBS="$LIBS $CAIRO_LIBS"
3504      AC_SUBST(CAIRO_CFLAGS)
3505      AC_SUBST(CAIRO_LIBS)
3506    else
3507      AC_MSG_WARN([cairo requested but not found.])
3508    fi
3509  fi
3510fi
3511
3512### Start of font-backend (under any platform) section.
3513# (nothing here yet -- this is a placeholder)
3514### End of font-backend (under any platform) section.
3515
3516### Start of font-backend (under X11) section.
3517if test "${HAVE_X11}" = "yes"; then
3518  if test $HAVE_CAIRO = yes; then
3519    dnl Strict linkers fail with
3520    dnl ftfont.o: undefined reference to symbol 'FT_New_Face'
3521    dnl if -lfreetype is not specified.
3522    dnl The following is needed to set FREETYPE_LIBS.
3523    EMACS_CHECK_MODULES([FREETYPE], [freetype2])
3524
3525    test "$HAVE_FREETYPE" = "no" && AC_MSG_ERROR(cairo requires libfreetype)
3526
3527    EMACS_CHECK_MODULES([FONTCONFIG], [fontconfig >= 2.2.0])
3528
3529    test "$HAVE_FONTCONFIG" = "no" && AC_MSG_ERROR(cairo requires libfontconfig)
3530    dnl For the "Does Emacs use" message at the end.
3531    HAVE_XFT=no
3532  else
3533    ## Use -lXft if available, unless '--with-xft=no'.
3534    HAVE_XFT=maybe
3535    if test "x${with_x}" = "xno"; then
3536      with_xft="no";
3537    fi
3538
3539    if test "$with_xft" != no; then
3540      EMACS_CHECK_MODULES([FONTCONFIG], [fontconfig >= 2.2.0])
3541      with_xft=$HAVE_FONTCONFIG
3542    fi
3543
3544    if test "x${with_xft}" != "xno"; then
3545
3546      EMACS_CHECK_MODULES([XFT], [xft >= 0.13.0], [], [HAVE_XFT=no])
3547      ## Because xterm.c uses XRenderQueryExtension when XFT is
3548      ## enabled, we also need to link to -lXrender.
3549      if test "$HAVE_XFT" != no && test "$HAVE_XRENDER" != no; then
3550	OLD_CPPFLAGS="$CPPFLAGS"
3551	OLD_CFLAGS="$CFLAGS"
3552	OLD_LIBS="$LIBS"
3553	CPPFLAGS="$CPPFLAGS $XFT_CFLAGS"
3554	CFLAGS="$CFLAGS $XFT_CFLAGS"
3555	LIBS="$XFT_LIBS $LIBS"
3556	AC_CHECK_HEADER(X11/Xft/Xft.h,
3557	  AC_CHECK_LIB(Xft, XftFontOpen, HAVE_XFT=yes, , $XFT_LIBS) , ,
3558          [[#include <X11/X.h>]])
3559
3560	if test "${HAVE_XFT}" = "yes"; then
3561	  AC_DEFINE(HAVE_XFT, 1, [Define to 1 if you have the Xft library.])
3562	    AC_SUBST(XFT_LIBS)
3563	  C_SWITCH_X_SITE="$C_SWITCH_X_SITE $XFT_CFLAGS"
3564	fi                        # "${HAVE_XFT}" = "yes"
3565	CPPFLAGS=$OLD_CPPFLAGS
3566	CFLAGS=$OLD_CFLAGS
3567	LIBS=$OLD_LIBS
3568      else
3569      # Make sure XFT is disabled if we found XFT but not XRender
3570	HAVE_XFT=no
3571      fi                          # "$HAVE_XFT" != no
3572    fi                            # "x${with_xft}" != "xno"
3573
3574    if test "$HAVE_XFT" != "yes"; then
3575       dnl For the "Does Emacs use" message at the end.
3576       HAVE_XFT=no
3577       HAVE_FREETYPE=no
3578    else
3579       dnl Strict linkers fail with
3580       dnl ftfont.o: undefined reference to symbol 'FT_New_Face'
3581       dnl if -lfreetype is not specified.
3582       dnl The following is needed to set FREETYPE_LIBS.
3583       EMACS_CHECK_MODULES([FREETYPE], [freetype2])
3584
3585       test "$HAVE_FREETYPE" = "no" && AC_MSG_ERROR(libxft requires libfreetype)
3586    fi
3587  fi				  # $HAVE_CAIRO != yes
3588
3589  HAVE_LIBOTF=no
3590  if test "${HAVE_FREETYPE}" = "yes"; then
3591    AC_DEFINE(HAVE_FREETYPE, 1,
3592	      [Define to 1 if using the freetype and fontconfig libraries.])
3593    OLD_CFLAGS=$CFLAGS
3594    OLD_LIBS=$LIBS
3595    CFLAGS="$CFLAGS $FREETYPE_CFLAGS"
3596    LIBS="$FREETYPE_LIBS $LIBS"
3597    AC_CHECK_FUNCS(FT_Face_GetCharVariantIndex)
3598    CFLAGS=$OLD_CFLAGS
3599    LIBS=$OLD_LIBS
3600    if test "${with_libotf}" != "no"; then
3601      EMACS_CHECK_MODULES([LIBOTF], [libotf])
3602      if test "$HAVE_LIBOTF" = "yes"; then
3603	AC_DEFINE(HAVE_LIBOTF, 1, [Define to 1 if using libotf.])
3604	AC_CHECK_LIB(otf, OTF_get_variation_glyphs,
3605		     HAVE_OTF_GET_VARIATION_GLYPHS=yes,
3606		     HAVE_OTF_GET_VARIATION_GLYPHS=no)
3607	if test "${HAVE_OTF_GET_VARIATION_GLYPHS}" = "yes"; then
3608	  AC_DEFINE(HAVE_OTF_GET_VARIATION_GLYPHS, 1,
3609		    [Define to 1 if libotf has OTF_get_variation_glyphs.])
3610	fi
3611	if ! $PKG_CONFIG --atleast-version=0.9.16 libotf; then
3612	  AC_DEFINE(HAVE_OTF_KANNADA_BUG, 1,
3613[Define to 1 if libotf is affected by https://debbugs.gnu.org/28110.])
3614	fi
3615      fi
3616    fi
3617  dnl FIXME should there be an error if HAVE_FREETYPE != yes?
3618  dnl Does the new font backend require it, or can it work without it?
3619  fi
3620
3621  HAVE_M17N_FLT=no
3622  if test "${HAVE_LIBOTF}" = yes; then
3623    if test "${with_m17n_flt}" != "no"; then
3624      EMACS_CHECK_MODULES([M17N_FLT], [m17n-flt])
3625      if test "$HAVE_M17N_FLT" = "yes"; then
3626	AC_DEFINE(HAVE_M17N_FLT, 1, [Define to 1 if using libm17n-flt.])
3627      fi
3628    fi
3629  fi
3630else # "${HAVE_X11}" != "yes"
3631  if test $window_system = pgtk; then
3632    EMACS_CHECK_MODULES([FONTCONFIG], [fontconfig >= 2.2.0])
3633    EMACS_CHECK_MODULES([FREETYPE], [freetype2])
3634    if test "$HAVE_FONTCONFIG" != yes -o "$HAVE_FREETYPE" != yes; then
3635      AC_MSG_ERROR(fontconfig and freetype is required.)
3636    fi
3637    HAVE_LIBOTF=no
3638    AC_DEFINE(HAVE_FREETYPE, 1,
3639	      [Define to 1 if using the freetype and fontconfig libraries.])
3640    if test "${with_libotf}" != "no"; then
3641      EMACS_CHECK_MODULES([LIBOTF], [libotf])
3642      if test "$HAVE_LIBOTF" = "yes"; then
3643	AC_DEFINE(HAVE_LIBOTF, 1, [Define to 1 if using libotf.])
3644	AC_CHECK_LIB(otf, OTF_get_variation_glyphs,
3645		     HAVE_OTF_GET_VARIATION_GLYPHS=yes,
3646		     HAVE_OTF_GET_VARIATION_GLYPHS=no)
3647	if test "${HAVE_OTF_GET_VARIATION_GLYPHS}" = "yes"; then
3648	  AC_DEFINE(HAVE_OTF_GET_VARIATION_GLYPHS, 1,
3649		    [Define to 1 if libotf has OTF_get_variation_glyphs.])
3650	fi
3651      fi
3652    fi
3653  else
3654    HAVE_XFT=no
3655    HAVE_FREETYPE=no
3656    HAVE_LIBOTF=no
3657    HAVE_M17N_FLT=no
3658  fi
3659fi   # "${HAVE_X11}" != "yes"
3660
3661HAVE_HARFBUZZ=no
3662### On MS-Windows we use hb_font_get_nominal_glyph, which appeared
3663### in HarfBuzz version 1.2.3
3664if test "${HAVE_W32}" = "yes"; then
3665  harfbuzz_required_ver=1.2.3
3666else
3667  harfbuzz_required_ver=0.9.42
3668fi
3669if test "${HAVE_X11}" = "yes" && test "${HAVE_FREETYPE}" = "yes" \
3670        || test "$window_system" = "pgtk" \
3671        || test "${HAVE_W32}" = "yes"; then
3672  if test "${with_harfbuzz}" != "no"; then
3673    EMACS_CHECK_MODULES([HARFBUZZ], [harfbuzz >= $harfbuzz_required_ver])
3674    if test "$HAVE_HARFBUZZ" = "yes"; then
3675      AC_DEFINE(HAVE_HARFBUZZ, 1, [Define to 1 if using HarfBuzz.])
3676      ### mingw32 and Cygwin-w32 don't use -lharfbuzz, since they load
3677      ### the library dynamically.
3678      if test "${HAVE_W32}" = "yes"; then
3679        HARFBUZZ_LIBS=
3680      fi
3681    fi
3682  fi
3683fi
3684
3685### Start of font-backend (under Haiku) selectionn.
3686if test "${HAVE_BE_APP}" = "yes"; then
3687  if test $HAVE_CAIRO = "yes"; then
3688      EMACS_CHECK_MODULES([FREETYPE], [freetype2 >= 2.5.0])
3689      test "$HAVE_FREETYPE" = "no" && AC_MSG_ERROR(cairo on Haiku requires libfreetype)
3690      EMACS_CHECK_MODULES([FONTCONFIG], [fontconfig >= 2.2.0])
3691      test "$HAVE_FONTCONFIG" = "no" && AC_MSG_ERROR(cairo on Haiku requires libfontconfig)
3692  fi
3693
3694  HAVE_LIBOTF=no
3695
3696  if test "${HAVE_FREETYPE}" = "yes"; then
3697    AC_DEFINE(HAVE_FREETYPE, 1,
3698	      [Define to 1 if using the freetype and fontconfig libraries.])
3699    OLD_CFLAGS=$CFLAGS
3700    OLD_LIBS=$LIBS
3701    CFLAGS="$CFLAGS $FREETYPE_CFLAGS"
3702    LIBS="$FREETYPE_LIBS $LIBS"
3703    AC_CHECK_FUNCS(FT_Face_GetCharVariantIndex)
3704    CFLAGS=$OLD_CFLAGS
3705    LIBS=$OLD_LIBS
3706    if test "${with_libotf}" != "no"; then
3707      EMACS_CHECK_MODULES([LIBOTF], [libotf])
3708      if test "$HAVE_LIBOTF" = "yes"; then
3709	AC_DEFINE(HAVE_LIBOTF, 1, [Define to 1 if using libotf.])
3710	AC_CHECK_LIB(otf, OTF_get_variation_glyphs,
3711		     HAVE_OTF_GET_VARIATION_GLYPHS=yes,
3712		     HAVE_OTF_GET_VARIATION_GLYPHS=no)
3713	if test "${HAVE_OTF_GET_VARIATION_GLYPHS}" = "yes"; then
3714	  AC_DEFINE(HAVE_OTF_GET_VARIATION_GLYPHS, 1,
3715		    [Define to 1 if libotf has OTF_get_variation_glyphs.])
3716	fi
3717	if ! $PKG_CONFIG --atleast-version=0.9.16 libotf; then
3718	  AC_DEFINE(HAVE_OTF_KANNADA_BUG, 1,
3719[Define to 1 if libotf is affected by https://debbugs.gnu.org/28110.])
3720	fi
3721      fi
3722    fi
3723  dnl FIXME should there be an error if HAVE_FREETYPE != yes?
3724  dnl Does the new font backend require it, or can it work without it?
3725  fi
3726fi
3727
3728if test "${HAVE_BE_APP}" = "yes" && test "${HAVE_FREETYPE}" = "yes"; then
3729  if test "${with_harfbuzz}" != "no"; then
3730    EMACS_CHECK_MODULES([HARFBUZZ], [harfbuzz >= $harfbuzz_required_ver])
3731    if test "$HAVE_HARFBUZZ" = "yes"; then
3732      AC_DEFINE(HAVE_HARFBUZZ, 1, [Define to 1 if using HarfBuzz.])
3733    fi
3734  fi
3735fi
3736
3737### End of font-backend section.
3738
3739AC_SUBST(FREETYPE_CFLAGS)
3740AC_SUBST(FREETYPE_LIBS)
3741AC_SUBST(FONTCONFIG_CFLAGS)
3742AC_SUBST(FONTCONFIG_LIBS)
3743AC_SUBST(HARFBUZZ_CFLAGS)
3744AC_SUBST(HARFBUZZ_LIBS)
3745AC_SUBST(LIBOTF_CFLAGS)
3746AC_SUBST(LIBOTF_LIBS)
3747AC_SUBST(M17N_FLT_CFLAGS)
3748AC_SUBST(M17N_FLT_LIBS)
3749
3750if test "${HAVE_X11}" = "yes"; then
3751  AC_CHECK_HEADER(X11/Xlib-xcb.h,
3752    AC_CHECK_LIB(xcb, xcb_translate_coordinates, HAVE_XCB=yes))
3753  if test "${HAVE_XCB}" = "yes"; then
3754    AC_CHECK_LIB(X11-xcb, XGetXCBConnection, HAVE_X11_XCB=yes)
3755    if test "${HAVE_X11_XCB}" = "yes"; then
3756      AC_DEFINE(USE_XCB, 1,
3757[Define to 1 if you have the XCB library and X11-XCB library for mixed
3758   X11/XCB programming.])
3759      XCB_LIBS="-lX11-xcb -lxcb"
3760      AC_SUBST(XCB_LIBS)
3761    fi
3762  fi
3763fi
3764
3765### Use -lXpm if available, unless '--with-xpm=no'.
3766### mingw32 doesn't use -lXpm, since it loads the library dynamically.
3767### The Cygwin-w32 build uses <noX/xpm.h> instead of <X11/xpm.h>, so
3768### we need to set LDFLAGS accordingly.
3769HAVE_XPM=no
3770LIBXPM=
3771if test "${HAVE_W32}" = "yes" && test "${opsys}" = "cygwin"; then
3772  if test "${with_xpm}" != "no"; then
3773    SAVE_LDFLAGS="$LDFLAGS"
3774    LDFLAGS="$LDFLAGS -L/usr/lib/noX"
3775    AC_CHECK_HEADER(noX/xpm.h,
3776      [AC_CHECK_LIB(Xpm, XpmReadFileToImage, HAVE_XPM=yes)])
3777    if test "${HAVE_XPM}" = "yes"; then
3778      AC_CACHE_CHECK([for XpmReturnAllocPixels preprocessor define],
3779      [emacs_cv_cpp_xpm_return_alloc_pixels],
3780      [AC_EGREP_CPP(no_return_alloc_pixels,
3781      [#include "noX/xpm.h"
3782#ifndef XpmReturnAllocPixels
3783no_return_alloc_pixels
3784#endif
3785      ], emacs_cv_cpp_xpm_return_alloc_pixels=no,
3786      emacs_cv_cpp_xpm_return_alloc_pixels=yes)])
3787
3788      if test "$emacs_cv_cpp_xpm_return_alloc_pixels" = "no"; then
3789        HAVE_XPM=no
3790        LDFLAGS="$SAVE_LDFLAGS"
3791      fi
3792    fi
3793  fi
3794
3795  if test "${HAVE_XPM}" = "yes"; then
3796    AC_DEFINE(HAVE_XPM, 1, [Define to 1 if you have the Xpm library (-lXpm).])
3797    LIBXPM=-lXpm
3798  fi
3799fi
3800
3801if test "${HAVE_X11}" = "yes"; then
3802  dnl Avoid Xpm on AIX unless requested, as it crashes; see Bug#17598.
3803  case $opsys,$with_xpm_set,$with_xpm in
3804    aix4-2,set,yes) ;;
3805    aix4-2,*) with_xpm=no;;
3806  esac
3807
3808  if test "${with_xpm}" != "no"; then
3809    AC_CHECK_HEADER(X11/xpm.h,
3810      [AC_CHECK_LIB(Xpm, XpmReadFileToPixmap, HAVE_XPM=yes, , -lX11)])
3811    if test "${HAVE_XPM}" = "yes"; then
3812      AC_CACHE_CHECK([for XpmReturnAllocPixels preprocessor define],
3813      [emacs_cv_cpp_xpm_return_alloc_pixels],
3814      [AC_EGREP_CPP(no_return_alloc_pixels,
3815      [#include "X11/xpm.h"
3816#ifndef XpmReturnAllocPixels
3817no_return_alloc_pixels
3818#endif
3819      ], emacs_cv_cpp_xpm_return_alloc_pixels=no,
3820      emacs_cv_cpp_xpm_return_alloc_pixels=yes)])
3821
3822      if test "$emacs_cv_cpp_xpm_return_alloc_pixels" = "no"; then
3823	HAVE_XPM=no
3824      fi
3825    fi
3826  fi
3827
3828  if test "${HAVE_XPM}" = "yes"; then
3829    AC_DEFINE(HAVE_XPM, 1, [Define to 1 if you have the Xpm library (-lXpm).])
3830    LIBXPM=-lXpm
3831  elif test "$opsys,$LUCID_LIBW" = aix4-2,-lXaw; then
3832    dnl AIX -lXaw needs -lXpm linked too; see Bug#17598 Message#152.
3833    LIBXPM=-lXpm
3834  fi
3835fi
3836
3837### FIXME: Perhaps regroup to minimize code duplication due to MinGW's
3838### slightly different requirements wrt image libraries (it doesn't
3839### use -lXpm because it loads the xpm shared library dynamically at
3840### run time).
3841if test "${opsys}" = "mingw32"; then
3842  if test "${with_xpm}" != "no"; then
3843    AC_CHECK_HEADER(X11/xpm.h, HAVE_XPM=yes, HAVE_XPM=no, [
3844#define FOR_MSW 1])
3845  fi
3846
3847  if test "${HAVE_XPM}" = "yes"; then
3848    AC_DEFINE(HAVE_XPM, 1, [Define to 1 if you have the Xpm library (-lXpm).])
3849  fi
3850fi
3851
3852AC_SUBST(LIBXPM)
3853
3854### Use -ljpeg if available, unless '--with-jpeg=no'.
3855HAVE_JPEG=no
3856LIBJPEG=
3857if test "${HAVE_X11}" = "yes" || test "${HAVE_W32}" = "yes" \
3858   || test "${HAVE_NS}" = "yes" || test "${HAVE_BE_APP}" = "yes" \
3859   || test "$window_system" = "pgtk"; then
3860  if test "${with_jpeg}" != "no"; then
3861    AC_CACHE_CHECK([for jpeglib 6b or later],
3862      [emacs_cv_jpeglib],
3863      [OLD_LIBS=$LIBS
3864       for emacs_cv_jpeglib in yes -ljpeg no; do
3865	 case $emacs_cv_jpeglib in
3866	   yes) ;;
3867	   no) break;;
3868	   *) LIBS="$LIBS $emacs_cv_jpeglib";;
3869	 esac
3870	 AC_LINK_IFELSE(
3871	   [AC_LANG_PROGRAM(
3872	      [[#undef HAVE_STDLIB_H /* Avoid config.h/jpeglib.h collision.  */
3873		#include <stdio.h> /* jpeglib.h needs FILE and size_t.  */
3874		#include <jpeglib.h>
3875		#include <jerror.h>
3876		char verify[JPEG_LIB_VERSION < 62 ? -1 : 1];
3877		struct jpeg_decompress_struct cinfo;
3878	      ]],
3879	      [[
3880		jpeg_create_decompress (&cinfo);
3881		WARNMS (&cinfo, JWRN_JPEG_EOF);
3882		jpeg_destroy_decompress (&cinfo);
3883	      ]])],
3884	   [emacs_link_ok=yes],
3885	   [emacs_link_ok=no])
3886	 LIBS=$OLD_LIBS
3887	 test $emacs_link_ok = yes && break
3888       done])
3889    if test "$emacs_cv_jpeglib" != no; then
3890      HAVE_JPEG=yes
3891      AC_DEFINE([HAVE_JPEG], 1,
3892	[Define to 1 if you have the jpeg library (typically -ljpeg).])
3893      ### mingw32 doesn't use -ljpeg, since it loads the library
3894      ### dynamically when needed, and doesn't want a run-time
3895      ### dependency on the jpeglib DLL.
3896      test "$emacs_cv_jpeglib" != yes && test "${opsys}" != "mingw32" \
3897      && LIBJPEG=$emacs_cv_jpeglib
3898    fi
3899  fi
3900fi
3901AC_SUBST(LIBJPEG)
3902
3903HAVE_LCMS2=no
3904LCMS2_CFLAGS=
3905LCMS2_LIBS=
3906if test "${with_lcms2}" != "no"; then
3907  EMACS_CHECK_MODULES([LCMS2], [lcms2])
3908fi
3909if test "${HAVE_LCMS2}" = "yes"; then
3910  AC_DEFINE([HAVE_LCMS2], 1, [Define to 1 if you have the lcms2 library (-llcms2).])
3911  ### mingw32 doesn't use -llcms2, since it loads the library dynamically.
3912  if test "${opsys}" = "mingw32"; then
3913     LCMS2_LIBS=
3914  fi
3915fi
3916AC_SUBST(LCMS2_CFLAGS)
3917AC_SUBST(LCMS2_LIBS)
3918
3919HAVE_ZLIB=no
3920LIBZ=
3921if test "${with_zlib}" != "no"; then
3922  OLIBS=$LIBS
3923  AC_SEARCH_LIBS([inflateEnd], [z], [HAVE_ZLIB=yes])
3924  LIBS=$OLIBS
3925  case $ac_cv_search_inflateEnd in
3926    -*) LIBZ=$ac_cv_search_inflateEnd ;;
3927  esac
3928fi
3929if test "${HAVE_ZLIB}" = "yes"; then
3930  AC_DEFINE([HAVE_ZLIB], 1, [Define to 1 if you have the zlib library (-lz).])
3931  ### mingw32 doesn't use -lz, since it loads the library dynamically.
3932  if test "${opsys}" = "mingw32"; then
3933     LIBZ=
3934  fi
3935fi
3936AC_SUBST(LIBZ)
3937
3938### Dynamic modules support
3939LIBMODULES=
3940HAVE_MODULES=no
3941MODULES_OBJ=
3942NEED_DYNLIB=no
3943case $opsys in
3944  cygwin|mingw32) MODULES_SUFFIX=".dll" ;;
3945  darwin) MODULES_SUFFIX=".dylib" ;;
3946  *) MODULES_SUFFIX=".so" ;;
3947esac
3948case "${opsys}" in
3949  darwin) MODULES_SECONDARY_SUFFIX='.so' ;;
3950  *) MODULES_SECONDARY_SUFFIX='' ;;
3951esac
3952if test "${with_modules}" != "no"; then
3953  case $opsys in
3954    gnu|gnu-linux)
3955      LIBMODULES="-ldl"
3956      HAVE_MODULES=yes
3957      ;;
3958    cygwin|mingw32|darwin)
3959      HAVE_MODULES=yes
3960      ;;
3961    *)
3962      # BSD systems have dlopen in libc.
3963      AC_CHECK_FUNC([dlopen], [HAVE_MODULES=yes])
3964      ;;
3965  esac
3966
3967  if test "${HAVE_MODULES}" = no; then
3968    AC_MSG_ERROR([Dynamic modules are not supported on your system])
3969  else
3970    SAVE_LIBS=$LIBS
3971    LIBS="$LIBS $LIBMODULES"
3972    AC_CHECK_FUNCS([dladdr dlfunc])
3973    LIBS=$SAVE_LIBS
3974  fi
3975fi
3976
3977if test "${HAVE_MODULES}" = yes; then
3978   MODULES_OBJ="emacs-module.o"
3979   NEED_DYNLIB=yes
3980   AC_DEFINE(HAVE_MODULES, 1, [Define to 1 if dynamic modules are enabled])
3981   AC_DEFINE_UNQUOTED(MODULES_SUFFIX, "$MODULES_SUFFIX",
3982     [System extension for dynamic libraries])
3983   if test -n "${MODULES_SECONDARY_SUFFIX}"; then
3984     AC_DEFINE_UNQUOTED(MODULES_SECONDARY_SUFFIX, "$MODULES_SECONDARY_SUFFIX",
3985       [Alternative system extension for dynamic libraries.])
3986   fi
3987fi
3988AC_SUBST(MODULES_OBJ)
3989AC_SUBST(LIBMODULES)
3990AC_SUBST(HAVE_MODULES)
3991AC_SUBST(MODULES_SUFFIX)
3992AC_SUBST(MODULES_SECONDARY_SUFFIX)
3993
3994AC_CONFIG_FILES([src/emacs-module.h])
3995AC_SUBST_FILE([module_env_snippet_25])
3996AC_SUBST_FILE([module_env_snippet_26])
3997AC_SUBST_FILE([module_env_snippet_27])
3998AC_SUBST_FILE([module_env_snippet_28])
3999AC_SUBST_FILE([module_env_snippet_29])
4000module_env_snippet_25="$srcdir/src/module-env-25.h"
4001module_env_snippet_26="$srcdir/src/module-env-26.h"
4002module_env_snippet_27="$srcdir/src/module-env-27.h"
4003module_env_snippet_28="$srcdir/src/module-env-28.h"
4004module_env_snippet_29="$srcdir/src/module-env-29.h"
4005emacs_major_version="${PACKAGE_VERSION%%.*}"
4006AC_SUBST(emacs_major_version)
4007
4008### Emacs Lisp native compiler support
4009
4010AC_DEFUN([libgccjit_smoke_test], [
4011  AC_LANG_SOURCE(
4012    [[#include <libgccjit.h>
4013      #include <stdlib.h>
4014      #include <stdio.h>
4015      int
4016      main (int argc, char **argv)
4017      {
4018        gcc_jit_context *ctxt;
4019        gcc_jit_result *result;
4020        ctxt = gcc_jit_context_acquire ();
4021        if (!ctxt)
4022          exit (1);
4023        gcc_jit_type *int_type =
4024          gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
4025        gcc_jit_function *func =
4026          gcc_jit_context_new_function (ctxt, NULL,
4027                                        GCC_JIT_FUNCTION_EXPORTED,
4028                                        int_type, "foo", 0, NULL, 0);
4029        gcc_jit_block *block = gcc_jit_function_new_block (func, "foo");
4030        gcc_jit_block_end_with_return (
4031          block,
4032          NULL,
4033          gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 1));
4034        result = gcc_jit_context_compile (ctxt);
4035        if (!result)
4036          exit (1);
4037        typedef int (*fn_type) (void);
4038        fn_type foo =
4039          (fn_type)gcc_jit_result_get_code (result, "foo");
4040        if (!foo)
4041          exit (1);
4042        if (foo () != 1)
4043          exit (1);
4044        gcc_jit_context_release (ctxt);
4045        gcc_jit_result_release (result);
4046        return 0;
4047      }]])])
4048
4049AC_DEFUN([libgccjit_not_found], [
4050  AC_MSG_ERROR([ELisp native compiler was requested, but libgccjit was not found.
4051Please try installing libgccjit or a similar package.
4052If you are sure you want Emacs be compiled without ELisp native compiler,
4053pass the --without-native-compilation option to configure.])])
4054
4055AC_DEFUN([libgccjit_dev_not_found], [
4056  AC_MSG_ERROR([ELisp native compiler was requested, but libgccjit header files were
4057not found.
4058Please try installing libgccjit-dev or a similar package.
4059If you are sure you want Emacs be compiled without ELisp native compiler,
4060pass the --without-native-compilation option to configure.])])
4061
4062AC_DEFUN([libgccjit_broken], [
4063  AC_MSG_ERROR([The installed libgccjit failed to compile and run a test program using
4064the libgccjit library; see config.log for the details of the failure.
4065The test program can be found here:
4066<https://gcc.gnu.org/onlinedocs/jit/intro/tutorial01.html>.
4067You can try compiling it yourself to investigate the issues.
4068Please report the issue to your distribution if libgccjit was installed
4069through that.
4070You can find the instructions on how to compile and install libgccjit from
4071source on this site:
4072<https://gcc.gnu.org/wiki/JIT>.])])
4073
4074HAVE_NATIVE_COMP=no
4075LIBGCCJIT_LIBS=
4076LIBGCCJIT_CFLAGS=
4077if test "$canonical" = i686-pc-cygwin; then
4078  if test "${with_cygwin32_native_compilation}" = yes; then
4079    with_native_compilation=yes
4080  elif test "${with_native_compilation}" != no; then
4081    AC_MSG_ERROR([Native compilation is not supported on 32-bit Cygwin.
4082If you really want to try it anyway, use the configure option
4083'--with-cygwin32-native-compilation'.])
4084  fi
4085fi
4086
4087if test "${with_native_compilation}" != "no"; then
4088    if test "${HAVE_PDUMPER}" = no; then
4089       AC_MSG_ERROR(['--with-native-compilation' requires '--with-dumping=pdumper'])
4090    fi
4091    if test "${HAVE_ZLIB}" = no; then
4092       AC_MSG_ERROR(['--with-native-compilation' requires zlib])
4093    fi
4094
4095    SAVE_CFLAGS=$CFLAGS
4096    SAVE_LIBS=$LIBS
4097
4098    if test "${opsys}" = "darwin"; then
4099      # Ensure libgccjit installed by Homebrew or macports can be found.
4100      if test -n "$BREW"; then
4101        if test -n "`$BREW --prefix --installed libgccjit 2>/dev/null`"; then
4102          MAC_CFLAGS="-I$(dirname $($BREW ls -v libgccjit | \
4103                                                grep libgccjit.h))"
4104          MAC_LIBS="-L$(dirname $($BREW ls -v libgccjit| \
4105                                            grep libgccjit.so\$))"
4106        fi
4107      fi
4108
4109      if test -n "$HAVE_MACPORTS"; then
4110        # Determine which gcc version has been installed (gcc11, for
4111        # instance). Use the latest version, if more than one is
4112        # available.  (We filter out the gcc4 packages, because they
4113        # don't support jit, and they have names like "gcc49" that
4114        # sort later than "gcc11".)
4115        PORT_PACKAGE=$(port installed active | grep '^ *gcc@<:@0-9@:>@* ' | \
4116                            awk '{ print $1; }' | grep -v 'gcc4@<:@0-9@:>@' | \
4117                            sort -V | tail -n 1)
4118        if test -n "$PORT_PACKAGE"; then
4119          MAC_CFLAGS="-I$(dirname $(port contents $PORT_PACKAGE | \
4120                                           grep libgccjit.h))"
4121          MAC_LIBS="-L$(dirname $(port contents $PORT_PACKAGE | \
4122                                              grep libgccjit.dylib))"
4123        fi
4124      fi
4125
4126      if test -n "$MAC_CFLAGS" && test -n "$MAC_LIBS"; then
4127        CFLAGS="$CFLAGS ${MAC_CFLAGS}"
4128        LIBS="$LIBS ${MAC_LIBS}"
4129      fi
4130    fi
4131
4132    # Check if libgccjit is available.
4133    AC_CHECK_LIB(gccjit, gcc_jit_context_acquire, [], [libgccjit_not_found])
4134    AC_CHECK_HEADERS(libgccjit.h, [], [libgccjit_dev_not_found])
4135    # Check if libgccjit really works.
4136    AC_RUN_IFELSE([libgccjit_smoke_test], [], [libgccjit_broken])
4137    HAVE_NATIVE_COMP=yes
4138    case "${opsys}" in
4139      # mingw32 loads the library dynamically.
4140      mingw32) ;;
4141      # OpenBSD doesn't have libdl, all the functions are in libc
4142      netbsd|openbsd)
4143        LIBGCCJIT_LIBS="-lgccjit" ;;
4144      darwin)
4145        LIBGCCJIT_CFLAGS="${MAC_CFLAGS}"
4146        LIBGCCJIT_LIBS="${MAC_LIBS} -lgccjit -ldl";;
4147      *)
4148        LIBGCCJIT_LIBS="-lgccjit -ldl" ;;
4149    esac
4150    NEED_DYNLIB=yes
4151    AC_DEFINE(HAVE_NATIVE_COMP, 1, [Define to 1 if native compiler is available.])
4152
4153    CFLAGS=$SAVE_CFLAGS
4154    LIBS=$SAVE_LIBS
4155fi
4156AC_DEFINE_UNQUOTED(NATIVE_ELISP_SUFFIX, ".eln",
4157  [System extension for native compiled elisp])
4158AC_SUBST(HAVE_NATIVE_COMP)
4159AC_SUBST(LIBGCCJIT_CFLAGS)
4160AC_SUBST(LIBGCCJIT_LIBS)
4161
4162DYNLIB_OBJ=
4163if test "${NEED_DYNLIB}" = yes; then
4164  DYNLIB_OBJ="dynlib.o"
4165fi
4166AC_SUBST(DYNLIB_OBJ)
4167
4168### Use -lpng if available, unless '--with-png=no'.
4169HAVE_PNG=no
4170LIBPNG=
4171PNG_CFLAGS=
4172if test "${with_png}" != no; then
4173  # mingw32 loads the library dynamically.
4174  if test "$opsys" = mingw32; then
4175    AC_CHECK_HEADER([png.h], [HAVE_PNG=yes])
4176  elif test "${HAVE_X11}" = "yes" || test "${HAVE_W32}" = "yes" \
4177       || test "${HAVE_NS}" = "yes" || test "${HAVE_BE_APP}" = "yes" \
4178       || test "$window_system" = "pgtk"; then
4179    EMACS_CHECK_MODULES([PNG], [libpng >= 1.0.0])
4180    if test $HAVE_PNG = yes; then
4181      LIBPNG=$PNG_LIBS
4182    else
4183      # Test old way in case pkg-config doesn't have it (older machines).
4184      AC_MSG_CHECKING([for libpng not configured by pkg-config])
4185
4186      png_cflags=`(libpng-config --cflags) 2>&AS_MESSAGE_LOG_FD` &&
4187      png_ldflags=`(libpng-config --ldflags) 2>&AS_MESSAGE_LOG_FD` || {
4188	# libpng-config does not work; configure by hand.
4189	# Debian unstable as of July 2003 has multiple libpngs, and puts png.h
4190	# in /usr/include/libpng.
4191	if test -r /usr/include/libpng/png.h &&
4192	   test ! -r /usr/include/png.h; then
4193	  png_cflags=-I/usr/include/libpng
4194	else
4195	  png_cflags=
4196	fi
4197	png_ldflags='-lpng'
4198      }
4199      SAVE_CFLAGS=$CFLAGS
4200      SAVE_LIBS=$LIBS
4201      CFLAGS="$CFLAGS $png_cflags"
4202      LIBS="$png_ldflags -lz -lm $LIBS"
4203      AC_LINK_IFELSE(
4204	[AC_LANG_PROGRAM([[#include <png.h>]],
4205	   [[return !png_get_channels (0, 0);]])],
4206	[HAVE_PNG=yes
4207	 PNG_CFLAGS=`AS_ECHO(["$png_cflags"]) | sed -e "$edit_cflags"`
4208	 LIBPNG=$png_ldflags])
4209      CFLAGS=$SAVE_CFLAGS
4210      LIBS=$SAVE_LIBS
4211      AC_MSG_RESULT([$HAVE_PNG])
4212    fi
4213
4214    # $LIBPNG requires explicit -lz in some cases.
4215    # We don't know what those cases are, exactly, so play it safe and
4216    # append -lz to any nonempty $LIBPNG, unless we're already using LIBZ.
4217    case " $LIBPNG ",$LIBZ in
4218      *' -lz '*, | *' ',?*) ;;
4219      *) LIBPNG="$LIBPNG -lz" ;;
4220    esac
4221  fi
4222fi
4223if test $HAVE_PNG = yes; then
4224  AC_DEFINE([HAVE_PNG], [1], [Define to 1 if you have the png library.])
4225
4226  SAVE_CFLAGS=$CFLAGS
4227  CFLAGS="$CFLAGS $PNG_CFLAGS"
4228  AC_CHECK_DECL([png_longjmp],
4229    [],
4230    [AC_DEFINE([PNG_DEPSTRUCT], [],
4231       [Define to empty to suppress deprecation warnings when building
4232	with --enable-gcc-warnings and with libpng versions before 1.5,
4233	which lack png_longjmp.])],
4234    [[#include <png.h>
4235    ]])
4236  CFLAGS=$SAVE_CFLAGS
4237fi
4238AC_SUBST(LIBPNG)
4239AC_SUBST(PNG_CFLAGS)
4240
4241### Use -ltiff if available, unless '--with-tiff=no'.
4242### mingw32 doesn't use -ltiff, since it loads the library dynamically.
4243HAVE_TIFF=no
4244LIBTIFF=
4245if test "${opsys}" = "mingw32"; then
4246  if test "${with_tiff}" != "no"; then
4247    AC_CHECK_HEADER(tiffio.h, HAVE_TIFF=yes, HAVE_TIFF=no)
4248  fi
4249  if test "${HAVE_TIFF}" = "yes"; then
4250    AC_DEFINE(HAVE_TIFF, 1, [Define to 1 if you have the tiff library (-ltiff).])
4251  fi
4252elif test "${HAVE_X11}" = "yes" || test "${HAVE_W32}" = "yes" \
4253     || test "${HAVE_NS}" = "yes" || test "${HAVE_BE_APP}" = "yes" \
4254     || test "$window_system" = "pgtk"; then
4255  if test "${with_tiff}" != "no"; then
4256    AC_CHECK_HEADER(tiffio.h,
4257      [tifflibs="-lz -lm"
4258      # At least one tiff package requires the jpeg library.
4259      if test "${HAVE_JPEG}" = yes; then tifflibs="-ljpeg $tifflibs"; fi
4260      AC_CHECK_LIB(tiff, TIFFGetVersion, HAVE_TIFF=yes, , $tifflibs)])
4261  fi
4262
4263  if test "${HAVE_TIFF}" = "yes"; then
4264    AC_DEFINE(HAVE_TIFF, 1, [Define to 1 if you have the tiff library (-ltiff).])
4265    dnl FIXME -lz -lm, as per libpng?
4266    LIBTIFF=-ltiff
4267  fi
4268fi
4269AC_SUBST(LIBTIFF)
4270
4271### Use -lgif or -lungif if available, unless '--with-gif=no'.
4272### mingw32 doesn't use -lgif/-lungif, since it loads the library dynamically.
4273HAVE_GIF=no
4274LIBGIF=
4275if test "${opsys}" = "mingw32"; then
4276  if test "${with_gif}" != "no"; then
4277    AC_CHECK_HEADER(gif_lib.h, HAVE_GIF=yes, HAVE_GIF=no)
4278  fi
4279  if test "${HAVE_GIF}" = "yes"; then
4280    AC_DEFINE(HAVE_GIF, 1, [Define to 1 if you have a gif (or ungif) library.])
4281  fi
4282elif test "${HAVE_X11}" = "yes" && test "${with_gif}" != "no" \
4283        || test "${HAVE_W32}" = "yes" || test "${HAVE_NS}" = "yes" \
4284	|| test "${HAVE_BE_APP}" = "yes" || test "$window_system" = "pgtk"; then
4285  AC_CHECK_HEADER(gif_lib.h,
4286# EGifPutExtensionLast only exists from version libungif-4.1.0b1.
4287# Earlier versions can crash Emacs, but version 5.0 removes EGifPutExtensionLast.
4288    [AC_CHECK_LIB(gif, GifMakeMapObject, HAVE_GIF=yes,
4289        [AC_CHECK_LIB(gif, EGifPutExtensionLast, HAVE_GIF=yes, HAVE_GIF=maybe)])])
4290
4291  if test "$HAVE_GIF" = yes; then
4292    LIBGIF=-lgif
4293  elif test "$HAVE_GIF" = maybe; then
4294# If gif_lib.h but no libgif, try libungif.
4295    AC_CHECK_LIB(ungif, EGifPutExtensionLast, HAVE_GIF=yes, HAVE_GIF=no)
4296    test "$HAVE_GIF" = yes && LIBGIF=-lungif
4297  fi
4298
4299  if test "${HAVE_GIF}" = "yes"; then
4300    AC_DEFINE(HAVE_GIF, 1, [Define to 1 if you have a gif (or ungif) library.])
4301  fi
4302fi
4303AC_SUBST(LIBGIF)
4304
4305dnl Check for required libraries.
4306MISSING=
4307WITH_IFAVAILABLE=
4308if test "${HAVE_X11}" = "yes"; then
4309  case $with_xpm,$HAVE_XPM in
4310    no,* | ifavailable,* | *,yes) ;;
4311    *) MISSING="libXpm"
4312       WITH_IFAVAILABLE="--with-xpm=ifavailable";;
4313  esac
4314  case $with_jpeg,$HAVE_JPEG in
4315    no,* | ifavailable,* | *,yes) ;;
4316    *) MISSING="$MISSING libjpeg"
4317       WITH_IFAVAILABLE="$WITH_IFAVAILABLE --with-jpeg=ifavailable";;
4318  esac
4319  case $with_png,$HAVE_PNG in
4320    no,* | ifavailable,* | *,yes) ;;
4321    *) MISSING="$MISSING libpng"
4322       WITH_IFAVAILABLE="$WITH_IFAVAILABLE --with-png=ifavailable";;
4323  esac
4324  case $with_gif,$HAVE_GIF in
4325    no,* | ifavailable,* | *,yes) ;;
4326    *) MISSING="$MISSING libgif/libungif"
4327       WITH_IFAVAILABLE="$WITH_IFAVAILABLE --with-gif=ifavailable";;
4328  esac
4329  case $with_tiff,$HAVE_TIFF in
4330    no,* | ifavailable,* | *,yes) ;;
4331    *) MISSING="$MISSING libtiff"
4332       WITH_IFAVAILABLE="$WITH_IFAVAILABLE --with-tiff=ifavailable";;
4333  esac
4334fi
4335case $with_gnutls,$HAVE_GNUTLS in
4336  no,* | ifavailable,* | *,yes) ;;
4337  *) MISSING="$MISSING gnutls"
4338     WITH_IFAVAILABLE="$WITH_IFAVAILABLE --with-gnutls=ifavailable";;
4339esac
4340case $with_json,$HAVE_JSON in
4341  no,* | ifavailable,* | *,yes) ;;
4342  *) MISSING="$MISSING json"
4343     WITH_IFAVAILABLE="$WITH_IFAVAILABLE --with-json=ifavailable";;
4344esac
4345if test "X${MISSING}" != X; then
4346  # If we have a missing library, and we don't have pkg-config installed,
4347  # the missing pkg-config may be the reason.  Give the user a hint.
4348  if test "X${PKG_CONFIG}" = X; then
4349    AC_MSG_WARN([Unable to locate a usable pkg-config])
4350  fi
4351  AC_MSG_ERROR([The following required libraries were not found:
4352    $MISSING
4353Maybe some development libraries/packages are missing?
4354To build anyway, give:
4355    $WITH_IFAVAILABLE
4356as options to configure.])
4357fi
4358
4359### Use -lgpm if available, unless '--with-gpm=no'.
4360HAVE_GPM=no
4361LIBGPM=
4362if test "${with_gpm}" != "no"; then
4363  AC_CHECK_HEADER(gpm.h,
4364    [AC_CHECK_LIB(gpm, Gpm_Open, HAVE_GPM=yes)])
4365
4366  if test "${HAVE_GPM}" = "yes"; then
4367    AC_DEFINE(HAVE_GPM, 1, [Define to 1 if you have the gpm library (-lgpm).])
4368    LIBGPM=-lgpm
4369  fi
4370fi
4371AC_SUBST(LIBGPM)
4372
4373dnl Check for malloc/malloc.h on darwin
4374AC_CHECK_HEADERS_ONCE(malloc/malloc.h)
4375
4376GNUSTEP_CFLAGS=
4377### Use NeXTstep API to implement GUI.
4378if test "${HAVE_NS}" = "yes"; then
4379  AC_DEFINE(HAVE_NS, 1, [Define to 1 if you are using the NeXTstep API, either GNUstep or Cocoa on macOS.])
4380  if test "${NS_IMPL_COCOA}" = "yes"; then
4381    AC_DEFINE(NS_IMPL_COCOA, 1, [Define to 1 if you are using NS windowing under macOS.])
4382  fi
4383  if test "${NS_IMPL_GNUSTEP}" = "yes"; then
4384    AC_DEFINE(NS_IMPL_GNUSTEP, 1, [Define to 1 if you are using NS windowing under GNUstep.])
4385    if test $NS_GNUSTEP_CONFIG != yes; then
4386      # See also .m.o rule in src/Makefile.in.  */
4387      # FIXME: are all these flags really needed?  Document here why.  */
4388      GNUSTEP_CFLAGS="-D_REENTRANT -fPIC -fno-strict-aliasing -I${GNUSTEP_SYSTEM_HEADERS} ${GNUSTEP_LOCAL_HEADERS}"
4389      ## Extra CFLAGS applied to src/*.m files.
4390      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"
4391    fi
4392  fi
4393  OTHER_FILES=ns-app
4394fi
4395
4396### Use session management (-lSM -lICE) if available
4397HAVE_X_SM=no
4398LIBXSM=
4399if test "${HAVE_X11}" = "yes"; then
4400  AC_CHECK_HEADER(X11/SM/SMlib.h,
4401    [AC_CHECK_LIB(SM, SmcOpenConnection, HAVE_X_SM=yes, , -lICE)])
4402
4403  if test "${HAVE_X_SM}" = "yes"; then
4404    AC_DEFINE(HAVE_X_SM, 1, [Define to 1 if you have the SM library (-lSM).])
4405    LIBXSM="-lSM -lICE"
4406  fi
4407fi
4408AC_SUBST(LIBXSM)
4409
4410### Use XRandr (-lXrandr) if available
4411HAVE_XRANDR=no
4412if test "${HAVE_X11}" = "yes"; then
4413  XRANDR_REQUIRED=1.2.2
4414  XRANDR_MODULES="xrandr >= $XRANDR_REQUIRED"
4415  EMACS_CHECK_MODULES([XRANDR], [$XRANDR_MODULES])
4416  if test $HAVE_XRANDR = no; then
4417    # Test old way in case pkg-config doesn't have it (older machines).
4418    # Include Xrender.h by hand to work around bug in older Xrandr.h
4419    # (e.g. RHEL5) and silence (harmless) configure warning (bug#18465).
4420    AC_CHECK_HEADER(X11/extensions/Xrandr.h,
4421      [AC_CHECK_LIB(Xrandr, XRRGetScreenResources, HAVE_XRANDR=yes)],
4422      [], [AC_INCLUDES_DEFAULT
4423#include <X11/extensions/Xrender.h>])
4424    if test $HAVE_XRANDR = yes; then
4425      XRANDR_LIBS=-lXrandr
4426    fi
4427  fi
4428  if test $HAVE_XRANDR = yes; then
4429    AC_DEFINE(HAVE_XRANDR, 1, [Define to 1 if you have the XRandr extension.])
4430  fi
4431fi
4432AC_SUBST(XRANDR_CFLAGS)
4433AC_SUBST(XRANDR_LIBS)
4434
4435### Use Xinerama (-lXinerama) if available
4436HAVE_XINERAMA=no
4437if test "${HAVE_X11}" = "yes"; then
4438  XINERAMA_REQUIRED=1.0.2
4439  XINERAMA_MODULES="xinerama >= $XINERAMA_REQUIRED"
4440  EMACS_CHECK_MODULES([XINERAMA], [$XINERAMA_MODULES])
4441  if test $HAVE_XINERAMA = no; then
4442    # Test old way in case pkg-config doesn't have it (older machines).
4443    AC_CHECK_HEADER(X11/extensions/Xinerama.h,
4444      [AC_CHECK_LIB(Xinerama, XineramaQueryExtension, HAVE_XINERAMA=yes)])
4445    if test $HAVE_XINERAMA = yes; then
4446      XINERAMA_LIBS=-lXinerama
4447    fi
4448  fi
4449  if test $HAVE_XINERAMA = yes; then
4450    AC_DEFINE(HAVE_XINERAMA, 1, [Define to 1 if you have the Xinerama extension.])
4451  fi
4452fi
4453AC_SUBST(XINERAMA_CFLAGS)
4454AC_SUBST(XINERAMA_LIBS)
4455
4456### Use Xfixes (-lXfixes) if available
4457HAVE_XFIXES=no
4458if test "${HAVE_X11}" = "yes"; then
4459  XFIXES_REQUIRED=4.0.0
4460  XFIXES_MODULES="xfixes >= $XFIXES_REQUIRED"
4461  EMACS_CHECK_MODULES([XFIXES], [$XFIXES_MODULES])
4462  if test $HAVE_XFIXES = no; then
4463    # Test old way in case pkg-config doesn't have it (older machines).
4464    AC_CHECK_HEADER(X11/extensions/Xfixes.h,
4465      [AC_CHECK_LIB(Xfixes, XFixesHideCursor, HAVE_XFIXES=yes)])
4466    if test $HAVE_XFIXES = yes; then
4467      XFIXES_LIBS=-lXfixes
4468    fi
4469  fi
4470  if test $HAVE_XFIXES = yes; then
4471    AC_DEFINE(HAVE_XFIXES, 1, [Define to 1 if you have the Xfixes extension.])
4472  fi
4473fi
4474AC_SUBST(XFIXES_CFLAGS)
4475AC_SUBST(XFIXES_LIBS)
4476
4477## Use XInput 2.0 if available
4478HAVE_XINPUT2=no
4479if test "${HAVE_X11}" = "yes" && test "${with_xinput2}" != "no"; then
4480   EMACS_CHECK_MODULES([XINPUT], [xi])
4481   if test $HAVE_XINPUT = yes; then
4482     # Now check for XInput2.h
4483     AC_CHECK_HEADER(X11/extensions/XInput2.h,
4484       [AC_CHECK_LIB(Xi, XIGrabButton, HAVE_XINPUT2=yes)])
4485   fi
4486   if test $HAVE_XINPUT2 = yes; then
4487     AC_DEFINE(HAVE_XINPUT2, 1, [Define to 1 if the X Input Extension version 2.0 or later is present.])
4488     if test "$USE_GTK_TOOLKIT" = "GTK2"; then
4489       AC_MSG_WARN([You are building Emacs with GTK+ 2 and the X Input Extension version 2.
4490This might lead to problems if your version of GTK+ is not built with support for XInput 2.])
4491     fi
4492     # Detect both faulty installations of libXi where gesture event
4493     # types are defined but gesture event structures are not, and
4494     # also where gesture event structures are empty.
4495     AC_CHECK_MEMBERS([XIGesturePinchEvent.delta_unaccel_y],
4496       [AC_DEFINE(HAVE_USABLE_XI_GESTURE_PINCH_EVENT, 1,
4497         [Define to 1 if XInput headers define gesture structures correctly.])],
4498       [], [[#include <X11/extensions/XInput2.h>]])
4499   fi
4500fi
4501AC_SUBST(XINPUT_CFLAGS)
4502AC_SUBST(XINPUT_LIBS)
4503
4504### Use Xdbe (-lXdbe) if available
4505HAVE_XDBE=no
4506if test "${HAVE_X11}" = "yes"; then
4507  if test "${with_xdbe}" != "no"; then
4508    AC_CHECK_HEADER(X11/extensions/Xdbe.h,
4509      [AC_CHECK_LIB(Xext, XdbeAllocateBackBufferName, HAVE_XDBE=yes)],
4510      [],
4511      [#include <X11/Xlib.h>
4512      ])
4513  fi
4514  if test $HAVE_XDBE = yes; then
4515    XDBE_LIBS=-lXext
4516  fi
4517  if test $HAVE_XDBE = yes; then
4518    AC_DEFINE(HAVE_XDBE, 1, [Define to 1 if you have the Xdbe extension.])
4519  fi
4520fi
4521AC_SUBST(XDBE_CFLAGS)
4522AC_SUBST(XDBE_LIBS)
4523
4524### Use libxml (-lxml2) if available
4525### mingw32 doesn't use -lxml2, since it loads the library dynamically.
4526HAVE_LIBXML2=no
4527if test "${with_xml2}" != "no"; then
4528  ### I'm not sure what the version number should be, so I just guessed.
4529  EMACS_CHECK_MODULES([LIBXML2], [libxml-2.0 > 2.6.17])
4530  # Built-in libxml2 on OS X 10.8 lacks libxml-2.0.pc.
4531  if test "${HAVE_LIBXML2}" != "yes" && test "$opsys" = "darwin"; then
4532    SAVE_CPPFLAGS="$CPPFLAGS"
4533    if test -z "$xcsdkdir" -a -n "$XCRUN" -a ! -d /usr/include; then
4534      dnl /usr/include is not found.  Try Xcode SDK dir if it is sane.
4535      xcsdkdir=`$XCRUN --show-sdk-path 2>/dev/null`
4536      case $xcsdkdir in
4537	*[[\\\"\#\$\&\'\`$am_lf\ \	]]*)
4538	xcsdkdir="" ;;
4539      esac
4540    fi
4541    CPPFLAGS="$CPPFLAGS -isystem${xcsdkdir}/usr/include/libxml2"
4542    AC_CHECK_HEADER(libxml/HTMLparser.h,
4543      [AC_CHECK_DECL(HTML_PARSE_RECOVER, HAVE_LIBXML2=yes, ,
4544		     [#include <libxml/HTMLparser.h>])])
4545    CPPFLAGS="$SAVE_CPPFLAGS"
4546    if test "${HAVE_LIBXML2}" = "yes"; then
4547      LIBXML2_CFLAGS="-isystem${xcsdkdir}/usr/include/libxml2"
4548      LIBXML2_LIBS="-lxml2"
4549    fi
4550  fi
4551  if test "${HAVE_LIBXML2}" = "yes"; then
4552    if test "${opsys}" != "mingw32"; then
4553      AC_CHECK_LIB(xml2, htmlReadMemory, HAVE_LIBXML2=yes, HAVE_LIBXML2=no,
4554        [$LIBXML2_LIBS])
4555    else
4556      LIBXML2_LIBS=""
4557    fi
4558    if test "${HAVE_LIBXML2}" = "yes"; then
4559      AC_DEFINE(HAVE_LIBXML2, 1, [Define to 1 if you have the libxml library (-lxml2).])
4560    else
4561      LIBXML2_LIBS=""
4562      LIBXML2_CFLAGS=""
4563    fi
4564  fi
4565fi
4566AC_SUBST(LIBXML2_LIBS)
4567AC_SUBST(LIBXML2_CFLAGS)
4568
4569BLESSMAIL_TARGET=
4570LIBS_MAIL=
4571if test ! "$with_mailutils"; then
4572  # Check for mail-locking functions in a "mail" library.  Probably this should
4573  # have the same check as for liblockfile below.
4574  AC_CHECK_LIB([mail], [maillock], [have_mail=yes], [have_mail=no])
4575  if test $have_mail = yes; then
4576    LIBS_MAIL=-lmail
4577    AC_DEFINE([HAVE_LIBMAIL], [1],
4578      [Define to 1 if you have the 'mail' library (-lmail).])
4579
4580    OLD_LIBS=$LIBS
4581    LIBS="$LIBS_MAIL $LIBS"
4582    AC_CHECK_FUNCS([touchlock])
4583    LIBS=$OLD_LIBS
4584  fi
4585  dnl Debian, at least:
4586  AC_CHECK_LIB([lockfile], [maillock], [have_lockfile=yes], [have_lockfile=no])
4587  if test $have_lockfile = yes; then
4588     LIBS_MAIL=-llockfile
4589     AC_DEFINE([HAVE_LIBLOCKFILE], [1],
4590       [Define to 1 if you have the 'lockfile' library (-llockfile).])
4591  else
4592    # If we have the shared liblockfile, assume we must use it for mail
4593    # locking (e.g. Debian).  If we couldn't link against liblockfile
4594    # (no liblockfile.a installed), ensure that we don't need to.
4595    dnl This works for files generally, not just executables.
4596    dnl Should we look elsewhere for it?  Maybe examine /etc/ld.so.conf?
4597    AC_CHECK_PROG([liblockfile], [liblockfile.so], [yes], [no],
4598		  [/usr/lib:/lib:/usr/local/lib:$LD_LIBRARY_PATH])
4599    if test "$ac_cv_prog_liblockfile" = yes; then
4600      AC_MSG_ERROR([Shared liblockfile found but can't link against it.
4601This probably means that movemail could lose mail.
4602There may be a 'development' package to install containing liblockfile.])
4603    fi
4604  fi
4605  AC_CHECK_HEADERS([maillock.h])
4606
4607  ## Define MAIL_USE_FLOCK (or LOCKF) if the mailer uses flock (or lockf) to
4608  ## interlock access to the mail spool.  The alternative is a lock file named
4609  ## /usr/spool/mail/$USER.lock.
4610  mail_lock=no
4611  case $opsys in
4612    aix4-2) mail_lock="lockf" ;;
4613
4614    gnu|freebsd|dragonfly|netbsd|openbsd|darwin) mail_lock="flock" ;;
4615
4616    ## On GNU/Linux systems, both methods are used by various mail programs.
4617    ## I assume most people are using newer mailers that have heard of flock.
4618    ## Change this if you need to.
4619    ## Debian contains a patch which says: "On Debian/GNU/Linux systems,
4620    ## configure gets the right answers, and that means *NOT* using flock.
4621    ## Using flock is guaranteed to be the wrong thing. See Debian Policy
4622    ## for details." and then uses '#ifdef DEBIAN'.  Unfortunately the
4623    ## Debian maintainer hasn't provided a clean fix for Emacs.
4624    ## movemail.c will use 'maillock' when MAILDIR, HAVE_LIBMAIL and
4625    ## HAVE_MAILLOCK_H are defined, so the following appears to be the
4626    ## correct logic.  -- fx
4627    ## We must check for HAVE_LIBLOCKFILE too, as movemail does.
4628    ## liblockfile is a Free Software replacement for libmail, used on
4629    ## Debian systems and elsewhere. -rfr.
4630    gnu-*)
4631      mail_lock="flock"
4632      if test $have_mail = yes || test $have_lockfile = yes; then
4633	test $ac_cv_header_maillock_h = yes && mail_lock=no
4634      fi ;;
4635
4636    mingw32)
4637      mail_lock="none-needed" ;;
4638  esac
4639
4640  case $mail_lock in
4641    flock) AC_DEFINE([MAIL_USE_FLOCK], [1],
4642	     [Define if the mailer uses flock to interlock the mail spool.]);;
4643
4644    lockf) AC_DEFINE([MAIL_USE_LOCKF], [1],
4645	     [Define if the mailer uses lockf to interlock the mail spool.]);;
4646
4647    none-needed) ;;
4648
4649    *) BLESSMAIL_TARGET="need-blessmail" ;;
4650  esac
4651fi
4652AC_SUBST([BLESSMAIL_TARGET])
4653AC_SUBST([LIBS_MAIL])
4654
4655HAVE_SECCOMP=no
4656AC_CHECK_HEADERS(
4657  [linux/seccomp.h linux/filter.h],
4658  [AC_CHECK_DECLS(
4659    [SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_TSYNC],
4660    [HAVE_SECCOMP=yes], [],
4661    [[
4662    #include <linux/seccomp.h>
4663    ]])])
4664AC_SUBST([HAVE_SECCOMP])
4665
4666EMACS_CHECK_MODULES([LIBSECCOMP], [libseccomp >= 2.4.0])
4667AC_SUBST([HAVE_LIBSECCOMP])
4668AC_SUBST([LIBSECCOMP_LIBS])
4669AC_SUBST([LIBSECCOMP_CFLAGS])
4670
4671OLD_LIBS=$LIBS
4672LIBS="$LIB_PTHREAD $LIB_MATH $LIBS"
4673AC_CHECK_FUNCS(accept4 fchdir gethostname \
4674getrusage get_current_dir_name \
4675lrand48 random rint trunc \
4676select getpagesize setlocale newlocale \
4677getrlimit setrlimit shutdown \
4678pthread_sigmask strsignal setitimer \
4679sendto recvfrom getsockname getifaddrs freeifaddrs \
4680gai_strerror sync \
4681getpwent endpwent getgrent endgrent \
4682cfmakeraw cfsetspeed __executable_start log2 pthread_setname_np \
4683pthread_set_name_np)
4684LIBS=$OLD_LIBS
4685
4686if test "$ac_cv_func_pthread_setname_np" = "yes"; then
4687  AC_CACHE_CHECK(
4688   [whether pthread_setname_np takes a single argument],
4689   [emacs_cv_pthread_setname_np_1arg],
4690   [AC_COMPILE_IFELSE(
4691     [AC_LANG_PROGRAM(
4692       [[#include <pthread.h>]],
4693       [[pthread_setname_np ("a");]])],
4694     [emacs_cv_pthread_setname_np_1arg=yes],
4695     [emacs_cv_pthread_setname_np_1arg=no])])
4696  if test "$emacs_cv_pthread_setname_np_1arg" = "yes"; then
4697    AC_DEFINE(
4698      HAVE_PTHREAD_SETNAME_NP_1ARG, 1,
4699      [Define to 1 if pthread_setname_np takes a single argument.])
4700  else
4701    AC_CACHE_CHECK(
4702     [whether pthread_setname_np takes three arguments],
4703     [emacs_cv_pthread_setname_np_3arg],
4704     [AC_COMPILE_IFELSE(
4705       [AC_LANG_PROGRAM(
4706         [[#include <pthread.h>]],
4707         [[pthread_setname_np (0, "%s", "a");]])],
4708       [emacs_cv_pthread_setname_np_3arg=yes],
4709       [emacs_cv_pthread_setname_np_3arg=no])])
4710     if test "$emacs_cv_pthread_setname_np_3arg" = "yes"; then
4711       AC_DEFINE(
4712         HAVE_PTHREAD_SETNAME_NP_3ARG, 1,
4713         [Define to 1 if pthread_setname_np takes three arguments.])
4714     fi
4715  fi
4716fi
4717
4718dnl No need to check for posix_memalign if aligned_alloc works.
4719AC_CHECK_FUNCS([aligned_alloc posix_memalign], [break])
4720AC_CHECK_DECLS([aligned_alloc], [], [], [[#include <stdlib.h>]])
4721
4722case $with_unexec,$canonical in
4723  yes,alpha*)
4724    AC_CHECK_DECL([__ELF__], [],
4725      [AC_MSG_ERROR([Non-ELF systems are not supported on this platform.])]);;
4726esac
4727
4728if test "$with_unexec" = yes && test "$opsys" = "haiku"; then
4729  dnl A serious attempt was actually made to port unexec to Haiku.
4730  dnl Something in libstdc++ seems to prevent it from working.
4731  AC_MSG_ERROR([Haiku is not supported by the legacy unexec dumper.
4732Please use the portable dumper instead.])
4733fi
4734
4735# Dump loading
4736AC_CHECK_FUNCS([posix_madvise])
4737
4738dnl Cannot use AC_CHECK_FUNCS
4739AC_CACHE_CHECK([for __builtin_frame_address],
4740  [emacs_cv_func___builtin_frame_address],
4741  [AC_LINK_IFELSE([AC_LANG_PROGRAM([], [__builtin_frame_address (0);])],
4742     [emacs_cv_func___builtin_frame_address=yes],
4743     [emacs_cv_func___builtin_frame_address=no])])
4744if test $emacs_cv_func___builtin_frame_address = yes; then
4745  AC_DEFINE([HAVE___BUILTIN_FRAME_ADDRESS], 1,
4746	    [Define to 1 if you have the '__builtin_frame_address' function.])
4747fi
4748AC_CACHE_CHECK([for __builtin_unwind_init],
4749	       emacs_cv_func___builtin_unwind_init,
4750[AC_LINK_IFELSE([AC_LANG_PROGRAM([], [__builtin_unwind_init ();])],
4751		emacs_cv_func___builtin_unwind_init=yes,
4752		emacs_cv_func___builtin_unwind_init=no)])
4753if test $emacs_cv_func___builtin_unwind_init = yes; then
4754  AC_DEFINE(HAVE___BUILTIN_UNWIND_INIT, 1,
4755	    [Define to 1 if you have the '__builtin_unwind_init' function.])
4756fi
4757
4758AC_CHECK_HEADERS_ONCE(sys/un.h)
4759
4760AC_FUNC_FSEEKO
4761
4762# UNIX98 PTYs.
4763AC_CHECK_FUNCS(grantpt)
4764
4765# PTY-related GNU extensions.
4766AC_CHECK_FUNCS(getpt posix_openpt)
4767
4768dnl Run a test program that contains a call to tputs, a call that is
4769dnl never executed.  This tests whether a pre-'main' dynamic linker
4770dnl works with the library.  It's too much trouble to actually call
4771dnl tputs in the test program, due to portability hassles.  When
4772dnl cross-compiling, assume the test program will run if it links.
4773AC_DEFUN([tputs_link_source], [
4774  AC_LANG_SOURCE(
4775     [[extern void tputs (const char *, int, int (*)(int));
4776       int main (int argc, char **argv)
4777       {
4778	  if (argc == 10000)
4779	    tputs (argv[0], 0, 0);
4780	  return 0;
4781       }]])
4782])
4783# Check this now, so that we will NOT find the above functions in ncurses.
4784# That is because we have not set up to link ncurses in lib-src.
4785# It's better to believe a function is not available
4786# than to expect to find it in ncurses.
4787# Also we need tputs and friends to be able to build at all.
4788AC_CACHE_CHECK([for library containing tputs], [emacs_cv_tputs_lib],
4789[if test "${opsys}" = "mingw32"; then
4790  emacs_cv_tputs_lib='none required'
4791else
4792  # curses precedes termcap because of AIX (Bug#9736#35) and OpenIndiana.
4793  tputs_libraries='tinfo ncurses terminfo curses termcap tinfow ncursesw'
4794  for tputs_library in '' $tputs_libraries; do
4795    OLIBS=$LIBS
4796    if test -z "$tputs_library"; then
4797      emacs_cv_tputs_lib='none required'
4798    else
4799      emacs_cv_tputs_lib=-l$tputs_library
4800      LIBS="$emacs_cv_tputs_lib $LIBS"
4801    fi
4802    AC_RUN_IFELSE([tputs_link_source], [], [emacs_cv_tputs_lib=no],
4803      [AC_LINK_IFELSE([tputs_link_source], [], [emacs_cv_tputs_lib=no])])
4804    LIBS=$OLIBS
4805    if test "X$emacs_cv_tputs_lib" != Xno; then
4806      break
4807    fi
4808  done
4809fi])
4810AS_CASE(["$emacs_cv_tputs_lib"],
4811  [no], [AC_MSG_ERROR([The required function 'tputs' was not found in any library.
4812The following libraries were tried (in order):
4813  libtinfo, libncurses, libterminfo, libcurses, libtermcap
4814Please try installing whichever of these libraries is most appropriate
4815for your system, together with its header files.
4816For example, a libncurses-dev(el) or similar package.])],
4817  [-l*], [LIBS_TERMCAP=$emacs_cv_tputs_lib],
4818  [*], [LIBS_TERMCAP=])
4819
4820## Use termcap instead of terminfo?
4821## Only true for: freebsd < 40000, ms-w32, msdos, netbsd < 599002500.
4822TERMINFO=yes
4823## FIXME?  In the cases below where we unconditionally set
4824## LIBS_TERMCAP="-lncurses", this overrides LIBS_TERMCAP = -ltinfo,
4825## if that was found above to have tputs.
4826## Should we use the gnu* logic everywhere?
4827case "$opsys" in
4828  ## darwin: Prevents crashes when running Emacs in Terminal.app under 10.2.
4829  ##  The ncurses library has been moved out of the System framework in
4830  ##  Mac OS X 10.2.  So if configure detects it, set the command-line
4831  ##  option to use it.
4832  darwin) LIBS_TERMCAP="-lncurses" ;;
4833
4834  gnu*) test -z "$LIBS_TERMCAP" && LIBS_TERMCAP="-lncurses" ;;
4835
4836  freebsd)
4837    AC_MSG_CHECKING([whether FreeBSD is new enough to use terminfo])
4838    AC_CACHE_VAL(emacs_cv_freebsd_terminfo,
4839    [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <osreldate.h>]],
4840[[#if __FreeBSD_version < 400000
4841fail;
4842#endif
4843]])], emacs_cv_freebsd_terminfo=yes, emacs_cv_freebsd_terminfo=no)])
4844
4845    AC_MSG_RESULT($emacs_cv_freebsd_terminfo)
4846
4847    if test $emacs_cv_freebsd_terminfo = yes; then
4848      LIBS_TERMCAP="-lncurses"
4849    else
4850      TERMINFO=no
4851      LIBS_TERMCAP="-ltermcap"
4852    fi
4853    ;;
4854
4855  mingw32)
4856    TERMINFO=no
4857    LIBS_TERMCAP=
4858    ;;
4859
4860  netbsd)
4861    if test "x$LIBS_TERMCAP" != "x-lterminfo"; then
4862      TERMINFO=no
4863      LIBS_TERMCAP="-ltermcap"
4864    fi
4865    ;;
4866
4867  openbsd | dragonfly) LIBS_TERMCAP="-lncurses" ;;
4868
4869  ## hpux: Make sure we get select from libc rather than from libcurses
4870  ##  because libcurses on HPUX 10.10 has a broken version of select.
4871  ##  We used to use -lc -lcurses, but this may be cleaner.
4872  ## FIXME?  But TERMINFO = yes on hpux (it used to be explicitly
4873  # set that way, now it uses the default).  Isn't this a contradiction?
4874  hpux*) LIBS_TERMCAP="-ltermcap" ;;
4875
4876esac
4877
4878TERMCAP_OBJ=tparam.o
4879if test $TERMINFO = yes; then
4880  AC_DEFINE(TERMINFO, 1, [Define to 1 if you use terminfo instead of termcap.])
4881  TERMCAP_OBJ=terminfo.o
4882  AC_CACHE_CHECK([whether $LIBS_TERMCAP library defines BC],
4883    [emacs_cv_terminfo_defines_BC],
4884    [OLD_LIBS=$LIBS
4885     LIBS="$LIBS $LIBS_TERMCAP"
4886     AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern char *BC;]], [[return !*BC;]])],
4887       [emacs_cv_terminfo_defines_BC=yes],
4888       [emacs_cv_terminfo_defines_BC=no])
4889     LIBS=$OLD_LIBS])
4890  if test "$emacs_cv_terminfo_defines_BC" = yes; then
4891    AC_DEFINE([TERMINFO_DEFINES_BC], 1, [Define to 1 if the
4892      terminfo library defines the variables BC, PC, and UP.])
4893  fi
4894fi
4895if test "X$LIBS_TERMCAP" = "X-lncurses"; then
4896  AC_DEFINE(USE_NCURSES, 1, [Define to 1 if you use ncurses.])
4897fi
4898AC_SUBST(LIBS_TERMCAP)
4899AC_SUBST(TERMCAP_OBJ)
4900
4901# GNU/Linux-specific timer functions.
4902AC_CACHE_CHECK([for timerfd interface], [emacs_cv_have_timerfd],
4903  [AC_COMPILE_IFELSE(
4904     [AC_LANG_PROGRAM([[#include <sys/timerfd.h>
4905		      ]],
4906		      [[timerfd_create (CLOCK_REALTIME,
4907					TFD_CLOEXEC | TFD_NONBLOCK);
4908			timerfd_settime (0, TFD_TIMER_ABSTIME, 0, 0);]])],
4909     [emacs_cv_have_timerfd=yes],
4910     [emacs_cv_have_timerfd=no])])
4911if test "$emacs_cv_have_timerfd" = yes; then
4912  AC_DEFINE([HAVE_TIMERFD], 1,
4913    [Define to 1 if timerfd functions are supported as in GNU/Linux.])
4914fi
4915
4916# Alternate stack for signal handlers.
4917AC_CACHE_CHECK([whether signals can be handled on alternate stack],
4918	       [emacs_cv_alternate_stack],
4919  [AC_COMPILE_IFELSE(
4920     [AC_LANG_PROGRAM([[#include <signal.h>
4921		      ]],
4922		      [[stack_t ss;
4923			struct sigaction sa;
4924			ss.ss_sp = malloc (SIGSTKSZ);
4925			ss.ss_size = SIGSTKSZ;
4926			sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
4927			sigaltstack (&ss, 0);
4928			sigaction (SIGSEGV, &sa, 0);]])],
4929     [emacs_cv_alternate_stack=yes],
4930     [emacs_cv_alternate_stack=no])])
4931
4932# Do we need the Hesiod library to provide the support routines?
4933dnl FIXME?  Should we be skipping this on Darwin too?
4934LIBHESIOD=
4935LIBRESOLV=
4936if test "$with_hesiod" != no ; then
4937  # Don't set $LIBS here -- see comments above.  FIXME which comments?
4938  resolv=no
4939  AC_CHECK_FUNC(res_send, , [AC_CHECK_FUNC(__res_send, ,
4940     [AC_CHECK_LIB(resolv, res_send, resolv=yes,
4941		  [AC_CHECK_LIB(resolv, __res_send, resolv=yes)])])])
4942  if test "$resolv" = yes ; then
4943    RESOLVLIB=-lresolv
4944  else
4945    RESOLVLIB=
4946  fi
4947  hesiod=no
4948  AC_CHECK_FUNC(hes_getmailhost, , [AC_CHECK_LIB(hesiod, hes_getmailhost,
4949	hesiod=yes, :, $RESOLVLIB)])
4950
4951  if test x"$hesiod" = xyes; then
4952    LIBHESIOD=-lhesiod
4953    LIBRESOLV=$RESOLVLIB
4954  fi
4955fi
4956AC_SUBST(LIBHESIOD)
4957AC_SUBST(LIBRESOLV)
4958
4959# These tell us which Kerberos-related libraries to use.
4960COM_ERRLIB=
4961CRYPTOLIB=
4962KRB5LIB=
4963DESLIB=
4964KRB4LIB=
4965
4966if test "${with_kerberos}" != no; then
4967  OLD_LIBS=$LIBS
4968  AC_CHECK_LIB(com_err, com_err, have_com_err=yes, have_com_err=no)
4969  if test $have_com_err = yes; then
4970    COM_ERRLIB=-lcom_err
4971    LIBS="$COM_ERRLIB $LIBS"
4972  fi
4973  AC_CHECK_LIB(crypto, mit_des_cbc_encrypt, have_crypto=yes, have_crypto=no)
4974  if test $have_crypto = yes; then
4975    CRYPTOLIB=-lcrypto
4976    LIBS="$CRYPTOLIB $LIBS"
4977  fi
4978  AC_CHECK_LIB(k5crypto, mit_des_cbc_encrypt, have_k5crypto=yes, have_k5crypto=no)
4979  if test $have_k5crypto = yes; then
4980    CRYPTOLIB=-lk5crypto
4981    LIBS="$CRYPTOLIB $LIBS"
4982  fi
4983  AC_CHECK_LIB(krb5, krb5_init_context, have_krb5=yes, have_krb5=no)
4984  if test $have_krb5=yes; then
4985    KRB5LIB=-lkrb5
4986    LIBS="$KRB5LIB $LIBS"
4987  fi
4988  dnl FIXME Simplify.  Does not match 22 logic, thanks to default_off?
4989  if test "${with_kerberos5}" = no; then
4990    AC_CHECK_LIB(des425, des_cbc_encrypt, have_des425=yes, have_des425=no )
4991    if test $have_des425 = yes; then
4992      DESLIB=-ldes425
4993      LIBS="$DESLIB $LIBS"
4994    else
4995      AC_CHECK_LIB(des, des_cbc_encrypt, have_des=yes, have_des=no)
4996      if test $have_des = yes; then
4997        DESLIB=-ldes
4998        LIBS="$DESLIB $LIBS"
4999      fi
5000    fi
5001    AC_CHECK_LIB(krb4, krb_get_cred, have_krb4=yes, have_krb4=no)
5002    if test $have_krb4 = yes; then
5003      KRB4LIB=-lkrb4
5004      LIBS="$KRB4LIB $LIBS"
5005    else
5006      AC_CHECK_LIB(krb, krb_get_cred, have_krb=yes, have_krb=no)
5007      if test $have_krb = yes; then
5008        KRB4LIB=-lkrb
5009        LIBS="$KRB4LIB $LIBS"
5010      fi
5011    fi
5012  fi
5013
5014  if test "${with_kerberos5}" != no; then
5015    AC_CHECK_HEADERS(krb5.h,
5016      [AC_CHECK_MEMBERS([krb5_error.text, krb5_error.e_text],,,
5017		        [#include <krb5.h>])])
5018  else
5019    AC_CHECK_HEADERS(krb.h,,
5020		     [AC_CHECK_HEADERS(kerberosIV/krb.h,,
5021				       [AC_CHECK_HEADERS(kerberos/krb.h)])])
5022  fi
5023  AC_CHECK_HEADERS(com_err.h)
5024  LIBS=$OLD_LIBS
5025fi
5026
5027AC_SUBST(COM_ERRLIB)
5028AC_SUBST(CRYPTOLIB)
5029AC_SUBST(KRB5LIB)
5030AC_SUBST(DESLIB)
5031AC_SUBST(KRB4LIB)
5032
5033AC_CHECK_HEADERS(valgrind/valgrind.h)
5034
5035AC_CHECK_MEMBERS([struct unipair.unicode], [], [], [[#include <linux/kd.h>]])
5036
5037AC_CHECK_FUNCS_ONCE([__lsan_ignore_object])
5038
5039AC_FUNC_FORK
5040
5041dnl AC_CHECK_FUNCS_ONCE wouldn’t be right for snprintf, which needs
5042dnl the current CFLAGS etc.
5043AC_CHECK_FUNCS(snprintf)
5044
5045dnl posix_spawn.  The chdir and setsid functionality is relatively
5046dnl recent, so we check for it specifically.
5047AC_CHECK_HEADERS([spawn.h])
5048AC_SUBST([HAVE_SPAWN_H])
5049AC_CHECK_FUNCS([posix_spawn \
5050                posix_spawn_file_actions_addchdir \
5051                posix_spawn_file_actions_addchdir_np \
5052                posix_spawnattr_setflags])
5053AC_SUBST([HAVE_POSIX_SPAWN])
5054AC_SUBST([HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR])
5055AC_SUBST([HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR_NP])
5056AC_SUBST([HAVE_POSIX_SPAWNATTR_SETFLAGS])
5057AC_CHECK_DECLS([POSIX_SPAWN_SETSID], [], [], [[
5058               #include <spawn.h>
5059               ]])
5060AC_SUBST([HAVE_DECL_POSIX_SPAWN_SETSID])
5061
5062dnl Check for glib.  This differs from other library checks in that
5063dnl Emacs need not link to glib unless some other library is already
5064dnl linking to glib.  Although glib provides no facilities that Emacs
5065dnl needs for its own purposes, when glib is present Emacs needs to
5066dnl use primitives like g_main_context_query to avoid clashing with
5067dnl glib at a low level.
5068dnl
5069dnl Check this late, since it depends on $GTK_CFLAGS etc.
5070XGSELOBJ=
5071AC_CACHE_CHECK([whether GLib is linked in], [emacs_cv_links_glib],
5072[OLDCFLAGS="$CFLAGS"
5073OLDLIBS="$LIBS"
5074CFLAGS="$CFLAGS $GTK_CFLAGS $RSVG_CFLAGS $DBUS_CFLAGS $SETTINGS_CFLAGS"
5075LIBS="$LIBS $GTK_LIBS $RSVG_LIBS $DBUS_LIBS $SETTINGS_LIBS"
5076CFLAGS="$CFLAGS $NOTIFY_CFLAGS $CAIRO_CFLAGS"
5077LIBS="$LIBS $NOTIFY_LIBS $CAIRO_LIBS"
5078AC_LINK_IFELSE([AC_LANG_PROGRAM(
5079	[[#include <glib.h>
5080	]],
5081	[[g_print ("Hello world");]])],
5082     [emacs_cv_links_glib=yes],
5083     [emacs_cv_links_glib=no])
5084CFLAGS="$OLDCFLAGS"
5085LIBS="$OLDLIBS"])
5086if test "${emacs_cv_links_glib}" = "yes"; then
5087  AC_DEFINE(HAVE_GLIB, 1, [Define to 1 if GLib is linked in.])
5088  if test "$HAVE_NS" = no ; then
5089    XGSELOBJ=xgselect.o
5090  fi
5091fi
5092AC_SUBST(XGSELOBJ)
5093
5094dnl Adapted from Haible's version.
5095AC_CACHE_CHECK([for nl_langinfo and CODESET], [emacs_cv_langinfo_codeset],
5096  [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <langinfo.h>]],
5097    [[char *cs = nl_langinfo(CODESET);]])],
5098    [emacs_cv_langinfo_codeset=yes],
5099    [emacs_cv_langinfo_codeset=no])
5100  ])
5101if test "$emacs_cv_langinfo_codeset" = yes; then
5102  AC_DEFINE([HAVE_LANGINFO_CODESET], 1,
5103    [Define if you have <langinfo.h> and nl_langinfo (CODESET).])
5104
5105  AC_CACHE_CHECK([for nl_langinfo and _NL_PAPER_WIDTH],
5106    [emacs_cv_langinfo__nl_paper_width],
5107    [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <langinfo.h>]],
5108      [[char *cs = nl_langinfo (_NL_PAPER_WIDTH);]])],
5109      [emacs_cv_langinfo__nl_paper_width=yes],
5110      [emacs_cv_langinfo__nl_paper_width=no])
5111    ])
5112  if test "$emacs_cv_langinfo__nl_paper_width" = yes; then
5113    AC_DEFINE([HAVE_LANGINFO__NL_PAPER_WIDTH], 1,
5114      [Define if you have <langinfo.h> and nl_langinfo (_NL_PAPER_WIDTH).])
5115  fi
5116fi
5117
5118AC_TYPE_MBSTATE_T
5119
5120dnl Fixme: AC_SYS_POSIX_TERMIOS should probably be used, but it's not clear
5121dnl how the tty code is related to POSIX and/or other versions of termios.
5122dnl The following looks like a useful start.
5123dnl
5124dnl AC_SYS_POSIX_TERMIOS
5125dnl if test $ac_cv_sys_posix_termios = yes; then
5126dnl    AC_DEFINE(HAVE_TERMIOS, 1, [Define to 1 if you have POSIX-style functions
5127dnl                                and macros for terminal control.])
5128dnl    AC_DEFINE(HAVE_TCATTR, 1, [Define to 1 if you have tcgetattr and tcsetattr.])
5129dnl fi
5130
5131dnl Turned on June 1996 supposing nobody will mind it.
5132dnl MinGW emulates passwd database, so this feature doesn't make sense there.
5133if test "${opsys}" != "mingw32"; then
5134   AC_DEFINE(AMPERSAND_FULL_NAME, 1, [Define to use the convention that &
5135     in the full name stands for the login id.])
5136fi
5137
5138dnl Everybody supports this, except MS.
5139dnl Seems like the kind of thing we should be testing for, though.
5140## Note: PTYs are broken on darwin <6.  Use at your own risk.
5141if test "${opsys}" != "mingw32"; then
5142  AC_DEFINE(HAVE_PTYS, 1, [Define if the system supports pty devices.])
5143fi
5144
5145dnl Everybody supports this, except MS-DOS.
5146dnl Seems like the kind of thing we should be testing for, though.
5147AC_DEFINE(HAVE_SOCKETS, 1, [Define if the system supports
5148  4.2-compatible sockets.])
5149
5150AH_TEMPLATE(INTERNAL_TERMINAL, [This is substituted when $TERM is "internal".])
5151
5152AH_TEMPLATE(NULL_DEVICE, [Name of the file to open to get
5153  a null file, or a data sink.])
5154if test "${opsys}" = "mingw32"; then
5155  AC_DEFINE(NULL_DEVICE, ["NUL:"])
5156else
5157  AC_DEFINE(NULL_DEVICE, ["/dev/null"])
5158fi
5159
5160if test "${opsys}" = "mingw32"; then
5161  SEPCHAR=';'
5162else
5163  SEPCHAR=':'
5164fi
5165AC_DEFINE_UNQUOTED(SEPCHAR, ['$SEPCHAR'], [Character that separates PATH elements.])
5166dnl This is for MinGW, and is used in test/Makefile.in.
5167dnl The MSYS Bash has heuristics for replacing ':' with ';' when it
5168dnl decides that a command-line argument to be passed to a MinGW program
5169dnl is a PATH-style list of directories.  But that heuristics plays it
5170dnl safe, and only does the replacement when it is _absolutely_ sure it
5171dnl sees a colon-separated list of file names; e.g. ":." is left alone,
5172dnl which breaks in-tree builds.  So we do this manually instead.
5173dnl Note that we cannot rely on PATH_SEPARATOR, as that one will always
5174dnl be computed as ':' in MSYS Bash.
5175AC_SUBST(SEPCHAR)
5176
5177dnl Everybody supports this, except MS-DOS.
5178AC_DEFINE(subprocesses, 1, [Define to enable asynchronous subprocesses.])
5179
5180AC_DEFINE(USER_FULL_NAME, [pw->pw_gecos], [How to get a user's full name.])
5181
5182
5183AC_DEFINE(DIRECTORY_SEP, ['/'],
5184  [Character that separates directories in a file name.])
5185
5186if test "${opsys}" = "mingw32"; then
5187  AC_DEFINE(IS_DEVICE_SEP(_c_), [((_c_) == ':')],
5188    [Returns true if character is a device separator.])
5189
5190  AC_DEFINE(IS_DIRECTORY_SEP(_c_), [((_c_) == '/' || (_c_) == '\\')],
5191    [Returns true if character is a directory separator.])
5192
5193  AC_DEFINE(IS_ANY_SEP(_c_), [(IS_DIRECTORY_SEP (_c_) || IS_DEVICE_SEP(_c_))],
5194    [Returns true if character is any form of separator.])
5195else
5196  AC_DEFINE(IS_DEVICE_SEP(_c_), 0,
5197    [Returns true if character is a device separator.])
5198
5199  AC_DEFINE(IS_DIRECTORY_SEP(_c_), [((_c_) == DIRECTORY_SEP)],
5200    [Returns true if character is a directory separator.])
5201
5202  AC_DEFINE(IS_ANY_SEP(_c_), [(IS_DIRECTORY_SEP (_c_))],
5203    [Returns true if character is any form of separator.])
5204fi
5205
5206if test "$USE_X_TOOLKIT" != "none"; then
5207  have_editres=yes
5208  case $opsys in
5209    hpux*)
5210      dnl Assar Westerlund <assar@sics.se> says this is necessary
5211      dnl for HP-UX 10.20, and that it works for HP-UX 0 as well.
5212      have_editres=no
5213    ;;
5214  esac
5215  if test "$have_editres" != no && test ! -z "$LIBXMU"; then
5216    OLDLIBS="$LIBS"
5217    dnl See libXmu.a check above.
5218    if test x$HAVE_X11XTR6 = xyes; then
5219      LIBS="-lXt -lSM -lICE $LIBXMU"
5220    else
5221      OTHERLIBS="-lXt -$LIBXMU"
5222    fi
5223    AC_LINK_IFELSE([AC_LANG_PROGRAM(
5224      [[#include <X11/Intrinsic.h>
5225       #include <X11/Xmu/Editres.h>]],
5226      [[_XEditResCheckMessages (0, 0, 0, 0);]])],
5227      [AC_DEFINE([X_TOOLKIT_EDITRES], 1,
5228        [Define to 1 if we should use XEditRes.])])
5229    LIBS=$OLDLIBS
5230  fi
5231fi
5232
5233case $opsys in
5234  solaris | unixware )
5235    dnl Some SVr4s don't define NSIG in sys/signal.h for ANSI environments;
5236    dnl instead, there's a system variable _sys_nsig.  Unfortunately, we
5237    dnl need the constant to dimension an array.  So wire in the appropriate
5238    dnl value here.
5239    AC_DEFINE(NSIG_MINIMUM, 32, [Minimum value of NSIG.])
5240    ;;
5241esac
5242
5243emacs_broken_SIGIO=no
5244
5245case $opsys in
5246  dnl SIGIO exists, but the feature doesn't work in the way Emacs needs.
5247  hpux* | nacl | solaris | unixware )
5248    emacs_broken_SIGIO=yes
5249    ;;
5250
5251  aix4-2)
5252    dnl On AIX Emacs uses the gmalloc.c malloc implementation.  But given
5253    dnl the way this system works, libc functions that return malloced
5254    dnl memory use the libc malloc implementation. Calling xfree or
5255    dnl xrealloc on the results of such functions results in a crash.
5256    dnl
5257    dnl One solution for this could be to define SYSTEM_MALLOC in configure,
5258    dnl but that does not currently work on this system.
5259    dnl
5260    dnl It is possible to completely override the malloc implementation on
5261    dnl AIX, but that involves putting the malloc functions in a shared
5262    dnl library and setting the MALLOCTYPE environment variable to point to
5263    dnl that shared library.
5264    dnl
5265    dnl Emacs currently calls xrealloc on the results of get_current_dir name,
5266    dnl to avoid a crash just use the Emacs implementation for that function.
5267    dnl
5268    dnl FIXME We could change the AC_CHECK_FUNCS call near the start
5269    dnl of this file, so that we do not check for get_current_dir_name
5270    dnl on AIX.  But that might be fragile if something else ends
5271    dnl up testing for get_current_dir_name as a dependency.
5272    AC_DEFINE(BROKEN_GET_CURRENT_DIR_NAME, 1, [Define if
5273      get_current_dir_name should not be used.])
5274    ;;
5275
5276  freebsd)
5277    dnl Circumvent a bug in FreeBSD.  In the following sequence of
5278    dnl writes/reads on a PTY, read(2) returns bogus data:
5279    dnl
5280    dnl write(2)  1022 bytes
5281    dnl write(2)   954 bytes, get EAGAIN
5282    dnl read(2)   1024 bytes in process_read_output
5283    dnl read(2)     11 bytes in process_read_output
5284    dnl
5285    dnl That is, read(2) returns more bytes than have ever been written
5286    dnl successfully.  The 1033 bytes read are the 1022 bytes written
5287    dnl successfully after processing (for example with CRs added if the
5288    dnl terminal is set up that way which it is here).  The same bytes will
5289    dnl be seen again in a later read(2), without the CRs.
5290    AC_DEFINE(BROKEN_PTY_READ_AFTER_EAGAIN, 1, [Define on FreeBSD to
5291      work around an issue when reading from a PTY.])
5292    ;;
5293esac
5294
5295case $opsys in
5296  gnu-* | solaris )
5297    dnl FIXME Can't we test if this exists (eg /proc/$$)?
5298    AC_DEFINE(HAVE_PROCFS, 1, [Define if you have the /proc filesystem.])
5299  ;;
5300esac
5301
5302case $opsys in
5303  darwin | dragonfly | freebsd | netbsd | openbsd )
5304    AC_DEFINE(DONT_REOPEN_PTY, 1, [Define if process.c does not need to
5305      close a pty to make it a controlling terminal (it is already a
5306      controlling terminal of the subprocess, because we did ioctl TIOCSCTTY).])
5307  ;;
5308esac
5309
5310dnl FIXME Surely we can test for this rather than hard-code it.
5311case $opsys in
5312  netbsd | openbsd) sound_device="/dev/audio" ;;
5313  *) sound_device="/dev/dsp" ;;
5314esac
5315
5316dnl Used in sound.c
5317AC_DEFINE_UNQUOTED(DEFAULT_SOUND_DEVICE, "$sound_device",
5318  [Name of the default sound device.])
5319
5320
5321dnl Emacs can read input using SIGIO and buffering characters itself,
5322dnl or using CBREAK mode and making C-g cause SIGINT.
5323dnl The choice is controlled by the variable interrupt_input.
5324dnl
5325dnl Define INTERRUPT_INPUT to make interrupt_input = 1 the default (use SIGIO)
5326dnl
5327dnl Emacs uses the presence of the USABLE_SIGIO macro
5328dnl to indicate whether or not signal-driven I/O is possible.  It uses
5329dnl INTERRUPT_INPUT to decide whether to use it by default.
5330dnl
5331dnl SIGIO can be used only on systems that implement it (4.2 and 4.3).
5332dnl CBREAK mode has two disadvantages
5333dnl 1) At least in 4.2, it is impossible to handle the Meta key properly.
5334dnl I hear that in system V this problem does not exist.
5335dnl 2) Control-G causes output to be discarded.
5336dnl I do not know whether this can be fixed in system V.
5337dnl
5338dnl Another method of doing input is planned but not implemented.
5339dnl It would have Emacs fork off a separate process
5340dnl to read the input and send it to the true Emacs process
5341dnl through a pipe.
5342case $opsys in
5343  darwin | gnu-linux | gnu-kfreebsd)
5344    AC_DEFINE(INTERRUPT_INPUT, 1, [Define to read input using SIGIO.])
5345  ;;
5346esac
5347
5348
5349dnl If the system's imake configuration file defines 'NeedWidePrototypes'
5350dnl as 'NO', we must define NARROWPROTO manually.  Such a define is
5351dnl generated in the Makefile generated by 'xmkmf'.  If we don't define
5352dnl NARROWPROTO, we will see the wrong function prototypes for X functions
5353dnl taking float or double parameters.
5354case $opsys in
5355  cygwin|gnu|gnu-linux|gnu-kfreebsd|freebsd|netbsd|openbsd)
5356    AC_DEFINE(NARROWPROTO, 1, [Define if system's imake configuration
5357      file defines 'NeedWidePrototypes' as 'NO'.])
5358  ;;
5359esac
5360
5361
5362dnl Used in process.c, this must be a loop, even if it only runs once.
5363AH_TEMPLATE(PTY_ITERATION, [How to iterate over PTYs.])
5364dnl Only used if !PTY_ITERATION.  Iterate from FIRST_PTY_LETTER to z,
5365dnl trying suffixes 0-16.
5366AH_TEMPLATE(FIRST_PTY_LETTER, [Letter to use in finding device name of
5367  first PTY, if PTYs are supported.])
5368AH_TEMPLATE(PTY_OPEN, [How to open a PTY, if non-standard.])
5369AH_TEMPLATE(PTY_NAME_SPRINTF, [How to get the device name of the control
5370  end of a PTY, if non-standard.])
5371AH_TEMPLATE(PTY_TTY_NAME_SPRINTF, [How to get device name of the tty
5372  end of a PTY, if non-standard.])
5373
5374case $opsys in
5375  aix4-2 )
5376    AC_DEFINE(PTY_ITERATION, [int c; for (c = 0; !c ; c++)])
5377    dnl You allocate a pty by opening /dev/ptc to get the master side.
5378    dnl To get the name of the slave side, you just ttyname() the master side.
5379    AC_DEFINE(PTY_NAME_SPRINTF, [strcpy (pty_name, "/dev/ptc");])
5380    AC_DEFINE(PTY_TTY_NAME_SPRINTF, [strcpy (pty_name, ttyname (fd));])
5381    ;;
5382
5383  cygwin )
5384    AC_DEFINE(PTY_ITERATION, [int i; for (i = 0; i < 1; i++)])
5385    dnl multi-line AC_DEFINEs are hard. :(
5386    AC_DEFINE(PTY_OPEN, [ 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)])
5387    AC_DEFINE(PTY_NAME_SPRINTF, [])
5388    AC_DEFINE(PTY_TTY_NAME_SPRINTF, [])
5389    ;;
5390
5391  gnu | qnxnto )
5392    AC_DEFINE(FIRST_PTY_LETTER, ['p'])
5393    ;;
5394
5395  gnu-linux | gnu-kfreebsd | dragonfly | freebsd | openbsd | netbsd | darwin | nacl )
5396    dnl if HAVE_GRANTPT
5397    if test "x$ac_cv_func_grantpt" = xyes; then
5398      AC_DEFINE(UNIX98_PTYS, 1, [Define if the system has Unix98 PTYs.])
5399      AC_DEFINE(PTY_ITERATION, [int i; for (i = 0; i < 1; i++)])
5400      dnl Note that grantpt and unlockpt may fork.  We must block SIGCHLD
5401      dnl to prevent sigchld_handler from intercepting the child's death.
5402      AC_DEFINE(PTY_TTY_NAME_SPRINTF, [{ 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); }])
5403      dnl if HAVE_POSIX_OPENPT
5404      if test "x$ac_cv_func_posix_openpt" = xyes; then
5405        AC_DEFINE(PTY_OPEN, [do { fd = posix_openpt (O_RDWR | O_CLOEXEC | O_NOCTTY); if (fd < 0 && errno == EINVAL) fd = posix_openpt (O_RDWR | O_NOCTTY); } while (false)])
5406        AC_DEFINE(PTY_NAME_SPRINTF, [])
5407      dnl if HAVE_GETPT
5408      elif test "x$ac_cv_func_getpt" = xyes; then
5409        AC_DEFINE(PTY_OPEN, [fd = getpt ()])
5410        AC_DEFINE(PTY_NAME_SPRINTF, [])
5411      else
5412        AC_DEFINE(PTY_NAME_SPRINTF, [strcpy (pty_name, "/dev/ptmx");])
5413      fi
5414    else
5415      AC_DEFINE(FIRST_PTY_LETTER, ['p'])
5416    fi
5417    ;;
5418
5419  hpux*)
5420    AC_DEFINE(FIRST_PTY_LETTER, ['p'])
5421    AC_DEFINE(PTY_NAME_SPRINTF, [sprintf (pty_name, "/dev/ptym/pty%c%x", c, i);])
5422    AC_DEFINE(PTY_TTY_NAME_SPRINTF, [sprintf (pty_name, "/dev/pty/tty%c%x", c, i);])
5423    ;;
5424
5425  solaris )
5426    dnl On SysVr4, grantpt(3) forks a subprocess, so do not use
5427    dnl O_CLOEXEC when opening the pty, and keep the SIGCHLD handler
5428    dnl from intercepting that death.  If any child but grantpt's should die
5429    dnl within, it should be caught after sigrelse(2).
5430    AC_DEFINE(PTY_OPEN, [fd = open (pty_name, O_RDWR | O_NONBLOCK)])
5431    AC_DEFINE(PTY_TTY_NAME_SPRINTF, [{ 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); }])
5432    ;;
5433
5434  unixware )
5435    dnl Comments are as per solaris.
5436    AC_DEFINE(PTY_OPEN, [fd = open (pty_name, O_RDWR | O_NONBLOCK)])
5437    AC_DEFINE(PTY_TTY_NAME_SPRINTF, [{ 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); }])
5438    ;;
5439
5440  haiku*)
5441    AC_DEFINE(FIRST_PTY_LETTER, ['s'])
5442    AC_DEFINE(PTY_NAME_SPRINTF, [])
5443    dnl on Haiku pty names aren't distinctive, thus the use of posix_openpt
5444    AC_DEFINE(PTY_OPEN, [fd = posix_openpt (O_RDWR | O_NONBLOCK)])
5445    AC_DEFINE(PTY_TTY_NAME_SPRINTF, [{ 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); }])
5446    ;;
5447esac
5448
5449
5450case $opsys in
5451  solaris | unixware )
5452    dnl This change means that we don't loop through allocate_pty too
5453    dnl many times in the (rare) event of a failure.
5454    AC_DEFINE(FIRST_PTY_LETTER, ['z'])
5455    AC_DEFINE(PTY_NAME_SPRINTF, [strcpy (pty_name, "/dev/ptmx");])
5456    dnl Push various streams modules onto a PTY channel.  Used in process.c.
5457    AC_DEFINE(SETUP_SLAVE_PTY, [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.])
5458    ;;
5459esac
5460
5461
5462AH_TEMPLATE(SIGNALS_VIA_CHARACTERS, [Make process_send_signal work by
5463"typing" a signal character on the pty.])
5464
5465case $opsys in
5466  dnl Perry Smith <pedz@ddivt1.austin.ibm.com> says this is correct for AIX.
5467  aix4-2 | cygwin | gnu | dragonfly | freebsd | netbsd | openbsd | darwin )
5468    AC_DEFINE(SIGNALS_VIA_CHARACTERS, 1)
5469    ;;
5470
5471  dnl 21 Jun 06: Eric Hanchrow <offby1@blarg.net> says this works.
5472  dnl FIXME Does gnu-kfreebsd have linux/version.h?  It seems unlikely...
5473  gnu-linux | gnu-kfreebsd )
5474
5475    AC_CACHE_CHECK([for signals via characters], [emacs_cv_signals_via_chars],
5476    [AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[
5477#include <linux/version.h>
5478#if LINUX_VERSION_CODE < 0x20400
5479# error "Linux version too old"
5480#endif
5481      ]], [[]])], emacs_cv_signals_via_chars=yes, emacs_cv_signals_via_chars=no)])
5482
5483    test "$emacs_cv_signals_via_chars" = yes && AC_DEFINE(SIGNALS_VIA_CHARACTERS, 1)
5484    ;;
5485esac
5486
5487
5488AH_TEMPLATE(TAB3, [Undocumented.])
5489
5490case $opsys in
5491  darwin) AC_DEFINE(TAB3, OXTABS) ;;
5492
5493  gnu | dragonfly | freebsd | netbsd | openbsd )
5494    AC_DEFINE(TABDLY, OXTABS, [Undocumented.])
5495    AC_DEFINE(TAB3, OXTABS)
5496    ;;
5497
5498  gnu-linux | gnu-kfreebsd )
5499    AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[
5500#ifndef __ia64__
5501# error "not ia64"
5502#endif
5503      ]], [[]])], AC_DEFINE(GC_MARK_SECONDARY_STACK(),
5504        [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)],
5505        [Mark a secondary stack, like the register stack on the ia64.]), [])
5506    ;;
5507
5508  hpux*)
5509    AC_DEFINE(RUN_TIME_REMAP, 1, [Define if emacs.c needs to call
5510      run_time_remap; for HPUX.])
5511    ;;
5512esac
5513
5514
5515dnl This won't be used automatically yet.  We also need to know, at least,
5516dnl that the stack is continuous.
5517AH_TEMPLATE(GC_SETJMP_WORKS, [Define if setjmp is known to save all
5518  registers relevant for conservative garbage collection in the jmp_buf.])
5519
5520
5521case $opsys in
5522  dnl Not all the architectures are tested, but there are Debian packages
5523  dnl for SCM and/or Guile on them, so the technique must work.  See also
5524  dnl comments in alloc.c concerning setjmp and gcc.
5525  dnl Fixme: it's probably safe to just use the GCC conditional below.
5526  gnu-linux | gnu-kfreebsd )
5527    AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[
5528#if defined __i386__ || defined __sparc__ || defined __mc68000__ \
5529  || defined __alpha__ || defined __mips__ || defined __s390__ \
5530  || defined __arm__ || defined __powerpc__ || defined __amd64__ \
5531  || defined __x86_64__ \
5532  || defined __ia64__ || defined __sh__
5533/* ok */
5534#else
5535# error "setjmp not known to work on this arch"
5536#endif
5537    ]], [[]])], AC_DEFINE(GC_SETJMP_WORKS, 1))
5538    ;;
5539esac
5540
5541
5542if test x$GCC = xyes; then
5543   dnl GC_SETJMP_WORKS is nearly always appropriate for GCC.
5544   AC_DEFINE(GC_SETJMP_WORKS, 1)
5545else
5546  case $opsys in
5547    aix* | dragonfly | freebsd | netbsd | openbsd | solaris )
5548      AC_DEFINE(GC_SETJMP_WORKS, 1)
5549      ;;
5550  esac
5551fi                              dnl GCC?
5552
5553dnl In a weird quirk, MS runtime uses _setjmp and longjmp.
5554AC_CACHE_CHECK([for _setjmp], [emacs_cv_func__setjmp],
5555  [AC_LINK_IFELSE(
5556     [AC_LANG_PROGRAM(
5557       [[#include <setjmp.h>
5558         #ifdef __MINGW32__
5559         # define _longjmp longjmp
5560         #endif
5561       ]],
5562       [[jmp_buf j;
5563	 if (! _setjmp (j))
5564	   _longjmp (j, 1);]])],
5565     [emacs_cv_func__setjmp=yes],
5566     [emacs_cv_func__setjmp=no])])
5567if test $emacs_cv_func__setjmp = yes; then
5568  AC_DEFINE([HAVE__SETJMP], 1, [Define to 1 if _setjmp and _longjmp work.])
5569fi
5570
5571# We need to preserve signal mask to handle C stack overflows.
5572AC_CACHE_CHECK([for sigsetjmp], [emacs_cv_func_sigsetjmp],
5573  [AC_LINK_IFELSE(
5574     [AC_LANG_PROGRAM(
5575       [[#include <setjmp.h>
5576       ]],
5577       [[sigjmp_buf j;
5578         if (! sigsetjmp (j, 1))
5579	   siglongjmp (j, 1);]])],
5580     [emacs_cv_func_sigsetjmp=yes],
5581     [emacs_cv_func_sigsetjmp=no])])
5582if test $emacs_cv_func_sigsetjmp = yes; then
5583  AC_DEFINE([HAVE_SIGSETJMP], 1,
5584    [Define to 1 if sigsetjmp and siglongjmp work.])
5585fi
5586
5587case $emacs_cv_func_sigsetjmp,$emacs_cv_alternate_stack,$opsys in
5588  yes,yes,* | *,*,mingw32)
5589    AC_DEFINE([HAVE_STACK_OVERFLOW_HANDLING], 1,
5590      [Define to 1 if C stack overflow can be handled in some cases.]);;
5591esac
5592
5593case $opsys in
5594  solaris | unixware )
5595    dnl TIOCGPGRP is broken in SysVr4, so we can't send signals to PTY
5596    dnl subprocesses the usual way.  But TIOCSIGNAL does work for PTYs,
5597    dnl and this is all we need.
5598    AC_DEFINE(TIOCSIGSEND, TIOCSIGNAL, [Some platforms redefine this.])
5599    ;;
5600esac
5601
5602
5603case $opsys in
5604  hpux* | solaris )
5605    dnl Used in xfaces.c.
5606    AC_DEFINE(XOS_NEEDS_TIME_H, 1, [Compensate for a bug in Xos.h on
5607      some systems, where it requires time.h.])
5608    ;;
5609esac
5610
5611
5612dnl Define symbols to identify the version of Unix this is.
5613dnl Define all the symbols that apply correctly.
5614AH_TEMPLATE(DOS_NT, [Define if the system is MS DOS or MS Windows.])
5615AH_TEMPLATE(MSDOS, [Define if the system is MS DOS.])
5616AH_TEMPLATE(USG, [Define if the system is compatible with System III.])
5617AH_TEMPLATE(USG5_4, [Define if the system is compatible with System V Release 4.])
5618
5619case $opsys in
5620  aix4-2)
5621    AC_DEFINE(USG, [])
5622    dnl This symbol should be defined on AIX Version 3  ???????
5623    AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[
5624#ifndef _AIX
5625# error "_AIX not defined"
5626#endif
5627    ]], [[]])], [], AC_DEFINE(_AIX, [], [Define if the system is AIX.]))
5628    ;;
5629
5630  cygwin)
5631    AC_DEFINE(CYGWIN, 1, [Define if the system is Cygwin.])
5632    ;;
5633
5634  darwin)
5635    dnl Not __APPLE__, as this may not be defined on non-macOS Darwin.
5636    dnl Not DARWIN, because Panther and lower CoreFoundation.h use DARWIN to
5637    dnl distinguish macOS from pure Darwin.
5638    AC_DEFINE(DARWIN_OS, [], [Define if the system is Darwin.])
5639    ;;
5640
5641  gnu-linux | gnu-kfreebsd )
5642    AC_DEFINE(USG, [])
5643    AC_DEFINE(GNU_LINUX, [], [Define if ths system is compatible with GNU/Linux.])
5644    ;;
5645
5646  hpux*)
5647    AC_DEFINE(USG, [])
5648    AC_DEFINE(HPUX, [], [Define if the system is HPUX.])
5649    ;;
5650
5651  mingw32)
5652    AC_DEFINE(DOS_NT, [])
5653    AC_DEFINE(WINDOWSNT, 1, [Define if compiling for native MS Windows.])
5654    if test "x$ac_enable_checking" != "x" ; then
5655      AC_DEFINE(EMACSDEBUG, 1, [Define to 1 to enable w32 debug facilities.])
5656    fi
5657    ;;
5658
5659  solaris)
5660    AC_DEFINE(USG, [])
5661    AC_DEFINE(USG5_4, [])
5662    AC_DEFINE(SOLARIS2, [], [Define if the system is Solaris.])
5663    ;;
5664
5665  unixware)
5666    AC_DEFINE(USG, [])
5667    AC_DEFINE(USG5_4, [])
5668    ;;
5669
5670  haiku)
5671    AC_DEFINE(HAIKU, [], [Define if the system is Haiku.])
5672    ;;
5673esac
5674
5675AC_SYS_POSIX_TERMIOS
5676if test $ac_cv_sys_posix_termios = yes; then
5677  AC_CHECK_SIZEOF([speed_t], [], [#include <termios.h>])
5678  dnl on Haiku, and possibly other platforms, speed_t is defined to
5679  dnl unsigned char, even when speeds greater than 200 baud are
5680  dnl defined.
5681
5682  if test ${ac_cv_sizeof_speed_t} -lt 2; then
5683    AC_DEFINE([HAVE_TINY_SPEED_T], [1],
5684        [Define to 1 if speed_t has some sort of nonsensically tiny size.])
5685  fi
5686fi
5687
5688AC_CACHE_CHECK([for usable FIONREAD], [emacs_cv_usable_FIONREAD],
5689  [case $opsys in
5690     aix4-2 | nacl)
5691       dnl BUILD 9008 - FIONREAD problem still exists in X-Windows.
5692       emacs_cv_usable_FIONREAD=no
5693       ;;
5694
5695     mingw32)
5696       emacs_cv_usable_FIONREAD=yes
5697       ;;
5698
5699     *)
5700       AC_COMPILE_IFELSE(
5701	 [AC_LANG_PROGRAM([[#include <sys/types.h>
5702			    #include <sys/ioctl.h>
5703			    #ifdef USG5_4
5704			    # include <sys/filio.h>
5705			    #endif
5706			  ]],
5707			  [[int foo = ioctl (0, FIONREAD, &foo);]])],
5708	 [emacs_cv_usable_FIONREAD=yes],
5709	 [emacs_cv_usable_FIONREAD=no])
5710       ;;
5711   esac])
5712if test $emacs_cv_usable_FIONREAD = yes; then
5713  AC_DEFINE([USABLE_FIONREAD], [1], [Define to 1 if FIONREAD is usable.])
5714
5715  if test $emacs_broken_SIGIO = no; then
5716    AC_CACHE_CHECK([for usable SIGIO], [emacs_cv_usable_SIGIO],
5717      [AC_COMPILE_IFELSE(
5718	 [AC_LANG_PROGRAM([[#include <fcntl.h>
5719			    #include <signal.h>
5720			  ]],
5721			  [[int foo = SIGIO | F_SETFL | FASYNC;]])],
5722	 [emacs_cv_usable_SIGIO=yes],
5723	 [emacs_cv_usable_SIGIO=no])],
5724      [emacs_cv_usable_SIGIO=yes],
5725      [emacs_cv_usable_SIGIO=no])
5726    if test $emacs_cv_usable_SIGIO = yes; then
5727      AC_DEFINE([USABLE_SIGIO], [1], [Define to 1 if SIGIO is usable.])
5728    fi
5729  fi
5730
5731  if test $emacs_broken_SIGIO = no && test $emacs_cv_usable_SIGIO = no; then
5732    AC_CACHE_CHECK([for usable SIGPOLL], [emacs_cv_usable_SIGPOLL],
5733      [AC_COMPILE_IFELSE(
5734	 [AC_LANG_PROGRAM([[#include <fcntl.h>
5735			    #include <signal.h>
5736			  ]],
5737			  [[int foo = SIGPOLL | F_SETFL;]])],
5738	 [emacs_cv_usable_SIGPOLL=yes],
5739	 [emacs_cv_usable_SIGPOLL=no])],
5740      [emacs_cv_usable_SIGPOLL=yes],
5741      [emacs_cv_usable_SIGPOLL=no])
5742    if test $emacs_cv_usable_SIGPOLL = yes; then
5743      AC_DEFINE([USABLE_SIGPOLL], [1], [Define to 1 if SIGPOLL is usable but SIGIO is not.])
5744    fi
5745  fi
5746fi
5747
5748case $opsys in
5749  hpux11)
5750    dnl It works to open the pty's tty in the parent (Emacs), then
5751    dnl close and reopen it in the child.
5752    AC_DEFINE(USG_SUBTTY_WORKS, 1, [Define for USG systems where it
5753      works to open a pty's tty in the parent process, then close and
5754      reopen it in the child.])
5755    ;;
5756
5757  solaris)
5758    AC_DEFINE(_STRUCTURED_PROC, 1, [Needed for system_process_attributes
5759      on Solaris.])
5760    ;;
5761esac
5762
5763# Set up the CFLAGS for real compilation, so we can substitute it.
5764CFLAGS="$REAL_CFLAGS"
5765CPPFLAGS="$REAL_CPPFLAGS"
5766LIBS="$REAL_LIBS"
5767
5768## Hack to detect a buggy GCC version.
5769if test "$GCC" = yes && \
5770   $CC --version 2> /dev/null | grep 'gcc.* 4.5.0' >/dev/null; then
5771  case $CFLAGS in
5772    *-fno-optimize-sibling-calls*) ;;
5773    *-O@<:@23@:>@*)
5774      AC_MSG_ERROR([GCC 4.5.0 has problems compiling Emacs; see etc/PROBLEMS.]);;
5775  esac
5776fi
5777
5778version=$PACKAGE_VERSION
5779
5780copyright="Copyright (C) 2021 Free Software Foundation, Inc."
5781AC_DEFINE_UNQUOTED(COPYRIGHT, ["$copyright"],
5782  [Short copyright string for this version of Emacs.])
5783AC_SUBST(copyright)
5784
5785### Specify what sort of things we'll be editing into Makefile and config.h.
5786### Use configuration here uncanonicalized to avoid exceeding size limits.
5787AC_SUBST(version)
5788AC_SUBST(configuration)
5789## Unused?
5790AC_SUBST(canonical)
5791AC_SUBST(srcdir)
5792AC_SUBST(prefix)
5793AC_SUBST(exec_prefix)
5794AC_SUBST(bindir)
5795AC_SUBST(datadir)
5796AC_SUBST(gsettingsschemadir)
5797AC_SUBST(sharedstatedir)
5798AC_SUBST(libexecdir)
5799AC_SUBST(mandir)
5800AC_SUBST(infodir)
5801AC_SUBST(lispdirrel)
5802AC_SUBST(lispdir)
5803AC_SUBST(standardlisppath)
5804AC_SUBST(locallisppath)
5805AC_SUBST(lisppath)
5806AC_SUBST(x_default_search_path)
5807AC_SUBST(etcdir)
5808AC_SUBST(archlibdir)
5809AC_SUBST(etcdocdir)
5810AC_SUBST(bitmapdir)
5811AC_SUBST(gamedir)
5812AC_SUBST(gameuser)
5813AC_SUBST(gamegroup)
5814## FIXME? Nothing uses @LD_SWITCH_X_SITE@.
5815## src/Makefile.in did add LD_SWITCH_X_SITE (as a cpp define) to the
5816## end of LIBX_BASE, but nothing ever set it.
5817AC_SUBST(LD_SWITCH_X_SITE)
5818AC_SUBST(C_SWITCH_X_SITE)
5819AC_SUBST(GNUSTEP_CFLAGS)
5820AC_SUBST(CFLAGS)
5821## Used in lwlib/Makefile.in.
5822AC_SUBST(X_TOOLKIT_TYPE)
5823AC_SUBST(ns_appdir)
5824AC_SUBST(ns_appbindir)
5825AC_SUBST(ns_applibexecdir)
5826AC_SUBST(ns_applibdir)
5827AC_SUBST(ns_appresdir)
5828AC_SUBST(ns_appsrc)
5829AC_SUBST(GNU_OBJC_CFLAGS)
5830AC_SUBST(OTHER_FILES)
5831
5832if test -n "${term_header}"; then
5833    AC_DEFINE_UNQUOTED(TERM_HEADER, "${term_header}",
5834        [Define to the header for the built-in window system.])
5835fi
5836
5837AC_DEFINE_UNQUOTED(EMACS_CONFIGURATION,  "${canonical}",
5838		   [Define to the canonical Emacs configuration name.])
5839AC_DEFINE_UNQUOTED(EMACS_CONFIG_OPTIONS, "${emacs_config_options}",
5840		   [Define to the options passed to configure.])
5841
5842XMENU_OBJ=
5843XOBJ=
5844FONT_OBJ=
5845if test "${HAVE_X_WINDOWS}" = "yes" ; then
5846  AC_DEFINE(HAVE_X_WINDOWS, 1,
5847	    [Define to 1 if you want to use the X window system.])
5848  XMENU_OBJ=xmenu.o
5849  XOBJ="xterm.o xfns.o xselect.o xrdb.o xsmfns.o xsettings.o"
5850  FONT_OBJ=xfont.o
5851  if test "$HAVE_CAIRO" = "yes"; then
5852    FONT_OBJ="$FONT_OBJ ftfont.o ftcrfont.o"
5853  elif test "$HAVE_XFT" = "yes"; then
5854    FONT_OBJ="$FONT_OBJ ftfont.o xftfont.o"
5855  elif test "$HAVE_FREETYPE" = "yes"; then
5856    FONT_OBJ="$FONT_OBJ ftfont.o"
5857  fi
5858fi
5859
5860if test "${window_system}" = "pgtk"; then
5861   FONT_OBJ="ftfont.o ftcrfont.o"
5862fi
5863
5864if test "${HAVE_BE_APP}" = "yes" ; then
5865  if test "${HAVE_CAIRO}" = "yes"; then
5866    FONT_OBJ="$FONT_OBJ ftfont.o ftcrfont.o"
5867  fi
5868fi
5869
5870if test "${HAVE_HARFBUZZ}" = "yes" ; then
5871  FONT_OBJ="$FONT_OBJ hbfont.o"
5872fi
5873AC_SUBST(FONT_OBJ)
5874AC_SUBST(XMENU_OBJ)
5875AC_SUBST(XOBJ)
5876AC_SUBST(FONT_OBJ)
5877
5878WIDGET_OBJ=
5879MOTIF_LIBW=
5880if test "${USE_X_TOOLKIT}" != "none" ; then
5881  WIDGET_OBJ=widget.o
5882  AC_DEFINE(USE_X_TOOLKIT, 1, [Define to 1 if using an X toolkit.])
5883  if test "${USE_X_TOOLKIT}" = "LUCID"; then
5884    AC_DEFINE(USE_LUCID, 1, [Define to 1 if using the Lucid X toolkit.])
5885  elif test "${USE_X_TOOLKIT}" = "MOTIF"; then
5886    AC_DEFINE(USE_MOTIF, 1, [Define to 1 if using the Motif X toolkit.])
5887    MOTIF_LIBW=-lXm
5888    case "$opsys" in
5889      gnu-linux)
5890        ## Paul Abrahams <abrahams at equinox.shaysnet.com> says this is needed.
5891        MOTIF_LIBW="$MOTIF_LIBW -lXpm"
5892        ;;
5893
5894      unixware)
5895        ## Richard Anthony Ryan <ryanr at ellingtn.ftc.nrcs.usda.gov>
5896        ## says -lXimp is needed in UNIX_SV ... 4.2 1.1.2.
5897        MOTIF_LIBW="MOTIF_LIBW -lXimp"
5898        ;;
5899
5900      aix4-2)
5901        ## olson@mcs.anl.gov says -li18n is needed by -lXm.
5902        MOTIF_LIBW="$MOTIF_LIBW -li18n"
5903        ;;
5904    esac
5905    MOTIF_LIBW="$MOTIF_LIBW $LIBXP"
5906  fi
5907fi
5908AC_SUBST(WIDGET_OBJ)
5909
5910TOOLKIT_LIBW=
5911case "$USE_X_TOOLKIT" in
5912  MOTIF) TOOLKIT_LIBW="$MOTIF_LIBW" ;;
5913  LUCID) TOOLKIT_LIBW="$LUCID_LIBW" ;;
5914  none) test "x$HAVE_GTK" = "xyes" && TOOLKIT_LIBW="$GTK_LIBS" ;;
5915esac
5916if test "$HAVE_XWIDGETS" = "yes"; then
5917  TOOLKIT_LIBW="$TOOLKIT_LIBW -lXcomposite"
5918fi
5919AC_SUBST(TOOLKIT_LIBW)
5920
5921if test "${opsys}" != "mingw32"; then
5922  if test "$USE_X_TOOLKIT" = "none"; then
5923    LIBXT_OTHER="\$(LIBXSM)"
5924  else
5925    LIBXT_OTHER="\$(LIBXMU) -lXt \$(LIBXTR6) -lXext"
5926  fi
5927fi
5928AC_SUBST(LIBXT_OTHER)
5929
5930if test "${HAVE_X11}" = "yes" ; then
5931  AC_DEFINE(HAVE_X11, 1,
5932	    [Define to 1 if you want to use version 11 of X windows.])
5933  LIBX_OTHER="\$(LIBXT) \$(LIBX_EXTRA)"
5934else
5935  LIBX_OTHER=
5936fi
5937AC_SUBST(LIBX_OTHER)
5938
5939HAVE_OLDXMENU=no
5940if test "$HAVE_GTK" = yes || test "$HAVE_X11" != yes; then
5941  LIBXMENU=
5942elif test "$USE_X_TOOLKIT" = none; then
5943  HAVE_OLDXMENU=yes
5944  LIBXMENU='$(oldXMenudir)/libXMenu11.a'
5945  AUTODEPEND_PARENTS="$AUTODEPEND_PARENTS oldXMenu"
5946else
5947  LIBXMENU='$(lwlibdir)/liblw.a'
5948  AUTODEPEND_PARENTS="$AUTODEPEND_PARENTS lwlib"
5949fi
5950AC_SUBST(LIBXMENU)
5951
5952AC_CACHE_CHECK([for struct alignment],
5953  [emacs_cv_struct_alignment],
5954  [AC_COMPILE_IFELSE(
5955     [AC_LANG_PROGRAM([[#include <stddef.h>
5956			struct s { char c; } __attribute__ ((aligned (8)));
5957			struct t { char c; struct s s; };
5958			char verify[offsetof (struct t, s) == 8 ? 1 : -1];
5959		      ]])],
5960     [emacs_cv_struct_alignment=yes],
5961     [emacs_cv_struct_alignment=no])])
5962if test "$emacs_cv_struct_alignment" = yes; then
5963  AC_DEFINE([HAVE_STRUCT_ATTRIBUTE_ALIGNED], 1,
5964    [Define to 1 if 'struct __attribute__ ((aligned (N)))' aligns the
5965     structure to an N-byte boundary.])
5966fi
5967
5968AC_C_TYPEOF
5969
5970AC_CACHE_CHECK([for statement expressions],
5971  [emacs_cv_statement_expressions],
5972  [AC_COMPILE_IFELSE(
5973     [AC_LANG_PROGRAM([], [[return ({ int x = 5; x-x; });]])],
5974     [emacs_cv_statement_expressions=yes],
5975     [emacs_cv_statement_expressions=no])])
5976if test "$emacs_cv_statement_expressions" = yes; then
5977  AC_DEFINE([HAVE_STATEMENT_EXPRESSIONS], 1,
5978    [Define to 1 if statement expressions work.])
5979fi
5980
5981if test "${GNU_MALLOC}" = "yes" ; then
5982  AC_DEFINE(GNU_MALLOC, 1,
5983	    [Define to 1 if you want to use the GNU memory allocator.])
5984fi
5985
5986RALLOC_OBJ=
5987if test "${REL_ALLOC}" = "yes" ; then
5988  AC_DEFINE(REL_ALLOC, 1,
5989	    [Define REL_ALLOC if you want to use the relocating allocator for
5990	     buffer space.])
5991
5992  test "$system_malloc" != "yes" && RALLOC_OBJ=ralloc.o
5993fi
5994AC_SUBST(RALLOC_OBJ)
5995
5996if test "$opsys" = "cygwin"; then
5997  CYGWIN_OBJ="cygw32.o"
5998  ## Cygwin differs because of its unexec().
5999  PRE_ALLOC_OBJ=
6000  POST_ALLOC_OBJ=lastfile.o
6001elif test "$opsys" = "mingw32"; then
6002  CYGWIN_OBJ=
6003  PRE_ALLOC_OBJ=
6004  POST_ALLOC_OBJ=lastfile.o
6005else
6006  CYGWIN_OBJ=
6007  PRE_ALLOC_OBJ=lastfile.o
6008  POST_ALLOC_OBJ=
6009fi
6010AC_SUBST(CYGWIN_OBJ)
6011AC_SUBST(PRE_ALLOC_OBJ)
6012AC_SUBST(POST_ALLOC_OBJ)
6013
6014dnl Call this 'FORTIFY_SOUR' so that it sorts before the 'FORTIFY_SOURCE'
6015dnl verbatim defined above.  The tricky name is apropos, as this hack
6016dnl makes Fortify go sour!
6017AH_VERBATIM([FORTIFY_SOUR],
6018[/* Without the following workaround, Emacs runs slowly on OS X 10.8.
6019   The workaround disables some useful run-time checking, so it
6020   should be conditional to the platforms with the performance bug.
6021   Perhaps Apple will fix this some day; also see m4/extern-inline.m4.  */
6022#if defined __APPLE__ && defined __GNUC__
6023# ifndef _DONT_USE_CTYPE_INLINE_
6024#  define _DONT_USE_CTYPE_INLINE_
6025# endif
6026# ifndef _FORTIFY_SOURCE
6027#  define _FORTIFY_SOURCE 0
6028# endif
6029#endif
6030])
6031
6032# If user asks to omit features, disable optional features that gnulib
6033# might otherwise enable.
6034if test "$with_features" = no && test "$enable_acl" != yes; then
6035  enable_acl=no
6036fi
6037
6038# Configure gnulib.  Although this does not affect CFLAGS or LIBS permanently.
6039# it temporarily reverts them to their pre-pkg-config values,
6040# because gnulib needs to work with both src (which uses the
6041# pkg-config stuff) and lib-src (which does not).  For example, gnulib
6042# may need to determine whether LIB_CLOCK_GETTIME should contain -lrt,
6043# and it therefore needs to run in an environment where LIBS does not
6044# already contain -lrt merely because 'pkg-config --libs' printed '-lrt'
6045# for some package unrelated to lib-src.
6046SAVE_CFLAGS=$CFLAGS
6047SAVE_LIBS=$LIBS
6048CFLAGS=$pre_PKG_CONFIG_CFLAGS
6049LIBS="$LIB_PTHREAD $pre_PKG_CONFIG_LIBS"
6050gl_ASSERT_NO_GNULIB_POSIXCHECK
6051gl_ASSERT_NO_GNULIB_TESTS
6052gl_EEMALLOC
6053gl_INIT
6054CFLAGS=$SAVE_CFLAGS
6055LIBS=$SAVE_LIBS
6056
6057# timer_getoverrun needs the same library as timer_settime
6058OLD_LIBS=$LIBS
6059LIBS="$LIB_TIMER_TIME $LIBS"
6060AC_CHECK_FUNCS(timer_getoverrun)
6061LIBS=$OLD_LIBS
6062
6063if test "${opsys}" = "mingw32"; then
6064  CPPFLAGS="$CPPFLAGS -DUSE_CRT_DLL=1 -I \${abs_top_srcdir}/nt/inc"
6065  # Remove unneeded switches from the value of CC that goes to Makefiles
6066  CC=`AS_ECHO(["$CC"]) | sed -e "s,$GCC_TEST_OPTIONS,,"`
6067fi
6068
6069case "$opsys" in
6070  aix4-2) LD_SWITCH_SYSTEM_TEMACS="-Wl,-bnodelcsect" ;;
6071
6072  cygwin) LD_SWITCH_SYSTEM_TEMACS="-Wl,-stack,0x00800000" ;;
6073
6074  darwin)
6075   if test "$HAVE_NS" = "yes"; then
6076     libs_nsgui="-framework AppKit"
6077     if test "$NS_IMPL_COCOA" = "yes"; then
6078        libs_nsgui="$libs_nsgui -framework IOKit -framework Carbon \
6079                    -framework IOSurface -framework QuartzCore"
6080     fi
6081   else
6082     libs_nsgui=
6083   fi
6084   LD_SWITCH_SYSTEM_TEMACS=$libs_nsgui
6085   ## The -headerpad option tells ld (see man page) to leave room at the
6086   ## end of the header for adding load commands.  Needed for dumping.
6087   ## 0x1000 is enough for roughly 52 load commands on the x86_64
6088   ## architecture (where they are 78 bytes each). The actual number of
6089   ## load commands added is not consistent but normally ranges from
6090   ## about 14 to about 34. Setting it high gets us plenty of slop and
6091   ## only costs about 1.5K of wasted binary space.
6092   headerpad_extra=1000
6093   if test "$with_unexec" = yes; then
6094     LD_SWITCH_SYSTEM_TEMACS="-fno-pie $LD_SWITCH_SYSTEM_TEMACS -Xlinker -headerpad -Xlinker $headerpad_extra"
6095   fi
6096
6097   ## This is here because src/Makefile.in did some extra fiddling around
6098   ## with LD_SWITCH_SYSTEM.  It seems cleaner to put this in
6099   ## LD_SWITCH_SYSTEM_TEMACS instead,
6100   test "x$LD_SWITCH_SYSTEM" = "x" && test "x$GCC" != "xyes" && \
6101     LD_SWITCH_SYSTEM_TEMACS="-X $LD_SWITCH_SYSTEM_TEMACS"
6102   ;;
6103
6104  ## LD_SWITCH_X_SITE_RPATH is a -rpath option saying where to
6105  ## find X at run-time.
6106  ## When handled by cpp, this was in LD_SWITCH_SYSTEM.  However, at the
6107  ## point where configure sourced the s/*.h file, LD_SWITCH_X_SITE_RPATH
6108  ## had not yet been defined and was expanded to null.  Hence LD_SWITCH_SYSTEM
6109  ## had different values in configure (in ac_link) and src/Makefile.in.
6110  ## It seems clearer therefore to put this piece in LD_SWITCH_SYSTEM_TEMACS.
6111  gnu*) LD_SWITCH_SYSTEM_TEMACS="\$(LD_SWITCH_X_SITE_RPATH)" ;;
6112
6113  mingw32)
6114   ## Is it any better under MinGW64 to relocate emacs into higher addresses?
6115   case "$canonical" in
6116     x86_64-*-*) LD_SWITCH_SYSTEM_TEMACS="-Wl,-stack,0x00800000 -Wl,-heap,0x00100000 -Wl,-image-base,0x400000000 -Wl,-entry,__start -Wl,-Map,./temacs.map" ;;
6117     *) LD_SWITCH_SYSTEM_TEMACS="-Wl,-stack,0x00800000 -Wl,-heap,0x00100000 -Wl,-image-base,0x01000000 -Wl,-entry,__start -Wl,-Map,./temacs.map" ;;
6118   esac
6119   ## If they want unexec, disable Windows ASLR for the Emacs binary
6120   if test "$with_dumping" = "unexec"; then
6121      case "$canonical" in
6122        x86_64-*-*) LD_SWITCH_SYSTEM_TEMACS="$LD_SWITCH_SYSTEM_TEMACS -Wl,-disable-dynamicbase -Wl,-disable-high-entropy-va -Wl,-default-image-base-low" ;;
6123        *) LD_SWITCH_SYSTEM_TEMACS="$LD_SWITCH_SYSTEM_TEMACS -Wl,-disable-dynamicbase" ;;
6124      esac
6125   fi
6126   ;;
6127
6128  *) LD_SWITCH_SYSTEM_TEMACS= ;;
6129esac
6130
6131# -no-pie or -nopie fixes a temacs segfault on Gentoo, OpenBSD,
6132# Ubuntu, and other systems with "hardened" GCC configurations for
6133# some reason (Bug#18784).  We don't know why this works, but not
6134# segfaulting is better than segfaulting.  Use ac_c_werror_flag=yes
6135# when trying the option, otherwise clang keeps warning that it does
6136# not understand it, and pre-4.6 GCC has a similar problem
6137# (Bug#20338).  Prefer -no-pie to -nopie, as -no-pie is the
6138# spelling used by GCC 6.1.0 and later (Bug#24682).
6139AC_CACHE_CHECK(
6140  [for $CC option to disable position independent executables],
6141  [emacs_cv_prog_cc_no_pie],
6142  [if test $with_unexec = no; then
6143     emacs_cv_prog_cc_no_pie='not needed'
6144   else
6145     emacs_save_c_werror_flag=$ac_c_werror_flag
6146     emacs_save_LDFLAGS=$LDFLAGS
6147     ac_c_werror_flag=yes
6148     for emacs_cv_prog_cc_no_pie in -no-pie -nopie no; do
6149       test $emacs_cv_prog_cc_no_pie = no && break
6150       LDFLAGS="$emacs_save_LDFLAGS $emacs_cv_prog_cc_no_pie"
6151       AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [break])
6152     done
6153     ac_c_werror_flag=$emacs_save_c_werror_flag
6154     LDFLAGS=$emacs_save_LDFLAGS
6155   fi])
6156case $emacs_cv_prog_cc_no_pie in
6157  -*)
6158    LD_SWITCH_SYSTEM_TEMACS="$LD_SWITCH_SYSTEM_TEMACS $emacs_cv_prog_cc_no_pie"
6159    ;;
6160esac
6161
6162if test x$ac_enable_profiling != x ; then
6163  case $opsys in
6164    *freebsd | gnu-linux) ;;
6165    *) LD_SWITCH_SYSTEM_TEMACS="$LD_SWITCH_SYSTEM_TEMACS -pg" ;;
6166  esac
6167fi
6168
6169LD_SWITCH_SYSTEM_TEMACS="$LDFLAGS_NOCOMBRELOC $LD_SWITCH_SYSTEM_TEMACS"
6170
6171AC_SUBST(LD_SWITCH_SYSTEM_TEMACS)
6172
6173## Common for all window systems
6174if test "$window_system" != "none"; then
6175  AC_DEFINE(HAVE_WINDOW_SYSTEM, 1, [Define if you have a window system.])
6176  AC_DEFINE(POLL_FOR_INPUT, 1, [Define if you poll periodically to detect C-g.])
6177  WINDOW_SYSTEM_OBJ="fontset.o fringe.o image.o"
6178fi
6179
6180AC_SUBST(WINDOW_SYSTEM_OBJ)
6181
6182AH_TOP([/* GNU Emacs site configuration template file.
6183
6184Copyright (C) 1988, 1993-1994, 1999-2002, 2004-2021
6185  Free Software Foundation, Inc.
6186
6187This file is part of GNU Emacs.
6188
6189GNU Emacs is free software: you can redistribute it and/or modify
6190it under the terms of the GNU General Public License as published by
6191the Free Software Foundation, either version 3 of the License, or (at
6192your option) any later version.
6193
6194GNU Emacs is distributed in the hope that it will be useful,
6195but WITHOUT ANY WARRANTY; without even the implied warranty of
6196MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6197GNU General Public License for more details.
6198
6199You should have received a copy of the GNU General Public License
6200along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
6201
6202
6203/* No code in Emacs #includes config.h twice, but some bits of code
6204   intended to work with other packages as well (like gmalloc.c)
6205   think they can include it as many times as they like.  */
6206#ifndef EMACS_CONFIG_H
6207#define EMACS_CONFIG_H
6208])dnl
6209
6210AH_BOTTOM([#include <conf_post.h>
6211
6212#endif /* EMACS_CONFIG_H */
6213
6214/*
6215Local Variables:
6216mode: c
6217End:
6218*/
6219])dnl
6220
6221#### Report on what we decided to do.
6222#### Report GTK as a toolkit, even if it doesn't use Xt.
6223#### It makes printing result more understandable as using GTK sets
6224#### toolkit_scroll_bars to yes by default.
6225if test "${HAVE_GTK}" = "yes"; then
6226  USE_X_TOOLKIT="$USE_GTK_TOOLKIT"
6227fi
6228
6229if test $USE_ACL -ne 0; then
6230  ACL_SUMMARY="yes $LIB_ACL"
6231else
6232  ACL_SUMMARY=no
6233fi
6234
6235if test -z "$GMP_H"; then
6236  HAVE_GMP=yes
6237else
6238  HAVE_GMP=no
6239fi
6240
6241emacs_standard_dirs='Standard dirs'
6242AS_ECHO(["
6243Configured for '${canonical}'.
6244
6245  Where should the build process find the source code?    ${srcdir}
6246  What compiler should emacs be built with?               ${CC} ${CFLAGS}
6247  Should Emacs use the GNU version of malloc?             ${GNU_MALLOC}${GNU_MALLOC_reason}
6248  Should Emacs use a relocating allocator for buffers?    ${REL_ALLOC}
6249  Should Emacs use mmap(2) for buffer allocation?         $use_mmap_for_buffers
6250  What window system should Emacs use?                    ${window_system}
6251  What toolkit should Emacs use?                          ${USE_X_TOOLKIT}
6252  Where do we find X Windows header files?                ${x_includes:-$emacs_standard_dirs}
6253  Where do we find X Windows libraries?                   ${x_libraries:-$emacs_standard_dirs}"])
6254
6255#### Please respect alphabetical ordering when making additions.
6256optsep=
6257emacs_config_features=
6258for opt in ACL BE_APP CAIRO DBUS FREETYPE GCONF GIF GLIB GMP GNUTLS GPM GSETTINGS \
6259 HARFBUZZ IMAGEMAGICK JPEG JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 \
6260 M17N_FLT MODULES NATIVE_COMP NOTIFY NS OLDXMENU PDUMPER PGTK PNG RSVG SECCOMP \
6261 SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS \
6262 UNEXEC WEBP X11 XAW3D XDBE XFT XIM XINPUT2 XPM XWIDGETS X_TOOLKIT \
6263 ZLIB; do
6264
6265    case $opt in
6266      PDUMPER) val=${with_pdumper} ;;
6267      UNEXEC) val=${with_unexec} ;;
6268      GLIB) val=${emacs_cv_links_glib} ;;
6269      NOTIFY|ACL) eval val=\${${opt}_SUMMARY} ;;
6270      TOOLKIT_SCROLL_BARS|X_TOOLKIT) eval val=\${USE_$opt} ;;
6271      THREADS) val=${threads_enabled} ;;
6272      *) eval val=\${HAVE_$opt} ;;
6273    esac
6274    case x$val in
6275      xno|xnone|x) continue ;;
6276    esac
6277    case $opt in
6278      X_TOOLKIT)
6279        case $val in
6280          GTK*|LUCID|MOTIF) opt=$val ;;
6281          *) continue ;;
6282        esac
6283      ;;
6284      NOTIFY)
6285        case $val in
6286          *lkqueue*) opt="$opt LIBKQUEUE" ;;
6287          *kqueue*) opt="$opt KQUEUE" ;;
6288          *inotify*) opt="$opt INOTIFY" ;;
6289          *gfile*) opt="$opt GFILENOTIFY" ;;
6290          *w32*) opt="$opt W32NOTIFY" ;;
6291        esac
6292      ;;
6293    esac
6294    AS_VAR_APPEND([emacs_config_features], ["$optsep$opt"])
6295    optsep=' '
6296done
6297AC_DEFINE_UNQUOTED(EMACS_CONFIG_FEATURES, "${emacs_config_features}",
6298  [Summary of some of the main features enabled by configure.])
6299
6300AS_ECHO(["  Does Emacs use -lXaw3d?                                 ${HAVE_XAW3D}
6301  Does Emacs use -lXpm?                                   ${HAVE_XPM}
6302  Does Emacs use -ljpeg?                                  ${HAVE_JPEG}
6303  Does Emacs use -ltiff?                                  ${HAVE_TIFF}
6304  Does Emacs use a gif library?                           ${HAVE_GIF} $LIBGIF
6305  Does Emacs use a png library?                           ${HAVE_PNG} $LIBPNG
6306  Does Emacs use -lrsvg-2?                                ${HAVE_RSVG}
6307  Does Emacs use -lwebp?                                  ${HAVE_WEBP}
6308  Does Emacs use -lsqlite3?                               ${HAVE_SQLITE3}
6309  Does Emacs use cairo?                                   ${HAVE_CAIRO}
6310  Does Emacs use -llcms2?                                 ${HAVE_LCMS2}
6311  Does Emacs use imagemagick?                             ${HAVE_IMAGEMAGICK}
6312  Does Emacs use native APIs for images?                  ${NATIVE_IMAGE_API}
6313  Does Emacs support sound?                               ${HAVE_SOUND}
6314  Does Emacs use -lgpm?                                   ${HAVE_GPM}
6315  Does Emacs use -ldbus?                                  ${HAVE_DBUS}
6316  Does Emacs use -lgconf?                                 ${HAVE_GCONF}
6317  Does Emacs use GSettings?                               ${HAVE_GSETTINGS}
6318  Does Emacs use a file notification library?             ${NOTIFY_SUMMARY}
6319  Does Emacs use access control lists?                    ${ACL_SUMMARY}
6320  Does Emacs use -lselinux?                               ${HAVE_LIBSELINUX}
6321  Does Emacs use -lgnutls?                                ${HAVE_GNUTLS}
6322  Does Emacs use -lxml2?                                  ${HAVE_LIBXML2}
6323  Does Emacs use -lfreetype?                              ${HAVE_FREETYPE}
6324  Does Emacs use HarfBuzz?                                ${HAVE_HARFBUZZ}
6325  Does Emacs use -lm17n-flt?                              ${HAVE_M17N_FLT}
6326  Does Emacs use -lotf?                                   ${HAVE_LIBOTF}
6327  Does Emacs use -lxft?                                   ${HAVE_XFT}
6328  Does Emacs use -lsystemd?                               ${HAVE_LIBSYSTEMD}
6329  Does Emacs use -ljansson?                               ${HAVE_JSON}
6330  Does Emacs use the GMP library?                         ${HAVE_GMP}
6331  Does Emacs directly use zlib?                           ${HAVE_ZLIB}
6332  Does Emacs have dynamic modules support?                ${HAVE_MODULES}
6333  Does Emacs use toolkit scroll bars?                     ${USE_TOOLKIT_SCROLL_BARS}
6334  Does Emacs support Xwidgets?                            ${HAVE_XWIDGETS}
6335  Does Emacs have threading support in lisp?              ${threads_enabled}
6336  Does Emacs support the portable dumper?                 ${with_pdumper}
6337  Does Emacs support legacy unexec dumping?               ${with_unexec}
6338  Which dumping strategy does Emacs use?                  ${with_dumping}
6339  Does Emacs have native lisp compiler?                   ${HAVE_NATIVE_COMP}
6340  Does Emacs use version 2 of the the X Input Extension?  ${HAVE_XINPUT2}
6341"])
6342
6343if test -n "${EMACSDATA}"; then
6344   AS_ECHO(["  Environment variable EMACSDATA set to:                  $EMACSDATA"])
6345fi
6346if test -n "${EMACSDOC}"; then
6347   AS_ECHO(["  Environment variable EMACSDOC set to:                   $EMACSDOC"])
6348fi
6349
6350echo
6351
6352if test "$HAVE_NS" = "yes"; then
6353   echo
6354   AS_ECHO(["Run '${MAKE-make}' to build Emacs, then run 'src/emacs' to test it.
6355Run '${MAKE-make} install' in order to build an application bundle.
6356The application will go to nextstep/Emacs.app and can be run or moved
6357from there."])
6358   if test "$EN_NS_SELF_CONTAINED" = "yes"; then
6359      echo "The application will be fully self-contained."
6360    else
6361      AS_ECHO(["The lisp resources for the application will be installed under ${prefix}.
6362You may need to run \"${MAKE-make} install\" with sudo.  The application will fail
6363to run if these resources are not installed."])
6364   fi
6365   echo
6366fi
6367
6368case $opsys,$emacs_uname_r in
6369  cygwin,1.5.*)
6370    AC_MSG_WARN([[building Emacs on Cygwin 1.5 is not supported.]])
6371           echo
6372	   ;;
6373  cygwin,3.0.[[0-7]]'('* | cygwin,3.1.[[0-2]]'('*)
6374    AC_DEFINE([HAVE_CYGWIN_O_PATH_BUG], 1,
6375      [Define to 1 if opening a FIFO, socket, or symlink with O_PATH is buggy.]);;
6376esac
6377
6378# Remove any trailing slashes in these variables.
6379case $prefix in
6380  */) prefix=`AS_DIRNAME(["$prefix."])`;;
6381esac
6382case $exec_prefix in
6383  */) exec_prefix=`AS_DIRNAME(["$exec_prefix."])`;;
6384esac
6385
6386if test "$HAVE_NS" = "yes"; then
6387  if test "$NS_IMPL_GNUSTEP" = yes; then
6388    AC_CONFIG_FILES([nextstep/GNUstep/Emacs.base/Resources/Info-gnustep.plist:nextstep/templates/Info-gnustep.plist.in \
6389      nextstep/GNUstep/Emacs.base/Resources/Emacs.desktop:nextstep/templates/Emacs.desktop.in])
6390    ns_check_file=Resources/Info-gnustep.plist
6391  else
6392    AC_CONFIG_FILES([nextstep/Cocoa/Emacs.base/Contents/Info.plist:nextstep/templates/Info.plist.in \
6393      nextstep/Cocoa/Emacs.base/Contents/Resources/English.lproj/InfoPlist.strings:nextstep/templates/InfoPlist.strings.in])
6394    ns_check_file=Contents/Info.plist
6395  fi
6396  AC_SUBST(ns_check_file)
6397fi
6398
6399AC_CONFIG_FILES([Makefile lib/gnulib.mk])
6400
6401dnl config.status treats $srcdir specially, so I think this is ok...
6402AC_CONFIG_FILES([$srcdir/doc/man/emacs.1])
6403
6404m4_define([subdir_makefiles],
6405  [lib/Makefile lib-src/Makefile oldXMenu/Makefile doc/emacs/Makefile doc/misc/Makefile doc/lispintro/Makefile doc/lispref/Makefile src/Makefile lwlib/Makefile lisp/Makefile leim/Makefile nextstep/Makefile nt/Makefile])
6406SUBDIR_MAKEFILES="subdir_makefiles"
6407AC_CONFIG_FILES(subdir_makefiles)
6408
6409dnl The test/ directory is missing if './make-dist --no-tests' was used.
6410opt_makefile=test/Makefile
6411if test -f "$srcdir/$opt_makefile.in"; then
6412  SUBDIR_MAKEFILES="$SUBDIR_MAKEFILES $opt_makefile"
6413  dnl Again, it's best not to use a variable.  Though you can add
6414  dnl ", [], [opt_makefile='$opt_makefile']" and it should work.
6415  AC_CONFIG_FILES([test/Makefile])
6416fi
6417opt_makefile=test/infra/Makefile
6418if test -f "$srcdir/$opt_makefile.in"; then
6419  SUBDIR_MAKEFILES="$SUBDIR_MAKEFILES $opt_makefile"
6420  dnl Again, it's best not to use a variable.  Though you can add
6421  dnl ", [], [opt_makefile='$opt_makefile']" and it should work.
6422  AC_CONFIG_FILES([test/infra/Makefile])
6423fi
6424
6425
6426dnl The admin/ directory used to be excluded from tarfiles.
6427if test -d $srcdir/admin; then
6428  SUBDIR_MAKEFILES="$SUBDIR_MAKEFILES admin/charsets/Makefile admin/unidata/Makefile admin/grammars/Makefile"
6429  AC_CONFIG_FILES([admin/charsets/Makefile])
6430  AC_CONFIG_FILES([admin/unidata/Makefile])
6431  AC_CONFIG_FILES([admin/grammars/Makefile])
6432fi                              dnl -d admin
6433
6434
6435SUBDIR_MAKEFILES_IN=`echo " ${SUBDIR_MAKEFILES}" | sed -e 's| | $(srcdir)/|g' -e 's|Makefile|Makefile.in|g'`
6436
6437AC_SUBST(SUBDIR_MAKEFILES_IN)
6438
6439dnl You might wonder (I did) why epaths.h is generated by running make,
6440dnl rather than just letting configure generate it from epaths.in.
6441dnl One reason is that the various paths are not fully expanded (see above);
6442dnl e.g., gamedir='${localstatedir}/games/emacs'.
6443dnl Secondly, the GNU Coding standards require that one should be able
6444dnl to run 'make prefix=/some/where/else' and override the values set
6445dnl by configure.  This also explains the 'move-if-change' test and
6446dnl the use of force in the 'epaths-force' rule in Makefile.in.
6447AC_CONFIG_COMMANDS([src/epaths.h], [
6448if test "${opsys}" = "mingw32"; then
6449  ${MAKE-make} MAKEFILE_NAME=do-not-make-Makefile epaths-force-w32
6450elif test "$HAVE_NS" = "yes" && test "$EN_NS_SELF_CONTAINED" = "yes"; then
6451  ${MAKE-make} MAKEFILE_NAME=do-not-make-Makefile epaths-force-ns-self-contained
6452else
6453  ${MAKE-make} MAKEFILE_NAME=do-not-make-Makefile epaths-force
6454fi || AC_MSG_ERROR(['src/epaths.h' could not be made.])
6455], [GCC="$GCC" CPPFLAGS="$CPPFLAGS" opsys="$opsys" HAVE_NS="$HAVE_NS"
6456    EN_NS_SELF_CONTAINED="$EN_NS_SELF_CONTAINED"])
6457
6458dnl NB we have to cheat and use the ac_... version because abs_top_srcdir
6459dnl is not yet set, sigh.  Or we could use ../$srcdir/src/.gdbinit,
6460dnl or a symlink?
6461AC_CONFIG_COMMANDS([src/.gdbinit], [
6462if test ! -f src/.gdbinit && test -f "$srcdir/src/.gdbinit"; then
6463  AS_ECHO(["source $ac_abs_top_srcdir/src/.gdbinit"]) > src/.gdbinit
6464fi
6465])
6466
6467dnl Perhaps this would be better named doc-emacs-emacsver.texi?
6468dnl See comments for etc-refcards-emacsver.tex.
6469dnl Since we get a doc/emacs directory generated anyway, for the Makefile,
6470dnl it is not quite the same.  But we are generating in $srcdir.
6471AC_CONFIG_COMMANDS([doc/emacs/emacsver.texi], [
6472${MAKE-make} -s --no-print-directory -C doc/emacs doc-emacsver || \
6473AC_MSG_ERROR(['doc/emacs/emacsver.texi' could not be made.])
6474])
6475
6476dnl If we give this the more natural name, etc/refcards/emacsver.texi,
6477dnl then a directory etc/refcards is created in the build directory,
6478dnl which is probably harmless, but confusing (in out-of-tree builds).
6479dnl (If we were to generate etc/refcards/Makefile, this might change.)
6480dnl It is really $srcdir/etc/refcards/emacsver.tex that we generate.
6481AC_CONFIG_COMMANDS([etc-refcards-emacsver.tex], [
6482${MAKE-make} -s MAKEFILE_NAME=do-not-make-Makefile etc-emacsver || \
6483AC_MSG_ERROR(['etc/refcards/emacsver.tex' could not be made.])
6484])
6485
6486if test $AUTO_DEPEND = yes; then
6487   for dir in $AUTODEPEND_PARENTS; do
6488     AS_MKDIR_P([$dir/deps])
6489   done
6490fi
6491if $gl_gnulib_enabled_dynarray || $gl_gnulib_enabled_scratch_buffer; then
6492  AS_MKDIR_P([lib/malloc])
6493  if test $AUTO_DEPEND = yes; then
6494    AS_MKDIR_P([lib/deps/malloc])
6495  fi
6496fi
6497
6498AC_OUTPUT
6499
6500if test ! "$with_mailutils"; then
6501  if test "$with_pop" = yes; then
6502    AC_MSG_WARN([This configuration installs a 'movemail' program
6503that retrieves POP3 email via only insecure channels.
6504To omit insecure POP3, you can use '$0 --without-pop'.])
6505  elif test "$with_pop" = no-by-default; then
6506    AC_MSG_WARN([This configuration installs a 'movemail' program
6507that does not retrieve POP3 email.  By default, Emacs 25 and earlier
6508installed a 'movemail' program that retrieved POP3 email via only
6509insecure channels, a practice that is no longer recommended but that
6510you can continue to support by using '$0 --with-pop'.])
6511  fi
6512
6513  case $opsys in
6514    mingw32)
6515      # Don't suggest GNU Mailutils, as it hasn't been ported.
6516      ;;
6517    *)
6518      emacs_fix_movemail="use '$0 --with-mailutils'"
6519      case `(movemail --version) 2>/dev/null` in
6520	*Mailutils*) ;;
6521	*) emacs_fix_movemail="install GNU Mailutils
6522<https://mailutils.org> and $emacs_fix_movemail";;
6523      esac
6524      AC_MSG_NOTICE([You might want to $emacs_fix_movemail.]);;
6525  esac
6526fi
6527
6528if test "${HAVE_XFT}" = yes; then
6529  AC_MSG_WARN([This configuration uses libXft, which has a number of
6530    font rendering issues, and is being considered for removal in the
6531    next release of Emacs.  Please consider using Cairo graphics +
6532    HarfBuzz text shaping instead (they are auto-detected if the
6533    relevant development headers are installed).])
6534fi
6535
6536if test "${HAVE_CAIRO}" = "yes" && test "${HAVE_HARFBUZZ}" = no; then
6537  AC_MSG_WARN([This configuration uses the Cairo graphics library,
6538    but not the HarfBuzz font shaping library (minimum version $harfbuzz_required_ver).
6539    We recommend the use of HarfBuzz when using Cairo, please install
6540    appropriate HarfBuzz development packages.])
6541fi
6542
6543# Let plain 'make' work.
6544test "$MAKE" = make || test -f makefile || cat >makefile <<EOF
6545.POSIX:
6546MAKE = $MAKE
6547all:
6548	\$(MAKE) -f Makefile \$?
6549.DEFAULT:
6550	\$(MAKE) -f Makefile \$<
6551EOF
6552