Is there a smarter alternative to “watch make”?

前端 未结 11 621
渐次进展
渐次进展 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:02

    This shell script uses make itself to detect changes with the -q flag, and then does a full rebuild if and only if there are changes.

    #!/bin/sh
    
    while true;
    do
      if ! make -q "$@";
      then
        echo "#-> Starting build: `date`"
        make "$@";
        echo "#-> Build complete."
      fi
      sleep 0.5;
    done
    
    • It does not have any dependencies apart from make.

    • You can pass normal make arguments (such as -C mydir) to it as they are passed on to the make command.

    • As requested in the question it is silent if there is nothing to build but does not swallow output when there is.

    • You can keep this script handy as e.g. ~/bin/watch-make to use across multiple projects.

提交回复
热议问题