Multiline bash commands in makefile

后端 未结 5 1474
醉梦人生
醉梦人生 2020-11-27 11:57

I have a very comfortable way to compile my project via a few lines of bash commands. But now I need to compile it via makefile. Considering, that every command is run in it

5条回答
  •  死守一世寂寞
    2020-11-27 12:37

    You can use backslash for line continuation. However note that the shell receives the whole command concatenated into a single line, so you also need to terminate some of the lines with a semicolon:

    foo:
        for i in `find`;     \
        do                   \
            all="$$all $$i"; \
        done;                \
        gcc $$all
    

    But if you just want to take the whole list returned by the find invocation and pass it to gcc, you actually don't necessarily need a multiline command:

    foo:
        gcc `find`
    

    Or, using a more shell-conventional $(command) approach (notice the $ escaping though):

    foo:
        gcc $$(find)
    

提交回复
热议问题