Home | History | Annotate | Line # | Download | only in dist
ylwrap revision 1.1.1.2
      1      1.1     skrll #! /bin/sh
      2      1.1     skrll # ylwrap - wrapper for lex/yacc invocations.
      3      1.1     skrll 
      4  1.1.1.2  christos scriptversion=2009-04-28.21; # UTC
      5      1.1     skrll 
      6  1.1.1.2  christos # Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005,
      7  1.1.1.2  christos # 2007, 2009 Free Software Foundation, Inc.
      8      1.1     skrll #
      9      1.1     skrll # Written by Tom Tromey <tromey (at] cygnus.com>.
     10      1.1     skrll #
     11      1.1     skrll # This program is free software; you can redistribute it and/or modify
     12      1.1     skrll # it under the terms of the GNU General Public License as published by
     13      1.1     skrll # the Free Software Foundation; either version 2, or (at your option)
     14      1.1     skrll # any later version.
     15      1.1     skrll #
     16      1.1     skrll # This program is distributed in the hope that it will be useful,
     17      1.1     skrll # but WITHOUT ANY WARRANTY; without even the implied warranty of
     18      1.1     skrll # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19      1.1     skrll # GNU General Public License for more details.
     20      1.1     skrll #
     21      1.1     skrll # You should have received a copy of the GNU General Public License
     22  1.1.1.2  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     23      1.1     skrll 
     24      1.1     skrll # As a special exception to the GNU General Public License, if you
     25      1.1     skrll # distribute this file as part of a program that contains a
     26      1.1     skrll # configuration script generated by Autoconf, you may include it under
     27      1.1     skrll # the same distribution terms that you use for the rest of that program.
     28      1.1     skrll 
     29      1.1     skrll # This file is maintained in Automake, please report
     30      1.1     skrll # bugs to <bug-automake (at] gnu.org> or send patches to
     31      1.1     skrll # <automake-patches (at] gnu.org>.
     32      1.1     skrll 
     33      1.1     skrll case "$1" in
     34      1.1     skrll   '')
     35      1.1     skrll     echo "$0: No files given.  Try \`$0 --help' for more information." 1>&2
     36      1.1     skrll     exit 1
     37      1.1     skrll     ;;
     38      1.1     skrll   --basedir)
     39      1.1     skrll     basedir=$2
     40      1.1     skrll     shift 2
     41      1.1     skrll     ;;
     42      1.1     skrll   -h|--h*)
     43      1.1     skrll     cat <<\EOF
     44      1.1     skrll Usage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]...
     45      1.1     skrll 
     46      1.1     skrll Wrapper for lex/yacc invocations, renaming files as desired.
     47      1.1     skrll 
     48      1.1     skrll   INPUT is the input file
     49      1.1     skrll   OUTPUT is one file PROG generates
     50      1.1     skrll   DESIRED is the file we actually want instead of OUTPUT
     51      1.1     skrll   PROGRAM is program to run
     52      1.1     skrll   ARGS are passed to PROG
     53      1.1     skrll 
     54      1.1     skrll Any number of OUTPUT,DESIRED pairs may be used.
     55      1.1     skrll 
     56      1.1     skrll Report bugs to <bug-automake (at] gnu.org>.
     57      1.1     skrll EOF
     58      1.1     skrll     exit $?
     59      1.1     skrll     ;;
     60      1.1     skrll   -v|--v*)
     61      1.1     skrll     echo "ylwrap $scriptversion"
     62      1.1     skrll     exit $?
     63      1.1     skrll     ;;
     64      1.1     skrll esac
     65      1.1     skrll 
     66      1.1     skrll 
     67      1.1     skrll # The input.
     68      1.1     skrll input="$1"
     69      1.1     skrll shift
     70      1.1     skrll case "$input" in
     71      1.1     skrll   [\\/]* | ?:[\\/]*)
     72      1.1     skrll     # Absolute path; do nothing.
     73      1.1     skrll     ;;
     74      1.1     skrll   *)
     75      1.1     skrll     # Relative path.  Make it absolute.
     76      1.1     skrll     input="`pwd`/$input"
     77      1.1     skrll     ;;
     78      1.1     skrll esac
     79      1.1     skrll 
     80      1.1     skrll pairlist=
     81      1.1     skrll while test "$#" -ne 0; do
     82      1.1     skrll   if test "$1" = "--"; then
     83      1.1     skrll     shift
     84      1.1     skrll     break
     85      1.1     skrll   fi
     86      1.1     skrll   pairlist="$pairlist $1"
     87      1.1     skrll   shift
     88      1.1     skrll done
     89      1.1     skrll 
     90      1.1     skrll # The program to run.
     91      1.1     skrll prog="$1"
     92      1.1     skrll shift
     93      1.1     skrll # Make any relative path in $prog absolute.
     94      1.1     skrll case "$prog" in
     95      1.1     skrll   [\\/]* | ?:[\\/]*) ;;
     96      1.1     skrll   *[\\/]*) prog="`pwd`/$prog" ;;
     97      1.1     skrll esac
     98      1.1     skrll 
     99      1.1     skrll # FIXME: add hostname here for parallel makes that run commands on
    100      1.1     skrll # other machines.  But that might take us over the 14-char limit.
    101      1.1     skrll dirname=ylwrap$$
    102  1.1.1.2  christos trap "cd '`pwd`'; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15
    103      1.1     skrll mkdir $dirname || exit 1
    104      1.1     skrll 
    105      1.1     skrll cd $dirname
    106      1.1     skrll 
    107      1.1     skrll case $# in
    108  1.1.1.2  christos   0) "$prog" "$input" ;;
    109  1.1.1.2  christos   *) "$prog" "$@" "$input" ;;
    110      1.1     skrll esac
    111      1.1     skrll ret=$?
    112      1.1     skrll 
    113      1.1     skrll if test $ret -eq 0; then
    114      1.1     skrll   set X $pairlist
    115      1.1     skrll   shift
    116      1.1     skrll   first=yes
    117      1.1     skrll   # Since DOS filename conventions don't allow two dots,
    118      1.1     skrll   # the DOS version of Bison writes out y_tab.c instead of y.tab.c
    119      1.1     skrll   # and y_tab.h instead of y.tab.h. Test to see if this is the case.
    120      1.1     skrll   y_tab_nodot="no"
    121      1.1     skrll   if test -f y_tab.c || test -f y_tab.h; then
    122      1.1     skrll     y_tab_nodot="yes"
    123      1.1     skrll   fi
    124      1.1     skrll 
    125      1.1     skrll   # The directory holding the input.
    126      1.1     skrll   input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'`
    127      1.1     skrll   # Quote $INPUT_DIR so we can use it in a regexp.
    128      1.1     skrll   # FIXME: really we should care about more than `.' and `\'.
    129      1.1     skrll   input_rx=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'`
    130      1.1     skrll 
    131      1.1     skrll   while test "$#" -ne 0; do
    132      1.1     skrll     from="$1"
    133      1.1     skrll     # Handle y_tab.c and y_tab.h output by DOS
    134      1.1     skrll     if test $y_tab_nodot = "yes"; then
    135      1.1     skrll       if test $from = "y.tab.c"; then
    136      1.1     skrll     	from="y_tab.c"
    137      1.1     skrll       else
    138      1.1     skrll     	if test $from = "y.tab.h"; then
    139      1.1     skrll     	  from="y_tab.h"
    140      1.1     skrll     	fi
    141      1.1     skrll       fi
    142      1.1     skrll     fi
    143      1.1     skrll     if test -f "$from"; then
    144      1.1     skrll       # If $2 is an absolute path name, then just use that,
    145      1.1     skrll       # otherwise prepend `../'.
    146      1.1     skrll       case "$2" in
    147      1.1     skrll     	[\\/]* | ?:[\\/]*) target="$2";;
    148      1.1     skrll     	*) target="../$2";;
    149      1.1     skrll       esac
    150      1.1     skrll 
    151      1.1     skrll       # We do not want to overwrite a header file if it hasn't
    152      1.1     skrll       # changed.  This avoid useless recompilations.  However the
    153      1.1     skrll       # parser itself (the first file) should always be updated,
    154      1.1     skrll       # because it is the destination of the .y.c rule in the
    155      1.1     skrll       # Makefile.  Divert the output of all other files to a temporary
    156      1.1     skrll       # file so we can compare them to existing versions.
    157      1.1     skrll       if test $first = no; then
    158      1.1     skrll 	realtarget="$target"
    159      1.1     skrll 	target="tmp-`echo $target | sed s/.*[\\/]//g`"
    160      1.1     skrll       fi
    161      1.1     skrll       # Edit out `#line' or `#' directives.
    162      1.1     skrll       #
    163      1.1     skrll       # We don't want the resulting debug information to point at
    164      1.1     skrll       # an absolute srcdir; it is better for it to just mention the
    165      1.1     skrll       # .y file with no path.
    166      1.1     skrll       #
    167      1.1     skrll       # We want to use the real output file name, not yy.lex.c for
    168      1.1     skrll       # instance.
    169      1.1     skrll       #
    170      1.1     skrll       # We want the include guards to be adjusted too.
    171      1.1     skrll       FROM=`echo "$from" | sed \
    172      1.1     skrll             -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
    173      1.1     skrll             -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
    174      1.1     skrll       TARGET=`echo "$2" | sed \
    175      1.1     skrll             -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
    176      1.1     skrll             -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
    177      1.1     skrll 
    178      1.1     skrll       sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \
    179      1.1     skrll           -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$?
    180      1.1     skrll 
    181      1.1     skrll       # Check whether header files must be updated.
    182      1.1     skrll       if test $first = no; then
    183      1.1     skrll 	if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
    184      1.1     skrll 	  echo "$2" is unchanged
    185      1.1     skrll 	  rm -f "$target"
    186      1.1     skrll 	else
    187      1.1     skrll           echo updating "$2"
    188      1.1     skrll           mv -f "$target" "$realtarget"
    189      1.1     skrll         fi
    190      1.1     skrll       fi
    191      1.1     skrll     else
    192      1.1     skrll       # A missing file is only an error for the first file.  This
    193      1.1     skrll       # is a blatant hack to let us support using "yacc -d".  If -d
    194      1.1     skrll       # is not specified, we don't want an error when the header
    195      1.1     skrll       # file is "missing".
    196      1.1     skrll       if test $first = yes; then
    197      1.1     skrll         ret=1
    198      1.1     skrll       fi
    199      1.1     skrll     fi
    200      1.1     skrll     shift
    201      1.1     skrll     shift
    202      1.1     skrll     first=no
    203      1.1     skrll   done
    204      1.1     skrll else
    205      1.1     skrll   ret=$?
    206      1.1     skrll fi
    207      1.1     skrll 
    208      1.1     skrll # Remove the directory.
    209      1.1     skrll cd ..
    210      1.1     skrll rm -rf $dirname
    211      1.1     skrll 
    212      1.1     skrll exit $ret
    213      1.1     skrll 
    214      1.1     skrll # Local Variables:
    215      1.1     skrll # mode: shell-script
    216      1.1     skrll # sh-indentation: 2
    217      1.1     skrll # eval: (add-hook 'write-file-hooks 'time-stamp)
    218      1.1     skrll # time-stamp-start: "scriptversion="
    219      1.1     skrll # time-stamp-format: "%:y-%02m-%02d.%02H"
    220  1.1.1.2  christos # time-stamp-time-zone: "UTC"
    221  1.1.1.2  christos # time-stamp-end: "; # UTC"
    222      1.1     skrll # End:
    223