#!/bin/sh
 
##Build script for Darwin Streaming Server


OSNAME=`uname`
HARDWARENAME=`uname -m`
 
PLAT=$OSNAME.$HARDWARENAME

echo "Darwin Streaming Server"
echo "-----------------------"


case $PLAT in

	Linux.ppc)
        echo "Configuring for the "$OSNAME" "$HARDWARENAME" platform"
		CPLUS=gcc
		CCOMP=gcc
		LINKER='gcc'
 		MAKE=make
 		
		COMPILER_FLAGS= "-D__linuxppc__ -Wno-multichar -pipe"
        INCLUDE_FLAG="-include"
		
		CORE_LINK_LIBS="-lpthread -ldl -lm -lcrypt"

		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 the "$OSNAME" "$HARDWARENAME" platform"
		CPLUS=gcc
		CCOMP=gcc
		LINKER='gcc'
 		MAKE=make
 		
		COMPILER_FLAGS="-D_REENTRANT -D__USE_POSIX -D__linux__ -pipe"
        INCLUDE_FLAG="-include"
		
		CORE_LINK_LIBS="-lpthread -ldl -lm -lcrypt -lstdc++"

		SHARED=-shared
		MODULE_LIBS=
		
		if [ -f /usr/include/socketbits.h ]; then
			NEED_SOCKETBITS=1
			export NEED_SOCKETBITS
		fi
		;;

	Linux.mips)
        echo "Configuring for the "$OSNAME" "$HARDWARENAME" platform"
		CPLUS=gcc
		CCOMP=gcc
		LINKER='egcs'
 		MAKE=make
 		
		COMPILER_FLAGS="-D_REENTRANT -D__linux__ -Wno-multichar -pipe"
        INCLUDE_FLAG="-include"
		
		CORE_LINK_LIBS="-lpthread -ldl -lm -lcrypt"

		SHARED=-shared
		MODULE_LIBS=
		
		if [ -f /usr/include/socketbits.h ]; then
			NEED_SOCKETBITS=1
			export NEED_SOCKETBITS
		fi
		;;

	FreeBSD.i386)
        echo "Configuring for the "$OSNAME" "$HARDWARENAME" platform"
		CPLUS=gcc
		CCOMP=gcc
		LINKER="gcc"
 		MAKE=make
 		
		COMPILER_FLAGS=
        INCLUDE_FLAG="-include"
		
		CORE_LINK_LIBS="-pthread -lm -lcrypt"

		SHARED=-shared
		MODULE_LIBS="-lgcc -lstdc++"
		;;
	
#	SunOS.sun4m | \
#	SunOS.sun4u)
	SunOS.*)
        echo "Configuring for the "$OSNAME" "$HARDWARENAME" platform"
		CPLUS=g++
		CCOMP=gcc
		LINKER="g++"
 		MAKE=make
 		
		COMPILER_FLAGS="-D__solaris__ -D_REENTRANT -L/usr/local/lib -R/usr/local/lib"
        INCLUDE_FLAG="-include"

		CORE_LINK_LIBS="-lpthread -ldl -lsocket -lnsl -lresolv -lm -lcrypt -lstdc++"

		SHARED=-G
		MODULE_LIBS=
		;;
		
 	OSF1.alpha)
         echo "Configuring for the "$OSNAME" "$HARDWARENAME" Tru64 UNIX platform"
 		CPLUS=`pwd`/my_tru64_cxx
 		CCOMP=cc
		LINKER="cxx"
		MAKE=/usr/local/bin/make

 		COMPILER_FLAGS="-D__osf__ -DTRUCLUSTER -pthread"
        INCLUDE_FLAG="-FI"

		CORE_LINK_LIBS="-lpthread -lclu -lm"

		SHARED=-shared
		MODULE_LIBS=
 		;;

	"Darwin.Power Macintosh")
         echo "Configuring for "$OSNAME" on "$HARDWARENAME". This is a pbxbuild of the QuickTimeStreamingServer."
 	
 		;;

	
	*)
		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=gcc
		CCOMP=gcc
		LINKER='egcs'
 		MAKE=make
 		
		COMPILER_FLAGS=-D__linux__
        INCLUDE_FLAG="-include"

		CORE_LINK_LIBS="-lpthread -ldl -lm -lcrypt"

		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}" = "Darwin.Power Macintosh" ]; then

	## just need to call "pbxbuild" for Mac OS X
	pbxbuild $*
	
else
	export CPLUS
	export CCOMP
	export LINKER
	export COMPILER_FLAGS
	export INCLUDE_FLAG
	export CORE_LINK_LIBS
	export SHARED
	export MODULE_LIBS
	
echo Building CommonUtilitiesLib for $PLAT with $CPLUS
	cd CommonUtilitiesLib/
	$MAKE -f Makefile.POSIX $*

echo Building QTFileLib for $PLAT with $CPLUS
	cd ../QTFileLib/
	$MAKE -f Makefile.POSIX $*

echo Building StreamingServer for $PLAT with $CPLUS
	cd ..
	$MAKE -f Makefile.POSIX $*

echo Building DemoAuthorizationModule for $PLAT with $CPLUS
	cd APIModules/QTSSDemoAuthorizationModule.bproj/
	$MAKE -f Makefile.POSIX $*
	
echo Building RawFileModule for $PLAT with $CPLUS
	cd ../QTSSRawFileModule.bproj/
	$MAKE -f Makefile.POSIX $*
	
echo Building SpamDefenseModule for $PLAT with $CPLUS
	cd ../QTSSSpamDefenseModule.bproj/
	$MAKE -f Makefile.POSIX $*
	
	cd ..
	
echo Building StreamingProxy for $PLAT with $CPLUS
	cd ../StreamingProxy.tproj/
	$MAKE -f Makefile.POSIX $*
	
echo Building qtpasswd for $PLAT with $CPLUS
	cd ../qtpasswd.tproj/
	$MAKE -f Makefile.POSIX $*

echo Building PlaylistBroadcaster for $PLAT with $CPLUS
	cd ../PlaylistBroadcaster.tproj/
	$MAKE -f Makefile.POSIX $*
	
echo Building MP3Broadcaster for $PLAT with $CPLUS
	cd ../MP3Broadcaster/
	$MAKE -f Makefile.POSIX $*
	
echo Building QTFileTools for $PLAT with $CPLUS
        cd ../QTFileTools/

echo Building QTBroadcaster for $PLAT with $CPLUS
	cd QTBroadcaster.tproj/
	$MAKE -f Makefile.POSIX $*

echo Building QTFileInfo for $PLAT with $CPLUS
	cd ../QTFileInfo.tproj/
	$MAKE -f Makefile.POSIX $*

echo Building QTFileTest for $PLAT with $CPLUS
	cd ../QTFileTest.tproj/
	$MAKE -f Makefile.POSIX $*

echo Building QTRTPFileTest for $PLAT with $CPLUS
	cd ../QTRTPFileTest.tproj/
	$MAKE -f Makefile.POSIX $*

echo Building QTRTPGen for $PLAT with $CPLUS
	cd ../QTRTPGen.tproj/
	$MAKE -f Makefile.POSIX $*

echo Building QTSDPGen for $PLAT with $CPLUS
	cd ../QTSDPGen.tproj/
	$MAKE -f Makefile.POSIX $*

echo Building QTSampleLister for $PLAT with $CPLUS
	cd ../QTSampleLister.tproj/
	$MAKE -f Makefile.POSIX $*

echo Building QTTrackInfo for $PLAT with $CPLUS
	cd ../QTTrackInfo.tproj/
	$MAKE -f Makefile.POSIX $*

if [ -d ../../SpamPro.tproj ]; then
	echo Building StreamingLoadTool for $PLAT with $CPLUS
		cd ../../SpamPro.tproj/
		$MAKE -f Makefile.POSIX $*
fi


fi
