我不希望 gnu make 将自动变量传递给规则中的 gnuplot 脚本

I don't want gnu make to pass automatic variables to a gnuplot script in a rule

我在 gnu-make Makefile 中有一个如下所示的目标:

Makefile 片段:

rateplots: binattrate.bin
    gnuplot -c $(src)\Plot.gp binattrate.bin

实用程序 gnuplot 将 $1 解释为 Plot.gp 脚本中的特殊字段,当直接从 shell 终端调用时,脚本 运行s 是正确的。当 运行 作为上面显示的 Makefile 片段的规则时,它在 gnuplot-.

中失败

我发现我可以在 Plot.gp 脚本中替换双倍的 $。也就是说,用 $$1 替换 Plot.gp 中的 $1 并且 make 规则的功能与没有从 shell 终端替换时一样。看起来 gnuplot 看到从 make 传递的命令参数 $0、$1、$2 等。我不想要这个。我希望 gnuplot 将 $1 解释为它自己的字段变量。

我可以在调用 gnuplot 将 $ 替换为 Plot.gp 之前在 make 中破解 sed 脚本,但我更喜欢不修改原始代码的解决方案,因为破解会增加代码的复杂性并使其他人更难理解 makefile。总之,我希望 gnu-make 调用规则而不替换 $1 命令参数变量或任何其他神秘变量。

我正在 Windows 10 平台上使用 cygwin64

  1. 和 GNU Make 4.3 和
  2. gnuplot 5.2(补丁级别 8){请参阅 post 末尾添加的注释}

这是 Plot.gp 中失败的行:

plot inputfile every ::1 binary format=fileformat \
   using (gtime+):2  with lines linestyle 1 linecolor rgbcolor "black" linewidth 3 title 'GPS1/GPS2'

如果我用 $$1 替换 $1,代码的工作方式与从命令 shell.

手动调用时一样

我通过添加一条规则来解决这个问题,该规则使用 sed 将 $$ 替换为 $,从而发出“scratch.gp”:

rateplots: binattrate.bin
  cat $(src)/Plot.gp | sed 's/$$/$$$$/g' >scratch.gp
  gnuplot -c scratch.gp binattrate.bin

我发现该解决方法在其他 5 个相关脚本中很有效,但它不应该这样做。

我推测这是 cygwin 下的 gnuplot(相当新)或 Windows cmd shell 的某些元素中的错误——但我不知道。我正在经历的事情应该是不可能的。找到解决方案非常重要。

谢谢大家

注意:我发现当我从 shell 终端 window 调用 gnuplot 时:

gnuplot --version

返回以下内容:

gnuplot 5.2 patchlevel 8

然而,当创建 makefile 以在配方中发出相同的命令时:

all:
     gnuplot --version

命令

make all

returns

gnuplot --version
gnuplot 5.4 patchlevel 0

总而言之,gnu make 以某种方式调用 gnuplot 5.4 补丁级别 0 而在 shell 终端中手动发出相同的命令调用 gnuplot 5.2 补丁级别 8 。为什么会这样?

我进一步观察到 gnuplot 5.4 补丁级别 0 包含版本 4 向后兼容功能(可能包括 $n 环境变量的解释。

我的问题的所有要素都来自:

  1. gnuplot 5.4.0 中的错误
  2. make 调用 /bin/sh (linux bash) 而不是 windows shell.

我向 gnuplot 开发组 (https://sourceforge.net/p/gnuplot/bugs/2368/) 提交了一份关于 cygwin 发行版中 gnuplot 5.4.0 的错误报告。开发者表示会在5.4.1中修复。

该错误是由于不推荐使用的 $0、$1、$2 等符号被错误地启用并分配给 gnuplot (5.4.0) 的命令行参数造成的。

有问题的 Gnuplot 5.4.0 是“gnuplot-base.exe”,“过时的”gnuplot 5.2.8 在 cygwin 发行版中显示为“gnuplot.exe”。

我观察命令“gnuplot”:

  1. 从 windows cmd shell 运行“gnuplot.exe” (5.2.8)。
  2. 而从 /bin/sh 到 gnuplot 的链接指向“gnuplot-base.exe”(5.4.0)。

“make”实用程序通过 /bin/sh 提交规则,解释了为什么 gnuplot 在“make”中失败,而不是通过命令 shell。

我正在通过在“make”规则中调用“gnuplot.exe”而不是“gnuplot”来解决问题。 “gnuplot.exe 是过时的版本 5.2.8.

谢谢。我爱你们。