How to generate targets in a Makefile by iterating over a list?

后端 未结 3 787
别那么骄傲
别那么骄傲 2021-02-04 09:44

CODE:

LIST=0 1 2 3 4 5
PREFIX=rambo

# some looping logic to interate over LIST

EXPECTED RESULT:

rambo0:
    sh rambo_script0.s         


        
3条回答
  •  北海茫月
    2021-02-04 10:36

    Use text-transforming functions. With patsubst you can make quite general transformations. For constructing filenames, addsuffix and addprefix are both convenient.

    For the rules, use pattern rules.

    The overall result might look something like this:

    LIST = 0 1 3 4 5
    targets = $(addprefix rambo, $(LIST))
    
    all: $(targets)
    
    $(targets): rambo%: rambo%.sh
        sh $<
    

提交回复
热议问题