On 2024-07-24 02:44, Masahiro Yamada wrote:
> Hi.
> 
> My question is very similar to this:
> https://stackoverflow.com/questions/31443920/remove-target-from-makecmdgoals
> 
> When a particular flag is set, I want to do something extra.
> I know this is hard, but please forgive me to repeat a similar question
> in case somebody in the list may know something.

By the way, why is it necessary to have a variable for this,
and not a target?

The only difference between

  make foo bar
  make foo MAKE_BAR_ALSO=y

is that we have an argument which contains =.  Do we need this solution
because we are fond of the syntax?

Make already has a solution for "what blurb can I put on the
command line to have another target built also". The syntax of make
is such that a variable assignment cannot easily be that blurb.

You have to work from the language up; don't have a favorite syntax
and insist that it be bent into doing the job. Ask how the tool
can do the job, and use that syntax.

The variable provides abstraction in that we don't know
exactly what extra target or targets get built.

But an actual target name provides equivalent abstraction, due
to the existence of phony targets. "make install" doesn't literally
check and build a file called "install".

  .PHONY: bar
  bar: real-bar

  real:bar: ...
         recipe

Furthermore, if we need Makefile variable to be set to y
if bar has been specified as a target, that's easy to do:

  bar_is_a_target=$(if $(filter bar,$(MAKECMDGOALS)),y)

Thus "bar" being present in or absent from the command line
serves as a good enough flag.

Reply via email to