GNU Make for循环具有两个变量 [英] GNU Make for loop with two variables

查看:146
本文介绍了GNU Make for循环具有两个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想按照以下方式写点东西:

I want to write something along these lines:

$(foreach (var1, var2), ($(LIST1), $(LIST2)), cp $(var1) $(var2);)

我该如何在GNU makefile中执行此操作?

How do I go about doing this in a GNU makefile?

推荐答案

Beta关于使用join的建议是正确的,但是问题在于,以构造包含空格的命令行的方式使用它并不容易,例如您最初想要的一个:

Beta's suggestion to use join is on the right track, but the problem is that it's not so easy to use it in a way that constructs a command line containing whitespace, such as the one you originally wanted:

$(foreach (var1, var2), ($(LIST1), $(LIST2)), cp $(var1) $(var2);)

因为join将单词连接在一起:它最初是用于构造文件名的.但是,您可以耍个把戏.这是使用联接的一种示例,它为您提供所需的输出:

because join joins words together: it was originally intended for constructing filenames. However you can play a trick; here's an example of a way to use join that gives you the output you are looking for:

$(subst ^, ,$(join $(addprefix cp^,$(LIST1)),$(patsubst %,^%;,$(LIST2))))

如果您认为列表可能包含^个字符,请选择其他内容.让我知道您是否需要解压/解释.

If you think your lists might contain ^ characters then choose something else. Let me know if you need this unpacked/explained.

这篇关于GNU Make for循环具有两个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆