4

In a Makefile, I have a rule to make a figure list from a LaTeX paper by piping the output from a script to a perl expression that increments figure numbers $f++ and prepends Figure $f: to the lines.

From a command line, it works fine, as follows:

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

generating 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
...

I can't figure out how to make this work in a Makefile, because the $f stuff in the perl expression gets interpreted by make and I can't figure out how to quote it or otherwise make it invisible to make.

My most recent attempt in my Makefile:

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

Can someone help?

-Michael

4

1 回答 1

4

双倍的美元符号。

## 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

于 2012-12-03T20:42:14.750 回答