>From e5b964c4ddac632d53138e9e483f105839514fe7 Mon Sep 17 00:00:00 2001 Message-Id: From: Stefano Lattarini Date: Wed, 1 Feb 2012 22:07:43 +0100 Subject: [PATCH] [ng] yacc, lex, compiling: better use of '$<' (simplify and fix bug) With GNU make (at least since version 3.78), the automatic variable '$<' automatically undergoes VPATH rewrites when needed. We can use this fact to simplify some of our recently-touched rules even more. This change is also a bug fix, since without it the two tests 'yacc-subobj-nodep.test' and 'lex-subobj-nodep.test' were failing with at least GNU make 3.81 (while passing with GNU make 3.82), probably due to some incompatibility between those two versions that was affecting our '$(am__vpath_rewrite)' function. * lib/am/yacc.am, lib/am/lex.am: Take advantage of the described '$<' behaviour. * lib/am/depend2.am: Likewise. Accordingly, ... (am__cooked_source_0, am__cooked_source_1): ... remove these variables, which are not needed anymore. * tests/spy-vpath-rewrite.test: New test, verifying that our expectations about '$<' really hold. * tests/list-of-tests.mk: Add the new test. --- lib/am/depend2.am | 29 +++----- lib/am/lex.am | 8 +-- lib/am/yacc.am | 8 +-- tests/list-of-tests.mk | 1 + tests/spy-vpath-rewrite.test | 150 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 168 insertions(+), 28 deletions(-) create mode 100755 tests/spy-vpath-rewrite.test diff --git a/lib/am/depend2.am b/lib/am/depend2.am index df5db1e..7a5db63 100644 --- a/lib/am/depend2.am +++ b/lib/am/depend2.am @@ -35,19 +35,12 @@ ## and easily inline the dependency tracking. if %?FIRST% - ?SUBDIROBJ?am__depdir = $(dir $@)/$(DEPDIR) ?!SUBDIROBJ?am__depdir = $(DEPDIR) ## FIXME: more precise in the removal of the suffix? am__depbase = $(am__depdir)/$(basename $(notdir $@)) ## Avoid useless forks when possible. am__ensure_depdir = test -d $(am__depdir) || $(MKDIR_P) $(am__depdir) - -## Used for suffix rules. -am__cooked_source_0 = $(call am__vpath_rewrite, $<) -## Used for explicit rules. -am__cooked_source_1 = $< - endif %?FIRST% if %?NONLIBTOOL% @@ -56,8 +49,8 @@ if %?NONLIBTOOL% if %FASTDEP% %SILENT%$(am__ensure_depdir) ## In fast-dep mode, we can always use -o. - %VERBOSE%%COMPILE% -MT $@ -MD -MP -MF $(am__depbase).Tpo %-c% -o $@ \ - %SOURCEFLAG%$(am__cooked_source_%GENERIC%) + %VERBOSE%%COMPILE% -MT $@ -MD -MP -MF $(am__depbase).Tpo \ + %-c% -o $@ %SOURCEFLAG%$< %SILENT%$(am__mv) $(am__depbase).Tpo $(am__depbase).Po else !%FASTDEP% if %AMDEP% @@ -65,8 +58,8 @@ if %AMDEP% %VERBOSE%source='%SOURCE%' object='%OBJ%' libtool=no @AMDEPBACKSLASH@ DEPDIR=$(DEPDIR) $(%FPFX%DEPMODE) $(depcomp) @AMDEPBACKSLASH@ endif %AMDEP% -?-o? %VERBOSE-NODEP%%COMPILE% %-c% %-o% %OBJ% %SOURCEFLAG%$(am__cooked_source_%GENERIC%) -?!-o? %VERBOSE-NODEP%%COMPILE% %-c% %SOURCEFLAG%$(am__cooked_source_%GENERIC%) +?-o? %VERBOSE-NODEP%%COMPILE% %-c% %-o% %OBJ% %SOURCEFLAG%$< +?!-o? %VERBOSE-NODEP%%COMPILE% %-c% %SOURCEFLAG%$< endif !%FASTDEP% ?GENERIC?%EXT%.obj: @@ -74,8 +67,8 @@ endif !%FASTDEP% if %FASTDEP% %SILENT%$(am__ensure_depdir) ## In fast-dep mode, we can always use -o. - %VERBOSE%%COMPILE% -MT $@ -MD -MP -MF $(am__depbase).Tpo %-c% -o $@ \ - %SOURCEFLAG%`$(CYGPATH_W) $(am__cooked_source_%GENERIC%)` + %VERBOSE%%COMPILE% -MT $@ -MD -MP -MF $(am__depbase).Tpo \ + %-c% -o $@ %SOURCEFLAG%`$(CYGPATH_W) $<` %SILENT%$(am__mv) $(am__depbase).Tpo $(am__depbase).Po else !%FASTDEP% if %AMDEP% @@ -83,8 +76,8 @@ if %AMDEP% %VERBOSE%source='%SOURCE%' object='%OBJOBJ%' libtool=no @AMDEPBACKSLASH@ DEPDIR=$(DEPDIR) $(%FPFX%DEPMODE) $(depcomp) @AMDEPBACKSLASH@ endif %AMDEP% -?-o? %VERBOSE-NODEP%%COMPILE% %-c% %-o% %OBJOBJ% %SOURCEFLAG%`$(CYGPATH_W) $(am__cooked_source_%GENERIC%)` -?!-o? %VERBOSE-NODEP%%COMPILE% %-c% %SOURCEFLAG%`$(CYGPATH_W) $(am__cooked_source_%GENERIC%)` +?-o? %VERBOSE-NODEP%%COMPILE% %-c% %-o% %OBJOBJ% %SOURCEFLAG%`$(CYGPATH_W) $<` +?!-o? %VERBOSE-NODEP%%COMPILE% %-c% %SOURCEFLAG%`$(CYGPATH_W) $<` endif !%FASTDEP% endif %?NONLIBTOOL% @@ -94,8 +87,8 @@ if %?LIBTOOL% if %FASTDEP% %SILENT%$(am__ensure_depdir) ## In fast-dep mode, we can always use -o. - %VERBOSE%%LTCOMPILE% -MT $@ -MD -MP -MF $(am__depbase).Tpo %-c% -o $@ \ - %SOURCEFLAG%$(am__cooked_source_%GENERIC%) + %VERBOSE%%LTCOMPILE% -MT $@ -MD -MP -MF $(am__depbase).Tpo \ + %-c% -o $@ %SOURCEFLAG%$< %SILENT%$(am__mv) $(am__depbase).Tpo $(am__depbase).Plo else !%FASTDEP% if %AMDEP% @@ -104,6 +97,6 @@ if %AMDEP% DEPDIR=$(DEPDIR) $(%FPFX%DEPMODE) $(depcomp) @AMDEPBACKSLASH@ endif %AMDEP% ## We can always use `-o' with Libtool. - %VERBOSE-NODEP%%LTCOMPILE% %-c% -o %LTOBJ% %SOURCEFLAG%$(am__cooked_source_%GENERIC%) + %VERBOSE-NODEP%%LTCOMPILE% %-c% -o %LTOBJ% %SOURCEFLAG%$< endif !%FASTDEP% endif %?LIBTOOL% diff --git a/lib/am/lex.am b/lib/am/lex.am index 7926d74..8036107 100644 --- a/lib/am/lex.am +++ b/lib/am/lex.am @@ -25,8 +25,6 @@ endif %?MAINTAINER-MODE% ?GENERIC?%EXT%%DERIVED-EXT%: ?!GENERIC?%OBJ%: %SOURCE% ?SUBDIROBJ? %SILENT%test -d $(dir $@) || $(MKDIR_P) $(dir $@) -?GENERIC? %VERBOSE%$(am__skiplex) $(SHELL) $(YLWRAP) %SOURCE% $(LEX_OUTPUT_ROOT).c %OBJ% -- %COMPILE% -?!GENERIC? %VERBOSE% \ -?!GENERIC??DIST_SOURCE? $(am__skiplex) \ -## For non-suffix rules, we must emulate a VPATH search on %SOURCE%. -?!GENERIC? $(SHELL) $(YLWRAP) `test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE% $(LEX_OUTPUT_ROOT).c %OBJ% -- %COMPILE% +?GENERIC? %VERBOSE%$(am__skipyacc) \ +?!GENERIC??DIST_SOURCE? %VERBOSE%$(am__skiplex) \ + $(SHELL) $(YLWRAP) $< $(LEX_OUTPUT_ROOT).c %OBJ% -- %COMPILE% diff --git a/lib/am/yacc.am b/lib/am/yacc.am index 4f608b0..1551232 100644 --- a/lib/am/yacc.am +++ b/lib/am/yacc.am @@ -42,8 +42,6 @@ endif %?MAINTAINER-MODE% ?GENERIC?%EXT%%DERIVED-EXT%: ?!GENERIC?%OBJ%: %SOURCE% ?SUBDIROBJ? %SILENT%test -d $(dir $@) || $(MKDIR_P) $(dir $@) -?GENERIC? %VERBOSE%$(am__skipyacc) $(SHELL) $(YLWRAP) %SOURCE% y.tab.c %OBJ% y.tab.h %BASE%.h y.output %BASE%.output -- %COMPILE% -?!GENERIC? %VERBOSE% \ -?!GENERIC??DIST_SOURCE? $(am__skipyacc) \ -## For non-suffix rules, we must emulate a VPATH search on %SOURCE%. -?!GENERIC? $(SHELL) $(YLWRAP) `test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE% y.tab.c %OBJ% y.tab.h %BASE%.h y.output %BASE%.output -- %COMPILE% +?GENERIC? %VERBOSE%$(am__skipyacc) \ +?!GENERIC??DIST_SOURCE? %VERBOSE%$(am__skipyacc) \ + $(SHELL) $(YLWRAP) $< y.tab.c %OBJ% y.tab.h %BASE%.h y.output %BASE%.output -- %COMPILE% diff --git a/tests/list-of-tests.mk b/tests/list-of-tests.mk index ee0edf2..da40dab 100644 --- a/tests/list-of-tests.mk +++ b/tests/list-of-tests.mk @@ -935,6 +935,7 @@ spell2.test \ spell3.test \ spelling.test \ spy.test \ +spy-vpath-rewrite.test \ stdinc.test \ stamph2.test \ stdlib.test \ diff --git a/tests/spy-vpath-rewrite.test b/tests/spy-vpath-rewrite.test new file mode 100755 index 0000000..b5dd589 --- /dev/null +++ b/tests/spy-vpath-rewrite.test @@ -0,0 +1,150 @@ +#! /bin/sh +# Copyright (C) 2012 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Check that the automatic variable '$<' always undergoes VPATH rewrite. +# We use that assumption in some of our rules, so it better explicitly +# check that it truly holds. + +. ./defs || Exit 1 + +ocwd=`pwd` || fatal_ "couldn't get current working directory" + +mkdir src +cd src + +cat > mk <<'END' +.SUFFIXES: +.SUFFIXES: .a .b .a2 .b2 .a3 .b3 .a4 .b4 + +empty = +source = $< + +all: one.b two.b2 three.b3 four.b4 +all: www.d xxx.d2 yyy.d3 zzz.d4 +all: bar/mu.x is.ok zardoz +all: here here2 he/re + +.a.b: + cp $< $@ + +.a2.b2: + cp '$<' $@ + +.a3.b3: + cp $(empty)$<$(empty) $@ + +.a4.b4: + cp $(source) $@ + +%.d: %.c + cp $< $@ + +%.d2: %.c2 + cp '$(source)' $@ + +%.d3: %.c3 %.cc + cp `echo '$<'` $@ + +%.d4: %.c4 ignore-me + orig=x$(<)x && orig=`expr "$$orig" : 'x\(.*\)x$$'` && cp $$orig $@ + +bar/%: foo/% + mkdir $(dir $@) + cp $< $@ + +%.ok: zap/% + cp "$<" $@ + +%: zap/sub/% + cp '$<' $@ + +here: there + cp $< $@ + +here2: there2 ignore-me + cp '$<' $@ + +he/re: the/re + mkdir $(dir $@) + cp "$(source)" $@ +END + +mkdir foo zap zap/sub the +for file in \ + one.a \ + two.a2 \ + three.a3 \ + four.a4 \ + www.c \ + xxx.c2 \ + yyy.c3 \ + zzz.c4 \ + foo/mu.x \ + zap/is \ + zap/sub/zardoz \ + there \ + there2 \ + the/re \ +; do + echo $file > $file +done +touch yyy.cc ignore-me + +do_test () +{ + srcdir=$1 + cp $srcdir/mk Makefile + $MAKE -k all VPATH=$srcdir + if test "$srcdir" != "."; then + test ! -f $srcdir/bar && test ! -d $srcdir/bar || Exit 1 + test ! -f $srcdir/he && test ! -d $srcdir/he || Exit 1 + fi + diff $srcdir/one.a one.b + diff $srcdir/two.a2 two.b2 + diff $srcdir/three.a3 three.b3 + diff $srcdir/four.a4 four.b4 + diff $srcdir/www.c www.d + diff $srcdir/xxx.c2 xxx.d2 + diff $srcdir/yyy.c3 yyy.d3 + diff $srcdir/zzz.c4 zzz.d4 + diff $srcdir/foo/mu.x bar/mu.x + diff $srcdir/zap/is is.ok + diff $srcdir/zap/sub/zardoz zardoz + diff $srcdir/there here + diff $srcdir/the/re he/re +} + +cd "$ocwd" +mkdir build +cd build +do_test ../src + +cd "$ocwd" +mkdir build2 +cd build2 +do_test "$ocwd"/src + +cd "$ocwd" +cd src +mkdir build +cd build +do_test .. + +cd "$ocwd" +cd src +do_test . + +: -- 1.7.7.3