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