# Copyright 2016 Julian Ospald
# Distributed under the terms of the GNU General Public License v2

require github [ user=solarus-games tag=v${PV} ] \
    cmake [ api=2 ] \
    lua [ whitelist="5.1" multibuild=false ] \
    gtk-icon-cache

SUMMARY="GUI to edit quests for the Solarus engine"

LICENCES="
    GPL-3 [[ note = [ original source code ] ]]
    CCPL-Attribution-ShareAlike-3.0 [[ note = [ images in the editor ] ]]
"
SLOT="0"
PLATFORMS="~amd64 ~x86"
MYOPTIONS=""

DEPENDENCIES="
    build:
        x11-libs/qttools:5
    build+run:
        dev-games/physfs
        games-engines/solarus[>=1.5.1]
        media-libs/SDL:2
        media-libs/SDL_image:2
        media-libs/SDL_ttf:2
        media-libs/libmodplug[>=0.8.8.4]
        media-libs/libvorbis
        media-libs/openal
        x11-libs/qtbase:5
"

BUGS_TO="hasufell@posteo.de"

CMAKE_SRC_CONFIGURE_PARAMS=(
    -DCMAKE_INSTALL_PREFIX="/usr"
    -DSOLARUS_INCLUDE_DIR="/usr/$(exhost --target)/include/solarus"
    -DSOLARUS_INSTALL_BINDIR="/usr/$(exhost --target)/bin"
    -DSOLARUS_LIBRARY="/usr/$(exhost --target)/lib/libsolarus.so"
    -DSOLARUS_USE_LUAJIT=OFF
)

src_prepare() {
    cmake_src_prepare

    edo sed -i \
        -e "s#^Exec=.*#Exec=${PN}#" \
        -e "s#^Icon=.*#Icon=${PN}#" \
        "${CMAKE_SOURCE}"/resources/solarus-quest-editor.desktop

    # code doesn't expect share and bin to have different prefixes, although
    # cmake allows it
    edo sed -i \
        -e '/bool running_installed_executable = /s#executable_path == .*$#executable_path == "/usr/'$(exhost --target)'/bin");#' \
            "${CMAKE_SOURCE}"/src/file_tools.cpp
}