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