Blame autoconf/ylwrap

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