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

name                micropolis
version             4.0-20180629
git.branch          cc31822e4ebe54c0109623ac0c5cdf0e3acad755
revision            0
checksums           rmd160  34b86d9d5891473aa3eda1556bf9dde23b206b4b \
                    sha256  f55a1f3ee276e093fb56d0d1a4db5efb2a0cb925ee4e8af5eb7107e972854c77 \
                    size    7912528

categories          games
maintainers         {ryandesign @ryandesign} openmaintainer
license             GPL-3+ Tcl/Tk

description         city building simulation game

long_description    ${name} is the open-source descendant of the 1989 \
                    city building simulation game SimCity.

# Originally from:
# https://www.donhopkins.com/home/micropolis/
# https://github.com/SimHacker/micropolis
homepage            http://git.zerfleddert.de/cgi-bin/gitweb.cgi/micropolis
master_sites        ${homepage}/snapshot/
distname            ${git.branch}
worksrcdir          ${name}-[string range ${git.branch} 0 6]

depends_build       port:pkgconfig

depends_lib         port:libsdl_mixer \
                    port:xorg-libX11 \
                    port:xpm

pre-patch {
    foreach f [list tclx/config/linux] {
        move        ${worksrcpath}/src/${f} ${worksrcpath}/src/${f}.orig
        copy        ${worksrcpath}/src/${f}.orig ${worksrcpath}/src/${f}
    }
}

patch.post_args -b
patchfiles          Makefile.patch \
                    src-sim-makefile.patch \
                    src-tclx-src-tclxgdat.y.patch \
                    src-tclx-tkucbsrc-makefile.patch \
                    src-tclx-ucbsrc-makefile.patch \
                    src-tclx-ucbsrc-tclbasic.sed.patch \
                    src-tclx-ucbsrc-tclexpr.sed.patch \
                    src-tk-makefile.patch \
                    src-tk-tkconfig.h.patch \
                    src-tk-tkevent.c.patch \
                    src-tk-tkrawtcp.c.patch

post-patch {
    reinplace       -W ${worksrcpath} \
                    -E "s|/usr/include/X11|${prefix}/include|g;s|/usr/X11(R6)?/lib|${prefix}/lib|g" \
                    src/tk/makefile \
                    src/tclx/config/linux \
                    src/sim/makefile
}

# To make sure the -I and -L flags in the makefiles are right.
compiler.cpath
compiler.library_path
configure.cppflags-delete   -I${prefix}/include
configure.ldflags-delete    -L${prefix}/lib

makefile.override-append    PREFIX

universal_variant   no
use_parallel_build  no

livecheck.url       ${homepage}
livecheck.version   ${git.branch}
livecheck.type      regex
livecheck.regex     {>log</a> \| <a href="[^"]+/commit/([0-9a-f]{40})}
