Skeen
Skeen

Reputation: 4722

GNU Make (running program on multiple files)

I'm stuck trying to figure out how to run a program, on a set of files, using GNU Make:

I have a variable that loads some filenames alike this:

FILES=$(shell ls *.pdf)

Now I'm wanting to run a program 'p' on each of the files in 'FILES', however I can't seem to figure how to do exactly that.

An example of the 'FILES' variable would be:

"a.pdf k.pdf omg.pdf"

I've tried the $(foreach,,) without any luck, and #!bin/bash like loops seem to fail.

Upvotes: 0

Views: 260

Answers (1)

Beta
Beta

Reputation: 99094

You can do a shell loop within the command:

all:
    for x in $(FILES) ; do \                                                
      p $$x ; \
    done

(Note that only the first line of the command must start with a tab, the others can have any old whitespace.)

Here's a more Make-style approach:

TARGETS = $(FILES:=_target)

all: $(TARGETS)
    @echo done

.PHONY: $(TARGETS)

$(TARGETS): %_target : %
    p $*

Upvotes: 1

Related Questions