Iterating over lists in Makefiles?

后端 未结 6 1506
一整个雨季
一整个雨季 2020-12-31 11:45

I find I\'m writing a lot of Makefiles that could be cleaned up with the use of n-tuple lists. But I can\'t find any way to do this properly (and cleanly). So far I

6条回答
  •  执笔经年
    2020-12-31 12:11

    Thanks for the hints -- after some hacking I think this is more what I was hoping for:

    XYZs = \
        dog.c:pull_tail:bark  \
        duck.c:chase:quack \
        cow.c:tip:moo
    
    all:
        @- $(foreach XYZ,$(XYZs), \
            $(eval X = $(word 1,$(subst :, ,$(XYZ)))) \
            $(eval Y = $(word 2,$(subst :, ,$(XYZ)))) \
            $(eval Z = $(word 3,$(subst :, ,$(XYZ)))) \
            \
            $(CC) $X -o bully/$Y ; \
            ln bully/$Y sounds/$Z ; \
        )
    

    Can anyone do better?

提交回复
热议问题