#!/bin/sh

# Uncomment the next line for testing
#set -x

TEMPLATE_PROJ=`echo "$1" | tr '[A-Z]' '[a-z]'`

XCODE_PROJ_NAME=Proj.xcodeproj

if [ "$TEMPLATE_PROJ" == "" ]; then
	echo "Must specify template project"
	exit 1
fi


if [ "$0" == "./copyProjects.sh" ]; then

	. ./setProjList.sh

	cd ..
	CARRARASDK=`pwd`
	
	echo "sdk: $CARRARASDK"
	
	#Find the template path
	for projPath in $PROJ_LIST ;
	do
		CUR_PROJ=`basename $projPath | tr '[A-Z]' '[a-z]'`
		
		if [ "$TEMPLATE_PROJ" == "$CUR_PROJ" ]; then
			SRC_PROJ="$CARRARASDK/Samples/$projPath/$XCODE_PROJ_NAME"
		fi		
	done
	
	if [ ! -d $SRC_PROJ ]; then
		echo "The template project ($SRC_PROJ) does not exist"
		exit 1
	else
		echo "Using template: $SRC_PROJ"
	fi

	
	for projPath in $PROJ_LIST ;
	do
		CUR_PROJ=`basename $projPath | tr '[A-Z]' '[a-z]'`
		
		if [ "$TEMPLATE_PROJ" == "$CUR_PROJ" ]; then
			echo "Skipping reference project: $projPath"
		else
			DST_PROJ="$CARRARASDK/Samples/$projPath/$XCODE_PROJ_NAME"
			cp -R "$SRC_PROJ" "$DST_PROJ"
		fi
	done
	
else
	echo "This script must be called from the BuildMac folder: ./copyProjects.sh"
fi



