[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Change a target within Makefile?
From: |
Taylor Hutt |
Subject: |
Re: Change a target within Makefile? |
Date: |
Wed, 24 Jul 2024 06:08:16 -0700 |
> 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.
<snip>
> 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
>
As you have a specific flag, you can make 'x.a' dependent on a
conditionalized version of x.b. The example below makes a simple
mapping to conditionally include 'x.b' in the prerequisites of 'x.a'
based on the value of 'GENERATE_B_AS_WELL'.
_MAP_x_b_1 := x.b
_MAP_x_b_0 :=
x.b:
@echo "$@ is up-to-date";
x.a: $(_MAP_x_b_$(GENERATE_B_AS_WELL))
@echo "$@ is up-to-date";
It is left as an excercise in robustness to ensure
'GENERATE_B_AS_WELL' is always in {0, 1}.
On Wed, Jul 24, 2024 at 4:35 AM Paul Smith <psmith@gnu.org> wrote:
> 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 $< $@
>
>
--
This electronic communication and the information and any files transmitted
with it, or attached to it, are confidential and are intended solely for
the use of the individual or entity to whom it is addressed and may contain
information that is confidential, legally privileged, protected by privacy
laws, or otherwise restricted from disclosure to anyone else. If you are
not the intended recipient or the person responsible for delivering the
e-mail to the intended recipient, you are hereby notified that any use,
copying, distributing, dissemination, forwarding, printing, or copying of
this e-mail is strictly prohibited. If you received this e-mail in error,
please return the e-mail to the sender, delete it from your computer, and
destroy any printed copy of it.