configure.ac 196 KB
Newer Older
1
dnl  Autoconf script for GNU Emacs
2 3
dnl To rebuild the 'configure' script from this, execute the command
dnl	autoconf
David J. MacKenzie's avatar
David J. MacKenzie committed
4
dnl in the directory containing this script.
5
dnl If you changed any AC_DEFINES, also run autoheader.
6
dnl
Paul Eggert's avatar
Paul Eggert committed
7
dnl Copyright (C) 1994-1996, 1999-2020 Free Software Foundation, Inc.
8
dnl
9
dnl  This file is part of GNU Emacs.
10
dnl
11
dnl  GNU Emacs is free software: you can redistribute it and/or modify
12
dnl  it under the terms of the GNU General Public License as published by
13 14
dnl  the Free Software Foundation, either version 3 of the License, or
dnl  (at your option) any later version.
15
dnl
16 17 18 19
dnl  GNU Emacs is distributed in the hope that it will be useful,
dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dnl  GNU General Public License for more details.
20
dnl
21
dnl  You should have received a copy of the GNU General Public License
22
dnl  along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
23

24
AC_PREREQ(2.65)
Glenn Morris's avatar
Glenn Morris committed
25
dnl Note this is parsed by (at least) make-dist and lisp/cedet/ede/emacs.el.
Eli Zaretskii's avatar
Eli Zaretskii committed
26
AC_INIT(GNU Emacs, 28.0.50, bug-gnu-emacs@gnu.org, , https://www.gnu.org/software/emacs/)
27

28 29 30 31 32 33
dnl Set emacs_config_options to the options of 'configure', quoted for the shell,
dnl and then quoted again for a C string.  Separate options with spaces.
dnl Add some environment variables, if they were passed via the environment
dnl rather than on the command-line.
emacs_config_options=
optsep=
34 35
dnl This is the documented way to record the args passed to configure,
dnl rather than $ac_configure_args.
Paul Eggert's avatar
Paul Eggert committed
36
for opt in "$@" CFLAGS CPPFLAGS LDFLAGS; do
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
  case $opt in
    -n | --no-create | --no-recursion)
      continue ;;
    CFLAGS | CPPFLAGS | LDFLAGS)
      eval 'test "${'$opt'+set}" = set' || continue
      case " $*" in
	*" $opt="*) continue ;;
      esac
      eval opt=$opt=\$$opt ;;
  esac

  emacs_shell_specials=$IFS\''"#$&()*;<>?@<:@\\`{|~'
  case $opt in
    *[["$emacs_shell_specials"]]*)
      case $opt in
	*\'*)
	  emacs_quote_apostrophes="s/'/'\\\\''/g"
	  opt=`AS_ECHO(["$opt"]) | sed "$emacs_quote_apostrophes"` ;;
      esac
      opt="'$opt'"
      case $opt in
	*[['"\\']]*)
	  emacs_quote_for_c='s/[["\\]]/\\&/g; $!s/$/\\n\\/'
	  opt=`AS_ECHO(["$opt"]) | sed "$emacs_quote_for_c"` ;;
      esac ;;
  esac
  AS_VAR_APPEND([emacs_config_options], ["$optsep$opt"])
  optsep=' '
65 66
done

67
AC_CONFIG_HEADERS(src/config.h:src/config.in)
68
AC_CONFIG_SRCDIR(src/lisp.h)
69
AC_CONFIG_AUX_DIR(build-aux)
70
AC_CONFIG_MACRO_DIR(m4)
71 72 73 74

xcsdkdir=
AC_CHECK_PROGS(XCRUN, [xcrun])
if test -n "$XCRUN"; then
75 76
  if test -z "$MAKE"; then
    dnl Call the variable MAKE_PROG, not MAKE, to avoid confusion with
77
    dnl the usual MAKE variable that 'make' itself uses.
78 79 80 81
    AC_CHECK_PROG([MAKE_PROG], [make], [yes])
    if test -z "$MAKE_PROG"; then
      MAKE="$XCRUN MAKE"
      export MAKE
82
      xcsdkdir=`$XCRUN --show-sdk-path 2>/dev/null`
83 84
    fi
  fi
85 86
fi

Paul Eggert's avatar
Paul Eggert committed
87
dnl Check for GNU Make and possibly set MAKE.
88 89 90 91 92 93 94 95 96
[emacs_check_gnu_make ()
{
  emacs_makeout=`($1 --version) 2>/dev/null` &&
  case $emacs_makeout in
    'GNU Make '3.8[1-9]* | 'GNU Make '3.9[0-9]* | \
    'GNU Make '3.[1-9][0-9][0-9]* | 'GNU Make '[4-9]* | 'GNU Make '[1-9][0-9]* )
       ac_path_MAKE_found=:;;
  esac
}]
97 98 99
AC_CACHE_CHECK([for GNU Make], [ac_cv_path_MAKE],
  [ac_path_MAKE_found=false
   if test -n "$MAKE"; then
100
     emacs_check_gnu_make "$MAKE"
101 102 103 104 105 106
     ac_cv_path_MAKE=$MAKE
   else
     emacs_tried_make=false
     emacs_tried_gmake=false
     emacs_tried_gnumake=false
     AC_PATH_PROGS_FEATURE_CHECK([MAKE], [make gmake gnumake],
107 108 109 110 111 112 113 114 115 116
       [[emacs_check_gnu_make "$ac_path_MAKE"
	 if $ac_path_MAKE_found; then
	   # Use the fully-qualified program name only if the basename
	   # would not resolve to it.
	   if eval \$emacs_tried_$ac_prog; then
	     ac_cv_path_MAKE=$ac_path_MAKE
	   else
	     ac_cv_path_MAKE=$ac_prog
	   fi
	 fi
117 118
	 eval emacs_tried_$ac_prog=:]])
   fi])
119 120
$ac_path_MAKE_found || {
AC_MSG_ERROR([[Building Emacs requires GNU Make, at least version 3.81.
121 122 123 124
If you have it installed under another name, configure with 'MAKE=...'.
For example, run '$0 MAKE=gnu-make'.]])
}
MAKE=$ac_cv_path_MAKE
125
export MAKE
126

127 128 129
dnl Canonicalize the configuration name.
AC_CANONICAL_HOST

130
case $host in
131 132
 *-mingw*)

133 134 135 136 137 138 139 140 141
  if test -z "$host_alias"; then

      # No --host argument was given to 'configure'; therefore $host
      # was set to a default value based on the build platform.  But
      # this default value may be wrong if we are building from a
      # 64-bit MSYS[2] pre-configured to build 32-bit MinGW programs.
      # Therefore, we'll try to get the right host platform from the
      # compiler's target.

142
      AC_MSG_CHECKING([the compiler's target])
143
      if test -z "$CC"; then
144 145 146 147
	  cc=gcc
      else
	  cc=$CC
      fi
148 149 150
      cc_target=`$cc -v 2>&1 | sed -n 's/Target: //p'`
      case "$cc_target" in
          *-*) host=$cc_target
151 152
	      ;;
          "") AC_MSG_ERROR([Impossible to obtain $cc compiler target.
153
Please explicitly provide --host.])
154 155
              ;;
	  *) AC_MSG_WARN([Compiler reported non-standard target.
156
Defaulting to $host.])
157 158
              ;;
      esac
159
      AC_MSG_RESULT([$host])
160 161
  fi

162 163 164 165 166 167 168 169
  . $srcdir/nt/mingw-cfg.site

  case $srcdir in
    /* | ?:*)
      # srcdir is an absolute path.  In this case, force the format
      # "/c/foo/bar", to simplify later conversions to native Windows
      # format ("c:/foo/bar").
      srcdir=`cd "${srcdir}" && pwd -W`
170
      # 'eval' pacifies strict POSIX non-MinGW shells (Bug#18612).
171 172
      # We downcase the drive letter to avoid warnings when
      # generating autoloads.
173
      eval 'srcdir=/`echo ${srcdir:0:1} | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"`"${srcdir:2}"'
174 175 176 177
      ;;
  esac;;
esac

178 179
canonical=$host
configuration=${host_alias-${build_alias-$host}}
180
emacs_uname_r=`uname -r`
181

182 183 184 185
dnl Support for --program-prefix, --program-suffix and
dnl --program-transform-name options
AC_ARG_PROGRAM

186 187 188 189
dnl It is important that variables on the RHS not be expanded here,
dnl hence the single quotes.  This is per the GNU coding standards, see
dnl (autoconf) Installation Directory Variables
dnl See also epaths.h below.
David J. MacKenzie's avatar
David J. MacKenzie committed
190
lispdir='${datadir}/emacs/${version}/lisp'
191
standardlisppath='${lispdir}'
192
locallisppath='${datadir}/emacs/${version}/site-lisp:'\
193
'${datadir}/emacs/site-lisp'
194
lisppath='${locallisppath}:${standardlisppath}'
David J. MacKenzie's avatar
David J. MacKenzie committed
195
etcdir='${datadir}/emacs/${version}/etc'
196
archlibdir='${libexecdir}/emacs/${version}/${configuration}'
197
etcdocdir='${datadir}/emacs/${version}/etc'
198
gamedir='${localstatedir}/games/emacs'
199

200 201 202
dnl Special option to disable the most of other options.
AC_ARG_WITH(all,
[AS_HELP_STRING([--without-all],
203 204
		[omit almost all features and build
		small executable with minimal dependencies])],
205
  [with_features=$withval],
206
  [with_features=yes])
207

208 209 210 211 212 213 214 215 216 217 218 219
dnl OPTION_DEFAULT_OFF(NAME, HELP-STRING)
dnl Create a new --with option that defaults to being disabled.
dnl NAME is the base name of the option.  The shell variable with_NAME
dnl   will be set to either the user's value (if the option is
dnl   specified; 'yes' for a plain --with-NAME) or to 'no' (if the
dnl   option is not specified).  Note that the shell variable name is
dnl   constructed as autoconf does, by replacing non-alphanumeric
dnl   characters with "_".
dnl HELP-STRING is the help text for the option.
AC_DEFUN([OPTION_DEFAULT_OFF], [dnl
  AC_ARG_WITH([$1],[AS_HELP_STRING([--with-$1],[$2])],[],[dnl
    m4_bpatsubst([with_$1], [[^0-9a-z]], [_])=no])dnl
220
])dnl
221 222

dnl OPTION_DEFAULT_ON(NAME, HELP-STRING)
Michael Albinus's avatar
Michael Albinus committed
223
dnl Create a new --with option that defaults to $with_features.
224
dnl NAME is the base name of the option.  The shell variable with_NAME
225 226 227 228 229 230 231
dnl   will be set either to 'no' (for a plain --without-NAME) or to
dnl   'yes' (if the option is not specified).  Note that the shell
dnl   variable name is constructed as autoconf does, by replacing
dnl   non-alphanumeric characters with "_".
dnl HELP-STRING is the help text for the option.
AC_DEFUN([OPTION_DEFAULT_ON], [dnl
  AC_ARG_WITH([$1],[AS_HELP_STRING([--without-$1],[$2])],[],[dnl
232
   m4_bpatsubst([with_$1], [[^0-9a-z]], [_])=$with_features])dnl
233 234
])dnl

235 236 237
# For retrieving mail, unencrypted network connections are the default
# only on native MS-Windows platforms.  (FIXME: These platforms should
# also be secure by default.)
238

239 240 241 242 243 244 245 246 247 248
AC_ARG_WITH([mailutils],
  [AS_HELP_STRING([--with-mailutils],
     [rely on GNU Mailutils, so that the --without-pop through --with-mailhost
      options are irrelevant; this is the default if GNU Mailutils is
      installed])],
  [],
  [with_mailutils=$with_features
   if test "$with_mailutils" = yes; then
     (movemail --version) >/dev/null 2>&1 || with_mailutils=no
   fi])
249 250 251 252 253
if test "$with_mailutils" = no; then
  with_mailutils=
fi
AC_SUBST([with_mailutils])

254 255 256 257 258 259 260 261
AC_ARG_WITH([pop],
  [AS_HELP_STRING([--with-pop],
     [Support POP mail retrieval if Emacs movemail is used (not recommended,
      as Emacs movemail POP is insecure).  This is the default only on
      native MS-Windows.])],
  [],
  [case $host in
     *-mingw*) with_pop=yes;;
262
     *) with_pop=no-by-default;;
263
   esac])
264
if test "$with_pop" = yes; then
Dave Love's avatar
Dave Love committed
265
   AC_DEFINE(MAIL_USE_POP)
266
fi
267
AH_TEMPLATE(MAIL_USE_POP, [Define to support POP mail retrieval.])dnl
268

269
OPTION_DEFAULT_OFF([kerberos],[support Kerberos-authenticated POP])
270
if test "$with_kerberos" != no; then
271
   AC_DEFINE(KERBEROS)
272
fi
273 274
AH_TEMPLATE(KERBEROS,
	    [Define to support Kerberos-authenticated POP mail retrieval.])dnl
275

276
OPTION_DEFAULT_OFF([kerberos5],[support Kerberos version 5 authenticated POP])
277 278
if test "${with_kerberos5}" != no; then
  if test "${with_kerberos}" = no; then
279 280 281
    with_kerberos=yes
    AC_DEFINE(KERBEROS)
  fi
282
  AC_DEFINE(KERBEROS5, 1, [Define to use Kerberos 5 instead of Kerberos 4.])
283
fi
284

285
OPTION_DEFAULT_OFF([hesiod],[support Hesiod to get the POP server host])
Glenn Morris's avatar
Glenn Morris committed
286 287
dnl FIXME hesiod support may not be present, so it seems like an error
dnl to define, or at least use, this unconditionally.
288
if test "$with_hesiod" != no; then
289
  AC_DEFINE(HESIOD, 1, [Define to support using a Hesiod database to find the POP server.])
290
fi
Pavel Janík's avatar
Pavel Janík committed
291

Glenn Morris's avatar
Glenn Morris committed
292 293 294 295 296 297 298 299 300
OPTION_DEFAULT_OFF([mail-unlink],[unlink, rather than empty, mail spool after reading])
if test "$with_mail_unlink" != no; then
   AC_DEFINE(MAIL_UNLINK_SPOOL, 1, [Define to unlink, rather than empty, mail spool after reading.])
fi

AC_ARG_WITH([mailhost],[AS_HELP_STRING([--with-mailhost=HOSTNAME],
    [string giving default POP mail host])],
    AC_DEFINE_UNQUOTED(MAILHOST, ["$withval"], [String giving fallback POP mail host.]))

301
AC_ARG_WITH([sound],[AS_HELP_STRING([--with-sound=VALUE],
Joakim Verona's avatar
Joakim Verona committed
302
  [compile with sound support (VALUE one of: yes, alsa, oss, bsd-ossaudio, no;
303
default yes).  Only for GNU/Linux, FreeBSD, NetBSD, MinGW, Cygwin.])],
304
  [ case "${withval}" in
Joakim Verona's avatar
Joakim Verona committed
305
      yes|no|alsa|oss|bsd-ossaudio) val=$withval ;;
306 307
      *) AC_MSG_ERROR(['--with-sound=$withval' is invalid;
this option's value should be 'yes', 'no', 'alsa', 'oss', or 'bsd-ossaudio'.])
308 309 310 311 312
      ;;
    esac
    with_sound=$val
  ],
  [with_sound=$with_features])
Pavel Janík's avatar
Pavel Janík committed
313

Daniel Colascione's avatar
Daniel Colascione committed
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
AC_ARG_WITH([pdumper],
  AS_HELP_STRING(
    [--with-pdumper=VALUE],
    [enable pdumper support unconditionally
      ('yes', 'no', or 'auto': default 'auto')]),
    [ case "${withval}" in
        yes|no|auto) val=$withval ;;
        *) AC_MSG_ERROR(
           ['--with-pdumper=$withval' is invalid;
this option's value should be 'yes' or 'no'.]) ;;
      esac
      with_pdumper=$val
    ],
    [with_pdumper=auto])

AC_ARG_WITH([unexec],
  AS_HELP_STRING(
    [--with-unexec=VALUE],
    [enable unexec support unconditionally
      ('yes', 'no', or 'auto': default 'auto')]),
    [ case "${withval}" in
        yes|no|auto) val=$withval ;;
        *) AC_MSG_ERROR(
           ['--with-unexec=$withval' is invalid;
this option's value should be 'yes' or 'no'.]) ;;
      esac
      with_unexec=$val
    ],
    [with_unexec=auto])

AC_ARG_WITH([dumping],[AS_HELP_STRING([--with-dumping=VALUE],
    [kind of dumping to use for initial Emacs build
(VALUE one of: pdumper, unexec, none; default pdumper)])],
    [ case "${withval}" in
        pdumper|unexec|none) val=$withval ;;
        *) AC_MSG_ERROR(['--with-dumping=$withval is invalid;
this option's value should be 'pdumper', 'unexec', or 'none'.])
        ;;
      esac
      with_dumping=$val
    ],
    [with_dumping=pdumper])

if test "$with_pdumper" = "auto"; then
  if test "$with_dumping" = "pdumper"; then
    with_pdumper=yes
  else
    with_pdumper=no
  fi
fi

if test "$with_unexec" = "auto"; then
  if test "$with_dumping" = "unexec"; then
    with_unexec=yes
  else
    with_unexec=no
  fi
fi

if test "$with_dumping" = "pdumper" && test "$with_pdumper" = "no"; then
  AC_MSG_ERROR(['--with-dumping=pdumper' requires pdumper support])
fi

if test "$with_dumping" = "unexec" && test "$with_unexec" = "no"; then
  AC_MSG_ERROR(['--with-dumping=unexec' requires unexec support])
fi

if test "$with_pdumper" = "yes"; then
382 383 384 385
  AC_DEFINE([HAVE_PDUMPER], 1, [Define to build with portable dumper support])
  HAVE_PDUMPER=yes
else
  HAVE_PDUMPER=no
Daniel Colascione's avatar
Daniel Colascione committed
386
fi
387
AC_SUBST([HAVE_PDUMPER])
Daniel Colascione's avatar
Daniel Colascione committed
388 389 390 391

DUMPING=$with_dumping
AC_SUBST(DUMPING)

392
dnl FIXME currently it is not the last.
David J. MacKenzie's avatar
David J. MacKenzie committed
393
dnl This should be the last --with option, because --with-x is
394
dnl added later on when we find the file name of X, and it's best to
David J. MacKenzie's avatar
David J. MacKenzie committed
395
dnl keep them together visually.
396
AC_ARG_WITH([x-toolkit],[AS_HELP_STRING([--with-x-toolkit=KIT],
397
 [use an X toolkit (KIT one of: yes or gtk, gtk2, gtk3, lucid or athena, motif, no)])],
David J. MacKenzie's avatar
David J. MacKenzie committed
398
[	  case "${withval}" in
Glenn Morris's avatar
Glenn Morris committed
399
	    y | ye | yes )	val=gtk ;;
David J. MacKenzie's avatar
David J. MacKenzie committed
400 401
	    n | no )		val=no  ;;
	    l | lu | luc | luci | lucid )	val=lucid ;;
402
	    a | at | ath | athe | athen | athena )	val=athena ;;
David J. MacKenzie's avatar
David J. MacKenzie committed
403
	    m | mo | mot | moti | motif )	val=motif ;;
Jan Djärv's avatar
Jan Djärv committed
404
	    g | gt | gtk  )	val=gtk ;;
405
	    gtk2  )	val=gtk2 ;;
406
	    gtk3  )	val=gtk3 ;;
David J. MacKenzie's avatar
David J. MacKenzie committed
407
	    * )
408 409 410 411
AC_MSG_ERROR(['--with-x-toolkit=$withval' is invalid;
this option's value should be 'yes', 'no', 'lucid', 'athena', 'motif', 'gtk',
'gtk2' or 'gtk3'.  'yes' and 'gtk' are synonyms.
'athena' and 'lucid' are synonyms.])
David J. MacKenzie's avatar
David J. MacKenzie committed
412 413 414 415
	    ;;
	  esac
	  with_x_toolkit=$val
])
416

417 418 419 420 421
OPTION_DEFAULT_OFF([wide-int],
  [prefer wide Emacs integers (typically 62-bit);
   on 32-bit hosts, this allows buffer and string size up to 2GB,
   at the cost of 10% to 30% slowdown of Lisp interpreter
   and larger memory footprint])
Paul Eggert's avatar
Paul Eggert committed
422 423 424 425
if test "$with_wide_int" = yes; then
  AC_DEFINE([WIDE_EMACS_INT], 1, [Use long long for EMACS_INT if available.])
fi

426 427
dnl _ON results in a '--without' option in the --help output, so
dnl the help text should refer to "don't compile", etc.
Paul Eggert's avatar
Paul Eggert committed
428
with_xpm_set=${with_xpm+set}
429 430 431 432 433 434
OPTION_DEFAULT_ON([xpm],[don't compile with XPM image support])
OPTION_DEFAULT_ON([jpeg],[don't compile with JPEG image support])
OPTION_DEFAULT_ON([tiff],[don't compile with TIFF image support])
OPTION_DEFAULT_ON([gif],[don't compile with GIF image support])
OPTION_DEFAULT_ON([png],[don't compile with PNG image support])
OPTION_DEFAULT_ON([rsvg],[don't compile with SVG image support])
435
OPTION_DEFAULT_ON([lcms2],[don't compile with Little CMS support])
436
OPTION_DEFAULT_ON([libsystemd],[don't compile with libsystemd support])
Robert Pluim's avatar
Robert Pluim committed
437
OPTION_DEFAULT_ON([cairo],[don't compile with Cairo drawing])
438
OPTION_DEFAULT_ON([xml2],[don't compile with XML parsing support])
439
OPTION_DEFAULT_OFF([imagemagick],[compile with ImageMagick image support])
440
OPTION_DEFAULT_ON([native-image-api], [don't use native image APIs (GDI+ on Windows)])
441
OPTION_DEFAULT_ON([json], [don't compile with native JSON support])
442

443
OPTION_DEFAULT_ON([xft],[don't use XFT for anti aliased fonts])
Paul Eggert's avatar
Paul Eggert committed
444
OPTION_DEFAULT_ON([harfbuzz],[don't use HarfBuzz for text shaping])
Miles Bader's avatar
Miles Bader committed
445 446 447
OPTION_DEFAULT_ON([libotf],[don't use libotf for OpenType font support])
OPTION_DEFAULT_ON([m17n-flt],[don't use m17n-flt for text shaping])

448
OPTION_DEFAULT_ON([toolkit-scroll-bars],[don't use Motif/Xaw3d/GTK toolkit scroll bars])
449
OPTION_DEFAULT_ON([xaw3d],[don't use Xaw3d])
450
OPTION_DEFAULT_ON([xim],[at runtime, default X11 XIM to off])
451
AC_ARG_WITH([ns],[AS_HELP_STRING([--with-ns],
452 453
[use Nextstep (macOS Cocoa or GNUstep) windowing system.
On by default on macOS.])],[],[with_ns=maybe])
454
OPTION_DEFAULT_OFF([w32], [use native MS Windows GUI in a Cygwin build])
455 456

OPTION_DEFAULT_ON([gpm],[don't use -lgpm for mouse support on a GNU/Linux console])
457
OPTION_DEFAULT_ON([dbus],[don't compile with D-Bus support])
458
AC_ARG_WITH([gconf],[AS_HELP_STRING([--with-gconf],
459 460 461 462 463 464
[compile with Gconf support (Gsettings replaces this)])],[],
[if test $with_features = yes; then
with_gconf=maybe
else
with_gconf=no
fi])
465
OPTION_DEFAULT_ON([gsettings],[don't compile with GSettings support])
Karel Klíc's avatar
Karel Klíc committed
466
OPTION_DEFAULT_ON([selinux],[don't compile with SELinux support])
Ted Zlatanov's avatar
Ted Zlatanov committed
467
OPTION_DEFAULT_ON([gnutls],[don't use -lgnutls for SSL/TLS support])
Paul Eggert's avatar
Paul Eggert committed
468
OPTION_DEFAULT_ON([zlib],[don't compile with zlib decompression support])
469
OPTION_DEFAULT_ON([modules],[don't compile with dynamic modules support])
470
OPTION_DEFAULT_ON([threads],[don't compile with elisp threading support])
471 472

AC_ARG_WITH([file-notification],[AS_HELP_STRING([--with-file-notification=LIB],
Michael Albinus's avatar
Michael Albinus committed
473
 [use a file notification library (LIB one of: yes, inotify, kqueue, gfile, w32, no)])],
474 475 476 477
 [ case "${withval}" in
    y | ye | yes )	val=yes ;;
    n | no )		val=no  ;;
    i | in | ino | inot | inoti | inotif | inotify )	val=inotify ;;
Michael Albinus's avatar
Michael Albinus committed
478 479
    k | kq | kqu | kque | kqueu | kqueue )	val=kqueue ;;
    g | gf | gfi | gfil | gfile )	val=gfile ;;
480
    w | w3 | w32 )	val=w32 ;;
481
    * ) AC_MSG_ERROR(['--with-file-notification=$withval' is invalid;
Paul Eggert's avatar
Paul Eggert committed
482
this option's value should be 'yes', 'no', 'inotify', 'kqueue', 'gfile' or 'w32'.
483
'yes' is a synonym for 'w32' on MS-Windows, for 'no' on Nextstep,
Michael Albinus's avatar
Michael Albinus committed
484
otherwise for the first of 'inotify', 'kqueue' or 'gfile' that is usable.])
485 486 487 488
    ;;
   esac
   with_file_notification=$val
 ],
489
 [with_file_notification=$with_features])
490

491
OPTION_DEFAULT_OFF([xwidgets],
492
  [enable use of some gtk widgets in Emacs buffers (requires gtk3)])
493

494 495
## For the times when you want to build Emacs but don't have
## a suitable makeinfo, and can live without the manuals.
496
dnl https://lists.gnu.org/r/emacs-devel/2008-04/msg01844.html
497 498
OPTION_DEFAULT_ON([makeinfo],[don't require makeinfo for building manuals])

499 500 501
## Makefile.in needs the cache file name.
AC_SUBST(cache_file)

502 503
## This is an option because I do not know if all info/man support
## compressed files, nor how to test if they do so.
Joakim Verona's avatar
Joakim Verona committed
504 505 506
OPTION_DEFAULT_ON([compress-install],
  [don't compress some files (.el, .info, etc.) when installing.  Equivalent to:
make GZIP_PROG= install])
507

508
AC_ARG_WITH(gameuser,dnl
509 510 511 512 513 514
[AS_HELP_STRING([--with-gameuser=USER_OR_GROUP],
		[user for shared game score files.
		An argument prefixed by ':' specifies a group instead.])])
gameuser=
gamegroup=
case ${with_gameuser} in
515 516
  '' | no) ;;
  yes) gamegroup=games ;;
517
  :*) gamegroup=${with_gameuser#:} ;;
518 519
  *) gameuser=${with_gameuser} ;;
esac
520

521
AC_ARG_WITH([gnustep-conf],dnl
522
[AS_HELP_STRING([--with-gnustep-conf=FILENAME],
Paul Eggert's avatar
Paul Eggert committed
523 524 525
   [name of GNUstep configuration file to use on systems where the command
    'gnustep-config' does not work; default $GNUSTEP_CONFIG_FILE, or
    /etc/GNUstep/GNUstep.conf])])
526 527 528 529 530
test "X${with_gnustep_conf}" != X && test "${with_gnustep_conf}" != yes && \
  GNUSTEP_CONFIG_FILE="${with_gnustep_conf}"
test "X$GNUSTEP_CONFIG_FILE" = "X" && \
     GNUSTEP_CONFIG_FILE=/etc/GNUstep/GNUstep.conf

531
AC_ARG_ENABLE(ns-self-contained,
532 533 534
[AS_HELP_STRING([--disable-ns-self-contained],
                [disable self contained build under NeXTstep])],
   EN_NS_SELF_CONTAINED=$enableval,
535 536
   EN_NS_SELF_CONTAINED=yes)

Jan D's avatar
Jan D committed
537
locallisppathset=no
Lute Kamstra's avatar
Lute Kamstra committed
538
AC_ARG_ENABLE(locallisppath,
539 540 541
[AS_HELP_STRING([--enable-locallisppath=PATH],
                [directories Emacs should search for lisp files specific
		 to this site])],
Lute Kamstra's avatar
Lute Kamstra committed
542 543 544
if test "${enableval}" = "no"; then
  locallisppath=
elif test "${enableval}" != "yes"; then
Jan D's avatar
Jan D committed
545
  locallisppath=${enableval} locallisppathset=yes
Lute Kamstra's avatar
Lute Kamstra committed
546 547
fi)

548
AC_ARG_ENABLE(checking,
549
[AS_HELP_STRING([--enable-checking@<:@=LIST@:>@],
Paul Eggert's avatar
Paul Eggert committed
550
		[enable expensive checks.  With LIST,
551 552 553
		 enable only specific categories of checks.
		 Categories are: all,yes,no.
		 Flags are: stringbytes, stringoverrun, stringfreelist,
554
		 structs, glyphs])],
555 556
[ac_checking_flags="${enableval}"],[])
IFS="${IFS= 	}"; ac_save_IFS="$IFS"; IFS="$IFS,"
Paul Eggert's avatar
Paul Eggert committed
557
CHECK_STRUCTS=false
558 559 560 561 562 563
for check in $ac_checking_flags
do
	case $check in
	# these set all the flags to specific states
	yes)		ac_enable_checking=1 ;;
	no)		ac_enable_checking= ;
Paul Eggert's avatar
Paul Eggert committed
564
			CHECK_STRUCTS=false
565 566 567
			ac_gc_check_stringbytes= ;
	                ac_gc_check_string_overrun= ;
	                ac_gc_check_string_free_list= ;
568
			ac_glyphs_debug= ;;
569
	all)		ac_enable_checking=1 ;
Paul Eggert's avatar
Paul Eggert committed
570
			CHECK_STRUCTS=true
571 572 573
			ac_gc_check_stringbytes=1 ;
	                ac_gc_check_string_overrun=1 ;
	                ac_gc_check_string_free_list=1 ;
574
			ac_glyphs_debug=1 ;;
575
	# these enable particular checks
576 577
	stringbytes)	ac_gc_check_stringbytes=1 ;;
	stringoverrun)	ac_gc_check_string_overrun=1 ;;
578
	stringfreelist) ac_gc_check_string_free_list=1 ;;
Paul Eggert's avatar
Paul Eggert committed
579
	structs)	CHECK_STRUCTS=true ;;
580
	glyphs)		ac_glyphs_debug=1 ;;
581 582 583 584 585 586 587
	*)	AC_MSG_ERROR(unknown check category $check) ;;
	esac
done
IFS="$ac_save_IFS"

if test x$ac_enable_checking != x ; then
  AC_DEFINE(ENABLE_CHECKING, 1,
588
[Define to 1 if expensive run-time data type and consistency checks are enabled.])
589
fi
Paul Eggert's avatar
Paul Eggert committed
590 591 592 593 594 595 596 597 598
if $CHECK_STRUCTS; then
  AC_DEFINE([CHECK_STRUCTS], 1,
    [Define this to check whether someone updated the portable dumper
     code after changing the layout of a structure that it uses.
     If you change one of these structures, check that the pdumper.c
     code is still valid, and update the pertinent hash in pdumper.c
     by manually copying the hash from the newly-generated dmpstruct.h.])
fi
AC_SUBST([CHECK_STRUCTS])
599 600 601 602 603 604
if test x$ac_gc_check_stringbytes != x ; then
  AC_DEFINE(GC_CHECK_STRING_BYTES, 1,
[Define this temporarily to hunt a bug.  If defined, the size of
   strings is redundantly recorded in sdata structures so that it can
   be compared to the sizes recorded in Lisp strings.])
fi
605
if test x$ac_gc_check_string_overrun != x ; then
606 607 608 609 610 611 612
  AC_DEFINE(GC_CHECK_STRING_OVERRUN, 1,
[Define this to check for short string overrun.])
fi
if test x$ac_gc_check_string_free_list != x ; then
  AC_DEFINE(GC_CHECK_STRING_FREE_LIST, 1,
[Define this to check the string free list.])
fi
613
if test x$ac_glyphs_debug != x ; then
614 615 616
  AC_DEFINE(GLYPH_DEBUG, 1,
[Define this to enable glyphs debugging code.])
fi
617

618 619 620
dnl The name of this option is unfortunate.  It predates, and has no
dnl relation to, the "sampling-based elisp profiler" added in 24.3.
dnl Actually, it stops it working.
621
dnl https://lists.gnu.org/r/emacs-devel/2012-11/msg00393.html
622
AC_ARG_ENABLE(profiling,
623
[AS_HELP_STRING([--enable-profiling],
624 625 626
		[build emacs with low-level, gprof profiling support.
                Mainly useful for debugging Emacs itself.  May not work on
                all platforms.  Stops profiler.el working.])],
627 628 629 630 631 632
[ac_enable_profiling="${enableval}"],[])
if test x$ac_enable_profiling != x ; then
   PROFILING_CFLAGS="-DPROFILING=1 -pg"
else
   PROFILING_CFLAGS=
fi
633
AC_SUBST(PROFILING_CFLAGS)
634

635 636 637
AC_ARG_ENABLE(autodepend,
[AS_HELP_STRING([--enable-autodepend],
		[automatically generate dependencies to .h-files.
638
		 Requires gcc, enabled if found.])],
639 640
[ac_enable_autodepend="${enableval}"],[ac_enable_autodepend=yes])

641 642 643 644 645
AC_ARG_ENABLE(gtk-deprecation-warnings,
[AS_HELP_STRING([--enable-gtk-deprecation-warnings],
		[Show Gtk+/Gdk deprecation warnings for Gtk+ >= 3.0])],
[ac_enable_gtk_deprecation_warnings="${enableval}"],[])

Paul Eggert's avatar
Paul Eggert committed
646 647 648 649 650 651 652
BUILD_DETAILS=
AC_ARG_ENABLE([build-details],
  [AS_HELP_STRING([--disable-build-details],
		  [Make the build more deterministic by omitting host
		   names, time stamps, etc. from the output.])],
  [test "$enableval" = no && BUILD_DETAILS=--no-build-details])
AC_SUBST([BUILD_DETAILS])
653

654
dnl This used to use changequote, but, apart from 'changequote is evil'
Dave Love's avatar
Dave Love committed
655 656 657
dnl per the autoconf manual, we can speed up autoconf somewhat by quoting
dnl the great gob of text.  Thus it's not processed for possible expansion.
dnl Just make sure the brackets remain balanced.
658 659 660 661
dnl
dnl Since Emacs can't find matching pairs of quotes, boundaries are
dnl indicated by comments.
dnl quotation begins
Dave Love's avatar
Dave Love committed
662
[
David J. MacKenzie's avatar
David J. MacKenzie committed
663 664 665

### If you add support for a new configuration, add code to this
### switch statement to recognize your configuration name and select
Glenn Morris's avatar
Glenn Morris committed
666 667
### the appropriate opsys.

David J. MacKenzie's avatar
David J. MacKenzie committed
668 669 670 671 672 673
### As far as handling version numbers on operating systems is
### concerned, make sure things will fail in a fixable way.  If
### /etc/MACHINES doesn't say anything about version numbers, be
### prepared to handle anything reasonably.  If version numbers
### matter, be sure /etc/MACHINES says something about it.

Paul Eggert's avatar
Paul Eggert committed
674
opsys='' unported=no
David J. MacKenzie's avatar
David J. MacKenzie committed
675 676
case "${canonical}" in

677 678
  ## GNU/Linux and similar ports
  *-*-linux* )
679 680 681
    opsys=gnu-linux
  ;;

682
  ## FreeBSD ports
683
  *-*-freebsd* )
684 685 686
    opsys=freebsd
  ;;

687 688 689 690 691
  ## DragonFly ports
  *-*-dragonfly* )
    opsys=dragonfly
  ;;

692 693 694 695 696
  ## FreeBSD kernel + glibc based userland
  *-*-kfreebsd*gnu* )
    opsys=gnu-kfreebsd
  ;;

David J. MacKenzie's avatar
David J. MacKenzie committed
697 698 699 700 701
  ## NetBSD ports
  *-*-netbsd* )
    opsys=netbsd
  ;;

702
  ## OpenBSD ports
703
  *-*-openbsd* | *-*-mirbsd* )
704 705 706
    opsys=openbsd
  ;;

707
  ## Apple Darwin / macOS
708 709
  *-apple-darwin* )
    case "${canonical}" in
710
      *-apple-darwin[0-9].*) unported=yes ;;
711
      i[3456]86-* | x86_64-* )  ;;
712 713 714
      * )            unported=yes ;;
    esac
    opsys=darwin
Paul Eggert's avatar
Paul Eggert committed
715
    ## FIXME: Find a way to use Fink if available (Bug#11507).
716 717
  ;;

718 719 720 721 722
  ## Chromium Native Client
  *-nacl )
    opsys=nacl
  ;;

723 724 725 726 727
  ## Cygwin ports
  *-*-cygwin )
    opsys=cygwin
  ;;

728 729
  ## HP 9000 series 700 and 800, running HP/UX
  hppa*-hp-hpux10.2* )
730
    opsys=hpux10-20
731 732
  ;;
  hppa*-hp-hpux1[1-9]* )
733
    opsys=hpux11
734 735 736
    CFLAGS="-D_INCLUDE__STDC_A1_SOURCE $CFLAGS"
  ;;

David J. MacKenzie's avatar
David J. MacKenzie committed
737
  ## IBM machines
738
  rs6000-ibm-aix4.[23]* )
Paul Eggert's avatar
Paul Eggert committed
739
    opsys=aix4-2
740
  ;;
741
  powerpc-ibm-aix4.[23]*  )
Paul Eggert's avatar
Paul Eggert committed
742
    opsys=aix4-2
743
  ;;
744
  rs6000-ibm-aix[56]* )
Paul Eggert's avatar
Paul Eggert committed
745
    opsys=aix4-2
Eli Zaretskii's avatar
Eli Zaretskii committed
746
  ;;
Paul Eggert's avatar
Paul Eggert committed
747
  powerpc-ibm-aix[5-9]* | powerpc-ibm-aix[1-9][0-9]* )
Paul Eggert's avatar
Paul Eggert committed
748
    opsys=aix4-2
749
  ;;
David J. MacKenzie's avatar
David J. MacKenzie committed
750 751

  ## Suns
752
  *-sun-solaris* \
Dan Nicolaescu's avatar
Dan Nicolaescu committed
753
    | i[3456]86-*-solaris2* | i[3456]86-*-sunos5* \
754
    | x86_64-*-solaris2*    | x86_64-*-sunos5*)
David J. MacKenzie's avatar
David J. MacKenzie committed
755
    case "${canonical}" in
Paul Eggert's avatar
Paul Eggert committed
756 757 758
      i[3456]86-*-* )   ;;
      amd64-*-*|x86_64-*-*) ;;
      sparc* )		;;
David J. MacKenzie's avatar
David J. MacKenzie committed
759 760 761
      * )		unported=yes ;;
    esac
    case "${canonical}" in
762 763 764 765
      *-sunos5.[1-9][0-9]* | *-solaris2.[1-9][0-9]* )
		opsys=sol2-10
		emacs_check_sunpro_c=yes
		;;
766 767
      *-sunos5.[1-5]* | *-solaris2.[1-5]* ) unported=yes ;;
      ## Note that Emacs 23.1's NEWS said the following would be dropped.
768 769 770 771
      *-sunos5.6* | *-solaris2.6* )
		opsys=sol2-6
		RANLIB="ar -ts"
		;;
772
      ## 5.7 EOL Aug 2008, 5.8 EOL Mar 2012.
773
      *-sunos5.[7-9]* | *-solaris2.[7-9]* )
774
		opsys=sol2-6
775
		emacs_check_sunpro_c=yes
Dan Nicolaescu's avatar
Dan Nicolaescu committed
776
		;;
David J. MacKenzie's avatar
David J. MacKenzie committed
777
    esac
778 779 780 781 782 783 784 785 786 787 788
    ## Watch out for a compiler that we know will not work.
    case "${canonical}" in
     *-solaris* | *-sunos5* )
		if [ "x$CC" = x/usr/ucb/cc ]; then
		  ## /usr/ucb/cc doesn't work;
		  ## we should find some other compiler that does work.
		  unset CC
		fi
		;;
      *) ;;
    esac
David J. MacKenzie's avatar
David J. MacKenzie committed
789 790
  ;;

Paul Eggert's avatar
Paul Eggert committed
791 792 793
  ## QNX Neutrino
  *-nto-qnx* )
    opsys=qnxnto
Paul Eggert's avatar
Paul Eggert committed
794
    test -z "$CC" && CC=qcc
Paul Eggert's avatar
Paul Eggert committed
795
    CFLAGS="$CFLAGS -D__NO_EXT_QNX"
796 797 798
    if test "$with_unexec" = yes; then
      LDFLAGS="-N2MB $LDFLAGS"
    fi
Paul Eggert's avatar
Paul Eggert committed
799 800
  ;;

801
  ## Intel 386 machines where we don't care about the manufacturer.
802
  i[3456]86-*-* )
David J. MacKenzie's avatar
David J. MacKenzie committed
803
    case "${canonical}" in
804
      *-darwin* )               opsys=darwin ;;
805
      *-mingw* )
806
		opsys=mingw32
807
		# MinGW overrides and adds some system headers in nt/inc.
808
		GCC_TEST_OPTIONS="-I $srcdir/nt/inc"
809
		;;
810 811 812
      *-sysv4.2uw* )		opsys=unixware ;;
      *-sysv5uw* )		opsys=unixware ;;
      *-sysv5OpenUNIX* )	opsys=unixware ;;
David J. MacKenzie's avatar
David J. MacKenzie committed
813 814 815 816
      ## Otherwise, we'll fall through to the generic opsys code at the bottom.
    esac
  ;;

817 818 819
  # MinGW64
  x86_64-*-* )
    case "${canonical}" in
820
      *-mingw* )
821 822 823 824 825 826 827 828
		opsys=mingw32
		# MinGW overrides and adds some system headers in nt/inc.
		GCC_TEST_OPTIONS="-I $srcdir/nt/inc"
		;;
      ## Otherwise, we'll fall through to the generic opsys code at the bottom.
    esac
  ;;

David J. MacKenzie's avatar
David J. MacKenzie committed
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848
  * )
    unported=yes
  ;;
esac

### If the code above didn't choose an operating system, just choose
### an operating system based on the configuration name.  You really
### only want to use this when you have no idea what the right
### operating system is; if you know what operating systems a machine
### runs, it's cleaner to make it explicit in the case statement
### above.
if test x"${opsys}" = x; then
  case "${canonical}" in
    *-gnu* )				opsys=gnu ;;
    * )
      unported=yes
    ;;
  esac
fi

Dave Love's avatar
Dave Love committed
849
]
850
dnl quotation ends
David J. MacKenzie's avatar
David J. MacKenzie committed
851 852

if test $unported = yes; then
853
  AC_MSG_ERROR([Emacs does not support '${canonical}' systems.
Glenn Morris's avatar
Glenn Morris committed
854
If you think it should, please send a report to ${PACKAGE_BUGREPORT}.
855
Check 'etc/MACHINES' for recognized configuration names.])
David J. MacKenzie's avatar
David J. MacKenzie committed
856 857 858
fi

#### Choose a compiler.
859

Paul Eggert's avatar
Paul Eggert committed
860 861 862
dnl Don't bother to test for C89.
AC_DEFUN([_AC_PROG_CC_C89], [$2])

863
dnl Sets GCC=yes if using gcc.
864
AC_PROG_CC([gcc cc cl clang "$XCRUN gcc" "$XCRUN clang"])
865
if test -n "$XCRUN"; then
866
  AC_CHECK_PROGS(AR, [ar "$XCRUN ar"])
867
  test -n "$AR" && export AR
868
fi
869

Paul Eggert's avatar
Paul Eggert committed
870 871 872
dnl Emacs needs C99 or later.
gl_PROG_CC_C99

Paul Eggert's avatar
Paul Eggert committed
873
AC_PROG_CC_C_O
Paul Eggert's avatar
Paul Eggert committed
874

875 876
if test x$GCC = xyes; then
  test "x$GCC_TEST_OPTIONS" != x && CC="$CC $GCC_TEST_OPTIONS"
877
fi
David J. MacKenzie's avatar
David J. MacKenzie committed
878

879 880
# Avoid gnulib's tests for -lcrypto, so that there's no static dependency on it.
AC_DEFUN([gl_CRYPTO_CHECK])
881 882
# Avoid gnulib's tests for HAVE_WORKING_O_NOATIME and HAVE_WORKING_O_NOFOLLOW,
# as we don't use them.
883
AC_DEFUN([gl_FCNTL_O_FLAGS])
884 885 886 887 888 889
# Avoid gnulib's test for pthread_sigmask.
funcs=
for func in $ac_func_list; do
  test $func = pthread_sigmask || AS_VAR_APPEND([funcs], [" $func"])
done
ac_func_list=$funcs
890 891 892 893
# Emacs does not use the wchar or wctype-h modules.
AC_DEFUN([gt_TYPE_WINT_T],
  [GNULIB_OVERRIDES_WINT_T=0
   AC_SUBST([GNULIB_OVERRIDES_WINT_T])])
894

895
# Initialize gnulib right after choosing the compiler.
Glenn Morris's avatar
Comment  
Glenn Morris committed
896
dnl Amongst other things, this sets AR and ARFLAGS.
897
gl_EARLY
898

899
if test "$ac_test_CFLAGS" != set; then
Paul Eggert's avatar
Paul Eggert committed
900 901 902
  # It's helpful to have C macros available to GDB, so prefer -g3 to -g
  # if -g3 works and the user does not specify CFLAGS.
  # This test must follow gl_EARLY; otherwise AC_LINK_IFELSE complains.
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917
  case $CFLAGS in
    '-g')
      emacs_g3_CFLAGS='-g3';;
    '-g -O2')
      emacs_g3_CFLAGS='-g3 -O2';;
    *)
      emacs_g3_CFLAGS='';;
  esac
  if test -n "$emacs_g3_CFLAGS"; then
    emacs_save_CFLAGS=$CFLAGS
    CFLAGS=$emacs_g3_CFLAGS
    AC_CACHE_CHECK([whether $CC accepts $emacs_g3_CFLAGS],
      [emacs_cv_prog_cc_g3],
      [AC_LINK_IFELSE([AC_LANG_PROGRAM()],
	 [emacs_cv_prog_cc_g3=yes],
Paul Eggert's avatar
Paul Eggert committed
918 919
	 [emacs_cv_prog_cc_g3=no])])
    if test $emacs_cv_prog_cc_g3 != yes; then
920 921
      CFLAGS=$emacs_save_CFLAGS
    fi
922 923 924
    if test $opsys = mingw32; then
      CFLAGS="$CFLAGS -gdwarf-2"
    fi
925
  fi
Paul Eggert's avatar
Paul Eggert committed
926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943

  case $CFLAGS in
    *-O*) ;;
    *)
      # No optimization flag was inferred for this non-GCC compiler.
      # Try -O.  This is needed for xlc on AIX; see Bug#14258.
      emacs_save_CFLAGS=$CFLAGS
      test -z "$CFLAGS" || CFLAGS="$CFLAGS "
      CFLAGS=${CFLAGS}-O
      AC_CACHE_CHECK([whether $CC accepts -O],
        [emacs_cv_prog_cc_o],
	[AC_LINK_IFELSE([AC_LANG_PROGRAM()],
	   [emacs_cv_prog_cc_o=yes],
	   [emacs_cv_prog_cc_o=no])])
      if test $emacs_cv_prog_cc_o != yes; then
	CFLAGS=$emacs_save_CFLAGS
      fi ;;
  esac
944 945
fi

946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963
# gl_GCC_VERSION_IFELSE([major], [minor], [run-if-found], [run-if-not-found])
# ---------------------------------------------------------------------------
# If $CPP is gcc-MAJOR.MINOR or newer, then run RUN-IF-FOUND.
# Otherwise, run RUN-IF-NOT-FOUND.
AC_DEFUN([gl_GCC_VERSION_IFELSE],
  [AC_PREPROC_IFELSE(
    [AC_LANG_PROGRAM(
      [[
#if ($1) < __GNUC__ || (($1) == __GNUC__ && ($2) <= __GNUC_MINOR__)
/* ok */
#else
# error "your version of gcc is older than $1.$2"
#endif
      ]]),
    ], [$3], [$4])
  ]
)

964
AC_ARG_ENABLE([gcc-warnings],
965 966 967 968 969 970
  [AS_HELP_STRING([--enable-gcc-warnings@<:@=TYPE@:>@],
                  [control generation of GCC warnings.  The TYPE 'yes'
		   means to fail if any warnings are issued; 'warn-only'
		   means issue warnings without failing (default for
		   developer builds); 'no' means disable warnings
		   (default for non-developer builds).])],
971
  [case $enableval in
972
     yes|no|warn-only) ;;
973 974 975
     *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
   esac
   gl_gcc_warnings=$enableval],
976 977
  [# By default, use 'warn-only' if it looks like the invoker of 'configure'
   # is a developer as opposed to a builder.  This is most likely true
978
   # if GCC is recent enough and there is a .git directory or file;
979
   # however, if there is also a .tarball-version file it is probably
Paul Eggert's avatar
Paul Eggert committed
980
   # just a release imported into Git for patch management.
981
   gl_gcc_warnings=no
982
   if test -e "$srcdir"/.git && test ! -f "$srcdir"/.tarball-version; then
983 984 985 986 987
     gl_GCC_VERSION_IFELSE([5], [3], [gl_gcc_warnings=warn-only])
   fi])

AC_ARG_ENABLE([check-lisp-object-type],
  [AS_HELP_STRING([--enable-check-lisp-object-type],
988 989 990
     [Enable compile time checks for the Lisp_Object data type,
      which can catch some bugs during development.])])
if test "$enable_check_lisp_object_type" = yes; then
991 992 993
  AC_DEFINE([CHECK_LISP_OBJECT_TYPE], 1,
    [Define to enable compile-time checks for the Lisp_Object data type.])
fi
994

995 996 997 998 999
# clang is unduly picky about some things.
AC_CACHE_CHECK([whether the compiler is clang], [emacs_cv_clang],
  [AC_COMPILE_IFELSE(
     [AC_LANG_PROGRAM([[
	  #ifndef __clang__
Paul Eggert's avatar
Paul Eggert committed
1000
	    error "not clang";
1001 1002 1003 1004
	  #endif
        ]])],
     [emacs_cv_clang=yes],
     [emacs_cv_clang=no])])
1005

1006
WERROR_CFLAGS=
1007 1008
# When compiling with GCC, prefer -isystem to -I when including system
# include files, to avoid generating useless diagnostics for the files.
1009
AS_IF([test $gl_gcc_warnings = no],
Paul Eggert's avatar
Paul Eggert committed
1010
 [
1011
  isystem='-I'
Paul Eggert's avatar
Paul Eggert committed
1012 1013
  AS_IF([test "$emacs_cv_clang" = yes],
   [
1014 1015 1016
     # Turn off some warnings if supported.
     gl_WARN_ADD([-Wno-switch])
     gl_WARN_ADD([-Wno-pointer-sign])
1017
     gl_WARN_ADD([-Wno-string-plus-int])
Paul Eggert's avatar
Paul Eggert committed
1018
     gl_WARN_ADD([-Wno-unknown-attributes])
Paul Eggert's avatar
Paul Eggert committed
1019 1020
   ])
 ],[
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
  isystem='-isystem '

  # This, $nw, is the list of warnings we disable.
  nw=

  case $with_x_toolkit in
    lucid | athena | motif)
       # Old toolkits mishandle 'const'.
       nw="$nw -Wwrite-strings"
       ;;
  esac
1032
  AS_IF([test $gl_gcc_warnings = yes],
1033
    [WERROR_CFLAGS=-Werror])
1034

1035
  nw="$nw -Wcast-align -Wcast-align=strict" # Emacs is tricky with pointers.
1036 1037
  nw="$nw -Wduplicated-branches"    # Too many false alarms
  nw="$nw -Wformat-overflow=2"      # False alarms due to GCC bug 80776
1038 1039
  nw="$nw -Wsystem-headers"         # Don't let system headers trigger warnings
  nw="$nw -Woverlength-strings"     # Not a problem these days
1040
  nw="$nw -Wformat-nonliteral"      # we do this a lot
Paul Eggert's avatar
Paul Eggert committed
1041
  nw="$nw -Wvla"                    # Emacs uses <vla.h>.
1042
  nw="$nw -Wunused-const-variable=2" # lisp.h declares const objects.
1043
  nw="$nw -Winline"                 # OK to ignore 'inline'
1044 1045
  nw="$nw -Wstrict-overflow"        # OK to optimize assuming that
                                    # signed overflow has undefined behavior
1046 1047
  nw="$nw -Wsync-nand"              # irrelevant here, and provokes ObjC warning
  nw="$nw -Wunsafe-loop-optimizations" # OK to suppress unsafe optimizations
1048
  nw="$nw -Wbad-function-cast"      # These casts are no worse than others.
1049
  nw="$nw -Wabi"                    # Not useful, perceived as noise
1050 1051

  # Emacs doesn't care about shadowing; see
1052
  # <https://lists.gnu.org/r/emacs-diffs/2011-11/msg00265.html>.
1053 1054
  nw="$nw -Wshadow"

1055 1056 1057
  # Emacs's use of alloca inhibits protecting the stack.
  nw="$nw -Wstack-protector"

1058 1059 1060
  # Emacs's use of __attribute__ ((cold)) causes false alarms with this option.
  nw="$nw -Wsuggest-attribute=cold"

1061 1062 1063 1064
  # Emacs's use of partly-const functions such as Fgnutls_available_p
  # make this option problematic.
  nw="$nw -Wsuggest-attribute=const"

Paul Eggert's avatar
Paul Eggert committed
1065 1066
  # Emacs's use of partly-pure functions such as CHECK_TYPE make this
  # option problematic.
1067 1068
  nw="$nw -Wsuggest-attribute=pure"

1069 1070 1071 1072
  # This part is merely for shortening the command line,
  # since -Wall implies -Wswitch.
  nw="$nw -Wswitch"

Joakim Verona's avatar
Joakim Verona committed
1073 1074 1075
  # This part is merely for shortening the command line,
  # since -Wno-FOO needs to be added below regardless.
  nw="$nw -Wmissing-field-initializers"
Paul Eggert's avatar
Paul Eggert committed
1076
  nw="$nw -Woverride-init"
Joakim Verona's avatar
Joakim Verona committed
1077 1078 1079
  nw="$nw -Wtype-limits"
  nw="$nw -Wunused-parameter"

1080
  if test "$emacs_cv_clang" = yes; then
1081
    nw="$nw -Wcast-align"
1082
    nw="$nw -Wdouble-promotion"
1083
    nw="$nw -Wmissing-braces"
1084 1085
  fi

1086
  # These cause too much noise in the MinGW build
1087 1088
  if test $opsys = mingw32; then
    nw="$nw -Wpointer-sign"
1089
    nw="$nw -Wsuggest-attribute=format"
1090 1091
  fi

1092 1093 1094 1095 1096
  gl_MANYWARN_ALL_GCC([ws])
  gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
  for w in $ws; do
    gl_WARN_ADD([$w])
  done
Paul Eggert's avatar
Paul Eggert committed
1097
  gl_WARN_ADD([-Wredundant-decls])     # Prefer this, as we don't use Bison.
1098
  gl_WARN_ADD([-Wno-missing-field-initializers]) # We need this one
Paul Eggert's avatar
Paul Eggert committed
1099
  gl_WARN_ADD([-Wno-override-init])    # More trouble than it is worth
1100 1101 1102 1103
  gl_WARN_ADD([-Wno-sign-compare])     # Too many warnings for now
  gl_WARN_ADD([-Wno-type-limits])      # Too many warnings for now
  gl_WARN_ADD([-Wno-unused-parameter]) # Too many warnings for now
  gl_WARN_ADD([-Wno-format-nonliteral])
1104

1105
  # clang is unduly picky about some things.
1106
  if test "$emacs_cv_clang" = yes; then
1107
    gl_WARN_ADD([-Wno-missing-braces])
1108
    gl_WARN_ADD([-Wno-null-pointer-arithmetic])
1109 1110
  fi

1111 1112 1113 1114 1115
  # This causes too much noise in the MinGW build
  if test $opsys = mingw32; then
    gl_WARN_ADD([-Wno-pointer-sign])
  fi

1116
  AC_DEFINE([GCC_LINT], [1], [Define to 1 if --enable-gcc-warnings.])
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
  AS_IF([test $gl_gcc_warnings = yes],
    [AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks])
     AH_VERBATIM([GNULIB_PORTCHECK_FORTIFY_SOURCE],
     [/* Enable compile-time and run-time bounds-checking, and some warnings,
	 without upsetting glibc 2.15+. */
      #if (defined GNULIB_PORTCHECK && !defined _FORTIFY_SOURCE \
	   && defined __OPTIMIZE__ && __OPTIMIZE__)
      # define _FORTIFY_SOURCE 2
      #endif
     ])])
1127
 ])
1128

Paul Eggert's avatar
Paul Eggert committed
1129
# clang is picky about these regardless of whether
1130 1131
# --enable-gcc-warnings is specified.
if test "$emacs_cv_clang" = yes; then
Paul Eggert's avatar
Paul Eggert committed
1132
  gl_WARN_ADD([-Wno-initializer-overrides])
1133 1134 1135
  gl_WARN_ADD([-Wno-tautological-compare])
  gl_WARN_ADD([-Wno-tautological-constant-out-of-range-compare])
fi
David J. MacKenzie's avatar
David J. MacKenzie committed
1136

1137 1138 1139 1140 1141 1142 1143
# Use a slightly smaller set of warning options for lib/.
nw=
nw="$nw -Wunused-macros"
gl_MANYWARN_COMPLEMENT([GNULIB_WARN_CFLAGS], [$WARN_CFLAGS], [$nw])

AC_SUBST([WERROR_CFLAGS])
AC_SUBST([GNULIB_WARN_CFLAGS])
1144

1145 1146 1147 1148 1149 1150
edit_cflags="
  s,///*,/,g
  s/^/ /
  s/ -I/ $isystem/g
  s/^ //
"
1151

1152 1153
AC_ARG_ENABLE(link-time-optimization,
[AS_HELP_STRING([--enable-link-time-optimization],
1154
                [build with link-time optimization
1155
		 (experimental; see INSTALL)])],
1156 1157
if test "${enableval}" != "no"; then
   ac_lto_supported=no
1158
   if test "$emacs_cv_clang" = yes; then
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186
      AC_MSG_CHECKING([whether link-time optimization is supported by clang])
      GOLD_PLUGIN=`$CC -print-file-name=LLVMgold.so 2>/dev/null`
      if test -x "$GOLD_PLUGIN"; then
	 LTO="-flto"
      fi
   elif test x$GCC = xyes; then
      AC_MSG_CHECKING([whether link-time optimization is supported by gcc])
      CPUS=`getconf _NPROCESSORS_ONLN 2>/dev/null`
      if test x$CPUS != x; then
	 LTO="-flto=$CPUS"
      else
	 LTO="-flto"
      fi
   else
      AC_MSG_ERROR([Link-time optimization is not supported with your compiler.])
   fi
   if test -z "$LTO"; then
      ac_lto_supported=no
   else
      old_CFLAGS=$CFLAGS
      CFLAGS="$CFLAGS $LTO"
      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
         [ac_lto_supported=yes], [ac_lto_supported=no])
         CFLAGS="$old_CFLAGS"
   fi
   AC_MSG_RESULT([$ac_lto_supported])
   if test "$ac_lto_supported" = "yes"; then
      CFLAGS="$CFLAGS $LTO"
1187
      if test "$emacs_cv_clang" = yes; then
1188 1189 1190 1191 1192
	 AC_MSG_WARN([Please read INSTALL before using link-time optimization with clang])
	 # WARNING: 'ar --plugin ...' doesn't work without
	 # command, so plugin name is appended to ARFLAGS.
	 ARFLAGS="cru --plugin $GOLD_PLUGIN"
	 RANLIB="$RANLIB --plugin $GOLD_PLUGIN"
1193 1194 1195 1196 1197 1198 1199
      else
        dnl The following is needed for GCC 4.9.0.  The GCC 4.9.0 release notes
        dnl suggest that instead of -ffat-lto-objects we should use gcc-ar and
        dnl gcc-ranlib in place of ar and ranlib, but gcc-ar makes /usr/bin/ar
        dnl dump core on Fedora 20, so play it safe for now.
        gl_COMPILER_OPTION_IF([-ffat-lto-objects],
          [CFLAGS="$CFLAGS -ffat-lto-objects"])
1200 1201 1202
      fi
   fi
fi)
1203

Paul Eggert's avatar
Paul Eggert committed
1204 1205 1206 1207 1208 1209

dnl Automake replacements.
AC_DEFUN([AM_CONDITIONAL],
  [$2 && $1=1 || $1=
   AC_SUBST([$1])])

1210 1211
dnl Prefer silent make output.  For verbose output, use
dnl 'configure --disable-silent-rules' or 'make V=1' .
Paul Eggert's avatar
Paul Eggert committed
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225
dnl This code is adapted from Automake.
dnl Although it can be simplified now that GNU Make is assumed,
dnl the simplification hasn't been done yet.
AC_ARG_ENABLE([silent-rules],
  [AS_HELP_STRING(
     [--disable-silent-rules],
     [verbose build output (undo: "make V=0")])])
if test "$enable_silent_rules" = no; then
  AM_DEFAULT_VERBOSITY=1
else
  AM_DEFAULT_VERBOSITY=0
fi
AM_V='$(V)'
AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)'
1226 1227 1228 1229
AC_SUBST([AM_V])
AC_SUBST([AM_DEFAULT_V])
AC_SUBST([AM_DEFAULT_VERBOSITY])