Makefile loop results from ls command

I have a list of text files, which when executing the following command:

ls *.txt

Will result in something like:

foo.txt bar.txt baz.txt

Now if I want to have the output be something like:

File: foo.txt
File: bar.txt
File: baz.txt

How would I achieve that in a Makefile?

I’ve been trying:

txtfiles = $$(ls *.txt)

list: $(txtfiles)

    echo "File:" $@

But when running this with make list, it results with:

File: $
File: $

I was thinking of trying to achieve this using placeholders % but wasn’t sure how to do that.

Note: instead of $$(ls *.txt) I’m guessing I could use $(wildcard *.txt) ?

Source: shell

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.