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

require cmake [ api=2 ]
require github [ user=ja2-stracciatella tag=v${PV} ]
require desktop-utils gtk-icon-cache

SUMMARY="A port of Jagged Alliance 2 to SDL"
HOMEPAGE+=" http://tron.homeunix.org/ja2/"
DOWNLOADS+=" mirror://gentoo/editor.slf.gz"

LICENCES="
    SFI-SCLA [[ note = [ Original Jagged Alliance source codes ] ]]
    public-domain [[ note = [ all changes since commit 8287b98 ] ]]
    ZLIB [[ note = [ _build/lib-MicroIni ] ]]
    LGPL-2.1 [[ note = [ _build/lib-SDL-* ] ]]
    Boost-1.0 [[ note = [ _build/lib-boost, _build/lib-utf8cpp ] ]]
    BSD-3 [[ note = [ _build/lib-gtest ] ]]
    MIT [[ note = [ _build/lib-rapidjson, _build/lib-slog ] ]]
    CCPL-Attribution-NonCommercial-2.0 [[ note = [ _build/lib-smacker ] ]]
"
SLOT="0"
PLATFORMS="~amd64 ~x86"

DEPENDENCIES="
    build:
        dev-lang/rust
    build+run:
        dev-libs/boost
        media-libs/SDL:2[>=2.0.4][X]
    suggestion:
        games-strategy/ja2-stracciatella-data [[ description = [ GOG data files
                                                                 of ja2 ] ]]
"

DEFAULT_SRC_PREPARE_PATCHES=(
    "${FILES}"/0001-BUILD-fix-install-paths-by-utilizing-GNUInstallDirs.patch
)

src_prepare() {
    edo sed -i \
        -e 's#/some/place/where/the/data/is#/usr/share/ja2#' \
        "${CMAKE_SOURCE}"/rust/src/stracciatella.rs
    default
}

src_compile() {
    # cargo fetching during build time
    esandbox disable_net
    default
    esandbox enable_net
}

src_install() {
    cmake_src_install

    insinto /usr/share/ja2/data
    doins "${WORKBASE}"/editor.slf

    install_desktop_entry 'Exec=ja2'
}

pkg_postinst() {
    elog "If you don't use games-strategy/ja2-stracciatella-data, then"
    elog "you need to copy all files from the Data directory of"
    elog "Jagged Alliance 2 installation to some directory and set it in"
    elog "  ~/.ja2/ja2.ini"
    elog "possibly utilizing app-arch/innoextract for windows .exe files."
    elog
    elog "Make sure the filenames are all lowercase."
}