On 2025-04-30 10:29, Paul Smith wrote: > Hi Marek! Please choose just onee mailing list to ask your question, > rather than sending it to multiple lists. Either one would be > appropriate for this question IMO. > > > On Wed, 2025-04-30 at 12:15 +0000, Marek Küthe wrote: >> I am currently taking a closer look at the `patsubst` function in >> `make`. The documentation [1] says >> > Whitespace between words is folded into single space characters; >> > leading and trailing whitespace is discarded. > > I believe that was trying to discuss whitespace etc. within the pattern > words, not within the to-be-substituted text. But, it doesn't even > work there. > > I think you should ignore that paragraph in the documentation and > pretend it's not there. I have no idea what it really refers to.
Isn't it just this? Makefile: $(info $(patsubst %.c,%.o,lexer.c parser.c main.c \ )) Output: lexer.o parser.o main.o If I change it to $(patsubst ,,lexer.c ....) the whitespace is preserved. It seems to be as if patsubst decides that there is nothing to do at all. Furthermore, $(info $(patsubst ,X,lexer.c parser.c main.c \ )) $ make lexer.c parser.c main.c X The behavior seems to be that the input is considered to have an empty word at the end. An empty pattern matches this empty word. A replacement not using the % stem preserves trailing space: $(info $(patsubst lexer.c,scanner.c,lexer.c parser.c main.c \ )) $ make scanner.c parser.c main.c If we replace a word in the middle, neither leading nor trailing spaces are eliminated: $(info $(patsubst parser.c,grammar.c,lexer.c parser.c main.c \ )) $ make lexer.c grammar.c main.c The whitespace flossing seems to occur only when using stem-driven patterns, even for the words which don't match the pattern: $(info $(patsubst parser.%,grammar.%,lexer.c parser.c main.c \ )) $ make lexer.c grammar.c main.c I would say it's a bug. In a world in which we don't care about backward bug compatibility, we probably want these requirements: - patsubst should in all cases squeeze out spaces, even around words that don't match the pattern, whether or not it is a stem pattern or not. - an empty pattern should not match anything; there is no such thing as an empty word.
