# $Id: Portfile 58210 2009-09-24 06:56:08Z ryandesign@macports.org $

PortSystem          1.0

name                simutrans
version             99-17-1
categories          games
platforms           darwin
maintainers         simon openmaintainer
description         Simutrans is a freeware transport simulation game.
long_description    Simutrans Transport Simulator (short: Simutrans) is a \
                    freeware simulation game for Windows, BeOS, Mac OS X and \
                    Linux that focuses on the transporting of goods, people, \
                    mail and power. It was originally written by Hansjörg \
                    Malthaner, and is now maintained and developed by a \
                    small team. \
                    \
                    This port installs simutrans with the default pak64 \
                    image set. If you want to use another pak, download it \
                    (for example from \
                    http://simutrans.sourceforge.net/ufcs.htm) and put it \
                    into \"${prefix}/share/simutrans\".

homepage            http://simutrans.sourceforge.net/
master_sites        sourceforge
use_zip             yes
set source          ${name}-src-${version}${extract.suffix}
set pak64           pak64-${version}${extract.suffix}
distfiles           ${source} \
                    ${pak64}
checksums           ${source} md5 2ebeb3439707c955d87f1b1ff0f1c0da \
                    ${source} sha1 c66429cf2578fdcf6e41e443b4edac58650ac23e \
                    ${source} rmd160 157f6e55317bb719badfd68743ce36f1ceaa1f49 \
                    ${pak64} md5 9a7d4494ec15f4311737bfadf991a6fe \
                    ${pak64} sha1 ab978c43b4b02a4c7eda226a4a7984f0b29135f2 \
                    ${pak64} rmd160 682334005d38cb6516327869a935eb9a8c012ea6
extract.mkdir       yes

depends_lib         port:libpng \
                    path:lib/pkgconfig/sdl.pc:libsdl \
                    port:zlib

pre-patch {
    copy -force ${worksrcpath}/config.template ${worksrcpath}/config.default
}

patchfiles          patch-config.default.diff \
                    patch-Makefile.diff

post-patch {
    reinplace "s|__PREFIX__|${prefix}|g" ${worksrcpath}/Makefile

    # If music should not be enabled then don't use the mixer_sdl backend
    # which is only used with music. This may speed up the game.
    if {![variant_isset enable_music]} {
        reinplace "s|BACKEND = mixer_sdl|#BACKEND = mixer_sdl|g" \
            ${worksrcpath}/config.default
    }
}

use_configure       no

destroot {
    # Install the simutrans data into share/simutrans.
    copy ${worksrcpath}/simutrans ${destroot}${prefix}/share
    # Install the simutrans binary to the directory in share/. Necessary as
    # the data and binary needs to be in the same directory.
    xinstall ${worksrcpath}/sim ${destroot}${prefix}/share/simutrans

    # Install the helper script which allows to simply call simutrans. Also
    # use the correct prefix path in the helper script.
    xinstall ${portpath}/${filesdir}/simutrans ${destroot}${prefix}/bin
    reinplace "s|__PREFIX__|${prefix}|g" ${destroot}${prefix}/bin/simutrans
}


variant enable_music description {Allows to listen to simutrans own music\
                                  while playing. May reduce speed.} {
    depends_lib-append  port:libsdl_mixer
}
