File: bootcheck

package info (click to toggle)
mercury 0.9-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 18,488 kB
  • ctags: 9,800
  • sloc: objc: 146,680; ansic: 51,418; sh: 6,436; lisp: 1,567; cpp: 1,040; perl: 854; makefile: 450; asm: 232; awk: 203; exp: 32; fortran: 3; csh: 1
file content (775 lines) | stat: -rwxr-xr-x 19,225 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
#!/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 in directory <dirname>. Multiple such options
		may be given, in which case the tests in all the named
		directories will be run. In the absence of any such options,
		all tests in all directories will be run (unless testing
		as a whole is disabled).
	-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.
	--stop-after-stage-2
		Stop after building stage 2, even if it is successful.
	--use-subdirs
		Assume intermediate files are built in subdirectories.
		(Same as the \`--use-subdirs' option to mmake and mmc.)
"

testdirs=""
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
stop_after_stage_2=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)
		testdirs="$testdirs $2"; shift ;;
	-d*)
		testdirs="$testdirs ` 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 ;;

	--stop-after-stage-2)
		stop_after_stage_2=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

#-----------------------------------------------------------------------------#

# on hg, the file system we're using does not support links
case `hostname` in
	hg*)	LN="cp -r"; LN_S="cp -r" ;;
	*)	LN="ln"; LN_S="ln -s" ;;
esac

#-----------------------------------------------------------------------------#

# Turn off the debugger, since accidentally leaving it on will result
# in user interaction every time we invoke 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-o]*.m .
	$LN_S $root/compiler/[p-s]*.m .
	$LN_S $root/compiler/[t-z]*.m .
	$LN_S $root/compiler/*.pp .	

	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 -f 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 -f 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 -f 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

	MMAKE_VPATH=.
	export MMAKE_VPATH
	MMAKE_DIR=$root/scripts
	export MMAKE_DIR

	# Use the new mmake to build stage 2
	MMAKE=$MMAKE_DIR/mmake

	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

	# 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

	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

	if $stop_after_stage_2
	then
		echo "stopping after building stage 2"
		exit 0
	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
		find $root/stage2/library -name "*.o" -print |
		xargs /bin/rm -f
	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-o]*.m .
	$LN_S $root/compiler/[p-s]*.m .
	$LN_S $root/compiler/[t-z]*.m .
	$LN_S $root/compiler/*.pp .	

	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

	MMAKE_VPATH=.
	export MMAKE_VPATH
	MMAKE_DIR=$root/scripts
	export MMAKE_DIR

	# Use the new mmake to build stage 3
	MMAKE=$MMAKE_DIR/mmake

	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

	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 initially not successful"
		df .
		# try again, in case the failure cause was transient
		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
	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
		find $root/stage2/compiler -name "*.o" -print |
		xargs /bin/rm -f
	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 initially not successful"
		df .
		# try again, in case the failure cause was transient
		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
	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 initially not successful"
		df .
		# try again, in case the failure cause was transient
		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
	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

	test_status=0
	if test -d ../tests
	then
		tests_prefix="../"
	elif test -d tests
	then
		tests_prefix=""
	else
		echo "cannot find test directory"
		test_status=1
	fi

	if test "$test_status" = 0
	then
		cp $root/doc/mdb_command_test.inp ${tests_prefix}tests/debugger
		if test "$testdirs" = ""
		then
			cd ${tests_prefix}tests
			./runtests $jfactor $test_grade_opt
		else
			for testdir in $testdirs
			do
				cd $root/${tests_prefix}tests/$testdir
				./runtests $jfactor $test_grade_opt
			done
		fi
		test_status=$?
		cd $root
	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