Bug fixed in BuildCode.
[IRC.git] / Robust / src / buildscript
index b7a0c04acb311e6f946ac033585c7251e016abe9..1c73bf726b4b30bd08df3a1123ae3bfd015b1ccc 100755 (executable)
@@ -1,7 +1,218 @@
 #!/bin/bash
+
+printhelp() {
+echo -dsm distributed shared memory
+echo -check generate check code
+echo -dmalloc link in dmalloc
+echo -recover compile task code
+echo -specdir directory
+echo -taskstate do task state analysis
+echo -optional enable optional
+echo -debug generate debug symbols
+echo -webinterface enable web interface
+echo -runtimedebug printout runtime debug messages
+echo "-thread use support for multiple threads"
+echo "-optimize call gcc with -O9 (optimize)"
+echo "-nooptimize call gcc with -O0 (do not optimize)"
+echo -curdir directory 
+echo -mainclass class with main method
+echo -o binary
+echo -instructionfailures inject code for instructionfailures
+echo -help help
+}
+
 ROBUSTROOT=~/research/Robust/src
-MAINFILE=$1
+REPAIRROOT=~/research/Repair/RepairCompiler/
+CURDIR=`pwd`
+CHECKFLAG=false
+RECOVERFLAG=false
+USEDMALLOC=false
+THREADFLAG=false
+SPECDIR=`pwd`
+SRCFILES=''
+EXTRAOPTIONS=''
+MAINFILE='a'
+JAVAOPTS=''
+OPTIONALFLAG=false
+
+if [[ -z $1 ]]
+then
+printhelp
+exit
+fi
+
+while [[ -n $1 ]]
+do
+if [[ $1 = '-help' ]]
+then
+printhelp
+exit
+elif [[ $1 = '-o' ]]
+then
+MAINFILE="$2"
 shift
-mkdir tmpbuilddirectory
-java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary $ROBUSTROOT/ClassLibrary/ -dir tmpbuilddirectory -mainclass $MAINFILE $@
-gcc -I$ROBUSTROOT/Runtime -Itmpbuilddirectory -O0 -g tmpbuilddirectory/methods.c $ROBUSTROOT/Runtime/runtime.c -o $MAINFILE.bin
\ No newline at end of file
+elif [[ $1 = '-mainclass' ]]
+then
+JAVAOPTS="$JAVAOPTS -mainclass $2"
+shift
+elif [[ $1 = '-dsm' ]]
+then
+JAVAOPTS="$JAVAOPTS -dsm"
+elif [[ $1 = '-taskstate' ]]
+then
+JAVAOPTS="$JAVAOPTS -taskstate"
+elif [[ $1 = '-optional' ]]
+then
+JAVAOPTS="$JAVAOPTS -optional"
+OPTIONALFLAG=true
+elif [[ $1 = '-dmalloc' ]]
+then
+USEDMALLOC=true
+elif [[ $1 = '-recover' ]]
+then
+RECOVERFLAG=true
+JAVAOPTS="$JAVAOPTS -task"
+elif [[ $1 = '-webinterface' ]]
+then
+JAVAOPTS="$JAVAOPTS -webinterface"
+elif [[ $1 = '-instructionfailures' ]]
+then
+JAVAOPTS="$JAVAOPTS -instructionfailures"
+elif [[ $1 = '-check' ]]
+then
+CHECKFLAG=true
+JAVAOPTS="$JAVAOPTS -conscheck"
+elif [[ $1 = '-specdir' ]]
+then
+cd $2
+SPECDIR=`pwd`
+cd $CURDIR
+shift
+elif [[ $1 = '-debug' ]]
+then
+EXTRAOPTIONS="$EXTRAOPTIONS -g"
+elif [[ $1 = '-runtimedebug' ]]
+then
+EXTRAOPTIONS="$EXTRAOPTIONS -DDEBUG"
+elif [[ $1 = '-nooptimize' ]]
+then
+EXTRAOPTIONS="$EXTRAOPTIONS -O0"
+elif [[ $1 = '-optimize' ]]
+then
+EXTRAOPTIONS="$EXTRAOPTIONS -O9"
+elif [[ $1 = '-thread' ]]
+then
+JAVAOPTS="$JAVAOPTS -thread"
+EXTRAOPTIONS="$EXTRAOPTIONS -DTHREADS -lpthread"
+THREADFLAG=true
+elif [[ $1 = '-curdir' ]]
+then
+CURDIR=$2
+shift
+else
+SRCFILES="$SRCFILES $1"
+fi
+shift
+done
+
+BUILDDIR="$CURDIR/tmpbuilddirectory"
+
+cd $1
+cd $CURDIR
+shift
+
+mkdir $BUILDDIR
+
+if $CHECKFLAG #Generate structure files for repair tool
+then
+JAVAOPTS="$JAVAOPTS -struct structfile"
+fi
+
+# Build bristlecone/java sources
+
+java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
+$ROBUSTROOT/ClassLibrary/ -dir $BUILDDIR -precise \
+$JAVAOPTS $SRCFILES
+
+# Build all of the consistency specs
+
+if $CHECKFLAG # CHECKFLAG
+then
+cd $SPECDIR
+mkdir $BUILDDIR/specdir
+cp $REPAIRROOT/MCC/CRuntime/* $BUILDDIR/specdir
+
+echo > $BUILDDIR/specs
+
+# compile specs into C code
+for i in * # iterate over all directories
+do
+if [[ "$i" != "CVS" ]] # CVSDIR CHECK
+then
+cd $SPECDIR/$i
+cat $BUILDDIR/structfile.struct $i.label > $i.struct
+java -cp $REPAIRROOT/:. MCC.Compiler -name $i -checkonly $i
+cp size.[c,h] $BUILDDIR/specdir
+cp $i.c $i\_aux.[c,h] $BUILDDIR/specdir
+echo $i >> $BUILDDIR/specs
+fi # CVSDIR CHECK
+done # iterate over all directories
+
+#compile C code
+
+cd $BUILDDIR/specdir
+./buildrobust
+echo > $BUILDDIR/checkers.h
+for i in `cat $BUILDDIR/specs`
+do
+gcc -O0 -g -c $i\_aux.c
+echo \#include \"specdir\/$i\_aux.h\" >> $BUILDDIR/checkers.h
+done
+fi # CHECKFLAG
+
+#build and link everything
+
+cd $CURDIR 
+
+INCLUDES="$INCLUDES -I$ROBUSTROOT/Runtime -I. -IRuntime/include \
+-I$BUILDDIR"
+
+FILES="$ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/task.c \
+$ROBUSTROOT/Runtime/file.c $ROBUSTROOT/Runtime/Queue.c \
+$ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/option.c \
+$ROBUSTROOT/Runtime/garbage.c $ROBUSTROOT/Runtime/socket.c \
+$ROBUSTROOT/Runtime/GenericHashtable.c $ROBUSTROOT/Runtime/object.c"
+
+if $RECOVERFLAG
+then
+EXTRAOPTIONS="$EXTRAOPTIONS -DTASK"
+FILES="$FILES tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/checkpoint.c"
+fi
+
+if $OPTIONALFLAG
+then
+EXTRAOPTIONS="$EXTRAOPTIONS -DOPTIONAL"
+FILES="$FILES tmpbuilddirectory/optionalarrays.c"
+fi
+
+if $THREADFLAG
+then
+FILES="$FILES $ROBUSTROOT/Runtime/thread.c"
+fi
+
+if $CHECKFLAG
+then
+EXTRAOPTIONS="$EXTRAOPTIONS -DCONSCHECK $BUILDDIR/specdir/*.o"
+INCLUDES="$INCLUDES -I$BUILDDIR/specdir"
+fi
+
+if $USEDMALLOC
+then
+EXTRAOPTIONS="$EXTRAOPTIONS -ldmalloc -DDMALLOC"
+fi
+
+gcc $INCLUDES $EXTRAOPTIONS -DPRECISE_GC \
+tmpbuilddirectory/methods.c $FILES -o $MAINFILE.bin
+
+exit
+