From: Stefano Lattarini Date: Tue, 31 Jan 2012 19:37:16 +0000 (+0100) Subject: [ng] vpath: define generic make function for VPATH rewrites X-Git-Tag: ng-0.5a~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a6a7de012b649535a9b88640b370bd4baa942742;p=thirdparty%2Fautomake.git [ng] vpath: define generic make function for VPATH rewrites This change generalizes and makes available to all the Automake generated Makefiles a common idiom dealing with VPATH rewrites. This idiom was introduced in recent commits (see in particular 'v1.11-1835-gcf93724'). * lib/am/depend2.am (am__vpath_rewrite): Move ... * lib/am/header-vars.am: ... here. * tests/vpath-rewrite.test: New test. * tests/list-of-tests.mk: Add it. --- diff --git a/lib/am/depend2.am b/lib/am/depend2.am index 59dd90e88..df5db1ef5 100644 --- a/lib/am/depend2.am +++ b/lib/am/depend2.am @@ -43,10 +43,6 @@ am__depbase = $(am__depdir)/$(basename $(notdir $@)) ## Avoid useless forks when possible. am__ensure_depdir = test -d $(am__depdir) || $(MKDIR_P) $(am__depdir) -## Emulate VPATH rewrites. This only uses GNU make primitives, which -## allows us to avoid extra forks. -am__vpath_rewrite = $(firstword $(wildcard $(strip $(1))) $(srcdir)/$(strip $(1))) - ## Used for suffix rules. am__cooked_source_0 = $(call am__vpath_rewrite, $<) ## Used for explicit rules. diff --git a/lib/am/header-vars.am b/lib/am/header-vars.am index f4124706f..425a6b236 100644 --- a/lib/am/header-vars.am +++ b/lib/am/header-vars.am @@ -17,6 +17,11 @@ VPATH = @srcdir@ +## Emulate VPATH rewrites. This uses only GNU make primitives, which +## allows us to avoid extra forks. +am__vpath_rewrite = \ + $(firstword $(wildcard $(strip $(1))) $(srcdir)/$(strip $(1))) + ## We used to define this. However, we don't because vendor makes ## (e.g., Solaris, Irix) won't correctly propagate variables that are ## defined in Makefile. This particular variable can't be correctly diff --git a/tests/list-of-tests.mk b/tests/list-of-tests.mk index d59086885..77f0d0090 100644 --- a/tests/list-of-tests.mk +++ b/tests/list-of-tests.mk @@ -1154,6 +1154,7 @@ version6.test \ version7.test \ version8.test \ vpath.test \ +vpath-rewrite.test \ vtexi.test \ vtexi2.test \ vtexi3.test \ diff --git a/tests/vpath-rewrite.test b/tests/vpath-rewrite.test new file mode 100755 index 000000000..0b4323657 --- /dev/null +++ b/tests/vpath-rewrite.test @@ -0,0 +1,100 @@ +#! /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 . + +# Test Automake-provided internal make macros to deal with VPATH rewrites. + +. ./defs || Exit 1 + +echo AC_OUTPUT >> configure.in + +cat > Makefile.am << END +bsub: + mkdir \$@ +bsub/foo: bsub + mkdir \$@ +bsub/foo/bar: bsub/foo + mkdir \$@ +bsub/mu.c++: bsub/foo + touch \$@ +bsub/foo/pu.cxx: bsub/foo + touch \$@ + +clean-local: + rm -rf bsub + +## Yes, I'm a lazy typist. +vr = \$(am__vpath_rewrite) + +test-common: bsub/foo/bar bsub/mu.c++ bsub/foo/pu.cxx + test '\$(call vr,Makefile)' = Makefile + test '\$(call vr,$tab config.status )' = config.status + test '\$(call vr,.)' = . +## FIXME: These two do not work apparently :-( Such use cases are not +## FIXME: required presently though, so this is not a big deal. + : test '\$(call vr, bsub$tab )' = bsub + : test '\$(call vr,bsub)' = bsub + test '\$(call vr,bsub/.)' = bsub/. + test '\$(call vr,bsub/mu.c++)' = bsub/mu.c++ + test '\$(call vr,bsub/foo/pu.cxx)' = bsub/foo/pu.cxx + test '\$(call vr,bsub/foo )' = bsub/foo + test '\$(call vr,bsub/foo/bar)' = bsub/foo/bar + test '\$(call vr,nonesuch)' = \$(srcdir)/nonesuch + test '\$(call vr, $tab nonesuch2 )' = \$(srcdir)/nonesuch2 + test '\$(call vr, sub/none)' = \$(srcdir)/sub/none + +test-vpath: test-common + test '\$(call vr,ssub)' = \$(srcdir)/ssub + test '\$(call vr,ssub/foo )' = \$(srcdir)/ssub/foo + test '\$(call vr, ssub/foo/bar)' = \$(srcdir)/ssub/foo/bar + test '\$(call vr,Makefile.in )' = \$(srcdir)/Makefile.in + test '\$(call vr,zap/paz.c)' = \$(srcdir)/zap/paz.c + test '\$(call vr,configure $tab)' = \$(srcdir)/configure + test '\$(call vr, configure.in$tab )' = \$(srcdir)/configure.in + +test-intree: test-common + test '\$(call vr,ssub)' = ssub + test '\$(call vr,ssub/foo )' = ssub/foo + test '\$(call vr, ssub/foo/bar)' = ssub/foo/bar + test '\$(call vr,Makefile.in )' = Makefile.in + test '\$(call vr,zap/paz.c)' = zap/paz.c + test '\$(call vr,configure $tab)' = configure + test '\$(call vr, configure.in$tab )' = configure.in +END + +$ACLOCAL +$AUTOMAKE +$AUTOCONF + +mkdir zap ssub ssub/foo ssub/foo/bar +: > zap/paz.c + +./configure +$MAKE test-intree +$MAKE distclean + +mkdir build +cd build +../configure +$MAKE test-vpath +cd .. + +ocwd=`pwd` || fatal_ "couldn't get current working directory" +mkdir build2 build2/subbuild +cd build2/subbuild +"$ocwd"/configure +$MAKE test-vpath + +: