Blame autoconf/ylwrap

Packit Service 5195f2
#! /bin/sh
Packit Service 5195f2
# ylwrap - wrapper for lex/yacc invocations.
Packit Service 5195f2
Packit Service 5195f2
scriptversion=2013-01-12.17; # UTC
Packit Service 5195f2
Packit Service 5195f2
# Copyright (C) 1996-2014 Free Software Foundation, Inc.
Packit Service 5195f2
#
Packit Service 5195f2
# Written by Tom Tromey <tromey@cygnus.com>.
Packit Service 5195f2
#
Packit Service 5195f2
# This program is free software; you can redistribute it and/or modify
Packit Service 5195f2
# it under the terms of the GNU General Public License as published by
Packit Service 5195f2
# the Free Software Foundation; either version 2, or (at your option)
Packit Service 5195f2
# any later version.
Packit Service 5195f2
#
Packit Service 5195f2
# This program is distributed in the hope that it will be useful,
Packit Service 5195f2
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 5195f2
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 5195f2
# GNU General Public License for more details.
Packit Service 5195f2
#
Packit Service 5195f2
# You should have received a copy of the GNU General Public License
Packit Service 5195f2
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit Service 5195f2
Packit Service 5195f2
# As a special exception to the GNU General Public License, if you
Packit Service 5195f2
# distribute this file as part of a program that contains a
Packit Service 5195f2
# configuration script generated by Autoconf, you may include it under
Packit Service 5195f2
# the same distribution terms that you use for the rest of that program.
Packit Service 5195f2
Packit Service 5195f2
# This file is maintained in Automake, please report
Packit Service 5195f2
# bugs to <bug-automake@gnu.org> or send patches to
Packit Service 5195f2
# <automake-patches@gnu.org>.
Packit Service 5195f2
Packit Service 5195f2
get_dirname ()
Packit Service 5195f2
{
Packit Service 5195f2
  case $1 in
Packit Service 5195f2
    */*|*\\*) printf '%s\n' "$1" | sed -e 's|\([\\/]\)[^\\/]*$|\1|';;
Packit Service 5195f2
    # Otherwise,  we want the empty string (not ".").
Packit Service 5195f2
  esac
Packit Service 5195f2
}
Packit Service 5195f2
Packit Service 5195f2
# guard FILE
Packit Service 5195f2
# ----------
Packit Service 5195f2
# The CPP macro used to guard inclusion of FILE.
Packit Service 5195f2
guard ()
Packit Service 5195f2
{
Packit Service 5195f2
  printf '%s\n' "$1"                                                    \
Packit Service 5195f2
    | sed                                                               \
Packit Service 5195f2
        -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'   \
Packit Service 5195f2
        -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'                        \
Packit Service 5195f2
        -e 's/__*/_/g'
Packit Service 5195f2
}
Packit Service 5195f2
Packit Service 5195f2
# quote_for_sed [STRING]
Packit Service 5195f2
# ----------------------
Packit Service 5195f2
# Return STRING (or stdin) quoted to be used as a sed pattern.
Packit Service 5195f2
quote_for_sed ()
Packit Service 5195f2
{
Packit Service 5195f2
  case $# in
Packit Service 5195f2
    0) cat;;
Packit Service 5195f2
    1) printf '%s\n' "$1";;
Packit Service 5195f2
  esac \
Packit Service 5195f2
    | sed -e 's|[][\\.*]|\\&|g'
Packit Service 5195f2
}
Packit Service 5195f2
Packit Service 5195f2
case "$1" in
Packit Service 5195f2
  '')
Packit Service 5195f2
    echo "$0: No files given.  Try '$0 --help' for more information." 1>&2
Packit Service 5195f2
    exit 1
Packit Service 5195f2
    ;;
Packit Service 5195f2
  --basedir)
Packit Service 5195f2
    basedir=$2
Packit Service 5195f2
    shift 2
Packit Service 5195f2
    ;;
Packit Service 5195f2
  -h|--h*)
Packit Service 5195f2
    cat <<\EOF
Packit Service 5195f2
Usage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]...
Packit Service 5195f2
Packit Service 5195f2
Wrapper for lex/yacc invocations, renaming files as desired.
Packit Service 5195f2
Packit Service 5195f2
  INPUT is the input file
Packit Service 5195f2
  OUTPUT is one file PROG generates
Packit Service 5195f2
  DESIRED is the file we actually want instead of OUTPUT
Packit Service 5195f2
  PROGRAM is program to run
Packit Service 5195f2
  ARGS are passed to PROG
Packit Service 5195f2
Packit Service 5195f2
Any number of OUTPUT,DESIRED pairs may be used.
Packit Service 5195f2
Packit Service 5195f2
Report bugs to <bug-automake@gnu.org>.
Packit Service 5195f2
EOF
Packit Service 5195f2
    exit $?
Packit Service 5195f2
    ;;
Packit Service 5195f2
  -v|--v*)
Packit Service 5195f2
    echo "ylwrap $scriptversion"
Packit Service 5195f2
    exit $?
Packit Service 5195f2
    ;;
Packit Service 5195f2
esac
Packit Service 5195f2
Packit Service 5195f2
Packit Service 5195f2
# The input.
Packit Service 5195f2
input=$1
Packit Service 5195f2
shift
Packit Service 5195f2
# We'll later need for a correct munging of "#line" directives.
Packit Service 5195f2
input_sub_rx=`get_dirname "$input" | quote_for_sed`
Packit Service 5195f2
case $input in
Packit Service 5195f2
  [\\/]* | ?:[\\/]*)
Packit Service 5195f2
    # Absolute path; do nothing.
Packit Service 5195f2
    ;;
Packit Service 5195f2
  *)
Packit Service 5195f2
    # Relative path.  Make it absolute.
Packit Service 5195f2
    input=`pwd`/$input
Packit Service 5195f2
    ;;
Packit Service 5195f2
esac
Packit Service 5195f2
input_rx=`get_dirname "$input" | quote_for_sed`
Packit Service 5195f2
Packit Service 5195f2
# The parser itself, the first file, is the destination of the .y.c
Packit Service 5195f2
# rule in the Makefile.
Packit Service 5195f2
parser=$1
Packit Service 5195f2
Packit Service 5195f2
# A sed program to s/FROM/TO/g for all the FROM/TO so that, for
Packit Service 5195f2
# instance, we rename #include "y.tab.h" into #include "parse.h"
Packit Service 5195f2
# during the conversion from y.tab.c to parse.c.
Packit Service 5195f2
sed_fix_filenames=
Packit Service 5195f2
Packit Service 5195f2
# Also rename header guards, as Bison 2.7 for instance uses its header
Packit Service 5195f2
# guard in its implementation file.
Packit Service 5195f2
sed_fix_header_guards=
Packit Service 5195f2
Packit Service 5195f2
while test $# -ne 0; do
Packit Service 5195f2
  if test x"$1" = x"--"; then
Packit Service 5195f2
    shift
Packit Service 5195f2
    break
Packit Service 5195f2
  fi
Packit Service 5195f2
  from=$1
Packit Service 5195f2
  shift
Packit Service 5195f2
  to=$1
Packit Service 5195f2
  shift
Packit Service 5195f2
  sed_fix_filenames="${sed_fix_filenames}s|"`quote_for_sed "$from"`"|$to|g;"
Packit Service 5195f2
  sed_fix_header_guards="${sed_fix_header_guards}s|"`guard "$from"`"|"`guard "$to"`"|g;"
Packit Service 5195f2
done
Packit Service 5195f2
Packit Service 5195f2
# The program to run.
Packit Service 5195f2
prog=$1
Packit Service 5195f2
shift
Packit Service 5195f2
# Make any relative path in $prog absolute.
Packit Service 5195f2
case $prog in
Packit Service 5195f2
  [\\/]* | ?:[\\/]*) ;;
Packit Service 5195f2
  *[\\/]*) prog=`pwd`/$prog ;;
Packit Service 5195f2
esac
Packit Service 5195f2
Packit Service 5195f2
dirname=ylwrap$$
Packit Service 5195f2
do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret'
Packit Service 5195f2
trap "ret=129; $do_exit" 1
Packit Service 5195f2
trap "ret=130; $do_exit" 2
Packit Service 5195f2
trap "ret=141; $do_exit" 13
Packit Service 5195f2
trap "ret=143; $do_exit" 15
Packit Service 5195f2
mkdir $dirname || exit 1
Packit Service 5195f2
Packit Service 5195f2
cd $dirname
Packit Service 5195f2
Packit Service 5195f2
case $# in
Packit Service 5195f2
  0) "$prog" "$input" ;;
Packit Service 5195f2
  *) "$prog" "$@" "$input" ;;
Packit Service 5195f2
esac
Packit Service 5195f2
ret=$?
Packit Service 5195f2
Packit Service 5195f2
if test $ret -eq 0; then
Packit Service 5195f2
  for from in *
Packit Service 5195f2
  do
Packit Service 5195f2
    to=`printf '%s\n' "$from" | sed "$sed_fix_filenames"`
Packit Service 5195f2
    if test -f "$from"; then
Packit Service 5195f2
      # If $2 is an absolute path name, then just use that,
Packit Service 5195f2
      # otherwise prepend '../'.
Packit Service 5195f2
      case $to in
Packit Service 5195f2
        [\\/]* | ?:[\\/]*) target=$to;;
Packit Service 5195f2
        *) target=../$to;;
Packit Service 5195f2
      esac
Packit Service 5195f2
Packit Service 5195f2
      # Do not overwrite unchanged header files to avoid useless
Packit Service 5195f2
      # recompilations.  Always update the parser itself: it is the
Packit Service 5195f2
      # destination of the .y.c rule in the Makefile.  Divert the
Packit Service 5195f2
      # output of all other files to a temporary file so we can
Packit Service 5195f2
      # compare them to existing versions.
Packit Service 5195f2
      if test $from != $parser; then
Packit Service 5195f2
        realtarget=$target
Packit Service 5195f2
        target=tmp-`printf '%s\n' "$target" | sed 's|.*[\\/]||g'`
Packit Service 5195f2
      fi
Packit Service 5195f2
Packit Service 5195f2
      # Munge "#line" or "#" directives.  Don't let the resulting
Packit Service 5195f2
      # debug information point at an absolute srcdir.  Use the real
Packit Service 5195f2
      # output file name, not yy.lex.c for instance.  Adjust the
Packit Service 5195f2
      # include guards too.
Packit Service 5195f2
      sed -e "/^#/!b"                           \
Packit Service 5195f2
          -e "s|$input_rx|$input_sub_rx|"       \
Packit Service 5195f2
          -e "$sed_fix_filenames"               \
Packit Service 5195f2
          -e "$sed_fix_header_guards"           \
Packit Service 5195f2
        "$from" >"$target" || ret=$?
Packit Service 5195f2
Packit Service 5195f2
      # Check whether files must be updated.
Packit Service 5195f2
      if test "$from" != "$parser"; then
Packit Service 5195f2
        if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
Packit Service 5195f2
          echo "$to is unchanged"
Packit Service 5195f2
          rm -f "$target"
Packit Service 5195f2
        else
Packit Service 5195f2
          echo "updating $to"
Packit Service 5195f2
          mv -f "$target" "$realtarget"
Packit Service 5195f2
        fi
Packit Service 5195f2
      fi
Packit Service 5195f2
    else
Packit Service 5195f2
      # A missing file is only an error for the parser.  This is a
Packit Service 5195f2
      # blatant hack to let us support using "yacc -d".  If -d is not
Packit Service 5195f2
      # specified, don't fail when the header file is "missing".
Packit Service 5195f2
      if test "$from" = "$parser"; then
Packit Service 5195f2
        ret=1
Packit Service 5195f2
      fi
Packit Service 5195f2
    fi
Packit Service 5195f2
  done
Packit Service 5195f2
fi
Packit Service 5195f2
Packit Service 5195f2
# Remove the directory.
Packit Service 5195f2
cd ..
Packit Service 5195f2
rm -rf $dirname
Packit Service 5195f2
Packit Service 5195f2
exit $ret
Packit Service 5195f2
Packit Service 5195f2
# Local Variables:
Packit Service 5195f2
# mode: shell-script
Packit Service 5195f2
# sh-indentation: 2
Packit Service 5195f2
# eval: (add-hook 'write-file-hooks 'time-stamp)
Packit Service 5195f2
# time-stamp-start: "scriptversion="
Packit Service 5195f2
# time-stamp-format: "%:y-%02m-%02d.%02H"
Packit Service 5195f2
# time-stamp-time-zone: "UTC"
Packit Service 5195f2
# time-stamp-end: "; # UTC"
Packit Service 5195f2
# End: