# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI=4

inherit cmake-utils

DESCRIPTION="Bidirectional file synchronizer (ownCloud fork)"
HOMEPAGE="http://www.csync.org/ http://owncloud.org/sync-clients/"
SRC_URI="http://download.owncloud.com/download/${P}.tar.bz2"

LICENSE="GPL-2"
SLOT="owncloud"
KEYWORDS="~amd64"
IUSE="doc +log2callback log4c samba sftp test +owncloud"

# no point in adding log4c dependency if log2callback is active
REQUIRED_USE="log2callback? ( !log4c )"

RDEPEND="dev-db/sqlite:3
	dev-libs/iniparser
	log4c? ( dev-libs/log4c )
	samba? ( net-fs/samba )
	sftp? ( net-libs/libssh[sftp] )
	owncloud? ( net-libs/neon )"
DEPEND="${RDEPEND}
	doc? ( app-doc/doxygen )
	test? ( dev-libs/check )"

DOCS=( "AUTHORS" "ChangeLog" "README" "doc/csync.txt" )
HTML_DOCS=( "doc/userguide" )
PATCHES=( "${FILESDIR}/${PV}-configureable-modules.patch" )

src_configure() {
	mycmakeargs=(
		$(cmake-utils_use log2callback LOG_TO_CALLBACK)
		$(cmake-utils_use_with log4c LOG4C)
		$(cmake-utils_use_want owncloud OWNCLOUD)
		$(cmake-utils_use_want samba SMB)
		$(cmake-utils_use_want sftp SFTP)
		$(cmake-utils_use test UNIT_TESTING)
	)
	cmake-utils_src_configure
}

src_compile() {
	cmake-utils_src_compile
	use doc && emake -C "${CMAKE_BUILD_DIR}" doc
}

src_install() {
	cmake-utils_src_install
	mv "${D}"/{usr,}/etc
	rm -rf "${D}/usr/share/doc/${PN}"
	use doc && dohtml -p api "${CMAKE_BUILD_DIR}/doc/html/"
}