如何自动执行文件更改的make目标?

How do I write a make target that will watch for any file changes in specific folders and execute some other make target to compile files? I am looking for a way that can do this with minimal dependency on tools in addition to make itself to keep things simple.

For the watching you can use fswatch. (There's also a go version of this program which may be easier to install: fswatch) For example:

fswatch -ext cpp,c,h make -f Makefile

Anytime you change a cpp, c or h file it will run make again.

Make can be a bit slow for this, so I tend to use ninja instead, but that really depends on the size of your project.

Another option is tup, which has watching built-in:

tup monitor

But, sadly, only for linux.