start of new file
[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 EXTRAOPTIONS="$EXTRAOPTIONS -DCHECKTB"
195 elif [[ $1 = '-nooptimize' ]]
196 then
197 EXTRAOPTIONS="$EXTRAOPTIONS -O0"
198 elif [[ $1 = '-optimize' ]]
199 then
200 EXTRAOPTIONS="$EXTRAOPTIONS -O9"
201 elif [[ $1 = '-thread' ]]
202 then
203 JAVAOPTS="$JAVAOPTS -thread"
204 EXTRAOPTIONS="$EXTRAOPTIONS -DTHREADS -lpthread"
205 THREADFLAG=true
206 elif [[ $1 = '-curdir' ]]
207 then
208 CURDIR=$2
209 shift
210 else
211 SRCFILES="$SRCFILES $1"
212 fi
213 shift
214 done
215
216 BUILDDIR="$CURDIR/tmpbuilddirectory"
217
218 cd $1
219 cd $CURDIR
220 shift
221
222 mkdir $BUILDDIR
223
224 if $CHECKFLAG #Generate structure files for repair tool
225 then
226 JAVAOPTS="$JAVAOPTS -struct structfile"
227 fi
228
229 # Build bristlecone/java sources
230
231 if $MULTICOREFLAG
232 then
233 if ! java $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
234 $ROBUSTROOT/ClassLibrary/ -dir $BUILDDIR \
235 $JAVAOPTS $SRCFILES
236 then exit $?
237 fi
238 else
239 #if ! java -Xms5m -Xmx100m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
240 if ! $NOJAVA
241 then
242 if ! java -Xms5m -Xmx100m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
243 $ROBUSTROOT/ClassLibrary/ -dir $BUILDDIR -precise \
244 $JAVAOPTS $SRCFILES
245 then exit $?
246 fi
247 fi
248 fi
249
250 # Build all of the consistency specs
251
252 if $CHECKFLAG # CHECKFLAG
253 then
254 cd $SPECDIR
255 mkdir $BUILDDIR/specdir
256 cp $REPAIRROOT/MCC/CRuntime/* $BUILDDIR/specdir
257
258 echo > $BUILDDIR/specs
259
260 # compile specs into C code
261 for i in * # iterate over all directories
262 do
263 if [[ "$i" != "CVS" ]] # CVSDIR CHECK
264 then
265 cd $SPECDIR/$i
266 cat $BUILDDIR/structfile.struct $i.label > $i.struct
267 java -cp $REPAIRROOT/:. MCC.Compiler -name $i -checkonly $i
268 cp size.[c,h] $BUILDDIR/specdir
269 cp $i.c $i\_aux.[c,h] $BUILDDIR/specdir
270 echo $i >> $BUILDDIR/specs
271 fi # CVSDIR CHECK
272 done # iterate over all directories
273
274 #compile C code
275
276 cd $BUILDDIR/specdir
277 ./buildrobust
278 echo > $BUILDDIR/checkers.h
279 for i in `cat $BUILDDIR/specs`
280 do
281 gcc -O0 -g -fbounds-check -c $i\_aux.c
282 echo \#include \"specdir\/$i\_aux.h\" >> $BUILDDIR/checkers.h
283 done
284 fi # CHECKFLAG
285
286 #build and link everything
287
288 if $RAWFLAG
289 then # RAWFLAG
290 RAWDIR="$CURDIR/raw"
291 MAKEFILE="../Makefile.raw"
292 mkdir $RAWDIR
293 cd $RAWDIR
294 make clean
295 rm ./*
296
297 export RAWRGCCFLAGS="-DTASK -DMULTICORE -DRAW"
298
299 if $RAWDEBUGFLAG
300 then #debug version
301 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWDEBUG"
302 fi
303
304 if $INTERRUPTFLAG
305 then #INTERRUPT version
306 MAKEFILE="$MAKEFILE.i"
307 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DINTERRUPT"
308 fi #INTERRUPT version
309
310 MAKEFILE="$MAKEFILE.$RAWCONFIG"
311
312 cp $MAKEFILE ./Makefile
313 cp ../Runtime/*.c ./
314 cp ../Runtime/*.h ./
315 cp ../Runtime/*.S ./
316 cp ../Runtime/*.s ./
317 cp ../tmpbuilddirectory/*.c ./
318 cp ../tmpbuilddirectory/*.h ./
319
320 make
321
322 else #!RAWFLAG
323 cd $CURDIR 
324
325 INCLUDES="$INCLUDES -I$ROBUSTROOT/Runtime -I. -IRuntime/include \
326 -I$BUILDDIR"
327
328 if $MULTICOREFLAG
329 then
330 RUNTIMEFILE="$ROBUSTROOT/Runtime/multicoreruntime.c $ROBUSTROOT/Runtime/multicoretask.c"
331 else
332 RUNTIMEFILE="$ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/task.c"
333 fi
334
335 FILES="$RUNTIMEFILE \
336 $ROBUSTROOT/Runtime/file.c $ROBUSTROOT/Runtime/Queue.c \
337 $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/option.c \
338 $ROBUSTROOT/Runtime/ObjectHash.c \
339 $ROBUSTROOT/Runtime/garbage.c $ROBUSTROOT/Runtime/socket.c \
340 $ROBUSTROOT/Runtime/math.c \
341 $ROBUSTROOT/Runtime/GenericHashtable.c $ROBUSTROOT/Runtime/object.c"
342
343 if $DSMFLAG
344 then
345 EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DCOMPILER -DDSTM -I$DSMRUNTIME"
346 if $TRANSSTATSFLAG
347 then
348 EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DTRANSSTATS -DCOMPILER -DDSTM -I$DSMRUNTIME"
349 fi
350 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"
351 fi
352
353 if $RECOVERFLAG
354 then
355 EXTRAOPTIONS="$EXTRAOPTIONS -DTASK"
356 if $MULTICOREFLAG
357 then
358 EXTRAOPTIONS="$EXTRAOPTIONS -DMULTICORE"
359 fi
360 FILES="$FILES tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/checkpoint.c"
361 if $RAWFLAG
362 then
363 EXTRAOPTIONS="$EXTRAOPTIONS -DRAW"
364 fi
365 if $THREADSIMULATEFLAG
366 then
367 # -lpthread for pthread functions, -lrt for message queue functions
368 EXTRAOPTIONS="$EXTRAOPTIONS -DTHREADSIMULATE -lpthread -lrt"
369 fi
370 fi
371
372 if $OPTIONALFLAG
373 then
374 EXTRAOPTIONS="$EXTRAOPTIONS -DOPTIONAL"
375 FILES="$FILES tmpbuilddirectory/optionalarrays.c"
376 fi
377
378 if $THREADFLAG
379 then
380 FILES="$FILES $ROBUSTROOT/Runtime/thread.c"
381 fi
382
383 if $CHECKFLAG
384 then
385 EXTRAOPTIONS="$EXTRAOPTIONS -DCONSCHECK $BUILDDIR/specdir/*.o"
386 INCLUDES="$INCLUDES -I$BUILDDIR/specdir"
387 fi
388
389 if $USEDMALLOC
390 then
391 EXTRAOPTIONS="$EXTRAOPTIONS -ldmalloc -DDMALLOC"
392 fi
393
394 if $MULTICOREFLAG
395 then
396 gcc $INCLUDES $EXTRAOPTIONS \
397 tmpbuilddirectory/methods.c $FILES -lm -o $MAINFILE.bin
398 else
399 gcc $INCLUDES $EXTRAOPTIONS -DPRECISE_GC \
400 tmpbuilddirectory/methods.c $FILES -lm -o $MAINFILE.bin
401 fi
402
403 fi #!RAWFLAG
404
405 exit
406