【问题标题】:How to quote a perl $symbol in a makefile如何在 makefile 中引用 perl $symbol
【发布时间】:2012-12-03 20:30:47
【问题描述】:

在 Makefile 中,我有一条规则,可以通过管道从 LaTeX 论文中创建图形列表 从脚本输出到 perl 表达式,该表达式递增数字 $f++ 并将数字 $f: 添加到行中。

从命令行,它工作正常,如下:

% texdepend -format=1 -print=f MilestonesProject | perl -pe 'unless (/^#/){$f++; s/^/Figure $f: /}' > FIGLIST

生成FIGLIST:

# texdepend, v0.96 (Michael Friendly (friendly@yorku.ca))
# commandline: texdepend -format=1 -print=f MilestonesProject
# FIGS =
Figure 1: fig/langren-google-overlay2.pdf
Figure 2: fig/mileyears4.png
Figure 3: fig/datavis-schema-3.pdf
Figure 4: fig/datavis-timeline2.png
...

我不知道如何在 Makefile 中进行这项工作,因为 perl 表达式中的 $f 内容会被 make 解释,我不知道如何引用它或其他方式 让它不可见。

我最近在 Makefile 中的尝试:

## Generate FIGLIST; doesnt work due to Make quoting
FIGLIST:
    $(TEXDEPEND) -format=1 -print=f $(MAIN)  | perl -pe 'unless (/^#/){\$f++; s/^/Figure \$f: /}' > FIGLIST

有人可以帮忙吗?

-迈克尔

【问题讨论】:

    标签: perl makefile quoting


    【解决方案1】:

    加倍美元符号。

    ## Generate FIGLIST
    FIGLIST:
        $(TEXDEPEND) -format=1 -print=f $(MAIN) \
        | perl -pe 'unless (/^\#/){$$f++; s/^/Figure $$f: /}' > $@
    

    您可能还需要对注释符号进行反斜杠转义。我这样做是为了以防万一。

    另见http://www.gnu.org/software/make/manual/html_node/Variables-in-Recipes.html#Variables-in-Recipes

    【讨论】:

      猜你喜欢
      • 2019-12-02
      • 1970-01-01
      • 1970-01-01
      • 2010-11-20
      • 1970-01-01
      • 2021-03-23
      • 2011-04-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多