X-Git-Url: https://git.ucc.asn.au/?p=progcomp2013.git;a=blobdiff_plain;f=qchess%2Fupdate.sh;fp=qchess%2Fupdate.sh;h=a60ca80466f8c15a901d2dc1656e56e2836af268;hp=0edb377391c5d9c6c8e1fcb89475b30574f6a34c;hb=e0c24aed084b96f3c5800d869bc759f89667bd6a;hpb=65d9bb84c7e2dca4a8fac4d92c225ce1bb4f7c52 diff --git a/qchess/update.sh b/qchess/update.sh index 0edb377..a60ca80 100755 --- a/qchess/update.sh +++ b/qchess/update.sh @@ -2,6 +2,8 @@ # I still can't believe I am doing this +# (This can't be done with gnu make, because of circular dependency issues) + target=qchess.py components="piece.py board.py player.py thread_util.py game.py graphics.py main.py" # The below seems nicer, but doesn't work because things need to be imported in the right order :( @@ -13,22 +15,52 @@ footer="# EOF - created from update.sh on $(date)" # If the target was modified more recently than any of the components, update the component file -target_mod=$(stat -c %Y $target) +target_mod=$(stat -c %Y $target 2>/dev/null) + +if [ $? -ne 0 ]; then + merge_required=true +else + merge_required=false -merge_required=false + for f in $components; do + + component_mod=$(stat -c %Y $f 2>/dev/null) + if [ $? -ne 0 ]; then + update_required=true + elif [ $component_mod -lt $target_mod ]; then + update_required=true + else + update_required=false + fi -for f in $components; do - if [ $(stat -c %Y $f) -lt $target_mod ]; then - nawk "/+++ $f +++/, /--- $f ---/" $target | grep -v "+++ $f +++" | grep -v "\--- $f ---" > $f - else - merge_required=true -done + if $update_required; then + echo "$0 - update $f from $target" + sanity=$(egrep "(+++ $f +++)|(--- $f ---)" $target | wc -l) + if [ $sanity -ne 2 ]; then + $(echo "$0 - $target does not have markers for $f in it!") 1>&2 + exit 1 + fi + cp $f $f~ + new_contents=$(nawk "/+++ $f +++/, /--- $f ---/" $target | grep -v "+++ $f +++" | grep -v "\--- $f ---") + + echo "$new_contents" > $f + else + echo "$0 - $f is newer than $target" + merge_required=true + fi + done +fi +# If any components were modified more recently than the target, merge the components into the target if $merge_required; then echo $header > $target for f in $components; do - cat $components >> $target + echo "$0 - merge $f into $target" + echo "# +++ $f +++ #" >> $target + cat $f >> $target + echo "# --- $f --- #" >> $target done - echo $footer > $target + echo $footer >> $target + chmod u+x $target fi