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