>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