# -*- 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           github 1.0
PortGroup           legacysupport 1.1

github.setup        gpac gpac 2.4.0 v
revision            4
categories          multimedia
# https://trac.macports.org/ticket/56408
platforms           {darwin >= 12}
maintainers         {makr @mohd-akram} openmaintainer
license             LGPL-2.1+

description         multimedia framework for research and academic purposes
long_description    GPAC is an Open Source multimedia framework for \
                    research and academic purposes. The project \
                    covers different aspects of multimedia, with a \
                    focus on presentation technologies (graphics, \
                    animation and interactivity). Includes MP4Box and \
                    Osmo4.

homepage            https://gpac.wp.imt.fr

github.tarball_from archive
checksums           rmd160  a07a94f6bd0e8aafbe3a822fe55df9a324e4df13 \
                    sha256  99c8c994d5364b963d18eff24af2576b38d38b3460df27d451248982ea16157a \
                    size    9914579

# Needed for clock_gettime()
legacysupport.newest_darwin_requires_legacy \
                    15

set ffmpeg_ver      7

depends_build       path:bin/pkg-config:pkgconfig

depends_lib         port:freetype \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:libpng \
                    port:openjpeg \
                    port:libmad \
                    port:faad2 \
                    port:libogg \
                    port:libvorbis \
                    port:libtheora \
                    port:a52dec \
                    port:ffmpeg${ffmpeg_ver} \
                    port:XviD \
                    port:zlib \
                    path:lib/libssl.dylib:openssl \
                    port:libsdl2 \
                    port:libcaca \
                    port:nghttp2 \
                    port:pulseaudio \
                    port:xz

# Though HEVC is officially supported only in 10.13+, the symbol
# kCMVideoCodecType_HEVC is available in 10.11+ [1][2]
# [1] https://build.macports.org/builders/ports-10.10_x86_64-builder/builds/94933/steps/install-port/logs/stdio
# [2] https://build.macports.org/builders/ports-10.11_x86_64-builder/builds/94369/steps/install-port/logs/stdio
# Fix for FFmpeg 7 - https://github.com/gpac/gpac/issues/2991
patchfiles          patch-configure.diff \
                    patch-no-hevc-yosemite.diff \
                    patch-ffmpeg7.diff

post-patch {
    reinplace "s|@APPLICATIONS_DIR@|${applications_dir}|g" ${worksrcpath}/configure
}

# fatal error: 'stdatomic.h' file not found
compiler.blacklist-append {clang < 700}
compiler.c_standard   2011

configure.pkg_config_path   ${prefix}/libexec/ffmpeg${ffmpeg_ver}/lib/pkgconfig

# pulseaudio is recognized if installed but build fails
configure.args      --cc="${configure.cc}" \
                    --cxx="${configure.cxx}" \
                    --extra-cflags="${configure.cc_archflags}" \
                    --extra-ldflags="${configure.ld_archflags}" \
                    --mandir=${prefix}/share/man \
                    --disable-x11 \
                    --verbose

# This project's build system detects CPU and endianness at configure time.
# muniversal is worth a try.
universal_variant   no
