: check $PATH first
if sh ckpath
then :
else
	exit 1
fi
: check write-ability of /tmp and /usr/tmp
if ( >/usr/tmp/aaax.$$ )
then
	rm /usr/tmp/aaax.$$
else
	echo /usr/tmp must exist and be writable.
	exit 2
fi
if ( >/tmp/aaax.$$ )
then
	rm /tmp/aaax.$$
else
	echo /tmp must exist and be writable.
	exit 2
fi
: set ACK HOME Directory in ../h/em_path.h
rm -f em_path.h
sed -e "/^#define[ 	]*EM_DIR/s@\".*\"@\"`cd .. ; pwd`\"@" <../h/em_path.h >em_path.h
if cmp ../h/em_path.h em_path.h >/dev/null 2>&1
then
	: Don't touch ../h/em_path.h, it's already correct
else
	rm -f ../h/em_path.h
	if mv em_path.h ../h >/dev/null 2>&1
	then : success
	else
		echo "Sorry, can't replace ../h/em_path.h"
		exit 7
	fi
fi
: remove non-system as and ld from descr files
if (ack_sys) >/dev/null 2>&1
then
	: echo Your system is: `ack_sys`.
else
	echo -n "Give me the type of your system, the current choice is:
pdp_v7		PDP11 with sep I/D and version 7
vax_bsd4_1a	VAX11 with BSD4.1a
vax_bsd4_1c	VAX11 with BSD4.1c
vax_bsd4_2	VAX11 with BSD4.2
pc_ix		IBM PC with PC/IX
m68_unisoft	Motorola 68000 with Unisoft UNIX
ANY		Neither of the above

system type: "
	if read SYSNAME
	then
		echo echo "$SYSNAME" >../bin/ack_sys
		chmod +x ../bin/ack_sys
		case `ack_sys` in
		pdp_v7|vax_bsd4_1[ac]|vax_bsd4_2|pc_ix|m68_unisoft) ;;
		*)	echo None of the software especially intended for the named systems will work ;;
		esac
	else
		echo Sorry, got EOF when reading system name.
		exit 8
	fi
fi
echo -n "Your system is `ack_sys`, are you satisfied with that? (y/n) "
if read YESNO
then
	case $YESNO in
	j*|y*)	;;
	n*)	echo Ok, I will give you another chance....
		rm -f ../bin/ack_sys
		exec sh $0
		;;
	*)	echo "I do not understand your answer ($YESNO). Bye"
		exit 9
		;;
	esac
else
	echo Sorry, got EOF when reading your answer.
	exit 9
fi
: "Take action according to the system used"
: 'Prevent the use of the system assembler on for certain systems'
case `ack_sys` in
vax_bsd*)	RMD=pdp ;;
pdp_*)		RMD="vax2 vax4" ;;
*)		RMD="pdp vax2 vax4" ;;
esac
for i in $RMD
do
(	cd ../lib/$i
	if grep '^name as$' descr >/dev/null 2>&1
		then
cp descr descr.orig
ed - descr <<'ABC'
/^name as$/;/^end$/d
/^name ld$/;/^end$/d
w
q
ABC
	fi
)
done
: 'Set the default machine in ../h/local.h'
case `ack_sys` in
pdp_v7)		ACM=pdp ;;
vax_bsd4_1[ac]) ACM=vax2 ;;
vax_bsd4_2)	ACM=vax2 ;;
pc_ix)		ACM=ix ;;
m68_unisoft)	ACM=m68k2 ;;
*)		ACM=m68k2 ;;
esac
rm -f local.h
sed /ACKM/s/'".*"'/'"'$ACM'"'/ <../h/local.h >local.h
if cmp -s ../h/local.h local.h
then :
else
	cp local.h ../h
	rm -f local.h
fi
echo "Your default machine to compile for is $ACM"
case `ack_sys` in
vax_bsd4_*)
	echo 'Installing the include directory in lib/vax2'
	( cd ../lib/vax2 ; sh fetch_inc )
	echo Done
	case `ack_sys` in
	vax_bsd4_1a)	VERS=BSD41a ;;
	vax_bsd4_1c)	VERS=BSD41c ;;
	vax_bsd4_2)	VERS=BSD42 ;;
	*)		echo "Unknown VAX BSD version, look at mach/vax[24]/libem"
			break ;;
	esac
	for i in vax2 vax4
	do (
		cd ../mach/$i/libem
		ed - system.h <<ABC
g/^#/s/.*/\/* & *\//
/$VERS/s/^.*#/#/
/$VERS/s/*\/.*$//
w
q
ABC
	) done
	echo 'mach/vax[24]/libem/system.h reflects your BSD version.'
esac
