$(wildcard pattern-without-glob-chars) broken (Re: make ChangeLog read.c)

Kirill Smelkov <[email protected]>
Newsgroups gmane.comp.gnu.make.bugs,gmane.comp.gnu.make.devel
Organization Marine Bridge & Navigation Systems
Message-ID <[email protected]>
On Mon, May 02, 2011 at 12:18:06AM +0000, Paul D. Smith wrote:
> CVSROOT:	/sources/make
> Module name:	make
> Changes by:	Paul D. Smith <psmith>	11/05/02 00:18:06
> 
> Modified files:
> 	.              : ChangeLog read.c 
> 
> Log message:
> 	Avoid invoking glob() unless the filename has potential globbing
> 	characters in it, for performance improvements.
> 
> CVSWeb URLs:
> http://cvs.savannah.gnu.org/viewcvs/make/ChangeLog?cvsroot=make&r1=2.428&r2=2.429
> http://cvs.savannah.gnu.org/viewcvs/make/read.c?cvsroot=make&r1=1.198&r2=1.199

This change seems to be breaking how $(wildcard) works for patterns
without glob characters.

For example, I used to check wheter a file exists with

    ifneq ($(wildcard path/to/file),)
        $(info path/to/file exists)
    endif


but now this is triggering all the time, because wildcards does not see
glob characters in the pattern, decides to avoid globbing it,
and just leaves path/to/file in place.

And this seems to be going in contrary with what make's manual says:

---- 8< ----
    @example
    $(wildcard @var{pattern}@dots{})
    @end example
    
    @noindent
    This string, used anywhere in a makefile, is replaced by a
    space-separated list of names of existing files that match one of the
    given file name patterns.  If no existing file name matches a pattern,
    then that pattern is *omitted* from the output of the @code{wildcard}
    function.  Note that this is different from how unmatched wildcards
    behave in rules, where they are used verbatim rather than ignored
    (@pxref{Wildcard Pitfall}).
---- 8< ----

(emphasis added)


This example from the manual

---- 8< ----
    This one is slightly more interesting: it defines a macro to search for
    the first instance of a program in @code{PATH}:
    
    @smallexample
    pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH)))))
    
    LS := $(call pathsearch,ls)
    @end smallexample
---- 8< ----

is now broken too, because LS will return first directory from path + ls
regardless of whether ls is there. Try it:

---- 8< ----
    PATH    := /aaa/bbb:$(PATH)
    pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH)))))
    
    LS := $(call pathsearch,ls)
    $(info XXX $(LS))
---- 8< ----



Maybe we should turn globbing on for $(wildcard) unconditionally?


Thanks,
Kirill
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.