#!/bin/sh
# configuration scripts for imake/XFree86

F=$WRKDIR/.config

isyes() {
    if [ X$1 = XYES -o X$1 = XYes -o X$1 = Xyes -o X$1 = XY -o X$1 = Xy ]; then
	ret=YES
    else
        ret=$1
    fi
}

configure () {
rm -f $F

echo "/*" >> $F
echo "/* Followins are generated by FreeBSD imake-4/XFree86-4-* ports system." >> $F
echo " */" >> $F
if [ $OSVERSION -ge 300000 -a X$HasSecureRPC != "X" ]; then
    echo "#ifndef HasSecureRPC"                 >> $F
    echo "#define HasSecureRPC $HasSecureRPC" >> $F
    echo "#endif"                               >> $F
fi
if [ X$HasXdmAuth != "X" ]; then
    if [ -f $WRKDIR/xc/lib/Xdmcp/Wraphelp.c -o -f $DISTDIR/xc/Wraphelp.c ]; then
	echo "#ifndef HasXdmAuth"               >> $F
	echo "#define HasXdmAuth $HasXdmAuth" >> $F
        echo "#endif"                           >> $F
    fi
fi
if [ $OSVERSION -ge 310000 -a X$HasPam != "X" ]; then
    echo "#ifndef HasPam"                       >> $F
    echo "#define HasPam $HasPam"             >> $F
    echo "#endif"                               >> $F
fi
if [ X$BuildPexExt != "X" ]; then
    echo "#ifndef BuildPexExt"                  >> $F
    echo "#define BuildPexExt $BuildPexExt"   >> $F
    echo "#endif"                               >> $F
fi
if [ X$BuildXinerama != "X" ]; then
    echo "#ifndef BuildXinerama"                  >> $F
    echo "#define BuildXinerama $BuildXinerama" >> $F
    echo "#endif"                                 >> $F
fi
if [ X$BuildXIE != "X" ]; then
    echo "#ifndef BuildXIE"                       >> $F
    echo "#define BuildXIE $BuildXIE"           >> $F
    echo "#endif"                                 >> $F
fi
if [ X$BuildAoutLibraries != "X" ]; then
    echo "#ifndef BuildAoutLibraries"             >> $F
    echo "#define BuildAoutLibraries $BuildAoutLibraries" >> $F
    echo "#endif"                                 >> $F
fi
if [ X$ForceNormalLib != "X" ]; then
    echo "#ifndef ForceNormalLib"                   >> $F
    echo "#define ForceNormalLib $ForceNormalLib" >> $F
    echo "#endif"                                   >> $F
fi
isyes $DebuggableLibraries
if [ $ret = YES -a $OSVERSION -ge 400000 ]; then
    echo "#ifndef DebuggableLibraries"      >> $F
    echo "#define DebuggableLibraries $ret" >> $F
    echo "#endif"                           >> $F
fi
if [ X$JoystickSupport != "X" ]; then
    echo "#ifndef JoystickSupport"                    >> $F
    echo "#define JoystickSupport $JoystickSupport" >> $F
    echo "#endif"                                     >> $F
fi
if [ X$InstallXdmConfig != "X" ]; then
    echo "#ifndef InstallXdmConfig"                     >> $F
    echo "#define InstallXdmConfig $InstallXdmConfig" >> $F
    echo "#endif"                                       >> $F
fi
if [ X$InstallXinitConfig != "X" ]; then
    echo "#ifndef InstallXinitConfig"                       >> $F
    echo "#define InstallXinitConfig $InstallXinitConfig" >> $F
    echo "#endif"                                           >> $F
fi
if [ X$InstallAppDefFiles != "X" ]; then
    echo "#ifndef InstallAppDefFiles"                       >> $F
    echo "#define InstallAppDefFiles $InstallAppDefFiles" >> $F
    echo "#endif"                                           >> $F
fi
if [ X$ExtendedInputDevices = XYES ]; then
    echo "#define XInputDrivers mouse digitaledge dynapro elo2300 \
				elographics magellan \
				microtouch mutouch spaceorb summa \
				wacom void citron"  >> $F
else
    echo "#define XInputDrivers mouse" >> $F
fi
if [ X$Build75DpiFonts != "X" ]; then
    echo "#ifndef Build75DpiFonts"                       >> $F
    echo "#define Build75DpiFonts $Build75DpiFonts"      >> $F
    echo "#endif"                                        >> $F
fi
if [ X$Build100DpiFonts != "X" ]; then
    echo "#ifndef Build100DpiFonts"                       >> $F
    echo "#define Build100DpiFonts $Build100DpiFonts"      >> $F
    echo "#endif"                                        >> $F
fi
if [ X$BuildSpeedoFonts != "X" ]; then
    echo "#ifndef BuildSpeedoFonts"                       >> $F
    echo "#define BuildSpeedoFonts $BuildSpeedoFonts"      >> $F
    echo "#endif"                                        >> $F
fi
if [ X$BuildType1Fonts != "X" ]; then
    echo "#ifndef BuildType1Fonts"                       >> $F
    echo "#define BuildType1Fonts $BuildType1Fonts"      >> $F
    echo "#endif"                                        >> $F
fi
if [ X$BuildCIDFonts != "X" ]; then
    echo "#ifndef BuildCIDFonts"                     >> $F
    echo "#define BuildCIDFonts $BuildCIDFonts"      >> $F
    echo "#endif"                                    >> $F
fi
if [ X$BuildTTFonts != "X" ]; then
    echo "#ifndef BuildTTFonts"                    >> $F
    echo "#define BuildTTFonts $BuildTTFonts"      >> $F
    echo "#endif"                                  >> $F
fi

echo "#define BuildXF86Setup NO" >> $F
echo "#define HasFreetype2 YES" >> $F
echo "#define Freetype2Dir ${LOCALBASE}" >> $F
cat >> $F <<EOF
#ifndef XF86CardDrivers
#ifdef i386Architecture
#define XF86CardDrivers         mga glint nv tga s3virge sis rendition \
                                neomagic i740 tdfx savage \
                                cirrus vmware tseng trident chips apm \
                                GlideDriver fbdev i128 \
                                ati AgpGartDrivers DevelDrivers ark cyrix \
				siliconmotion \
				vesa vga XF86OSCardDrivers XF86ExtraCardDrivers
#else
#ifdef AlphaArchitecture
#define XF86CardDrivers         mga tdfx glint s3virge rendition tga \
				savage nv DevelDrivers siliconmotion vga \
				XF86OSCardDrivers XF86ExtraCardDrivers
#endif
#endif
#endif
EOF
    # Never install something to outside ${X11BASE}!!
    echo "#define NothingOutsideProjectRoot YES" >> $F
}

configure

cat $F >> ${WRKDIR}/xc/config/cf/xf86site.def

echo "#define ProjectRoot ${PREFIX}" > ${WRKDIR}/xc/config/cf/host.def

cd ${WRKDIR}/xc
touch config/cf/version.def
make Makefile.boot
make -f xmakefile SUBDIRS="include config" VerifyOS version.def Makefiles includes
