Home > OS >  How to do something for each file starting with test_*.py in a Makefile
How to do something for each file starting with test_*.py in a Makefile

Time:05-28

Im trying to write a makefile target that runs a command for each of my test files (test_[name].py). I'm wondering how to use the foreach command to do something for those files, and only those files.

Any help would be much appreciated.

CodePudding user response:

Here is a simple example:

.PHONY: all

TEST_PY:=$(wildcard test_*.py)

$(foreach i,$(TEST_PY),$(info $(i)))

all:
    @:

It will print the name of each file, the list of files is provided by the function wildcard. The documentation of these functions are at GNU Make Functions

The "@:" is to avoid the message "make: Nothing to be done for 'all'."

CodePudding user response:

Also found that this work quite well for what I was trying...

test: $(TEST_DIRECTORY)/*/*
   for file in $^ ; do \
      ...
   done
  • Related