>From d7c8a35e2bd9bcab2718427636d41b3734c351b2 Mon Sep 17 00:00:00 2001 From: Peter Rosin
Date: Wed, 23 Jan 2013 15:34:03 +0100 Subject: [PATCH] curdir: add support for relative names in included fragments Suggested by Bob Friesenhahn, and later discussed in bug #13524. automake.in (read_am_file): Add third argument specifying the relative directory of this makefile fragment compared to the main makefile. Replace &{CUR/DIR}& and &{CUR_DIR}& in the fragment with this relative directory (with slashes etc, or canonicalized). (read_main_am_file): Adjust. t/curdir.sh: New test. t/list-of-tests.mk: Augment. --- automake.in | 30 ++++++++++++++++++--- t/curdir.sh | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ t/list-of-tests.mk | 1 + 3 files changed, 99 insertions(+), 5 deletions(-) create mode 100755 t/curdir.sh diff --git a/automake.in b/automake.in index 0e3b882..9c9f41d 100644 --- a/automake.in +++ b/automake.in @@ -6330,15 +6330,15 @@ sub check_trailing_slash ($\$) } -# &read_am_file ($AMFILE, $WHERE) -# ------------------------------- +# &read_am_file ($AMFILE, $WHERE, $CURDIR) +# ---------------------------------------- # Read Makefile.am and set up %contents. Simultaneously copy lines # from Makefile.am into $output_trailer, or define variables as # appropriate. NOTE we put rules in the trailer section. We want # user rules to come after our generated stuff. sub read_am_file ($$) { - my ($amfile, $where) = @_; + my ($amfile, $where, $curdir) = @_; my $am_file = new Automake::XFile ("< $amfile"); verb "reading $amfile"; @@ -6423,6 +6423,21 @@ sub read_am_file ($$) my $new_saw_bk = check_trailing_slash ($where, $_); + if ($curdir ne '.') + { + my $cur_dir = &canonicalize ($curdir); + $_ =~ s/&\{CUR\/DIR\}&/${curdir}/g; + $_ =~ s/&\{CUR_DIR\}&/${cur_dir}/g; + } + else + { + # If present, eat the following '_' or '/', converting + # "&{CUR/DIR}&/foo" and "&{CUR_DIR}&_foo" into plain "foo" + # when $curdir is '.'. + $_ =~ s/&\{CUR([_\/])DIR\}&\1//g; + $_ =~ s/&\{CUR[_\/]DIR\}&/${curdir}/g; + } + if (/$IGNORE_PATTERN/o) { # Merely delete comments beginning with two hashes. @@ -6584,8 +6599,13 @@ sub read_am_file ($$) push_dist_common ("\$\(srcdir\)/$path"); $path = $relative_dir . "/" . $path if $relative_dir ne '.'; } + my $new_curdir = $path; + if ($new_curdir !~ s,/[^/]*$,,) + { + $new_curdir = '.'; + } $where->push_context ("'$path' included from here"); - &read_am_file ($path, $where); + &read_am_file ($path, $where, $new_curdir); $where->pop_context; } else @@ -6658,7 +6678,7 @@ sub read_main_am_file ($$) &define_standard_variables; # Read user file, which might override some of our values. - &read_am_file ($amfile, new Automake::Location); + &read_am_file ($amfile, new Automake::Location, '.'); } diff --git a/t/curdir.sh b/t/curdir.sh new file mode 100755 index 0000000..e2251dc --- /dev/null +++ b/t/curdir.sh @@ -0,0 +1,73 @@ +#! /bin/sh +# Copyright (C) 2013 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