Destinos comodín en un Makefile


¿Cómo puedo compactar los siguientes destinos Makefile?

$(GRAPHDIR)/Complex.png: $(GRAPHDIR)/Complex.dot
        dot $(GRAPHDIR)/Complex.dot -Tpng -o $(GRAPHDIR)/Complex.png

$(GRAPHDIR)/Simple.png: $(GRAPHDIR)/Simple.dot
        dot $(GRAPHDIR)/Simple.dot -Tpng -o $(GRAPHDIR)/Simple.png

$(GRAPHDIR)/IFileReader.png: $(GRAPHDIR)/IFileReader.dot
        dot $(GRAPHDIR)/IFileReader.dot -Tpng -o $(GRAPHDIR)/IFileReader.png

$(GRAPHDIR)/McCabe-linear.png: $(GRAPHDIR)/McCabe-linear.dot
        dot $(GRAPHDIR)/McCabe-linear.dot -Tpng -o $(GRAPHDIR)/McCabe-linear.png

graphs: $(GRAPHDIR)/Complex.png $(GRAPHDIR)/Simple.png $(GRAPHDIR)/IFileReader.png $(GRAPHDIR)/McCabe-linear.png

--

Usando GNU Make 3.81.

Author: P Shved, 2009-10-27

3 answers

El concepto se llama reglas de patrón. Puede leer sobre ello en GNU make manual.

$(GRAPHDIR)/%.png: $(GRAPHDIR)/%.dot
        dot $< -Tpng -o $@

graphs: $(patsubst %,$(GRAPHDIR)/%.png, Complex Simple IFileReader McCabe)\

O simplemente

%.png: %.dot
        dot $< -Tpng -o $@

graphs: $(patsubst %,$(GRAPHDIR)/%.png, Complex Simple IFileReader McCabe)

Cosas avanzadas: es divertido notar que hay una repetición allí arriba...

PNG_pattern=$(GRAPHDIR)/%.png

$(PNG_pattern): $(GRAPHDIR)/%.dot
        dot $< -Tpng -o $@

graphs: $(patsubst %,$(PNG_pattern), Complex Simple IFileReader McCabe)
 45
Author: P Shved,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-10-28 00:18:44

Solo en caso de que realmente desee generar un.PNG para cada .PUNTO dentro del directorio actual:

%.png : %.dot
    dot -Tpng -o $@ $<

all: $(addsuffix .png, $(basename $(wildcard *.dot)))

Se me ocurrió este Makefile después de leer la respuesta de @Pavel.

 18
Author: Metaphox,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-02-27 13:25:59

Creo que quieres algunas reglas de patrón. Prueba esto.

TARGETS = $(GRAPHDIR)/Complex.png \  
          $(GRAPHDIR)/Simple.png \ 
          $(GRAPHDIR)/IFileReader.png \
          $(GRAPHDIR)/McCabe-linear.png

%.png : %.dot
        dot $^ -Tpng -o $@

graphs: $(TARGETS)
 8
Author: Carl Norum,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-10-27 20:50:53