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