Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter out files with multiple criteria in a Makefile?

Lets say you filter for cpp files like so

$(wildcard **/*.cpp)

But you don't want files that contain the word foo and you don't want the file with the exact name bar.cpp

How does one use filter-out with multiple criteria?

like image 879
Johnny Haddock Avatar asked Apr 19 '16 13:04

Johnny Haddock


People also ask

What is $@ in Makefile?

The file name of the target of the rule. If the target is an archive member, then ' $@ ' is the name of the archive file. In a pattern rule that has multiple targets (see Introduction to Pattern Rules), ' $@ ' is the name of whichever target caused the rule's recipe to be run.

What is wildcard in Makefile?

The Function wildcard $(wildcard pattern ...) This string, used anywhere in a makefile, is replaced by a space-separated list of names of existing files that match one of the given file name patterns. If no existing file name matches a pattern, then that pattern is omitted from the output of the wildcard function.

What is in a Makefile?

Makefiles contain five kinds of things: explicit rules , implicit rules , variable definitions , directives , and comments . Rules, variables, and directives are described at length in later chapters. An explicit rule says when and how to remake one or more files, called the rule's targets.


1 Answers

This seems to work. Also recursively.

$(filter-out $(wildcard **/bar.cpp) $(wildcard **/*foo*), $(wildcard **/*.cpp))

Please also note Etan's simpler suggestion below. Leaving mine only for completeness.

like image 161
Johnny Haddock Avatar answered Oct 19 '22 04:10

Johnny Haddock