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