# -*- 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 github 1.0

github.setup        nigels-com glew 2.3.0 glew-
categories          graphics devel
# some build scripts are GPL-2+ but we don't install them
license             BSD MIT
maintainers         {jmr @jmroot} openmaintainer
description         OpenGL Extension Wrangler Library
long_description    The OpenGL Extension Wrangler Library (GLEW) is a \
                    cross-platform C/C++ extension loading library. GLEW \
                    provides efficient run-time mechanisms for determining \
                    which OpenGL extensions are supported on the target \
                    platform. OpenGL core and extension functionality is \
                    exposed in a single header file.

homepage            https://glew.sourceforge.net/
github.tarball_from releases
extract.suffix      .tgz
checksums           rmd160 6f8e827a685c8e9606e2eba0aaf83d164a1be040 \
                    sha256 b261a06dfc8b970e0a1974488530e58dd2390acf68acb05b45235cd6fb17a086

patchfiles          config_Makefile.darwin.patch

post-patch {
    reinplace "s:/usr/X11R6:${prefix}:g" ${worksrcpath}/config/Makefile.darwin
}

use_configure       no
build.env           GLEW_PREFIX=${prefix} GLEW_DEST=${prefix}
build.args          CC=${configure.cc} LD=${configure.cc} \
                    POPT="${configure.optflags}" STRIP=
destroot.env        GLEW_PREFIX=${prefix} GLEW_DEST=${prefix}
destroot.target     install.all

variant universal {
    build.env-append ARFLAGS=crs
}
build.args-append CFLAGS.ARCH="[get_canonical_archflags cc]" \
                  LDFLAGS.ARCH="[get_canonical_archflags ld]"

variant x11 description {Build libGLEW for GLX rather than OpenGL.framework} {
    depends_lib-append port:mesa
    build.args-append GLEW_APPLE_GLX=1
    destroot.args-append GLEW_APPLE_GLX=1
}

if {${os.subplatform} ne "macosx"} {
    default_variants +x11
}
