Iterating over lists in Makefiles?

后端 未结 6 1515
一整个雨季
一整个雨季 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条回答
  •  旧时难觅i
    2020-12-31 12:27

    None that I know of, but that is because you're trying to force make to work ans an imperative language, when that is not what it is.

    In GNU make you'd probably want to do something like:

    pull_tail : SOUND=bark
    pull_tail : dog.c 
            $(CC) $< -o $^
            ln $@ $(SOUND)
    
    chase : SOUND=quack
    chase : duck.c 
            $(CC) $< -o $^
            ln $@ $(SOUND)
    
    ...
    

    Or better yet, redefine the default rule for .c files to handle the linking for you, but the strange structure of your names (the program names don't have a lexical relationship to the source names) makes that hard.

    If what you want to be able to rebuild this quickly without an lot of hand editing, you probably want to write a script to regenerate the makefile framgment from data and use the include feature of GNU make...

提交回复
热议问题