Move declarations of program_invocation_name and program_invocation_short_name to...
[gnulib.git] / gnulib-tool
index 361201c..5b44ee0 100755 (executable)
@@ -22,7 +22,7 @@
 
 progname=$0
 package=gnulib
-cvsdatestamp='$Date: 2006-08-30 18:13:34 $'
+cvsdatestamp='$Date: 2006-09-09 19:02:08 $'
 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
 
@@ -59,9 +59,6 @@ if test -z "$SORT"; then
   SORT=sort
 fi
 
-nl='
-'
-
 # func_usage
 # outputs to stdout the --help usage message.
 func_usage ()
@@ -1036,12 +1033,21 @@ func_modules_to_filelist ()
 # - actioncmd       (optional) command that will reproduce this invocation
 func_emit_lib_Makefile_am ()
 {
+  # When creating an includable Makefile.am snippet, augment variables with
+  # += instead of assigning them.
+  if test -n "$makefile_name"; then
+    assign='+='
+  else
+    assign='='
+  fi
   if test "$libtool" = true; then
     libext=la
     perhapsLT=LT
+    sed_eliminate_LDFLAGS=
   else
     libext=a
     perhapsLT=
+    sed_eliminate_LDFLAGS='/^lib_LDFLAGS[      ]*+=/d'
   fi
   echo "## Process this file with automake to produce Makefile.in."
   func_emit_copyright_notice
@@ -1049,8 +1055,10 @@ func_emit_lib_Makefile_am ()
     echo "# Reproduce by: $actioncmd"
   fi
   echo
-  # No need to generate dependencies since the sources are in gnulib, not here.
-  echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
+  if test -z "$makefile_name"; then
+    # No need to generate dependencies since the sources are in gnulib, not here.
+    echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
+  fi
   echo
   (
     for module in $modules; do
@@ -1060,6 +1068,7 @@ func_emit_lib_Makefile_am ()
           func_get_automake_snippet "$module" |
             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' |
+            sed -e "$sed_eliminate_LDFLAGS" |
             sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' |
             sed -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g'
@@ -1085,25 +1094,34 @@ func_emit_lib_Makefile_am ()
     :
   else
     # By default, the generated library should not be installed.
-    echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
+    echo "noinst_${perhapsLT}LIBRARIES $assign $libname.$libext"
   fi
   echo
   echo "${libname}_${libext}_SOURCES ="
   echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
-  echo "noinst_HEADERS ="
-  if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
-    echo "pkgdata_DATA ="
+  if test "$libtool" = true; then
+    echo "${libname}_${libext}_LDFLAGS = \$(AM_LDFLAGS)"
+  fi
+  if test -z "$makefile_name"; then
+    echo "noinst_HEADERS ="
+    # Automake versions < 1.9b create an empty pkgdatadir at installation time
+    # if you specify pkgdata_DATA to empty. This is a workaround.
+    if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
+      echo "pkgdata_DATA ="
+    fi
+    echo "EXTRA_DIST ="
+    echo "BUILT_SOURCES ="
+    echo "SUFFIXES ="
+  fi
+  echo "MOSTLYCLEANFILES $assign core *.stackdump"
+  if test -z "$makefile_name"; then
+    echo "MOSTLYCLEANDIRS ="
+    echo "CLEANFILES ="
+    echo "DISTCLEANFILES ="
+    echo "MAINTAINERCLEANFILES ="
+    echo
+    echo "AM_CPPFLAGS ="
   fi
-  echo "EXTRA_DIST ="
-  echo "BUILT_SOURCES ="
-  echo "SUFFIXES ="
-  echo "MOSTLYCLEANFILES = core *.stackdump"
-  echo "MOSTLYCLEANDIRS ="
-  echo "CLEANFILES ="
-  echo "DISTCLEANFILES ="
-  echo "MAINTAINERCLEANFILES ="
-  echo
-  echo "AM_CPPFLAGS ="
   echo
   cat allsnippets.tmp
   echo
@@ -1135,6 +1153,13 @@ func_emit_tests_Makefile_am ()
   else
     libext=a
   fi
+  if test "$libtool" = true; then
+    libext=la
+    sed_eliminate_LDFLAGS=
+  else
+    libext=a
+    sed_eliminate_LDFLAGS='/^lib_LDFLAGS[      ]*+=/d'
+  fi
   testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
   echo "## Process this file with automake to produce Makefile.in."
   func_emit_copyright_notice
@@ -1148,7 +1173,15 @@ func_emit_tests_Makefile_am ()
     for module in $modules; do
       func_verify_tests_module
       if test -n "$module"; then
-        func_get_automake_snippet "$module" > amsnippet.tmp
+        {
+          func_get_automake_snippet "$module" |
+            sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
+                -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' |
+            sed -e "$sed_eliminate_LDFLAGS" |
+            sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' |
+            sed -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
+                -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g'
+        } > amsnippet.tmp
         # Skip the contents if its entirely empty.
         if grep '[^     ]' amsnippet.tmp > /dev/null ; then
           echo "## begin gnulib module $module"
@@ -1405,7 +1438,7 @@ func_import ()
       license=`func_get_license $module`
       case $license in
         LGPL | 'GPLed build tool') ;;
-       'public domain' | 'unlimited' | 'unmodifiable license text') ;;
+        'public domain' | 'unlimited' | 'unmodifiable license text') ;;
         *) func_fatal_error "incompatible license on module $module: $license" ;;
       esac
     done
@@ -1413,13 +1446,15 @@ func_import ()
 
   # Determine script to apply to imported library files.
   sed_transform_lib_file=
-  case $nl$modules$nl in
-    *"${nl}config-h$nl"*)
+  for module in $modules; do
+    if test $module = config-h; then
       # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
       sed_transform_lib_file=$sed_transform_lib_file'
-       s/^#ifdef[       ]*HAVE_CONFIG_H[        ]*$/#if 1/
-      ' ;;
-  esac
+        s/^#ifdef[      ]*HAVE_CONFIG_H[        ]*$/#if 1/
+      '
+      break
+    fi
+  done
   if test -n "$lgpl"; then
     # Update license.
     sed_transform_lib_file=$sed_transform_lib_file'
@@ -1551,7 +1586,7 @@ func_import ()
     func_dest_tmpfilename "$g"
     func_lookup_file "$f"
     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
-    if test -n "sed_transform_lib_file"; then
+    if test -n "$sed_transform_lib_file"; then
       case "$f" in
         lib/*)
           sed -e "$sed_transform_lib_file" \
@@ -1801,8 +1836,12 @@ func_import ()
     echo "["
     if test "$libtool" = true; then
       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
+      echo "  gl_cond_libtool=true"
     else
       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
+      echo "  gl_cond_libtool=false"
+      echo "  gl_libdeps="
+      echo "  gl_ltlibdeps="
     fi
     if test "$auxdir" != "build-aux"; then
       sed_replace_build_aux='
@@ -1830,6 +1869,15 @@ func_import ()
         fi
       fi
     done
+    # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
+    # created using libtool, because libtool already handles the dependencies.
+    if test "$libtool" != true; then
+      libname_upper=`echo "$libname" | tr 'a-z' 'A-Z'`
+      echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
+      echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
+      echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
+      echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
+    fi
     echo "])"
     echo
     echo "# This macro records the list of files which have been installed by"
@@ -2074,8 +2122,12 @@ func_create_testdir ()
      fi
      if test "$libtool" = true; then
        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
+       echo "gl_cond_libtool=true"
      else
        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
+       echo "gl_cond_libtool=false"
+       echo "gl_libdeps="
+       echo "gl_ltlibdeps="
      fi
      # Wrap the set of autoconf snippets into an autoconf macro that is then
      # invoked. This is needed because autoconf does not support AC_REQUIRE
@@ -2113,6 +2165,15 @@ func_create_testdir ()
            | sed -e "$sed_replace_build_aux"
        fi
      done
+     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
+     # created using libtool, because libtool already handles the dependencies.
+     if test "$libtool" != true; then
+       libname_upper=`echo "$libname" | tr 'a-z' 'A-Z'`
+       echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
+       echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
+       echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
+       echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
+     fi
      echo "])"
      echo "gl_INIT"
      echo
@@ -2169,8 +2230,12 @@ func_create_testdir ()
    fi
    if test "$libtool" = true; then
      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
+     echo "gl_cond_libtool=true"
    else
      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
+     echo "gl_cond_libtool=false"
+     echo "gl_libdeps="
+     echo "gl_ltlibdeps="
    fi
    # Wrap the set of autoconf snippets into an autoconf macro that is then
    # invoked. This is needed because autoconf does not support AC_REQUIRE
@@ -2198,6 +2263,15 @@ func_create_testdir ()
          | sed -e "$sed_replace_build_aux"
      fi
    done
+   # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
+   # created using libtool, because libtool already handles the dependencies.
+   if test "$libtool" != true; then
+     libname_upper=`echo "$libname" | tr 'a-z' 'A-Z'`
+     echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
+     echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
+     echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
+     echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
+   fi
    echo "])"
    echo "gl_INIT"
    echo
@@ -2417,7 +2491,12 @@ case $mode in
           if test $# = 0; then
             # No further arguments. Guess the user wants to update all of them.
             for m4base in $m4dirs; do
-              func_import
+              # Perform func_import in a subshell, so that variable values
+              # such as
+              #   local_gnulib_dir, avoidlist, sourcebase, m4base, docbase,
+              #   testsbase, libname, lgpl, makefile_name, libtool, macro_prefix
+              # don't propagate from one directory to another.
+              (func_import) || exit 1
             done
           else
             # Really ambiguous.
@@ -2598,3 +2677,8 @@ trap '' 0
 trap 'exit $?' 1 2 3 15
 
 exit 0
+
+# Local Variables:
+# indent-tabs-mode: nil
+# whitespace-check-buffer-indent: nil
+# End: