# $NetBSD: INSTALL,v 1.11 2004/04/30 19:44:21 tv Exp $

FONT_PROGS="@FONT_PROGS@"
X11BASE=@X11BASE@

X11_HOSTDEF=${X11BASE}/lib/X11/config/host.def
HOSTDEF=${PKG_PREFIX}/lib/X11/config/host.def
X11_SITEDEF=${X11BASE}/lib/X11/config/site.def
SITEDEF=${PKG_PREFIX}/lib/X11/config/site.def
X11_SV4LIB=${X11BASE}/lib/X11/config/sv4Lib.tmpl
SV4LIB=${PKG_PREFIX}/lib/X11/config/sv4Lib.tmpl

SV4LIB_SUBST_SED="-e s/^	/        /"
SITEDEF_SUBST_SED="-e s/\#endif.*VendorCF.*/\#include <host.def>\\
&/"

case ${STAGE} in
POST-INSTALL)
	${ECHO_N} "Symlinking font programs..."
	for prog in ${FONT_PROGS}; do
		if [ -f ${X11BASE}/bin/$prog -a				\
		     ${PKG_PREFIX} != ${X11BASE} ]; then
			${LN} -fs ${X11BASE}/bin/$prog			\
				${PKG_PREFIX}/bin/$prog
		fi
	done
	${ECHO} "done."
	;;

VIEW-INSTALL)
	if [ ${PKG_PREFIX} = ${X11BASE} -o -s ${HOSTDEF} ]; then
		${ECHO_N} "Updating ${HOSTDEF}..."
		${CP} -f ${HOSTDEF} ${HOSTDEF}.bak
	else
		${ECHO_N} "Creating ${HOSTDEF}..."
		if [ -f ${X11_HOSTDEF} ]; then
			${CP} -f ${X11_HOSTDEF} ${HOSTDEF}.bak
		else
			${CP} -f /dev/null ${HOSTDEF}.bak
		fi
	fi
	( ${ECHO} '#include <xpkgwedge.def>';				\
	  ${GREP} -v xpkgwedge ${HOSTDEF}.bak;				\
	) > ${HOSTDEF}
	${RM} -f ${HOSTDEF}.bak
	${ECHO} "done."
	case `uname`:${X11BASE} in
	*:*openwin)
		${ECHO_N} "Patching OpenWindows templates..."
		${SED} "${SITEDEF_SUBST_SED}" ${X11_SITEDEF} > ${SITEDEF}
		${SED} "${SV4LIB_SUBST_SED}" ${X11_SV4LIB} > ${SV4LIB}
		${ECHO} "done."
		;;
	Interix:/usr/X11R6)
		${ECHO_N} "Patching Interix templates..."
		${SED} -e "1i\\
#include <host.def>
" -e "/CcCmd/d;/ProjectRoot/d" ${X11_SITEDEF} > ${SITEDEF}
		${ECHO} "done."
		;;
	esac
	;;
esac