Blame build-aux/gnu-web-doc-update

Packit 33f14e
#!/bin/sh
Packit 33f14e
# Run this after each non-alpha release, to update the web documentation at
Packit 33f14e
# http://www.gnu.org/software/$pkg/manual/
Packit 33f14e
Packit 33f14e
VERSION=2016-01-12.23; # UTC
Packit 33f14e
Packit 33f14e
# Copyright (C) 2009-2017 Free Software Foundation, Inc.
Packit 33f14e
Packit 33f14e
# This program is free software: you can redistribute it and/or modify
Packit 33f14e
# it under the terms of the GNU General Public License as published by
Packit 33f14e
# the Free Software Foundation, either version 3 of the License, or
Packit 33f14e
# (at your option) any later version.
Packit 33f14e
Packit 33f14e
# This program is distributed in the hope that it will be useful,
Packit 33f14e
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 33f14e
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 33f14e
# GNU General Public License for more details.
Packit 33f14e
Packit 33f14e
# You should have received a copy of the GNU General Public License
Packit 33f14e
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 33f14e
Packit 33f14e
ME=$(basename "$0")
Packit 33f14e
warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
Packit 33f14e
die() { warn "$*"; exit 1; }
Packit 33f14e
Packit 33f14e
help()
Packit 33f14e
{
Packit 33f14e
  cat <
Packit 33f14e
Usage: $ME
Packit 33f14e
Packit 33f14e
Run this script from top_srcdir (no arguments) after each non-alpha
Packit 33f14e
release, to update the web documentation at
Packit 33f14e
http://www.gnu.org/software/\$pkg/manual/
Packit 33f14e
Packit 33f14e
This script assumes you're using git for revision control, and
Packit 33f14e
requires a .prev-version file as well as a Makefile, from which it
Packit 33f14e
extracts the version number and package name, respectively.  Also, it
Packit 33f14e
assumes all documentation is in the doc/ sub-directory.
Packit 33f14e
Packit 33f14e
Options:
Packit 33f14e
  -C, --builddir=DIR  location of (configured) Makefile (default: .)
Packit 33f14e
  -n, --dry-run       don't actually commit anything
Packit 33f14e
  -m, --mirror        remove out of date files from document server
Packit 33f14e
  --help              print this help, then exit
Packit 33f14e
  --version           print version number, then exit
Packit 33f14e
Packit 33f14e
Report bugs and patches to <bug-gnulib@gnu.org>.
Packit 33f14e
EOF
Packit 33f14e
  exit
Packit 33f14e
}
Packit 33f14e
Packit 33f14e
version()
Packit 33f14e
{
Packit 33f14e
  year=$(echo "$VERSION" | sed 's/[^0-9].*//')
Packit 33f14e
  cat <
Packit 33f14e
$ME $VERSION
Packit 33f14e
Copyright (C) $year Free Software Foundation, Inc,
Packit 33f14e
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
Packit 33f14e
This is free software: you are free to change and redistribute it.
Packit 33f14e
There is NO WARRANTY, to the extent permitted by law.
Packit 33f14e
EOF
Packit 33f14e
  exit
Packit 33f14e
}
Packit 33f14e
Packit 33f14e
# find_tool ENVVAR NAMES...
Packit 33f14e
# -------------------------
Packit 33f14e
# Search for a required program.  Use the value of ENVVAR, if set,
Packit 33f14e
# otherwise find the first of the NAMES that can be run (i.e.,
Packit 33f14e
# supports --version).  If found, set ENVVAR to the program name,
Packit 33f14e
# die otherwise.
Packit 33f14e
#
Packit 33f14e
# FIXME: code duplication, see also bootstrap.
Packit 33f14e
find_tool ()
Packit 33f14e
{
Packit 33f14e
  find_tool_envvar=$1
Packit 33f14e
  shift
Packit 33f14e
  find_tool_names=$@
Packit 33f14e
  eval "find_tool_res=\$$find_tool_envvar"
Packit 33f14e
  if test x"$find_tool_res" = x; then
Packit 33f14e
    for i
Packit 33f14e
    do
Packit 33f14e
      if ($i --version </dev/null) >/dev/null 2>&1; then
Packit 33f14e
       find_tool_res=$i
Packit 33f14e
       break
Packit 33f14e
      fi
Packit 33f14e
    done
Packit 33f14e
  else
Packit 33f14e
    find_tool_error_prefix="\$$find_tool_envvar: "
Packit 33f14e
  fi
Packit 33f14e
  test x"$find_tool_res" != x \
Packit 33f14e
    || die "one of these is required: $find_tool_names"
Packit 33f14e
  ($find_tool_res --version </dev/null) >/dev/null 2>&1 \
Packit 33f14e
    || die "${find_tool_error_prefix}cannot run $find_tool_res --version"
Packit 33f14e
  eval "$find_tool_envvar=\$find_tool_res"
Packit 33f14e
  eval "export $find_tool_envvar"
Packit 33f14e
}
Packit 33f14e
Packit 33f14e
## ------ ##
Packit 33f14e
## Main.  ##
Packit 33f14e
## ------ ##
Packit 33f14e
Packit 33f14e
# Requirements: everything required to bootstrap your package, plus
Packit 33f14e
# these.
Packit 33f14e
find_tool CVS cvs
Packit 33f14e
find_tool GIT git
Packit 33f14e
find_tool RSYNC rsync
Packit 33f14e
find_tool XARGS gxargs xargs
Packit 33f14e
Packit 33f14e
builddir=.
Packit 33f14e
dryrun=
Packit 33f14e
rm_stale='echo'
Packit 33f14e
while test $# != 0
Packit 33f14e
do
Packit 33f14e
  # Handle --option=value by splitting apart and putting back on argv.
Packit 33f14e
  case $1 in
Packit 33f14e
    --*=*)
Packit 33f14e
      opt=$(echo "$1" | sed -e 's/=.*//')
Packit 33f14e
      val=$(echo "$1" | sed -e 's/[^=]*=//')
Packit 33f14e
      shift
Packit 33f14e
      set dummy "$opt" "$val" "$@"; shift
Packit 33f14e
      ;;
Packit 33f14e
  esac
Packit 33f14e
Packit 33f14e
  case $1 in
Packit 33f14e
    --help|--version) ${1#--};;
Packit 33f14e
    -C|--builddir) shift; builddir=$1; shift ;;
Packit 33f14e
    -n|--dry-run) dryrun=echo; shift;;
Packit 33f14e
    -m|--mirror) rm_stale=''; shift;;
Packit 33f14e
    --*) die "unrecognized option: $1";;
Packit 33f14e
    *) break;;
Packit 33f14e
  esac
Packit 33f14e
done
Packit 33f14e
Packit 33f14e
test $# = 0 \
Packit 33f14e
  || die "too many arguments"
Packit 33f14e
Packit 33f14e
prev=.prev-version
Packit 33f14e
version=$(cat $prev) || die "no $prev file?"
Packit 33f14e
pkg=$(sed -n 's/^PACKAGE = \(.*\)/\1/p' $builddir/Makefile) \
Packit 33f14e
  || die "no Makefile?"
Packit 33f14e
tmp_branch=web-doc-$version-$$
Packit 33f14e
current_branch=$($GIT branch | sed -ne '/^\* /{s///;p;q;}')
Packit 33f14e
Packit 33f14e
cleanup()
Packit 33f14e
{
Packit 33f14e
  __st=$?
Packit 33f14e
  $dryrun rm -rf "$tmp"
Packit 33f14e
  $GIT checkout "$current_branch"
Packit 33f14e
  $GIT submodule update --recursive
Packit 33f14e
  $GIT branch -d $tmp_branch
Packit 33f14e
  exit $__st
Packit 33f14e
}
Packit 33f14e
trap cleanup 0
Packit 33f14e
trap 'exit $?' 1 2 13 15
Packit 33f14e
Packit 33f14e
# We must build using sources for which --version reports the
Packit 33f14e
# just-released version number, not some string like 7.6.18-20761.
Packit 33f14e
# That version string propagates into all documentation.
Packit 33f14e
set -e
Packit 33f14e
$GIT checkout -b $tmp_branch v$version
Packit 33f14e
$GIT submodule update --recursive
Packit 33f14e
./bootstrap
Packit 33f14e
srcdir=$(pwd)
Packit 33f14e
cd "$builddir"
Packit 33f14e
builddir=$(pwd)
Packit 33f14e
  ./config.status --recheck
Packit 33f14e
  ./config.status
Packit 33f14e
  make
Packit 33f14e
  make web-manual
Packit 33f14e
cd "$srcdir"
Packit 33f14e
set +e
Packit 33f14e
Packit 33f14e
tmp=$(mktemp -d web-doc-update.XXXXXX) || exit 1
Packit 33f14e
( cd $tmp \
Packit 33f14e
    && $CVS -d $USER@cvs.sv.gnu.org:/webcvs/$pkg co $pkg )
Packit 33f14e
$RSYNC -avP "$builddir"/doc/manual/ $tmp/$pkg/manual
Packit 33f14e
Packit 33f14e
(
Packit 33f14e
  cd $tmp/$pkg/manual
Packit 33f14e
Packit 33f14e
  # Add all the files.  This is simpler than trying to add only the
Packit 33f14e
  # new ones because of new directories
Packit 33f14e
  # First add non empty dirs individually
Packit 33f14e
  find . -name CVS -prune -o -type d \! -empty -print             \
Packit 33f14e
    | $XARGS -n1 --no-run-if-empty -- $dryrun $CVS add -ko
Packit 33f14e
  # Now add all files
Packit 33f14e
  find . -name CVS -prune -o -type f -print             \
Packit 33f14e
    | $XARGS --no-run-if-empty -- $dryrun $CVS add -ko
Packit 33f14e
Packit 33f14e
  # Report/Remove stale files
Packit 33f14e
  #   excluding doc server specific files like CVS/* and .symlinks
Packit 33f14e
  if test -n "$rm_stale"; then
Packit 33f14e
    echo 'Consider the --mirror option if all of the manual is generated,' >&2
Packit 33f14e
    echo 'which will run `cvs remove` to remove stale files.' >&2
Packit 33f14e
  fi
Packit 33f14e
  { find . \( -name CVS -o -type f -name '.*' \) -prune -o -type f -print
Packit 33f14e
    (cd "$builddir"/doc/manual/ && find . -type f -print | sed p)
Packit 33f14e
  } | sort | uniq -u \
Packit 33f14e
    | $XARGS --no-run-if-empty -- ${rm_stale:-$dryrun} $CVS remove -f
Packit 33f14e
Packit 33f14e
  $dryrun $CVS ci -m $version
Packit 33f14e
)
Packit 33f14e
Packit 33f14e
# Local variables:
Packit 33f14e
# eval: (add-hook 'write-file-hooks 'time-stamp)
Packit 33f14e
# time-stamp-start: "VERSION="
Packit 33f14e
# time-stamp-format: "%:y-%02m-%02d.%02H"
Packit 33f14e
# time-stamp-time-zone: "UTC0"
Packit 33f14e
# time-stamp-end: "; # UTC"
Packit 33f14e
# End: