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