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

PortSystem          1.0
PortGroup           wxWidgets 1.0
PortGroup           boost 1.0
PortGroup           app 1.0

name                codeblocks
conflicts           codeblocks-devel
version             20.03
revision            1
platforms           darwin freebsd
categories          devel aqua x11
license             GPL-3+
license_noconflict  boost
maintainers         nomaintainer

description         Open Source, Cross-platform, Free C/C++/D IDE
long_description    Code::Blocks is a free C++ IDE built specifically \
                    to meet the most demanding needs of its users. \
                    It was designed, right from the start, to be \
                    extensible and configurable.

homepage            https://www.codeblocks.org/
master_sites        https://sourceforge.net/projects/codeblocks/files/Sources/${version}
use_xz              yes

checksums           rmd160  2b4a2136cc34b1d27a8c7bdb3747f87904648cab \
                    sha256  15eeb3e28aea054e1f38b0c7f4671b4d4d1116fd05f63c07aa95a91db89eaac5 \
                    size    11799264

patchfiles          patch-sqvm-header-fix.diff
if {${os.arch} ne "i386"} {
  patchfiles-append dragscroll.patch
}

# fix boost detection with i386 systems
patchfiles-append   patch-m4-boost.diff

depends_build-append \
                    port:pkgconfig

depends_lib-append  port:hunspell

use_autoconf        yes
autoconf.cmd        ./bootstrap
# TODO: These dependencies are needed after `autoconf.cmd`,
#       else autoconf.cmd removes them.
#       https://trac.macports.org/ticket/54394
depends_build-append \
                    port:autoconf \
                    port:automake \
                    port:libtool

compiler.cxx_standard   2011

# FileManager requires "gamin" to be installed when using wxGTK,
# not sure whether it works with Carbon/Cocoa at all,
# so it was disabled for now
configure.args      --with-contrib-plugins=all,-FileManager \
                    --with-boost=[boost::install_area]

# disable precompiled headers for the universal build
variant universal {
    configure.args-append   --disable-pch
}


app.name              CodeBlocks
app.use_launch_script yes
app.icon              src/src/resources/icons/app.icns
app.hide_dock_icon    yes

variant wxwidgets30 conflicts wxwidgets28 wxgtk30 wxgtk28 description {Use Cocoa-based wxWidgets 3.0} {
    wxWidgets.use           wxWidgets-3.0
    depends_lib-append      port:${wxWidgets.port}
    autoconf.env-append     ACLOCAL_PATH=${wxWidgets.prefix}/share/aclocal
    configure.args-append   --with-wxdir=${wxWidgets.wxdir}
}

variant wxwidgets28 conflicts wxwidgets30 wxgtk30 wxgtk28 description {Use 32-bit Carbon-based wxWidgets 2.8} {
    wxWidgets.use           wxWidgets-2.8
    depends_lib-append      port:${wxWidgets.port}
    autoconf.env-append     ACLOCAL_PATH=${wxWidgets.prefix}/share/aclocal
    configure.args-append   --with-wxdir=${wxWidgets.wxdir}

    if {${wxWidgets.sdk} ne ""} {
        configure.sdkroot ${wxWidgets.sdk}
    }
}

variant wxgtk30 conflicts wxwidgets30 wxwidgets28 wxgtk28 description {Use wxWidgets 3.0 with GTK} {
    wxWidgets.use           wxGTK-3.0
    depends_lib-append      port:${wxWidgets.port}
    autoconf.env-append     ACLOCAL_PATH=${wxWidgets.prefix}/share/aclocal
    configure.args-append   --with-wxdir=${wxWidgets.wxdir}
}

variant wxgtk28 conflicts wxwidgets30 wxwidgets28 wxgtk30 description {Use wxWidgets 2.8 with GTK} {
    wxWidgets.use           wxGTK-2.8
    depends_lib-append      port:${wxWidgets.port}
    autoconf.env-append     ACLOCAL_PATH=${wxWidgets.prefix}/share/aclocal
    configure.args-append   --with-wxdir=${wxWidgets.wxdir}
}

if {[variant_isset wxgtk28] || [variant_isset wxgtk30]} {
    # TODO: someone needs to do a careful check of this list of dependencies
    # codeblocks ends up linking against these, but it is quite possible that
    # some of them are also needed when liking against Carbon/Cocoa-based wxWidgets
    depends_lib-append      path:lib/pkgconfig/cairo.pc:cairo \
                            path:lib/pkgconfig/pango.pc:pango \
                            path:lib/pkgconfig/glib-2.0.pc:glib2 \
                            port:atk \
                            port:fontconfig \
                            port:freetype \
                            path:lib/pkgconfig/gdk-pixbuf-2.0.pc:gdk-pixbuf2 \
                            port:gettext \
                            path:lib/pkgconfig/gtk+-2.0.pc:gtk2 \
                            port:xorg-libX11 \
                            port:xorg-libXcomposite \
                            port:xorg-libXcursor \
                            port:xorg-libXdamage \
                            port:xorg-libXdmcp \
                            port:xorg-libXext \
                            port:xorg-libXfixes \
                            port:xorg-libXi \
                            port:xorg-libXinerama \
                            port:xorg-libXrandr \
                            port:xrender
}

if {![variant_isset wxwidgets30] && ![variant_isset wxwidgets28] && ![variant_isset wxgtk30] && ![variant_isset wxgtk28]} {
    default_variants +wxgtk30
}

platform darwin arm {
    post-patch {
        # Use newer config.guess and config.sub to support Apple Silicon.
        set automake_dirs [glob -directory ${prefix}/share automake-*]
        set automake_dir [lindex [lsort -command vercmp $automake_dirs] end]
        copy -force ${automake_dir}/config.guess ${automake_dir}/config.sub \
            ${worksrcpath}
    }
}

notes {
for information about how to configure the spellchecker module\
please see https://trac.macports.org/ticket/71176
}
