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