[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Issue with order-only-prerequisites on pattern rule
From: |
Paul Smith |
Subject: |
Re: Issue with order-only-prerequisites on pattern rule |
Date: |
Thu, 28 May 2020 14:22:55 -0400 |
On Thu, 2020-05-28 at 19:34 +0200, Juan Pablo Garibotti Arias wrote:
> $(build_dir)%.o : src/%.cpp | $(dir $(build_dir)%)
This cannot work because of the way make reads makefiles.
See: https://www.gnu.org/software/make/manual/html_node/Reading-Makefiles.html
Variables etc. are expanded when the makefile is read in, but in
pattern rules the patterns are not replaced until the second stage,
when make is trying to actually build targets (how can make know, when
it's parsing the makefile, what to replace % with?)
It's not that % is replaced with nothing, it's that make expands the
literal value % which is tossed out by the $(dir ...) function.
One way to do this is with secondary expansion:
https://www.gnu.org/software/make/manual/html_node/Secondary-Expansion.html
which would be something like:
.SECONDEXPANSION:
$(build_dir)%.o : src/%.cpp | $$(@D)
$(CXX) $< -c -o $@