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

后端 未结 3 790
别那么骄傲
别那么骄傲 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:29

    If you're using GNU make, you can generate arbitrary targets at run-time:

    LIST = 0 1 2 3 4 5
    define make-rambo-target
      rambo$1:
             sh rambo_script$1.sh
      all:: rambo$1
    endef
    
    $(foreach element,$(LIST),$(eval $(call make-rambo-target,$(element))))
    

提交回复
热议问题