184d9c625SLionel Sambuc#! /bin/sh 284d9c625SLionel Sambuc# ylwrap - wrapper for lex/yacc invocations. 384d9c625SLionel Sambuc 4*0a6a1f1dSLionel Sambucscriptversion=2011-08-25.18; # UTC 584d9c625SLionel Sambuc 684d9c625SLionel Sambuc# Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005, 7*0a6a1f1dSLionel Sambuc# 2007, 2009, 2010, 2011 Free Software Foundation, Inc. 884d9c625SLionel Sambuc# 984d9c625SLionel Sambuc# Written by Tom Tromey <tromey@cygnus.com>. 1084d9c625SLionel Sambuc# 1184d9c625SLionel Sambuc# This program is free software; you can redistribute it and/or modify 1284d9c625SLionel Sambuc# it under the terms of the GNU General Public License as published by 1384d9c625SLionel Sambuc# the Free Software Foundation; either version 2, or (at your option) 1484d9c625SLionel Sambuc# any later version. 1584d9c625SLionel Sambuc# 1684d9c625SLionel Sambuc# This program is distributed in the hope that it will be useful, 1784d9c625SLionel Sambuc# but WITHOUT ANY WARRANTY; without even the implied warranty of 1884d9c625SLionel Sambuc# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1984d9c625SLionel Sambuc# GNU General Public License for more details. 2084d9c625SLionel Sambuc# 2184d9c625SLionel Sambuc# You should have received a copy of the GNU General Public License 2284d9c625SLionel Sambuc# along with this program. If not, see <http://www.gnu.org/licenses/>. 2384d9c625SLionel Sambuc 2484d9c625SLionel Sambuc# As a special exception to the GNU General Public License, if you 2584d9c625SLionel Sambuc# distribute this file as part of a program that contains a 2684d9c625SLionel Sambuc# configuration script generated by Autoconf, you may include it under 2784d9c625SLionel Sambuc# the same distribution terms that you use for the rest of that program. 2884d9c625SLionel Sambuc 2984d9c625SLionel Sambuc# This file is maintained in Automake, please report 3084d9c625SLionel Sambuc# bugs to <bug-automake@gnu.org> or send patches to 3184d9c625SLionel Sambuc# <automake-patches@gnu.org>. 3284d9c625SLionel Sambuc 3384d9c625SLionel Sambuccase "$1" in 3484d9c625SLionel Sambuc '') 3584d9c625SLionel Sambuc echo "$0: No files given. Try \`$0 --help' for more information." 1>&2 3684d9c625SLionel Sambuc exit 1 3784d9c625SLionel Sambuc ;; 3884d9c625SLionel Sambuc --basedir) 3984d9c625SLionel Sambuc basedir=$2 4084d9c625SLionel Sambuc shift 2 4184d9c625SLionel Sambuc ;; 4284d9c625SLionel Sambuc -h|--h*) 4384d9c625SLionel Sambuc cat <<\EOF 4484d9c625SLionel SambucUsage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]... 4584d9c625SLionel Sambuc 4684d9c625SLionel SambucWrapper for lex/yacc invocations, renaming files as desired. 4784d9c625SLionel Sambuc 4884d9c625SLionel Sambuc INPUT is the input file 4984d9c625SLionel Sambuc OUTPUT is one file PROG generates 5084d9c625SLionel Sambuc DESIRED is the file we actually want instead of OUTPUT 5184d9c625SLionel Sambuc PROGRAM is program to run 5284d9c625SLionel Sambuc ARGS are passed to PROG 5384d9c625SLionel Sambuc 5484d9c625SLionel SambucAny number of OUTPUT,DESIRED pairs may be used. 5584d9c625SLionel Sambuc 5684d9c625SLionel SambucReport bugs to <bug-automake@gnu.org>. 5784d9c625SLionel SambucEOF 5884d9c625SLionel Sambuc exit $? 5984d9c625SLionel Sambuc ;; 6084d9c625SLionel Sambuc -v|--v*) 6184d9c625SLionel Sambuc echo "ylwrap $scriptversion" 6284d9c625SLionel Sambuc exit $? 6384d9c625SLionel Sambuc ;; 6484d9c625SLionel Sambucesac 6584d9c625SLionel Sambuc 6684d9c625SLionel Sambuc 6784d9c625SLionel Sambuc# The input. 6884d9c625SLionel Sambucinput="$1" 6984d9c625SLionel Sambucshift 7084d9c625SLionel Sambuccase "$input" in 7184d9c625SLionel Sambuc [\\/]* | ?:[\\/]*) 7284d9c625SLionel Sambuc # Absolute path; do nothing. 7384d9c625SLionel Sambuc ;; 7484d9c625SLionel Sambuc *) 7584d9c625SLionel Sambuc # Relative path. Make it absolute. 7684d9c625SLionel Sambuc input="`pwd`/$input" 7784d9c625SLionel Sambuc ;; 7884d9c625SLionel Sambucesac 7984d9c625SLionel Sambuc 8084d9c625SLionel Sambucpairlist= 8184d9c625SLionel Sambucwhile test "$#" -ne 0; do 8284d9c625SLionel Sambuc if test "$1" = "--"; then 8384d9c625SLionel Sambuc shift 8484d9c625SLionel Sambuc break 8584d9c625SLionel Sambuc fi 8684d9c625SLionel Sambuc pairlist="$pairlist $1" 8784d9c625SLionel Sambuc shift 8884d9c625SLionel Sambucdone 8984d9c625SLionel Sambuc 9084d9c625SLionel Sambuc# The program to run. 9184d9c625SLionel Sambucprog="$1" 9284d9c625SLionel Sambucshift 9384d9c625SLionel Sambuc# Make any relative path in $prog absolute. 9484d9c625SLionel Sambuccase "$prog" in 9584d9c625SLionel Sambuc [\\/]* | ?:[\\/]*) ;; 9684d9c625SLionel Sambuc *[\\/]*) prog="`pwd`/$prog" ;; 9784d9c625SLionel Sambucesac 9884d9c625SLionel Sambuc 9984d9c625SLionel Sambuc# FIXME: add hostname here for parallel makes that run commands on 10084d9c625SLionel Sambuc# other machines. But that might take us over the 14-char limit. 10184d9c625SLionel Sambucdirname=ylwrap$$ 102*0a6a1f1dSLionel Sambucdo_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret' 103*0a6a1f1dSLionel Sambuctrap "ret=129; $do_exit" 1 104*0a6a1f1dSLionel Sambuctrap "ret=130; $do_exit" 2 105*0a6a1f1dSLionel Sambuctrap "ret=141; $do_exit" 13 106*0a6a1f1dSLionel Sambuctrap "ret=143; $do_exit" 15 10784d9c625SLionel Sambucmkdir $dirname || exit 1 10884d9c625SLionel Sambuc 10984d9c625SLionel Sambuccd $dirname 11084d9c625SLionel Sambuc 11184d9c625SLionel Sambuccase $# in 11284d9c625SLionel Sambuc 0) "$prog" "$input" ;; 11384d9c625SLionel Sambuc *) "$prog" "$@" "$input" ;; 11484d9c625SLionel Sambucesac 11584d9c625SLionel Sambucret=$? 11684d9c625SLionel Sambuc 11784d9c625SLionel Sambucif test $ret -eq 0; then 11884d9c625SLionel Sambuc set X $pairlist 11984d9c625SLionel Sambuc shift 12084d9c625SLionel Sambuc first=yes 12184d9c625SLionel Sambuc # Since DOS filename conventions don't allow two dots, 12284d9c625SLionel Sambuc # the DOS version of Bison writes out y_tab.c instead of y.tab.c 12384d9c625SLionel Sambuc # and y_tab.h instead of y.tab.h. Test to see if this is the case. 12484d9c625SLionel Sambuc y_tab_nodot="no" 12584d9c625SLionel Sambuc if test -f y_tab.c || test -f y_tab.h; then 12684d9c625SLionel Sambuc y_tab_nodot="yes" 12784d9c625SLionel Sambuc fi 12884d9c625SLionel Sambuc 12984d9c625SLionel Sambuc # The directory holding the input. 13084d9c625SLionel Sambuc input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'` 13184d9c625SLionel Sambuc # Quote $INPUT_DIR so we can use it in a regexp. 13284d9c625SLionel Sambuc # FIXME: really we should care about more than `.' and `\'. 13384d9c625SLionel Sambuc input_rx=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'` 13484d9c625SLionel Sambuc 13584d9c625SLionel Sambuc while test "$#" -ne 0; do 13684d9c625SLionel Sambuc from="$1" 13784d9c625SLionel Sambuc # Handle y_tab.c and y_tab.h output by DOS 13884d9c625SLionel Sambuc if test $y_tab_nodot = "yes"; then 13984d9c625SLionel Sambuc if test $from = "y.tab.c"; then 14084d9c625SLionel Sambuc from="y_tab.c" 14184d9c625SLionel Sambuc else 14284d9c625SLionel Sambuc if test $from = "y.tab.h"; then 14384d9c625SLionel Sambuc from="y_tab.h" 14484d9c625SLionel Sambuc fi 14584d9c625SLionel Sambuc fi 14684d9c625SLionel Sambuc fi 14784d9c625SLionel Sambuc if test -f "$from"; then 14884d9c625SLionel Sambuc # If $2 is an absolute path name, then just use that, 14984d9c625SLionel Sambuc # otherwise prepend `../'. 15084d9c625SLionel Sambuc case "$2" in 15184d9c625SLionel Sambuc [\\/]* | ?:[\\/]*) target="$2";; 15284d9c625SLionel Sambuc *) target="../$2";; 15384d9c625SLionel Sambuc esac 15484d9c625SLionel Sambuc 15584d9c625SLionel Sambuc # We do not want to overwrite a header file if it hasn't 15684d9c625SLionel Sambuc # changed. This avoid useless recompilations. However the 15784d9c625SLionel Sambuc # parser itself (the first file) should always be updated, 15884d9c625SLionel Sambuc # because it is the destination of the .y.c rule in the 15984d9c625SLionel Sambuc # Makefile. Divert the output of all other files to a temporary 16084d9c625SLionel Sambuc # file so we can compare them to existing versions. 16184d9c625SLionel Sambuc if test $first = no; then 16284d9c625SLionel Sambuc realtarget="$target" 16384d9c625SLionel Sambuc target="tmp-`echo $target | sed s/.*[\\/]//g`" 16484d9c625SLionel Sambuc fi 16584d9c625SLionel Sambuc # Edit out `#line' or `#' directives. 16684d9c625SLionel Sambuc # 16784d9c625SLionel Sambuc # We don't want the resulting debug information to point at 16884d9c625SLionel Sambuc # an absolute srcdir; it is better for it to just mention the 16984d9c625SLionel Sambuc # .y file with no path. 17084d9c625SLionel Sambuc # 17184d9c625SLionel Sambuc # We want to use the real output file name, not yy.lex.c for 17284d9c625SLionel Sambuc # instance. 17384d9c625SLionel Sambuc # 17484d9c625SLionel Sambuc # We want the include guards to be adjusted too. 17584d9c625SLionel Sambuc FROM=`echo "$from" | sed \ 17684d9c625SLionel Sambuc -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\ 17784d9c625SLionel Sambuc -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'` 17884d9c625SLionel Sambuc TARGET=`echo "$2" | sed \ 17984d9c625SLionel Sambuc -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\ 18084d9c625SLionel Sambuc -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'` 18184d9c625SLionel Sambuc 18284d9c625SLionel Sambuc sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \ 18384d9c625SLionel Sambuc -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$? 18484d9c625SLionel Sambuc 18584d9c625SLionel Sambuc # Check whether header files must be updated. 18684d9c625SLionel Sambuc if test $first = no; then 18784d9c625SLionel Sambuc if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then 18884d9c625SLionel Sambuc echo "$2" is unchanged 18984d9c625SLionel Sambuc rm -f "$target" 19084d9c625SLionel Sambuc else 19184d9c625SLionel Sambuc echo updating "$2" 19284d9c625SLionel Sambuc mv -f "$target" "$realtarget" 19384d9c625SLionel Sambuc fi 19484d9c625SLionel Sambuc fi 19584d9c625SLionel Sambuc else 19684d9c625SLionel Sambuc # A missing file is only an error for the first file. This 19784d9c625SLionel Sambuc # is a blatant hack to let us support using "yacc -d". If -d 19884d9c625SLionel Sambuc # is not specified, we don't want an error when the header 19984d9c625SLionel Sambuc # file is "missing". 20084d9c625SLionel Sambuc if test $first = yes; then 20184d9c625SLionel Sambuc ret=1 20284d9c625SLionel Sambuc fi 20384d9c625SLionel Sambuc fi 20484d9c625SLionel Sambuc shift 20584d9c625SLionel Sambuc shift 20684d9c625SLionel Sambuc first=no 20784d9c625SLionel Sambuc done 20884d9c625SLionel Sambucelse 20984d9c625SLionel Sambuc ret=$? 21084d9c625SLionel Sambucfi 21184d9c625SLionel Sambuc 21284d9c625SLionel Sambuc# Remove the directory. 21384d9c625SLionel Sambuccd .. 21484d9c625SLionel Sambucrm -rf $dirname 21584d9c625SLionel Sambuc 21684d9c625SLionel Sambucexit $ret 21784d9c625SLionel Sambuc 21884d9c625SLionel Sambuc# Local Variables: 21984d9c625SLionel Sambuc# mode: shell-script 22084d9c625SLionel Sambuc# sh-indentation: 2 22184d9c625SLionel Sambuc# eval: (add-hook 'write-file-hooks 'time-stamp) 22284d9c625SLionel Sambuc# time-stamp-start: "scriptversion=" 22384d9c625SLionel Sambuc# time-stamp-format: "%:y-%02m-%02d.%02H" 22484d9c625SLionel Sambuc# time-stamp-time-zone: "UTC" 22584d9c625SLionel Sambuc# time-stamp-end: "; # UTC" 22684d9c625SLionel Sambuc# End: 227