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