1

I want to use multiple % in my Makefile. Something kind of build-%-%, is that possible to do? Here is a sample of what I would like to create:

SETA = cmd1 cmd2
SETB = amd64 arm

all: push

push: $(addprefix sub-push-,$(SETA))

sub-push-%: $(addprefix, sub-sub-push-%-,$(SETB))

sub-sub-push-%-%:
         // This builds cmd1 for amd64 and arm and then cmd2 for amd64 and arm 

Is it possible to do something like this? Apologies if the question is too dumb. :) TIA.

Pensu
  • 3,263
  • 10
  • 46
  • 71
  • Not really, but what you are trying to achieve is probably achievable. Can you spell out in more detail what exactly this should do? – tripleee Jan 13 '20 at 06:04
  • @tripleee Yeah, I am trying to loop over combination. Let's say, for a value a, I should run some rules with values i.e. c and d, and then same for b. Basically, 4 combinations, i.e. a-c, a-d and then b-c and b-d. I hope that makes sense. When I run this, I get error that sub-push-a needs a target to run. – Pensu Jan 13 '20 at 06:09
  • The combinatorics are easy as such, but why do you need these to be target names in a `Makefile`? And why do you need them to be parameters -- surely the output should use the parameters somehow, not just `echo "This works"` four times? – tripleee Jan 13 '20 at 06:11
  • Ok, I am not sure if it can be done without targets. What I am trying to do is building cmd1 and cmd2 for 2 different archs. I want each command build to run on both the archs. Should I be using loops? I have updated the question as well for more clarity. – Pensu Jan 13 '20 at 06:15
  • Thanks. That looks similar. I will try it out and get back. – Pensu Jan 13 '20 at 06:25
  • Maybe also https://stackoverflow.com/questions/58158881/extract-macro-parameters-from-target-name-in-makefile/58166352#58166352 may be of interest to you. – Vroomfondel Jan 13 '20 at 10:28

0 Answers0