#!/bin/sh
 
x=`uname`
y=`uname -m`
 
PLAT=$x.$y

echo $PLAT

case $PLAT in

	"Rhapsody.Power Macintosh")
		## nothing to do here...
		;;

	Linux.ppc)
		echo "Configuring for a Linux PPC platform"
		CPLUS='egcs'
		CCOMP=egcs
		LINKER='egcs'
		MACHDEFINES=-D__linuxppc__
		PTHREADLIB=-lpthread
		DLLIB=-ldl
		SHARED=-shared
		MODULE_LIBS=
		if [ -f /usr/include/socketbits.h ]; then
			NEED_SOCKETBITS=1
			export NEED_SOCKETBITS
		fi
		;;		

	Linux.i586 | \
	Linux.i686)
		echo "Configuring for a Linux x86 platform"
		CPLUS='egcs'
		CCOMP=egcs
		LINKER='egcs'
		MACHDEFINES=-D__linux__
		DLLIB=-ldl
		PTHREADLIB=-lpthread
		SHARED=-shared
		MODULE_LIBS=
		if [ -f /usr/include/socketbits.h ]; then
			NEED_SOCKETBITS=1
			export NEED_SOCKETBITS
		fi
		;;

	FreeBSD.i386)
		echo "Configuring for a FreeBSD platform"
		CPLUS=gcc
		CCOMP=gcc
		LINKER="gcc"
		PTHREADLIB=-pthread
		DLLIB=
		SHARED=-shared
		MODULE_LIBS="-lgcc -lstdc++"
		MACHDEFINES="-D__FreeBSD__ -fhandle-exceptions"
		;;
	
	SunOS.sun4m)
		echo "Configuring for a Solaris platform"
		CPLUS=gcc
		CCOMP=gcc
		LINKER="gcc"
		PTHREADLIB=-lpthread
		DLLIB="-ldl -lsocket -lnsl"
		MACHDEFINES="-D__solaris__"
		SHARED=-G
		MODULE_LIBS=
		;;

	*)
		echo "I don't know your platform. I'll assume this is a Linux x86 platform."
		echo "Please edit the BuildServer script & PlatformHeader.h to add your platform."
		CPLUS='egcs'
		CCOMP=egcs
		LINKER='egcs'
		MACHDEFINES=-D__linux__
		DLLIB=-ldl
		PTHREADLIB=-lpthread
		SHARED=-shared
		MODULE_LIBS=
		if [ -f /usr/include/socketbits.h ]; then
			NEED_SOCKETBITS=1
			export NEED_SOCKETBITS
		fi
		;;
esac

echo Building for $PLAT with $CPLUS

if [ "${PLAT}" = "Rhapsody.Power Macintosh" ]; then

## just need to call "make" for Mac OS X Server
	make
	
else

	export CPLUS
	export CCOMP
	export LINKER
	export MACHDEFINES
	export PTHREADLIB
	export DLLIB
	export SHARED
	export MODULE_LIBS
	
	
	make -f Makefile.POSIX
	
	cd APIModules/QTSSAccessModule.bproj/
	make -f Makefile.POSIX
	
	cd ../QTSSDemoAuthorizationModule.bproj/
	make -f Makefile.POSIX
	
	cd ../QTSSRawFileModule.bproj/
	make -f Makefile.POSIX
	
	cd ../QTSSSpamDefenseModule.bproj/
	make -f Makefile.POSIX
	
	cd ..
	
	cd ../StreamingProxy.tproj/
	make -f Makefile.POSIX
	
	cd ../qtpasswd.tproj/
	make -f Makefile.POSIX
	
	cd ../PlaylistBroadcaster.tproj/
	make -f Makefile.POSIX

	if [ ! -f /etc/QTSS.conf ]; then
		echo "#################################################################"
		echo
		echo "Make sure that you modify streamingserver.conf and put it in your"
		echo "   /etc directory."
		echo "Items to change include 'movie_folder', 'request_logfile_dir',"
		echo "   and 'error_logfile_dir'."
		echo "Then, put hinted movie files into the 'movie_folder'."
		echo "Then, as root, run DarwinStreamingServer."
		echo
		echo "#################################################################"
	fi

fi


