3 ms·
If anyone (the author or anyone else!) wants to demonstrate their make-fu, here is a very subtle issue I ran into with make that I never did get to the bottom o
by haberman 12y ago
If anyone (the author or anyone else!) wants to demonstrate their make-fu, here is a very subtle issue I ran into with make that I never did get to the bottom of.
http://stackoverflow.com/questions/25589586/why-does-patsubst-stop-working-when-using-secondary-expansion-of http://stackoverflow.com/questions/25589586/why-does-patsubs...
Someone pretty knowledgable chimed in, but we were both stumped. In the end I found a workaround, but never did get to the bottom of this peculiar behavior.
- deleted 12y ago[deleted]
- ploxiln 12y agoThe confirmed answer looks correct to me. I think your last comment on it is also correct. The example from the GNU Make manual for SECONDEXPANSION uses patsubst but is not a pattern rule. You tried to use it with a pattern rule, but then the pattern rule interfered with the % in the patsubst, replacing it before the second expansion, which is when the patsubst ran. All that said... you could probably re-architect your Makefile a bit to make it simpler. I bit more verbosity might be worth it to avoid SECONDEXPANSION tricks.
- LukeShu 12y ago> EDIT: I had a theory that the % characters inside the patsubst > were getting evaluated early, using the stem match (foo), so > that the patsubst itself was looking something like this: > > $(patsubst foo.c,foo.o,bar.c baz.c) That is what happened. The answer on SO explains how to work around it. > To test this theory, I added a file called foo.c to foo_SRCS: ... > That resulted in something even weirder: > make: *** No rule to make target `foo.a', needed by `all'. Stop. Which resulted in Make seeing the line as %.a: %.o bar.c baz.c Now, Make will only choose to use a pattern rule if it knows how to make all of the prerequisites. If Make doesn't know how to make foo.o (which it wouldn't if you don't have an actual file named foo.c), then it won't even consider the rule as a possibility to make foo.a.