PortSystem          1.0

name                rrgbis
version             1.12
revision            1
set data_version    1.11
categories          games
platforms           darwin
maintainers         nomaintainer
description         Real time strategy game with fleets of spaceships.
long_description    ${description}

homepage            http://rrgbis.sourceforge.net/
master_sites        sourceforge:project/${name}/${name}/${version}:source \
                    sourceforge:project/${name}/${name}/${data_version}:data
use_bzip2           yes
set source          rrgbis-${version}-src${extract.suffix}
set data            rrgbis-${data_version}-data${extract.suffix}
distfiles           ${source}:source \
                    ${data}:data
checksums           ${source} \
                        md5 14396c77f2b68cf2e5104174c135f4e4 \
                        sha1 aa48440907f82fdb99f564fba69084146b9fae59 \
                        rmd160 ec7d2f15086125d437179a53e552fd03f16c4539 \
                    ${data} \
                        md5 abd55dc67686ac99e96f9db2e59b5981 \
                        sha1 bbfb809982f3c1a9d39d1685f23bd2e6b9b5599e \
                        rmd160 65d9eca5be7c67d3e3c48bf90fb4a5a17f2bada4
worksrcdir          ${name}

depends_lib         port:freetype \
                    port:libsdl \
                    port:libsdl_image \
                    port:libsdl_mixer \
                    port:libvorbis

patchfiles          patch-src_GLSDL.cpp.diff \
                    patch-Makefile.diff

pre-patch {
    # Convert files from DOS to UNIX linefeeds before patching.
    reinplace "s/\r$//g" ${worksrcpath}/Makefile
}
post-patch {
    # Set the correct path to the installed rrgbis data in the settings file.
    reinplace "s|pwd|${prefix}/share/rrgbis/|g" ${worksrcpath}/settings.dat
}

configure.dir       ${worksrcpath}/src/FTGL

build.target        default

destroot {
    # Install the helper script which automatically sets the correct
    # LD_LIBRARY_PATH variable and set the right ${prefix} path.
    xinstall ${filespath}/rrgbis ${destroot}${prefix}/bin
    reinplace "s|__PREFIX__|${prefix}|g" ${destroot}${prefix}/bin/rrgbis

    # Install the helper setup script which creates ~/.rrgbis and the
    # settings.dat file in it.
    xinstall ${filespath}/rrgbis-setup ${destroot}${prefix}/bin
    reinplace "s|__PREFIX__|${prefix}|g" ${destroot}${prefix}/bin/rrgbis-setup

    # Install the real binary and rename it to rrgbis-bin.
    copy ${worksrcpath}/rrgbis ${destroot}${prefix}/bin/rrgbis-bin

    # Create the directory for the rrgbis data.
    xinstall -d ${destroot}${prefix}/share/rrgbis
    # Copy all data files and directories to ${destroot}.
    set files {aiscripts fonts images missions music settings.dat sound \
               squirrelscripts unitdata unitpictures}
    foreach file $files {
        move ${worksrcpath}/${file} ${destroot}${prefix}/share/rrgbis/${file}
    }
}

post-install {
    ui_msg "****************************************************************"
    ui_msg "*                                                              *"
    ui_msg "* Before you run rrgbis for the first time, you must run       *"
    ui_msg "* rrgbis-setup to set up the default configuration.            *"
    ui_msg "*                                                              *"
    ui_msg "* This script is provided by MacPorts and not part of the      *"
    ui_msg "* official distribution! If there are any problems with it     *"
    ui_msg "* contact the port maintainer.                                 *"
    ui_msg "*                                                              *"
    ui_msg "****************************************************************"
}
