Re: Change a target within Makefile?

Paul Smith <[email protected]> Wed, 24 Jul 2024 07:34:22 -0400
Newsgroups gmane.comp.gnu.make.general
Organization GNU's Not UNIX!
Message-ID <[email protected]>
On Wed, 2024-07-24 at 18:44 +0900, Masahiro Yamada wrote:
> ifdef GENERATE_B_AS_WELL
> # When this flag is set, we want to generate %.b as well.
> # I know I cannot update MAKECMDGOALS...
> MAKECMDGOALS := $(patsubst %.a, %.b, $(MAKECMDGOALS))
> endif
> 
> 
> %.a:
>         touch
> 
> %.b: %.a
>         cp $< $@

> Then, I hope the following would happen.
> 
> 
> $ make x.a
>    -> create x.a
> 
> 
> $ make x.a GENERATE_B_AS_WELL=1
>    -> create x.b as well as x.a


Your example output cannot be generated by this makefile, so it's
confusing as to what exactly you want to happen.

However, doesn't something like this work:

    a_prereq =
    ifdef GENERATE_B_AS_WELL
    a_prereq = %.b
    endif

    %a: $(a_prereq)
            touch $@

    %.b: %.a
            cp $< $@