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