Add a newline in Makefile 'foreach' loop

2019-01-22 14:12发布

Is it possible to insert a new-line to be executed within a foreach loop in a Makefile?

Currently, I have the following:

$(foreach my_lib,$(MY_LIBS),$(call my_func,results,boxer,$(my_lib)))

Now, assuming that I have:

MY_LIBS = lib1 \
          lib2

The above foreach loop would evaluate to:

lib1 lib2

I would like this to evaluate to:

lib1
lib2

Is it possible to insert a newline in the foreach loop to accomplish this?

Thank you.

标签: makefile
2条回答
时光不老,我们不散
2楼-- · 2019-01-22 14:53
define \n


endef

$(error Here is a message${\n}with embedded${\n}newlines.${\n}${\n}hooray!)

You can use ${\n} in things like $(subst...).

查看更多
Evening l夕情丶
3楼-- · 2019-01-22 14:58

You could do this by using

define MY_LIBS
lib1
lib2
endef

In more complex cases, where you want to generate multiline makefile commands from the loop, you will need to use the eval function.

查看更多
登录 后发表回答