Is there a smarter alternative to “watch make”?

前端 未结 11 595
渐次进展
渐次进展 2021-02-01 15:28

I ran into this useful tip that if you\'re working on files a lot and you want them to build automatically you run:

watch make

And it re-runs make every couple s

11条回答
  •  迷失自我
    2021-02-01 16:04

    Here is a one-liner:

    while true; do make -q || make; sleep 0.5; done
    

    Using make -q || make instead of just make will only run the build if there is something to be done and will not output any messages otherwise.

    You can add this as a rule to your project's Makefile:

    watch:
        while true; do $(MAKE) -q || $(MAKE); sleep 0.5; done
    

    And then use make watch to invoke it.

    This technique will prevent Make from filling a terminal with "make: Nothing to be done for TARGET" messages.

    It also does not retain a bunch of open file descriptors like some file-watcher solutions, which can lead to ulimit errors.

提交回复
热议问题