Popovici Cosmi
Popovici Cosmi

Reputation: 53

How to check if a file from a list contains something , in makefile?

I want to check if all the files that have a specific name have in them a string , if not to report them . I wrote this sequence and tried multiple some others, but I don't know how to access the contain of a file from list.

SOURCES := $(shell find $(SOURCEDIR) -name 'mod.mak')#here I take the list of targeted files (this works fine)
$(foreach File, Files,
$(if $(grep -q "aaabbb" "$File"),,@echo "WARNING Missing sequence")
)

Upvotes: 3

Views: 1936

Answers (1)

randomir
randomir

Reputation: 18697

You have multiple issues with your script.

First of all, you need some rule/target. For your example we can make a PHONY target test. Second, to iterate over values in SOURCES, you need to reference it as $(SOURCES). Similarly for $(file) in call to grep. Also, make's if is interpreting value, not exit code, so you shouldn't silence grep.

This will do it:

.PHONY: test

SOURCES := $(shell find "$(SOURCEDIR)" -name 'mod.mak')

test:
    $(foreach file,$(SOURCES),$(if $(shell grep "aaabbb" "$(file)"),,@echo "WARNING Missing sequence in $(file)"))

Upvotes: 2

Related Questions