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

require desktop-utils
require cmake [ api=2 out_of_source=false ]
require sourceforge [ project=alleg suffix=tar.gz ]

SUMMARY="cross-platform multimedia library"

LICENCES="Allegro MIT GPL-2 ZLIB"
SLOT="0"
PLATFORMS="amd64 ~mips ppc ppc64 x86"
MYOPTIONS="
    alsa
    fbcon [[ description = [ Add framebuffer support for the console,
                             via the kernel ] ]]
    jack
    opengl
    oss
    ogg
    ( providers: ijg-jpeg jpeg-turbo ) [[ number-selected = exactly-one ]]
"

DEPENDENCIES="
    build:
        virtual/pkg-config
        x11-proto/xorgproto
    build+run:
        media-libs/libpng:=
        x11-libs/libX11
        x11-libs/libXcursor
        x11-libs/libXext
        x11-libs/libXpm
        x11-libs/libXt
        x11-libs/libXxf86dga
        x11-libs/libXxf86vm
        alsa? ( sys-sound/alsa-lib )
        jack? ( media-sound/jack-audio-connection-kit )
        ogg? ( media-libs/libvorbis )
        opengl? (
            x11-dri/glu
            x11-dri/mesa
        )
        providers:ijg-jpeg? ( media-libs/jpeg:= )
        providers:jpeg-turbo? ( media-libs/libjpeg-turbo )
"

DEFAULT_SRC_PREPARE_PATCHES=(
    -p0 "${FILES}"/${PNV}-underlink.patch
)

CMAKE_SRC_CONFIGURE_PARAMS=(
    "-DCMAKE_SKIP_BUILD_RPATH=TRUE"
    "-DDOCDIR=/usr/share/doc"
    "-DINFODIR=/usr/share/info"
    "-DMANDIR=/usr/share/man"
    "-DWANT_EXAMPLES=OFF"
    "-DWANT_JPGALLEG=ON"
    "-DWANT_LINUX_CONSOLE=OFF"
    "-DWANT_LINUX_SVGALIB=OFF"
    "-DWANT_LINUX_VGA=ON"
    "-DWANT_LOADPNG=ON"
    "-DWANT_TOOLS=ON"
    "-DWANT_X11=ON"
)

CMAKE_SRC_CONFIGURE_OPTION_WANTS=(
    "alsa   ALSA"
    "fbcon  LINUX_FBCON"
    "jack   JACK"
    "ogg    LOGG"
    "opengl ALLEGROGL"
    "oss    OSS"
)

CMAKE_SRC_CONFIGURE_TESTS=(
    "-DWANT_TESTS=ON"
)

src_prepare() {
    default

    edo sed -i \
        -e 's#ADDON_LINKAGE STATIC#ADDON_LINKAGE SHARED#' \
        CMakeLists.txt
}

src_install() {
    cmake_src_install

    newbin setup/setup ${PN}-setup
    insinto /usr/share/${PN}
    doins {keyboard,language,setup/setup}.dat
    insinto /usr/share/pixmaps
    newins misc/icon.png ${PN}.png

    install_desktop_entry "Name=Allegro Setup" \
        "Exec=allegro-setup" "Categories=Settings;"
}