From 52ae0782814a75d29276fbcdba21d4d3dfcb04f9 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Sat, 27 Dec 2003 01:38:54 +0000 Subject: [PATCH] * automake.in (maybe_push_required_file): Add $(srcdir) in front a required files outside the current directory or its subdirectories. * lib/am/distdir.am (distdir): Update comment. Report from Nicolas Joly. --- ChangeLog | 7 +++++++ automake.in | 52 +++++++++++++++++++++++++++++++++++++++++----------- lib/am/distdir.am | 28 +++++++++++++++++++++------- 3 files changed, 69 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1b1c80272..b85a49084 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2003-12-27 Alexandre Duret-Lutz + + * automake.in (maybe_push_required_file): Add $(srcdir) in front + a required files outside the current directory or its subdirectories. + * lib/am/distdir.am (distdir): Update comment. + Report from Nicolas Joly. + 2003-12-26 Alexandre Duret-Lutz * doc/automake.texi (@copying): Do not repeat the version. diff --git a/automake.in b/automake.in index 26e3bd3fa..194c6f6e6 100755 --- a/automake.in +++ b/automake.in @@ -6434,22 +6434,52 @@ my @require_file_paths = (); # encodes the rules for deciding when to do so. sub maybe_push_required_file { - my ($dir, $file, $fullfile) = @_; + my ($dir, $file, $fullfile) = @_; - if ($dir eq $relative_dir) + if ($dir eq $relative_dir) { - push_dist_common ($file); - return 1; + push_dist_common ($file); + return 1; } - elsif ($relative_dir eq '.' && ! &is_make_dir ($dir)) + elsif ($relative_dir eq '.' && ! &is_make_dir ($dir)) { - # If we are doing the topmost directory, and the file is in a - # subdir which does not have a Makefile, then we distribute it - # here. - push_dist_common ($fullfile); - return 1; + # If we are doing the topmost directory, and the file is in a + # subdir which does not have a Makefile, then we distribute it + # here. + + # If a required file is above the source tree, it is important + # to prefix it with `$(srcdir)' so that no VPATH search is + # performed. Otherwise problems occur with Make implementations + # that rewrite and simplify rules whose dependencies are found in a + # VPATH location. Here is an example with OSF1/Tru64 Make. + # + # % cat Makefile + # VPATH = sub + # distdir: ../a + # echo ../a + # % ls + # Makefile a + # % make + # echo a + # a + # + # Dependency `../a' was found in `sub/../a', but this make + # implementation simplified it as `a'. (Note that the sub/ + # directory does not even exist.) + # + # This kind of VPATH rewriting seems hard to cancel. The + # distdir.am hack against VPATH rewriting works only when no + # simplification is done, i.e., for dependencies which are in + # subdirectories, not in enclosing directories. Hence, in + # the latter case we use a full path to make sure no VPATH + # search occurs. + $fullfile = '$(srcdir)/' . $fullfile + if $dir =~ m,^\.\.(?:$|/),; + + push_dist_common ($fullfile); + return 1; } - return 0; + return 0; } diff --git a/lib/am/distdir.am b/lib/am/distdir.am index 2ffe9bbc1..0671a4843 100644 --- a/lib/am/distdir.am +++ b/lib/am/distdir.am @@ -64,19 +64,21 @@ endif %?TOPDIR_P% ## Yet another hack to support SUN make. ## ## Let's assume `foo' appears in DISTFILES and is not a built file. -## When building with VPATH=$(srcdir), SUN make will rewrite `foo' as -## `$(srcdir)/foo'. An attempt to install the file with +## When building with VPATH=$(srcdir), SUN make and OSF1/Tru64 will +## rewrite `foo' as `$(srcdir)/foo'. An attempt to install the file +## with ## cp $file $(distdir)/$file ## will thus install $(srcdir)/foo as $(distdir)/$(srcdir)/foo ## instead of $(distdir)/foo. ## ## So let's strip this leading $(srcdir)/ when it exists. (As far we -## know, only SUN make adds it.) Searching whether the file is to be -## found in the source or build directory will be done latter. +## know, only SUN make and OSF1/Tru64 make add it.) Searching whether +## the file is to be found in the source or build directory will be +## done latter. ## -## In case we are _not_ using SUN make, how can we be sure we are -## not stripping a legitimate filename that starts with the same -## pattern as $(srcdir)? +## In case we are _not_ using SUN or OSF1/Tru64 make, how can we be sure +## we are not stripping a legitimate filename that starts with the +## same pattern as $(srcdir)? ## Well, it can't happen without the Makefile author distributing ## something out of the distribution (which is bad). As an example, ## consider `EXTRA_DIST = ../bar'. This is an issue if $srcdir is `..', @@ -84,6 +86,18 @@ endif %?TOPDIR_P% ## implies we are in a subdirectory (so `../bar' is within the package), ## hence `$srcdir' is something like `../../subdir'. ## +## There is more to say about files which are above the current directory, +## like `../bar' in the previous example. The OSF1/Tru64 make +## implementation can simplify filenames resulting from a VPATH lookup. +## For instance if `VPATH = ../../subdir' and `../bar' is found in that +## VPATH directory, then occurrences of `../bar' will be replaced by +## `../../bar' (instead of `../../subdir/../bar'). This obviously defeats +## any attempt to strip a leading $srcdir. Presently we have no workaround +## for this. We avoid this issue by writing `EXTRA_DIST = $(srcdir)/../bar' +## instead of `EXTRA_DIST = ../bar'. This prefixing is needed only for files +## above the current directory. Fortunately, apart from auxdir files which +## can be located in .. or ../.., this situation hardly occurs in practice. +## case $$file in \ $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ ## Also rewrite $(top_srcdir) (which sometimes appears in DISTFILES, and can -- 2.11.4.GIT