#! /bin/sh
# $Id: reautoconf 73472 2025-01-15 22:51:19Z karl $
# This "reautoconf" script at the root of the TeX Live source tree 
# runs autoreconf (from PATH) in all relevant TL directories.
#
# Copyright 2008-2025 Karl Berry.
# Copyright 2004-2009 Peter Breitenlohner.
# Copyright 2005 Olaf Weber.
#
# 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

unset CDPATH

usage="Usage: $0 [OPTION]... [DIR]...
  Run \`autoreconf --no-recursive' in the directories DIR...
  (default all) of the TeX Live source tree.
  
  By default, also pass -Wno-obsolete, because Autoconf 2.70
  and later deprecated many widely used macros. See Build/m4/README for
  a lengthy discussion of this. To see the obsolete warnings (perhaps
  because you want to spend time fixing them), use --warn-obsolete.

Options:
  -f, --force     pass --force to autoreconf
  -h, --help      display this help and exit successfully
  -n, --dry-run   don't run any commands; just print them
  -q, --quiet     don't echo commands
  -v, --verbose   verbosely report processing (default)
      --warn-obsolete  do not pass -Wno-obsolete

All programs are found along PATH.

This script should be invoked only from the top level of the TeX Live
source tree.

Report bugs (and any other discussion) to:
  tlbuild@tug.org (https://lists.tug.org/tlbuild)

Version: $Id: reautoconf 73472 2025-01-15 22:51:19Z karl $
"

do_cmd=eval
do_say=echo
force=
verbose=-v
warn_obsolete=-Wno-obsolete

list=

for option
do
  case $option in
    -f | --force) force=--force              ;;
    -h | --help | --version) echo "$usage"; exit 0 ;;
    -n | --dry-run)  do_cmd=:                ;;
    -q | --quiet)    do_say=:;    verbose=   ;;
    -v | --verbose)  do_say=echo; verbose=-v ;;
    --warn-obsolete) warn_obsolete=          ;;
    -*) echo "$0: *** unrecognized option \`$option'" >&2
        echo "Try --help if you need it." >&2; exit 1 ;;
     *) list="$list $option" ;;
  esac
done

test x"$do_cmd" = x: && do_say=echo	# -n implies -v

if test ! -f ./m4/kpse-setup.m4; then
  echo "$0: *** can't find ./m4/kpse-setup.m4 (from `pwd`)" >&2
  exit 1
fi

echo "$0: using `autoconf --version | sed 1q`"
echo "$0: using `autoheader --version | sed 1q`"
echo "$0: using `autom4te --version | sed 1q`"
echo "$0: using `automake --version | sed 1q`"
echo "$0: using `aclocal --version | sed 1q`"
echo "$0: using `libtool --version | sed 1q`"
echo "$0:       if you want to use different versions, set PATH."

# Give users a chance to quit here.
$do_cmd sleep 4
$do_say "$0: starting at `date`."

do_it () {
  test x"$do_say" = x: || printf "\f "
  $do_say "$0: running \"$@\""
  $do_cmd "$@"
  if test $? -ne 0; then
    echo "$0: goodbye, exit status of $*: $?" >&2
    echo "$0: directory: `/bin/pwd`" >&2
    exit 1
  fi
}

if test "x$list" = x; then
  list=". auxdir/auxsub libs utils texk \
        `find libs utils texk -type d -name ac | sed 's,/ac\$,,'`"
fi

# Run autoreconf in all directories.
for dir in $list; do

  if test ! -d "$dir"; then
    echo "$0: $dir not a directory, skipping." >&2
    continue
  fi
  if test ! -f "$dir/configure.ac"; then
    echo "$0: $dir/configure.ac: no such file, skipping." >&2
    continue
  fi
  if test -f "$dir/ac/withenable.ac"; then
    extra_dirs=`grep 'dnl extra_dirs = ' $dir/ac/withenable.ac |
      sed 's,^.*= ,,'`
  else
    extra_dirs=
  fi
  do_it autoreconf $verbose --no-recursive \
                   $warn_obsolete $force $dir $extra_dirs
done

echo "$0: done at `date`."
