kusano 7d535a
#! /bin/sh
kusano 7d535a
# ylwrap - wrapper for lex/yacc invocations.
kusano 7d535a
kusano 7d535a
scriptversion=2007-11-22.22
kusano 7d535a
kusano 7d535a
# Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005,
kusano 7d535a
# 2007  Free Software Foundation, Inc.
kusano 7d535a
#
kusano 7d535a
# Written by Tom Tromey <tromey@cygnus.com>.</tromey@cygnus.com>
kusano 7d535a
#
kusano 7d535a
# This program is free software; you can redistribute it and/or modify
kusano 7d535a
# it under the terms of the GNU General Public License as published by
kusano 7d535a
# the Free Software Foundation; either version 3, or (at your option)
kusano 7d535a
# any later version.
kusano 7d535a
#
kusano 7d535a
# This program is distributed in the hope that it will be useful,
kusano 7d535a
# but WITHOUT ANY WARRANTY; without even the implied warranty of
kusano 7d535a
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
kusano 7d535a
# GNU General Public License for more details.
kusano 7d535a
#
kusano 7d535a
# You should have received a copy of the GNU General Public License
kusano 7d535a
# along with this program.  If not, see <http: licenses="" www.gnu.org="">.</http:>
kusano 7d535a
kusano 7d535a
# As a special exception to the GNU General Public License, if you
kusano 7d535a
# distribute this file as part of a program that contains a
kusano 7d535a
# configuration script generated by Autoconf, you may include it under
kusano 7d535a
# the same distribution terms that you use for the rest of that program.
kusano 7d535a
kusano 7d535a
# This file is maintained in Automake, please report
kusano 7d535a
# bugs to <bug-automake@gnu.org> or send patches to</bug-automake@gnu.org>
kusano 7d535a
# <automake-patches@gnu.org>.</automake-patches@gnu.org>
kusano 7d535a
kusano 7d535a
case "$1" in
kusano 7d535a
  '')
kusano 7d535a
    echo "$0: No files given.  Try \`$0 --help' for more information." 1>&2
kusano 7d535a
    exit 1
kusano 7d535a
    ;;
kusano 7d535a
  --basedir)
kusano 7d535a
    basedir=$2
kusano 7d535a
    shift 2
kusano 7d535a
    ;;
kusano 7d535a
  -h|--h*)
kusano 7d535a
    cat <<\EOF
kusano 7d535a
Usage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]...
kusano 7d535a
kusano 7d535a
Wrapper for lex/yacc invocations, renaming files as desired.
kusano 7d535a
kusano 7d535a
  INPUT is the input file
kusano 7d535a
  OUTPUT is one file PROG generates
kusano 7d535a
  DESIRED is the file we actually want instead of OUTPUT
kusano 7d535a
  PROGRAM is program to run
kusano 7d535a
  ARGS are passed to PROG
kusano 7d535a
kusano 7d535a
Any number of OUTPUT,DESIRED pairs may be used.
kusano 7d535a
kusano 7d535a
Report bugs to <bug-automake@gnu.org>.</bug-automake@gnu.org>
kusano 7d535a
EOF
kusano 7d535a
    exit $?
kusano 7d535a
    ;;
kusano 7d535a
  -v|--v*)
kusano 7d535a
    echo "ylwrap $scriptversion"
kusano 7d535a
    exit $?
kusano 7d535a
    ;;
kusano 7d535a
esac
kusano 7d535a
kusano 7d535a
kusano 7d535a
# The input.
kusano 7d535a
input="$1"
kusano 7d535a
shift
kusano 7d535a
case "$input" in
kusano 7d535a
  [\\/]* | ?:[\\/]*)
kusano 7d535a
    # Absolute path; do nothing.
kusano 7d535a
    ;;
kusano 7d535a
  *)
kusano 7d535a
    # Relative path.  Make it absolute.
kusano 7d535a
    input="`pwd`/$input"
kusano 7d535a
    ;;
kusano 7d535a
esac
kusano 7d535a
kusano 7d535a
pairlist=
kusano 7d535a
while test "$#" -ne 0; do
kusano 7d535a
  if test "$1" = "--"; then
kusano 7d535a
    shift
kusano 7d535a
    break
kusano 7d535a
  fi
kusano 7d535a
  pairlist="$pairlist $1"
kusano 7d535a
  shift
kusano 7d535a
done
kusano 7d535a
kusano 7d535a
# The program to run.
kusano 7d535a
prog="$1"
kusano 7d535a
shift
kusano 7d535a
# Make any relative path in $prog absolute.
kusano 7d535a
case "$prog" in
kusano 7d535a
  [\\/]* | ?:[\\/]*) ;;
kusano 7d535a
  *[\\/]*) prog="`pwd`/$prog" ;;
kusano 7d535a
esac
kusano 7d535a
kusano 7d535a
# FIXME: add hostname here for parallel makes that run commands on
kusano 7d535a
# other machines.  But that might take us over the 14-char limit.
kusano 7d535a
dirname=ylwrap$$
kusano 7d535a
trap "cd '`pwd`'; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15
kusano 7d535a
mkdir $dirname || exit 1
kusano 7d535a
kusano 7d535a
cd $dirname
kusano 7d535a
kusano 7d535a
case $# in
kusano 7d535a
  0) "$prog" "$input" ;;
kusano 7d535a
  *) "$prog" "$@" "$input" ;;
kusano 7d535a
esac
kusano 7d535a
ret=$?
kusano 7d535a
kusano 7d535a
if test $ret -eq 0; then
kusano 7d535a
  set X $pairlist
kusano 7d535a
  shift
kusano 7d535a
  first=yes
kusano 7d535a
  # Since DOS filename conventions don't allow two dots,
kusano 7d535a
  # the DOS version of Bison writes out y_tab.c instead of y.tab.c
kusano 7d535a
  # and y_tab.h instead of y.tab.h. Test to see if this is the case.
kusano 7d535a
  y_tab_nodot="no"
kusano 7d535a
  if test -f y_tab.c || test -f y_tab.h; then
kusano 7d535a
    y_tab_nodot="yes"
kusano 7d535a
  fi
kusano 7d535a
kusano 7d535a
  # The directory holding the input.
kusano 7d535a
  input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'`
kusano 7d535a
  # Quote $INPUT_DIR so we can use it in a regexp.
kusano 7d535a
  # FIXME: really we should care about more than `.' and `\'.
kusano 7d535a
  input_rx=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'`
kusano 7d535a
kusano 7d535a
  while test "$#" -ne 0; do
kusano 7d535a
    from="$1"
kusano 7d535a
    # Handle y_tab.c and y_tab.h output by DOS
kusano 7d535a
    if test $y_tab_nodot = "yes"; then
kusano 7d535a
      if test $from = "y.tab.c"; then
kusano 7d535a
    	from="y_tab.c"
kusano 7d535a
      else
kusano 7d535a
    	if test $from = "y.tab.h"; then
kusano 7d535a
    	  from="y_tab.h"
kusano 7d535a
    	fi
kusano 7d535a
      fi
kusano 7d535a
    fi
kusano 7d535a
    if test -f "$from"; then
kusano 7d535a
      # If $2 is an absolute path name, then just use that,
kusano 7d535a
      # otherwise prepend `../'.
kusano 7d535a
      case "$2" in
kusano 7d535a
    	[\\/]* | ?:[\\/]*) target="$2";;
kusano 7d535a
    	*) target="../$2";;
kusano 7d535a
      esac
kusano 7d535a
kusano 7d535a
      # We do not want to overwrite a header file if it hasn't
kusano 7d535a
      # changed.  This avoid useless recompilations.  However the
kusano 7d535a
      # parser itself (the first file) should always be updated,
kusano 7d535a
      # because it is the destination of the .y.c rule in the
kusano 7d535a
      # Makefile.  Divert the output of all other files to a temporary
kusano 7d535a
      # file so we can compare them to existing versions.
kusano 7d535a
      if test $first = no; then
kusano 7d535a
	realtarget="$target"
kusano 7d535a
	target="tmp-`echo $target | sed s/.*[\\/]//g`"
kusano 7d535a
      fi
kusano 7d535a
      # Edit out `#line' or `#' directives.
kusano 7d535a
      #
kusano 7d535a
      # We don't want the resulting debug information to point at
kusano 7d535a
      # an absolute srcdir; it is better for it to just mention the
kusano 7d535a
      # .y file with no path.
kusano 7d535a
      #
kusano 7d535a
      # We want to use the real output file name, not yy.lex.c for
kusano 7d535a
      # instance.
kusano 7d535a
      #
kusano 7d535a
      # We want the include guards to be adjusted too.
kusano 7d535a
      FROM=`echo "$from" | sed \
kusano 7d535a
            -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
kusano 7d535a
            -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
kusano 7d535a
      TARGET=`echo "$2" | sed \
kusano 7d535a
            -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
kusano 7d535a
            -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
kusano 7d535a
kusano 7d535a
      sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \
kusano 7d535a
          -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$?
kusano 7d535a
kusano 7d535a
      # Check whether header files must be updated.
kusano 7d535a
      if test $first = no; then
kusano 7d535a
	if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
kusano 7d535a
	  echo "$2" is unchanged
kusano 7d535a
	  rm -f "$target"
kusano 7d535a
	else
kusano 7d535a
          echo updating "$2"
kusano 7d535a
          mv -f "$target" "$realtarget"
kusano 7d535a
        fi
kusano 7d535a
      fi
kusano 7d535a
    else
kusano 7d535a
      # A missing file is only an error for the first file.  This
kusano 7d535a
      # is a blatant hack to let us support using "yacc -d".  If -d
kusano 7d535a
      # is not specified, we don't want an error when the header
kusano 7d535a
      # file is "missing".
kusano 7d535a
      if test $first = yes; then
kusano 7d535a
        ret=1
kusano 7d535a
      fi
kusano 7d535a
    fi
kusano 7d535a
    shift
kusano 7d535a
    shift
kusano 7d535a
    first=no
kusano 7d535a
  done
kusano 7d535a
else
kusano 7d535a
  ret=$?
kusano 7d535a
fi
kusano 7d535a
kusano 7d535a
# Remove the directory.
kusano 7d535a
cd ..
kusano 7d535a
rm -rf $dirname
kusano 7d535a
kusano 7d535a
exit $ret
kusano 7d535a
kusano 7d535a
# Local Variables:
kusano 7d535a
# mode: shell-script
kusano 7d535a
# sh-indentation: 2
kusano 7d535a
# eval: (add-hook 'write-file-hooks 'time-stamp)
kusano 7d535a
# time-stamp-start: "scriptversion="
kusano 7d535a
# time-stamp-format: "%:y-%02m-%02d.%02H"
kusano 7d535a
# time-stamp-end: "$"
kusano 7d535a
# End: