Feature adds to webinterface:
[IRC.git] / Robust / src / buildscript
1 #!/bin/bash
2
3 printhelp() {
4 echo -check generate check code
5 echo -dmalloc link in dmalloc
6 echo -recover compile task code
7 echo -specdir directory
8 echo -taskstate do task state analysis
9 echo -debug generate debug symbols
10 echo -webinterface enable web interface
11 echo -runtimedebug printout runtime debug messages
12 echo "-thread use support for multiple threads"
13 echo "-optimize call gcc with -O9 (optimize)"
14 echo "-nooptimize call gcc with -O0 (do not optimize)"
15 echo -curdir directory 
16 echo -mainclass class with main method
17 echo -o binary
18 echo -instructionfailures inject code for instructionfailures
19 echo -help help
20 }
21
22 ROBUSTROOT=~/research/Robust/src
23 REPAIRROOT=~/research/Repair/RepairCompiler/
24 CURDIR=`pwd`
25 CHECKFLAG=false
26 RECOVERFLAG=false
27 USEDMALLOC=false
28 THREADFLAG=false
29 SPECDIR=`pwd`
30 SRCFILES=''
31 EXTRAOPTIONS=''
32 MAINFILE='a'
33 JAVAOPTS=''
34
35 if [[ -z $1 ]]
36 then
37 printhelp
38 exit
39 fi
40
41 while [[ -n $1 ]]
42 do
43 if [[ $1 = '-help' ]]
44 then
45 printhelp
46 exit
47 elif [[ $1 = '-o' ]]
48 then
49 MAINFILE="$2"
50 shift
51 elif [[ $1 = '-mainclass' ]]
52 then
53 JAVAOPTS="$JAVAOPTS -mainclass $2"
54 shift
55 elif [[ $1 = '-taskstate' ]]
56 then
57 JAVAOPTS="$JAVAOPTS -taskstate"
58 elif [[ $1 = '-dmalloc' ]]
59 then
60 USEDMALLOC=true
61 elif [[ $1 = '-recover' ]]
62 then
63 RECOVERFLAG=true
64 JAVAOPTS="$JAVAOPTS -task"
65 elif [[ $1 = '-webinterface' ]]
66 then
67 JAVAOPTS="$JAVAOPTS -webinterface"
68 elif [[ $1 = '-instructionfailures' ]]
69 then
70 JAVAOPTS="$JAVAOPTS -instructionfailures"
71 elif [[ $1 = '-check' ]]
72 then
73 CHECKFLAG=true
74 JAVAOPTS="$JAVAOPTS -conscheck"
75 elif [[ $1 = '-specdir' ]]
76 then
77 cd $2
78 SPECDIR=`pwd`
79 cd $CURDIR
80 shift
81 elif [[ $1 = '-debug' ]]
82 then
83 EXTRAOPTIONS="$EXTRAOPTIONS -g"
84 elif [[ $1 = '-runtimedebug' ]]
85 then
86 EXTRAOPTIONS="$EXTRAOPTIONS -DDEBUG"
87 elif [[ $1 = '-nooptimize' ]]
88 then
89 EXTRAOPTIONS="$EXTRAOPTIONS -O0"
90 elif [[ $1 = '-optimize' ]]
91 then
92 EXTRAOPTIONS="$EXTRAOPTIONS -O9"
93 elif [[ $1 = '-thread' ]]
94 then
95 JAVAOPTS="$JAVAOPTS -thread"
96 EXTRAOPTIONS="$EXTRAOPTIONS -DTHREADS -lpthread"
97 THREADFLAG=true
98 elif [[ $1 = '-curdir' ]]
99 then
100 CURDIR=$2
101 shift
102 else
103 SRCFILES="$SRCFILES $1"
104 fi
105 shift
106 done
107
108 BUILDDIR="$CURDIR/tmpbuilddirectory"
109
110 cd $1
111 cd $CURDIR
112 shift
113
114 mkdir $BUILDDIR
115
116 if $CHECKFLAG #Generate structure files for repair tool
117 then
118 JAVAOPTS="$JAVAOPTS -struct structfile"
119 fi
120
121 # Build bristlecone/java sources
122
123 java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
124 $ROBUSTROOT/ClassLibrary/ -dir $BUILDDIR -precise \
125 $JAVAOPTS $SRCFILES
126
127 # Build all of the consistency specs
128
129 if $CHECKFLAG # CHECKFLAG
130 then
131 cd $SPECDIR
132 mkdir $BUILDDIR/specdir
133 cp $REPAIRROOT/MCC/CRuntime/* $BUILDDIR/specdir
134
135 echo > $BUILDDIR/specs
136
137 # compile specs into C code
138 for i in * # iterate over all directories
139 do
140 if [[ "$i" != "CVS" ]] # CVSDIR CHECK
141 then
142 cd $SPECDIR/$i
143 cat $BUILDDIR/structfile.struct $i.label > $i.struct
144 java -cp $REPAIRROOT/:. MCC.Compiler -name $i -checkonly $i
145 cp size.[c,h] $BUILDDIR/specdir
146 cp $i.c $i\_aux.[c,h] $BUILDDIR/specdir
147 echo $i >> $BUILDDIR/specs
148 fi # CVSDIR CHECK
149 done # iterate over all directories
150
151 #compile C code
152
153 cd $BUILDDIR/specdir
154 ./buildrobust
155 echo > $BUILDDIR/checkers.h
156 for i in `cat $BUILDDIR/specs`
157 do
158 gcc -O0 -g -c $i\_aux.c
159 echo \#include \"specdir\/$i\_aux.h\" >> $BUILDDIR/checkers.h
160 done
161 fi # CHECKFLAG
162
163 #build and link everything
164
165 cd $CURDIR 
166
167 INCLUDES="$INCLUDES -I$ROBUSTROOT/Runtime -I. -IRuntime/include \
168 -I$BUILDDIR"
169
170 FILES="$ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/file.c \
171 $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c \
172 $ROBUSTROOT/Runtime/option.c $ROBUSTROOT/Runtime/garbage.c \
173 $ROBUSTROOT/Runtime/socket.c $ROBUSTROOT/Runtime/GenericHashtable.c \
174 $ROBUSTROOT/Runtime/object.c"
175
176 if $RECOVERFLAG
177 then
178 EXTRAOPTIONS="$EXTRAOPTIONS -DTASK"
179 FILES="$FILES tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/checkpoint.c"
180 fi
181
182 if $THREADFLAG
183 then
184 FILES="$FILES $ROBUSTROOT/Runtime/thread.c"
185 fi
186
187 if $CHECKFLAG
188 then
189 EXTRAOPTIONS="$EXTRAOPTIONS -DCONSCHECK $BUILDDIR/specdir/*.o"
190 INCLUDES="$INCLUDES -I$BUILDDIR/specdir"
191 fi
192
193 if $USEDMALLOC
194 then
195 EXTRAOPTIONS="$EXTRAOPTIONS -ldmalloc -DDMALLOC"
196 fi
197
198 gcc $INCLUDES $EXTRAOPTIONS -DPRECISE_GC \
199 tmpbuilddirectory/methods.c $FILES -o $MAINFILE.bin
200
201 exit
202