Skip to content

Instantly share code, notes, and snippets.

@swarminglogic
Last active December 17, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swarminglogic/5623057 to your computer and use it in GitHub Desktop.
Save swarminglogic/5623057 to your computer and use it in GitHub Desktop.
Watch over project files, and automatically rebuild project when files are modified. Created with SCons and C++ in mind, but can easily be customized.
#!/bin/bash
#
# Watch over project files, and automatically rebuild
# project when files are modified. Can easily be
# customized for different project types/languages.
#
# Use: ./autobuild.sh [executable]
#
# Optional: Pass path to executable to run whenever
# build succeeds.
#
# e.g. ./autobuild.sh bin/main
#
commnd='find ./src ./SConstruct
-name "[!\.]*.cpp" -or
-name "[!\.]*.h" -or
-name "[!\.]*.tpp" -or
-name "SConscript*" -or
-name "SConstruct"
| xargs stat -c %y | md5sum'
compileCmmnd='scons -Q'
# ----------------------------------------
md5sumStart=`eval $commnd`
clear
echo "Waiting for changes."
while [[ true ]]
do
md5sumNow=$md5sumStart
# Loop until some files have changed
while [[ "$md5sumNow" = "$md5sumStart" ]]
do
sleep 0.5
md5sumNow=`eval $commnd`
done
# Recompile
clear
$compileCmmnd
compileOk=$?
md5sumStart=`eval $commnd`
# Report build ok, or failure (clear if former)
if [[ $compileOk -eq 0 ]]
then
clear
echo -e '[\033[1;32m Build OK\033[0m ]'
else
echo -e '[\033[0;31m Build Failed\033[0m ]'
fi
# Run executed command.
if [[ $# -gt 0 && $compileOk -eq 0 ]]
then
if [[ -e ./$1 ]]
then
./$1 ^
else
echo -e "[\033[0;31m Executable '$1' was not found!\033[0m ]";
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment