Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile rule that detects any changed file in a directory (and subdirs)

Tags:

makefile

I want to create a Makefile rule that runs whenever anything is changed inside a directory (which contains multiple source files in different languages, and at different subdirectory levels).

As an example, take this Makefile:

newest: src
        touch newest

with a tree like:

src/
src/a
scr/subdir/
scr/subdir/c

First time I run make, newest is created all right. But if I now touch src/subdir/b, make does nothing.

Is it possible at all to create such a rule?

like image 489
Jellby Avatar asked Sep 06 '25 05:09

Jellby


1 Answers

I think you would need to use something like FILES := $(shell find src -type f) and a rule of newest: $(FILES) to get the sort of behavior you want.

like image 177
Etan Reisner Avatar answered Sep 10 '25 18:09

Etan Reisner