125b3c049e70834cf33790a28643ab058b507b35cBen Cheng#! /bin/sh 225b3c049e70834cf33790a28643ab058b507b35cBen Cheng# ylwrap - wrapper for lex/yacc invocations. 325b3c049e70834cf33790a28643ab058b507b35cBen Cheng 425b3c049e70834cf33790a28643ab058b507b35cBen Chengscriptversion=2009-04-28.21; # UTC 525b3c049e70834cf33790a28643ab058b507b35cBen Cheng 625b3c049e70834cf33790a28643ab058b507b35cBen Cheng# Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005, 725b3c049e70834cf33790a28643ab058b507b35cBen Cheng# 2007, 2009 Free Software Foundation, Inc. 825b3c049e70834cf33790a28643ab058b507b35cBen Cheng# 925b3c049e70834cf33790a28643ab058b507b35cBen Cheng# Written by Tom Tromey <tromey@cygnus.com>. 1025b3c049e70834cf33790a28643ab058b507b35cBen Cheng# 1125b3c049e70834cf33790a28643ab058b507b35cBen Cheng# This program is free software; you can redistribute it and/or modify 1225b3c049e70834cf33790a28643ab058b507b35cBen Cheng# it under the terms of the GNU General Public License as published by 1325b3c049e70834cf33790a28643ab058b507b35cBen Cheng# the Free Software Foundation; either version 2, or (at your option) 1425b3c049e70834cf33790a28643ab058b507b35cBen Cheng# any later version. 1525b3c049e70834cf33790a28643ab058b507b35cBen Cheng# 1625b3c049e70834cf33790a28643ab058b507b35cBen Cheng# This program is distributed in the hope that it will be useful, 1725b3c049e70834cf33790a28643ab058b507b35cBen Cheng# but WITHOUT ANY WARRANTY; without even the implied warranty of 1825b3c049e70834cf33790a28643ab058b507b35cBen Cheng# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1925b3c049e70834cf33790a28643ab058b507b35cBen Cheng# GNU General Public License for more details. 2025b3c049e70834cf33790a28643ab058b507b35cBen Cheng# 2125b3c049e70834cf33790a28643ab058b507b35cBen Cheng# You should have received a copy of the GNU General Public License 2225b3c049e70834cf33790a28643ab058b507b35cBen Cheng# along with this program. If not, see <http://www.gnu.org/licenses/>. 2325b3c049e70834cf33790a28643ab058b507b35cBen Cheng 2425b3c049e70834cf33790a28643ab058b507b35cBen Cheng# As a special exception to the GNU General Public License, if you 2525b3c049e70834cf33790a28643ab058b507b35cBen Cheng# distribute this file as part of a program that contains a 2625b3c049e70834cf33790a28643ab058b507b35cBen Cheng# configuration script generated by Autoconf, you may include it under 2725b3c049e70834cf33790a28643ab058b507b35cBen Cheng# the same distribution terms that you use for the rest of that program. 2825b3c049e70834cf33790a28643ab058b507b35cBen Cheng 2925b3c049e70834cf33790a28643ab058b507b35cBen Cheng# This file is maintained in Automake, please report 3025b3c049e70834cf33790a28643ab058b507b35cBen Cheng# bugs to <bug-automake@gnu.org> or send patches to 3125b3c049e70834cf33790a28643ab058b507b35cBen Cheng# <automake-patches@gnu.org>. 3225b3c049e70834cf33790a28643ab058b507b35cBen Cheng 3325b3c049e70834cf33790a28643ab058b507b35cBen Chengcase "$1" in 3425b3c049e70834cf33790a28643ab058b507b35cBen Cheng '') 3525b3c049e70834cf33790a28643ab058b507b35cBen Cheng echo "$0: No files given. Try \`$0 --help' for more information." 1>&2 3625b3c049e70834cf33790a28643ab058b507b35cBen Cheng exit 1 3725b3c049e70834cf33790a28643ab058b507b35cBen Cheng ;; 3825b3c049e70834cf33790a28643ab058b507b35cBen Cheng --basedir) 3925b3c049e70834cf33790a28643ab058b507b35cBen Cheng basedir=$2 4025b3c049e70834cf33790a28643ab058b507b35cBen Cheng shift 2 4125b3c049e70834cf33790a28643ab058b507b35cBen Cheng ;; 4225b3c049e70834cf33790a28643ab058b507b35cBen Cheng -h|--h*) 4325b3c049e70834cf33790a28643ab058b507b35cBen Cheng cat <<\EOF 4425b3c049e70834cf33790a28643ab058b507b35cBen ChengUsage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]... 4525b3c049e70834cf33790a28643ab058b507b35cBen Cheng 4625b3c049e70834cf33790a28643ab058b507b35cBen ChengWrapper for lex/yacc invocations, renaming files as desired. 4725b3c049e70834cf33790a28643ab058b507b35cBen Cheng 4825b3c049e70834cf33790a28643ab058b507b35cBen Cheng INPUT is the input file 4925b3c049e70834cf33790a28643ab058b507b35cBen Cheng OUTPUT is one file PROG generates 5025b3c049e70834cf33790a28643ab058b507b35cBen Cheng DESIRED is the file we actually want instead of OUTPUT 5125b3c049e70834cf33790a28643ab058b507b35cBen Cheng PROGRAM is program to run 5225b3c049e70834cf33790a28643ab058b507b35cBen Cheng ARGS are passed to PROG 5325b3c049e70834cf33790a28643ab058b507b35cBen Cheng 5425b3c049e70834cf33790a28643ab058b507b35cBen ChengAny number of OUTPUT,DESIRED pairs may be used. 5525b3c049e70834cf33790a28643ab058b507b35cBen Cheng 5625b3c049e70834cf33790a28643ab058b507b35cBen ChengReport bugs to <bug-automake@gnu.org>. 5725b3c049e70834cf33790a28643ab058b507b35cBen ChengEOF 5825b3c049e70834cf33790a28643ab058b507b35cBen Cheng exit $? 5925b3c049e70834cf33790a28643ab058b507b35cBen Cheng ;; 6025b3c049e70834cf33790a28643ab058b507b35cBen Cheng -v|--v*) 6125b3c049e70834cf33790a28643ab058b507b35cBen Cheng echo "ylwrap $scriptversion" 6225b3c049e70834cf33790a28643ab058b507b35cBen Cheng exit $? 6325b3c049e70834cf33790a28643ab058b507b35cBen Cheng ;; 6425b3c049e70834cf33790a28643ab058b507b35cBen Chengesac 6525b3c049e70834cf33790a28643ab058b507b35cBen Cheng 6625b3c049e70834cf33790a28643ab058b507b35cBen Cheng 6725b3c049e70834cf33790a28643ab058b507b35cBen Cheng# The input. 6825b3c049e70834cf33790a28643ab058b507b35cBen Chenginput="$1" 6925b3c049e70834cf33790a28643ab058b507b35cBen Chengshift 7025b3c049e70834cf33790a28643ab058b507b35cBen Chengcase "$input" in 7125b3c049e70834cf33790a28643ab058b507b35cBen Cheng [\\/]* | ?:[\\/]*) 7225b3c049e70834cf33790a28643ab058b507b35cBen Cheng # Absolute path; do nothing. 7325b3c049e70834cf33790a28643ab058b507b35cBen Cheng ;; 7425b3c049e70834cf33790a28643ab058b507b35cBen Cheng *) 7525b3c049e70834cf33790a28643ab058b507b35cBen Cheng # Relative path. Make it absolute. 7625b3c049e70834cf33790a28643ab058b507b35cBen Cheng input="`pwd`/$input" 7725b3c049e70834cf33790a28643ab058b507b35cBen Cheng ;; 7825b3c049e70834cf33790a28643ab058b507b35cBen Chengesac 7925b3c049e70834cf33790a28643ab058b507b35cBen Cheng 8025b3c049e70834cf33790a28643ab058b507b35cBen Chengpairlist= 8125b3c049e70834cf33790a28643ab058b507b35cBen Chengwhile test "$#" -ne 0; do 8225b3c049e70834cf33790a28643ab058b507b35cBen Cheng if test "$1" = "--"; then 8325b3c049e70834cf33790a28643ab058b507b35cBen Cheng shift 8425b3c049e70834cf33790a28643ab058b507b35cBen Cheng break 8525b3c049e70834cf33790a28643ab058b507b35cBen Cheng fi 8625b3c049e70834cf33790a28643ab058b507b35cBen Cheng pairlist="$pairlist $1" 8725b3c049e70834cf33790a28643ab058b507b35cBen Cheng shift 8825b3c049e70834cf33790a28643ab058b507b35cBen Chengdone 8925b3c049e70834cf33790a28643ab058b507b35cBen Cheng 9025b3c049e70834cf33790a28643ab058b507b35cBen Cheng# The program to run. 9125b3c049e70834cf33790a28643ab058b507b35cBen Chengprog="$1" 9225b3c049e70834cf33790a28643ab058b507b35cBen Chengshift 9325b3c049e70834cf33790a28643ab058b507b35cBen Cheng# Make any relative path in $prog absolute. 9425b3c049e70834cf33790a28643ab058b507b35cBen Chengcase "$prog" in 9525b3c049e70834cf33790a28643ab058b507b35cBen Cheng [\\/]* | ?:[\\/]*) ;; 9625b3c049e70834cf33790a28643ab058b507b35cBen Cheng *[\\/]*) prog="`pwd`/$prog" ;; 9725b3c049e70834cf33790a28643ab058b507b35cBen Chengesac 9825b3c049e70834cf33790a28643ab058b507b35cBen Cheng 9925b3c049e70834cf33790a28643ab058b507b35cBen Cheng# FIXME: add hostname here for parallel makes that run commands on 10025b3c049e70834cf33790a28643ab058b507b35cBen Cheng# other machines. But that might take us over the 14-char limit. 10125b3c049e70834cf33790a28643ab058b507b35cBen Chengdirname=ylwrap$$ 10225b3c049e70834cf33790a28643ab058b507b35cBen Chengtrap "cd '`pwd`'; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15 10325b3c049e70834cf33790a28643ab058b507b35cBen Chengmkdir $dirname || exit 1 10425b3c049e70834cf33790a28643ab058b507b35cBen Cheng 10525b3c049e70834cf33790a28643ab058b507b35cBen Chengcd $dirname 10625b3c049e70834cf33790a28643ab058b507b35cBen Cheng 10725b3c049e70834cf33790a28643ab058b507b35cBen Chengcase $# in 10825b3c049e70834cf33790a28643ab058b507b35cBen Cheng 0) "$prog" "$input" ;; 10925b3c049e70834cf33790a28643ab058b507b35cBen Cheng *) "$prog" "$@" "$input" ;; 11025b3c049e70834cf33790a28643ab058b507b35cBen Chengesac 11125b3c049e70834cf33790a28643ab058b507b35cBen Chengret=$? 11225b3c049e70834cf33790a28643ab058b507b35cBen Cheng 11325b3c049e70834cf33790a28643ab058b507b35cBen Chengif test $ret -eq 0; then 11425b3c049e70834cf33790a28643ab058b507b35cBen Cheng set X $pairlist 11525b3c049e70834cf33790a28643ab058b507b35cBen Cheng shift 11625b3c049e70834cf33790a28643ab058b507b35cBen Cheng first=yes 11725b3c049e70834cf33790a28643ab058b507b35cBen Cheng # Since DOS filename conventions don't allow two dots, 11825b3c049e70834cf33790a28643ab058b507b35cBen Cheng # the DOS version of Bison writes out y_tab.c instead of y.tab.c 11925b3c049e70834cf33790a28643ab058b507b35cBen Cheng # and y_tab.h instead of y.tab.h. Test to see if this is the case. 12025b3c049e70834cf33790a28643ab058b507b35cBen Cheng y_tab_nodot="no" 12125b3c049e70834cf33790a28643ab058b507b35cBen Cheng if test -f y_tab.c || test -f y_tab.h; then 12225b3c049e70834cf33790a28643ab058b507b35cBen Cheng y_tab_nodot="yes" 12325b3c049e70834cf33790a28643ab058b507b35cBen Cheng fi 12425b3c049e70834cf33790a28643ab058b507b35cBen Cheng 12525b3c049e70834cf33790a28643ab058b507b35cBen Cheng # The directory holding the input. 12625b3c049e70834cf33790a28643ab058b507b35cBen Cheng input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'` 12725b3c049e70834cf33790a28643ab058b507b35cBen Cheng # Quote $INPUT_DIR so we can use it in a regexp. 12825b3c049e70834cf33790a28643ab058b507b35cBen Cheng # FIXME: really we should care about more than `.' and `\'. 12925b3c049e70834cf33790a28643ab058b507b35cBen Cheng input_rx=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'` 13025b3c049e70834cf33790a28643ab058b507b35cBen Cheng 13125b3c049e70834cf33790a28643ab058b507b35cBen Cheng while test "$#" -ne 0; do 13225b3c049e70834cf33790a28643ab058b507b35cBen Cheng from="$1" 13325b3c049e70834cf33790a28643ab058b507b35cBen Cheng # Handle y_tab.c and y_tab.h output by DOS 13425b3c049e70834cf33790a28643ab058b507b35cBen Cheng if test $y_tab_nodot = "yes"; then 13525b3c049e70834cf33790a28643ab058b507b35cBen Cheng if test $from = "y.tab.c"; then 13625b3c049e70834cf33790a28643ab058b507b35cBen Cheng from="y_tab.c" 13725b3c049e70834cf33790a28643ab058b507b35cBen Cheng else 13825b3c049e70834cf33790a28643ab058b507b35cBen Cheng if test $from = "y.tab.h"; then 13925b3c049e70834cf33790a28643ab058b507b35cBen Cheng from="y_tab.h" 14025b3c049e70834cf33790a28643ab058b507b35cBen Cheng fi 14125b3c049e70834cf33790a28643ab058b507b35cBen Cheng fi 14225b3c049e70834cf33790a28643ab058b507b35cBen Cheng fi 14325b3c049e70834cf33790a28643ab058b507b35cBen Cheng if test -f "$from"; then 14425b3c049e70834cf33790a28643ab058b507b35cBen Cheng # If $2 is an absolute path name, then just use that, 14525b3c049e70834cf33790a28643ab058b507b35cBen Cheng # otherwise prepend `../'. 14625b3c049e70834cf33790a28643ab058b507b35cBen Cheng case "$2" in 14725b3c049e70834cf33790a28643ab058b507b35cBen Cheng [\\/]* | ?:[\\/]*) target="$2";; 14825b3c049e70834cf33790a28643ab058b507b35cBen Cheng *) target="../$2";; 14925b3c049e70834cf33790a28643ab058b507b35cBen Cheng esac 15025b3c049e70834cf33790a28643ab058b507b35cBen Cheng 15125b3c049e70834cf33790a28643ab058b507b35cBen Cheng # We do not want to overwrite a header file if it hasn't 15225b3c049e70834cf33790a28643ab058b507b35cBen Cheng # changed. This avoid useless recompilations. However the 15325b3c049e70834cf33790a28643ab058b507b35cBen Cheng # parser itself (the first file) should always be updated, 15425b3c049e70834cf33790a28643ab058b507b35cBen Cheng # because it is the destination of the .y.c rule in the 15525b3c049e70834cf33790a28643ab058b507b35cBen Cheng # Makefile. Divert the output of all other files to a temporary 15625b3c049e70834cf33790a28643ab058b507b35cBen Cheng # file so we can compare them to existing versions. 15725b3c049e70834cf33790a28643ab058b507b35cBen Cheng if test $first = no; then 15825b3c049e70834cf33790a28643ab058b507b35cBen Cheng realtarget="$target" 15925b3c049e70834cf33790a28643ab058b507b35cBen Cheng target="tmp-`echo $target | sed s/.*[\\/]//g`" 16025b3c049e70834cf33790a28643ab058b507b35cBen Cheng fi 16125b3c049e70834cf33790a28643ab058b507b35cBen Cheng # Edit out `#line' or `#' directives. 16225b3c049e70834cf33790a28643ab058b507b35cBen Cheng # 16325b3c049e70834cf33790a28643ab058b507b35cBen Cheng # We don't want the resulting debug information to point at 16425b3c049e70834cf33790a28643ab058b507b35cBen Cheng # an absolute srcdir; it is better for it to just mention the 16525b3c049e70834cf33790a28643ab058b507b35cBen Cheng # .y file with no path. 16625b3c049e70834cf33790a28643ab058b507b35cBen Cheng # 16725b3c049e70834cf33790a28643ab058b507b35cBen Cheng # We want to use the real output file name, not yy.lex.c for 16825b3c049e70834cf33790a28643ab058b507b35cBen Cheng # instance. 16925b3c049e70834cf33790a28643ab058b507b35cBen Cheng # 17025b3c049e70834cf33790a28643ab058b507b35cBen Cheng # We want the include guards to be adjusted too. 17125b3c049e70834cf33790a28643ab058b507b35cBen Cheng FROM=`echo "$from" | sed \ 17225b3c049e70834cf33790a28643ab058b507b35cBen Cheng -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\ 17325b3c049e70834cf33790a28643ab058b507b35cBen Cheng -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'` 17425b3c049e70834cf33790a28643ab058b507b35cBen Cheng TARGET=`echo "$2" | sed \ 17525b3c049e70834cf33790a28643ab058b507b35cBen Cheng -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\ 17625b3c049e70834cf33790a28643ab058b507b35cBen Cheng -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'` 17725b3c049e70834cf33790a28643ab058b507b35cBen Cheng 17825b3c049e70834cf33790a28643ab058b507b35cBen Cheng sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \ 17925b3c049e70834cf33790a28643ab058b507b35cBen Cheng -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$? 18025b3c049e70834cf33790a28643ab058b507b35cBen Cheng 18125b3c049e70834cf33790a28643ab058b507b35cBen Cheng # Check whether header files must be updated. 18225b3c049e70834cf33790a28643ab058b507b35cBen Cheng if test $first = no; then 18325b3c049e70834cf33790a28643ab058b507b35cBen Cheng if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then 18425b3c049e70834cf33790a28643ab058b507b35cBen Cheng echo "$2" is unchanged 18525b3c049e70834cf33790a28643ab058b507b35cBen Cheng rm -f "$target" 18625b3c049e70834cf33790a28643ab058b507b35cBen Cheng else 18725b3c049e70834cf33790a28643ab058b507b35cBen Cheng echo updating "$2" 18825b3c049e70834cf33790a28643ab058b507b35cBen Cheng mv -f "$target" "$realtarget" 18925b3c049e70834cf33790a28643ab058b507b35cBen Cheng fi 19025b3c049e70834cf33790a28643ab058b507b35cBen Cheng fi 19125b3c049e70834cf33790a28643ab058b507b35cBen Cheng else 19225b3c049e70834cf33790a28643ab058b507b35cBen Cheng # A missing file is only an error for the first file. This 19325b3c049e70834cf33790a28643ab058b507b35cBen Cheng # is a blatant hack to let us support using "yacc -d". If -d 19425b3c049e70834cf33790a28643ab058b507b35cBen Cheng # is not specified, we don't want an error when the header 19525b3c049e70834cf33790a28643ab058b507b35cBen Cheng # file is "missing". 19625b3c049e70834cf33790a28643ab058b507b35cBen Cheng if test $first = yes; then 19725b3c049e70834cf33790a28643ab058b507b35cBen Cheng ret=1 19825b3c049e70834cf33790a28643ab058b507b35cBen Cheng fi 19925b3c049e70834cf33790a28643ab058b507b35cBen Cheng fi 20025b3c049e70834cf33790a28643ab058b507b35cBen Cheng shift 20125b3c049e70834cf33790a28643ab058b507b35cBen Cheng shift 20225b3c049e70834cf33790a28643ab058b507b35cBen Cheng first=no 20325b3c049e70834cf33790a28643ab058b507b35cBen Cheng done 20425b3c049e70834cf33790a28643ab058b507b35cBen Chengelse 20525b3c049e70834cf33790a28643ab058b507b35cBen Cheng ret=$? 20625b3c049e70834cf33790a28643ab058b507b35cBen Chengfi 20725b3c049e70834cf33790a28643ab058b507b35cBen Cheng 20825b3c049e70834cf33790a28643ab058b507b35cBen Cheng# Remove the directory. 20925b3c049e70834cf33790a28643ab058b507b35cBen Chengcd .. 21025b3c049e70834cf33790a28643ab058b507b35cBen Chengrm -rf $dirname 21125b3c049e70834cf33790a28643ab058b507b35cBen Cheng 21225b3c049e70834cf33790a28643ab058b507b35cBen Chengexit $ret 21325b3c049e70834cf33790a28643ab058b507b35cBen Cheng 21425b3c049e70834cf33790a28643ab058b507b35cBen Cheng# Local Variables: 21525b3c049e70834cf33790a28643ab058b507b35cBen Cheng# mode: shell-script 21625b3c049e70834cf33790a28643ab058b507b35cBen Cheng# sh-indentation: 2 21725b3c049e70834cf33790a28643ab058b507b35cBen Cheng# eval: (add-hook 'write-file-hooks 'time-stamp) 21825b3c049e70834cf33790a28643ab058b507b35cBen Cheng# time-stamp-start: "scriptversion=" 21925b3c049e70834cf33790a28643ab058b507b35cBen Cheng# time-stamp-format: "%:y-%02m-%02d.%02H" 22025b3c049e70834cf33790a28643ab058b507b35cBen Cheng# time-stamp-time-zone: "UTC" 22125b3c049e70834cf33790a28643ab058b507b35cBen Cheng# time-stamp-end: "; # UTC" 22225b3c049e70834cf33790a28643ab058b507b35cBen Cheng# End: 223