bug fixes for udp broadcast
[IRC.git] / Robust / src / buildscript
1 #!/bin/bash
2
3 printhelp() {
4 echo -robustroot set up the ROBUSTROOT to directory other than default one
5 echo -dsm distributed shared memory
6 echo -trueprob double - probabiltiy of true branch
7 echo -mac distributed shared memory mac support
8 echo -check generate check code
9 echo -dmalloc link in dmalloc
10 echo -recover compile task code
11 echo -specdir directory
12 echo -printflat print out flat representation
13 echo -selfloop task - this task cannot self loop forever
14 echo "-excprefetch methoddescriptor - exclude prefetches for this method (specified as class.method)"
15 echo -taskstate do task state analysis
16 echo -tagstate do tag state analysis
17 echo -scheduling do task scheduling
18 echo -multicore generate multi-core version binary
19 echo "-numcore set the number of cores (should be used together with -multicore), defaultly set as 1"
20 echo "-raw generate raw version binary (should be used together with -multicore)"
21 echo -threadsimulate generate multi-thread simulate version binary
22 echo -optional enable optional
23 echo -debug generate debug symbols
24 echo -prefetch do prefetch analysis
25 echo -transstats generates transaction stats on commits and aborts
26 echo -webinterface enable web interface
27 echo -runtimedebug printout runtime debug messages
28 echo "-thread use support for multiple threads"
29 echo "-optimize call gcc with -O9 (optimize)"
30 echo "-nooptimize call gcc with -O0 (do not optimize)"
31 echo -curdir directory 
32 echo -mainclass class with main method
33 echo -o binary
34 echo -nojava do not run bristlecone compiler
35 echo -instructionfailures inject code for instructionfailures
36 echo -profile build with profile options
37 echo "-enable-assertions execute assert statements during compilation"
38 echo -help help
39 }
40
41 ROBUSTROOT=~/research/Robust/src
42 DSMRUNTIME=$ROBUSTROOT/Runtime/DSTM/interface/
43 REPAIRROOT=~/research/Repair/RepairCompiler/
44 CURDIR=`pwd`
45 DSMFLAG=false
46 NOJAVA=false
47 CHECKFLAG=false
48 RECOVERFLAG=false
49 MULTICOREFLAG=false
50 TRANSSTATSFLAG=false
51 RAWFLAG=false
52 THREADSIMULATEFLAG=false;
53 USEDMALLOC=false
54 THREADFLAG=false
55 SPECDIR=`pwd`
56 SRCFILES=''
57 EXTRAOPTIONS=''
58 MAINFILE='a'
59 JAVAFORWARDOPTS=''
60 JAVAOPTS=''
61 OPTIONALFLAG=false
62
63 if [[ -z $1 ]]
64 then
65 printhelp
66 exit
67 fi
68
69 while [[ -n $1 ]]
70 do
71 if [[ $1 = '-help' ]]
72 then
73 printhelp
74 exit
75 elif [[ $1 = '-robustroot' ]]
76 then
77 ROBUSTROOT="$2"
78 shift
79 elif [[ $1 = '-nojava' ]]
80 then
81 NOJAVA=true
82 elif [[ $1 = '-o' ]]
83 then
84 MAINFILE="$2"
85 shift
86 elif [[ $1 = '-mainclass' ]]
87 then
88 JAVAOPTS="$JAVAOPTS -mainclass $2"
89 shift
90 elif [[ $1 = '-selfloop' ]]
91 then
92 JAVAOPTS="$JAVAOPTS -selfloop $2"
93 shift
94 elif [[ $1 = '-excprefetch' ]]
95 then
96 JAVAOPTS="$JAVAOPTS -excprefetch $2"
97 shift
98 elif [[ $1 = '-dsm' ]]
99 then
100 JAVAOPTS="$JAVAOPTS -dsm"
101 DSMFLAG=true
102 elif [[ $1 = '-prefetch' ]]
103 then
104 JAVAOPTS="$JAVAOPTS -prefetch"
105 elif [[ $1 = '-transstats' ]]
106 then
107 TRANSSTATSFLAG=true
108 elif [[ $1 = '-printflat' ]]
109 then
110 JAVAOPTS="$JAVAOPTS -printflat"
111 elif [[ $1 = '-trueprob' ]]
112 then
113 JAVAOPTS="$JAVAOPTS -trueprob $2"
114 shift
115 elif [[ $1 = '-mac' ]]
116 then
117 EXTRAOPTIONS="$EXTRAOPTIONS -DMAC"
118 elif [[ $1 = '-profile' ]]
119 then
120 EXTRAOPTIONS="$EXTRAOPTIONS -pg"
121 elif [[ $1 = '-taskstate' ]]
122 then
123 JAVAOPTS="$JAVAOPTS -taskstate"
124 elif [[ $1 = '-tagstate' ]]
125 then
126 JAVAOPTS="$JAVAOPTS -tagstate"
127 elif [[ $1 = '-scheduling' ]]
128 then
129 JAVAOPTS="$JAVAOPTS -scheduling"
130 elif [[ $1 = '-multicore' ]]
131 then
132 MULTICOREFLAG=true
133 JAVAOPTS="$JAVAOPTS -multicore"
134 elif [[ $1 = '-numcore' ]]
135 then
136 JAVAOPTS="$JAVAOPTS -numcore $2"
137 shift
138 elif [[ $1 = '-raw' ]]
139 then
140 RAWFLAG=true
141 #JAVAOPTS="$JAVAOPTS -raw"
142 elif [[ $1 = '-threadsimulate' ]]
143 then
144 THREADSIMULATEFLAG=true
145 elif [[ $1 = '-optional' ]]
146 then
147 JAVAOPTS="$JAVAOPTS -optional"
148 OPTIONALFLAG=true
149 elif [[ $1 = '-dmalloc' ]]
150 then
151 USEDMALLOC=true
152 elif [[ $1 = '-recover' ]]
153 then
154 RECOVERFLAG=true
155 JAVAOPTS="$JAVAOPTS -task"
156 elif [[ $1 = '-webinterface' ]]
157 then
158 JAVAOPTS="$JAVAOPTS -webinterface"
159 elif [[ $1 = '-instructionfailures' ]]
160 then
161 JAVAOPTS="$JAVAOPTS -instructionfailures"
162 elif [[ $1 = '-check' ]]
163 then
164 CHECKFLAG=true
165 JAVAOPTS="$JAVAOPTS -conscheck"
166 elif [[ $1 = '-enable-assertions' ]]
167 then
168 JAVAFORWARDOPTS="$JAVAFORWARDOPTS -ea"
169 elif [[ $1 = '-specdir' ]]
170 then
171 cd $2
172 SPECDIR=`pwd`
173 cd $CURDIR
174 shift
175 elif [[ $1 = '-debug' ]]
176 then
177 EXTRAOPTIONS="$EXTRAOPTIONS -g"
178 elif [[ $1 = '-runtimedebug' ]]
179 then
180 EXTRAOPTIONS="$EXTRAOPTIONS -DDEBUG"
181 elif [[ $1 = '-nooptimize' ]]
182 then
183 EXTRAOPTIONS="$EXTRAOPTIONS -O0"
184 elif [[ $1 = '-optimize' ]]
185 then
186 EXTRAOPTIONS="$EXTRAOPTIONS -O9"
187 elif [[ $1 = '-thread' ]]
188 then
189 JAVAOPTS="$JAVAOPTS -thread"
190 EXTRAOPTIONS="$EXTRAOPTIONS -DTHREADS -lpthread"
191 THREADFLAG=true
192 elif [[ $1 = '-curdir' ]]
193 then
194 CURDIR=$2
195 shift
196 else
197 SRCFILES="$SRCFILES $1"
198 fi
199 shift
200 done
201
202 BUILDDIR="$CURDIR/tmpbuilddirectory"
203
204 cd $1
205 cd $CURDIR
206 shift
207
208 mkdir $BUILDDIR
209
210 if $CHECKFLAG #Generate structure files for repair tool
211 then
212 JAVAOPTS="$JAVAOPTS -struct structfile"
213 fi
214
215 # Build bristlecone/java sources
216
217 if $MULTICOREFLAG
218 then
219 if ! java $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
220 $ROBUSTROOT/ClassLibrary/ -dir $BUILDDIR \
221 $JAVAOPTS $SRCFILES
222 then exit $?
223 fi
224 else
225 #if ! java -Xms5m -Xmx100m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
226 if ! $NOJAVA
227 then
228 if ! java -Xms5m -Xmx100m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
229 $ROBUSTROOT/ClassLibrary/ -dir $BUILDDIR -precise \
230 $JAVAOPTS $SRCFILES
231 then exit $?
232 fi
233 fi
234 fi
235
236 # Build all of the consistency specs
237
238 if $CHECKFLAG # CHECKFLAG
239 then
240 cd $SPECDIR
241 mkdir $BUILDDIR/specdir
242 cp $REPAIRROOT/MCC/CRuntime/* $BUILDDIR/specdir
243
244 echo > $BUILDDIR/specs
245
246 # compile specs into C code
247 for i in * # iterate over all directories
248 do
249 if [[ "$i" != "CVS" ]] # CVSDIR CHECK
250 then
251 cd $SPECDIR/$i
252 cat $BUILDDIR/structfile.struct $i.label > $i.struct
253 java -cp $REPAIRROOT/:. MCC.Compiler -name $i -checkonly $i
254 cp size.[c,h] $BUILDDIR/specdir
255 cp $i.c $i\_aux.[c,h] $BUILDDIR/specdir
256 echo $i >> $BUILDDIR/specs
257 fi # CVSDIR CHECK
258 done # iterate over all directories
259
260 #compile C code
261
262 cd $BUILDDIR/specdir
263 ./buildrobust
264 echo > $BUILDDIR/checkers.h
265 for i in `cat $BUILDDIR/specs`
266 do
267 gcc -O0 -g -fbounds-check -c $i\_aux.c
268 echo \#include \"specdir\/$i\_aux.h\" >> $BUILDDIR/checkers.h
269 done
270 fi # CHECKFLAG
271
272 #build and link everything
273
274 cd $CURDIR 
275
276 INCLUDES="$INCLUDES -I$ROBUSTROOT/Runtime -I. -IRuntime/include \
277 -I$BUILDDIR"
278
279 if $MULTICOREFLAG
280 then
281 RUNTIMEFILE="$ROBUSTROOT/Runtime/multicoreruntime.c $ROBUSTROOT/Runtime/multicoretask.c"
282 else
283 RUNTIMEFILE="$ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/task.c"
284 fi
285
286 FILES="$RUNTIMEFILE \
287 $ROBUSTROOT/Runtime/file.c $ROBUSTROOT/Runtime/Queue.c \
288 $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/option.c \
289 $ROBUSTROOT/Runtime/ObjectHash.c \
290 $ROBUSTROOT/Runtime/garbage.c $ROBUSTROOT/Runtime/socket.c \
291 $ROBUSTROOT/Runtime/math.c \
292 $ROBUSTROOT/Runtime/signal.c \
293 $ROBUSTROOT/Runtime/GenericHashtable.c $ROBUSTROOT/Runtime/object.c"
294
295 if $DSMFLAG
296 then
297 EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DCOMPILER -DDSTM -I$DSMRUNTIME"
298 if $TRANSSTATSFLAG
299 then
300 EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DTRANSSTATS -DCOMPILER -DDSTM -I$DSMRUNTIME"
301 fi
302 FILES="$FILES $DSMRUNTIME/trans.c $DSMRUNTIME/mcpileq.c $DSMRUNTIME/objstr.c $DSMRUNTIME/dstm.c $DSMRUNTIME/mlookup.c $DSMRUNTIME/clookup.c $DSMRUNTIME/llookup.c $DSMRUNTIME/threadnotify.c $DSMRUNTIME/dstmserver.c $DSMRUNTIME/plookup.c $DSMRUNTIME/ip.c $DSMRUNTIME/queue.c $DSMRUNTIME/prelookup.c $DSMRUNTIME/machinepile.c $DSMRUNTIME/localobjects.c $ROBUSTROOT/Runtime/thread.c $DSMRUNTIME/sockpool.c $DSMRUNTIME/addUdpEnhance.c"
303 fi
304
305 if $RECOVERFLAG
306 then
307 EXTRAOPTIONS="$EXTRAOPTIONS -DTASK"
308 if $MULTICOREFLAG
309 then
310 EXTRAOPTIONS="$EXTRAOPTIONS -DMULTICORE"
311 fi
312 FILES="$FILES tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/checkpoint.c"
313 if $RAWFLAG
314 then
315 EXTRAOPTIONS="$EXTRAOPTIONS -DRAW"
316 fi
317 if $THREADSIMULATEFLAG
318 then
319 # -lpthread for pthread functions, -lrt for message queue functions
320 EXTRAOPTIONS="$EXTRAOPTIONS -DTHREADSIMULATE -lpthread -lrt"
321 fi
322 fi
323
324 if $OPTIONALFLAG
325 then
326 EXTRAOPTIONS="$EXTRAOPTIONS -DOPTIONAL"
327 FILES="$FILES tmpbuilddirectory/optionalarrays.c"
328 fi
329
330 if $THREADFLAG
331 then
332 FILES="$FILES $ROBUSTROOT/Runtime/thread.c"
333 fi
334
335 if $CHECKFLAG
336 then
337 EXTRAOPTIONS="$EXTRAOPTIONS -DCONSCHECK $BUILDDIR/specdir/*.o"
338 INCLUDES="$INCLUDES -I$BUILDDIR/specdir"
339 fi
340
341 if $USEDMALLOC
342 then
343 EXTRAOPTIONS="$EXTRAOPTIONS -ldmalloc -DDMALLOC"
344 fi
345
346 if $MULTICOREFLAG
347 then
348 gcc $INCLUDES $EXTRAOPTIONS \
349 tmpbuilddirectory/methods.c $FILES -lm -o $MAINFILE.bin
350 else
351 gcc $INCLUDES $EXTRAOPTIONS -DPRECISE_GC \
352 tmpbuilddirectory/methods.c $FILES -lm -o $MAINFILE.bin
353 fi
354
355 exit
356