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