Bug 285726 - make: AT&T/SysV-style substitution error if the pattern starts with 't'
Summary: make: AT&T/SysV-style substitution error if the pattern starts with 't'
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 14.2-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-03-28 13:47 UTC by Tavian Barnes
Modified: 2025-03-31 00:42 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tavian Barnes 2025-03-28 13:47:25 UTC
The ${VAR:pattern%.o=replacement%.c} variable modifier syntax is very useful for portable makefiles because GNU make supports the same syntax.  But I just noticed a bug: if the pattern starts with 't', make prints an error rather than performing the substitution.  I think the parser is looking for one of the :t modifiers (:tl, :tu, etc.)

$ cat Makefile
foo:
	@echo ${@:f%=b%}
test:
	@echo ${@:t%=b%}
$ make foo
boo
$ make test
make: Bad modifier ":t%=b%" for variable "@"
=b%}
Comment 1 Simon J. Gerraty freebsd_committer freebsd_triage 2025-03-28 18:08:14 UTC
A sysV style modifier can be mistaken for any of bmake's other modifiers,
a possible tweak to address this has collateral fallout - needs to be assessed.
Comment 2 Tavian Barnes 2025-03-28 18:32:18 UTC
> A sysV style modifier can be mistaken for any of bmake's other modifiers,
> a possible tweak to address this has collateral fallout - needs to be assessed.

True, I see that ${@:M%=b%} treats `%=b%` as a pattern rather than doing the substitution.

That's a pretty gnarly ambiguity.  At least the :t ones could look ahead for an `=` or something, but something like this looks impossible to me:

    ${@:S/%.c=O/%/g}

Is that

    S / %.c=O / % /g

or

    S/%.c = O/%/g

?
Comment 3 Simon J. Gerraty freebsd_committer freebsd_triage 2025-03-31 00:42:10 UTC
The next version of bmake (>= 20250330) will allow sysV style modifiers to take precedence in POSIX mode (ie. first non-comment line in the Makefile is `.POSIX:`)
This is about the only sane way to expect random sysV modifiers to work as expected.