# -*- 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
# $Id: Portfile 115157 2013-12-27 08:08:34Z ryandesign@macports.org $

PortSystem              1.0

name                    xgalaga
version                 2.1.1.0
revision                2
categories              games x11
license                 GPL-2
platforms               darwin
maintainers             nomaintainer
description             xgalaga is a rework of the Galaga shooting game.
long_description        ${description}

homepage                http://sourceforge.net/projects/xgalaga/
master_sites            sourceforge
checksums               md5     f37c3377b245d2d53b33eb489966bf28 \
                        sha1    ef40ad833d2434b0643d4c00202bd75ec14b94ac \
                        rmd160  b55a97187b61ffe7c072ecd784cf9a16fe568c26

patchfiles              patch-Makefile.in.diff \
                        patch-main.c.diff

depends_lib             port:xorg-libX11 \
                        port:xorg-libXext \
                        port:xorg-libXmu \
                        port:xorg-libXt \
                        port:xpm

# The shipped config.guess and config.sub are too old to recognize OS X.
# https://sourceforge.net/p/xgalaga/bugs/2/
pre-configure {
    copy -force ${prefix}/share/libtool/config/config.guess ${prefix}/share/libtool/config/config.sub ${worksrcpath}
}
use_autoconf            yes

# The configure script uses these variables incorrectly, hence the strange values.
configure.pre_args      --prefix=${prefix}/share/${name}
configure.args          --exec-prefix=${prefix}/bin \
                        --mandir=${prefix}/share/man \
                        --with-xpm-lib=${prefix}/lib

post-destroot {
    set docdir ${prefix}/share/doc/${subport}
    xinstall -d ${destroot}${docdir}
    xinstall -m 644 -W ${worksrcpath} \
        CHANGES \
        CREDITS \
        README \
        README.SOUND \
        ${destroot}${docdir}
}

pre-activate {
    # xgalaga <= 2.1.1.0_1 installed its manpage directly into /usr; remove it if found.
    # https://sourceforge.net/p/xgalaga/bugs/11/
    foreach filepath {/usr/share/man/xgalaga.6x.gz} {
        if {[file exists ${filepath}] && [registry_file_registered ${filepath}] == "0"} {
            if {[catch {delete ${filepath}}]} {
                ui_warn "Cannot delete ${filepath}; please remove it manually"
            }
        }
    }
}
