Makefile的配方与此文档重定向 [英] Makefile recipe with a here-document redirection

查看:147
本文介绍了Makefile的配方与此文档重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何使用此文档的重定向上的配方?

Does anyone know how to use a here-document redirection on a recipe?

test:
  sh <<EOF
  echo I Need This
  echo To Work
  ls
  EOF

我找不到任何解决方案试图常用的方法反斜杠(基本上与命令在一行结束)。

I can't find any solution trying the usual backslash method (which basically ends with a command in a single line).

理由:

我必须通过另一个命令一组多行的食谱,我要代理(例如,SH,码头工人)。

I have a set of multi-line recipes that I want to proxy through another command (e.g., sh, docker).

onelinerecipe := echo l1
define twolinerecipe :=
echo l1
echo l2
endef
define threelinerecipe :=
echo l1
echo l2
echo l3
endef

# sh as proxy command and proof of concept
proxy := sh

test1:
  $(proxy) <<EOF
  $(onelinerecipe)
  EOF

test2:
  $(proxy) <<EOF
  $(twolinerecipe)
  EOF

test3:
  $(proxy) <<EOF
  $(threelinerecipe)
  EOF

我很想避开解决办法:多行转换成宏单行

The solution I would love to avoid: transform multiline macros into single lines.

define threelinerecipe :=
echo l1;
echo l2;
echo l3
endef

test3:
  $(proxy) <<< "$(strip $(threelinerecipe))"

这工作(我用了gmake 4.0和bash作为化妆的shell),但它需要改变我的食谱和我有很多。
地带删除新行,从宏观,那么一切都写在一行。

This works (I use gmake 4.0 and bash as make's shell) but it requires changing my recipes and I have a lot. Strip removes the newlines, from the macro, then everything is written in a single line.

我的最终目标是:代理:=泊坞窗运行...

推荐答案

使用该行的 .ONESHELL: 某处在您的Makefile将发送的所有配方行到一个shell调用,你会发现你原来的Makefile按预期工作。

Using the line .ONESHELL: somewhere in your Makefile will send all recipe lines to a single shell invocation, you should find your original Makefile works as expected.

这篇关于Makefile的配方与此文档重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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