Move gnulib-tool invocation back from autopull.sh to autogen.sh.

* autogen.sh: Revert last change. Improve comments.
* autopull.sh: Only call 'gitsub.sh pull'.
* HACKING: Mention autopull.sh.
diff --git a/.gitignore b/.gitignore
index 7f388a0..74300e4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -250,7 +250,7 @@
 /libcharset/build-aux/install-sh
 /libcharset/build-aux/mkinstalldirs
 
-# Other files brought in by autopull.sh:
+# Other files brought in by autogen.sh:
 /build-aux/config.guess
 /build-aux/config.sub
 /libcharset/build-aux/config.guess
diff --git a/ChangeLog b/ChangeLog
index b21cc7b..6b67b98 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2022-07-18  Bruno Haible  <bruno@clisp.org>
+
+	Move gnulib-tool invocation back from autopull.sh to autogen.sh.
+	* autogen.sh: Revert last change. Improve comments.
+	* autopull.sh: Only call 'gitsub.sh pull'.
+	* HACKING: Mention autopull.sh.
+
 2022-07-17  Bruno Haible  <bruno@clisp.org>
 
 	Split autogen.sh into autopull.sh and autogen.sh.
diff --git a/HACKING b/HACKING
index 933cc3c..fe28688 100644
--- a/HACKING
+++ b/HACKING
@@ -55,7 +55,7 @@
 Then you can proceed with "./configure" as usual.
 
 Each time you want to update the source, do not only "git pull".  Instead do
-  git pull && ./gitsub.sh pull
+  git pull && ./autopull.sh
   ./autogen.sh
 
 
diff --git a/autogen.sh b/autogen.sh
index 90fc9f9..dd72d83 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -23,8 +23,69 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
-# Prerequisite (if not used from a released tarball): ./autopull.sh
-# Usage: ./autogen.sh
+# Prerequisite (if not used from a released tarball): either
+#   - the GNULIB_SRCDIR environment variable pointing to a gnulib checkout, or
+#   - a preceding invocation of './autopull.sh'.
+#
+# Usage: ./autogen.sh [--skip-gnulib]
+#
+# Options:
+#   --skip-gnulib       Avoid fetching files from Gnulib.
+#                       This option is useful
+#                       - when you are working from a released tarball (possibly
+#                         with modifications), or
+#                       - as a speedup, if the set of gnulib modules did not
+#                         change since the last time you ran this script.
+
+skip_gnulib=false
+while :; do
+  case "$1" in
+    --skip-gnulib) skip_gnulib=true; shift;;
+    *) break ;;
+  esac
+done
+
+# ========== Copy files from gnulib, automake, or the internet. ==========
+
+if test $skip_gnulib = false; then
+  if test -n "$GNULIB_SRCDIR"; then
+    test -d "$GNULIB_SRCDIR" || {
+      echo "*** GNULIB_SRCDIR is set but does not point to an existing directory." 1>&2
+      exit 1
+    }
+  else
+    GNULIB_SRCDIR=`pwd`/gnulib
+    test -d "$GNULIB_SRCDIR" || {
+      echo "*** Subdirectory 'gnulib' does not yet exist. Use './gitsub.sh pull' to create it, or set the environment variable GNULIB_SRCDIR." 1>&2
+      exit 1
+    }
+  fi
+  # Now it should contain a gnulib-tool.
+  GNULIB_TOOL="$GNULIB_SRCDIR/gnulib-tool"
+  test -f "$GNULIB_TOOL" || {
+    echo "*** gnulib-tool not found." 1>&2
+    exit 1
+  }
+  for file in build-aux/compile build-aux/ar-lib; do
+    $GNULIB_TOOL --copy-file $file || exit $?
+    chmod a+x $file || exit $?
+  done
+  make -f Makefile.devel \
+       gnulib-clean srclib/Makefile.gnulib gnulib-imported-files srclib/Makefile.in \
+       GNULIB_TOOL="$GNULIB_TOOL"
+fi
+
+# Copy files into the libcharset subpackage, so that libcharset/autogen.sh
+# does not need to invoke gnulib-tool nor automake.
+for file in INSTALL.generic; do
+  cp -p $file libcharset/$file || exit $?
+done
+for file in config.guess config.libpath config.sub install-sh libtool-reloc mkinstalldirs; do
+  cp -p build-aux/$file libcharset/build-aux/$file || exit $?
+done
+for file in codeset.m4 fcntl-o.m4 lib-ld.m4 relocatable.m4 relocatable-lib.m4 visibility.m4; do
+  cp -p srcm4/$file libcharset/m4/$file || exit $?
+done
 
 # ========== Generate files. ==========
 
diff --git a/autopull.sh b/autopull.sh
index a0016a7..0d08d35 100755
--- a/autopull.sh
+++ b/autopull.sh
@@ -1,12 +1,8 @@
 #!/bin/sh
 # Convenience script for fetching auxiliary files that are omitted from
 # the version control repository of this package.
-#
-# This script requires either
-#   - the GNULIB_SRCDIR environment variable pointing to a gnulib checkout, or
-#   - a preceding invocation of './gitsub.sh pull'.
 
-# Copyright (C) 2003-2012, 2016, 2018-2022 Free Software Foundation, Inc.
+# Copyright (C) 2022 Free Software Foundation, Inc.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -23,46 +19,6 @@
 
 # Usage: ./autopull.sh
 
-./gitsub.sh pull
-
-# ========== Copy files from gnulib, automake, or the internet. ==========
-
-if test -n "$GNULIB_SRCDIR"; then
-  test -d "$GNULIB_SRCDIR" || {
-    echo "*** GNULIB_SRCDIR is set but does not point to an existing directory." 1>&2
-    exit 1
-  }
-else
-  GNULIB_SRCDIR=`pwd`/gnulib
-  test -d "$GNULIB_SRCDIR" || {
-    echo "*** Subdirectory 'gnulib' does not yet exist. Use './gitsub.sh pull' to create it, or set the environment variable GNULIB_SRCDIR." 1>&2
-    exit 1
-  }
-fi
-# Now it should contain a gnulib-tool.
-GNULIB_TOOL="$GNULIB_SRCDIR/gnulib-tool"
-test -f "$GNULIB_TOOL" || {
-  echo "*** gnulib-tool not found." 1>&2
-  exit 1
-}
-for file in build-aux/compile build-aux/ar-lib; do
-  $GNULIB_TOOL --copy-file $file || exit $?
-  chmod a+x $file || exit $?
-done
-make -f Makefile.devel \
-     gnulib-clean srclib/Makefile.gnulib gnulib-imported-files srclib/Makefile.in \
-     GNULIB_TOOL="$GNULIB_TOOL"
-
-# Copy files into the libcharset subpackage, so that libcharset/autogen.sh
-# does not need to invoke gnulib-tool nor automake.
-for file in INSTALL.generic; do
-  cp -p $file libcharset/$file || exit $?
-done
-for file in config.guess config.libpath config.sub install-sh libtool-reloc mkinstalldirs; do
-  cp -p build-aux/$file libcharset/build-aux/$file || exit $?
-done
-for file in codeset.m4 fcntl-o.m4 lib-ld.m4 relocatable.m4 relocatable-lib.m4 visibility.m4; do
-  cp -p srcm4/$file libcharset/m4/$file || exit $?
-done
+./gitsub.sh pull || exit 1
 
 echo "$0: done.  Now you can run './autogen.sh'."