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

name                grafx2
version             2.7
revision            1
# upstream doesn't tag "bugfixes" releases, but uses a commit count :
# tag v2.6 was v2.6.2475
# commit 75579a9 is v2.6.2490
set commit_count    2945
set jobid           422881812
categories          graphics
maintainers         {@miniupnp free.fr:miniupnp} openmaintainer
platforms           darwin
license             GPL-2

description         The ultimate 256-color painting program
long_description    GrafX2 is a bitmap paint program inspired by the Amiga programs \
                    Deluxe Paint and Brilliance. Specialized in 256-color drawing, \
                    it includes a very large number of tools and effects that make \
                    it particularly suitable for pixel art, game graphics, and generally \
                    any detailed graphics painted with a mouse.

homepage            http://grafx2.chez.com/
# https://gitlab.com/GrafX2/grafX2/-/jobs/422881812/artifacts/raw/grafx2-2.7.2945-src.tgz
distname            grafx2-${version}.${commit_count}-src
master_sites        https://gitlab.com/GrafX2/grafX2/-/jobs/${jobid}/artifacts/raw/
distfiles           ${distname}.tgz
checksums           ${distname}.tgz \
                    sha256  b176fd051ec9256d4b3d06a4c93d7470f01ad78838983a2def7dddcd5340d4f4 \
                    rmd160  e93cb37ac32ff8a1f49373176523e44a1ee055ff \
                    size    1101545
fetch.ignore_sslcert    yes

worksrcdir          grafx2/src

depends_build-append \
                    port:pkgconfig

depends_lib         port:libsdl \
                    port:libsdl_ttf \
                    port:libsdl_image \
                    port:libpng \
                    port:tiff \
                    port:lua

use_configure       no

patch.pre_args-replace  -p0 -p2
patchfiles-append   patch-osx-tiger_realpath.c.diff patch-osx-tiger_Makefile.diff patch-osx-tiger_Makefile-b.diff

pre-build {
    system "echo 'const char SVN_revision\[\]=\"macports_${revision}\";' > ${worksrcpath}/version.c"
}

build.args-append   CC=${configure.cc} CXX=${configure.cxx} CPP=${configure.cpp}
if {${os.subplatform} eq "macosx"} {
    build.args-append   OSX_STATIC=0 NO_X11=1
}

variant sdl2 conflicts sdl description {Use SDL 2.0.x instead of old SDL 1.2.x} {
    depends_lib-delete  port:libsdl \
                        port:libsdl_ttf \
                        port:libsdl_image
    depends_lib-append  port:libsdl2 \
                        port:libsdl2_ttf \
                        port:libsdl2_image
    build.args-append   API=sdl2
}

variant sdl conflicts sdl2 description {Use SDL 1.2.x} {
    build.args-append   API=sdl
}

if {![variant_isset sdl] && ${os.platform} eq "darwin" && ${os.major} >= 11} {
    default_variants    +sdl2
} elseif {![variant_isset sdl2]} {
    default_variants    +sdl
}

destroot {
    xinstall -d ${destroot}${applications_dir}
    copy ${worksrcpath}/Grafx2.app ${destroot}${applications_dir}
}
