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