
CheckGLIBC()
{
	cat >glibc.c <<__EOF__
#include <stdlib.h>
#include <features.h>
#ifdef __GLIBC__
int main () { exit(0); }
#else
int main () { exit(1); }
#endif
__EOF__
	make glibc >/dev/null 2>&1
	if [ -x glibc ] && ./glibc >/dev/null; then
	    status=0
	else
	    status=1
	fi
	rm -f glibc.c glibc
	return $status
}

CheckXF86DGA()
{
	cat >xf86dga.c <<__EOF__
#include <X11/Xlib.h>
#include <X11/extensions/xf86dga.h>
#include <X11/extensions/xf86vmode.h>
int main () { exit(0); }
__EOF__
	make CFLAGS="-I/usr/X11R6/include" xf86dga >/dev/null 2>&1
	status=$?
	rm -f xf86dga.c xf86dga
	return $status
}

CheckMTRR()
{
	cat >mtrr.c <<__EOF__
#include <asm/mtrr.h>
int main() { struct mtrr_sentry entry; exit(0); }
__EOF__
	make mtrr >/dev/null 2>&1
	status=$?
	rm -f mtrr.c mtrr
	return $status
}

CheckESD()
{
	cat >esd.c <<__EOF__
#include <esd.h>
int main () { exit(0); }
__EOF__
	make LDFLAGS="-lesd" esd >/dev/null 2>&1
	status=$?
	rm -f esd.c esd
	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
	  x11)
		includes="$includes -I/usr/X11R6/include -Isrc/linux/x11"
		libraries="$libraries lib/libSDLx11.so.\$(version)"
		if CheckXF86DGA; then
		    echo \
"
* Detected XFree86 Direct Graphics Access extension (supported) "
#
		    options="$options -DXFREE86_DGA"
		    extralibs="$extralibs -lXxf86dga -lXxf86vm"
		fi
		if CheckMTRR; then
		    echo \
"
* Detected MTRR (Memory Type Range Register) interface (supported) "
#
		    options="$options -DMTRR_SUPPORT"
		fi
		;;
	  svga)
		includes="$includes -Isrc/linux/svgalib"
		libraries="$libraries lib/libSDLsvga.so.\$(version)"
		;;
	  ggi)
		includes="$includes -Isrc/linux/ggi"
		libraries="$libraries lib/libSDLggi.so.\$(version)"
		;;
	  *)
		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
	case `uname -m` in
	  i?86)	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
		;;
	  *)    ;;
	esac

	# Check for ESD audio daemon support
	if CheckESD; then
	    echo \
"
* Detected Enlightenment Sound Daemon audio API (supported) "
#
	    options="$options -DESD_SUPPORT"
	    extralibs="$extralibs -lesd"
	fi

	# Check for broken LinuxPPC pthreads
	if [ "`uname -m`" = "ppc" ]; then
		set -- `uname -r | sed 's/\./ /g'`
		if [ "$1" -lt 2 -o "$2" -lt 2 ]; then
		    echo \
"
* Linux threads are broken under LinuxPPC 4.x (fixed in LinuxPPC 5.0)"
#
		    brokenthreads=true
		fi
	fi
	if [ "$brokenthreads" = "true" ]; then
	    options="$options -DFORK_HACK -D_REENTRANT"
	elif CheckGLIBC; then
	    echo \
"
* Compiling with pthreads -- you need compile your application with
   -D_REENTRANT and link with the pthread library (-lpthread)"
#
	    options="$options -DSDL_USE_PTHREADS -D_REENTRANT"
	else
	    asmobjs="$asmfiles clone.o"
	fi
}

# Determine which subsystems to build
# WARNING: The SVGA driver is ALPHA quality and may lock your system!
#possible="X11 SVGA"
possible="X11"
