# -*- coding: utf-8; 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
PortGroup           cmake 1.1
PortGroup           github 1.0

name                glfw
categories          graphics
maintainers         {michaelld @michaelld} openmaintainer
description         GLFW is a free, open-source, portable library for OpenGL and OpenGL ES application development
license             zlib
platforms           darwin macosx

# glfw does not build on Mac OS X 10.5 or prior due to CoreGraphics
# references that are 10.6+.
if {${os.platform} eq "darwin" && ${os.major} < 10} {
    pre-fetch {
        ui_error "$name does not build on Mac OS X 10.5 'Leopard' or prior."
        error "unsupported platform"
    }
}

# special build on Mac OS X 10.6
if {${os.platform} eq "darwin" && ${os.major} == 10} {

    # Mac OS X 10.6: use the latest commit supporting this OS version
    github.setup    glfw glfw a94a84b507b0d6d11e8a3f257cb21f4bd6553516
    version         3.1.2-20151024
    checksums       rmd160 1c07a75a88f272653ca246aa1212a208a83ecb30 \
                    sha256 ff4745264f92b740c50ecc90370f102c86c439f2b6108f1495bd60c87e5d6a83
    revision        0

    # bump the epoch because I moved the version from 20151012 to 3.1.2

    epoch           1

    long_description ${description}. This version of GLFW is the latest to provide support for \
        Mac OS X 10.6 and prior, and it will not be updated. It is provided in the \
        hope that it allows ports depending on GLFW to build on these older Mac OS X installs.

    # patch to fix install directory for cmake files and docs

    patchfiles-append patch-CMakeLists.txt.legacy.diff

} else {

    # Mac OS X 10.7 and newer: release and devel

    # requires c11 support as of 82ca58da (20190305) for
    # <stdatomic.h>; 3.3 was released shortly after this change, so
    # this requirement is now for all modern GLFW. hopefully the
    # following force a C11 compliant compiler to be used! require GCC
    # >= 4.6 (4.9 for full C11) or MacPorts' Clang >= 3.1 or
    # AppleClang >= 700. MacPorts' Clang starts at 3.3, so nothing to
    # block there!

    PortGroup cxx11                       1.1
    PortGroup compiler_blacklist_versions 1.0

    compiler.blacklist-append macports-gcc-4.3 macports-gcc-4.4 macports-gcc-4.5 \
        macports-gcc macports-gcc-4.6 macports-gcc-4.7 macports-gcc-4.8 \
        macports-llvm-gcc-4.2 macports-dragonegg-3.3 macports-dragonegg-3.4 \
        apple-gcc-4.0 apple-gcc-4.2 gcc-3.3 gcc-4.0 llvm-gcc-4.2 gcc cc \
        {clang < 700} macports-clang-3.*

    configure.args-append -DCMAKE_C_STANDARD=11 -DCMAKE_C_EXTENSIONS=OFF

    subport glfw-devel {}

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

        # release

        github.setup    glfw glfw 3.3
        checksums       rmd160 c119dfda395c2250042b1463eaf00b068422e9b2 \
                        sha256 7f788385e1bce1151f80101a14310bd8add536fbe940fbce02aef1d28417009b \
                        size   758548
        revision        0

        # bump the epoch because I moved the version from 20151012 to 3.1.2

        epoch           1

        conflicts       glfw-devel
        long_description ${description}: \
            This port follows the release version of GLFW, which is typically updated every 6 months. If for some reason this port does not build or function as desired, try the ${name}-devel port.

        # patch to fix install directory for cmake files and docs

        patchfiles-append patch-CMakeLists.txt.release.diff

        # patch to fix install name of library

        patchfiles-append patch-src_CMakeLists.txt.release.diff

    } else {

        # devel

        github.setup glfw glfw 243b1bc292a2e3f8c9aee8884574c1c7f4354402
        version   20190906-[string range ${github.version} 0 7]
        checksums rmd160 dbd932a10c7767b98986634769307bb64a5d27f5 \
                  sha256 705e1709f3644ccfd2e3d6daffdf720e8b2f493d9bc3cc3b63f11f447679f31b \
                  size   756326
        revision  0

        conflicts       glfw
        long_description ${description}: \
            This port follows the GIT master version of GLFW, which is typically updated every few days to weeks.

        # patch to fix install directory for cmake files and docs

        patchfiles-append patch-CMakeLists.txt.devel.diff

        # patch to fix install name of library

        patchfiles-append patch-src_CMakeLists.txt.devel.diff

    }
}

# use the real home page, not github's

homepage            http://www.glfw.org/

# do VPATH (out of source tree) build

cmake.out_of_source yes

# configuration arguments for MacPorts build

configure.args-append \
    -DBUILD_SHARED_LIBS=on \
    -DGLFW_BUILD_EXAMPLES=off \
    -DGLFW_BUILD_TESTS=off \
    -DGLFW_CMAKE_CONFIG_PATH=share

# remove top-level library path, such that internal libraries are used
# instead of any already-installed ones.

configure.ldflags-delete -L${prefix}/lib

variant docs description {build documentation} {}

default_variants    +docs

if {[variant_isset docs]} {
    depends_build-append  port:doxygen
    configure.args-append -DDOXYGEN_EXECUTABLE=${prefix}/bin/doxygen
} else {
    configure.args-append -DDOXYGEN_EXECUTABLE=
}
