Is there a smarter alternative to “watch make”?

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

    I do it this way in my Makefile:

    watch:
        (while true; do make build.log; sleep 1; done) | grep -v 'make\[1\]'
    
    build.log: ./src/*
        thecompiler | tee build.log
    

    So, it will only build when my source code is newer than my build.log, and the "grep -v" stuff removes some unnecessary make output.

    0 讨论(0)
  • 2021-02-01 16:09

    Using classic gnu make and inotifywait, without interval-based polling:

    watch:
        while true; do \
            make $(WATCHMAKE); \
            inotifywait -qre close_write .; \
        done
    

    This way make is triggered on every file write in the current directory tree. You can specify the target by running

    make watch WATCHMAKE=foo
    
    0 讨论(0)
  • 2021-02-01 16:16

    Twitter Bootstrap uses the watchr ruby gem for this.

    https://github.com/twbs/bootstrap/blob/v2.3.2/Makefile

    https://github.com/mynyml/watchr

    Edit:

    After two years the watchr project seems not to be maintained anymore. Please look for another solution among the answers. Personally, if the goal is only to have a better output, i would recommend the answer from wch here

    0 讨论(0)
  • 2021-02-01 16:16

    There are several automatic build systems that do this and more - basically when you check a change into version control they will make/build - look for Continuous Integration

    Simple ones are TeamCity and Hudson

    0 讨论(0)
  • 2021-02-01 16:19

    How about

    # In the makefile:
    .PHONY: continuously
    continuously:
        while true; do make 1>/dev/null; sleep 3; done  
    

    ?

    This way you can run

    make continuously

    and only get output if something is wrong.

    0 讨论(0)
提交回复
热议问题