[ucsim] Implement [features:#769] Check writeability of output file when uart sends
[sdcc.git] / sdcc-build / sdcc-build-bootstrap.sh
blobafdf4a330757af0f72426765fa886ed199ac395d
1 #!/bin/sh
3 # Simple shell script that knows enough to download the sdcc build scripts
4 # and start them running.
6 # Use gmake over make by default.
7 if command -v gmake > /dev/null; then
8 MAKE=gmake
9 else
10 MAKE=make
13 BUILDROOT=$HOME/build
14 #test -z $BUILDROOT && \
15 # BUILDROOT=/var/tmp/`whoami`/build
17 # SVN sdcc-build repository
18 SVNROOT=svn://svn.code.sf.net/p/sdcc/code/trunk
20 BUILDDATE=`date +%Y%m%d`
22 # The lockfile ensures that the new build doesn't start until the previous one s not done
24 # uniq id
25 MYID=$HOSTNAME
26 # time to sleep until next check of lockfile, in seconds
27 SLEEP=60
28 # maximum age of lockfile; after this the lock will be removed
29 MAXMINUTES=1440 #one day
30 # filename of lock
31 LOCKFILE=$BUILDROOT/sdcc-build.lock
32 # prefix for all messages, which is used to filter the messages out of the buildlogs
33 MSGPREFIX="Buildlock: "
35 # Delete lockfile
36 # but check first, if it's (still) our own lockfile.
37 cleanup ()
39 echo $MSGPREFIX cleanup
40 test -f $LOCKFILE && head -n 1 $LOCKFILE | grep $MYID > /dev/null && rm $LOCKFILE && echo $MSGPREFIX "Lock released on " `date`
43 # Execute supported version of ls -l --full-time
44 ls_l_full_time ()
46 # test if ls -l --full-time is supported
47 res=`ls -l --full-time $1 2>&1`
48 if test $? = 0; then
49 # ls -l --full-time supported: echo the result
50 echo "$res"
51 else
52 # ls -l --full-time not supported: execute ls -l
53 ls -l $1
57 # Perform locking
58 do_lock ()
60 echo $MSGPREFIX Try to obtain lock on `date`
61 test -f $LOCKFILE && printf "%s %s\n" $MSGPREFIX "`ls_l_full_time $LOCKFILE`"
62 while true
64 if test -f $LOCKFILE
65 then
66 sleep $SLEEP
67 res=`find $LOCKFILE -mmin +$MAXMINUTES \
68 -exec echo $MSGPREFIX lock from \`cat $LOCKFILE\` expired \; \
69 -exec rm -f {} \; 2> /dev/null`
70 if test $? = 0; then
71 echo $res
72 else
73 echo $MSGPREFIX "Can't obtain the lock"
74 return 1
76 else
77 echo $MYID > $LOCKFILE
78 # check, if we're in the first line of lockfile;
79 # if we're not in the first line, another host was faster
80 # and we have to wait again.
81 head -n 1 $LOCKFILE | grep $MYID > /dev/null || continue
82 echo $MSGPREFIX "Obtained lock on " `date`
83 break
85 done
87 return 0
90 trap 'echo $MSGPREFIX caught signal ; cleanup ; exit 1' 1 2 3 13 15
92 mkdir -p $BUILDROOT
94 if do_lock
95 then
96 success=0
97 # Include local apps.
98 if test -d ~/local-$HOSTNAME/bin; then
99 PATH=$PATH:$HOME/local-$HOSTNAME/bin
100 elif test -d ~/local/bin; then
101 PATH=$PATH:$HOME/local/bin
104 for i in 0 1 2
106 # Checkout the latest sdcc-build version to $BUILDROOT/sdcc-build
107 # Quick & dirty temporary fix: don't remove the build if uploading
108 test "$1" != "do-upload" && rm -rf $BUILDROOT/sdcc-build
109 if svn checkout $SVNROOT/sdcc-build $BUILDROOT/sdcc-build
110 then
111 success=1
112 break
113 else
114 sleep 300
116 done
118 if test "$success" = 1
119 then
120 # Spawn onto the actual build
121 # Don't use "make -C" to change directory since the "Entering directory" and
122 # "Leaving directory" messages are displayed in the regression test results
123 cd $BUILDROOT/sdcc-build
124 $MAKE $*
125 else
126 echo $MSGPREFIX "can't checkout"
130 cleanup