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

PortSystem      1.0

name            fltk
categories      aqua devel
license         LGPL
platforms       macosx
maintainers     {michaelld @michaelld} openmaintainer
description     Fast Light Tool Kit

long_description \
    FLTK (pronounced fulltick) \
    is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), \
    Microsoft Windows, and Mac OS X. \
    FLTK provides modern GUI functionality without the bloat \
    and supports 3D graphics via OpenGL and \
    its built-in GLUT emulation. \
    FLTK is designed to be small and modular enough to be \
    statically linked, but works fine as a shared library. \
    FLTK also includes an excellent UI builder called FLUID \
    that can be used to create applications in minutes.

homepage        http://www.fltk.org/

livecheck.type  regexm
livecheck.url   ${homepage}

subport fltk-devel {}

if {${subport} eq ${name}} {

    conflicts       fltk-devel
    long_description ${long_description} \
        This port provides the release of FLTK, typically updated a few times a year.

    # NOTE: when this release is updated fix the octave port to use it
    # again on 10.11.

    version         1.3.4
    set ver_bump    1
    master_sites    http://fltk.org/pub/fltk/${version}/
    if {${ver_bump} == 0} {
        worksrcdir      ${name}-${version}
    } else {
        worksrcdir      ${name}-${version}-${ver_bump}
    }
    distname        ${worksrcdir}-source

    checksums       rmd160 06abc605fe4f27a8086c01c7d7941ea152132760 \
                    sha256 7fb2c8882433ce694e6900c94fda505e8f4ed3fa9c7e597007098a33b85c53f4

    livecheck.regex "Stable Release.*?\n.*?VERSION=(\\d+(\\.\\d+)*)'"

} else {

    long_description ${long_description} \
        This port provides the snapshot released of FLTK, typically updated a few times a month.

    conflicts       fltk

    version         1.4.x-r12990
    checksums       rmd160 c1aaf9fb4b96258f96776f49ef798f05fd6d7988 \
                    sha256 5d1d62e563773cb867340fb7dc1184fab7fa8c25b3a291c117208d59bf8c1167 \
                    size   5399921

    master_sites    http://fltk.org/pub/fltk/snapshots/
    distname        fltk-${version}
    use_bzip2       yes

    livecheck.regex "Snapshots:.*\n.*v(1\\.4\\.x-r\\d+)"

}

depends_lib     port:jpeg \
                port:libpng \
                port:zlib

patchfiles-append \
        patch-fluid-Makefile.diff

#if {${subport} eq "fltk"} {
#    patchfiles-append \
#        patch-src-Makefile.release.diff \
#        patch-fix_LP64.release.diff \

    # the following patches are already integrated into the devel version
#    patchfiles-append \
#        patch-src-Fl_JPEG_Image.cxx.diff \
#        patch-src_fl_line_style.cxx.diff

#} else {
#    patchfiles-append \
    #patch-src-Makefile.devel.diff \
     #   patch-fix_LP64.devel.diff \
#}

post-patch {

    reinplace "s|/Applications|${applications_dir}/fltk|g" \
        ${worksrcpath}/fluid/Makefile \
        ${worksrcpath}/test/Makefile

    # Disable silent rules
    reinplace "/^\\.SILENT:$/d" ${worksrcpath}/makeinclude.in

    # tell fltk's make script to create config.sub, which is required
    # before configure will execute properly.  This command actually
    # runs configure through once, to create the file; we then call
    # configure manually with the correct arguments, which overwrites
    # this (and other) files to be what we want.  Make sure CC is set
    # correctly per "using the right compiler".  While this port will
    # work correctly without this addition, doing this allows the port
    # to not error out on dev's systems set up to check whether the
    # right compiler is being used.

    system -W ${worksrcpath} "CC=${configure.cc} make config.sub"

}

pre-configure {
    configure.args-append \
        --with-archflags="[get_canonical_archflags]"
    configure.cc_archflags
    configure.cxx_archflags
    configure.objc_archflags
    configure.objcxx_archflags
    configure.ld_archflags
}

configure.args  --enable-shared \
                --disable-localjpeg \
                --disable-localzlib \
                --disable-localpng

configure.universal_args-delete --disable-dependency-tracking

post-configure {
    reinplace -E {s|-arch [a-z0-9_]+||g} ${worksrcpath}/fltk-config
}

destroot.target install install-desktop