]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
autoconf: warn if AC_*_IFELSE lacks complete program
authorEric Blake <eblake@redhat.com>
Thu, 26 Aug 2010 21:07:38 +0000 (15:07 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 26 Aug 2010 21:24:13 +0000 (15:24 -0600)
* lib/autoconf/lang.m4 (AC_LANG_DEFINES_PROVIDED): New macro.
(AC_LANG_SOURCE): Call it.
(AC_LANG_CONFTEST): Add warning if new macro is not called.
* lib/autoconf/c.m4 (_AC_LANG_OPENMP): Add missing AC_LANG_SOURCE.
* lib/autoconf/fortran.m4 (AC_FC_FREEFORM, AC_FC_FIXEDFORM)
(AC_FC_LINE_LENGTH, __AC_FC_NAME_MANGLING): Intentionally bypass
AC_LANG_SOURCE.
* lib/autoconf/programs.m4 (_AC_PROG_LEX_YYTEXT_DECL): Likewise.
* tests/compile.at (AC_COMPILE_IFELSE): New test.
* doc/autoconf.texi (Generating Sources) <AC_LANG_CONFTEST>:
Document new warning.
<AC_LANG_DEFINES_PROVIDED>: Document new macro.
<AC_LANG_SOURCE>: Document use of new macro.
* NEWS: Document the improvement.
Suggested by Bruno Haible.

Signed-off-by: Eric Blake <eblake@redhat.com>
ChangeLog
NEWS
doc/autoconf.texi
lib/autoconf/c.m4
lib/autoconf/fortran.m4
lib/autoconf/lang.m4
lib/autoconf/programs.m4
tests/compile.at

index 6ff1bc382d5cbc3689a3ba3a320456ea92c1b2fc..0be58095e0df69f6392dda3007d901c38eadf290 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
 2010-08-26  Eric Blake  <eblake@redhat.com>
 
+       autoconf: warn if AC_*_IFELSE lacks complete program
+       * lib/autoconf/lang.m4 (AC_LANG_DEFINES_PROVIDED): New macro.
+       (AC_LANG_SOURCE): Call it.
+       (AC_LANG_CONFTEST): Add warning if new macro is not called.
+       * lib/autoconf/c.m4 (_AC_LANG_OPENMP): Add missing AC_LANG_SOURCE.
+       * lib/autoconf/fortran.m4 (AC_FC_FREEFORM, AC_FC_FIXEDFORM)
+       (AC_FC_LINE_LENGTH, __AC_FC_NAME_MANGLING): Intentionally bypass
+       AC_LANG_SOURCE.
+       * lib/autoconf/programs.m4 (_AC_PROG_LEX_YYTEXT_DECL): Likewise.
+       * tests/compile.at (AC_COMPILE_IFELSE): New test.
+       * doc/autoconf.texi (Generating Sources) <AC_LANG_CONFTEST>:
+       Document new warning.
+       <AC_LANG_DEFINES_PROVIDED>: Document new macro.
+       <AC_LANG_SOURCE>: Document use of new macro.
+       * NEWS: Document the improvement.
+       Suggested by Bruno Haible.
+
        autoconf: fix regression in AC_FUNC_SELECT_ARGTYPES
        * lib/autoconf/functions.m4 (AC_FUNC_SELECT_ARGTYPES): Fix
        quoting; regression from yesteray leaked '' into default value.
diff --git a/NEWS b/NEWS
index 3c0aed394f886e98608adb0abd0b070c9f96ac62..9998ab7c5450d315bad6582d63f11a767a8d9fe8 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,13 @@ GNU Autoconf NEWS - User visible changes.
 ** AC_INIT again allows URLs with '?' for its BUG-REPORT argument.
    Regression introduced in 2.66.
 
+** The macros AC_PREPROC_IFELSE, AC_COMPILE_IFELSE, AC_LINK_IFELSE, and
+   AC_RUN_IFELSE now warn if the first argument failed to use
+   AC_LANG_SOURCE or AC_LANG_PROGRAM to generate the conftest file
+   contents.  A new macro AC_LANG_DEFINES_PROVIDED exists if you have
+   a compelling reason why you cannot use AC_LANG_SOURCE but must
+   avoid the warning.
+
 
 * Major changes in Autoconf 2.67 (2010-07-21) [stable]
   Released by Eric Blake, based on git versions 2.66.*.
index 98dafa9d46568ccdd6459b04ca84a33700cfa9aa..cf0c0a1041e6979e7521546cdbfad8fbc0053691 100644 (file)
@@ -8730,15 +8730,38 @@ the results of all of the @code{AC_DEFINE} performed so far.
 Note that the @var{source} is evaluated exactly once, like regular
 Autoconf macro arguments, and therefore (i) you may pass a macro
 invocation, (ii) if not, be sure to double quote if needed.
+
+This macro issues a warning during @command{autoconf} processing if
+@var{source} does not include an expansion of the macro
+@code{AC_LANG_DEFINES_PROVIDED} (note that both @code{AC_LANG_SOURCE} and
+@code{AC_LANG_PROGRAM} call this macro, and thus avoid the warning).
+
+This macro is seldom called directly, but is used under the hood by more
+common macros such as @code{AC_COMPILE_IFELSE} and @code{AC_RUN_IFELSE}.
+@end defmac
+
+@defmac AC_LANG_DEFINES_PROVIDED
+@acindex{LANG_DEFINES_PROVIDED}
+This macro is called as a witness that the file
+@file{conftest.@var{extension}} appropriate for the current language is
+complete, including all previously determined results from
+@code{AC_DEFINE}.  This macro is seldom called directly, but exists if
+you have a compelling reason to write a conftest file without using
+@code{AC_LANG_SOURCE}, yet still want to avoid a syntax warning from
+@code{AC_LANG_CONFTEST}.
 @end defmac
 
 @defmac AC_LANG_SOURCE (@var{source})
 @acindex{LANG_SOURCE}
 Expands into the @var{source}, with the definition of
-all the @code{AC_DEFINE} performed so far.
+all the @code{AC_DEFINE} performed so far.  This macro includes an
+expansion of @code{AC_LANG_DEFINES_PROVIDED}.
+
+In many cases, you may find it more convenient to use the wrapper
+@code{AC_LANG_PROGRAM}.
 @end defmac
 
-For instance executing (observe the double quotation!):
+For instance, executing (observe the double quotation!):
 
 @example
 @c If you change this example, adjust tests/compile.at:AC_LANG_SOURCE example.
index 9a28adf99fc6dd138e184bf9fa6e06fbf3b05005..233644a0c7c18fc6cec0f38ee5995cc854347b04 100644 (file)
@@ -1930,7 +1930,7 @@ AC_DEFUN([AC_C_TYPEOF],
 # Expands to some language dependent source code for testing the presence of
 # OpenMP.
 AC_DEFUN([_AC_LANG_OPENMP],
-[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
+[AC_LANG_SOURCE([_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])])
 
 # _AC_LANG_OPENMP(C)
 # ------------------
index 0a487ee9da44c1e932471b80f1527f109947f039..5e48468db9674abe14180f6b65377928cee849f7 100644 (file)
@@ -897,13 +897,13 @@ AC_DEFUN([__AC_FC_NAME_MANGLING],
 [_AC_FORTRAN_ASSERT()dnl
 AC_CACHE_CHECK([for _AC_LANG name-mangling scheme],
               ac_cv_[]_AC_LANG_ABBREV[]_mangling,
-[AC_COMPILE_IFELSE(
+[AC_COMPILE_IFELSE([AC_LANG_DEFINES_PROVIDED
 [      subroutine foobar()
       return
       end
       subroutine foo_bar()
       return
-      end],
+      end]],
 [mv conftest.$ac_objext cfortran_test.$ac_objext
 
   ac_save_LIBS=$LIBS
@@ -1186,12 +1186,12 @@ for ac_flag in none -ffree-form -FR -free -qfree -Mfree -Mfreeform \
 do
   test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_freeform_FCFLAGS_save $ac_flag"
 dnl Use @&t@ below to ensure that editors don't turn 8+ spaces into tab.
-  AC_COMPILE_IFELSE([
+  AC_COMPILE_IFELSE([AC_LANG_DEFINES_PROVIDED[
   program freeform
        ! FIXME: how to best confuse non-freeform compilers?
        print *, 'Hello ', &
      @&t@     'world.'
-       end],
+       end]],
                    [ac_cv_fc_freeform=$ac_flag; break])
 done
 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
@@ -1241,10 +1241,10 @@ for ac_flag in none -ffixed-form -fixed -qfixed -Mfixed -fixedform "-f fixed" \
               +source=fixed -fix
 do
   test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_fixedform_FCFLAGS_save $ac_flag"
-  AC_COMPILE_IFELSE([
+  AC_COMPILE_IFELSE([AC_LANG_DEFINES_PROVIDED[
 C     This comment should confuse free-form compilers.
       program main
-      end],
+      end]],
                    [ac_cv_fc_fixedform=$ac_flag; break])
 done
 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
@@ -1324,8 +1324,8 @@ for ac_flag in none \
               "-W $ac_fc_line_len" +extend_source -wide -e
 do
   test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_line_length_FCFLAGS_save $ac_flag"
-  AC_COMPILE_IFELSE([$ac_fc_line_length_test
-      end subroutine],
+  AC_COMPILE_IFELSE([AC_LANG_DEFINES_PROVIDED[$ac_fc_line_length_test
+      end subroutine]],
                    [ac_cv_fc_line_length=$ac_flag; break])
 done
 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
index 3e8de53e018359296ca2952b571abf1f5ed39441..bd4b68b7030636bfcdf2157d4e93852de2a83938 100644 (file)
@@ -192,7 +192,10 @@ m4_define([AC_LANG_DEFINE],
 # ----------------------
 # Save the BODY in `conftest.$ac_ext'.  Add a trailing new line.
 AC_DEFUN([AC_LANG_CONFTEST],
-[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
+[m4_pushdef([_AC_LANG_DEFINES_PROVIDED],
+  [m4_warn([syntax], [$0: no AC_LANG_SOURCE call detected in body])])]dnl
+[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)]dnl
+[[]_AC_LANG_DEFINES_PROVIDED[]m4_popdef([_AC_LANG_DEFINES_PROVIDED])])
 
 
 # AC_LANG_CONFTEST()(BODY)
@@ -203,13 +206,20 @@ m4_define([AC_LANG_CONFTEST()],
 $1
 _ACEOF])
 
+# AC_LANG_DEFINES_PROVIDED
+# ------------------------
+# Witness macro that all prior AC_DEFINE results have been output
+# into the current expansion, to silence warning from AC_LANG_CONFTEST.
+m4_define([AC_LANG_DEFINES_PROVIDED],
+[m4_define([_$0])])
+
 
 # AC_LANG_SOURCE(BODY)
 # --------------------
 # Produce a valid source for the current language, which includes the
 # BODY, and as much as possible `confdefs.h'.
 AC_DEFUN([AC_LANG_SOURCE],
-[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
+[AC_LANG_DEFINES_PROVIDED[]_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
 
 
 # AC_LANG_SOURCE()(BODY)
index 4b9060f079a71cef9895c1121daa8336988e7821..e7eeb6f8ea38d3be32a82842f821f0a4476cb97b 100644 (file)
@@ -756,7 +756,8 @@ if test -z "${LEXLIB+set}"; then
     ac_cv_lib_lex='none needed'
     for ac_lib in '' -lfl -ll; do
       LIBS="$ac_lib $ac_save_LIBS"
-      AC_LINK_IFELSE([`cat $LEX_OUTPUT_ROOT.c`], [ac_cv_lib_lex=$ac_lib])
+      AC_LINK_IFELSE([AC_LANG_DEFINES_PROVIDED[`cat $LEX_OUTPUT_ROOT.c`]],
+       [ac_cv_lib_lex=$ac_lib])
       test "$ac_cv_lib_lex" != 'none needed' && break
     done
     LIBS=$ac_save_LIBS
@@ -772,9 +773,9 @@ AC_CACHE_CHECK(whether yytext is a pointer, ac_cv_prog_lex_yytext_pointer,
 ac_cv_prog_lex_yytext_pointer=no
 ac_save_LIBS=$LIBS
 LIBS="$LEXLIB $ac_save_LIBS"
-AC_LINK_IFELSE(
+AC_LINK_IFELSE([AC_LANG_DEFINES_PROVIDED
   [#define YYTEXT_POINTER 1
-`cat $LEX_OUTPUT_ROOT.c`],
+`cat $LEX_OUTPUT_ROOT.c`]],
   [ac_cv_prog_lex_yytext_pointer=yes])
 LIBS=$ac_save_LIBS
 ])
index 6a1092b063c35092220bf90ce15fc4253c8a48e0..dd7175b0794d459bf647bf6e44dd202295b0da58 100644 (file)
@@ -260,11 +260,55 @@ fputs (hw, stdout);
 AT_CLEANUP
 
 
+## ------------------- ##
+## AC_COMPILE_IFELSE.  ##
+## ------------------- ##
+
+AT_SETUP([AC_COMPILE_IFELSE])
+AT_KEYWORDS([AC_LANG_DEFINES_PROVIDED])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_COMPILE_IFELSE([int main () { return 0; }], [],
+  [AC_MSG_ERROR([compiling trivial program failed])])
+]])
+
+AT_CHECK_AUTOCONF([], [], [], [stderr])
+AT_CHECK([grep 'no AC_LANG_SOURCE call detected in body' stderr], [], [ignore])
+AT_CHECK_AUTOCONF([-W no-syntax])
+AT_CHECK_CONFIGURE([-q])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_COMPILE_IFELSE([AC_LANG_DEFINES_PROVIDED()int main () { return 0; }], [],
+  [AC_MSG_ERROR([compiling trivial program failed])])
+]])
+
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE([-q])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return 0])],
+             [],
+             [AC_MSG_ERROR([compiling `return 0' failed])])
+
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return 2])],
+             [],
+             [AC_MSG_ERROR([compiling `return 2' failed])])
+]])
+
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE([-q])
+
+AT_CLEANUP
+
 ## --------------- ##
 ## AC_RUN_IFELSE.  ##
 ## --------------- ##
 
 AT_SETUP([AC_RUN_IFELSE])
+AT_KEYWORDS([AC_TRY_RUN])
 
 AT_DATA([configure.ac],
 [[AC_INIT