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