+2006-08-15 Paul Eggert <eggert@cs.ucla.edu>
+
+ * NEWS: Autoconf now uses constructs like "#ifdef HAVE_STDLIB_H"
+ rather than "#if HAVE_STDLIB_H", so that it now works with "gcc
+ -Wundef -Werror". Problem reported by David Fang in
+ <http://lists.gnu.org/archive/html/autoconf/2006-08/msg00045.html>.
+ * doc/autoconf.texi (Header Templates, Default Includes):
+ (Particular Functions, Generic Functions, Header Portability):
+ (Particular Headers, Generic Headers, Generic Declarations, Guidelines):
+ (Obsolete Macros, AC_FOO_IFELSE vs AC_TRY_FOO):
+ (Present But Cannot Be Compiled, Preprocessor Symbol Index):
+ Prefer #ifdef to #if.
+ * lib/autoconf/c.m4 (AC_C_BIGENDIAN): Prefer #ifdef to #if.
+ * lib/autoconf/functions.m4 (AC_FUNC_ALLOCA, _AC_FUNC_MALLOC_IF):
+ (AC_FUNC_MKTIME, AC_FUNC_MMAP, _AC_FUNC_REALLOC_IF):
+ (AC_FUNC_SELECT_ARGTYPES, AC_FUNC_SETVBUF_REVERSED, _AC_FUNC_VFORK):
+ Likewise.
+ * lib/autoconf/headers.m4 (_AC_INCLUDES_DEFAULT_REQUIREMENTS):
+ (AC_HEADER_RESOLV, AC_HEADER_STAT): Likewise.
+ * lib/autoconf/specific.m4 (AC_DECL_SYS_SYGLIST):
+ (AC_SYS_RESTARTABLE_SYSCALLS): Likewise.
+ * lib/autoconf/types.m4 (AC_STRUCT_TIMEZONE): Likewise.
+ * lib/autoconf/headers.m4 (AC_HEADER_STAT): Don't assume that
+ S_ISDIR etc. are valid for use in #if; POSIX doesn't guarantee
+ this.
+
2006-08-14 Paul Eggert <eggert@cs.ucla.edu>
* doc/autoconf.texi (Limitations of Usual Tools): Document sed
** GNU M4 1.4.5 or later is now recommended. At least one "make check"
test fails with earlier versions of M4.
+** Autoconf now uses constructs like "#ifdef HAVE_STDLIB_H" rather than
+ "#if HAVE_STDLIB_H", so that it now works with "gcc -Wundef -Werror".
+
** The functionality of the undocumented _AC_COMPUTE_INT is now provided
by a public and documented macro, AC_COMPUTE_INT. The parameters to the
two macros are different, so autoupdate will not change the old private name
@group
#include <conf.h>
-#if HAVE_UNISTD_H
+#ifdef HAVE_UNISTD_H
# include <unistd.h>
#else
/* We are in trouble. */
@example
@group
-#if TIME_WITH_SYS_TIME
+#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
-# if HAVE_SYS_TIME_H
+# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
@example
@group
#include <stdio.h>
-#if HAVE_SYS_TYPES_H
+#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
-#if HAVE_SYS_STAT_H
+#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
-#if STDC_HEADERS
+#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
-# if HAVE_STDLIB_H
+# ifdef HAVE_STDLIB_H
# include <stdlib.h>
# endif
#endif
-#if HAVE_STRING_H
-# if !STDC_HEADERS && HAVE_MEMORY_H
+#ifdef HAVE_STRING_H
+# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
# include <memory.h>
# endif
# include <string.h>
#endif
-#if HAVE_STRINGS_H
+#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
-#if HAVE_INTTYPES_H
+#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
-#if HAVE_STDINT_H
+#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
-#if HAVE_UNISTD_H
+#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
@end group
@example
@group
-#if HAVE_ALLOCA_H
+#ifdef HAVE_ALLOCA_H
# include <alloca.h>
#elif defined __GNUC__
# define alloca __builtin_alloca
yourself in new code:
@example
@group
-#if !HAVE_WORKING_VFORK
+#ifndef HAVE_WORKING_VFORK
# define vfork fork
#endif
@end group
behaves like Posix's @code{getpgid}.
@example
-#if GETPGRP_VOID
+#ifdef GETPGRP_VOID
pid = getpgrp ();
#else
pid = getpgrp (0);
the @samp{#undef malloc}):
@verbatim
-#if HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#undef malloc
@ovindex LIBOBJS
Like @code{AC_CHECK_FUNCS}, but uses @samp{AC_LIBOBJ(@var{function})} as
@var{action-if-not-found}. You can declare your replacement function by
-enclosing the prototype in @samp{#if !HAVE_@var{function}}. If the
+enclosing the prototype in @samp{#ifndef HAVE_@var{function}}. If the
system has the function, it probably declares it in a header file you
should be including, so you shouldn't redeclare it lest your declaration
conflict.
AC_CHECK_HEADERS([sys/socket.h])
AC_CHECK_HEADERS([net/if.h], [], [],
[#include <stdio.h>
-#if STDC_HEADERS
+#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
-# if HAVE_STDLIB_H
+# ifdef HAVE_STDLIB_H
# include <stdlib.h>
# endif
#endif
-#if HAVE_SYS_SOCKET_H
+#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
])
AC_CHECK_HEADERS([sys/socket.h])
AC_CHECK_HEADERS([netinet/if_ether.h], [], [],
[#include <stdio.h>
-#if STDC_HEADERS
+#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
-# if HAVE_STDLIB_H
+# ifdef HAVE_STDLIB_H
# include <stdlib.h>
# endif
#endif
-#if HAVE_SYS_SOCKET_H
+#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
])
#else
# define dirent direct
# define NAMLEN(dirent) ((dirent)->d_namlen)
-# if HAVE_SYS_NDIR_H
+# ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h>
# endif
-# if HAVE_SYS_DIR_H
+# ifdef HAVE_SYS_DIR_H
# include <sys/dir.h>
# endif
-# if HAVE_NDIR_H
+# ifdef HAVE_NDIR_H
# include <ndir.h>
# endif
#endif
the following:
@verbatim
-#if HAVE_SYS_TYPES_H
+#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_NETINET_IN_H
@file{system.h} could contain the following code:
@verbatim
-#if HAVE_STDBOOL_H
+#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#else
-# if ! HAVE__BOOL
+# ifndef HAVE__BOOL
# ifdef __cplusplus
typedef bool _Bool;
# else
@group
/* This example is obsolescent.
Nowadays you can just #include <string.h>. */
-#if STDC_HEADERS
+#ifdef STDC_HEADERS
# include <string.h>
#else
-# if !HAVE_STRCHR
+# ifndef HAVE_STRCHR
# define strchr index
# define strrchr rindex
# endif
char *strchr (), *strrchr ();
-# if !HAVE_MEMCPY
+# ifndef HAVE_MEMCPY
# define memcpy(d, s, n) bcopy ((s), (d), (n))
# define memmove(d, s, n) bcopy ((s), (d), (n))
# endif
@example
@group
#include <sys/types.h>
-#if HAVE_SYS_WAIT_H
+#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
#ifndef WEXITSTATUS
@example
@group
-#if HAVE_UNISTD_H
+#ifdef HAVE_UNISTD_H
# include <sys/types.h>
# include <unistd.h>
#endif
@example
@group
-#if TIME_WITH_SYS_TIME
+#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
-# if HAVE_SYS_TIME_H
+# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
@example
@group
-#if HAVE_TERMIOS_H
+#ifdef HAVE_TERMIOS_H
# include <termios.h>
#endif
-#if GWINSZ_IN_SYS_IOCTL
+#ifdef GWINSZ_IN_SYS_IOCTL
# include <sys/ioctl.h>
#endif
@end group
@verbatim
AC_CHECK_HEADERS([foo.h])
AC_CHECK_HEADERS([bar.h], [], [],
-[#if HAVE_FOO_H
+[#ifdef HAVE_FOO_H
# include <foo.h>
# endif
])
declared, @code{HAVE_DECL_@var{symbol}} is defined to @samp{0} instead
of leaving @code{HAVE_DECL_@var{symbol}} undeclared. When you are
@emph{sure} that the check was performed, use
-@code{HAVE_DECL_@var{symbol}} just like any other result of Autoconf:
+@code{HAVE_DECL_@var{symbol}} in @code{#if}:
@example
#if !HAVE_DECL_SYMBOL
@example
@group
-#if HAVE_STDBOOL_H
+#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#endif
@end group
@end example
+Both @code{#if HAVE_STDBOOL_H} and @code{#ifdef HAVE_STDBOOL_H} will
+work with any standard C compiler. Some developers prefer @code{#if}
+because it is easier to read, while others prefer @code{#ifdef} because
+it avoids diagnostics with picky compilers like @acronym{GCC} with the
+@option{-Wundef} option.
+
If a test program needs to use or create a data file, give it a name
that starts with @file{conftest}, such as @file{conftest.data}. The
@command{configure} script cleans up by running @samp{rm -f -r conftest*}
@code{AC_CHECK_TYPES} together with
@example
-#if !HAVE_LOFF_T
+#ifndef HAVE_LOFF_T
typedef loff_t off_t;
#endif
@end example
AC_CHECK_DECLS([sys_siglist], [], [],
[#include <signal.h>
/* NetBSD declares sys_siglist in unistd.h. */
-#if HAVE_UNISTD_H
+#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
])
@example
@group
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
-[[#if !defined _AIX
+[[#ifndef _AIX
error: This isn't AIX!
#endif
]])],
$ @kbd{cat configure.ac}
AC_INIT([Example], [1.0], [bug-example@@example.org])
AC_CHECK_HEADERS([number.h pi.h], [], [],
-[[#if HAVE_NUMBER_H
+[[#ifdef HAVE_NUMBER_H
# include <number.h>
#endif
]])
This is an alphabetical list of the C preprocessor symbols that the
Autoconf macros define. To work with Autoconf, C source code needs to
-use these names in @code{#if} directives.
+use these names in @code{#if} or @code{#ifdef} directives.
@printindex cv
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
#include <sys/param.h>
],
-[#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
+[#if ! (defined BYTE_ORDER && defined BIG_ENDIAN && defined LITTLE_ENDIAN \
+ && BYTE_ORDER && BIG_ENDIAN && LITTLE_ENDIAN)
bogus endian macros
#endif
])],
# include <malloc.h>
# define alloca _alloca
# else
-# if HAVE_ALLOCA_H
+# ifdef HAVE_ALLOCA_H
# include <alloca.h>
# else
# ifdef _AIX
AC_CACHE_CHECK([for GNU libc compatible malloc], ac_cv_func_malloc_0_nonnull,
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
-[[#if STDC_HEADERS || HAVE_STDLIB_H
+[[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
# include <stdlib.h>
#else
char *malloc ();
AC_CACHE_CHECK([for working mktime], ac_cv_func_working_mktime,
[AC_RUN_IFELSE([AC_LANG_SOURCE(
[[/* Test program from Paul Eggert and Tony Leneis. */
-#if TIME_WITH_SYS_TIME
+#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
-# if HAVE_SYS_TIME_H
+# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif
-#if HAVE_STDLIB_H
+#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
-#if HAVE_UNISTD_H
+#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
-#if !HAVE_ALARM
+#ifndef HAVE_ALARM
# define alarm(X) /* empty */
#endif
#include <fcntl.h>
#include <sys/mman.h>
-#if !STDC_HEADERS && !HAVE_STDLIB_H
+#if !defined STDC_HEADERS && !defined HAVE_STDLIB_H
char *malloc ();
#endif
/* This mess was copied from the GNU getpagesize.h. */
-#if !HAVE_GETPAGESIZE
+#ifndef HAVE_GETPAGESIZE
/* Assume that all systems that can run configure have sys/param.h. */
-# if !HAVE_SYS_PARAM_H
+# ifndef HAVE_SYS_PARAM_H
# define HAVE_SYS_PARAM_H 1
# endif
# ifdef _SC_PAGESIZE
# define getpagesize() sysconf(_SC_PAGESIZE)
# else /* no _SC_PAGESIZE */
-# if HAVE_SYS_PARAM_H
+# ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
# ifdef EXEC_PAGESIZE
# define getpagesize() EXEC_PAGESIZE
AC_CACHE_CHECK([for GNU libc compatible realloc], ac_cv_func_realloc_0_nonnull,
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
-[[#if STDC_HEADERS || HAVE_STDLIB_H
+[[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
# include <stdlib.h>
#else
char *realloc ();
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[AC_INCLUDES_DEFAULT
-#if HAVE_SYS_SELECT_H
+#ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
#endif
-#if HAVE_SYS_SOCKET_H
+#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
],
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[#include <stdio.h>
-# if PROTOTYPES
+# ifdef PROTOTYPES
int (setvbuf) (FILE *, int, char *, size_t);
# endif]],
[[char buf; return setvbuf (stdout, _IOLBF, &buf, 1);]])],
[AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[#include <stdio.h>
-# if PROTOTYPES
+# ifdef PROTOTYPES
int (setvbuf) (FILE *, int, char *, size_t);
# endif]],
[[char buf; return setvbuf (stdout, &buf, _IOLBF, 1);]])],
[AC_RUN_IFELSE([AC_LANG_SOURCE([[/* Thanks to Paul Eggert for this test. */
]AC_INCLUDES_DEFAULT[
#include <sys/wait.h>
-#if HAVE_VFORK_H
+#ifdef HAVE_VFORK_H
# include <vfork.h>
#endif
/* On some sparc systems, changes by the child to local and incoming
dnl If ever you change this variable, please keep autoconf.texi in sync.
ac_includes_default="\
#include <stdio.h>
-#if HAVE_SYS_TYPES_H
+#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
-#if HAVE_SYS_STAT_H
+#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
-#if STDC_HEADERS
+#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
-# if HAVE_STDLIB_H
+# ifdef HAVE_STDLIB_H
# include <stdlib.h>
# endif
#endif
-#if HAVE_STRING_H
-# if !STDC_HEADERS && HAVE_MEMORY_H
+#ifdef HAVE_STRING_H
+# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
# include <memory.h>
# endif
# include <string.h>
#endif
-#if HAVE_STRINGS_H
+#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
-#if HAVE_INTTYPES_H
+#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
-#if HAVE_STDINT_H
+#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
-#if HAVE_UNISTD_H
+#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif"
])dnl
AC_DEFUN([AC_HEADER_RESOLV],
[AC_CHECK_HEADERS(sys/types.h netinet/in.h arpa/nameser.h netdb.h resolv.h,
[], [],
-[[#if HAVE_SYS_TYPES_H
+[[#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_NETINET_IN_H
AC_DEFUN([AC_HEADER_STAT],
[AC_CACHE_CHECK(whether stat file-mode macros are broken,
ac_cv_header_stat_broken,
-[AC_EGREP_CPP([You lose], [#include <sys/types.h>
+[AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <sys/types.h>
#include <sys/stat.h>
#if defined S_ISBLK && defined S_IFDIR
-# if S_ISBLK (S_IFDIR)
-You lose.
-# endif
+extern char c1[S_ISBLK (S_IFDIR) ? -1 : 1];
#endif
#if defined S_ISBLK && defined S_IFCHR
-# if S_ISBLK (S_IFCHR)
-You lose.
-# endif
+extern char c2[S_ISBLK (S_IFCHR) ? -1 : 1];
#endif
#if defined S_ISLNK && defined S_IFREG
-# if S_ISLNK (S_IFREG)
-You lose.
-# endif
+extern char c3[S_ISLNK (S_IFREG) ? -1 : 1];
#endif
#if defined S_ISSOCK && defined S_IFREG
-# if S_ISSOCK (S_IFREG)
-You lose.
-# endif
+extern char c4[S_ISSOCK (S_IFREG) ? -1 : 1];
#endif
-], ac_cv_header_stat_broken=yes, ac_cv_header_stat_broken=no)])
+]])], ac_cv_header_stat_broken=yes, ac_cv_header_stat_broken=no)])
if test $ac_cv_header_stat_broken = yes; then
AC_DEFINE(STAT_MACROS_BROKEN, 1,
[Define to 1 if the `S_IS*' macros in <sys/stat.h> do not
[AC_CHECK_DECLS([sys_siglist],,,
[#include <signal.h>
/* NetBSD declares sys_siglist in unistd.h. */
-#if HAVE_UNISTD_H
+#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
])
AC_INCLUDES_DEFAULT
#include <signal.h>
-#if HAVE_SYS_WAIT_H
+#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
AC_CACHE_CHECK(for tzname, ac_cv_var_tzname,
[AC_LINK_IFELSE([AC_LANG_PROGRAM(
[[#include <time.h>
-#if !HAVE_DECL_TZNAME
+#ifndef HAVE_DECL_TZNAME
extern char *tzname[];
#endif
]],