#
# set -o errexit -o noglob are assumed.
#

pkg_cmake_configure() {
	ex_rtl_fileop cp "${PREFIX}/share/cmake-${PKG_VERSION%.*}/Modules/Platform/BSDOS.cmake" \
		"${PREFIX}/share/cmake-${PKG_VERSION%.*}/Modules/Platform/Midipix.cmake";
	rm -f config.cache;
	env	CFLAGS="-L${PKG_PREFIX}/lib --sysroot=${PKG_PREFIX}"		\
		PREFIX=""							\
	cmake	-DBZIP2_INCLUDE_DIR="${PKG_PREFIX}/include"			\
		-DBZIP2_LIBRARIES="${PKG_PREFIX}/lib/libbz2.a"			\
		-DCMAKE_AR="${PREFIX}/bin/${PKG_AR}"				\
		-DCMAKE_C_COMPILER="${PREFIX}/bin/${PKG_CC}"			\
		-DCMAKE_CXX_COMPILER="${PREFIX}/bin/${PKG_TARGET}-g++"		\
		-DCMAKE_INSTALL_PREFIX=						\
		-DCMAKE_RANLIB="${PREFIX}/bin/${PKG_RANLIB}"			\
		-DCMAKE_SYSTEM_NAME=Midipix					\
		-DCMAKE_USE_SYSTEM_BZIP2=ON					\
		-DCMAKE_USE_SYSTEM_CURL=ON					\
		-DCMAKE_USE_SYSTEM_EXPAT=OFF					\
		-DCMAKE_USE_SYSTEM_LIBUV=ON					\
		-DCMAKE_USE_SYSTEM_LIBARCHIVE=ON				\
		-DCMAKE_USE_SYSTEM_ZLIB=ON					\
		-DCMAKE_VERBOSE_MAKEFILE=ON					\
		-DCURL_INCLUDE_DIR="${PKG_PREFIX}/include/curl"			\
		-DCURL_LIBRARY="${PKG_PREFIX}/lib/libcurl.lib.a"		\
		-DCURSES_NCURSES_LIBRARY="${PKG_PREFIX}/lib/libncurses.lib.a"	\
		-DKWSYS_LFS_WORKS=YES						\
		-DLibUV_INCLUDE_DIR="${PKG_PREFIX}/include"			\
		-DLibUV_LIBRARY="${PKG_PREFIX}/lib/libuv.1.0.0.lib.a"		\
		-DLibArchive_INCLUDE_DIR="${PKG_PREFIX}/include"		\
		-DLibArchive_LIBRARY="${PKG_PREFIX}/lib/libarchive.lib.a"	\
		-DLIBLZMA_HAS_AUTO_DECODER=YES					\
		-DLIBLZMA_HAS_EASY_ENCODER=YES					\
		-DLIBLZMA_HAS_LZMA_PRESET=YES					\
		-DLIBLZMA_INCLUDE_DIR="${PKG_PREFIX}/include"			\
		-DLIBLZMA_LIBRARY="${PKG_PREFIX}/lib/liblzma.lib.a"		\
		-DZLIB_INCLUDE_DIR="${PKG_PREFIX}/include"			\
		-DZLIB_LIBRARY="${PKG_PREFIX}/lib/libz.a"			\
		"../cmake-${PKG_VERSION}";
};

pkg_cmake_install_make_pre() {
	if [ ! -e cmake_install.cmake.orig ]; then
		sed -i.orig '/^\s*set(CMAKE_INSTALL_PREFIX ".*")$/s/".*"/""/'	\
			cmake_install.cmake;
	fi;
};

pkg_cmake_host_install_make_pre() {
	pkg_cmake_install_make_pre;
};

# vim:filetype=sh