Eric Blake | 2 Mar 2012 14:53
Picon
Favicon
Gravatar

bug in $(wildcard) with trailing slash

Make fails to restrict output to just directories when a wildcard
contains both a trailing slash and internal slashes, even though it does
the right thing with no internal slashes.

$ mkdir /tmp/example
$ cd /tmp/example/
$ touch a
$ mkdir b
$ printf 'all:\n\t <at> echo $(wildcard */)' | make -f -
b/
$ printf 'all:\n\t <at> echo $(wildcard ./*/)' | make -f -
./b/ ./a

Both invocations should have omitted a, since the trailing slash cannot
match a non-directory (other than a symlink to a directory).

$ make --version | head -n2
GNU Make 3.82
Built for x86_64-redhat-linux-gnu

I encountered this while writing a macro for libvirt; as a workaround, I
ended up using a trailing /. to force just directories, then using
$(patsubst) to strip things back to what I wanted in the first place.

cross_dirs=$(patsubst $(srcdir)/src/%.,%,$(wildcard $(srcdir)/src/*/.))

--

-- 
Eric Blake   eblake <at> redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

(Continue reading)

Eric Blake | 2 Mar 2012 14:56
Picon
Favicon
Gravatar

Re: bug in $(wildcard) with trailing slash

On 03/02/2012 06:53 AM, Eric Blake wrote:
> Make fails to restrict output to just directories when a wildcard
> contains both a trailing slash and internal slashes, even though it does
> the right thing with no internal slashes.

Sorry about that; I meant bug-make, but my mailer autocompleted to the
wrong list.

--

-- 
Eric Blake   eblake <at> redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


Gmane