3 # I still can't believe I am doing this
5 # This updates the component files from the target, as well as the target from the components
6 # You can't do that with gnu make, because of the circular dependency
7 # But this should probably not be used by any sane person
12 components="piece.py board.py player.py network.py thread_util.py game.py graphics.py main.py"
13 # The below seems nicer, but doesn't work because things need to be imported in the right order :(
14 #components=$(ls *.py | tr '\t' '\n' | grep -v $target)
16 header="#!/usr/bin/python -u"
17 footer="# EOF - created from update.sh on $(date)"
21 # If the target was modified more recently than any of the components, update the component file
22 target_mod=$(stat -c %Y $target 2>/dev/null)
30 for f in $components; do
32 component_mod=$(stat -c %Y $f 2>/dev/null)
35 elif [ $component_mod -lt $target_mod ]; then
41 if $update_required; then
42 echo "$0 - update $f from $target"
43 sanity=$(egrep "(+++ $f +++)|(--- $f ---)" $target | wc -l)
44 if [ $sanity -ne 2 ]; then
45 $(echo "$0 - $target does not have markers for $f in it!") 1>&2
49 new_contents=$(nawk "/+++ $f +++/, /--- $f ---/" $target | grep -v "+++ $f +++" | grep -v "\--- $f ---")
51 echo "$new_contents" > $f
53 echo "$0 - $f is newer than $target"
61 # If any components were modified more recently than the target, merge the components into the target
62 if $merge_required; then
63 echo $header > $target
64 for f in $components; do
65 echo "$0 - merge $f into $target"
66 echo "# +++ $f +++ #" >> $target
68 echo "# --- $f --- #" >> $target
71 echo $footer >> $target