From: Akim Demaille Date: Tue, 15 Feb 2000 09:33:59 +0000 (+0000) Subject: Define HAVE_DECL_FOO both to 1 if found and 0 otherwise. X-Git-Tag: autoconf-2.50~1138 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e4260dccb3eccb5834bb01b76205fe2ac931250;p=thirdparty%2Fautoconf.git Define HAVE_DECL_FOO both to 1 if found and 0 otherwise. * acgeneral.m4 (AC_CHECK_DECLS): Define HAVE_DECL_FOO to 1 instead of NEED_FOO_DECL if found. Define to 0 if not found. * autoheader.m4 (AC_CHECK_DECLS): Template HAVE_DECL_FOO. * tests/semantics.m4 (AC_CHECK_DECLS): Adjusted. * doc/autoconf.texi (Generic Declarations): Adjusted. --- diff --git a/ChangeLog b/ChangeLog index 1732d90e7..e661c1c49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2000-02-15 Akim Demaille + + Define HAVE_DECL_FOO both to 1 if found and 0 otherwise. + + * acgeneral.m4 (AC_CHECK_DECLS): Define HAVE_DECL_FOO to 1 instead + of NEED_FOO_DECL if found. Define to 0 if not found. + * autoheader.m4 (AC_CHECK_DECLS): Template HAVE_DECL_FOO. + * tests/semantics.m4 (AC_CHECK_DECLS): Adjusted. + * doc/autoconf.texi (Generic Declarations): Adjusted. + 2000-02-15 Akim Demaille * doc/autoconf.texi (Generic Structures): diff --git a/acgeneral.m4 b/acgeneral.m4 index 694423a26..c168d056c 100644 --- a/acgeneral.m4 +++ b/acgeneral.m4 @@ -2691,11 +2691,15 @@ AC_VAR_POPDEF([ac_Symbol])dnl # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], # [INCLUDES]) # -------------------------------------------------------- +# Defines HAVE_DECL_SYMBOL to 1 if declared, 0 otherwise. See the +# documentation for a detailed explanation of this difference with +# other AC_CHECK_*S macros. AC_DEFUN([AC_CHECK_DECLS], [m4_foreach([AC_Symbol], [$1], [AC_SPECIALIZE([AC_CHECK_DECL], AC_Symbol, - [$2], - [AC_DEFINE_UNQUOTED(AC_TR_CPP([NEED_]AC_Symbol[_DECL])) + [AC_DEFINE_UNQUOTED(AC_TR_CPP([HAVE_DECL_]AC_Symbol), 1) +$2], + [AC_DEFINE_UNQUOTED(AC_TR_CPP([HAVE_DECL_]AC_Symbol), 0) $3], [$4])]) ])# AC_CHECK_DECLS diff --git a/autoconf.texi b/autoconf.texi index 780852753..26ede3899 100644 --- a/autoconf.texi +++ b/autoconf.texi @@ -3006,12 +3006,13 @@ introducing extra declarations when not needed. @defmac AC_CHECK_DECLS ((@var{symbol}, @dots{}), @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{includes}) @maindex CHECK_DECLS -@cvindex NEED_@var{symbol}_DECL +@cvindex HAVE_DECL_@var{symbol} For each given @var{symbol} (comma separated list), define -@code{NEED_@var{symbol}_DECL} (in all capitals) if @var{symbol} has to -be declared to be used as an r-value. If @var{action-if-not-found} is -given, it is additional shell code to execute when one of the function -declarations is needed, otherwise @var{action-if-found} is executed. +@code{HAVE_DECL_@var{symbol}} (in all capitals) to @samp{1} if +@var{symbol} is declared, otherwise to @samp{0}. If +@var{action-if-not-found} is given, it is additional shell code to +execute when one of the function declarations is needed, otherwise +@var{action-if-found} is executed. This macro uses an m4 list as first argument: @example @@ -3019,22 +3020,34 @@ AC_CHECK_DECLS((strlen)) AC_CHECK_DECLS((malloc, realloc, calloc, free)) @end example -This macro does not define @code{HAVE_@var{symbol}_DECL} on purpose. -The following code +Unlike the other @samp{AC_CHECK_*S} macros, when a @var{symbol} is not +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: + @example -#if NEED_FOO_DECL -/* Declare foo. */ +#if !HAVE_DECL_SYMBOL +extern char *symbol; #endif @end example -is safer than + +@noindent +But if the test may have not been performed, because it is safer +@emph{not} to declare a symbol than to use a declaration which conflicts +with the system's one, you should use: + @example -#if !HAVE_FOO_DECL -/* Declare foo. */ +#if defined HAVE_DECL_MALLOC && !HAVE_DECL_MALLOC +char *malloc (size_t *s); #endif @end example -since in this last case, if @code{configure} was not run, then the test -succeeds, thus @code{foo} is declared, with risks to clash with previous -declarations. It is safer not to declare in case of doubts. + +@noindent +You fall into the second category only in extreme situations: either +your files may be used without being configured, or they are used during +the configuration. In most cases the traditional approach is enough. @end defmac diff --git a/autoheader.m4 b/autoheader.m4 index 5da30d8d4..981a759e0 100644 --- a/autoheader.m4 +++ b/autoheader.m4 @@ -171,8 +171,9 @@ AH_DEFUN([AC_CHECK_FILES], AH_DEFUN([AC_CHECK_DECLS], [m4_foreach([AC_Symbol], [$1], - [AH_TEMPLATE(AC_TR_CPP([NEED_]AC_Symbol[_DECL]), - [Define if you need the declaration of `]AC_Symbol['.]) + [AH_TEMPLATE(AC_TR_CPP([HAVE_DECL_]AC_Symbol), + [Define to 1 if you have the declaration of `]AC_Symbol[', + and to 0 if you don't.]) # Success $2 # Failure diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 780852753..26ede3899 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -3006,12 +3006,13 @@ introducing extra declarations when not needed. @defmac AC_CHECK_DECLS ((@var{symbol}, @dots{}), @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{includes}) @maindex CHECK_DECLS -@cvindex NEED_@var{symbol}_DECL +@cvindex HAVE_DECL_@var{symbol} For each given @var{symbol} (comma separated list), define -@code{NEED_@var{symbol}_DECL} (in all capitals) if @var{symbol} has to -be declared to be used as an r-value. If @var{action-if-not-found} is -given, it is additional shell code to execute when one of the function -declarations is needed, otherwise @var{action-if-found} is executed. +@code{HAVE_DECL_@var{symbol}} (in all capitals) to @samp{1} if +@var{symbol} is declared, otherwise to @samp{0}. If +@var{action-if-not-found} is given, it is additional shell code to +execute when one of the function declarations is needed, otherwise +@var{action-if-found} is executed. This macro uses an m4 list as first argument: @example @@ -3019,22 +3020,34 @@ AC_CHECK_DECLS((strlen)) AC_CHECK_DECLS((malloc, realloc, calloc, free)) @end example -This macro does not define @code{HAVE_@var{symbol}_DECL} on purpose. -The following code +Unlike the other @samp{AC_CHECK_*S} macros, when a @var{symbol} is not +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: + @example -#if NEED_FOO_DECL -/* Declare foo. */ +#if !HAVE_DECL_SYMBOL +extern char *symbol; #endif @end example -is safer than + +@noindent +But if the test may have not been performed, because it is safer +@emph{not} to declare a symbol than to use a declaration which conflicts +with the system's one, you should use: + @example -#if !HAVE_FOO_DECL -/* Declare foo. */ +#if defined HAVE_DECL_MALLOC && !HAVE_DECL_MALLOC +char *malloc (size_t *s); #endif @end example -since in this last case, if @code{configure} was not run, then the test -succeeds, thus @code{foo} is declared, with risks to clash with previous -declarations. It is safer not to declare in case of doubts. + +@noindent +You fall into the second category only in extreme situations: either +your files may be used without being configured, or they are used during +the configuration. In most cases the traditional approach is enough. @end defmac diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4 index 694423a26..c168d056c 100644 --- a/lib/autoconf/general.m4 +++ b/lib/autoconf/general.m4 @@ -2691,11 +2691,15 @@ AC_VAR_POPDEF([ac_Symbol])dnl # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], # [INCLUDES]) # -------------------------------------------------------- +# Defines HAVE_DECL_SYMBOL to 1 if declared, 0 otherwise. See the +# documentation for a detailed explanation of this difference with +# other AC_CHECK_*S macros. AC_DEFUN([AC_CHECK_DECLS], [m4_foreach([AC_Symbol], [$1], [AC_SPECIALIZE([AC_CHECK_DECL], AC_Symbol, - [$2], - [AC_DEFINE_UNQUOTED(AC_TR_CPP([NEED_]AC_Symbol[_DECL])) + [AC_DEFINE_UNQUOTED(AC_TR_CPP([HAVE_DECL_]AC_Symbol), 1) +$2], + [AC_DEFINE_UNQUOTED(AC_TR_CPP([HAVE_DECL_]AC_Symbol), 0) $3], [$4])]) ])# AC_CHECK_DECLS diff --git a/tests/semantics.m4 b/tests/semantics.m4 index 47c12467c..64993f499 100644 --- a/tests/semantics.m4 +++ b/tests/semantics.m4 @@ -16,8 +16,8 @@ AT_TEST_MACRO(AC_CHECK_DECLS, [AC_CHECK_DECLS((yes, no),,, [int yes = 1;])], [AT_CHECK_DEFINES( -[#define NEED_NO_DECL 1 -/* #undef NEED_YES_DECL */ +[#define HAVE_DECL_NO 0 +#define HAVE_DECL_YES 1 ])])