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