#!/bin/sh

know_target=0
case $SYSNAME in
vax*|i386|sun*|sparc*|m68_sysV_0|m68020|mantra|pmds4|m68k4)
	WS=4 ; PS=4
	know_target=1
	;;
m68_unisoft|m68k2|minixST|pmds)
	WS=2 ; PS=4
	know_target=1
	;;
i86|minix|xenix3)
	WS=2 ; PS=2
	know_target=1
	;;
*)	trap "rm -f ws.c ws.o a.out t$$" 0 1 2 3 15
		cat > ws.c <<'EOF'
#include <stdio.h>
main()
{
	printf("WS=%d ; PS=%d\n", sizeof(int), sizeof(char *));
	exit(0);
}
EOF
	if [ $TARGET_HOME = $UTIL_HOME ] && cc ws.c 2>/dev/null
	then
		: We can find out ourselves what the word-size and
		: the pointer-size of the target machine is.
		cc ws.c 2>/dev/null
		./a.out > t$$
		. t$$
		rm -f t$$ a.out ws.[co]
	else
		: we will have to ask installer.
		echo $E_FLAG "Please give the word-size of the target-machine (sizeof(int)) in bytes: [$WS] $E_SFX"
		. $FDIR/get_answer
		case $ANS in
		'')	ANS="$WS";;
		esac
		WS="$ANS"
		echo $E_FLAG "Please give the pointer-size of the target-machine (sizeof(char *)) in bytes: [$PS] $E_SFX"
		. $FDIR/get_answer
		case $ANS in
		'')	ANS="$PS";;
		esac
		PS="$ANS"
	fi
	;;
esac

echo "# Paths:
SRC_HOME = $SRC_HOME
TARGET_HOME = $TARGET_HOME
UTIL_HOME = $UTIL_HOME

# Machine independent part created?
DO_MACHINE_INDEP = $DO_MACHINE_INDEP

# Target machine, only needed for fast compilers
MACH = $MACH
" > make_macros

if [ $TARGET_HOME = $UTIL_HOME ]
then	
	if [ -f /bin/ranlib -o -f /usr/bin/ranlib -o -f /usr/ucb/ranlib ]
	then
		sed "s/^COPTIONS.*\$/COPTIONS=-O -D_EM_WSIZE=$WS -D_EM_PSIZE=$PS -D__${MACH}__/" < $FDIR/target_comp >> make_macros
	else
		sed -e "s/^COPTIONS.*\$/COPTIONS=-O -D_EM_WSIZE=$WS -D_EM_PSIZE=$PS -D__${MACH}__/" -e "s/^# RANLIB=:/RANLIB=:/" < $FDIR/target_comp >> make_macros
	fi
	case $ACM in
	sun3|sparc)
		ed -s make_macros <<'EOF'
/cc-and-mkdep.sun/s/^..//
w
q
EOF
		;;
	esac
	cat $FDIR/util_comp >> make_macros
else
	case $know_target in
	1)	sed -e "s/^COPTIONS.*\$/COPTIONS=-O -D_EM_WSIZE=$WS -D_EM_PSIZE=$PS -D__${MACH}__/" -e "/cc-and-mkdep.ack/s/^..//" -e "s/^CC=cc/CC=acc -m$ACM/" -e "s/^# AR=aal/AR=aal/" -e "s/^# RANLIB=:/RANLIB=:/" < $FDIR/target_comp >> make_macros
		;;
	*)	if [ -f /bin/ranlib -o -f /usr/bin/ranlib -o -f /usr/ucb/ranlib ]
		then
			sed "s/^COPTIONS.*\$/COPTIONS=-O -D_EM_WSIZE=$WS -D_EM_PSIZE=$PS -D__${MACH}__/" < $FDIR/target_comp >> make_macros
		else
			sed -e "s/^COPTIONS.*\$/COPTIONS=-O -D_EM_WSIZE=$WS -D_EM_PSIZE=$PS -D__${MACH}__/" -e "s/^# RANLIB=:/RANLIB=:/" < $FDIR/target_comp >> make_macros
		fi
		;;
	esac
	sed "s/^#U/U/" < $FDIR/util_comp >> make_macros
fi

cat $FDIR/lint_params >> make_macros

echo "A file called 'make_macros' has been created. This file defines some
'make' variables that parameterize all Makefiles in ACK. You may want
to check it before attempting to actually install ACK."
case $know_target in
0)	echo "In fact, this installation script does not know much about
your target machine, so expect some things to be wrong"
	;;
esac
