# -*- 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           app 1.0
PortGroup           boost 1.0
PortGroup           legacysupport 1.1
PortGroup           wxWidgets 1.0

boost.version       1.81
boost.depends_type  build

name                codeblocks
conflicts           codeblocks-devel
version             25.03
revision            0
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}
distname            ${name}_${version}
use_xz              yes
extract.suffix      .tar.xz

checksums           rmd160  af41981ddf69dd580df604289b0b5f27b1e3adc7 \
                    sha256  b0f6aa5908d336d7f41f9576b2418ac7d27efbc59282aa8c9171d88cea74049e \
                    size    17866880

# FIXME: this is done to avoid an error on legacysupport header: https://trac.macports.org/ticket/72428
# Needs to be reviewed.
patchfiles-append       patch-no-c90.diff

# This header is not installed and also seems to be completely useless anyway.
patchfiles-append       patch-unbreak-app.diff

# Since wxGTK on macOS is switched to native stdpaths, *Nix code here fails:
patchfiles-append       patch-wxGTK.diff

use_autoconf            yes
autoconf.cmd            ./bootstrap

depends_build-append    port:autoconf \
                        port:automake \
                        port:libtool \
                        path:bin/pkg-config:pkgconfig

# bzip2 is used by the libhelp_plugin
depends_lib-append      port:hunspell \
                        port:bzip2

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-boost=[boost::install_area] \
                        --with-contrib-plugins=all,-FileManager

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

# work around a directory layout issue based on MacPorts default non-bundled layout
post-destroot {
    ln -s ${prefix}/lib/codeblocks/plugins ${destroot}${prefix}/share/codeblocks/plugins
}

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

variant wxwidgets32 conflicts wxgtk32  description {Use Cocoa-based wxWidgets 3.2} {
    wxWidgets.use           wxWidgets-3.2
    depends_lib-append      port:${wxWidgets.port}
    autoconf.env-append     ACLOCAL_PATH=${wxWidgets.prefix}/share/aclocal
    configure.args-append   --with-wxdir=${wxWidgets.wxdir}
}

variant wxgtk32 conflicts wxwidgets32 description {Use wxWidgets 3.2 with GTK} {
    wxWidgets.use           wxGTK-3.2
    depends_lib-append      port:${wxWidgets.port}
    autoconf.env-append     ACLOCAL_PATH=${wxWidgets.prefix}/share/aclocal
    configure.args-append   --with-wxdir=${wxWidgets.wxdir}

    depends_lib-append      port:atk \
                            path:lib/pkgconfig/cairo.pc:cairo \
                            path:lib/pkgconfig/gdk-pixbuf-2.0.pc:gdk-pixbuf2 \
                            port:gettext-runtime \
                            path:lib/pkgconfig/glib-2.0.pc:glib2 \
                            path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                            path:lib/pkgconfig/harfbuzz.pc:harfbuzz \
                            path:lib/pkgconfig/pango.pc:pango
}

if {![variant_isset wxwidgets32] && ![variant_isset wxgtk32]} {
    if {${os.platform} eq "darwin" && ${os.major} > 15} {
      default_variants +wxwidgets32
    } else {
      default_variants +wxgtk32
    }
}

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