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