changes
[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 -dsmcaching -enable caching in dsm runtime
8 echo -mac distributed shared memory mac support
9 echo -check generate check code
10 echo -dmalloc link in dmalloc
11 echo -recover compile task code
12 echo -fastcheck fast checkpointing for Bristlecone
13 echo -specdir directory
14 echo -printflat print out flat representation
15 echo -selfloop task - this task cannot self loop forever
16 echo "-excprefetch methoddescriptor - exclude prefetches for this method (specified as class.method)"
17 echo -taskstate do task state analysis
18 echo -tagstate do tag state analysis
19 echo -scheduling do task scheduling
20 echo -multicore generate multi-core version binary
21 echo "-numcore set the number of cores (should be used together with -multicore), defaultly set as 1"
22 echo "-raw generate raw version binary (should be used together with -multicore)"
23 echo "-rawcacheflush enable cache flush in raw version binary (should be used togethere with -raw)"
24 echo "-interrupt generate raw version binary with interruption (should be used togethere with -raw)"
25 echo "-rawconfig config raw simulator as 4xn (should be used together with -raw)"
26 echo "-rawpath print out execute path information for raw version (should be used together with -raw)"
27 echo "-useprofile use profiling data for scheduling (should be used together with -raw)"
28 echo -threadsimulate generate multi-thread simulate version binary
29 echo -printscheduling print out scheduling graphs
30 echo -printschedulesim print out scheduling simulator result graphs
31 echo -optional enable optional
32 echo -debug generate debug symbols
33 echo -prefetch do prefetch analysis
34 echo -transstats generates transaction stats on commits and aborts
35 echo -webinterface enable web interface
36 echo -runtimedebug printout runtime debug messages
37 echo "-thread use support for multiple threads"
38 echo "-optimize call gcc with -O9 (optimize)"
39 echo "-nooptimize call gcc with -O0 (do not optimize)"
40 echo -curdir directory 
41 echo -mainclass class with main method
42 echo -o binary
43 echo -nojava do not run bristlecone compiler
44 echo -instructionfailures inject code for instructionfailures
45 echo -profile build with profile options
46 echo "-rawuseio use standard io to output profiling data (should be used together with -raw and -profile), it only works with single core version"
47 echo "-enable-assertions execute assert statements during compilation"
48 echo -help help
49 }
50
51 ROBUSTROOT=~/research/Robust/src
52 DSMRUNTIME=$ROBUSTROOT/Runtime/DSTM/interface/
53 REPAIRROOT=~/research/Repair/RepairCompiler/
54 CURDIR=`pwd`
55 DSMFLAG=false
56 NOJAVA=false
57 CHECKFLAG=false
58 RECOVERFLAG=false
59 MULTICOREFLAG=false
60 TRANSSTATSFLAG=false
61 RAWFLAG=false
62 RAWCACHEFLUSHFLAG=false
63 RAWCONFIG=''
64 RAWDEBUGFLAG=false
65 RAWPATHFLAG=false
66 RAWPROFILEFLAG=false
67 RAWUSEIOFLAG=false
68 INTERRUPTFLAG=false
69 THREADSIMULATEFLAG=false;
70 USEDMALLOC=false
71 THREADFLAG=false
72 FASTCHECK=false
73 SPECDIR=`pwd`
74 SRCFILES=''
75 EXTRAOPTIONS=''
76 MAINFILE='a'
77 JAVAFORWARDOPTS=''
78 JAVAOPTS=''
79 OPTIONALFLAG=false
80
81 if [[ -z $1 ]]
82 then
83 printhelp
84 exit
85 fi
86
87 while [[ -n $1 ]]
88 do
89 if [[ $1 = '-help' ]]
90 then
91 printhelp
92 exit
93 elif [[ $1 = '-robustroot' ]]
94 then
95 ROBUSTROOT="$2"
96 shift
97 elif [[ $1 = '-nojava' ]]
98 then
99 NOJAVA=true
100 elif [[ $1 = '-fastcheck' ]]
101 then
102 EXTRAOPTIONS="$EXTRAOPTIONS -DFASTCHECK"
103 JAVAOPTS="$JAVAOPTS -fastcheck"
104 FASTCHECK=true
105 elif [[ $1 = '-o' ]]
106 then
107 MAINFILE="$2"
108 shift
109 elif [[ $1 = '-mainclass' ]]
110 then
111 JAVAOPTS="$JAVAOPTS -mainclass $2"
112 shift
113 elif [[ $1 = '-selfloop' ]]
114 then
115 JAVAOPTS="$JAVAOPTS -selfloop $2"
116 shift
117 elif [[ $1 = '-excprefetch' ]]
118 then
119 JAVAOPTS="$JAVAOPTS -excprefetch $2"
120 shift
121 elif [[ $1 = '-dsm' ]]
122 then
123 JAVAOPTS="$JAVAOPTS -dsm"
124 DSMFLAG=true
125 elif [[ $1 = '-prefetch' ]]
126 then
127 JAVAOPTS="$JAVAOPTS -prefetch"
128 elif [[ $1 = '-transstats' ]]
129 then
130 TRANSSTATSFLAG=true
131 elif [[ $1 = '-printflat' ]]
132 then
133 JAVAOPTS="$JAVAOPTS -printflat"
134 elif [[ $1 = '-trueprob' ]]
135 then
136 JAVAOPTS="$JAVAOPTS -trueprob $2"
137 shift
138 elif [[ $1 = '-mac' ]]
139 then
140 EXTRAOPTIONS="$EXTRAOPTIONS -DMAC"
141 elif [[ $1 = '-profile' ]]
142 then
143 RAWPROFILEFLAG=true
144 EXTRAOPTIONS="$EXTRAOPTIONS -pg"
145 elif [[ $1 = '-rawuseio' ]]
146 then
147 RAWUSEIOFLAG=true
148 elif [[ $1 = '-taskstate' ]]
149 then
150 JAVAOPTS="$JAVAOPTS -taskstate"
151 elif [[ $1 = '-tagstate' ]]
152 then
153 JAVAOPTS="$JAVAOPTS -tagstate"
154 elif [[ $1 = '-scheduling' ]]
155 then
156 JAVAOPTS="$JAVAOPTS -scheduling"
157 elif [[ $1 = '-multicore' ]]
158 then
159 MULTICOREFLAG=true
160 JAVAOPTS="$JAVAOPTS -multicore"
161 elif [[ $1 = '-numcore' ]]
162 then
163 JAVAOPTS="$JAVAOPTS -numcore $2"
164 shift
165 elif [[ $1 = '-raw' ]]
166 then
167 RAWFLAG=true
168 JAVAOPTS="$JAVAOPTS -raw"
169 elif [[ $1 = '-rawcacheflush' ]]
170 then
171 RAWCACHEFLUSHFLAG=true
172 elif [[ $1 = '-rawconfig' ]]
173 then
174 RAWCONFIG="$2"
175 shift
176 elif [[ $1 = '-interrupt' ]]
177 then
178 INTERRUPTFLAG=true
179 elif [[ $1 = '-threadsimulate' ]]
180 then
181 THREADSIMULATEFLAG=true
182 elif [[ $1 = '-optional' ]]
183 then
184 JAVAOPTS="$JAVAOPTS -optional"
185 OPTIONALFLAG=true
186 elif [[ $1 = '-dmalloc' ]]
187 then
188 USEDMALLOC=true
189 elif [[ $1 = '-recover' ]]
190 then
191 RECOVERFLAG=true
192 JAVAOPTS="$JAVAOPTS -task"
193 elif [[ $1 = '-useprofile' ]]
194 then
195 JAVAOPTS="$JAVAOPTS -useprofile"
196 elif [[ $1 = '-webinterface' ]]
197 then
198 JAVAOPTS="$JAVAOPTS -webinterface"
199 elif [[ $1 = '-instructionfailures' ]]
200 then
201 JAVAOPTS="$JAVAOPTS -instructionfailures"
202 elif [[ $1 = '-check' ]]
203 then
204 CHECKFLAG=true
205 JAVAOPTS="$JAVAOPTS -conscheck"
206 elif [[ $1 = '-enable-assertions' ]]
207 then
208 JAVAFORWARDOPTS="$JAVAFORWARDOPTS -ea"
209 elif [[ $1 = '-specdir' ]]
210 then
211 cd $2
212 SPECDIR=`pwd`
213 cd $CURDIR
214 shift
215 elif [[ $1 = '-debug' ]]
216 then
217 RAWDEBUGFLAG=true
218 EXTRAOPTIONS="$EXTRAOPTIONS -g"
219 elif [[ $1 = '-rawpath' ]]
220 then
221 RAWPATHFLAG=true
222 elif [[ $1 = '-runtimedebug' ]]
223 then
224 EXTRAOPTIONS="$EXTRAOPTIONS -DDEBUG"
225 elif [[ $1 = '-dsmcaching' ]]
226 then
227 EXTRAOPTIONS="$EXTRAOPTIONS -DCACHE"
228 elif [[ $1 = '-rangeprefetch' ]]
229 then
230 EXTRAOPTIONS="$EXTRAOPTIONS -DRANGEPREFETCH"
231 elif [[ $1 = '-nooptimize' ]]
232 then
233 EXTRAOPTIONS="$EXTRAOPTIONS -O0"
234 elif [[ $1 = '-optimize' ]]
235 then
236 EXTRAOPTIONS="$EXTRAOPTIONS -O9"
237 elif [[ $1 = '-thread' ]]
238 then
239 JAVAOPTS="$JAVAOPTS -thread"
240 EXTRAOPTIONS="$EXTRAOPTIONS -DTHREADS -lpthread"
241 THREADFLAG=true
242 elif [[ $1 = '-curdir' ]]
243 then
244 CURDIR=$2
245 shift
246 else
247 SRCFILES="$SRCFILES $1"
248 fi
249 shift
250 done
251
252 BUILDDIR="$CURDIR/tmpbuilddirectory"
253
254 cd $1
255 cd $CURDIR
256 shift
257
258 mkdir $BUILDDIR
259
260 if $CHECKFLAG #Generate structure files for repair tool
261 then
262 JAVAOPTS="$JAVAOPTS -struct structfile"
263 fi
264
265 # Build bristlecone/java sources
266
267 if $MULTICOREFLAG
268 then
269 if ! ${ROBUSTROOT}/ourjava -Xms50m -Xmx800m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
270 $ROBUSTROOT/ClassLibrary/ -dir $BUILDDIR \
271 $JAVAOPTS $SRCFILES
272 then exit $?
273 fi
274 else
275 #if ! ${ROBUSTROOT}/ourjava -Xms5m -Xmx100m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
276 if ! $NOJAVA
277 then
278 if ! ${ROBUSTROOT}/ourjava -Xms50m -Xmx600m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
279 $ROBUSTROOT/ClassLibrary/ -dir $BUILDDIR -precise \
280 $JAVAOPTS $SRCFILES
281 then exit $?
282 fi
283 fi
284 fi
285
286 # Build all of the consistency specs
287
288 if $CHECKFLAG # CHECKFLAG
289 then
290 cd $SPECDIR
291 mkdir $BUILDDIR/specdir
292 cp $REPAIRROOT/MCC/CRuntime/* $BUILDDIR/specdir
293
294 echo > $BUILDDIR/specs
295
296 # compile specs into C code
297 for i in * # iterate over all directories
298 do
299 if [[ "$i" != "CVS" ]] # CVSDIR CHECK
300 then
301 cd $SPECDIR/$i
302 cat $BUILDDIR/structfile.struct $i.label > $i.struct
303 java -cp $REPAIRROOT/:. MCC.Compiler -name $i -checkonly $i
304 cp size.[c,h] $BUILDDIR/specdir
305 cp $i.c $i\_aux.[c,h] $BUILDDIR/specdir
306 echo $i >> $BUILDDIR/specs
307 fi # CVSDIR CHECK
308 done # iterate over all directories
309
310 #compile C code
311
312 cd $BUILDDIR/specdir
313 ./buildrobust
314 echo > $BUILDDIR/checkers.h
315 for i in `cat $BUILDDIR/specs`
316 do
317 gcc -O0 -g -fbounds-check -c $i\_aux.c
318 echo \#include \"specdir\/$i\_aux.h\" >> $BUILDDIR/checkers.h
319 done
320 fi # CHECKFLAG
321
322 #build and link everything
323
324 if $RAWFLAG
325 then # RAWFLAG
326 RAWDIR="$CURDIR/raw"
327 MAKEFILE="../Makefile.raw"
328 mkdir $RAWDIR
329 cd $RAWDIR
330 make clean
331 rm ./*
332
333 export RAWRGCCFLAGS="-DTASK -DMULTICORE -DRAW"
334
335 if $RAWCACHEFLUSHFLAG
336 then # print path
337 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWCACHEFLUSH"
338 fi
339
340 if $RAWPATHFLAG
341 then # print path
342 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWPATH"
343 fi
344
345 if $RAWDEBUGFLAG
346 then #debug version
347 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWDEBUG"
348 fi
349
350 if $RAWPROFILEFLAG
351 then # profile version
352 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWPROFILE"
353 fi
354
355 if $RAWUSEIOFLAG
356 then # useio version
357 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWUSEIO"
358 fi
359
360 if $INTERRUPTFLAG
361 then #INTERRUPT version
362 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DINTERRUPT"
363 fi #INTERRUPT version
364
365 if $RAWUSEIOFLAG
366 then # useio version
367 MAKEFILE="$MAKEFILE.io"
368 echo "+++++++++++use Makefile.raw.io++++++++++++++++"
369 else
370 MAKEFILE="$MAKEFILE.$RAWCONFIG"
371 fi #useio version
372
373 cp $MAKEFILE ./Makefile
374 cp ../Runtime/*.c ./
375 cp ../Runtime/*.h ./
376 cp ../Runtime/*.S ./
377 cp ../Runtime/*.s ./
378 cp ../tmpbuilddirectory/*.c ./
379 cp ../tmpbuilddirectory/*.h ./
380
381 make
382
383 else #!RAWFLAG
384 cd $CURDIR 
385
386 INCLUDES="$INCLUDES -I$ROBUSTROOT/Runtime -I. -IRuntime/include \
387 -I$BUILDDIR"
388
389 if $MULTICOREFLAG
390 then
391 RUNTIMEFILE="$ROBUSTROOT/Runtime/multicoreruntime.c $ROBUSTROOT/Runtime/multicoretask.c"
392 else
393 RUNTIMEFILE="$ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/task.c"
394 fi
395
396 FILES="$RUNTIMEFILE \
397 $ROBUSTROOT/Runtime/file.c $ROBUSTROOT/Runtime/Queue.c \
398 $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/option.c \
399 $ROBUSTROOT/Runtime/ObjectHash.c \
400 $ROBUSTROOT/Runtime/garbage.c $ROBUSTROOT/Runtime/socket.c \
401 $ROBUSTROOT/Runtime/math.c \
402 $ROBUSTROOT/Runtime/GenericHashtable.c $ROBUSTROOT/Runtime/object.c"
403
404 if $DSMFLAG
405 then
406 EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DCOMPILER -DDSTM -I$DSMRUNTIME"
407 if $TRANSSTATSFLAG
408 then
409 EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DTRANSSTATS -DCOMPILER -DDSTM -I$DSMRUNTIME"
410 fi
411 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 $ROBUSTROOT/Runtime/localobjects.c $ROBUSTROOT/Runtime/thread.c $DSMRUNTIME/sockpool.c $DSMRUNTIME/addUdpEnhance.c $DSMRUNTIME/signal.c $DSMRUNTIME/gCollect.c $DSMRUNTIME/addPrefetchEnhance.c $DSMRUNTIME/dsmlock.c $DSMRUNTIME/prefetch.c"
412 fi
413
414 if $FASTCHECK
415 then
416 FILES="$FILES $ROBUSTROOT/Runtime/localobjects.c"
417 fi
418
419 if $RECOVERFLAG
420 then
421 EXTRAOPTIONS="$EXTRAOPTIONS -DTASK"
422 if $MULTICOREFLAG
423 then
424 EXTRAOPTIONS="$EXTRAOPTIONS -DMULTICORE"
425 fi
426 FILES="$FILES tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/checkpoint.c $ROBUSTROOT/Runtime/chash.c"
427 if $RAWFLAG
428 then
429 EXTRAOPTIONS="$EXTRAOPTIONS -DRAW"
430 fi
431 if $THREADSIMULATEFLAG
432 then
433 # -lpthread for pthread functions, -lrt for message queue functions
434 EXTRAOPTIONS="$EXTRAOPTIONS -DTHREADSIMULATE -lpthread -lrt"
435 fi
436 fi
437
438 if $OPTIONALFLAG
439 then
440 EXTRAOPTIONS="$EXTRAOPTIONS -DOPTIONAL"
441 FILES="$FILES tmpbuilddirectory/optionalarrays.c"
442 fi
443
444 if $THREADFLAG
445 then
446 FILES="$FILES $ROBUSTROOT/Runtime/thread.c"
447 fi
448
449 if $CHECKFLAG
450 then
451 EXTRAOPTIONS="$EXTRAOPTIONS -DCONSCHECK $BUILDDIR/specdir/*.o"
452 INCLUDES="$INCLUDES -I$BUILDDIR/specdir"
453 fi
454
455 if $USEDMALLOC
456 then
457 EXTRAOPTIONS="$EXTRAOPTIONS -ldmalloc -DDMALLOC"
458 fi
459
460 if $MULTICOREFLAG
461 then
462 gcc $INCLUDES $EXTRAOPTIONS \
463 tmpbuilddirectory/methods.c $FILES -lm -o $MAINFILE.bin
464 else
465 gcc $INCLUDES $EXTRAOPTIONS -DPRECISE_GC \
466 tmpbuilddirectory/methods.c $FILES -lm -o $MAINFILE.bin
467 fi
468
469 fi #!RAWFLAG
470
471 exit
472