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

EAPI=5

inherit cmake-utils java-pkg-opt-2 versionator

DESCRIPTION="Zorba NoSQL query processor (JSON, XML, etc.)"
HOMEPAGE="http://www.zorba.io"
SRC_URI="https://launchpad.net/${PN}/trunk/$(get_version_component_range 1-2)/+download/zorba-${PV}.tar.gz"

LICENSE="Apache-2.0"
SLOT="0"
KEYWORDS="~amd64"
IUSE="debug java"

DEPEND=">=dev-libs/libxml2-2.2.16
	sys-apps/util-linux
	>=dev-libs/xerces-c-3.1.1
	dev-libs/icu
	java? (
	    >=dev-lang/swig-1.3.40
		=virtual/jdk-1.6*
	)"
# * sys-apps/util-linux is for libUUID
# * dev-libs/xerces-c is actually optional (not needed when using
#   ZORBA_NO_XMLSCHEMA=ON with CMake).  Documentation says Xerces-C 2.8.0 would also work
#   (with some bugs)
# * dev-libs/icu: documentation says "ICU4C 3.6 or later", whereas Portage has
#   something like dev-libs/icu-49.1.2 at the moment.
# * dev-lang/swig:
#   Java didn't work for me with dev-java/oracle-jdk-bin-1.7 in zorba-2.8.0,
#   so I restricted it to 1.6.
#   Note that bindings for Java, Ruby, PHP, Python are auto-generated if these
#   are installed; I do not currently enforce bindings for a language not to be
#   generated if the respective use flag is missing.
# 
# http://www.zorba.io/documentation/3.0/zorba/build/build_prerequisites/
# also mentions:
# * Iconv 1.12 (seems to be part of sys-libs/glibc)
# * CURL >= 7.12 (optional; net-misc/curl)
#   Build will automatically use an installed CURL unless we say
#   ZORBA_SUPPRESS_CURL=ON
# * LibXslt >= 1.1.24 (optional; dev-libs/libxslt)
#   Enable with ZORBA_XQUERYX=ON
# * Flex and Bison not needed to install, just when developing Zorba
# * further dependencies under "Non-core Module Requirements"
RDEPEND=">=dev-libs/libxml2-2.2.16
	sys-apps/util-linux
	>=dev-libs/xerces-c-3.1.1
	dev-libs/icu
	java? ( =virtual/jdk-1.6* )"

MAKEOPTS+=" -j1"

pkg_setup() {
	if use java; then
		java-pkg-opt-2_pkg_setup
	fi
}

src_configure() {
    filter-flags -j?
	
	local mycmakeargs=(
		-DZORBA_SUPPRESS_SWIG=ON
	)
	# Installing with SWIG didn't work
    # Error:
    #   * In program cave perform install --hooks --managed-output --output-exclusivity with-others =dev-libs/zorba-3.0:0::local --destination installed --replacing =dev-libs/zorba-2.9.0:0::installed --x-of-y 1 of 1:
    #   * When installing 'dev-libs/zorba-3.0:0::local' replacing { 'dev-libs/zorba-2.9.0:0::installed' }:
    #   * When running an ebuild command on 'dev-libs/zorba-3.0:0::local':
    #   * Install failed for 'dev-libs/zorba-3.0:0::local' (paludis::ActionFailedError)
    # 
    # -- Installing: /var/tmp/paludis/dev-libs-zorba-3.0/image/usr/lib64/libzorba_simplestore.so
    # -- Set runtime path of "/var/tmp/paludis/dev-libs-zorba-3.0/image//usr/lib64/libzorba_simplestore.so.3.0.0" to "/usr/lib"
    # -- Installing: /var/tmp/paludis/dev-libs-zorba-3.0/image/usr/share/python/zorba_api.py
    # CMake Error at swig/python/cmake_install.cmake:44 (FILE):
    #   file INSTALL cannot find
    #   "/var/tmp/paludis/dev-libs-zorba-3.0/work/zorba-3.0_build/swig/python/_zorba_api_python.so".
    # Call Stack (most recent call first):
    #   swig/cmake_install.cmake:37 (INCLUDE)
    #   cmake_install.cmake:47 (INCLUDE)
    # 
    # 
    # make: *** [install] Error 1

	cmake-utils_src_configure
}

src_install() {
	cmake-utils_src_install

	dodoc AUTHORS.txt ChangeLog KNOWN_ISSUES.txt NOTICE.txt README.txt
}