Search code examples
bashmakefilegnu-makegnu

Makefile the dependency is a list variable but $< is only taking the first dependency


I've some similar files on which I want to do an operation using makefile. So I'm doing this:

INPUT  := $(wildcard *.png)
OUTPUT := $(INPUT:.png=.jpeg)

.PHONY: all

all: $(OUTPUT)

$(OUTPUT): $(INPUT)
    convert $< -resize 30x30 $@

I'm getting correct jpeg file names but the image is the same (first dependency) in the all the files.

I know that using $< only refers to the first dependency in the list, and using $^ is giving all the deps but for all the ouputs.

Is there any way that dep1 for output1, dep2 for output2 and so on?


Solution

  • This way you declare that each output file depends on every input file. You should be using a pattern rule instead, i.e.:

    $(OUTPUT): %.jpeg: %.png
        convert $< -resize 30x30 $@