----- Original Message -----
> From: "Paul Smith" <psm...@gnu.org>
> To: "Renaud Pacalet" <renaud.paca...@telecom-paris.fr>, help-make@gnu.org
> Sent: Thursday, May 29, 2025 2:59:04 PM
> Subject: Re: patsubst strange behavior when substituting the empty string

> On Thu, 2025-05-29 at 09:43 +0200, Renaud Pacalet wrote:
>> I recently observed a strange `patsubst` behavior when substituting
>> the empty string:
>> 
>> ```
>> $ cat Makefile
>> 
>> .PHONY: all
>> all:;
>> $(info $(patsubst %.,,1.2))
>> 
>> $ make
>> 1.2
>> make: Nothing to be done for 'all'.
>> ```
>> 
>> I read the manual twice but I cannot explain this behavior. What did
>> I miss?
> 
> When using patsubst the pattern must match the _entire_ word.  If the
> pattern doesn't match the word, then the word is not changed.
> 
> Here, "%." does not match the word "1.2".  It would work if you used
> "%.2" as the pattern, like:
> 
>  $ echo '$(info $(patsubst %.2,2,1.2))' | make -f-
>  2
>  make: *** No targets.  Stop.
> 
> 
> If it were possible to have multiple match characters then you could do
> something like "%.%" but that is not possible.
> 
> Without knowing what you're actually trying to do, I can't suggest an
> alternative that might work for you.

Ah, I forgot the _entire_ word part. The alternative is probably a combination 
of `subst` and `word`: `$(word 2,$(subst ., ,1.2))`. Thanks a lot Paul.
-- 
Renaud Pacalet
Télécom Paris
Campus SophiaTech
450 Route des Chappes, CS 50193
06904 Biot Sophia Antipolis cedex, FRANCE
Tel : +33 (0) 4 9300 8402
Web : http://www.telecom-paris.fr/

Reply via email to