Avoid the need for AC_LIBSOURCES in m4 macros.
[gnulib.git] / gnulib-tool
index dfbdce8..3689944 100755 (executable)
@@ -22,7 +22,7 @@
 
 progname=$0
 package=gnulib
-cvsdatestamp='$Date: 2006-08-08 11:35:22 $'
+cvsdatestamp='$Date: 2006-08-21 18:49:51 $'
 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
 
@@ -619,7 +619,7 @@ func_all_modules ()
       (cd "$local_gnulib_dir/modules" && ls -1 | sed -e 's,\.diff$,,')
     fi
   } \
-      | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
+      | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^COPYING$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
       | sed -e '/-tests$/d' \
       | LC_ALL=C sort \
       | LC_ALL=C uniq
@@ -629,14 +629,18 @@ func_all_modules ()
 # verifies a module name
 func_verify_module ()
 {
-  if ! { test -f "$gnulib_dir/modules/$module" \
-         || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
-              && test -f "$local_gnulib_dir/modules/$module"; }; } \
-     || test "CVS" = "$module" \
-     || test "ChangeLog" = "$module" \
-     || test "README" = "$module" \
-     || test "TEMPLATE" = "$module" \
-     || test "TEMPLATE-TESTS" = "$module"; then
+  if { test -f "$gnulib_dir/modules/$module" \
+       || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
+            && test -f "$local_gnulib_dir/modules/$module"; }; } \
+     && test "CVS" != "$module" \
+     && test "ChangeLog" != "$module" \
+     && test "COPYING" != "$module" \
+     && test "README" != "$module" \
+     && test "TEMPLATE" != "$module" \
+     && test "TEMPLATE-TESTS" != "$module"; then
+    # OK, $module is a correct module name.
+    :
+  else
     echo "gnulib-tool: module $module doesn't exist" 1>&2
     module=
   fi
@@ -894,12 +898,44 @@ func_emit_lib_Makefile_am ()
   # No need to generate dependencies since the sources are in gnulib, not here.
   echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
   echo
-  echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
+  (
+    for module in $modules; do
+      func_verify_nontests_module
+      if test -n "$module"; then
+        {
+          func_get_automake_snippet "$module" |
+            sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
+          if test "$module" = 'alloca'; then
+            echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
+          fi
+        } > amsnippet.tmp
+        # Skip the contents if its entirely empty.
+        if grep '[^     ]' amsnippet.tmp > /dev/null ; then
+          echo "## begin gnulib module $module"
+          echo
+          cat amsnippet.tmp
+          echo "## end   gnulib module $module"
+          echo
+        fi
+        rm -f amsnippet.tmp
+      fi
+    done
+  ) > allsnippets.tmp
+  if grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *= *$libname\\.$libext\$" allsnippets.tmp > /dev/null; then
+    # One of the snippets already specifies an installation location for the
+    # library. Don't confuse automake by saying it should not be installed.
+    :
+  else
+    # By default, the generated library should not be installed.
+    echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
+  fi
   echo
   echo "${libname}_${libext}_SOURCES ="
   echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
   echo "noinst_HEADERS ="
-  echo "pkgdata_DATA ="
+  if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
+    echo "pkgdata_DATA ="
+  fi
   echo "EXTRA_DIST ="
   echo "BUILT_SOURCES ="
   echo "SUFFIXES ="
@@ -911,27 +947,7 @@ func_emit_lib_Makefile_am ()
   echo
   echo "AM_CPPFLAGS ="
   echo
-  for module in $modules; do
-    func_verify_nontests_module
-    if test -n "$module"; then
-      {
-        func_get_automake_snippet "$module" |
-          sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
-        if test "$module" = 'alloca'; then
-          echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
-        fi
-      } > amsnippet.tmp
-      # Skip the contents if its entirely empty.
-      if grep '[^       ]' amsnippet.tmp > /dev/null ; then
-        echo "## begin gnulib module $module"
-        echo
-        cat amsnippet.tmp
-        echo "## end   gnulib module $module"
-        echo
-      fi
-      rm -f amsnippet.tmp
-    fi
-  done
+  cat allsnippets.tmp
   echo
   echo "mostlyclean-local: mostlyclean-generic"
   echo "       @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
@@ -942,6 +958,7 @@ func_emit_lib_Makefile_am ()
   echo "         done"
   echo
   echo "# Makefile.am ends here"
+  rm -f allsnippets.tmp
 }
 
 # func_emit_tests_Makefile_am
@@ -969,6 +986,23 @@ func_emit_tests_Makefile_am ()
   echo
   echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
   echo
+  (
+    for module in $modules; do
+      func_verify_tests_module
+      if test -n "$module"; then
+        func_get_automake_snippet "$module" > amsnippet.tmp
+        # Skip the contents if its entirely empty.
+        if grep '[^     ]' amsnippet.tmp > /dev/null ; then
+          echo "## begin gnulib module $module"
+          echo
+          cat amsnippet.tmp
+          echo "## end   gnulib module $module"
+          echo
+        fi
+        rm -f amsnippet.tmp
+      fi
+    done
+  ) > allsnippets.tmp
   # Nothing is being added to SUBDIRS; nevertheless the existence of this
   # variable is needed to avoid an error from automake:
   #   "AM_GNU_GETTEXT used but SUBDIRS not defined"
@@ -978,7 +1012,9 @@ func_emit_tests_Makefile_am ()
   echo "noinst_PROGRAMS ="
   echo "check_PROGRAMS ="
   echo "noinst_HEADERS ="
-  echo "pkgdata_DATA ="
+  if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
+    echo "pkgdata_DATA ="
+  fi
   echo "EXTRA_DIST ="
   echo "BUILT_SOURCES ="
   echo "SUFFIXES ="
@@ -995,21 +1031,7 @@ func_emit_tests_Makefile_am ()
   echo
   echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
   echo
-  for module in $modules; do
-    func_verify_tests_module
-    if test -n "$module"; then
-      func_get_automake_snippet "$module" > amsnippet.tmp
-      # Skip the contents if its entirely empty.
-      if grep '[^       ]' amsnippet.tmp > /dev/null ; then
-        echo "## begin gnulib module $module"
-        echo
-        cat amsnippet.tmp
-        echo "## end   gnulib module $module"
-        echo
-      fi
-      rm -f amsnippet.tmp
-    fi
-  done
+  cat allsnippets.tmp
   echo "# Clean up after Solaris cc."
   echo "clean-local:"
   echo "       rm -rf SunWS_cache"
@@ -1023,6 +1045,7 @@ func_emit_tests_Makefile_am ()
   echo "         done"
   echo
   echo "# Makefile.am ends here"
+  rm -f allsnippets.tmp
 }
 
 # func_import modules
@@ -1526,6 +1549,8 @@ func_import ()
     echo "# any checks for libraries, header files, types and library functions."
     echo "AC_DEFUN([${macro_prefix}_EARLY],"
     echo "["
+    echo "  m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
+    echo "  m4_pattern_allow([^gl_ES$])dnl a valid locale name"
     echo "  AC_REQUIRE([AC_PROG_RANLIB])"
     if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
       echo "  AC_REQUIRE([AC_GNU_SOURCE])"
@@ -1872,6 +1897,10 @@ func_create_testdir ()
    echo "AC_PROG_CC"
    echo "AC_PROG_INSTALL"
    echo "AC_PROG_MAKE_SET"
+   echo
+   echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
+   echo "m4_pattern_allow([^gl_ES$])dnl a valid locale name"
+   echo
    echo "AC_PROG_RANLIB"
    echo
    if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then