# Copyright 2017 Julian Ospald <hasufell@posteo.de>
# Distributed under the terms of the GNU General Public License v2

WORK=${WORKBASE}/${PN}-community-${PV}-src

require cmake [ api=2 ]

SUMMARY="MySQL Workbench"
HOMEPAGE="https://www.mysql.com/products/workbench/"
DOWNLOADS="https://dev.mysql.com/get/Downloads/MySQLGUITools/${PN}-community-${PV}-src.tar.gz
    http://www.antlr3.org/download/antlr-3.4-complete.jar"

LICENCES="GPL-2"
SLOT="0"
PLATFORMS="~amd64 ~x86"
MYOPTIONS=""

# not 100% sure about tinyxml and net-tools
DEPENDENCIES="
    build:
        dev-lang/swig
        virtual/jre
        virtual/pkg-config
    build+run:
        app-arch/libzip
        dev-cpp/cairomm:1.0
        dev-cpp/ctemplate
        dev-cpp/libsigc++:2
        dev-db/libiodbc
        dev-db/mysql-connector-c++
        dev-db/vsqlite++
        dev-lang/python:2.7[sqlite]
        dev-libs/boost
        dev-libs/glib:2
        dev-libs/libxml2:2.0
        dev-libs/pcre
        dev-libs/tinyxml
        dev-python/paramiko[python_abis:2.7]
        dev-python/pexpect[python_abis:2.7]
        dev-python/pycairo[python_abis:2.7]
        gnome-bindings/atkmm:1.6
        gnome-bindings/glibmm:2.4
        gnome-bindings/gtkmm:3
        gnome-bindings/pangomm:1.4
        gnome-desktop/libgnome-keyring
        gnome-platform/libglade:2
        sci-libs/gdal
        virtual/mysql
        x11-dri/mesa
        x11-libs/cairo
        x11-libs/gdk-pixbuf:2.0
        x11-libs/gtk+:3
        x11-libs/libX11
        x11-libs/pango
    run:
        sys-apps/net-tools
"

BUGS_TO="hasufell@posteo.de"

src_prepare() {
    edo install -D "${FETCHEDDIR}"/antlr-3.4-complete.jar \
        "${WORKBASE}"/linux-res/bin/antlr-3.4-complete.jar

    # fix gdal includes
    edo sed -i \
            -e 's|#include <gdal/|#include <|' \
            "${CMAKE_SOURCE}"/backend/wbpublic/grt/*.h \
            "${CMAKE_SOURCE}"/backend/wbpublic/grtui/*.h \
            "${CMAKE_SOURCE}"/backend/wbpublic/objimpl/db.query/*.cpp

    # fix python detection
    edo sed -i \
            -e '/find_package(PythonLibs 2.6)/d' \
            "${CMAKE_SOURCE}"/CMakeLists.txt

    # rm -Werror, fails due to -Wdeprecated
    edo sed -i \
            -e 's/\-Werror//' \
            "${CMAKE_SOURCE}"/CMakeLists.txt

    cmake_src_prepare
}

src_configure() {
    CMAKE_SRC_CONFIGURE_PARAMS=(
        -DIODBC_CONFIG_PATH="/usr/$(exhost --target)/bin/iodbc-config"
        -DLIB_INSTALL_DIR="/usr/$(exhost --target)/lib"
        -DSHARE_INSTALL_PREFIX=/usr/share
    )

    cmake_src_configure
}