Avoid side effects from tests-related modules on the compilation of lib.
authorBruno Haible <bruno@clisp.org>
Sat, 27 Mar 2010 17:54:30 +0000 (18:54 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 27 Mar 2010 17:54:30 +0000 (18:54 +0100)
ChangeLog
gnulib-tool
m4/gnulib-common.m4

index d7ce559..57ded7c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2010-03-27  Bruno Haible  <bruno@clisp.org>
 
+       Avoid side effects from tests-related modules on the compilation of lib.
+       * m4/gnulib-common.m4 (gl_MODULE_INDICATOR_CONDITION): New macro.
+       (gl_MODULE_INDICATOR_SET_VARIABLE): Use its expansion as a value.
+       * gnulib-tool (func_emit_tests_Makefile_am): Accept a witness_macro
+       parameter. Emit into AM_CPPFLAGS a definition of the designated C
+       macro.
+       (func_import): Define a witness macro. Assign it a value that depends
+       on the current package. Override gl_MODULE_INDICATOR_CONDITION for the
+       tests-related modules.
+       (func_create_testdir): Update func_emit_tests_Makefile_am invocation.
+       Reported by Jim Meyering.
+
+2010-03-27  Bruno Haible  <bruno@clisp.org>
+
        Factorize common .m4 code.
        * m4/gnulib-common.m4 (gl_MODULE_INDICATOR_SET_VARIABLE): New macro.
        * m4/arpa_inet_h.m4 (gl_ARPA_INET_MODULE_INDICATOR): Use it.
index 493dfa3..c4f11ac 100755 (executable)
@@ -2761,7 +2761,7 @@ func_emit_po_POTFILES_in ()
   echo "$files" | sed -n -e "s,^lib/,$sourcebase/,p"
 }
 
-# func_emit_tests_Makefile_am
+# func_emit_tests_Makefile_am witness_macro
 # emits the contents of tests makefile to standard output.
 # Input:
 # - local_gnulib_dir  from --local-dir
@@ -2785,6 +2785,7 @@ func_emit_po_POTFILES_in ()
 # - uses_subdirs    nonempty if object files in subdirs exist
 func_emit_tests_Makefile_am ()
 {
+  witness_macro="$1"
   if test "$libtool" = true; then
     libext=la
     sed_eliminate_LDFLAGS="$sed_noop"
@@ -2913,6 +2914,9 @@ func_emit_tests_Makefile_am ()
   done
   echo
   echo "AM_CPPFLAGS = \\"
+  if test -n "${witness_macro}"; then
+    echo "  -D@${witness_macro}@=1 \\"
+  fi
   echo "  -I. -I\$(srcdir) \\"
   echo "  -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
   echo "  -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
@@ -4140,6 +4144,13 @@ s,//*$,/,'
     echo "  gltests_ltlibdeps="
     func_emit_initmacro_start ${macro_prefix}tests
     echo "  gl_source_base='$testsbase'"
+    # Define a tests witness macro that depends on the package.
+    # PACKAGE is defined by AM_INIT_AUTOMAKE, PACKAGE_TARNAME is defined by AC_INIT.
+    # See <http://lists.gnu.org/archive/html/automake/2009-05/msg00145.html>.
+    echo "  ${macro_prefix}tests_WITNESS=IN_\`echo \"\${PACKAGE-\$PACKAGE_TARNAME}\" | LC_ALL=C tr 'a-z' 'A-Z' | LC_ALL=C sed -e 's/[^A-Z0-9_]/_/g'\`_GNULIB_TESTS"
+    echo "  AC_SUBST([${macro_prefix}tests_WITNESS])"
+    echo "  gl_module_indicator_condition=\$${macro_prefix}tests_WITNESS"
+    echo "  m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [\$gl_module_indicator_condition])"
     for module in $testsrelated_modules; do
       func_verify_module
       if test -n "$module"; then
@@ -4152,6 +4163,7 @@ s,//*$,/,'
                 -e 's/gl_ltlibdeps/gltests_ltlibdeps/g'
       fi
     done
+    echo "  m4_popdef([gl_MODULE_INDICATOR_CONDITION])"
     func_emit_initmacro_end ${macro_prefix}tests
     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
     # created using libtool, because libtool already handles the dependencies.
@@ -4210,7 +4222,7 @@ s,//*$,/,'
     func_dest_tmpfilename $testsbase/$makefile_am
     destfile="$testsbase/$makefile_am"
     modules="$testsrelated_modules"
-    func_emit_tests_Makefile_am > "$tmpfile"
+    func_emit_tests_Makefile_am "${macro_prefix}tests_WITNESS" > "$tmpfile"
     if test -f "$destdir"/$testsbase/$makefile_am; then
       if cmp "$destdir"/$testsbase/$makefile_am "$tmpfile" > /dev/null; then
         rm -f "$tmpfile"
@@ -4620,7 +4632,7 @@ func_create_testdir ()
     # Create $testsbase/Makefile.am.
     use_libtests=false
     destfile="$testsbase/Makefile.am"
-    func_emit_tests_Makefile_am > "$testdir/$testsbase/Makefile.am"
+    func_emit_tests_Makefile_am "" > "$testdir/$testsbase/Makefile.am"
     any_uses_subdirs="$any_uses_subdirs$uses_subdirs"
     # Create $testsbase/configure.ac.
     (echo "# Process this file with autoconf to produce a configure script."
index 0000cc6..b578f07 100644 (file)
@@ -1,4 +1,4 @@
-# gnulib-common.m4 serial 14
+# gnulib-common.m4 serial 15
 dnl Copyright (C) 2007-2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -37,12 +37,18 @@ AC_DEFUN([gl_COMMON_BODY], [
 ])
 ])
 
+# gl_MODULE_INDICATOR_CONDITION
+# expands to a C preprocessor expression that evaluates to 1 or 0, depending
+# whether a gnulib module that has been requested shall be considered present
+# or not.
+AC_DEFUN([gl_MODULE_INDICATOR_CONDITION], [1])
+
 # gl_MODULE_INDICATOR_SET_VARIABLE([modulename])
 # sets the shell variable that indicates the presence of the given module to
 # a C preprocessor expression that will evaluate to 1.
 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
 [
-  GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
+  GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=gl_MODULE_INDICATOR_CONDITION
 ])
 
 # gl_MODULE_INDICATOR([modulename])