On Saturday 09 April 2011, Ralf Wildenhues wrote: > Hi Stefano, > > * Stefano Lattarini wrote on Sat, Apr 09, 2011 at 11:38:47AM CEST: > > On Friday 08 April 2011, Ralf Wildenhues wrote: > > > * Stefano Lattarini wrote on Fri, Apr 08, 2011 at 01:05:53PM CEST: > > > > On Wednesday 06 April 2011, Ralf Wildenhues wrote: > > > > > > + # makedepend may prepend the VPATH from the source file name to > > > > > the object. > > > > > + sed_object_re=`echo $object | sed 's/[].[^$\\*|]/\\\\&/g'` > > > > > > > > > A couple of questions/observations about the sed command: > > > > 1. I wasn't sure whether `.', `$', `^' and `*' are to be escaped when > > > > used in > > > > a bracket expression; however, the POSIX standard at: > > > > <http://pubs.opengroup.org/onlinepubs/007908799/xbd/re.html> > > > > says they shouldn't be. Also, I couldn't find any reference in the > > > > Autoconf manual pointing to a sed implementation that doesn't > > > > respect > > > > this part of the standard. > > > > > > Ah, cool. Then I recon we don't need this escaping step at all. > > > > > Why not? The sed command below: > > sed "s|^.*\($sed_object_re *:\)|\1|" "$tmpdepfile" > "$depfile" > > doesn't use any bracket, does it? > > I'm not sure I understand the question. Can you rephrase it? > > > but I don't see how it's related to my observation above. > > What am I missing? > > I guess then I don't understand your observation then. Your observation > tells me that object file names of the form foo^bar.o and foo$baz.o are > not problematic. > No. It just tells that sed regular expressions like [ab.^$0-9] are not problematic, because `.' and `$' are *not* recognized as metacharacters in *bracket expression*, and `^' is recognized as a metacharacter in a bracket expression only when used as *first* character there. Which simply means that your original command: sed_object_re=`echo $object | sed 's/[].[^$\\*|]/\\\\&/g'` was fully correct, and didn't lack any required escaping (while, on the first impression, I had *erronously* thought it did).
But re-reading what I wrote in my first reply, I must admit it sounded like I was adding something new to the discussion, while in fact I was just saying "hey, at first I wasn't sure that this change of yours was correct, but by reading the standards/manuals more carefully, I realized you are indeed completely right". Miscommunication on my part -- sorry for the noise and the time I made us loose. > > > The only character I was worried about was $, as it can occur in > > > object names now and then (ok, mostly java, and that doesn't use > > > depcomp). Any others in the list are pretty much excluded anyway, > > > because they will evoke shell expansion errors when used in a > > > makefile unquoted. Except for '.', but I'm not afraid of matching > > > a bit too broadly here, the final 'o' will take care that we don't > > > match any header files. > > > > > OK, this makes sense (even if I'd err on the safe side w.r.t. the `.' > > character), > > OK, can you come up with a practical example (i.e., a valid object file > name) where we would match something wrongly here? > Pratical examples? No, I'm just being a little paranoid (as usual). Well, too much paranoid this time: see below. > Remember the input > file only contains lines of the form > $object: header header... > $object: header \ > header header... > While somebody might arguably name their header foo.o, I do think they > deserve what they get. > Agreed. Especially because, to cause a spurious match, they would have to *also* have a `:' character in the header name, i.e., have an header named like "foo.o:bar.h" or "foo.obj:bar.h" -- in which case they probably do deserve to suffer a bit. > I observe that no one in their right mind names their > object foo[bar.o or foo]bar.o or foo\bar.o (see the various instspc* > tests for why they would not work in practice anyway). So I conclude > that it is not needed to do regex-escaping for the object file name. > OK, fully agreed now (well, once the possible problems with `$' and `^' have been cleared up). > > > @@ -503,7 +503,8 @@ makedepend) > > > touch "$tmpdepfile" > > > ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" > > > rm -f "$depfile" > > > - cat < "$tmpdepfile" > "$depfile" > > > + # makedepend may prepend the VPATH from the source file name to the > > > object. > > > > > I'd add a comment here telling why there's no need to escape $object for the > > sed commmand just below. > > I will, after I've understood your remaining comments. > Hope this reply is clearer than the previous ones. Thanks, Stefano