#!/bin/sh

set -e

PATH=::$CONFIG/bin:$UTIL_HOME/bin:/usr/ccs/bin:/usr/ucb:$PATH
export PATH

$SRC_HOME/first/create_dir $CONFIG
$SRC_HOME/first/create_dir $CONFIG/bin

(
	# Slight complication here to ensure that the #! magic at the
	# beginning of TakeAction is preserved correctly.

	head -1 $SRC_HOME/TakeAction
	echo "PATH=:$CONFIG/bin:$UTIL_HOME/bin:$PATH; export PATH"
	tail +2 $SRC_HOME/TakeAction
) > $CONFIG/bin/TakeAction

sed '/^#PARAMS/r make_macros' < $SRC_HOME/first/mk_makefile > $CONFIG/bin/mk_makefile
cp $SRC_HOME/first/create_dir $CONFIG/bin/create_dir
cp $SRC_HOME/first/cp_dir $CONFIG/bin/cp_dir
chmod +x $CONFIG/bin/*

$SRC_HOME/first/mk_config

$SRC_HOME/first/mk_target

$SRC_HOME/first/limit_impl

case $SYSNAME in
i386)
	ed -s $TARGET_HOME/lib/descr/fe << 'ABC'
1,$s/-D{NAME}/-D{NAME} -DNO_PROTOTYPE/
w
q
ABC
	;;
esac

: find varargs include file
: if not present use our own

if test -f /usr/include/varargs.h
then
	:
else
	cp $SRC_HOME/include/_tail_cc/varargs.h $TARGET_HOME/modules/h
fi

case X$SYSVAX in
Xvax_sysV_2)
	ed -s $TARGET_HOME/lib/vax4/descr << 'ABC'
/CPP_F/s/$/ -D__USG/
w
q
ABC
	ed -s $CONFIG/mach/vax4/Action << 'ABC'
/libbsd4_2/s/libbsd4_2/libsysV_2/
w
q
ABC
	( cd $CONFIG/mach/vax4
	  for i in libcc libcc.ansi
	  do
	  	ed -s $i/Makefile << 'ABC'
/BFS/s/BFS/UFS/
w
q
ABC
	  done
	)
	;;
Xvax_bsd4_2)
	ed -s $TARGET_HOME/lib/vax4/descr << 'ABC'
/CPP_F/s/$/ -D__BSD4_2/
w
q
ABC
	;;
Xvax_bsd4_1a)
	ed -s $CONFIG/mach/vax4/Action << 'ABC'
/libbsd4_2/s/libbsd4_2/libbsd4_1a/
w
q
ABC
	;;
esac

: and finally installing ...
cd $CONFIG
set +e
exec TakeAction