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