Files
mercury/tools/bootcheck
Simon Taylor f18ac4159e Fix a syntax error.
Estimated hours taken: 0.1

tools/bootcheck:
	Fix a syntax error.
1999-04-22 05:47:35 +00:00

715 lines
17 KiB
Bash
Executable File

#!/bin/sh
#---------------------------------------------------------------------------#
# Copyright (C) 1995-1999 The University of Melbourne.
# This file may only be copied under the terms of the GNU General
# Public License - see the file COPYING in the Mercury distribution.
#---------------------------------------------------------------------------#
usage="\
Usage: $0 [options]
Options:
-d <dirname>, --test-dir <dirname>
Run the tests only in <dirname>.
-h, --help
Display this usage message.
-j <num-jobs>, --jobs <num-jobs>
Run using <num-jobs> different parallel processes.
-k, --keep-objs
Keep the stage 2 object files even if stage 2 is successful.
-m <mmake-args>, --mmake-args <mmake-args>
Pass <mmake-args> as options to \`mmake'.
-o <filename>, --output-file <filename>
Output results to <filename>.
-G <grade>, --grade <grade>
Specify the grade to use in creating stages 2 and 3.
The tests will also be executed in this grade, unless
the --test-grade option says otherwise. Implies -r -g.
--test-grade <grade>
Specify the grade to use in executing the tests.
If this is the same as the grade of stages 2 and 3, then
we use the stage 2 runtime, library etc for the tests.
Otherwise, we use the stage 1 runtime, library etc,
and trust that these are compatible with the given grade.
Implies -r -g.
-g, --copy-boehm-gc
Copy the boehm_gc directory instead of linking it.
This is necessary if one wants to bootcheck a grade
that is not compatible with the standard one.
-r, --copy-runtime
Copy the runtime directory instead of linking it.
This is necessary if one wants to bootcheck a grade
that is not compatible with the standard one.
-p, --copy-profiler
Copy the profiler directory instead of linking it.
This is sometimes necessary for bootstrapping
changes.
-t, --no-test-suite
By default, bootcheck will also run the test quite.
This option prevents that.
-T, --test-suite-only
Do not run the bootstrap check; execute the test suite only.
This option requires a previous bootstrap check to have left
a working stage 2 directory.
-2, --keep-stage-2
Don't rebuild the stage 2 directory from scratch after
building stage 1. Instead use the existing stage 2 directory.
-3, --keep-stage-3
Don't rebuild the stage 3 directory from scratch after
building stage 1. Instead use the existing stage 3 directory.
--use-subdirs
Assume intermediate files are built in subdirectories.
(Same as the \`--use-subdirs' option to mmake and mmc.)
"
testdir=""
jfactor=""
keep_objs=false
mmake_opts="-k"
outfile=""
runtests=true
do_bootcheck=true
grade=
test_grade=
copy_runtime=false
copy_boehm_gc=false
copy_profiler=false
keep_stage_2=false
keep_stage_3=false
if [ -d compiler/Mercury ]; then
use_subdirs=${MMAKE_USE_SUBDIRS=yes}
else
use_subdirs=${MMAKE_USE_SUBDIRS=no}
fi
# If you change these, you will also need to change scripts/ml.in,
# scripts/c2init.in, Mmake.common.in, tools/binary, tools/binary_step
# and tools/linear.
RT_LIB_NAME=mer_rt
STD_LIB_NAME=mer_std
TRACE_LIB_NAME=mer_trace
BROWSER_LIB_NAME=mer_browser
while [ $# -gt 0 ]; do
case "$1" in
-d|--test-dir)
testdir="$2"; shift ;;
-d*)
testdir="` expr $1 : '-d\(.*\)' `"; ;;
-h|--help)
echo "$usage"
exit 0 ;;
-j|--jobs)
jfactor="-j$2"; shift ;;
-j*)
jfactor="-j` expr $1 : '-j\(.*\)' `" ;;
--jobs*)
jfactor="--jobs` expr $1 : '--jobs\(.*\)' `" ;;
-k|--keep-objs)
keep_objs=true ;;
-m|--mmake)
mmake_opts="$mmake_opts $2"; shift ;;
-o|--output-file)
outfile="$2"; shift ;;
-o*)
outfile="` expr $1 : '-o\(.*\)' `"; ;;
-G|--grade)
grade="$2"; shift ;;
-G*)
grade="` expr $1 : '-G\(.*\)' `"; ;;
--test-grade)
test_grade="$2"; shift ;;
-r|--copy-runtime)
copy_runtime=true ;;
-g|--copy-boehm-gc)
copy_boehm_gc=true ;;
-p|--copy-profiler)
copy_profiler=true ;;
-t|--no-test-suite)
runtests=false ;;
-T|--test-suite-only)
do_bootcheck=false ;;
-2|--keep-stage-2)
keep_stage_2=true ;;
-3|--keep-stage-3)
keep_stage_3=true ;;
--use-subdirs)
use_subdirs=yes ;;
--no-use-subdirs)
use_subdirs=no ;;
--)
shift; break ;;
-*)
echo "$0: unknown option \`$1'" 1>&2
echo "$usage" 1>&2
exit 1 ;;
*)
break ;;
esac
shift
done
if [ $# -ne 0 ]; then
echo "$0: unexpected argument(s) \`$*'" 1>&2
echo "$usage" 1>&2
exit 1
fi
if test "$grade" != "" -a "$test_grade" = ""
then
test_grade="$grade"
fi
case $use_subdirs in
yes) cs_subdir=Mercury/cs/
;;
no) cs_subdir=
;;
esac
if test "$grade" != "" -o "$test_grade" != ""
then
copy_runtime=true
copy_boehm_gc=true
fi
MMAKE_USE_SUBDIRS=$use_subdirs
export MMAKE_USE_SUBDIRS
# Turn off the debugger, since accidentally leaving it on will result
# in user interaction every time we any any version of the compiler
# that was compiled with tracing. This has happened to me accidentally
# one too many times - zs.
if echo $MERCURY_OPTIONS | grep '\-Di' > /dev/null
then
MERCURY_OPTIONS=`echo $MERCURY_OPTIONS | sed -e 's/-Di//'`
export MERCURY_OPTIONS
fi
echo "starting at `date`"
set -x
root=`/bin/pwd | sed '
s:/mount/munkora/mercury:/home/mercury:
s:/mount/munkora/home/mercury:/home/mercury:
s:/mount/munkora/clp/mercury:/home/mercury:'`
PATH=$root/tools:$PATH
export PATH
# Try the command given by the environment variable RMSTAGECMD to delete
# stage directories. Since this command may not always work due to
# security considerations (.rhost files), we execute /bin/rm -fr afterwards
# in any case.
if test "$RMSTAGECMD" = ""
then
RMSTAGECMD="/bin/rm -fr"
fi
if $do_bootcheck
then
if mmake $mmake_opts MMAKEFLAGS=$jfactor all
then
echo "building of stage 1 successful"
else
cd $root/library;
mmake depend
cd $root/browser;
mmake depend
cd $root/compiler;
mmake depend
cd $root/profiler;
mmake depend
cd $root
if mmake $mmake_opts MMAKEFLAGS=$jfactor all
then
echo "building of stage 1 successful"
else
echo "building of stage 1 not successful"
exit 1
fi
fi
# this is only for a transition period,
# until all stage1 dirs have been removed
/bin/rm -fr stage1
MERCURY_COMPILER=$root/compiler/mercury_compile
export MERCURY_COMPILER
MERCURY_INT_DIR=$root/stage2/library
export MERCURY_INT_DIR
[ -d stage2 ] || mkdir stage2
if $keep_stage_2
then
echo keeping existing stage2
else
# We try to do the removal of the stage 2 directory in parallel
# since recursive rm's across NFS can be quite slow ...
$RMSTAGECMD $root/stage2/compiler < /dev/null &
$RMSTAGECMD $root/stage2/library < /dev/null &
wait
$RMSTAGECMD $root/stage2/* < /dev/null
/bin/rm -fr $root/stage2/* < /dev/null
/bin/rm -fr $root/stage2/.[a-zA-Z]* < /dev/null
fi
set +x
echo linking stage 2... 1>&2
cd stage2
mkdir compiler
cd compiler
# Break up the links into several chunks.
# This is needed to cope with small limits
# on the size of argument vectors.
ln -s $root/compiler/[a-h]*.m .
ln -s $root/compiler/[i-s]*.m .
ln -s $root/compiler/[t-z]*.m .
cp $root/compiler/Mmake* .
cd $root/stage2
mkdir library
cd library
ln -s $root/library/library.nu.nl.in .
ln -s $root/library/[a-l]*.m .
ln -s $root/library/[m-z]*.m .
ln -s $root/library/*.nl .
cp $root/library/Mmake* .
ln -s $root/library/$STD_LIB_NAME.init .
cd $root/stage2
mkdir browser
cd browser
ln -s $root/browser/*.m .
cp $root/browser/Mmake* .
ln -s $root/browser/$BROWSER_LIB_NAME.init .
cd $root/stage2
if $copy_runtime
then
# Remove symbolic link to the stage 1 runtime if it's present,
# which it can be with the -2 option.
rm runtime
mkdir runtime
cd runtime
ln -s $root/runtime/*.h .
ln -s $root/runtime/*.c .
ln -s $root/runtime/*.in .
cp $root/runtime/Mmake* .
ln -s $root/runtime/machdeps .
cd $root/stage2
rm trace
mkdir trace
cd trace
ln -s $root/trace/*.h .
ln -s $root/trace/*.c .
cp $root/trace/Mmake* .
cd $root/stage2
else
ln -s $root/runtime .
ln -s $root/trace .
fi
if $copy_boehm_gc
then
# Remove symbolic link to the stage 1 gc if it's present,
# which it can be with the -2 option.
rm boehm_gc
mkdir boehm_gc
cd boehm_gc
ln -s $root/boehm_gc/*.h .
ln -s $root/boehm_gc/*.c .
ln -s $root/boehm_gc/*.s .
ln -s $root/boehm_gc/include .
cp $root/boehm_gc/Mmake* .
cp $root/boehm_gc/Makefile .
ln -s $root/boehm_gc/machdeps .
cd $root/stage2
else
ln -s $root/boehm_gc .
fi
ln -s $root/doc .
ln -s $root/scripts .
ln -s $root/util .
if $copy_profiler
then
mkdir profiler
cd profiler
ln -s $root/profiler/*.m .
cp $root/profiler/Mmake* .
cd $root/stage2
else
ln -s $root/profiler .
fi
ln -s $root/conf* .
ln -s $root/aclocal.m4 .
ln -s $root/VERSION .
ln -s $root/.*.in .
rm -f config*.log
cp $root/Mmake* .
if test -f $root/Mmake.stage.params
then
/bin/rm -f Mmake.params
cp $root/Mmake.stage.params Mmake.params
fi
if test "$grade" != ""
then
echo "GRADE = $grade" >> Mmake.params
fi
cd $root
set -x
if (cd stage2 && mmake $mmake_opts $jfactor runtime)
then
echo "building of stage 2 runtime successful"
else
echo "building of stage 2 runtime not successful"
exit 1
fi
if (cd stage2 && mmake $mmake_opts depend_library depend_browser \
depend_compiler depend_profiler)
then
echo "building of stage 2 dependencies successful"
else
echo "building of stage 2 dependencies not successful"
exit 1
fi
MMAKE_VPATH=.
export MMAKE_VPATH
MMAKE_DIR=$root/scripts
export MMAKE_DIR
# the `RM_C=:' ensures that the `.c' files do not get deleted
if (cd stage2/library && mmake $mmake_opts $jfactor RM_C=: mercury)
then
echo "building of stage 2 library successful"
else
echo "building of stage 2 library not successful"
exit 1
fi
if (cd stage2/browser && mmake $mmake_opts $jfactor RM_C=: library)
then
echo "building of stage 2 browser successful"
else
echo "building of stage 2 browser not successful"
exit 1
fi
if (cd stage2 && mmake $mmake_opts $jfactor trace)
then
echo "building of stage 2 trace successful"
else
echo "building of stage 2 trace not successful"
exit 1
fi
if (cd stage2/compiler && mmake $mmake_opts $jfactor RM_C=: mercury_compile)
then
echo "building of stage 2 compiler successful"
else
echo "building of stage 2 compiler not successful"
exit 1
fi
unset MMAKE_VPATH
unset MMAKE_DIR
if (cd stage2 && mmake $mmake_opts MMAKEFLAGS=$jfactor all)
then
echo "building of stage 2 successful"
else
echo "building of stage 2 not successful"
exit 1
fi
# We can remove the library object files now,
# but we will keep the compiler objects for a while longer
if $keep_objs
then
true
else
/bin/rm -f $root/stage2/library/[a-l]*.o < /dev/null
/bin/rm -f $root/stage2/library/[m-z]*.o < /dev/null
fi
MERCURY_COMPILER=$root/stage2/compiler/mercury_compile
export MERCURY_COMPILER
MERCURY_INT_DIR=$root/stage3/library
export MERCURY_INT_DIR
[ -d stage3 ] || mkdir stage3
if $keep_stage_3
then
echo keeping existing stage3
else
# We try to do the removal of the stage 3 directory in parallel
# since recursive rm's across NFS can be quite slow ...
$RMSTAGECMD $root/stage3/compiler < /dev/null &
$RMSTAGECMD $root/stage3/library < /dev/null &
wait
$RMSTAGECMD $root/stage3/* < /dev/null
/bin/rm -fr $root/stage3/* < /dev/null
/bin/rm -fr $root/stage3/.[a-zA-Z]* < /dev/null
fi
echo linking stage 3... 1>&2
set +x
cd stage3
mkdir compiler
cd compiler
# Break up the links into several chunks.
# This is needed to cope with small limits
# on the size of argument vectors.
ln -s $root/compiler/[a-h]*.m .
ln -s $root/compiler/[i-s]*.m .
ln -s $root/compiler/[t-z]*.m .
cp $root/compiler/Mmake* .
cd $root/stage3
mkdir library
cd library
ln -s $root/library/library.nu.nl.in .
ln -s $root/library/[a-l]*.m .
ln -s $root/library/[m-z]*.m .
ln -s $root/library/*.nl .
cp $root/library/Mmake* .
ln -s $root/library/$STD_LIB_NAME.init .
cd $root/stage3
mkdir browser
cd browser
ln -s $root/browser/*.m .
cp $root/browser/Mmake* .
ln -s $root/browser/$BROWSER_LIB_NAME.init .
cd $root/stage3
ln -s $root/boehm_gc .
ln -s $root/doc .
ln -s $root/runtime .
ln -s $root/trace .
ln -s $root/scripts .
ln -s $root/util .
ln -s $root/profiler .
ln -s $root/conf* .
ln -s $root/aclocal.m4 .
ln -s $root/VERSION .
ln -s $root/.*.in .
rm -f config*.log
cp $root/stage2/Mmake* .
cd $root
set -x
if (cd stage3 && mmake $mmake_opts depend_library depend_browser depend_compiler)
then
echo "building of stage 3 dependencies successful"
else
echo "building of stage 3 dependencies not successful"
exit 1
fi
MMAKE_VPATH=.
export MMAKE_VPATH
MMAKE_DIR=$root/scripts
export MMAKE_DIR
if (cd stage3/library &&
mmake $mmake_opts $jfactor all-ints &&
mmake $mmake_opts $jfactor cs)
then
echo "building of stage 3 library successful"
else
echo "building of stage 3 library not successful"
exit 1
fi
# We delay deleting the stage 2 compiler objects until now,
# so that if (a) an error manifests itself during the creation
# of the stage 3 library, and (b) this error can be fixed by
# changing the runtime, a bootcheck -2, which requires a relink,
# will not have to expensively recreate the stage 2 compiler objects.
if $keep_objs
then
true
else
/bin/rm -f $root/stage2/compiler/[a-l]*.o < /dev/null
/bin/rm -f $root/stage2/compiler/[i-s]*.o < /dev/null
/bin/rm -f $root/stage2/compiler/[t-z]*.o < /dev/null
fi
if (cd stage3/browser && mmake $mmake_opts $jfactor cs)
then
echo "building of stage 3 browser successful"
else
echo "building of stage 3 browser not successful"
exit 1
fi
if (cd stage3/compiler && mmake $mmake_opts $jfactor cs)
then
echo "building of stage 3 compiler successful"
else
echo "building of stage 3 compiler not successful"
exit 1
fi
diff_status=0
exec 3>&1 # save stdout in fd 3
if [ -n "$outfile" ]
then
exec > "$outfile" # redirect stdout to $outfile
fi
for dir in library browser compiler; do
for file in stage2/$dir/${cs_subdir}*.c; do
diff -u $file stage3/$dir/${cs_subdir}`basename $file` ||
diff_status=1
done
done
exec >&3 # restore stdout from fd 3
if [ $diff_status -ne 0 ]; then
echo "error - stage 2 and stage 3 differ!"
else
echo "stage 2 and stage 3 compare ok"
echo "removing stage 3..."
# We try to do the removal of the stage 3 directory in parallel
# since recursive rm's across NFS can be quite slow ...
$RMSTAGECMD $root/stage3/compiler < /dev/null &
$RMSTAGECMD $root/stage3/library < /dev/null &
wait
$RMSTAGECMD $root/stage3/* < /dev/null
/bin/rm -fr $root/stage3/* < /dev/null
/bin/rm -fr $root/stage3/.[a-zA-Z]* < /dev/null
fi
echo "finishing stage3 at `date`"
else
diff_status=0
echo "building of stages 1 and 2 skipped"
fi
if $runtests
then
# Use everything from stage 2, the options say that the tests
# should be done in grade different from the grade of stage 2,
# in which case use everything from stage 1, trusting the user
# that the grade of the tests and the grade of stage 1 are compatible.
MERCURY_COMPILER=$root/stage2/compiler/mercury_compile
export MERCURY_COMPILER
if test "$test_grade" != "$grade"
then
stage2_insert="stage2/"
else
stage2_insert=""
fi
MERCURY_INT_DIR=$root/${stage2_insert}library
export MERCURY_INT_DIR
MERCURY_LIBS="
$root/${stage2_insert}trace/lib$TRACE_LIB_NAME.a
$root/${stage2_insert}browser/lib$BROWSER_LIB_NAME.a
$root/${stage2_insert}library/lib$STD_LIB_NAME.a
$root/${stage2_insert}runtime/lib$RT_LIB_NAME.a
$root/${stage2_insert}boehm_gc/libgc.a
-lm"
export MERCURY_LIBS
MERCURY_ALL_C_INCL_DIRS="-I$root/${stage2_insert}trace
-I$root/${stage2_insert}runtime
-I$root/${stage2_insert}boehm_gc
-I$root/${stage2_insert}boehm_gc/include"
export MERCURY_ALL_C_INCL_DIRS
MMAKE_DIR="$root/${stage2_insert}scripts"
export MMAKE_DIR
MERCURY_MOD_LIB_MODS="
$root/${stage2_insert}browser/$BROWSER_LIB_NAME.init
$root/${stage2_insert}library/$STD_LIB_NAME.init
$root/${stage2_insert}runtime/$RT_LIB_NAME.init"
export MERCURY_MOD_LIB_MODS
# for mkinit, mmc, mgnuc, ml etc
PATH=$root/${stage2_insert}util:$root/${stage2_insert}scripts:$PATH
export PATH
# We need to give tests/debugger access to the mdbrc and mdb_doc
# files in the doc and scripts directories, without hardcoding their
# pathnames. We must also compensate for scripts/mdbrc having hardcoded
# within it the *installed* pathname of mdb_doc and not its current
# pathname.
cat $root/doc/mdb_doc > $root/scripts/test_mdbrc
sed -e '/^source/d' $root/scripts/mdbrc >> $root/scripts/test_mdbrc
MERCURY_DEBUGGER_INIT=$root/scripts/test_mdbrc
export MERCURY_DEBUGGER_INIT
if test "$test_grade" != ""
then
test_grade_opt="-g $test_grade"
else
test_grade_opt=""
fi
if test -d ../tests
then
cp $root/doc/mdb_command_test.inp ../tests/debugger
if test "$testdir" = ""
then
cd ../tests
./runtests $jfactor $test_grade_opt
else
cd ../tests/$testdir
./runtests $jfactor $test_grade_opt
fi
test_status=$?
cd $root
elif test -d tests
then
cp $root/doc/mdb_command_test.inp tests/debugger
if test "$testdir" = ""
then
cd tests
./runtests $jfactor $test_grade_opt
else
cd tests/$testdir
./runtests $jfactor $test_grade_opt
fi
test_status=$?
cd $root
else
echo "cannot find test directory"
test_status=1
fi
else
test_status=0
fi
echo "finishing at `date`"
if test "$diff_status" = 0 -a "$test_status" = 0
then
exit 0
else
exit 1
fi