# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem               1.0
PortGroup                cmake 1.1
PortGroup                github 1.0
PortGroup                boost 1.0

# bump revision when changes are made to this file
revision                 1

github.setup             @GITHUB_OWNER@ @GITHUB_REPO@ @GITHUB_BRANCH@
name                     @PROJECT_NAME@
version                  @PROJECT_VERSION@
categories               multimedia emulators games
platforms                darwin
license                  GPL-3
maintainers              {@SunshineStream sunshinestream}
description              @PROJECT_DESCRIPTION@
long_description         {*}${description}
homepage                 @PROJECT_HOMEPAGE_URL@
master_sites             https://github.com/@GITHUB_OWNER@/@GITHUB_REPO@/releases

fetch.type               git
post-fetch {
    system -W ${worksrcpath} "${git.cmd} submodule update --init --recursive"
}

depends_lib              port:avahi \
                         port:ffmpeg \
                         port:libopus

boost.version            1.76

configure.args           -DBOOST_ROOT=[boost::install_area] \
                         -DSUNSHINE_ASSETS_DIR=${prefix}/etc/sunshine/assets \
                         -DSUNSHINE_CONFIG_DIR=${prefix}/etc/sunshine/config

cmake.out_of_source      yes

startupitem.create       yes
startupitem.executable   "${prefix}/bin/{$name}"
startupitem.location     LaunchDaemons
startupitem.name         ${name}
startupitem.netchange    yes

# is this actually necessary? this should all be handled by CMakeLists
destroot {
    # install assets
    xinstall -d -m 755 ${destroot}${prefix}/etc/${name}/assets
    xinstall {*}[glob ${worksrcpath}/src_assets/common/assets/*.*] ${destroot}${prefix}/etc/${name}/assets
    xinstall {*}[glob ${worksrcpath}/src_assets/macos/assets/*.*] ${destroot}${prefix}/etc/${name}/assets

    # install web assets
    xinstall -d -m 755 ${destroot}${prefix}/etc/${name}/assets/web/fonts/fontawesome-free-web/css
    xinstall -d -m 755 ${destroot}${prefix}/etc/${name}/assets/web/fonts/fontawesome-free-web/webfonts
    xinstall {*}[glob ${worksrcpath}/src_assets/common/assets/web/*.*] ${destroot}${prefix}/etc/${name}/assets/web
    xinstall {*}[glob ${worksrcpath}/src_assets/common/assets/web/fonts/fontawesome-free-web/*.*] ${destroot}${prefix}/etc/${name}/assets/web/fonts/fontawesome-free-web
    xinstall {*}[glob ${worksrcpath}/src_assets/common/assets/web/fonts/fontawesome-free-web/css/*.*] ${destroot}${prefix}/etc/${name}/assets/web/fonts/fontawesome-free-web/css
    xinstall {*}[glob ${worksrcpath}/src_assets/common/assets/web/fonts/fontawesome-free-web/webfonts/*.*] ${destroot}${prefix}/etc/${name}/assets/web/fonts/fontawesome-free-web/webfonts
    xinstall -d -m 755 ${destroot}${prefix}/etc/${name}/assets/web/images
    xinstall -d -m 755 ${destroot}${prefix}/etc/${name}/assets/web/third_party
    xinstall {*}[glob ${worksrcpath}/src_assets/common/assets/web/images/*.*] ${destroot}${prefix}/etc/${name}/assets/web/images
    xinstall {*}[glob ${worksrcpath}/src_assets/common/assets/web/third_party/*.*] ${destroot}${prefix}/etc/${name}/assets/web/third_party

    xinstall -d -m 755 ${destroot}${prefix}/etc/${name}/config

    # install sunshine.conf
    xinstall {*}[glob ${worksrcpath}/src_assets/common/config/*.*] ${destroot}${prefix}/etc/${name}/config

    # install apps.json
    xinstall {*}[glob ${worksrcpath}/src_assets/macos/config/*.*] ${destroot}${prefix}/etc/${name}/config

    # install the binary
    xinstall ${workpath}/build/${name} ${destroot}${prefix}/bin
}
