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