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