When I look all over the place for a simple thing and can't find it, it makes me wonder whether I'm doing something completely the wrong way. I have used frameworks where you type make targetname
where targetname
is not known by the makefile, so it has to pick up targetname
as a makefile variable and figure out its dependencies from there. I'm trying to do that, but I can't figure out how, and apparently no one does this, because I can't find anyone talking about how to do it. They talk about everything else under the sun, but not how to get make hooplah
to execute using hooplah.html
as the top-level target.
A lot of searching and guessing has gotten me as far as the failing makefile below, and I'm so frustrated that here I am risking life and limb by asking a question on SO. In case it keeps me from harm, I'll mention that I've read this SO answer, and this, this, and this, as well as digging through a number of pages in the GNU makefile documentation, all to no avail.
I want to type make page-72
on the command line and get make to treat page-72.html
as its top-level dependency throughout the makefile, not just in the top-level rule. The other rules need to know about page-72.html
, but I can't figure out how to give them the information.
I've read about MAKECMDGOALS
, but it looks like that's only useful for checking for specific target names; I'm looking for something that will allow any target name and treat it as an output filename. Below is what I have. It shows me page-72
due to the %
target, and the $@.html
dependency works, but no variable I have found yet allows the $@.html
rule to know the name of the target that was specified on the command line.
%: $@.html
@echo "Top: dollar-at = $@"
$@.html:
@echo "html: $@, $%, $<, $?, $^, $+, $|, $*"
I get the following output:
html: .html, , , , , , ,
Top: dollar-at = makefile
Top: dollar-at = index
Am I getting this conceptually wrong? Is it just not done this way? Bonus points if anyone can help me get rid of Top: dollar-at = makefile
. Cheers