#!/bin/sh

NAME="[toluapp]"
WORKING_DIR="tolua++/toluapp-master"

BUILD_DIR=build

source ./build_common.sh

if [ $DO_CLEAN -eq 1 ]
then
	rm -rf $BUILD_DIR
	check_result $? "cleaning build dir"
fi

if [ $DO_BUILD -eq 1 ]
then
	# prepare build
	mkdir -p $BUILD_DIR
	check_result $? "creating build dir"
	cd $BUILD_DIR
	
	# export env variable
	export LUA_DIR="${TEMP_DIR}/ceguideps"

	# run cmake
	cmake .. -G "MSYS Makefiles"
	check_result $? "cmake"

	# compile
	make -j8
	check_result $? "make"

	# copy lib
	find "." -name "*.dll" -exec cp -a {} ${TARGET_BIN_DIR} \;
	check_result $? "copying library"
	
	# add to ceguideps
	mkdir -p "${TEMP_DIR}/ceguideps/lib"
	check_result $? "create lib dir"
	mkdir -p "${TEMP_DIR}/ceguideps/include"
	check_result $? "create include dir"
	
	find "." -name "*.dll" -exec cp -a {} "${TEMP_DIR}/ceguideps/lib" \;
	check_result $? "copy lib"
	find "../include" -name "*.h" -exec cp -a {} "${TEMP_DIR}/ceguideps/include" \;
	check_result $? "copy includes"

	echo "${NAME} Finished building ${NAME}"
fi
