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
Double the dollar signs.
## Generate FIGLIST
FIGLIST:
$(TEXDEPEND) -format=1 -print=f $(MAIN) \
| perl -pe 'unless (/^\#/){$$f++; s/^/Figure $$f: /}' > $@
You may need to backslash-escape the comment sign as well. I did so just in case.
See also http://www.gnu.org/software/make/manual/html_node/Variables-in-Recipes.html#Variables-in-Recipes
来源:https://stackoverflow.com/questions/13691180/how-to-quote-a-perl-symbol-in-a-makefile