From da15f1ab934ee984f061fe2d40e505de66dff30c Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 9 May 2001 03:10:04 +0000 Subject: [PATCH] For PR automake/29: * ylwrap: Handle arguments to program. Remove old code that tried to avoid absolute paths and add new code to do it in all cases. Removed ancient logic that tried to deal with relative path. * tests/Makefile.am (TESTS): Added yacc4.test. * tests/yacc4.test: New file. --- ChangeLog | 7 +++++ lib/am/yacc.am | 3 +- lib/ylwrap | 48 +++++++++++++++++------------- tests/Makefile.am | 1 + tests/Makefile.in | 1 + tests/yacc4.test | 75 +++++++++++++++++++++++++++++++++++++++++++++++ yacc.am | 3 +- ylwrap | 48 +++++++++++++++++------------- 8 files changed, 142 insertions(+), 44 deletions(-) create mode 100755 tests/yacc4.test diff --git a/ChangeLog b/ChangeLog index 8adede90..9ef2b852 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2001-05-08 Tom Tromey + For PR automake/29: + * ylwrap: Handle arguments to program. Remove old code that tried + to avoid absolute paths and add new code to do it in all cases. + Removed ancient logic that tried to deal with relative path. + * tests/Makefile.am (TESTS): Added yacc4.test. + * tests/yacc4.test: New file. + Fix for PR automake/149 and werror.test: * automake.in (require_file_internal): Use am_line_warning or am_conf_line_warning when suppressing error. diff --git a/lib/am/yacc.am b/lib/am/yacc.am index 0d7e1053..344fb9ec 100644 --- a/lib/am/yacc.am +++ b/lib/am/yacc.am @@ -21,7 +21,8 @@ if %?YLWRAP% $(SHELL) $(YLWRAP) $(YACC) $< y.tab.c $*%C_SUFFIX% y.tab.h $*.h -- $(AM_YFLAGS) $(YFLAGS) else !%?YLWRAP% - $(YACC) $(AM_YFLAGS) $(YFLAGS) $< && mv y.tab.c $*%C_SUFFIX% + $(YACC) $(AM_YFLAGS) $(YFLAGS) $< + sed -e '/^#/ s,$(srcdir)/,,' y.tab.c > $*%C_SUFFIX% if test -f y.tab.h; then \ if cmp -s y.tab.h $*.h; then \ rm -f y.tab.h; \ diff --git a/lib/ylwrap b/lib/ylwrap index 8aa0314d..c78cdd74 100755 --- a/lib/ylwrap +++ b/lib/ylwrap @@ -18,8 +18,8 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Usage: -# ylwrap PROGRAM INPUT [OUTPUT DESIRED]... -- [ARGS]... -# * PROGRAM is program to run. +# ylwrap PROGRAM [ARGS] INPUT [OUTPUT DESIRED]... -- [ARGS]... +# * PROGRAM is program to run; options can follow but must start with `-'. # * INPUT is the input file # * OUTPUT is file PROG generates # * DESIRED is file we actually want @@ -35,6 +35,21 @@ case "$prog" in */*) prog="`pwd`/$prog" ;; esac +# We also have to accept options here and append them to the program. +# Why? Suppose YACC is set to `bison -y'. Clearly nobody uses +# ylwrap, or this would have been discovered earlier! +while :; do + case "$1" in + -*) + prog="$prog $1" + shift + ;; + *) + break + ;; + esac +done + # The input. input="$1" shift @@ -43,19 +58,13 @@ case "$input" in # Absolute path; do nothing. ;; *) - # Relative path. Make it absolute. Why? Because otherwise any - # debugging info in the generated file will point to the wrong - # place. This is really gross. + # Relative path. Make it absolute. input="`pwd`/$input" ;; esac -# We don't want to use the absolute path if the input in the current -# directory like when making a tar ball. -input_base=`echo $input | sed -e 's|.*/||'` -if test -f $input_base && cmp $input_base $input >/dev/null 2>&1; then - input=$input_base -fi +# The directory holding the input. +input_dir="`echo $input | sed -e 's,/[^/]*$,,'`" pairlist= while test "$#" -ne 0; do @@ -74,15 +83,7 @@ trap "cd `pwd`; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15 mkdir $dirname || exit 1 cd $dirname -case "$input" in - /* | [A-Za-z]:*) - # Absolute path; do nothing. - ;; - *) - # Make a symbolic link, hard link or hardcopy. - ln -s ../"$input" . > /dev/null 2>&1 || ln ../"$input" . > /dev/null 2>&1 || cp ../"$input" . - ;; -esac + $prog ${1+"$@"} "$input" status=$? @@ -117,7 +118,12 @@ if test $status -eq 0; then /* | [A-Za-z]:*) target="$2";; *) target="../$2";; esac - mv "$from" "$target" || status=$? + + # Edit out `#line' or `#' directives. We don't want the + # resulting debug information to point at an absolute srcdir; + # it is better for it to just mention the .y file with no + # path. + sed -e "/^#/ s,$input_dir,," "$from" > "$target" || status=$? else # A missing file is only an error for the first file. This # is a blatant hack to let us support using "yacc -d". If -d diff --git a/tests/Makefile.am b/tests/Makefile.am index ab886ad1..2583ee4d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -285,6 +285,7 @@ xsource.test \ yacc.test \ yacc2.test \ yacc3.test \ +yacc4.test \ yaccpp.test \ yaccvpath.test diff --git a/tests/Makefile.in b/tests/Makefile.in index bdb453e8..a6f1a94d 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -357,6 +357,7 @@ xsource.test \ yacc.test \ yacc2.test \ yacc3.test \ +yacc4.test \ yaccpp.test \ yaccvpath.test diff --git a/tests/yacc4.test b/tests/yacc4.test new file mode 100755 index 00000000..769ca5e3 --- /dev/null +++ b/tests/yacc4.test @@ -0,0 +1,75 @@ +#! /bin/sh + +# Some simple tests of ylwrap functionality. + +. $srcdir/defs || exit 1 + +# Fail gracefully if no autoconf. +$needs_autoconf +# Likewise for some other tools. +(gcc -v) > /dev/null 2>&1 || exit 77 +(bison -V) > /dev/null 2>&1 || exit 77 + +cat > configure.in << 'END' +AC_INIT +AC_CONFIG_AUX_DIR([.]) +AM_INIT_AUTOMAKE(foo, 0.1) +PACKAGE=foo +VERSION=0.1 +AC_PROG_CC +AC_PROG_YACC +AC_OUTPUT(Makefile) +END + +cat > Makefile.am << 'END' +bin_PROGRAMS = foo bar +foo_SOURCES = parse.y foo.c +bar_SOURCES = bar.y foo.c +END + +# First parser. +cat > parse.y << 'END' +%{ +int yylex () {return 0;} +void yyerror (char *s) {} +%} +%% +foobar : 'f' 'o' 'o' 'b' 'a' 'r' {}; +END + +# Second parser. +cat > bar.y << 'END' +%{ +int yylex () {return 0;} +void yyerror (char *s) {} +%} +%% +fubar : 'f' 'o' 'o' 'b' 'a' 'r' {}; +END + +cat > foo.c << 'END' +int main () { return 0; } +END + +# We are not checking Autoconf, so we pick $YACC for it. +YACC="bison -y" +export YACC + +set -e + +$ACLOCAL +$AUTOCONF +$AUTOMAKE -a + +test -f ylwrap + +mkdir sub +cd sub + +../configure +$MAKE + +grep '^#.*/sub/\.\./' bar.c && exit 1 +grep '^#.*/sub/\.\./' parse.c && exit 1 + +exit 0 diff --git a/yacc.am b/yacc.am index 0d7e1053..344fb9ec 100644 --- a/yacc.am +++ b/yacc.am @@ -21,7 +21,8 @@ if %?YLWRAP% $(SHELL) $(YLWRAP) $(YACC) $< y.tab.c $*%C_SUFFIX% y.tab.h $*.h -- $(AM_YFLAGS) $(YFLAGS) else !%?YLWRAP% - $(YACC) $(AM_YFLAGS) $(YFLAGS) $< && mv y.tab.c $*%C_SUFFIX% + $(YACC) $(AM_YFLAGS) $(YFLAGS) $< + sed -e '/^#/ s,$(srcdir)/,,' y.tab.c > $*%C_SUFFIX% if test -f y.tab.h; then \ if cmp -s y.tab.h $*.h; then \ rm -f y.tab.h; \ diff --git a/ylwrap b/ylwrap index 8aa0314d..c78cdd74 100755 --- a/ylwrap +++ b/ylwrap @@ -18,8 +18,8 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Usage: -# ylwrap PROGRAM INPUT [OUTPUT DESIRED]... -- [ARGS]... -# * PROGRAM is program to run. +# ylwrap PROGRAM [ARGS] INPUT [OUTPUT DESIRED]... -- [ARGS]... +# * PROGRAM is program to run; options can follow but must start with `-'. # * INPUT is the input file # * OUTPUT is file PROG generates # * DESIRED is file we actually want @@ -35,6 +35,21 @@ case "$prog" in */*) prog="`pwd`/$prog" ;; esac +# We also have to accept options here and append them to the program. +# Why? Suppose YACC is set to `bison -y'. Clearly nobody uses +# ylwrap, or this would have been discovered earlier! +while :; do + case "$1" in + -*) + prog="$prog $1" + shift + ;; + *) + break + ;; + esac +done + # The input. input="$1" shift @@ -43,19 +58,13 @@ case "$input" in # Absolute path; do nothing. ;; *) - # Relative path. Make it absolute. Why? Because otherwise any - # debugging info in the generated file will point to the wrong - # place. This is really gross. + # Relative path. Make it absolute. input="`pwd`/$input" ;; esac -# We don't want to use the absolute path if the input in the current -# directory like when making a tar ball. -input_base=`echo $input | sed -e 's|.*/||'` -if test -f $input_base && cmp $input_base $input >/dev/null 2>&1; then - input=$input_base -fi +# The directory holding the input. +input_dir="`echo $input | sed -e 's,/[^/]*$,,'`" pairlist= while test "$#" -ne 0; do @@ -74,15 +83,7 @@ trap "cd `pwd`; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15 mkdir $dirname || exit 1 cd $dirname -case "$input" in - /* | [A-Za-z]:*) - # Absolute path; do nothing. - ;; - *) - # Make a symbolic link, hard link or hardcopy. - ln -s ../"$input" . > /dev/null 2>&1 || ln ../"$input" . > /dev/null 2>&1 || cp ../"$input" . - ;; -esac + $prog ${1+"$@"} "$input" status=$? @@ -117,7 +118,12 @@ if test $status -eq 0; then /* | [A-Za-z]:*) target="$2";; *) target="../$2";; esac - mv "$from" "$target" || status=$? + + # Edit out `#line' or `#' directives. We don't want the + # resulting debug information to point at an absolute srcdir; + # it is better for it to just mention the .y file with no + # path. + sed -e "/^#/ s,$input_dir,," "$from" > "$target" || status=$? else # A missing file is only an error for the first file. This # is a blatant hack to let us support using "yacc -d". If -d -- 2.43.5