Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make: Run when any file in directory or subdirectory changes or is added

Tags:

makefile

When I use this in a Makefile:

run: mydir/*
    do_something.sh

it triggers do_something.sh every time a file in mydir is added/changed. Is it possible to also trigger do_something.sh when any file in the directory-tree of mydir (i.e in any subdirectory or subdirectory of a subdirectory, etc.) changes or is added?

like image 576
Robby75 Avatar asked Dec 19 '25 20:12

Robby75


1 Answers

This might do the trick.

run: $(shell find mydir/ -type f)
    do_something.sh
  • run cannot be a PHONY target, i.e. it should create a file named run at the end of execution of the recipe
  • If any of the files in mydir have spaces in the name, you might get unexpected behavior
like image 179
Tuxdude Avatar answered Dec 24 '25 12:12

Tuxdude



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!