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

# MAP_ANONYMOUS
legacysupport.newest_darwin_requires_legacy 14

github.setup        LMMS lmms 1.2.2 v
revision            2
categories          multimedia audio
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
license             GPL-2+

description         Linux Multimedia Studio
long_description    LMMS is a free cross-platform alternative to commercial programs like FL Studio®, \
                    which allow you to produce music with your computer. This includes the creation of \
                    melodies and beats, the synthesis and mixing of sounds, and arranging of samples. \
                    You can have fun with your MIDI-keyboard and much more, all in a user-friendly and \
                    modern interface.

homepage            https://lmms.io/

distname            ${name}_${version}
checksums           rmd160  cb4a07dc27dfa31a70b5154a5386b2a8873774c8 \
                    sha256  b185507fb64ecfd8e31145135b58ab244b637f9efc09c4176caf70aa3cbaae1e \
                    size    22733960
github.tarball_from releases
extract.rename      yes
use_xz              yes

depends_lib-append  port:fftw-3-single \
                    path:lib/libfltk.dylib:fltk \
                    port:fluidsynth \
                    port:libogg \
                    port:libsamplerate \
                    port:libsdl \
                    port:libsndfile \
                    port:libvorbis \
                    port:portaudio \
                    port:stk

# These are merged to the upstream:
patchfiles-append   0001-CMakeLists-use-flags-for-Apple-correctly-6784.patch \
                    0002-Detect-PowerPC-and-ARM-correctly-6790.patch \
                    0003-MidiApple.cpp-fix-getName-to-allow-build-with-GCC-67.patch \
                    0004-versioninfo.h-fix-recognizing-archs-and-compiler-679.patch

# These are fixes, specific to Macports:
patchfiles-append   0005-Pick-Macports-patches.patch

post-patch {
    reinplace "s|@APPLICATIONS_DIR@|${applications_dir}|g" ${worksrcpath}/cmake/apple/install_apple.sh.in
    reinplace "s|@DESTROOT@|${destroot}|g" ${worksrcpath}/cmake/apple/install_apple.sh.in
    reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/cmake/apple/install_apple.sh.in
}

compiler.c_standard     2011
compiler.cxx_standard   2011

# The build system uses CMAKE_INSTALL_PREFIX in a nonstandard way, both by
# writing the Info.plist into it during configure and by attempting to copy
# all items contained in it into the application bundle during destroot. So
# it must be set to an empty writable directory.
set target_path         ${workpath}/target
pre-configure {
    file mkdir ${target_path}
}
configure.pre_args      -DCMAKE_INSTALL_PREFIX=${target_path}

configure.args-append   -DFLTK_FLUID_EXECUTABLE=${prefix}/bin/fluid \
                        -DSTK_INCLUDE_DIR=${prefix}/include/stk \
                        -DWANT_ALSA=OFF \
                        -DWANT_JACK=ON \
                        -DWANT_OGGVORBIS=ON \
                        -DWANT_PORTAUDIO=ON \
                        -DWANT_PULSEAUDIO=OFF \
                        -DWANT_SDL=ON \
                        -DWANT_STK=ON \
                        -DWANT_VST=OFF

if {${os.platform} ne "darwin" || ${os.major} >= 18} {
    PortGroup       qt5 1.0

    qt5.depends_build_component qttools

    configure.args-append   -DWANT_QT5=ON
} else {
    PortGroup       qt4 1.0

}

# See: https://github.com/jackaudio/jack2/issues/950
if {${os.platform} ne "darwin" || ${configure.build_arch} ni [list ppc ppc64]} {
    configure.args-replace \
                        -DWANT_JACK=OFF -DWANT_JACK=ON
    depends_lib-append  port:jack
}

configure.args-replace  -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib -DCMAKE_INSTALL_NAME_DIR=${applications_dir}/LMMS.app/Contents/Frameworks

# The build system only partly honors DESTDIR, such that the destroot fails
# if it is set, and since we've already patched the build system to stage
# into the destroot, we can just unset it. MacPorts base sets DESTDIR in
# destroot.destdir, while the qt4 portgroup sets it as an environment variable.
destroot.destdir
destroot.env-delete     DESTDIR=${destroot}

post-destroot {
    ln -s ${applications_dir}/LMMS.app/Contents/MacOS/lmms ${destroot}${prefix}/bin/
    ln -s ${applications_dir}/LMMS.app/Contents/share/man/man1/lmms.1.gz ${destroot}${prefix}/share/man/man1/
}

# cmake/modules/DetectMachine.cmake tries to detect bitness but because
# the build system does not destroot entirely within the destdir, using
# the muniversal portgroup will be complicated.
#PortGroup               muniversal 1.0
universal_variant       no
