help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Double expansion in eval?


From: Dario Teixeira
Subject: Double expansion in eval?
Date: Mon, 31 Oct 2005 11:50:42 +0100
User-agent: Mozilla Thunderbird 0.9 (X11/20041127)

Hi,

As you may recall, in a previous message to this list I wondered
about target-specific variables and implicit rules.  Several people
explained why this was not possible, and offered multiple suggestions
(thanks again!) to get around this limitation.

Anyway, I think that the "eval" function might be the best way to
achieve what I want.  However, I am having problems implementing
a solution in practice -- I reckon it might have to do with the
double expansion that is mentioned in the manual.
(The make manual is a bit terse on this matter; I think that adding
an example illustrating the double expansion pitfalls would help).

Attached you will find the current Makefile.  It is used to
automatically invoke gnuplot for the correct plot files found in
the current directory, and to convert the EPS and TEX files it
produces (I am using the epslatex terminal) into PDF and PDFTEX_T.

Though the makefile is a bit long, I am almost 100% sure that the
problem lies in the much shorter "makeplot" function which is invoked
by eval.  My question is: how exactly are these variables being
transformed by eval?  (And how should one protect the variables in
a fool-proof way?)

Thanks in advance for your help!
Kind regards,
Dario Teixeira
#
# Makefile for gnuplot plots.
#

.PHONY: all clean

COLOUR=monochrome

# Find out which plots and corresponding data files
# have names which begin by name of the directory itself.

BASENAME=$(basename $(notdir $(shell pwd)))
PLOTS=$(basename $(wildcard $(BASENAME)*.plot))
DATS=$(basename $(wildcard $(BASENAME)*.dat))

#
# If there are files common to all plots, they should be declared here.
#

COMMON=common.plot

#
# Build target list based on the matching plots.
#

TARGETS_PDF=$(foreach plot, $(PLOTS), $(plot)-$(COLOUR).pdf)
TARGETS_PDFTEX=$(foreach plot, $(PLOTS), $(plot)-$(COLOUR).pdftex_t)
TARGETS=$(TARGETS_PDF) $(TARGETS_PDFTEX)

all: $(TARGETS)

#
# Implicit rule for building a PDF out of the EPS generated by gnuplot.
#

%-$(COLOUR).pdf : %.eps
        cat $< | epstopdf --filter > $@

#
# Implicit rule for transforming the TEX file produced by gnuplot
# into a PDFTEX_T with correct path to figures.
#

%-$(COLOUR).pdftex_t : %.tex
        sed '/includegraphics/s/{/{figures\//' < $< > $@

#
# Rule for making EPS and TEX out of the plot and data files.
# This rule is to be invoked via the eval function.
# (Currently broken).
#

define makeplot
EPS=$(1).eps
TEX=$(1).tex
PLOT=$(1).plot
DAT=$(2).dat
INPUT=$(2)
OUTPUT=$(1)
$(EPS) $(TEX) : $(PLOT) $(DAT) $(COMMON) Makefile
        cat $(COMMON) $(PLOT) | sed 's/COLOUR/$(COLOUR)/' | sed 
's/INPUT/$(INPUT)/' | sed 's/OUTPUT/$(OUTPUT)/' | gnuplot
endef

#
# This function discovers the name of the data file associated with 
# a plot.  (There may be multiple plots of the same data file).
#

datdep=$(strip $(foreach dat,$(DATS),$(findstring $(dat),$(1))))

#
# Let us use eval to build the rules for all target plot files.
#

$(foreach plot,$(PLOTS),$(eval $(call makeplot,$(plot),$(call datdep,$(plot)))))

#
# Cleanup rule.
#

clean:
        rm -f *.pdf *.eps *.tex *.pdftex_t


reply via email to

[Prev in Thread] Current Thread [Next in Thread]