, script, cpp , , script, cpp ( ), cpp ? inotifywait. , script. :
.cpp
#include <iostream>
using namespace std;
int main (void) {
cout << endl << "Code Running (ver. 10)" << endl << "and being timed." << endl;
return 0;
}
inotifywait Script
#!/bin/bash
src=${1:-app.cpp}
out=${src%.cpp}
while inotifywait -q -e modify -e modify -e close_write -e delete "$PWD"; do
printf "\n compiling 'g++ %s -o %s'\n\n" $src $out
[ -f $out ] && rm $out
g++ -o $out $src
[ -f $out ] || {
printf "error: compilation failed. exiting script.\n\n"
printf "usage: %s source.cpp (default: app.cpp)\n\n"
exit 1
}
[ -x $out ] || {
printf "error: file produced from compilation is not executable.\n"
exit 1
}
time ./$out 2>&1
exesz=$(du -h $out | awk '{print $1}')
printf "\n Source file: %s\n" "$src"
printf " output file: %s\n" "$out"
printf " size of exe: %s bytes\n\n" "$exesz"
done
script . :.
( app.cpp)
$ ./watch.sh
/home/david/scr/tmp/stack/dat/tmp/bld/ MODIFY app.cpp
compiling 'g++ app.cpp -o app'
Code Running (ver. 10)
and being timed.
real 0m0.003s
user 0m0.001s
sys 0m0.001s
Source file: app.cpp
output file: app
size of exe: 16K bytes