
CheckWinGCC()
{
	cat >wincheck.c <<__EOF__
#include <windows.h>
int main () { exit(0); }
__EOF__
	make wincheck >/dev/null 2>&1
	status=$?
	rm -f wincheck.c wincheck wincheck.exe
	return $status
}

CheckDirectX()
{
	cat >dxcheck.c <<__EOF__
#include <directx.h>
int main () { exit(0); }
__EOF__
	make dxcheck CFLAGS="-I./directx/include" >/dev/null 2>&1
	status=$?
	rm -f dxcheck.c dxcheck dxcheck.exe
	return $status
}

CheckNASM()
{
	if findexe nasm >/dev/null; then
	    echo \
"
* Detected iX86 processor and NASM compiler, adding MMX support"
#
	    status=0
	else
	    echo \
"
* Couldn't find NASM compiler -- not compiling MMX support for $1
  (NASM is available from: http://www.cryogen.com/Nasm/ ) "
#
		status=1
	fi
	return $status
}

# The following global variables must be set:
#
#	$1		The interface subsystem
#
# The following global variables are set by this function:
#
#	$includes	Header directories for building shared library
#	$options	Compiler flags for building shared library
#	$asmobjs	Assembler objects to add to the build list
#	$libraries	The set of SDL libraries to build
#	$extralibs	Extra libraries necessary for building SDL
#
GenSubsystemFlags()
{
	case $1 in
	  windib)
		libraries="$libraries lib/SDL-dib.dll"
		;;
	  directx)
		libraries="$libraries lib/SDL-dx5.dll"
		;;
	  *)
		echo "Unknown subsystem '$1'"
		exit 3
		;;
	esac
}

# The following global variables must be set:
#
#	$1		The interface subsystem directory
#
# The following global variables are set by this function:
#
#	$includes	Header directories for building shared library
#	$options	Compiler flags for building shared library
#	$asmobjs	Assembler objects to add to the build list
#	$libraries	The set of SDL libraries to build
#	$extralibs	Extra libraries necessary for building SDL
#
GenMakeFlags()
{
	# Check for NASM and X86 for assembly blitter support
	if CheckNASM $subsystem; then
	    options="$options -DUSE_ASMBLIT"
	    asmobjs="$asmobjs obj/mmx_main.o"
	    asmobjs="$asmobjs obj/mmxp_32.o"
	    asmobjs="$asmobjs obj/x86_main.o"
	    asmobjs="$asmobjs obj/x86p_16.o"
	    asmobjs="$asmobjs obj/x86p_32.o"
	fi
}

# Check to make sure the compiler environment is sane
if CheckWinGCC; then
    :
else
    echo "
Couldn't compile a simple windows program.
 -- is your Win32 C compiler first in your execution path?
    "
    exit 1
fi

# Determine which subsystems to build
includes="$includes -Idirectx/include"
if CheckDirectX; then
    possible="WinDIB DirectX"
else
    prompt \
"Couldn't find DirectX headers -- will you install them?  [y/N] "
    read have_headers
    if [ "$have_headers" = "y" -o "$have_headers" = "Y" ]; then
    	echo \
"
* Read the directx/README file for header installation instructions
"
    	exit 1
    else
    	options="$options -DNO_DIRECTX_HEADERS"
    fi
    possible="WinDIB"
fi
