# Copyright 2015 Julian Ospald <hasufell@posteo.de>,
#                Heiko Schaefer <heiko@rangun.de>
# Distributed under the terms of the GNU General Public License v2

require flag-o-matic
require autotools [ supported_autoconf=[ 2.5 ] supported_automake=[ 1.15 ] ]
require lua [ whitelist="5.1" multibuild=false ]
require bash-completion
require github [ user=velnias75 tag=V${PV} ]

SUMMARY="Server for the popular card game Mau Mau"

LICENCES="LGPL-3"
SLOT="0"
PLATFORMS="~amd64 ~x86"
MYOPTIONS="
    console-client [[ description = [ Build a console based client ] ]]
    http [[ description = [ Enable embedded HTTP server ] ]]
"

DEPENDENCIES="
    build:
        dev-util/xxdi
        sys-apps/help2man
        virtual/awk
        virtual/pkg-config
    build+run:
        dev-db/sqlite:3
        dev-lang/lua:5.1
        dev-libs/popt
        sci-libs/gsl
        sys-apps/file
        http? (
            net-libs/libmicrohttpd
            sys-libs/zlib
        )
    suggestion:
        games-board/netmaumau [[ description = [ The GUI client for NetMauMau ] ]]
        sys-apps/xinetd [[ description = [ NetMauMau provides xinetd scripts ] ]]
"

WORK=${WORKBASE}/NetMauMau-${PV}

DEFAULT_SRC_CONFIGURE_PARAMS=(
    --disable-apidoc
    --disable-static
    --docdir=/usr/share/doc/${PNVR}
    --enable-ai-image="${FILES}/gblend.png"
    --enable-ai-name='Gentoo Hero'
    --enable-client
    --enable-xinetd
    --localstatedir=/var/lib/games/
    --with-bashcompletiondir="${BASHCOMPLETIONDIR}"
)

DEFAULT_SRC_CONFIGURE_OPTION_ENABLES=(
    'console-client'
    'http webserver'
)

DEFAULT_SRC_CONFIGURE_OPTION_WITHS=(
    "http zlib /usr/$(exhost --target)"
)

src_configure() {
    append-cppflags -DNDEBUG
    default
}

src_install() {
    default
    bash-completion_src_install
    keepdir /var/lib/games/netmaumau
    chown nobody:nogroup "${IMAGE%/}"/var/lib/games/netmaumau
}

pkg_postinst() {
    elog "You will need to restart your server instance for"
    elog "the changes to take effect."
}