################################################################################
#
# opensync.cygclass - functions for building OpenSync plugin packages
#
# Part of cygport - Cygwin packaging application
# Copyright (C) 2006-2015 Yaakov Selkowitz
# Provided by the Cygwin Ports project <http://sourceware.org/cygwinports/>
#
# cygport is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cygport is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cygport.  If not, see <http://www.gnu.org/licenses/>.
#
################################################################################

#****h* Cygclasses/opensync.cygclass
#  SYNOPSIS
#  inherit opensync
#  DESCRIPTION
#  OpenSync is a Personal Information Management (PIM) data syncronization
#  framework which supports various PIM sources through plugins.
#
#  This cygclass builds plugins for the new OpenSync 0.4x series, beginning
#  with 0.39.  Previous versions are no longer supported.
#  INHERITS
#  cmake.cygclass
#  REQUIRES
#  cmake, libopensync-devel, pkg-config
#****

inherit cmake

OPENSYNC_PLUGIN=${PN/libopensync*-plugin-}

DESCRIPTION="OpenSync ${OPENSYNC_PLUGIN} plugin"

#****o* opensync.cygclass/HOMEPAGE (opensync)
#  DEFINITION
HOMEPAGE="http://www.opensync.org/wiki/"
#****

#****o* opensync.cygclass/SRC_URI (opensync)
#  DESCRIPTION
#  Download location for the OpenSync plugin source package.
#****
SRC_URI="http://www.opensync.org/download/releases/${PV}/libopensync-plugin-${OPENSYNC_PLUGIN}-${PV}.tar.bz2"

SRC_DIR="libopensync-plugin-${OPENSYNC_PLUGIN}-${PV}"

case ${PV} in
	0.39|0.4*)	;;
	0.2*|0.3*)	error "opensync.cygclass: minimum supported version is 0.39" ;;
	*)			error "opensync.cygclass: unknown or unsupported version: ${PV}" ;;
esac

check_prog_req pkg-config

#****d* opensync.cygclass/OPENSYNC_VERSION
#  DESCRIPTION
#  Version of the currently installed OpenSync library.
#****
OPENSYNC_VERSION=$(pkg-config --modversion libopensync1)

#****d* opensync.cygclass/OPENSYNC_CONFIGDIR
#  DESCRIPTION
#  Installation directory for OpenSync default configuration files.
#****
OPENSYNC_CONFIGDIR=$(pkg-config --variable=configdir libopensync1)

#****d* opensync.cygclass/OPENSYNC_PLUGINDIR
#  DESCRIPTION
#  Installation directory for OpenSync C/C++ plugins.
#****
OPENSYNC_PLUGINDIR=$(pkg-config --variable=plugindir libopensync1)

#****d* opensync.cygclass/OPENSYNC_PYTHON_PLUGINDIR
#  DESCRIPTION
#  Installation directory for OpenSync Python plugins.
#****
OPENSYNC_PYTHON_PLUGINDIR=${OPENSYNC_PLUGINDIR%/*}/python-plugins

#****C* opensync.cygclass/opensync_plugin_compile
#  SYNOPSIS
#  opensync_plugin_compile [OPTIONS]
#  DESCRIPTION
#  Configures and compiles the OpenSync plugin package.  Options, if any, are
#  passed as flags to cygcmake.
#****
opensync_plugin_compile() {
	if [ ${PV} != ${OPENSYNC_VERSION} ]
	then
		error "${P} requires libopensync-devel-${PV}"
	fi

	cygcmake "${@}"
	cygmake
}

#****I* opensync.cygclass/opensync_doconfig
#  SYNOPSIS
#  opensync_doconfig FILE [FILE2] ...
#  DESCRIPTION
#  Installs OpenSync configuration files into OPENSYNC_CONFIGDIR.
#****
opensync_doconfig() {
	insinto ${OPENSYNC_CONFIGDIR}
	doins ${@}
}

#****I* opensync.cygclass/opensync_doplugin
#  SYNOPSIS
#  opensync_doplugin PLUGIN [PLUGIN2] ...
#  DESCRIPTION
#  Installs OpenSync plugins into OPENSYNC_PLUGINDIR or OPENSYNC_PYTHON_PLUGINDIR.
#****
opensync_doplugin() {
	local plugin

	for plugin
	do
		case ${plugin} in
			*.py)
				exeinto ${OPENSYNC_PYTHON_PLUGINDIR} ;;
			*.dll|*.la)
				exeinto ${OPENSYNC_PLUGINDIR} ;;
			*)
				error "opensync_doplugin: unknown plugin extension ${plugin##*.}"
		esac

		doexe ${@}
	done
}

#****o* opensync.cygclass/src_compile (opensync)
#  DEFINITION
src_compile() {
	cd ${B}
	opensync_plugin_compile
}
#****

readonly -f opensync_plugin_compile opensync_doconfig opensync_doplugin
