Last Updated: February 25, 2016
·
933
· icholy

make watch - recompile

Automatically recompiling when a file changes is the next best thing if a repl is not possible. Luckily it's extremely easy to do on linux with inotify-tools.

Get inotify-tools

sudo apt-get install inotify-tools

Add watch to your makefile. Here is an extremely basic example,

CC=rustc
OUT=out
SRC=main.rs
CFLAGS=

all:
    $(CC) $(CFLAGS) $(SRC) -o $(OUT)

clean:
    rm -f $(OUT)

watch:
    while true; do inotifywait $(SRC) && clear && make; done

Then just use it and make will be called every time a file is modified.

make watch