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 $< $@